diff --git a/BeefProj.toml b/BeefProj.toml new file mode 100644 index 0000000..8797221 --- /dev/null +++ b/BeefProj.toml @@ -0,0 +1,6 @@ +FileVersion = 1 +Dependencies = {corlib = "*", raylib-beef = "*", Theater-ECS = "*"} + +[Project] +Name = "Theater-ECS-Example" +StartupObject = "Theater_ECS_Example.Program" diff --git a/BeefSpace.toml b/BeefSpace.toml new file mode 100644 index 0000000..8e1027e --- /dev/null +++ b/BeefSpace.toml @@ -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" diff --git a/BeefSpace_Lock.toml b/BeefSpace_Lock.toml new file mode 100644 index 0000000..3e6b63d --- /dev/null +++ b/BeefSpace_Lock.toml @@ -0,0 +1 @@ +FileVersion = 1 diff --git a/img.png b/img.png new file mode 100644 index 0000000..6c0ed6f Binary files /dev/null and b/img.png differ diff --git a/img.png~ b/img.png~ new file mode 100644 index 0000000..4fccb88 Binary files /dev/null and b/img.png~ differ diff --git a/src/MovementSystem.bf b/src/MovementSystem.bf new file mode 100644 index 0000000..e255628 --- /dev/null +++ b/src/MovementSystem.bf @@ -0,0 +1,28 @@ +namespace Theater_ECS_Example; + +using Theater_ECS; + +class MovementSystem : System +{ + public override void RegisterSystem(ECS ecs) + { + RegisterComponent(ecs); + RegisterComponent(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; + } +} \ No newline at end of file diff --git a/src/Position.bf b/src/Position.bf new file mode 100644 index 0000000..15faf97 --- /dev/null +++ b/src/Position.bf @@ -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; + } +} \ No newline at end of file diff --git a/src/Program.bf b/src/Program.bf new file mode 100644 index 0000000..1866c03 --- /dev/null +++ b/src/Program.bf @@ -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(); + } + } +} \ No newline at end of file diff --git a/src/RendererSystem.bf b/src/RendererSystem.bf new file mode 100644 index 0000000..f4fdf87 --- /dev/null +++ b/src/RendererSystem.bf @@ -0,0 +1,20 @@ +namespace Theater_ECS_Example; + +using Theater_ECS; + +using RaylibBeef; + +class RendererSystem : System +{ + public override void RegisterSystem(ECS ecs) + { + RegisterComponent(ecs); + RegisterComponent(ecs); + } + + public override void Run(void* pos, void* sprite) + { + var toDraw = (Position*)pos; + //Raylib.DrawTexture(((Sprite*)sprite).sprite, (.)toDraw.x, (.)toDraw.y, Raylib.WHITE); + } +} \ No newline at end of file diff --git a/src/Sprite.bf b/src/Sprite.bf new file mode 100644 index 0000000..d342ffa --- /dev/null +++ b/src/Sprite.bf @@ -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; + } +} \ No newline at end of file diff --git a/src/Velocity.bf b/src/Velocity.bf new file mode 100644 index 0000000..b5b4b5a --- /dev/null +++ b/src/Velocity.bf @@ -0,0 +1,9 @@ +namespace Theater_ECS_Example; + +using System; + +struct Velocity +{ + public float x = (.)gRand.NextI32() % 30; + public float y = (.)gRand.NextI32() % 30; +} \ No newline at end of file