Submit cached map-object draws by pointer instead of copying

MapObjectManager::AppendDrawRefs references each visible object's cached
Render3DDraw (writing the per-frame light into the cache) rather than
copying the whole command (two texture strings, shared_ptrs, matrices)
every frame. main.cpp flattens owned draws and refs in submission order
(FlattenDraws) and passes a pointer list to RenderSceneGPU/RenderScene.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 17:09:45 +09:00
co-authored by Claude Opus 5.5
parent b5a15871f4
commit 46880be537
9 changed files with 89 additions and 12 deletions
+14 -2
View File
@@ -374,7 +374,16 @@ bool MapObjectManager::CheckCollisionNormal(float worldX, float worldZ, float ac
}
std::vector<Render3DDraw> MapObjectManager::BuildDrawCommands(const float* view, const float* proj) const {
std::vector<Render3DDrawRef> refs;
AppendDrawRefs(view, proj, 0, refs);
std::vector<Render3DDraw> all_draws;
all_draws.reserve(refs.size());
for (const auto& ref : refs) all_draws.push_back(*ref.draw);
return all_draws;
}
void MapObjectManager::AppendDrawRefs(const float* view, const float* proj, std::size_t before, std::vector<Render3DDrawRef>& out,
const float* light_direction, const float* light_ambient) const {
for (const auto& obj : m_objects) {
if (!obj.model) continue;
@@ -404,9 +413,12 @@ std::vector<Render3DDraw> MapObjectManager::BuildDrawCommands(const float* view,
obj.draws_cached = true;
}
if (!IsBoundsVisible(obj.bounds_min, obj.bounds_max, view, proj)) continue;
all_draws.insert(all_draws.end(), obj.cached_draws.begin(), obj.cached_draws.end());
for (auto& draw : obj.cached_draws) {
if (light_direction) std::copy_n(light_direction, 3, draw.light_direction);
if (light_ambient) std::copy_n(light_ambient, 3, draw.light_ambient);
out.push_back({before, &draw});
}
}
return all_draws;
}
void MapObjectManager::ClearObjects() {