LCOV - code coverage report
Current view: top level - src - clientmap.h (source / functions) Hit Total Coverage
Test: report Lines: 22 22 100.0 %
Date: 2015-07-11 18:23:49 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             : Minetest
       3             : Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
       4             : 
       5             : This program is free software; you can redistribute it and/or modify
       6             : it under the terms of the GNU Lesser General Public License as published by
       7             : the Free Software Foundation; either version 2.1 of the License, or
       8             : (at your option) any later version.
       9             : 
      10             : This program is distributed in the hope that it will be useful,
      11             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             : GNU Lesser General Public License for more details.
      14             : 
      15             : You should have received a copy of the GNU Lesser General Public License along
      16             : with this program; if not, write to the Free Software Foundation, Inc.,
      17             : 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             : */
      19             : 
      20             : #ifndef CLIENTMAP_HEADER
      21             : #define CLIENTMAP_HEADER
      22             : 
      23             : #include "irrlichttypes_extrabloated.h"
      24             : #include "map.h"
      25             : #include "camera.h"
      26             : #include <set>
      27             : #include <map>
      28             : 
      29             : struct MapDrawControl
      30             : {
      31           1 :         MapDrawControl():
      32             :                 range_all(false),
      33             :                 wanted_range(50),
      34             :                 wanted_max_blocks(0),
      35             :                 wanted_min_range(0),
      36             :                 blocks_drawn(0),
      37             :                 blocks_would_have_drawn(0),
      38           1 :                 farthest_drawn(0)
      39             :         {
      40           1 :         }
      41             :         // Overrides limits by drawing everything
      42             :         bool range_all;
      43             :         // Wanted drawing range
      44             :         float wanted_range;
      45             :         // Maximum number of blocks to draw
      46             :         u32 wanted_max_blocks;
      47             :         // Blocks in this range are drawn regardless of number of blocks drawn
      48             :         float wanted_min_range;
      49             :         // Number of blocks rendered is written here by the renderer
      50             :         u32 blocks_drawn;
      51             :         // Number of blocks that would have been drawn in wanted_range
      52             :         u32 blocks_would_have_drawn;
      53             :         // Distance to the farthest block drawn
      54             :         float farthest_drawn;
      55             : };
      56             : 
      57             : class Client;
      58             : class ITextureSource;
      59             : 
      60             : /*
      61             :         ClientMap
      62             :         
      63             :         This is the only map class that is able to render itself on screen.
      64             : */
      65             : 
      66             : class ClientMap : public Map, public scene::ISceneNode
      67             : {
      68             : public:
      69             :         ClientMap(
      70             :                         Client *client,
      71             :                         IGameDef *gamedef,
      72             :                         MapDrawControl &control,
      73             :                         scene::ISceneNode* parent,
      74             :                         scene::ISceneManager* mgr,
      75             :                         s32 id
      76             :         );
      77             : 
      78             :         ~ClientMap();
      79             : 
      80           6 :         s32 mapType() const
      81             :         {
      82           6 :                 return MAPTYPE_CLIENT;
      83             :         }
      84             : 
      85           1 :         void drop()
      86             :         {
      87           1 :                 ISceneNode::drop();
      88           1 :         }
      89             : 
      90        1166 :         void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset)
      91             :         {
      92        2332 :                 JMutexAutoLock lock(m_camera_mutex);
      93        1166 :                 m_camera_position = pos;
      94        1166 :                 m_camera_direction = dir;
      95        1166 :                 m_camera_fov = fov;
      96        1166 :                 m_camera_offset = offset;
      97        1166 :         }
      98             : 
      99             :         /*
     100             :                 Forcefully get a sector from somewhere
     101             :         */
     102             :         MapSector * emergeSector(v2s16 p);
     103             : 
     104             :         //void deSerializeSector(v2s16 p2d, std::istream &is);
     105             : 
     106             :         /*
     107             :                 ISceneNode methods
     108             :         */
     109             : 
     110             :         virtual void OnRegisterSceneNode();
     111             : 
     112        2332 :         virtual void render()
     113             :         {
     114        2332 :                 video::IVideoDriver* driver = SceneManager->getVideoDriver();
     115        2332 :                 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
     116        2332 :                 renderMap(driver, SceneManager->getSceneNodeRenderPass());
     117        2332 :         }
     118             :         
     119        2332 :         virtual const core::aabbox3d<f32>& getBoundingBox() const
     120             :         {
     121        2332 :                 return m_box;
     122             :         }
     123             :         
     124             :         void updateDrawList(video::IVideoDriver* driver);
     125             :         void renderMap(video::IVideoDriver* driver, s32 pass);
     126             : 
     127             :         int getBackgroundBrightness(float max_d, u32 daylight_factor,
     128             :                         int oldvalue, bool *sunlight_seen_result);
     129             : 
     130             :         void renderPostFx(CameraMode cam_mode);
     131             : 
     132             :         // For debug printing
     133             :         virtual void PrintInfo(std::ostream &out);
     134             :         
     135             :         // Check if sector was drawn on last render()
     136             :         bool sectorWasDrawn(v2s16 p)
     137             :         {
     138             :                 return (m_last_drawn_sectors.find(p) != m_last_drawn_sectors.end());
     139             :         }
     140             :         
     141             : private:
     142             :         Client *m_client;
     143             :         
     144             :         core::aabbox3d<f32> m_box;
     145             :         
     146             :         MapDrawControl &m_control;
     147             : 
     148             :         v3f m_camera_position;
     149             :         v3f m_camera_direction;
     150             :         f32 m_camera_fov;
     151             :         v3s16 m_camera_offset;
     152             :         JMutex m_camera_mutex;
     153             : 
     154             :         std::map<v3s16, MapBlock*> m_drawlist;
     155             :         
     156             :         std::set<v2s16> m_last_drawn_sectors;
     157             : 
     158             :         bool m_cache_trilinear_filter;
     159             :         bool m_cache_bilinear_filter;
     160             :         bool m_cache_anistropic_filter;
     161             : };
     162             : 
     163             : #endif
     164             : 

Generated by: LCOV version 1.11