Skip map objects beyond the AVA2 object loading distance
AVA2 builds with ENABLE_MAP_OBJECT_OPTIMIZATION: CArea:: __UpdateLoadedObjectInstances unloads objects whose 2D distance from the main actor is at least max(OBJECT_DIST, 5000). CPythonBackground::Update now takes the main actor position (as CPythonApplication passes it) and sets that loading center on MapObjectManager, which skips farther objects before their frustum test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
46880be537
commit
b57f2fba99
+1
-1
@@ -2023,7 +2023,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
#ifdef AVA2_HAS_PYTHON
|
||||
bool bg_rendered = false;
|
||||
if (ava2::CPythonBackground::Instance().IsMapReady()) {
|
||||
ava2::CPythonBackground::Instance().Update(eyeX, eyeY, eyeZ);
|
||||
ava2::CPythonBackground::Instance().Update(player_world_x, player_world_y, player_world_z);
|
||||
float camPos[3] = {eyeX, eyeY, eyeZ};
|
||||
ava2::CPythonBackground::Instance().BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), camPos, draws, &draw_refs);
|
||||
bg_rendered = true;
|
||||
|
||||
@@ -386,6 +386,10 @@ void MapObjectManager::AppendDrawRefs(const float* view, const float* proj, std:
|
||||
const float* light_direction, const float* light_ambient) const {
|
||||
for (const auto& obj : m_objects) {
|
||||
if (!obj.model) continue;
|
||||
if (m_maxDistanceSq > 0.0f) {
|
||||
const float dx = obj.x - m_centerX, dz = obj.z - m_centerZ;
|
||||
if (dx * dx + dz * dz >= m_maxDistanceSq) continue;
|
||||
}
|
||||
|
||||
float world[16];
|
||||
MakeFullTransformMatrix(obj.yaw, obj.pitch, obj.roll, obj.x, obj.y, obj.z, obj.scale, world);
|
||||
|
||||
@@ -149,6 +149,9 @@ public:
|
||||
size_t GetCachedModelCount() const { return m_model_cache.size(); }
|
||||
|
||||
const std::vector<MapObjectInstance>& GetObjects() const { return m_objects; }
|
||||
// CArea::__UpdateLoadedObjectInstances (ENABLE_MAP_OBJECT_OPTIMIZATION): objects farther than
|
||||
// maxDistance (2D, from the main actor) are not drawn. maxDistance <= 0 draws everything.
|
||||
void SetLoadingCenter(float x, float z, float maxDistance) { m_centerX = x; m_centerZ = z; m_maxDistanceSq = maxDistance > 0.0f ? maxDistance * maxDistance : 0.0f; }
|
||||
|
||||
private:
|
||||
const std::vector<size_t>& CollisionCandidates(float x,float z,float radius) const;
|
||||
@@ -162,6 +165,7 @@ private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Gr2ModelInstance>> m_model_cache;
|
||||
mutable std::unordered_map<const Gr2ModelInstance*,std::vector<std::shared_ptr<const Render3DDraw>>> m_meshStreams;
|
||||
std::vector<MapObjectInstance> m_objects;
|
||||
float m_centerX = 0.0f, m_centerZ = 0.0f, m_maxDistanceSq = 0.0f;
|
||||
};
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -589,8 +589,12 @@ void CPythonBackground::DeleteSpecialEffect(uint32_t dwID) {
|
||||
(void)dwID;
|
||||
}
|
||||
|
||||
void CPythonBackground::Update(float fCameraX, float fCameraY, float fCameraZ) {
|
||||
(void)fCameraX; (void)fCameraY; (void)fCameraZ;
|
||||
void CPythonBackground::Update(float fCenterX, float fCenterY, float fCenterZ) {
|
||||
(void)fCenterY;
|
||||
if (m_mapObjects) {
|
||||
// CArea::GetMaxLoadingDistanceSqr: OBJECT_DIST, never under 5000.
|
||||
m_mapObjects->SetLoadingCenter(fCenterX, fCenterZ, std::max(5000.0f, CPythonSystem::Instance().GetObjectDistance()));
|
||||
}
|
||||
if (m_skybox) {
|
||||
m_skybox->Update(0.033f);
|
||||
}
|
||||
|
||||
@@ -184,7 +184,8 @@ public:
|
||||
void CreateSpecialEffect(uint32_t dwID, float fx, float fy, float fz, const char* szFileName);
|
||||
void DeleteSpecialEffect(uint32_t dwID);
|
||||
|
||||
void Update(float fCameraX, float fCameraY, float fCameraZ);
|
||||
// Original CPythonApplication passes the main actor position (map-object loading center).
|
||||
void Update(float fCenterX, float fCenterY, float fCenterZ);
|
||||
|
||||
void Render();
|
||||
void RenderSky();
|
||||
|
||||
Reference in New Issue
Block a user