diff options
Diffstat (limited to 'src/client/clientmap.h')
-rw-r--r-- | src/client/clientmap.h | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/client/clientmap.h b/src/client/clientmap.h index 57cc4427e..b4dc42395 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -68,6 +68,7 @@ class ClientMap : public Map, public scene::ISceneNode public: ClientMap( Client *client, + RenderingEngine *rendering_engine, MapDrawControl &control, s32 id ); @@ -86,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; } /* @@ -118,10 +127,16 @@ public: } void getBlocksInViewRange(v3s16 cam_pos_nodes, - v3s16 *p_blocks_min, v3s16 *p_blocks_max); + 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, + const video::SMaterial &material, s32 pass, int frame, int total_frames); + int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result); @@ -131,9 +146,29 @@ public: virtual void PrintInfo(std::ostream &out); const MapDrawControl & getControl() const { return m_control; } + f32 getWantedRange() const { return m_control.wanted_range; } 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; aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000, BS * 1000000, BS * 1000000, BS * 1000000); @@ -145,11 +180,14 @@ 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; bool m_cache_trilinear_filter; bool m_cache_bilinear_filter; bool m_cache_anistropic_filter; + bool m_added_to_shadow_renderer{false}; }; |