aboutsummaryrefslogtreecommitdiff
path: root/src/client/clientmap.h
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
commit21df26984da91143c15587f5a03c98d68c3adc4e (patch)
treeaaa707a628ad331f67890023dffe1b4f60dd01d3 /src/client/clientmap.h
parentb09fc5de5cdb021f43ad32b7e3f50dc75c0bc622 (diff)
parenteabf05758e3ba5f6f4bb1b8d1d1f02179b84e410 (diff)
downloaddragonfireclient-21df26984da91143c15587f5a03c98d68c3adc4e.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'src/client/clientmap.h')
-rw-r--r--src/client/clientmap.h79
1 files changed, 59 insertions, 20 deletions
diff --git a/src/client/clientmap.h b/src/client/clientmap.h
index 97ce8d355..6d57f1911 100644
--- a/src/client/clientmap.h
+++ b/src/client/clientmap.h
@@ -56,6 +56,7 @@ struct MeshBufListList
class Client;
class ITextureSource;
+class PartialMeshBuffer;
/*
ClientMap
@@ -75,45 +76,37 @@ public:
virtual ~ClientMap() = default;
- s32 mapType() const
+ bool maySaveBlocks() override
{
- return MAPTYPE_CLIENT;
+ return false;
}
- void drop()
+ void drop() override
{
- ISceneNode::drop();
+ ISceneNode::drop(); // calls destructor
}
- void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset)
- {
- m_camera_position = pos;
- m_camera_direction = dir;
- m_camera_fov = fov;
- m_camera_offset = offset;
- }
+ void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset);
/*
Forcefully get a sector from somewhere
*/
- MapSector * emergeSector(v2s16 p);
-
- //void deSerializeSector(v2s16 p2d, std::istream &is);
+ MapSector * emergeSector(v2s16 p) override;
/*
ISceneNode methods
*/
- virtual void OnRegisterSceneNode();
+ virtual void OnRegisterSceneNode() override;
- virtual void render()
+ virtual void render() override
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
renderMap(driver, SceneManager->getSceneNodeRenderPass());
}
- virtual const aabb3f &getBoundingBox() const
+ virtual const aabb3f &getBoundingBox() const override
{
return m_box;
}
@@ -121,7 +114,9 @@ public:
void getBlocksInViewRange(v3s16 cam_pos_nodes,
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);
+ void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length);
+ // 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,
@@ -133,13 +128,54 @@ public:
void renderPostFx(CameraMode cam_mode);
// For debug printing
- virtual void PrintInfo(std::ostream &out);
+ void PrintInfo(std::ostream &out) override;
const MapDrawControl & getControl() const { return m_control; }
f32 getWantedRange() const { return m_control.wanted_range; }
f32 getCameraFov() const { return m_camera_fov; }
private:
+
+ // update the vertex order in transparent mesh buffers
+ void updateTransparentMeshBuffers();
+
+ // 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;
+ };
+
+
+ // reference to a mesh buffer used when rendering the map.
+ struct DrawDescriptor {
+ v3s16 m_pos;
+ union {
+ scene::IMeshBuffer *m_buffer;
+ const PartialMeshBuffer *m_partial_buffer;
+ };
+ bool m_reuse_material:1;
+ bool m_use_partial_buffer:1;
+
+ DrawDescriptor(v3s16 pos, scene::IMeshBuffer *buffer, bool reuse_material) :
+ m_pos(pos), m_buffer(buffer), m_reuse_material(reuse_material), m_use_partial_buffer(false)
+ {}
+
+ DrawDescriptor(v3s16 pos, const PartialMeshBuffer *buffer) :
+ m_pos(pos), m_partial_buffer(buffer), m_reuse_material(false), m_use_partial_buffer(true)
+ {}
+ };
+
Client *m_client;
RenderingEngine *m_rendering_engine;
@@ -152,9 +188,11 @@ private:
v3f m_camera_direction = v3f(0,0,1);
f32 m_camera_fov = M_PI;
v3s16 m_camera_offset;
+ bool m_needs_update_transparent_meshes = true;
- 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;
@@ -162,4 +200,5 @@ private:
bool m_cache_bilinear_filter;
bool m_cache_anistropic_filter;
bool m_added_to_shadow_renderer{false};
+ u16 m_cache_transparency_sorting_distance;
};