endif()
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops")
- set(CMAKE_CXX_FLAGS_DEBUG "-g -O1 -Wall ${WARNING_FLAGS}")
+ #set(CMAKE_CXX_FLAGS_DEBUG "-g -O1 -Wall ${WARNING_FLAGS}")
+ set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall ${WARNING_FLAGS}")
if(USE_GPROF)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
#include "main.h"
#include <sstream>
#include "porting.h"
+#include "mapsector.h"
void * MeshUpdateThread::Thread()
{
//TimeTaker timer("MapBlock deSerialize");
// 0ms
- try{
- block = sector->getBlockNoCreate(p.Y);
+ block = sector->getBlockNoCreateNoEx(p.Y);
+ if(block)
+ {
/*
Update an existing block
*/
//dstream<<"Updating"<<std::endl;
block->deSerialize(istr, ser_version);
}
- catch(InvalidPositionException &e)
+ else
{
/*
Create a new block
}
else if(command == TOCLIENT_SECTORMETA)
{
+ dstream<<"Client received DEPRECATED TOCLIENT_SECTORMETA"<<std::endl;
+#if 0
/*
[0] u16 command
[2] u8 sector count
((ClientMap&)m_env.getMap()).deSerializeSector(pos, is);
}
} //envlock
+#endif
}
else if(command == TOCLIENT_INVENTORY)
{
*/
#include "map.h"
+#include "mapsector.h"
+#include "mapblock.h"
#include "main.h"
-#include "jmutexautolock.h"
#include "client.h"
#include "filesys.h"
#include "utility.h"
return sector;
}
-MapBlock * Map::getBlockNoCreate(v3s16 p3d)
-{
+MapBlock * Map::getBlockNoCreateNoEx(v3s16 p3d)
+{
v2s16 p2d(p3d.X, p3d.Z);
MapSector * sector = getSectorNoGenerate(p2d);
-
- MapBlock *block = sector->getBlockNoCreate(p3d.Y);
-
+ MapBlock *block = sector->getBlockNoCreateNoEx(p3d.Y);
return block;
}
-MapBlock * Map::getBlockNoCreateNoEx(v3s16 p3d)
-{
- try
- {
- v2s16 p2d(p3d.X, p3d.Z);
- MapSector * sector = getSectorNoGenerate(p2d);
- MapBlock *block = sector->getBlockNoCreate(p3d.Y);
- return block;
- }
- catch(InvalidPositionException &e)
- {
- return NULL;
- }
+MapBlock * Map::getBlockNoCreate(v3s16 p3d)
+{
+ MapBlock *block = getBlockNoCreateNoEx(p3d);
+ if(block == NULL)
+ throw InvalidPositionException();
+ return block;
}
+
/*MapBlock * Map::getBlockCreate(v3s16 p3d)
{
v2s16 p2d(p3d.X, p3d.Z);
// Save if modified
if(block->getModified() != MOD_STATE_CLEAN)
saveBlock(block);
- // Unload
- sector->removeBlock(block);
- delete block;
+ // Delete from memory
+ sector->deleteBlock(block);
}
else
{
MapBlock *block = NULL;
bool created_new = false;
- try{
- block = sector->getBlockNoCreate(p3d.Y);
- }
- catch(InvalidPositionException &e)
+ block = sector->getBlockNoCreateNoEx(p3d.Y);
+ if(block == NULL)
{
block = sector->createBlankBlockNoInsert(p3d.Y);
created_new = true;
return sector;
}
+#if 0
void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
{
DSTACK(__FUNCTION_NAME);
sector->deSerialize(is);
}
+#endif
void ClientMap::OnRegisterSceneNode()
{
#define MAP_HEADER
#include <jmutex.h>
+#include <jmutexautolock.h>
#include <jthread.h>
#include <iostream>
#include "common_irrlicht.h"
#include "mapnode.h"
#include "mapblock.h"
-#include "mapsector.h"
#include "constants.h"
#include "voxel.h"
#include "mapchunk.h"
#include "nodemetadata.h"
+class MapSector;
+class ServerMapSector;
+class ClientMapSector;
+
+class MapBlock;
+
namespace mapgen{
struct BlockMakeData;
};
core::map<MapEventReceiver*, bool> m_event_receivers;
core::map<v2s16, MapSector*> m_sectors;
- //JMutex m_sector_mutex;
// Be sure to set this to NULL when the cached sector is deleted
MapSector *m_sector_cache;
*/
MapSector * emergeSector(v2s16 p);
- void deSerializeSector(v2s16 p2d, std::istream &is);
+ //void deSerializeSector(v2s16 p2d, std::istream &is);
/*
ISceneNode methods
#include "jmutexautolock.h"
#include "client.h"
#include "exceptions.h"
+#include "mapblock.h"
MapSector::MapSector(NodeContainer *parent, v2s16 pos):
- differs_from_disk(true),
+ differs_from_disk(false),
m_parent(parent),
m_pos(pos),
m_block_cache(NULL)
{
- m_mutex.Init();
- assert(m_mutex.IsInitialized());
}
MapSector::~MapSector()
void MapSector::deleteBlocks()
{
- JMutexAutoLock lock(m_mutex);
-
// Clear cache
m_block_cache = NULL;
MapBlock * MapSector::getBlockNoCreateNoEx(s16 y)
{
- JMutexAutoLock lock(m_mutex);
-
return getBlockBuffered(y);
}
-MapBlock * MapSector::getBlockNoCreate(s16 y)
-{
- MapBlock *block = getBlockNoCreateNoEx(y);
-
- if(block == NULL)
- throw InvalidPositionException();
-
- return block;
-}
-
MapBlock * MapSector::createBlankBlockNoInsert(s16 y)
{
- // There should not be a block at this position
- if(getBlockBuffered(y) != NULL)
- throw AlreadyExistsException("Block already exists");
+ assert(getBlockBuffered(y) == NULL);
v3s16 blockpos_map(m_pos.X, y, m_pos.Y);
MapBlock * MapSector::createBlankBlock(s16 y)
{
- JMutexAutoLock lock(m_mutex);
-
MapBlock *block = createBlankBlockNoInsert(y);
m_blocks.insert(y, block);
{
s16 block_y = block->getPos().Y;
- {
- JMutexAutoLock lock(m_mutex);
-
- MapBlock *block2 = getBlockBuffered(block_y);
- if(block2 != NULL){
- throw AlreadyExistsException("Block already exists");
- }
-
- v2s16 p2d(block->getPos().X, block->getPos().Z);
- assert(p2d == m_pos);
-
- // Insert into container
- m_blocks.insert(block_y, block);
+ MapBlock *block2 = getBlockBuffered(block_y);
+ if(block2 != NULL){
+ throw AlreadyExistsException("Block already exists");
}
+
+ v2s16 p2d(block->getPos().X, block->getPos().Z);
+ assert(p2d == m_pos);
+
+ // Insert into container
+ m_blocks.insert(block_y, block);
}
-void MapSector::removeBlock(MapBlock *block)
+void MapSector::deleteBlock(MapBlock *block)
{
s16 block_y = block->getPos().Y;
- JMutexAutoLock lock(m_mutex);
-
// Clear from cache
m_block_cache = NULL;
// Remove from container
m_blocks.remove(block_y);
+
+ // Delete
+ delete block;
}
void MapSector::getBlocks(core::list<MapBlock*> &dest)
{
- JMutexAutoLock lock(m_mutex);
-
core::list<MapBlock*> ref_list;
core::map<s16, MapBlock*>::Iterator bi;
{
}
-f32 ServerMapSector::getGroundHeight(v2s16 p, bool generate)
-{
- return GROUNDHEIGHT_NOTFOUND_SETVALUE;
-}
-
-void ServerMapSector::setGroundHeight(v2s16 p, f32 y, bool generate)
-{
-}
-
void ServerMapSector::serialize(std::ostream &os, u8 version)
{
if(!ser_ver_supported(version))
{
}
-void ClientMapSector::deSerialize(std::istream &is)
-{
- /*
- [0] u8 serialization version
- [1] s16 corners[0]
- [3] s16 corners[1]
- [5] s16 corners[2]
- [7] s16 corners[3]
- size = 9
-
- In which corners are in these positions
- v2s16(0,0),
- v2s16(1,0),
- v2s16(1,1),
- v2s16(0,1),
- */
-
- // Read version
- u8 version = SER_FMT_VER_INVALID;
- is.read((char*)&version, 1);
-
- if(!ser_ver_supported(version))
- throw VersionMismatchException("ERROR: MapSector format not supported");
-
- u8 buf[2];
-
- // Dummy read corners
- is.read((char*)buf, 2);
- is.read((char*)buf, 2);
- is.read((char*)buf, 2);
- is.read((char*)buf, 2);
-
- /*
- Set stuff in sector
- */
-
- // Nothing here
-
-}
#endif // !SERVER
//END
#include <jmutex.h>
#include "common_irrlicht.h"
-#include "mapblock.h"
-//#include "heightmap.h"
#include "exceptions.h"
+#include <ostream>
+
+class MapBlock;
+class NodeContainer;
/*
This is an Y-wise stack of MapBlocks.
#define MAPSECTOR_SERVER 0
#define MAPSECTOR_CLIENT 1
-class MapSector: public NodeContainer
+class MapSector
{
public:
MapSector(NodeContainer *parent, v2s16 pos);
virtual ~MapSector();
- virtual u16 nodeContainerId() const
- {
- return NODECONTAINER_ID_MAPSECTOR;
- }
-
virtual u32 getId() const = 0;
void deleteBlocks();
}
MapBlock * getBlockNoCreateNoEx(s16 y);
- MapBlock * getBlockNoCreate(s16 y);
MapBlock * createBlankBlockNoInsert(s16 y);
MapBlock * createBlankBlock(s16 y);
- //MapBlock * getBlock(s16 y, bool generate=true);
void insertBlock(MapBlock *block);
- // This is used to remove a dummy from the sector while generating it.
- // Block is only removed from internal container, not deleted.
- void removeBlock(MapBlock *block);
+ void deleteBlock(MapBlock *block);
- /*
- This might not be a thread-safe depending on the day.
- See the implementation.
- */
void getBlocks(core::list<MapBlock*> &dest);
- /*
- If all nodes in area can be accessed, returns true and
- adds all blocks in area to blocks.
-
- If all nodes in area cannot be accessed, returns false.
-
- The implementation of this is quite slow
-
- if blocks==NULL; it is not accessed at all.
- */
- bool isValidArea(v3s16 p_min_nodes, v3s16 p_max_nodes,
- core::map<s16, MapBlock*> *blocks)
- {
- core::map<s16, MapBlock*> bs;
-
- v3s16 p_min = getNodeBlockPos(p_min_nodes);
- v3s16 p_max = getNodeBlockPos(p_max_nodes);
- if(p_min.X != 0 || p_min.Z != 0
- || p_max.X != 0 || p_max.Z != 0)
- return false;
- v3s16 y;
- for(s16 y=p_min.Y; y<=p_max.Y; y++)
- {
- try{
- MapBlock *block = getBlockNoCreate(y);
- if(block->isDummy())
- return false;
- if(blocks!=NULL)
- bs[y] = block;
- }
- catch(InvalidPositionException &e)
- {
- return false;
- }
- }
-
- if(blocks!=NULL)
- {
- for(core::map<s16, MapBlock*>::Iterator i=bs.getIterator();
- i.atEnd()==false; i++)
- {
- MapBlock *block = i.getNode()->getValue();
- s16 y = i.getNode()->getKey();
- blocks->insert(y, block);
- }
- }
- return true;
- }
-
- void getBlocksInArea(v3s16 p_min_nodes, v3s16 p_max_nodes,
- core::map<v3s16, MapBlock*> &blocks)
- {
- v3s16 p_min = getNodeBlockPos(p_min_nodes);
- v3s16 p_max = getNodeBlockPos(p_max_nodes);
- v3s16 y;
- for(s16 y=p_min.Y; y<=p_max.Y; y++)
- {
- try{
- MapBlock *block = getBlockNoCreate(y);
- blocks.insert(block->getPos(), block);
- }
- catch(InvalidPositionException &e)
- {
- }
- }
- }
-
- // virtual from NodeContainer
- bool isValidPosition(v3s16 p)
- {
- v3s16 blockpos = getNodeBlockPos(p);
-
- if(blockpos.X != 0 || blockpos.Z != 0)
- return false;
-
- MapBlock *blockref;
- try{
- blockref = getBlockNoCreate(blockpos.Y);
- }
- catch(InvalidPositionException &e)
- {
- return false;
- }
-
- return true;
- }
-
- // virtual from NodeContainer
- MapNode getNode(v3s16 p)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- if(blockpos.X != 0 || blockpos.Z != 0)
- throw InvalidPositionException
- ("MapSector only allows Y");
-
- MapBlock * blockref = getBlockNoCreate(blockpos.Y);
- v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
-
- return blockref->getNode(relpos);
- }
- // virtual from NodeContainer
- void setNode(v3s16 p, MapNode & n)
- {
- v3s16 blockpos = getNodeBlockPos(p);
- if(blockpos.X != 0 || blockpos.Z != 0)
- throw InvalidPositionException
- ("MapSector only allows Y");
-
- MapBlock * blockref = getBlockNoCreate(blockpos.Y);
- v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- blockref->setNode(relpos, n);
- }
-
- // DEPRECATED?
- virtual f32 getGroundHeight(v2s16 p, bool generate=false)
- {
- return GROUNDHEIGHT_NOTFOUND_SETVALUE;
- }
- virtual void setGroundHeight(v2s16 p, f32 y, bool generate=false)
- {
- }
-
- // When true, sector metadata is changed from the one on disk
- // (sector metadata = all but blocks)
- // Basically, this should be changed to true in every setter method
+ // Always false at the moment, because sector contains no metadata.
bool differs_from_disk;
protected:
// The pile of MapBlocks
core::map<s16, MapBlock*> m_blocks;
- //JMutex m_blocks_mutex; // For public access functions
NodeContainer *m_parent;
// Position on parent (in MapBlock widths)
v2s16 m_pos;
-
+
+ // Last-used block is cached here for quicker access.
// Be sure to set this to NULL when the cached block is deleted
MapBlock *m_block_cache;
s16 m_block_cache_y;
- // This is used for protecting m_blocks
- JMutex m_mutex;
-
/*
Private methods
*/
{
return MAPSECTOR_SERVER;
}
-
- // DEPRECATED?
- f32 getGroundHeight(v2s16 p, bool generate=false);
- void setGroundHeight(v2s16 p, f32 y, bool generate=false);
/*
These functions handle metadata.
They do not handle blocks.
*/
+
void serialize(std::ostream &os, u8 version);
static ServerMapSector* deSerialize(
return MAPSECTOR_CLIENT;
}
- void deSerialize(std::istream &is);
-
- /*s16 getCorner(u16 i)
- {
- return m_corners[i];
- }*/
-
private:
- // The ground height of the corners is stored in here
- //s16 m_corners[4];
};
#endif
#include <sstream>
#include "porting.h"
#include "content_mapnode.h"
+#include "mapsector.h"
/*
Asserts that the exception occurs
// Create one with no heightmaps
ServerMapSector sector(&parent, v2s16(1,1));
- EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
- EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(1));
+ assert(sector.getBlockNoCreateNoEx(0) == 0);
+ assert(sector.getBlockNoCreateNoEx(1) == 0);
MapBlock * bref = sector.createBlankBlock(-2);
- EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
- assert(sector.getBlockNoCreate(-2) == bref);
+ assert(sector.getBlockNoCreateNoEx(0) == 0);
+ assert(sector.getBlockNoCreateNoEx(-2) == bref);
//TODO: Check for AlreadyExistsException