Adapted more debugging with Tracy, characters update
This commit is contained in:
@@ -26,12 +26,14 @@ static bool templatesLoaded = false;
|
||||
static std::list<std::pair<long, long> > addQueue;
|
||||
StaticGeometryModule::StaticGeometryModule(flecs::world &ecs)
|
||||
{
|
||||
ZoneScoped;
|
||||
ecs.module<StaticGeometryModule>();
|
||||
ecs.component<TerrainSlotParent>();
|
||||
ecs.component<TerrainItem>();
|
||||
ecs.component<FurnitureItem>();
|
||||
ecs.component<FurnitureInstance>()
|
||||
.on_remove([](flecs::entity e, FurnitureInstance &instance) {
|
||||
ZoneScoped;
|
||||
if (instance.furniture) {
|
||||
instance.furniture
|
||||
->destroyAllChildrenAndObjects();
|
||||
@@ -41,6 +43,7 @@ StaticGeometryModule::StaticGeometryModule(flecs::world &ecs)
|
||||
}
|
||||
})
|
||||
.on_set([](flecs::entity e, FurnitureInstance &instance) {
|
||||
ZoneScoped;
|
||||
if (instance.furniture !=
|
||||
e.get<FurnitureInstance>().furniture) {
|
||||
FurnitureInstance &f =
|
||||
@@ -54,11 +57,13 @@ StaticGeometryModule::StaticGeometryModule(flecs::world &ecs)
|
||||
}
|
||||
})
|
||||
.on_add([](flecs::entity e, FurnitureInstance &instance) {
|
||||
ZoneScoped;
|
||||
instance.furniture = nullptr;
|
||||
});
|
||||
ecs.component<TerrainItemNode>().on_remove([](flecs::entity e,
|
||||
TerrainItemNode &item) {
|
||||
if (item.itemNode) {
|
||||
ZoneScoped;
|
||||
if (item.itemNode) {
|
||||
item.itemNode->destroyAllChildrenAndObjects();
|
||||
item.itemNode->getCreator()->destroySceneNode(
|
||||
item.itemNode);
|
||||
@@ -76,7 +81,8 @@ StaticGeometryModule::StaticGeometryModule(flecs::world &ecs)
|
||||
ecs.observer<const Terrain>("LoadTerrainItems")
|
||||
.event(flecs::OnSet)
|
||||
.each([&](const Terrain &terrain) {
|
||||
if (terrain.mTerrainGroup && !itemsLoaded) {
|
||||
ZoneScopedN("LoadTerrainItems");
|
||||
if (terrain.mTerrainGroup && !itemsLoaded) {
|
||||
loadItems();
|
||||
itemsLoaded = true;
|
||||
}
|
||||
@@ -84,7 +90,8 @@ StaticGeometryModule::StaticGeometryModule(flecs::world &ecs)
|
||||
if (!Ogre::MeshLodGenerator::getSingletonPtr())
|
||||
new Ogre::MeshLodGenerator();
|
||||
ecs.system("AddGeometryQueue").kind(flecs::OnUpdate).run([&](flecs::iter &it) {
|
||||
std::list<flecs::entity> items;
|
||||
ZoneScopedN("AddGeometryQueue");
|
||||
std::list<flecs::entity> items;
|
||||
if (!ECS::get().has<Terrain>())
|
||||
return;
|
||||
if (!ECS::get<Terrain>().mTerrainGroup)
|
||||
@@ -143,11 +150,13 @@ StaticGeometryModule::StaticGeometryModule(flecs::world &ecs)
|
||||
}
|
||||
void StaticGeometryModule::addGeometryForSlot(long x, long y)
|
||||
{
|
||||
addQueue.push_back({ x, y });
|
||||
ZoneScoped;
|
||||
addQueue.push_back({ x, y });
|
||||
}
|
||||
void StaticGeometryModule::removeGeometryForSlot(long x, long y)
|
||||
{
|
||||
std::pair<long, long> slot = { x, y };
|
||||
ZoneScoped;
|
||||
std::pair<long, long> slot = { x, y };
|
||||
flecs::entity parent =
|
||||
ECS::get().query_builder<const TerrainSlotParent>().build().find(
|
||||
[&slot](const TerrainSlotParent &parent) {
|
||||
@@ -170,7 +179,8 @@ StaticGeometryModule::createItem(const Ogre::Vector3 &position,
|
||||
const Ogre::Quaternion &orientation,
|
||||
const Ogre::String &type)
|
||||
{
|
||||
long x, y;
|
||||
ZoneScoped;
|
||||
long x, y;
|
||||
ECS::get<Terrain>().mTerrainGroup->convertWorldPositionToTerrainSlot(
|
||||
position, &x, &y);
|
||||
std::pair<long, long> pos{ x, y };
|
||||
@@ -192,19 +202,22 @@ StaticGeometryModule::createItem(const Ogre::Vector3 &position,
|
||||
void StaticGeometryModule::setItemProperties(flecs::entity id,
|
||||
Ogre::String properties)
|
||||
{
|
||||
OgreAssert(id.is_valid(), "bad id");
|
||||
ZoneScoped;
|
||||
OgreAssert(id.is_valid(), "bad id");
|
||||
id.get_mut<TerrainItem>().properties = properties;
|
||||
id.modified<TerrainItem>();
|
||||
}
|
||||
const Ogre::String &StaticGeometryModule::getItemProperties(flecs::entity id)
|
||||
{
|
||||
OgreAssert(id.is_valid(), "bad id");
|
||||
ZoneScoped;
|
||||
OgreAssert(id.is_valid(), "bad id");
|
||||
return id.get<TerrainItem>().properties;
|
||||
}
|
||||
|
||||
nlohmann::json templates;
|
||||
void StaticGeometryModule::loadTemplates()
|
||||
{
|
||||
ZoneScoped;
|
||||
if (!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(
|
||||
"templates.list"))
|
||||
return;
|
||||
@@ -221,6 +234,7 @@ void StaticGeometryModule::loadTemplates()
|
||||
|
||||
void StaticGeometryModule::saveTemplates()
|
||||
{
|
||||
ZoneScoped;
|
||||
Ogre::String path = "resources/buildings/templates.list";
|
||||
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(
|
||||
"templates.list")) {
|
||||
@@ -243,7 +257,8 @@ void StaticGeometryModule::saveTemplates()
|
||||
|
||||
void StaticGeometryModule::saveItems()
|
||||
{
|
||||
Ogre::String path = "resources/buildings/items.list";
|
||||
ZoneScoped;
|
||||
Ogre::String path = "resources/buildings/items.list";
|
||||
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(
|
||||
"items.list")) {
|
||||
Ogre::String group =
|
||||
@@ -289,7 +304,8 @@ void StaticGeometryModule::saveItems()
|
||||
}
|
||||
void StaticGeometryModule::loadItems()
|
||||
{
|
||||
if (!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(
|
||||
ZoneScoped;
|
||||
if (!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(
|
||||
"items.list"))
|
||||
return;
|
||||
Ogre::String group = Ogre::ResourceGroupManager::getSingleton()
|
||||
@@ -363,6 +379,7 @@ void StaticGeometryModule::saveFurniture()
|
||||
|
||||
void StaticGeometryModule::loadFurniture()
|
||||
{
|
||||
ZoneScoped;
|
||||
ECS::get().delete_with<FurnitureItem>();
|
||||
static std::vector<Ogre::String> glb_names;
|
||||
const std::vector<Ogre::String> &groups =
|
||||
@@ -406,6 +423,7 @@ void StaticGeometryModule::loadFurniture()
|
||||
void StaticGeometryModule::getItemPositionPerSlot(
|
||||
long x, long y, std::list<Ogre::Vector3> *positions)
|
||||
{
|
||||
ZoneScoped;
|
||||
std::pair<long, long> pos{ x, y };
|
||||
if (!positions)
|
||||
return;
|
||||
@@ -426,6 +444,7 @@ void StaticGeometryModule::getItemPositionPerSlot(
|
||||
}
|
||||
void StaticGeometryModule::getItemPositions(std::list<Ogre::Vector3> *positions)
|
||||
{
|
||||
ZoneScoped;
|
||||
ECS::get().query_builder<const TerrainItem>().build().each(
|
||||
[&](flecs::entity e, const TerrainItem &item) {
|
||||
positions->push_back(item.position);
|
||||
@@ -434,12 +453,14 @@ void StaticGeometryModule::getItemPositions(std::list<Ogre::Vector3> *positions)
|
||||
void StaticGeometryModule::getItemPositionAndRotation(
|
||||
flecs::entity e, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
|
||||
{
|
||||
ZoneScoped;
|
||||
position = e.get<TerrainItem>().position;
|
||||
orientation = e.get<TerrainItem>().orientation;
|
||||
}
|
||||
void StaticGeometryModule::getItemsProperties(
|
||||
std::list<std::pair<flecs::entity, Ogre::String> > *items)
|
||||
{
|
||||
ZoneScoped;
|
||||
ECS::get().query_builder<const TerrainItem>().build().each(
|
||||
[&](flecs::entity e, const TerrainItem &item) {
|
||||
items->push_back({ e, item.properties });
|
||||
@@ -447,11 +468,13 @@ void StaticGeometryModule::getItemsProperties(
|
||||
}
|
||||
void StaticGeometryModule::createItemGeometry(flecs::entity e)
|
||||
{
|
||||
ZoneScoped;
|
||||
Geometry::createItemGeometry(e);
|
||||
}
|
||||
|
||||
void StaticGeometryModule::destroyItemGeometry(flecs::entity e)
|
||||
{
|
||||
ZoneScoped;
|
||||
Geometry::destroyItemGeometry(e);
|
||||
}
|
||||
|
||||
@@ -462,6 +485,7 @@ nlohmann::json &StaticGeometryModule::getTemplates()
|
||||
|
||||
void StaticGeometryModule::updateItemGeometry(flecs::entity e)
|
||||
{
|
||||
ZoneScoped;
|
||||
// We add this as task to reduce UI load
|
||||
Ogre::Root::getSingleton().getWorkQueue()->addMainThreadTask([e]() {
|
||||
ZoneScopedN("updateItemGeometry");
|
||||
@@ -478,6 +502,7 @@ void StaticGeometryModule::addTriangleBufferWork(
|
||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
|
||||
const Procedural::TriangleBuffer &tb)
|
||||
{
|
||||
ZoneScoped;
|
||||
struct WorkData {
|
||||
Ogre::String meshName;
|
||||
Ogre::StaticGeometry *geo;
|
||||
|
||||
Reference in New Issue
Block a user