#include "constants.h"
#include "voxel.h"
-class CacheLock
-{
-public:
- CacheLock()
- {
- m_count = 0;
- m_count_mutex.Init();
- m_cache_mutex.Init();
- m_waitcache_mutex.Init();
- }
-
- void cacheCreated()
- {
- //dstream<<"cacheCreated() begin"<<std::endl;
- JMutexAutoLock waitcachelock(m_waitcache_mutex);
- JMutexAutoLock countlock(m_count_mutex);
-
- // If this is the first cache, grab the cache lock
- if(m_count == 0)
- m_cache_mutex.Lock();
-
- m_count++;
-
- //dstream<<"cacheCreated() end"<<std::endl;
- }
-
- void cacheRemoved()
- {
- //dstream<<"cacheRemoved() begin"<<std::endl;
- JMutexAutoLock countlock(m_count_mutex);
-
- assert(m_count > 0);
-
- m_count--;
-
- // If this is the last one, release the cache lock
- if(m_count == 0)
- m_cache_mutex.Unlock();
-
- //dstream<<"cacheRemoved() end"<<std::endl;
- }
-
- /*
- This lock should be taken when removing stuff that can be
- pointed by the cache.
-
- You'll want to grab this in a SharedPtr.
- */
- JMutexAutoLock * waitCaches()
- {
- //dstream<<"waitCaches() begin"<<std::endl;
- JMutexAutoLock waitcachelock(m_waitcache_mutex);
- JMutexAutoLock *lock = new JMutexAutoLock(m_cache_mutex);
- //dstream<<"waitCaches() end"<<std::endl;
- return lock;
- }
-
-private:
- // Count of existing caches
- u32 m_count;
- JMutex m_count_mutex;
- // This is locked always when there are some caches
- JMutex m_cache_mutex;
- // Locked so that when waitCaches() is called, no more caches are created
- JMutex m_waitcache_mutex;
-};
-
#define MAPTYPE_BASE 0
#define MAPTYPE_SERVER 1
#define MAPTYPE_CLIENT 2
class Map : public NodeContainer, public Heightmappish
{
-protected:
-
- std::ostream &m_dout;
-
- core::map<v2s16, MapSector*> m_sectors;
- JMutex m_sector_mutex;
-
- v3f m_camera_position;
- v3f m_camera_direction;
- JMutex m_camera_mutex;
-
- // Be sure to set this to NULL when the cached sector is deleted
- MapSector *m_sector_cache;
- v2s16 m_sector_cache_p;
-
- WrapperHeightmap m_hwrapper;
-
public:
- v3s16 drawoffset; // for drawbox()
-
- /*
- 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;
-
Map(std::ostream &dout);
virtual ~Map();
m_camera_direction = dir;
}
- /*void StartUpdater()
- {
- updater.Start();
- }
-
- void StopUpdater()
- {
- updater.setRun(false);
- while(updater.IsRunning())
- sleep_s(1);
- }
-
- bool UpdaterIsRunning()
- {
- return updater.IsRunning();
- }*/
-
static core::aabbox3d<f32> getNodeBox(v3s16 p)
{
return core::aabbox3d<f32>(
their differing fetch methods.
*/
virtual MapSector * emergeSector(v2s16 p) = 0;
-
+
// Returns InvalidPositionException if not found
MapBlock * getBlockNoCreate(v3s16 p);
// Returns NULL if not found
void expireMeshes(bool only_daynight_diffed);
/*
- Updates the faces of the given block and blocks on the
+ Update the faces of the given block and blocks on the
leading edge.
*/
void updateMeshes(v3s16 blockpos, u32 daynight_ratio);
+
+ // Update meshes that touch the node
+ //void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);
#endif
/*
// For debug printing
virtual void PrintInfo(std::ostream &out);
+
+ void transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks);
+
+ /*
+ Variables
+ */
+
+protected:
+
+ std::ostream &m_dout;
+
+ core::map<v2s16, MapSector*> m_sectors;
+ JMutex m_sector_mutex;
+
+ v3f m_camera_position;
+ v3f m_camera_direction;
+ JMutex m_camera_mutex;
+
+ // Be sure to set this to NULL when the cached sector is deleted
+ MapSector *m_sector_cache;
+ v2s16 m_sector_cache_p;
+
+ WrapperHeightmap m_hwrapper;
+
+ // Queued transforming water nodes
+ UniqueQueue<v3s16> m_transforming_liquid;
};
// Master heightmap parameters
//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;
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:
/*
Methods for setting temporary modifications to nodes for
drawing.
- Return value is position of changed block.
+
+ Returns true if something changed.
+
+ All blocks whose mesh could have been changed are inserted
+ to affected_blocks.
*/
- v3s16 setTempMod(v3s16 p, NodeMod mod);
- v3s16 clearTempMod(v3s16 p);
+ bool setTempMod(v3s16 p, NodeMod mod,
+ core::map<v3s16, MapBlock*> *affected_blocks=NULL);
+ bool clearTempMod(v3s16 p,
+ core::map<v3s16, MapBlock*> *affected_blocks=NULL);
// Efficient implementation needs a cache of TempMods
//void clearTempMods();
void blitBack(core::map<v3s16, MapBlock*> & modified_blocks);
-private:
+protected:
Map *m_map;
/*
NOTE: This might be used or not
core::map<v3s16, bool> m_loaded_blocks;
};
+class ManualMapVoxelManipulator : public MapVoxelManipulator
+{
+public:
+ ManualMapVoxelManipulator(Map *map);
+ virtual ~ManualMapVoxelManipulator();
+
+ virtual void emerge(VoxelArea a, s32 caller_id=-1);
+
+ void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max);
+
+protected:
+};
+
#endif