Fixed freezing with NPCs

This commit is contained in:
2026-02-25 17:53:42 +03:00
parent cb2ce23009
commit fe083f13da
3 changed files with 15 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ CharacterModule::CharacterModule(flecs::world &ecs)
body_parts[age][sex].end())
body_parts[age][sex][slot] = nlohmann::json::array();
body_parts[age][sex][slot].push_back(mesh);
mesh_names.insert(mesh);
Ogre::MeshManager::getSingleton().load(mesh, "Characters");
}
std::cout << body_parts.dump(4) << std::endl;
@@ -768,4 +769,13 @@ void CharacterModule::getSlotMeshes(const Ogre::String &age,
for (auto &slots : body_parts[age][sex][slotName])
meshes.push_back(slots.get<Ogre::String>());
}
void CharacterModule::preloadMeshes()
{
for (const auto &mesh : mesh_names) {
Ogre::Entity *ent =
ECS::get<EngineData>().mScnMgr->createEntity(mesh);
ECS::get<EngineData>().mScnMgr->destroyEntity(ent);
}
}
}

View File

@@ -19,7 +19,7 @@ struct Female {};
struct CharacterBase {
Ogre::String type;
float mTimer;
float mTimer;
Ogre::Vector3 mBoneMotion;
Ogre::Vector3 mBonePrevMotion;
Ogre::Vector3 mGoalDirection; // actual intended direction in world-space
@@ -64,11 +64,13 @@ struct CharacterModule {
std::unordered_map<flecs::entity_t, Ogre::Quaternion>
characterOrientations;
nlohmann::json body_parts;
std::set<Ogre::String> mesh_names;
void remapMeshToMasterSkeleton(Ogre::MeshPtr clothMesh,
Ogre::MeshPtr masterMesh);
void getSlotMeshes(const Ogre::String &age, const Ogre::String &sex,
const Ogre::String &slotName,
std::vector<Ogre::String> &meshes);
void preloadMeshes();
};
}
#endif

View File

@@ -200,6 +200,8 @@ void setupExteriorScene(Ogre::SceneManager *scnMgr, Ogre::SceneNode *cameraNode,
new_game_run.destruct();
}
});
ecs.get_mut<CharacterModule>().preloadMeshes();
ecs.modified<CharacterModule>();
std::cout << "scene setup done" << std::endl;
}
void setupInteriorScene(Ogre::SceneManager *scnMgr, Ogre::SceneNode *cameraNode,