]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Minor clientmap improvements.
authorLars <larsh@apache.org>
Sun, 18 Oct 2020 23:38:51 +0000 (16:38 -0700)
committerlhofhansl <larsh@apache.org>
Mon, 19 Oct 2020 16:31:09 +0000 (09:31 -0700)
- Avoid calculating isBlockInSight for blocks without meshes.
- Add metric for how many blocks the client has currently loaded.
- Make some variables constant.

src/client/clientmap.cpp
src/mapsector.h

index d372a8e46c0997851e2ba4bbf2b1aa9db5012fae..c8561def6e6dc5982f4853d117b61bbed4de8a3b 100644 (file)
@@ -122,14 +122,17 @@ void ClientMap::updateDrawList()
        }
        m_drawlist.clear();
 
-       v3f camera_position = m_camera_position;
-       v3f camera_direction = m_camera_direction;
+       const v3f camera_position = m_camera_position;
+       const v3f camera_direction = m_camera_direction;
+       const f32 camera_fov = m_camera_fov;
 
        v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
        v3s16 p_blocks_min;
        v3s16 p_blocks_max;
        getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
 
+       // Number of blocks currently loaded by the client
+       u32 blocks_loaded = 0;
        // Number of blocks with mesh in rendering range
        u32 blocks_in_range_with_mesh = 0;
        // Number of blocks occlusion culled
@@ -154,6 +157,7 @@ void ClientMap::updateDrawList()
                MapSector *sector = sector_it.second;
                v2s16 sp = sector->getPos();
 
+               blocks_loaded += sector->size();
                if (!m_control.range_all) {
                        if (sp.X < p_blocks_min.X || sp.X > p_blocks_max.X ||
                                        sp.Y < p_blocks_min.Z || sp.Y > p_blocks_max.Z)
@@ -175,8 +179,12 @@ void ClientMap::updateDrawList()
                                if not seen on display
                        */
 
-                       if (block->mesh)
+                       if (block->mesh) {
                                block->mesh->updateCameraOffset(m_camera_offset);
+                       } else {
+                               // Ignore if mesh doesn't exist
+                               continue;
+                       }
 
                        float range = 100000 * BS;
                        if (!m_control.range_all)
@@ -184,14 +192,7 @@ void ClientMap::updateDrawList()
 
                        float d = 0.0;
                        if (!isBlockInSight(block->getPos(), camera_position,
-                                       camera_direction, m_camera_fov, range, &d))
-                               continue;
-
-
-                       /*
-                               Ignore if mesh doesn't exist
-                       */
-                       if (!block->mesh)
+                                       camera_direction, camera_fov, range, &d))
                                continue;
 
                        blocks_in_range_with_mesh++;
@@ -222,6 +223,7 @@ void ClientMap::updateDrawList()
        g_profiler->avg("MapBlock meshes in range [#]", blocks_in_range_with_mesh);
        g_profiler->avg("MapBlocks occlusion culled [#]", blocks_occlusion_culled);
        g_profiler->avg("MapBlocks drawn [#]", m_drawlist.size());
+       g_profiler->avg("MapBlocks loaded [#]", blocks_loaded);
 }
 
 struct MeshBufList
@@ -287,13 +289,13 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
        /*
                Get animation parameters
        */
-       float animation_time = m_client->getAnimationTime();
-       int crack = m_client->getCrackLevel();
-       u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
+       const float animation_time = m_client->getAnimationTime();
+       const int crack = m_client->getCrackLevel();
+       const u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
 
-       v3f camera_position = m_camera_position;
-       v3f camera_direction = m_camera_direction;
-       f32 camera_fov = m_camera_fov;
+       const v3f camera_position = m_camera_position;
+       const v3f camera_direction = m_camera_direction;
+       const f32 camera_fov = m_camera_fov;
 
        /*
                Get all blocks and draw all visible ones
index dede364f6fe1f41a046210c36d336abf69ba25f2..ffd4cdd1daa142b48634661dc4dd164a714a9fc9 100644 (file)
@@ -62,6 +62,7 @@ class MapSector
 
        bool empty() const { return m_blocks.empty(); }
 
+       int size() const { return m_blocks.size(); }
 protected:
 
        // The pile of MapBlocks