diff --git a/src/gamedata/BoatModule.cpp b/src/gamedata/BoatModule.cpp index 5e61523..10ac33e 100644 --- a/src/gamedata/BoatModule.cpp +++ b/src/gamedata/BoatModule.cpp @@ -9,6 +9,7 @@ #include "EventModule.h" #include "EventTriggerModule.h" #include "CharacterModule.h" +#include "WaterModule.h" #include "BoatModule.h" namespace ECS @@ -20,9 +21,11 @@ BoatModule::BoatModule(flecs::world &ecs) ecs.component(); ecs.component(); ecs.component(); + ecs.component(); ecs.import (); ecs.import (); ecs.import (); + ecs.import (); ecs.observer("CreateBoat") .event(flecs::OnSet) .without() @@ -136,6 +139,8 @@ BoatModule::BoatModule(flecs::world &ecs) if (ev.event == "actuator_created") { continue; } else if (ev.event == "actuator_enter") { + if (e.has()) + continue; if (ev.sender.has()) { if (ev.e2.has()) PhysicsModule:: @@ -208,12 +213,22 @@ BoatModule::BoatModule(flecs::world &ecs) orientation); } } + e.set( + { ev.event, + ev.sender }); } } else if (ev.event == "actuator_forward") { /* */ - ev.e2.set( - { "swimming-edge-climb", - { 0, 0, 0 } }); + if (e.has()) { + if (e.get() + .actuator == + "actuator_enter") + ev.e2.set< + CharacterInActuator>( + { "swimming-edge-climb", + { 0, 0, + 0 } }); + } } else if (ev.event == "actuator_backward") { /* */ } else if (ev.event == @@ -225,6 +240,7 @@ BoatModule::BoatModule(flecs::world &ecs) ev.e1.remove(ev.e2); ev.e2.add(); ev.e2.add(); + e.remove(); } else if (ev.event == "boat_control_enter") { Ogre::SceneNode *captainSeat = nullptr; std::vector children = diff --git a/src/gamedata/BoatModule.h b/src/gamedata/BoatModule.h index 352ad15..4a2550d 100644 --- a/src/gamedata/BoatModule.h +++ b/src/gamedata/BoatModule.h @@ -18,6 +18,10 @@ struct BoatBase { Ogre::Entity *mEnt; Ogre::SceneNode *mNode; }; +struct BoatCurrentActuator { + Ogre::String actuator; + flecs::entity actuator_e; +}; struct SpawnBoat {}; struct BoatModule { BoatModule(flecs::world &ecs); diff --git a/src/gamedata/CMakeLists.txt b/src/gamedata/CMakeLists.txt index c38965a..f965bb3 100644 --- a/src/gamedata/CMakeLists.txt +++ b/src/gamedata/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_CXX_STANDARD 17) find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain Overlay CONFIG) find_package(Bullet REQUIRED) add_library(GameData STATIC GameData.cpp CharacterModule.cpp WaterModule.cpp SunModule.cpp TerrainModule.cpp GUIModule.cpp LuaData.cpp WorldMapModule.cpp - BoatModule.cpp EventTriggerModule.cpp CharacterAnimationModule.cpp PhysicsModule.cpp EventModule.cpp SmartObject.cpp SlotsModule.cpp goap.cpp) + BoatModule.cpp EventTriggerModule.cpp CharacterAnimationModule.cpp PhysicsModule.cpp EventModule.cpp CharacterManagerModule.cpp SmartObject.cpp SlotsModule.cpp goap.cpp) target_link_libraries(GameData PUBLIC lua flecs::flecs_static OgreMain OgreBites OgrePaging OgreTerrain OgreOverlay PRIVATE sceneloader world-build physics) diff --git a/src/gamedata/CharacterAnimationModule.cpp b/src/gamedata/CharacterAnimationModule.cpp index 0e99a67..028e76f 100644 --- a/src/gamedata/CharacterAnimationModule.cpp +++ b/src/gamedata/CharacterAnimationModule.cpp @@ -5,6 +5,8 @@ #include "PhysicsModule.h" #include "CharacterAnimationModule.h" #include "EventModule.h" +#include "TerrainModule.h" +#include "WaterModule.h" #include "world-build.h" namespace ECS { @@ -13,6 +15,9 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs) ecs.module(); ecs.component(); ecs.import (); + ecs.import (); + ecs.import (); + ecs.import (); ecs.system("HandleAnimations") .kind(flecs::OnUpdate) .each([this](flecs::entity e, const CharacterBase &ch, diff --git a/src/gamedata/CharacterManagerModule.cpp b/src/gamedata/CharacterManagerModule.cpp new file mode 100644 index 0000000..476e130 --- /dev/null +++ b/src/gamedata/CharacterManagerModule.cpp @@ -0,0 +1,42 @@ +#include +#include +#include "GameData.h" +#include "Components.h" +#include "CharacterModule.h" +#include "CharacterAnimationModule.h" +#include "CharacterManagerModule.h" + +namespace ECS +{ +CharacterManagerModule::CharacterManagerModule(flecs::world &ecs) +{ + ecs.module(); + ecs.import (); + ecs.import (); +} +flecs::entity +CharacterManagerModule::createPlayer(const Ogre::Vector3 &position, + const Ogre::Quaternion &rotation) +{ + player = ECS::get().entity("player"); + Ogre::Vector3 playerPos(0, 0, 4); + player.set({ rotation, position }); + player.set({ "normal-male.glb" }); + player.add(); + player.add(); + return player; +} +flecs::entity +CharacterManagerModule::createCharacterData(const Ogre::String model, + const Ogre::Vector3 &position, + const Ogre::Quaternion &rotation) +{ + flecs::entity e = + ECS::get() + .entity() + .set({ rotation, position }) + .set({ model }) + .add(); + return e; +} +} \ No newline at end of file diff --git a/src/gamedata/CharacterManagerModule.h b/src/gamedata/CharacterManagerModule.h new file mode 100644 index 0000000..96741d1 --- /dev/null +++ b/src/gamedata/CharacterManagerModule.h @@ -0,0 +1,17 @@ +#ifndef _CHARACTER_MANAGER_MODULE_ +#define _CHARACTER_MANAGER_MODULE_ +#include +namespace ECS +{ +struct CharacterManagerModule { + std::set characters; + CharacterManagerModule(flecs::world &ecs); + flecs::entity createPlayer(const Ogre::Vector3 &position, + const Ogre::Quaternion &rotation); + flecs::entity createCharacterData(const Ogre::String model, + const Ogre::Vector3 &position, + const Ogre::Quaternion &rotation); + void removeCharacterData(int id); +}; +} +#endif \ No newline at end of file diff --git a/src/gamedata/CharacterModule.cpp b/src/gamedata/CharacterModule.cpp index 260fd7b..d4df303 100644 --- a/src/gamedata/CharacterModule.cpp +++ b/src/gamedata/CharacterModule.cpp @@ -30,6 +30,8 @@ CharacterModule::CharacterModule(flecs::world &ecs) ecs.component(); ecs.component(); ecs.component().add(flecs::Singleton); + ecs.import (); + ecs.import (); ecs.system("UpdateTimer") .kind(flecs::OnUpdate) diff --git a/src/gamedata/Components.h b/src/gamedata/Components.h index 22cef6d..bbadf68 100644 --- a/src/gamedata/Components.h +++ b/src/gamedata/Components.h @@ -75,10 +75,6 @@ struct App { struct CollisionShape { void *shape; }; -struct InWater {}; -struct TerrainReady {}; -struct WaterAlmostReady {}; -struct WaterReady {}; struct GroundCheckReady {}; struct Body2Entity { /* std::unordered_map entities; */ diff --git a/src/gamedata/GameData.cpp b/src/gamedata/GameData.cpp index b9c218d..483c1b4 100644 --- a/src/gamedata/GameData.cpp +++ b/src/gamedata/GameData.cpp @@ -14,6 +14,7 @@ #include "CharacterAnimationModule.h" #include "PhysicsModule.h" #include "EventModule.h" +#include "CharacterManagerModule.h" #include "world-build.h" namespace ECS @@ -28,6 +29,8 @@ void setup_minimal() ecs.component().add(flecs::Singleton); ecs.import (); ecs.import (); + ecs.import (); + ecs.import (); ecs.component(); ecs.component().add(flecs::Singleton); ecs.component().add(flecs::Singleton); @@ -40,7 +43,6 @@ void setup_minimal() }) .add(flecs::Singleton); /* lots of things depend on it */ - ecs.component().add(flecs::Singleton); ecs.component().add(flecs::Singleton); } void setup(Ogre::SceneManager *scnMgr, Ogre::SceneNode *cameraNode, @@ -110,12 +112,9 @@ void setup(Ogre::SceneManager *scnMgr, Ogre::SceneNode *cameraNode, std::cout << "Setup GameData done\n"; /* Create player */ - player = ecs.entity("player"); - Ogre::Vector3 playerPos(0, 0, 4); - player.set({ { 0, 0, 0, 1 }, playerPos }); - player.set({ "normal-male.glb" }); - player.add(); - player.add(); + player = ecs.get_mut().createPlayer( + { 0, 0, 4 }, Ogre::Quaternion(Ogre::Radian(Ogre::Math::PI), + Ogre::Vector3::UNIT_Y)); } void update(float delta) { diff --git a/src/gamedata/LuaData.cpp b/src/gamedata/LuaData.cpp index fa819cd..759b773 100644 --- a/src/gamedata/LuaData.cpp +++ b/src/gamedata/LuaData.cpp @@ -5,6 +5,7 @@ #include "PhysicsModule.h" #include "CharacterModule.h" #include "CharacterAnimationModule.h" +#include "CharacterManagerModule.h" #include "BoatModule.h" #include "EventTriggerModule.h" #include "SlotsModule.h" @@ -505,13 +506,13 @@ LuaData::LuaData() float x = lua_tonumber(L, 2); float y = lua_tonumber(L, 3); float z = lua_tonumber(L, 4); - flecs::entity e = ECS::get().entity(); Ogre::Quaternion orientation(Ogre::Radian(yaw), - Ogre::Vector3(0, 1, 0)); + Ogre::Vector3::UNIT_Y); Ogre::Vector3 npcPos(x, y, z); - e.set({ orientation, npcPos }); - e.set({ type }); - e.add(); + flecs::entity e = + ECS::get_mut() + .createCharacterData(type, npcPos, orientation); + ECS::modified(); lua_pushinteger(L, idmap.add_entity(e)); return 1; }); diff --git a/src/gamedata/PhysicsModule.cpp b/src/gamedata/PhysicsModule.cpp index 6385323..f9aa9ca 100644 --- a/src/gamedata/PhysicsModule.cpp +++ b/src/gamedata/PhysicsModule.cpp @@ -17,6 +17,7 @@ #include "physics.h" #include "loader.h" #include "EventModule.h" +#include "TerrainModule.h" #include "PhysicsModule.h" namespace ECS { @@ -58,6 +59,8 @@ PhysicsModule::PhysicsModule(flecs::world &ecs) ecs.component(); ecs.component().add(flecs::Singleton); ecs.component(); + ecs.import (); + ecs.import (); ecs.system("physics_init") .kind(PhysicsPreUpdate) .without() diff --git a/src/gamedata/SlotsModule.cpp b/src/gamedata/SlotsModule.cpp index 56d25c5..f58b148 100644 --- a/src/gamedata/SlotsModule.cpp +++ b/src/gamedata/SlotsModule.cpp @@ -3,6 +3,8 @@ #include "GameData.h" #include "CharacterModule.h" #include "BoatModule.h" +#include "WaterModule.h" +#include "BoatModule.h" #include "SlotsModule.h" namespace ECS { @@ -13,6 +15,8 @@ SlotsModule::SlotsModule(flecs::world &ecs) ecs.component(); ecs.component(); ecs.component(); + ecs.import (); + ecs.import (); ecs.observer("CreateBoatSlots") .event(flecs::OnSet) .each([&](flecs::entity e, const EngineData &eng, diff --git a/src/gamedata/TerrainModule.cpp b/src/gamedata/TerrainModule.cpp index 0612871..4eada02 100644 --- a/src/gamedata/TerrainModule.cpp +++ b/src/gamedata/TerrainModule.cpp @@ -397,10 +397,14 @@ struct TerrainPrivate { TerrainModule::TerrainModule(flecs::world &ecs) { struct CanSetPlayerPosition {}; + ecs.module(); ecs.component().add(flecs::Singleton); ecs.component().add(flecs::Singleton); ecs.component().add(flecs::Singleton); ecs.component(); + ecs.component().add(flecs::Singleton); + ecs.import (); + ecs.import (); ecs.set({ nullptr, {} }); ecs.system("SetupUpdateTerrain") diff --git a/src/gamedata/TerrainModule.h b/src/gamedata/TerrainModule.h index befd053..8019248 100644 --- a/src/gamedata/TerrainModule.h +++ b/src/gamedata/TerrainModule.h @@ -36,5 +36,6 @@ struct TerrainModule { static float get_height(Ogre::TerrainGroup *group, const Ogre::Vector3 &position); }; +struct TerrainReady {}; } #endif \ No newline at end of file diff --git a/src/gamedata/WaterModule.cpp b/src/gamedata/WaterModule.cpp index 5027723..dfba5a7 100644 --- a/src/gamedata/WaterModule.cpp +++ b/src/gamedata/WaterModule.cpp @@ -59,6 +59,10 @@ static const uint32_t WATER_MASK = 0xF00; WaterModule::WaterModule(flecs::world &ecs) { ecs.module(); + ecs.component(); + ecs.component().add(flecs::Singleton); + ecs.component().add(flecs::Singleton); + ecs.component().add(flecs::Singleton); ecs.component() .on_add([](flecs::entity e, WaterSurface &water) { water.mAbove = false; diff --git a/src/gamedata/WaterModule.h b/src/gamedata/WaterModule.h index 3405d37..bba5b37 100644 --- a/src/gamedata/WaterModule.h +++ b/src/gamedata/WaterModule.h @@ -37,6 +37,9 @@ struct WaterSurface { mRefractionClipPlaneBelow; Ogre::Viewport *mViewports[4]; }; +struct InWater {}; +struct WaterAlmostReady {}; +struct WaterReady {}; struct WaterModule { // btPairCachingGhostObject *mGhostObject; WaterModule(flecs::world &ecs);