From ba549946eb86d33b759f3bdc054497ef8703c13e Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Wed, 31 Jan 2024 10:16:49 +0000 Subject: [PATCH] docs(ecs): remove obsolete general sample --- core/samples/CMakeLists.txt | 1 - core/samples/ecs/general/main.cpp | 160 ------------------------------ 2 files changed, 161 deletions(-) delete mode 100644 core/samples/ecs/general/main.cpp diff --git a/core/samples/CMakeLists.txt b/core/samples/CMakeLists.txt index 5ed21ee5b2..68e47f2688 100644 --- a/core/samples/CMakeLists.txt +++ b/core/samples/CMakeLists.txt @@ -42,7 +42,6 @@ make_sample(DIR "data/ser/json") make_sample(DIR "data/des/custom") make_sample(DIR "data/serialization") make_sample(DIR "ecs/events") -make_sample(DIR "ecs/general") make_sample(DIR "ecs/relations") make_sample(DIR "gl/compute") make_sample(DIR "gl/debug_renderer") diff --git a/core/samples/ecs/general/main.cpp b/core/samples/ecs/general/main.cpp deleted file mode 100644 index 8decbb5222..0000000000 --- a/core/samples/ecs/general/main.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace cubos::core; - -using reflection::ConstructibleTrait; -using reflection::Type; - -struct Player -{ - CUBOS_REFLECT; -}; - -struct Position -{ - CUBOS_REFLECT; - - float x, y, z; -}; - -struct Velocity -{ - CUBOS_REFLECT; - - float x, y, z; -}; - -struct Parent -{ - CUBOS_REFLECT; - - ecs::Entity entity; -}; - -CUBOS_REFLECT_IMPL(Player) -{ - return ecs::TypeBuilder("Player").build(); -} - -CUBOS_REFLECT_IMPL(Position) -{ - return ecs::TypeBuilder("Position") - .withField("x", &Position::x) - .withField("y", &Position::y) - .withField("z", &Position::z) - .build(); -} - -CUBOS_REFLECT_IMPL(Velocity) -{ - return ecs::TypeBuilder("Velocity") - .withField("x", &Velocity::x) - .withField("y", &Velocity::y) - .withField("z", &Velocity::z) - .build(); -} - -CUBOS_REFLECT_IMPL(Parent) -{ - return ecs::TypeBuilder("Parent").withField("entity", &Parent::entity).build(); -} - -void spawner(ecs::Commands cmds) -{ - cmds.create().add(Position{0, 5, 1}).add(Velocity{0, 3, 1}).add(Player{}); - - ecs::Blueprint epicBlueprint{}; - auto main = epicBlueprint.create("main"); - epicBlueprint.add(main, Position{0, 0, 0}, Velocity{0, 0, 0}); - auto sub = epicBlueprint.create("sub"); - epicBlueprint.add(sub, Parent{main}); - - cmds.spawn(epicBlueprint).add("main", Position{1, 1, 1}); - cmds.spawn(epicBlueprint).add("main", Position{2, 2, 2}); - cmds.spawn(epicBlueprint).add("main", Position{3, 3, 3}); -} - -struct DeltaTime -{ - float dt; -}; - -struct MyResource -{ - int val; -}; - -void printPositions(ecs::Query query) -{ - std::cout << "positions w/velocity:" << std::endl; - for (auto [position, velocity] : query) - { - std::cout << position.x << ' ' << position.y << ' ' << position.z << std::endl; - } -} - -void printPlayerPosition(ecs::Query query) -{ - std::cout << "player positions:" << std::endl; - for (auto [player, position] : query) - { - std::cout << position.x << ' ' << position.y << ' ' << position.z << std::endl; - } -} - -void mySystem(DeltaTime& dt, const MyResource& res) -{ - std::cout << "mySystem: " << dt.dt << " " << res.val << std::endl; -} - -int main() -{ - Logger::level(Logger::Level::Critical); - ecs::World world; - world.registerResource(DeltaTime{1.0F}); - world.registerResource(MyResource{0}); - world.registerComponent(); - world.registerComponent(); - world.registerComponent(); - world.registerComponent(); - - ecs::Dispatcher dispatcher; - auto cmds = ecs::CommandBuffer(world); - - dispatcher.addSystem(spawner); - dispatcher.systemSetBeforeTag("PreProcess"); - - dispatcher.addTag("Main"); - dispatcher.addSystem(mySystem); - dispatcher.systemAddTag("Main"); - - dispatcher.addTag("Transform"); - dispatcher.tagSetAfterTag("Main"); - dispatcher.addSystem(printPositions); - dispatcher.systemAddTag("Transform"); - - dispatcher.addTag("New"); - dispatcher.tagSetAfterTag("Main"); - dispatcher.addSystem(printPlayerPosition); - dispatcher.systemAddTag("New"); - - dispatcher.addTag("PreProcess"); - dispatcher.tagSetBeforeTag("Main"); - dispatcher.tagSetBeforeTag("Transform"); - dispatcher.addSystem( - [](const DeltaTime& dt, MyResource& res) { std::cout << "lambda: " << dt.dt << " " << res.val << std::endl; }); - dispatcher.systemAddTag("PreProcess"); - - dispatcher.compileChain(); - // call systems on dispatcher - dispatcher.callSystems(world, cmds); -}