Fixed character creation missing components
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -98,7 +98,6 @@ CharacterManagerModule::CharacterManagerModule(flecs::world &ecs)
|
||||
.interval(1.0f)
|
||||
.write<CharacterBase>()
|
||||
.write<CharacterLocation>()
|
||||
.write<CharacterConf>()
|
||||
.write<Character>()
|
||||
.write<LivesIn>()
|
||||
.each([this](flecs::entity town, TerrainItem &item,
|
||||
|
||||
@@ -17,18 +17,54 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
ecs.module<CharacterModule>();
|
||||
ecs.component<Character>();
|
||||
ecs.component<Player>();
|
||||
ecs.component<CharacterBase>().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<CharacterBase>()
|
||||
.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<CharacterModule>();
|
||||
}
|
||||
})
|
||||
.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<EngineData>();
|
||||
Ogre::SceneNode *bodyNode =
|
||||
eng.mScnMgr->getRootSceneNode()
|
||||
->createChildSceneNode();
|
||||
Ogre::Entity *bodyEnt =
|
||||
eng.mScnMgr->createEntity(
|
||||
characterModels[e]);
|
||||
characterNodes[e] = bodyNode;
|
||||
characterEntities[e] = bodyEnt;
|
||||
ECS::modified<CharacterModule>();
|
||||
}
|
||||
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<CharacterGravity>();
|
||||
ecs.component<CharacterLocation>();
|
||||
ecs.component<CharacterLocation>().on_set(
|
||||
[this](flecs::entity e, CharacterLocation &loc) {
|
||||
characterOrientations[e] = loc.orientation;
|
||||
characterPositions[e] = loc.position;
|
||||
ECS::modified<CharacterModule>();
|
||||
});
|
||||
ecs.component<CharacterBuoyancy>();
|
||||
ecs.component<CharacterConf>();
|
||||
ecs.component<CharacterDisablePhysics>();
|
||||
ecs.component<CharacterUpdatePhysicsState>();
|
||||
ecs.component<CharacterInActuator>();
|
||||
@@ -211,36 +247,6 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
});
|
||||
#endif
|
||||
static int characterCount = 0;
|
||||
ecs.observer<const EngineData, const CharacterLocation,
|
||||
const CharacterConf, CharacterBase>(
|
||||
"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<CharacterModule>();
|
||||
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<CharacterModule>();
|
||||
}
|
||||
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<AnimationControl>("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<CharacterLocation>({ rotation, position });
|
||||
e.set<CharacterConf>({ model });
|
||||
e.add<CharacterBase>();
|
||||
e.add<AnimationControl>();
|
||||
characterOrientations[e] = rotation;
|
||||
characterPositions[e] = position;
|
||||
characterModels[e] = model;
|
||||
e.set<CharacterVelocity>(
|
||||
{ { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } });
|
||||
e.add<CharacterGravity>();
|
||||
e.add<CharacterBuoyancy>();
|
||||
e.add<Character>();
|
||||
e.add<CharacterBase>();
|
||||
e.add<AnimationControl>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<flecs::entity_t, Ogre::SceneNode *> characterNodes;
|
||||
std::unordered_map<flecs::entity_t, Ogre::Entity *> characterEntities;
|
||||
std::unordered_map<flecs::entity_t, Ogre::String> characterModels;
|
||||
std::unordered_map<flecs::entity_t, Ogre::Vector3> characterPositions;
|
||||
std::unordered_map<flecs::entity_t, Ogre::Quaternion> characterOrientations;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user