mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Order drawlist by distance to the camera when rendering (#11651)
This commit is contained in:
parent
d51d0f3a5a
commit
f5040707fe
3 changed files with 105 additions and 30 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue