#include "common_irrlicht.h"
#include "heightmap.h"
-#include "loadstatus.h"
#include "mapnode.h"
#include "mapblock.h"
#include "mapsector.h"
#include "constants.h"
#include "voxel.h"
-class Map;
-
-/*
- A cache for short-term fast access to map data
-
- NOTE: This doesn't really make anything more efficient
- NOTE: Use VoxelManipulator, if possible
- TODO: Get rid of this?
- NOTE: CONFIRMED: THIS CACHE DOESN'T MAKE ANYTHING ANY FASTER
-*/
-class MapBlockPointerCache : public NodeContainer
-{
-public:
- MapBlockPointerCache(Map *map);
- ~MapBlockPointerCache();
-
- virtual u16 nodeContainerId() const
- {
- return NODECONTAINER_ID_MAPBLOCKCACHE;
- }
-
- MapBlock * getBlockNoCreate(v3s16 p);
-
- // virtual from NodeContainer
- bool isValidPosition(v3s16 p)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- MapBlock *blockref;
- try{
- blockref = getBlockNoCreate(blockpos);
- }
- catch(InvalidPositionException &e)
- {
- return false;
- }
- return true;
- }
-
- // virtual from NodeContainer
- MapNode getNode(v3s16 p)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- MapBlock * blockref = getBlockNoCreate(blockpos);
- v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
-
- return blockref->getNodeNoCheck(relpos);
- }
-
- // virtual from NodeContainer
- void setNode(v3s16 p, MapNode & n)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- MapBlock * block = getBlockNoCreate(blockpos);
- v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- block->setNodeNoCheck(relpos, n);
- m_modified_blocks[blockpos] = block;
- }
-
- core::map<v3s16, MapBlock*> m_modified_blocks;
-
-private:
- Map *m_map;
- core::map<v3s16, MapBlock*> m_blocks;
-
- u32 m_from_cache_count;
- u32 m_from_map_count;
-};
-
class CacheLock
{
public:
Used by MapBlockPointerCache.
waitCaches() can be called to remove all caches before continuing
+
+ TODO: Remove this, MapBlockPointerCache doesn't exist anymore,
+ because it doesn't give any speed benefits
*/
CacheLock m_blockcachelock;
return MAPTYPE_BASE;
}
+ virtual void drop()
+ {
+ delete this;
+ }
+
void updateCamera(v3f pos, v3f dir)
{
JMutexAutoLock lock(m_camera_mutex);
// Returns InvalidPositionException if not found
MapBlock * getBlockNoCreate(v3s16 p);
- //virtual MapBlock * getBlock(v3s16 p, bool generate=true);
+ // Returns NULL if not found
+ MapBlock * getBlockNoCreateNoEx(v3s16 p);
// Returns InvalidPositionException if not found
f32 getGroundHeight(v2s16 p, bool generate=false);
}
// virtual from NodeContainer
+ // throws InvalidPositionException if not found
MapNode getNode(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
}
// virtual from NodeContainer
+ // throws InvalidPositionException if not found
void setNode(v3s16 p, MapNode & n)
{
v3s16 blockpos = getNodeBlockPos(p);
blockref->setNode(relpos, n);
}*/
- void unspreadLight(core::map<v3s16, u8> & from_nodes,
+ void unspreadLight(enum LightBank bank,
+ core::map<v3s16, u8> & from_nodes,
core::map<v3s16, bool> & light_sources,
core::map<v3s16, MapBlock*> & modified_blocks);
- void unLightNeighbors(v3s16 pos, u8 lightwas,
+ void unLightNeighbors(enum LightBank bank,
+ v3s16 pos, u8 lightwas,
core::map<v3s16, bool> & light_sources,
core::map<v3s16, MapBlock*> & modified_blocks);
- void spreadLight(core::map<v3s16, bool> & from_nodes,
+ void spreadLight(enum LightBank bank,
+ core::map<v3s16, bool> & from_nodes,
core::map<v3s16, MapBlock*> & modified_blocks);
- void lightNeighbors(v3s16 pos,
+ void lightNeighbors(enum LightBank bank,
+ v3s16 pos,
core::map<v3s16, MapBlock*> & modified_blocks);
- v3s16 getBrightestNeighbour(v3s16 p);
+ v3s16 getBrightestNeighbour(enum LightBank bank, v3s16 p);
s16 propagateSunlight(v3s16 start,
core::map<v3s16, MapBlock*> & modified_blocks);
+ void updateLighting(enum LightBank bank,
+ core::map<v3s16, MapBlock*> & a_blocks,
+ core::map<v3s16, MapBlock*> & modified_blocks);
+
void updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
core::map<v3s16, MapBlock*> & modified_blocks);
void removeNodeAndUpdate(v3s16 p,
core::map<v3s16, MapBlock*> &modified_blocks);
+#ifndef SERVER
+ void expireMeshes(bool only_daynight_diffed);
+
/*
Updates the faces of the given block and blocks on the
leading edge.
*/
- void updateMeshes(v3s16 blockpos);
+ void updateMeshes(v3s16 blockpos, u32 daynight_ratio);
+#endif
+
+ /*
+ Takes the blocks at the edges into account
+ */
+ bool dayNightDiffed(v3s16 blockpos);
//core::aabbox3d<s16> getDisplayedBlockArea();
//u16 max_objects_in_block;
};
+/*
+ ServerMap
+
+ This is the only map class that is able to generate map.
+*/
+
class ServerMap : public Map
{
public:
virtual void PrintInfo(std::ostream &out);
private:
+ // Generator parameters
UnlimitedHeightmap *m_heightmap;
MapParams m_params;
+ PointAttributeDatabase m_padb;
std::string m_savedir;
bool m_map_saving_enabled;
};
+#ifndef SERVER
+
+struct MapDrawControl
+{
+ MapDrawControl():
+ range_all(false),
+ wanted_range(50),
+ wanted_max_blocks(0),
+ wanted_min_range(0),
+ blocks_drawn(0),
+ blocks_would_have_drawn(0)
+ {
+ }
+ // Overrides limits by drawing everything
+ bool range_all;
+ // Wanted drawing range
+ float wanted_range;
+ // Maximum number of blocks to draw
+ u32 wanted_max_blocks;
+ // Blocks in this range are drawn regardless of number of blocks drawn
+ float wanted_min_range;
+ // Number of blocks rendered is written here by the renderer
+ u32 blocks_drawn;
+ // Number of blocks that would have been drawn in wanted_range
+ u32 blocks_would_have_drawn;
+};
+
class Client;
+/*
+ ClientMap
+
+ This is the only map class that is able to render itself on screen.
+*/
+
class ClientMap : public Map, public scene::ISceneNode
{
public:
ClientMap(
Client *client,
- video::SMaterial *materials,
+ MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id
return MAPTYPE_CLIENT;
}
+ void drop()
+ {
+ ISceneNode::drop();
+ }
+
/*
Forcefully get a sector from somewhere
*/
ISceneNode methods
*/
- virtual void OnRegisterSceneNode()
- {
- if(IsVisible)
- {
- //SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX);
- SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
- SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
- }
-
- ISceneNode::OnRegisterSceneNode();
- }
+ virtual void OnRegisterSceneNode();
virtual void render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
- renderMap(driver, m_materials, SceneManager->getSceneNodeRenderPass());
+ renderMap(driver, SceneManager->getSceneNodeRenderPass());
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
return m_box;
}
- void renderMap(video::IVideoDriver* driver,
- video::SMaterial *materials, s32 pass);
+ void renderMap(video::IVideoDriver* driver, s32 pass);
- // Update master heightmap mesh
- void updateMesh();
+ /*
+ Methods for setting temporary modifications to nodes for
+ drawing.
+ Return value is position of changed block.
+ */
+ v3s16 setTempMod(v3s16 p, NodeMod mod);
+ v3s16 clearTempMod(v3s16 p);
+ // Efficient implementation needs a cache of TempMods
+ //void clearTempMods();
// For debug printing
virtual void PrintInfo(std::ostream &out);
private:
Client *m_client;
- video::SMaterial *m_materials;
-
core::aabbox3d<f32> m_box;
// This is the master heightmap mesh
scene::SMesh *mesh;
JMutex mesh_mutex;
+
+ MapDrawControl &m_control;
};
+#endif
+
class MapVoxelManipulator : public VoxelManipulator
{
public: