aboutsummaryrefslogtreecommitdiff
path: root/src/client/clientmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/clientmap.h')
-rw-r--r--src/client/clientmap.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/client/clientmap.h b/src/client/clientmap.h
index 97ce8d355..b4dc42395 100644
--- a/src/client/clientmap.h
+++ b/src/client/clientmap.h
@@ -87,10 +87,18 @@ public:
void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset)
{
+ v3s16 previous_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE);
+
m_camera_position = pos;
m_camera_direction = dir;
m_camera_fov = fov;
m_camera_offset = offset;
+
+ v3s16 current_block = getContainerPos(floatToInt(m_camera_position, BS) + m_camera_offset, MAP_BLOCKSIZE);
+
+ // reorder the blocks when camera crosses block boundary
+ if (previous_block != current_block)
+ m_needs_update_drawlist = true;
}
/*
@@ -122,6 +130,8 @@ public:
v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f);
void updateDrawList();
void updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range);
+ // Returns true if draw list needs updating before drawing the next frame.
+ bool needsUpdateDrawList() { return m_needs_update_drawlist; }
void renderMap(video::IVideoDriver* driver, s32 pass);
void renderMapShadows(video::IVideoDriver *driver,
@@ -140,6 +150,23 @@ public:
f32 getCameraFov() const { return m_camera_fov; }
private:
+ // Orders blocks by distance to the camera
+ class MapBlockComparer
+ {
+ public:
+ MapBlockComparer(const v3s16 &camera_block) : m_camera_block(camera_block) {}
+
+ bool operator() (const v3s16 &left, const v3s16 &right) const
+ {
+ auto distance_left = left.getDistanceFromSQ(m_camera_block);
+ auto distance_right = right.getDistanceFromSQ(m_camera_block);
+ return distance_left > distance_right || (distance_left == distance_right && left > right);
+ }
+
+ private:
+ v3s16 m_camera_block;
+ };
+
Client *m_client;
RenderingEngine *m_rendering_engine;
@@ -153,8 +180,9 @@ private:
f32 m_camera_fov = M_PI;
v3s16 m_camera_offset;
- std::map<v3s16, MapBlock*> m_drawlist;
+ std::map<v3s16, MapBlock*, MapBlockComparer> m_drawlist;
std::map<v3s16, MapBlock*> m_drawlist_shadow;
+ bool m_needs_update_drawlist;
std::set<v2s16> m_last_drawn_sectors;