Fixes in modules

This commit is contained in:
2025-12-02 14:30:05 +03:00
parent 5b014dcb65
commit 6eed5063e6
16 changed files with 121 additions and 20 deletions

View File

@@ -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<BoatBase>();
ecs.component<BoatType>();
ecs.component<SpawnBoat>();
ecs.component<BoatCurrentActuator>();
ecs.import <EventModule>();
ecs.import <EventTriggerModule>();
ecs.import <CharacterModule>();
ecs.import <WaterModule>();
ecs.observer<const EngineData, const BoatType>("CreateBoat")
.event(flecs::OnSet)
.without<BoatBase>()
@@ -136,6 +139,8 @@ BoatModule::BoatModule(flecs::world &ecs)
if (ev.event == "actuator_created") {
continue;
} else if (ev.event == "actuator_enter") {
if (e.has<BoatCurrentActuator>())
continue;
if (ev.sender.has<EventTrigger>()) {
if (ev.e2.has<Player>())
PhysicsModule::
@@ -208,12 +213,22 @@ BoatModule::BoatModule(flecs::world &ecs)
orientation);
}
}
e.set<BoatCurrentActuator>(
{ ev.event,
ev.sender });
}
} else if (ev.event == "actuator_forward") {
/* */
ev.e2.set<CharacterInActuator>(
{ "swimming-edge-climb",
{ 0, 0, 0 } });
if (e.has<BoatCurrentActuator>()) {
if (e.get<BoatCurrentActuator>()
.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<TriggeredBy>(ev.e2);
ev.e2.add<CharacterGravity>();
ev.e2.add<CharacterBuoyancy>();
e.remove<BoatCurrentActuator>();
} else if (ev.event == "boat_control_enter") {
Ogre::SceneNode *captainSeat = nullptr;
std::vector<Ogre::Node *> children =

View File

@@ -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);

View File

@@ -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)

View File

@@ -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<CharacterAnimationModule>();
ecs.component<AnimationControl>();
ecs.import <EventModule>();
ecs.import <TerrainModule>();
ecs.import <WaterModule>();
ecs.import <PhysicsModule>();
ecs.system<const CharacterBase, AnimationControl>("HandleAnimations")
.kind(flecs::OnUpdate)
.each([this](flecs::entity e, const CharacterBase &ch,

View File

@@ -0,0 +1,42 @@
#include <Ogre.h>
#include <OgreConfigFile.h>
#include "GameData.h"
#include "Components.h"
#include "CharacterModule.h"
#include "CharacterAnimationModule.h"
#include "CharacterManagerModule.h"
namespace ECS
{
CharacterManagerModule::CharacterManagerModule(flecs::world &ecs)
{
ecs.module<CharacterManagerModule>();
ecs.import <CharacterModule>();
ecs.import <CharacterAnimationModule>();
}
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<CharacterLocation>({ rotation, position });
player.set<CharacterConf>({ "normal-male.glb" });
player.add<Character>();
player.add<Player>();
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<CharacterLocation>({ rotation, position })
.set<CharacterConf>({ model })
.add<Character>();
return e;
}
}

View File

@@ -0,0 +1,17 @@
#ifndef _CHARACTER_MANAGER_MODULE_
#define _CHARACTER_MANAGER_MODULE_
#include <flecs.h>
namespace ECS
{
struct CharacterManagerModule {
std::set<flecs::entity> 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

View File

@@ -30,6 +30,8 @@ CharacterModule::CharacterModule(flecs::world &ecs)
ecs.component<Male>();
ecs.component<Female>();
ecs.component<Planner>().add(flecs::Singleton);
ecs.import <TerrainModule>();
ecs.import <WaterModule>();
ecs.system<EngineData, CharacterBase>("UpdateTimer")
.kind(flecs::OnUpdate)

View File

@@ -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<btCollisionObject *, flecs::entity> entities; */

View File

@@ -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<Camera>().add(flecs::Singleton);
ecs.import <GameWorldModule>();
ecs.import <EventModule>();
ecs.import <CharacterManagerModule>();
ecs.import <WaterModule>();
ecs.component<InWater>();
ecs.component<WaterReady>().add(flecs::Singleton);
ecs.component<WaterAlmostReady>().add(flecs::Singleton);
@@ -40,7 +43,6 @@ void setup_minimal()
})
.add(flecs::Singleton);
/* lots of things depend on it */
ecs.component<TerrainReady>().add(flecs::Singleton);
ecs.component<Body2Entity>().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<CharacterLocation>({ { 0, 0, 0, 1 }, playerPos });
player.set<CharacterConf>({ "normal-male.glb" });
player.add<Character>();
player.add<Player>();
player = ecs.get_mut<CharacterManagerModule>().createPlayer(
{ 0, 0, 4 }, Ogre::Quaternion(Ogre::Radian(Ogre::Math::PI),
Ogre::Vector3::UNIT_Y));
}
void update(float delta)
{

View File

@@ -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<CharacterLocation>({ orientation, npcPos });
e.set<CharacterConf>({ type });
e.add<Character>();
flecs::entity e =
ECS::get_mut<CharacterManagerModule>()
.createCharacterData(type, npcPos, orientation);
ECS::modified<CharacterManagerModule>();
lua_pushinteger(L, idmap.add_entity(e));
return 1;
});

View File

@@ -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<CharacterVelocity>();
ecs.component<WaterBody>().add(flecs::Singleton);
ecs.component<CachedMass>();
ecs.import <TerrainModule>();
ecs.import <WaterModule>();
ecs.system<const EngineData, const Camera>("physics_init")
.kind(PhysicsPreUpdate)
.without<Physics>()

View File

@@ -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<ParentSlot>();
ecs.component<ParentSlotData>();
ecs.component<ObjectSlots>();
ecs.import <WaterModule>();
ecs.import <BoatModule>();
ecs.observer<const EngineData, const BoatBase>("CreateBoatSlots")
.event(flecs::OnSet)
.each([&](flecs::entity e, const EngineData &eng,

View File

@@ -397,10 +397,14 @@ struct TerrainPrivate {
TerrainModule::TerrainModule(flecs::world &ecs)
{
struct CanSetPlayerPosition {};
ecs.module<TerrainModule>();
ecs.component<CanSetPlayerPosition>().add(flecs::Singleton);
ecs.component<Terrain>().add(flecs::Singleton);
ecs.component<TerrainPrivate>().add(flecs::Singleton);
ecs.component<PlacementObjects>();
ecs.component<TerrainReady>().add(flecs::Singleton);
ecs.import <CharacterModule>();
ecs.import <SunModule>();
ecs.set<TerrainPrivate>({ nullptr, {} });
ecs.system<const EngineData, const Camera, const Sun, Terrain,
TerrainPrivate>("SetupUpdateTerrain")

View File

@@ -36,5 +36,6 @@ struct TerrainModule {
static float get_height(Ogre::TerrainGroup *group,
const Ogre::Vector3 &position);
};
struct TerrainReady {};
}
#endif

View File

@@ -59,6 +59,10 @@ static const uint32_t WATER_MASK = 0xF00;
WaterModule::WaterModule(flecs::world &ecs)
{
ecs.module<WaterModule>();
ecs.component<InWater>();
ecs.component<WaterReady>().add(flecs::Singleton);
ecs.component<WaterAlmostReady>().add(flecs::Singleton);
ecs.component<GroundCheckReady>().add(flecs::Singleton);
ecs.component<WaterSurface>()
.on_add([](flecs::entity e, WaterSurface &water) {
water.mAbove = false;

View File

@@ -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);