diff --git a/src/gamedata/CharacterAIModule.cpp b/src/gamedata/CharacterAIModule.cpp index 2b27c27..45f229f 100644 --- a/src/gamedata/CharacterAIModule.cpp +++ b/src/gamedata/CharacterAIModule.cpp @@ -333,8 +333,11 @@ public: props["tags"].end()) { std::cout << "toilet" << std::endl; OgreAssert(false, "props: " + props.dump(4)); - } else - OgreAssert(false, "props: " + props.dump(4)); + } else { + std::cout << "use: " << props.dump(4) + << std::endl; + // OgreAssert(false, "props: " + props.dump(4)); + } } else { OgreAssert(false, "props: " + props.dump(4)); } diff --git a/src/gamedata/CharacterManagerModule.cpp b/src/gamedata/CharacterManagerModule.cpp index 92e5690..8378328 100644 --- a/src/gamedata/CharacterManagerModule.cpp +++ b/src/gamedata/CharacterManagerModule.cpp @@ -98,7 +98,6 @@ CharacterManagerModule::CharacterManagerModule(flecs::world &ecs) .interval(1.0f) .write() .write() - .write() .write() .write() .each([this](flecs::entity town, TerrainItem &item, diff --git a/src/gamedata/CharacterModule.cpp b/src/gamedata/CharacterModule.cpp index 2f16070..2db6bb7 100644 --- a/src/gamedata/CharacterModule.cpp +++ b/src/gamedata/CharacterModule.cpp @@ -17,18 +17,54 @@ CharacterModule::CharacterModule(flecs::world &ecs) ecs.module(); ecs.component(); ecs.component(); - ecs.component().on_remove([this](flecs::entity e, - CharacterBase &ch) { - if (characterEntities.find(e) != characterEntities.end() || - characterNodes.find(e) != characterNodes.end()) { - characterEntities.erase(e); - characterNodes.erase(e); - } - }); + ecs.component() + .on_remove([this](flecs::entity e, CharacterBase &ch) { + // FIXME: clean up data + if (characterEntities.find(e) != + characterEntities.end() || + characterNodes.find(e) != characterNodes.end()) { + characterEntities.erase(e); + characterNodes.erase(e); + ECS::modified(); + } + }) + .on_add([this](flecs::entity e, CharacterBase &ch) { + if (characterNodes.find(e) == characterNodes.end()) { + OgreAssert(characterModels.find(e) != + characterModels.end(), + "no model set"); + const EngineData &eng = ECS::get(); + Ogre::SceneNode *bodyNode = + eng.mScnMgr->getRootSceneNode() + ->createChildSceneNode(); + Ogre::Entity *bodyEnt = + eng.mScnMgr->createEntity( + characterModels[e]); + characterNodes[e] = bodyNode; + characterEntities[e] = bodyEnt; + ECS::modified(); + } + OgreAssert(characterOrientations.find(e) != + characterOrientations.end(), + "Bad orientation/position"); + ch.mBodyEnt = characterEntities[e]; + ch.mBodyNode = characterNodes[e]; + ch.mBodyNode->setOrientation(characterOrientations[e]); + ch.mBodyNode->setPosition(characterPositions[e]); + ch.mBodyNode->attachObject(ch.mBodyEnt); + OgreAssert(ch.mBodyEnt->getSkeleton()->hasBone("Root"), + "No root bone"); + ch.mBoneMotion = Ogre::Vector3::ZERO; + ch.mBonePrevMotion = Ogre::Vector3::ZERO; + }); ecs.component(); - ecs.component(); + ecs.component().on_set( + [this](flecs::entity e, CharacterLocation &loc) { + characterOrientations[e] = loc.orientation; + characterPositions[e] = loc.position; + ECS::modified(); + }); ecs.component(); - ecs.component(); ecs.component(); ecs.component(); ecs.component(); @@ -211,36 +247,6 @@ CharacterModule::CharacterModule(flecs::world &ecs) }); #endif static int characterCount = 0; - ecs.observer( - "SetupCharacterBaseObs") - .event(flecs::OnAdd) - .each([&](flecs::entity e, const EngineData &eng, - const CharacterLocation &loc, - const CharacterConf &conf, CharacterBase &ch) { - CharacterModule &module = - ECS::get().get_mut(); - if (module.characterNodes.find(e) == - module.characterNodes.end()) { - Ogre::SceneNode *bodyNode = - eng.mScnMgr->getRootSceneNode() - ->createChildSceneNode(); - Ogre::Entity *bodyEnt = - eng.mScnMgr->createEntity(conf.type); - module.characterNodes[e] = bodyNode; - module.characterEntities[e] = bodyEnt; - ECS::modified(); - } - ch.mBodyEnt = module.characterEntities[e]; - ch.mBodyNode = module.characterNodes[e]; - ch.mBodyNode->setOrientation(loc.orientation); - ch.mBodyNode->setPosition(loc.position); - ch.mBodyNode->attachObject(ch.mBodyEnt); - OgreAssert(ch.mBodyEnt->getSkeleton()->hasBone("Root"), - "No root bone"); - ch.mBoneMotion = Ogre::Vector3::ZERO; - ch.mBonePrevMotion = Ogre::Vector3::ZERO; - }); ecs.observer("SetupAnimationControlObs") .event(flecs::OnAdd) .each([](flecs::entity e, AnimationControl &anim) { @@ -635,13 +641,15 @@ void CharacterModule::createCharacter(flecs::entity e, if (characterNodes.find(e) != characterNodes.end()) return; e.set({ rotation, position }); - e.set({ model }); - e.add(); - e.add(); + characterOrientations[e] = rotation; + characterPositions[e] = position; + characterModels[e] = model; e.set( { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }); e.add(); e.add(); e.add(); + e.add(); + e.add(); } } diff --git a/src/gamedata/CharacterModule.h b/src/gamedata/CharacterModule.h index 8f23efe..9f3a702 100644 --- a/src/gamedata/CharacterModule.h +++ b/src/gamedata/CharacterModule.h @@ -30,9 +30,6 @@ struct CharacterLocation { Ogre::Quaternion orientation; Ogre::Vector3 position; }; -struct CharacterConf { - Ogre::String type; -}; struct CharacterInActuator { Ogre::String animationState; Vector3 prevMotion; @@ -47,6 +44,9 @@ struct CharacterModule { const Ogre::String model); std::unordered_map characterNodes; std::unordered_map characterEntities; + std::unordered_map characterModels; + std::unordered_map characterPositions; + std::unordered_map characterOrientations; }; } #endif