Better protect allocated Ogre character data; proper blend path setting
This commit is contained in:
@@ -17,7 +17,14 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
ecs.module<CharacterModule>();
|
||||
ecs.component<Character>();
|
||||
ecs.component<Player>();
|
||||
ecs.component<CharacterBase>();
|
||||
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<CharacterGravity>();
|
||||
ecs.component<CharacterLocation>();
|
||||
ecs.component<CharacterBuoyancy>();
|
||||
@@ -211,9 +218,21 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
.each([&](flecs::entity e, const EngineData &eng,
|
||||
const CharacterLocation &loc,
|
||||
const CharacterConf &conf, CharacterBase &ch) {
|
||||
ch.mBodyEnt = eng.mScnMgr->createEntity(conf.type);
|
||||
ch.mBodyNode = eng.mScnMgr->getRootSceneNode()
|
||||
->createChildSceneNode();
|
||||
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);
|
||||
@@ -613,6 +632,8 @@ void CharacterModule::createCharacter(flecs::entity e,
|
||||
{
|
||||
if (e.has<CharacterBase>() || e.has<AnimationControl>())
|
||||
return;
|
||||
if (characterNodes.find(e) != characterNodes.end())
|
||||
return;
|
||||
e.set<CharacterLocation>({ rotation, position });
|
||||
e.set<CharacterConf>({ model });
|
||||
e.add<CharacterBase>();
|
||||
|
||||
Reference in New Issue
Block a user