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
+13 -2
View File
@@ -632,7 +632,8 @@ void CPythonBackground::RenderCharacterShadowToTexture() {
void CPythonBackground::RenderSnow() {
}
void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws) {
void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws,
std::vector<Render3DDrawRef>* outRefs) {
if (!IsMapReady()) return;
if (m_bVisiblePart[PART_SKY] && m_skybox && viewMatrix && projMatrix && camPos) {
@@ -675,7 +676,17 @@ void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float*
outDraws.push_back(std::move(wd));
}
if (m_bVisiblePart[PART_OBJECT] && m_mapObjects) {
if (m_bVisiblePart[PART_OBJECT] && m_mapObjects && outRefs) {
float lightDir[3], lightAmbient[3];
if (m_pCurrentEnvironment) {
std::copy_n(m_pCurrentEnvironment->dir_light.direction, 3, lightDir);
lightAmbient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
lightAmbient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
lightAmbient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
}
m_mapObjects->AppendDrawRefs(viewMatrix, projMatrix, outDraws.size(), *outRefs,
m_pCurrentEnvironment ? lightDir : nullptr, m_pCurrentEnvironment ? lightAmbient : nullptr);
} else if (m_bVisiblePart[PART_OBJECT] && m_mapObjects) {
auto bdraws = m_mapObjects->BuildDrawCommands(viewMatrix, projMatrix);
for (auto& bd : bdraws) {
if (m_pCurrentEnvironment) {
+3 -1
View File
@@ -205,7 +205,9 @@ public:
SpeedTreeForest* GetForest() { return m_forest.get(); }
const OutdoorMapInfo* GetOutdoorMap() const { return m_strMapName.empty() ? nullptr : &m_outdoorMap; }
void BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws);
// outRefs (optional) receives the cached map-object commands by pointer instead of copies in outDraws.
void BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws,
std::vector<Render3DDrawRef>* outRefs = nullptr);
private:
void LoadAtlas();