1
0
Fork 0

Added basic

This commit is contained in:
Booklordofthedings 2024-11-17 16:57:27 +01:00
parent 24ff95287d
commit 265ad04473
11 changed files with 165 additions and 0 deletions

6
BeefProj.toml Normal file
View file

@ -0,0 +1,6 @@
FileVersion = 1
Dependencies = {corlib = "*", raylib-beef = "*", Theater-ECS = "*"}
[Project]
Name = "Theater-ECS-Example"
StartupObject = "Theater_ECS_Example.Program"

5
BeefSpace.toml Normal file
View file

@ -0,0 +1,5 @@
FileVersion = 1
Projects = {Theater-ECS-Example = {Path = "."}, raylib-beef = {Path = "../../Program Files/BeefLang/BeefLibs/raylib-beef/raylib-beef"}, Theater-ECS = {Path = "../Theater-ECS"}}
[Workspace]
StartupProject = "Theater-ECS-Example"

1
BeefSpace_Lock.toml Normal file
View file

@ -0,0 +1 @@
FileVersion = 1

BIN
img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 927 B

BIN
img.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

28
src/MovementSystem.bf Normal file
View file

@ -0,0 +1,28 @@
namespace Theater_ECS_Example;
using Theater_ECS;
class MovementSystem : System
{
public override void RegisterSystem(ECS ecs)
{
RegisterComponent<Position>(ecs);
RegisterComponent<Velocity>(ecs);
}
public override void Run(void* pos, void* vel)
{
var mPos = ((Position*)pos);
mPos.Update(
((Velocity*)vel).x * RaylibBeef.Raylib.GetFrameTime(),
((Velocity*)vel).y * RaylibBeef.Raylib.GetFrameTime()
);
if(mPos.x > 1280 || mPos.x < 0)
((Velocity*)vel).x *= -1;
if(mPos.y > 720 || mPos.y < 0)
((Velocity*)vel).y *= -1;
}
}

15
src/Position.bf Normal file
View file

@ -0,0 +1,15 @@
namespace Theater_ECS_Example;
using System;
struct Position
{
public float x = (.)gRand.NextI32() % 1280;
public float y = (.)gRand.NextI32() % 720;
public void Update(float a, float b) mut
{
x += a;
y += b;
}
}

62
src/Program.bf Normal file
View file

@ -0,0 +1,62 @@
namespace Theater_ECS_Example;
using System;
using RaylibBeef;
using Theater_ECS;
class Program
{
public static void Main()
{
Raylib.InitWindow(1280, 720, "Theater-ECS-Example");
ECS ecs = new .();
defer delete ecs;
RendererSystem rendererSystem = new .();
defer delete rendererSystem;
rendererSystem.RegisterSystem(ecs);
MovementSystem movementSystem = new .();
defer delete movementSystem;
movementSystem.RegisterSystem(ecs);
uint64 entityCounter = 0;
for(int32 i < 50000)
{
entityCounter++;
var entity = ecs.Entity_Create();
ecs.[Friend]_compRegistry.Components[rendererSystem.[Friend]_Components[0]].Add(entity, &Position());
ecs.[Friend]_compRegistry.Components[rendererSystem.[Friend]_Components[1]].Add(entity, &Sprite());
ecs.[Friend]_compRegistry.Components[movementSystem.[Friend]_Components[1]].Add(entity, &Velocity());
}
while(!Raylib.WindowShouldClose())
{
movementSystem.RunSystem(ecs);
if(Raylib.IsMouseButtonDown((.)MouseButton.MOUSE_BUTTON_LEFT))
{
entityCounter++;
var entity = ecs.Entity_Create();
ecs.[Friend]_compRegistry.Components[rendererSystem.[Friend]_Components[0]].Add(entity, &Position());
ecs.[Friend]_compRegistry.Components[rendererSystem.[Friend]_Components[1]].Add(entity, &Sprite());
ecs.[Friend]_compRegistry.Components[movementSystem.[Friend]_Components[1]].Add(entity, &Velocity());
}
Raylib.BeginDrawing();
Raylib.ClearBackground(Raylib.RAYWHITE);
rendererSystem.RunSystem(ecs);
Raylib.DrawFPS(0,0);
Raylib.DrawText(entityCounter.ToString(.. scope .()), 0, 20, 20, Raylib.BLACK);
Raylib.EndDrawing();
}
}
}

20
src/RendererSystem.bf Normal file
View file

@ -0,0 +1,20 @@
namespace Theater_ECS_Example;
using Theater_ECS;
using RaylibBeef;
class RendererSystem : System
{
public override void RegisterSystem(ECS ecs)
{
RegisterComponent<Position>(ecs);
RegisterComponent<Sprite>(ecs);
}
public override void Run(void* pos, void* sprite)
{
var toDraw = (Position*)pos;
//Raylib.DrawTexture(((Sprite*)sprite).sprite, (.)toDraw.x, (.)toDraw.y, Raylib.WHITE);
}
}

19
src/Sprite.bf Normal file
View file

@ -0,0 +1,19 @@
namespace Theater_ECS_Example;
using System;
using RaylibBeef;
struct Sprite
{
private static Texture2D? _texture = null;
public Texture2D sprite;
public this()
{
if(_texture == null)
_texture = Raylib.LoadTexture("img.png");
sprite = (.)_texture;
}
}

9
src/Velocity.bf Normal file
View file

@ -0,0 +1,9 @@
namespace Theater_ECS_Example;
using System;
struct Velocity
{
public float x = (.)gRand.NextI32() % 30;
public float y = (.)gRand.NextI32() % 30;
}