Adapted more debugging with Tracy, characters update

This commit is contained in:
2026-02-13 18:14:09 +03:00
parent 71b7f47bcd
commit a85152a675
23 changed files with 814 additions and 133 deletions

View File

@@ -18,6 +18,7 @@
#include "PhysicsModule.h"
#include "StaticGeometryModule.h"
#include "TerrainModule.h"
#include <tracy/Tracy.hpp>
#define TERRAIN_SIZE 65
#define TERRAIN_WORLD_SIZE 500.0f
@@ -48,6 +49,7 @@ struct HeightData {
static HeightData *singleton;
HeightData()
{
ZoneScoped;
img.load(
"world_map.png",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
@@ -60,13 +62,15 @@ struct HeightData {
}
static HeightData *get_singleton()
{
if (!singleton)
ZoneScoped;
if (!singleton)
singleton = new HeightData();
return singleton;
}
float get_brush_height(int id, int x, int y)
{
int m = 0;
ZoneScoped;
int m = 0;
switch (id) {
case 0:
m = 0;
@@ -110,7 +114,8 @@ struct HeightData {
}
void save_heightmap()
{
Ogre::String group =
ZoneScoped;
Ogre::String group =
Ogre::ResourceGroupManager::getSingleton()
.findGroupContainingResource("world_map.png");
Ogre::FileInfoListPtr fileInfoList(
@@ -125,7 +130,7 @@ struct HeightData {
}
float get_base_height(long world_x, long world_y)
{
float height = 0.0f;
float height = 0.0f;
int world_img_x =
world_x + (int)img.getWidth() * BRUSH_SIZE / 2;
int world_img_y =
@@ -155,7 +160,7 @@ out:
}
float get_noise_height(long world_x, long world_y)
{
int h;
int h;
Ogre::Vector2 noisePoint;
struct noise_types {
@@ -192,7 +197,7 @@ out:
float get_height(Ogre::TerrainGroup *terrainGroup, long world_x,
long world_y)
{
long grid_center_x = img.getWidth() * BRUSH_SIZE / 2;
long grid_center_x = img.getWidth() * BRUSH_SIZE / 2;
long grid_center_y = img.getHeight() * BRUSH_SIZE / 2;
long world_grid_x = world_x + grid_center_x;
long world_grid_y = world_y + grid_center_y;
@@ -265,6 +270,7 @@ public:
void createTerrainChunk(Ogre::TerrainGroup *terrainGroup, long x,
long y)
{
ZoneScoped;
Ogre::Terrain *terrain = terrainGroup->getTerrain(x, y);
float minH = terrain->getMinHeight();
float maxH = terrain->getMaxHeight();
@@ -290,7 +296,8 @@ public:
}
void define(Ogre::TerrainGroup *terrainGroup, long x, long y) override
{
std::lock_guard<std::mutex> guard(mtx);
ZoneScoped;
std::lock_guard<std::mutex> guard(mtx);
uint16_t terrainSize = terrainGroup->getTerrainSize();
float *heightMap = OGRE_ALLOC_T(float, terrainSize *terrainSize,
MEMCATEGORY_GEOMETRY);
@@ -332,13 +339,15 @@ public:
}
bool frameStarted(const Ogre::FrameEvent &evt) override
{
(void)evt;
ZoneScoped;
(void)evt;
update();
return true;
}
void update()
{
std::lock_guard<std::mutex> guard(mtx);
ZoneScoped;
std::lock_guard<std::mutex> guard(mtx);
static bool created = false;
while (!collider_queue.empty()) {
Ogre::TerrainGroup *group =
@@ -478,7 +487,8 @@ public:
bool unloadProceduralPage(Ogre::Page *page,
Ogre::PagedWorldSection *section)
{
long x, y;
ZoneScoped;
long x, y;
ECS::get<Terrain>().mTerrainGroup->unpackIndex(page->CHUNK_ID,
&x, &y);
StaticGeometryModule::removeGeometryForSlot(x, y);
@@ -492,7 +502,8 @@ public:
};
TerrainModule::TerrainModule(flecs::world &ecs)
{
struct CanSetPlayerPosition {};
ZoneScoped;
struct CanSetPlayerPosition {};
ecs.module<TerrainModule>();
ecs.component<CanSetPlayerPosition>().add(flecs::Singleton);
ecs.component<Terrain>().add(flecs::Singleton);
@@ -509,7 +520,8 @@ TerrainModule::TerrainModule(flecs::world &ecs)
.each([](const EngineData &eng, const Camera &camera,
const Sun &sun, Terrain &terrain,
TerrainPrivate &priv) {
if (!terrain.mTerrainGroup && sun.mSun && eng.mScnMgr) {
ZoneScoped;
if (!terrain.mTerrainGroup && sun.mSun && eng.mScnMgr) {
std::cout << "Terrain setup\n";
if (!priv.mDummyPageProvider)
priv.mDummyPageProvider =
@@ -635,7 +647,8 @@ TerrainModule::TerrainModule(flecs::world &ecs)
.kind(flecs::OnUpdate)
.without<TerrainReady>()
.each([](const ECS::Camera &cam, const Terrain &terrain) {
std::cout << "mTerrainReady: " << terrain.mTerrainReady
ZoneScoped;
std::cout << "mTerrainReady: " << terrain.mTerrainReady
<< "\n";
if (cam.mCameraNode && terrain.mTerrainReady) {
long x, y;
@@ -653,7 +666,8 @@ TerrainModule::TerrainModule(flecs::world &ecs)
ecs.system<const Terrain, PlacementObjects>("UpdatePlacementObjects")
.kind(flecs::OnUpdate)
.each([](const Terrain &terrain, PlacementObjects &placement) {
if (placement.altar_items.size() == 0) {
ZoneScoped;
if (placement.altar_items.size() == 0) {
struct PlacementObjects::item item;
int i, j;
int worldSize = terrain.mTerrainGroup
@@ -766,7 +780,8 @@ TerrainModule::TerrainModule(flecs::world &ecs)
.kind(flecs::OnUpdate)
.interval(2.0f)
.each([](const Terrain &terrain) {
if (!terrain.mTerrainGroup
ZoneScoped;
if (!terrain.mTerrainGroup
->isDerivedDataUpdateInProgress())
terrain.mTerrainGroup->update(false);
});