summaryrefslogtreecommitdiff
path: root/src/map.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-06-25 04:25:14 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-06-25 04:25:14 +0300
commit7538b4c6201675c566c98b21c8ecddb798a14943 (patch)
treee61cbdb7c2d9fedd41e2793860aa26553c545f56 /src/map.h
parent47e4eda4bb87cd9dc20dddf81ca473b523eeb150 (diff)
downloadminetest-7538b4c6201675c566c98b21c8ecddb798a14943.tar.gz
minetest-7538b4c6201675c566c98b21c8ecddb798a14943.tar.bz2
minetest-7538b4c6201675c566c98b21c8ecddb798a14943.zip
New map generator added (and SQLite, messed up the commits at that time...) (import from temporary git repo)
Diffstat (limited to 'src/map.h')
-rw-r--r--src/map.h218
1 files changed, 46 insertions, 172 deletions
diff --git a/src/map.h b/src/map.h
index 691f3bdb4..ada17cd7e 100644
--- a/src/map.h
+++ b/src/map.h
@@ -132,7 +132,7 @@ public:
// On failure returns NULL
MapSector * getSectorNoGenerateNoExNoLock(v2s16 p2d);
- // On failure returns NULL
+ // Same as the above (there exists no lock anymore)
MapSector * getSectorNoGenerateNoEx(v2s16 p2d);
// On failure throws InvalidPositionException
MapSector * getSectorNoGenerate(v2s16 p2d);
@@ -268,6 +268,9 @@ public:
//bool updateChangedVisibleArea();
virtual void save(bool only_changed){assert(0);};
+
+ // Server implements this
+ virtual void saveBlock(MapBlock *block){};
/*
Updates usage timers
@@ -279,7 +282,7 @@ public:
void deleteSectors(core::list<v2s16> &list, bool only_blocks);
// Returns count of deleted sectors
- u32 deleteUnusedSectors(float timeout, bool only_blocks=false,
+ u32 unloadUnusedData(float timeout, bool only_blocks=false,
core::list<v3s16> *deleted_blocks=NULL);
// For debug printing
@@ -330,7 +333,9 @@ protected:
This is the only map class that is able to generate map.
*/
-struct ChunkMakeData;
+//struct ChunkMakeData;
+
+struct BlockMakeData;
class ServerMap : public Map
{
@@ -347,159 +352,24 @@ public:
}
/*
- Map generation
- */
-
- // Returns the position of the chunk where the sector is in
- v2s16 sector_to_chunk(v2s16 sectorpos)
- {
- if(m_chunksize == 0)
- return v2s16(0,0);
- sectorpos.X += m_chunksize / 2;
- sectorpos.Y += m_chunksize / 2;
- v2s16 chunkpos = getContainerPos(sectorpos, m_chunksize);
- return chunkpos;
- }
-
- // Returns the position of the (0,0) sector of the chunk
- v2s16 chunk_to_sector(v2s16 chunkpos)
- {
- if(m_chunksize == 0)
- return v2s16(0,0);
- v2s16 sectorpos(
- chunkpos.X * m_chunksize,
- chunkpos.Y * m_chunksize
- );
- sectorpos.X -= m_chunksize / 2;
- sectorpos.Y -= m_chunksize / 2;
- return sectorpos;
- }
-
- /*
- Get a chunk.
- */
- MapChunk *getChunk(v2s16 chunkpos)
- {
- core::map<v2s16, MapChunk*>::Node *n;
- n = m_chunks.find(chunkpos);
- if(n == NULL)
- return NULL;
- return n->getValue();
- }
-
- /*
- True if the chunk and its neighbors are fully generated.
- It means the chunk will not be touched in the future by the
- generator. If false, generateChunk will make it true.
- */
- bool chunkNonVolatile(v2s16 chunkpos)
- {
- if(m_chunksize == 0)
- return true;
-
- /*for(s16 x=-1; x<=1; x++)
- for(s16 y=-1; y<=1; y++)*/
- s16 x=0;
- s16 y=0;
- {
- v2s16 chunkpos0 = chunkpos + v2s16(x,y);
- MapChunk *chunk = getChunk(chunkpos);
- if(chunk == NULL)
- return false;
- if(chunk->getGenLevel() != GENERATED_FULLY)
- return false;
- }
- return true;
- }
-
- /*
- Returns true if any chunk is marked as modified
- */
- bool anyChunkModified()
- {
- for(core::map<v2s16, MapChunk*>::Iterator
- i = m_chunks.getIterator();
- i.atEnd()==false; i++)
- {
- v2s16 p = i.getNode()->getKey();
- MapChunk *chunk = i.getNode()->getValue();
- if(chunk->isModified())
- return true;
- }
- return false;
- }
-
- void setChunksNonModified()
- {
- for(core::map<v2s16, MapChunk*>::Iterator
- i = m_chunks.getIterator();
- i.atEnd()==false; i++)
- {
- v2s16 p = i.getNode()->getKey();
- MapChunk *chunk = i.getNode()->getValue();
- chunk->setModified(false);
- }
- }
-
- /*
- Chunks are generated by using these and makeChunk().
- */
- void initChunkMake(ChunkMakeData &data, v2s16 chunkpos);
- MapChunk* finishChunkMake(ChunkMakeData &data,
- core::map<v3s16, MapBlock*> &changed_blocks);
-
- /*
- Generate a chunk.
-
- All chunks touching this one can be altered also.
- */
- /*MapChunk* generateChunkRaw(v2s16 chunkpos,
- core::map<v3s16, MapBlock*> &changed_blocks,
- bool force=false);*/
-
- /*
- Generate a chunk and its neighbors so that it won't be touched
- anymore.
- */
- /*MapChunk* generateChunk(v2s16 chunkpos,
- core::map<v3s16, MapBlock*> &changed_blocks);*/
-
- /*
- Generate a sector.
-
- This is mainly called by generateChunkRaw.
- */
- //ServerMapSector * generateSector(v2s16 p);
-
- /*
Get a sector from somewhere.
- Check memory
- - Check disk (loads blocks also)
+ - Check disk (doesn't load blocks)
- Create blank one
*/
ServerMapSector * createSector(v2s16 p);
/*
- Get a sector from somewhere.
- - Check memory
- - Check disk (loads blocks also)
- - Generate chunk
+ Blocks are generated by using these and makeBlock().
*/
- /*MapSector * emergeSector(v2s16 p,
- core::map<v3s16, MapBlock*> &changed_blocks);*/
+ void initBlockMake(BlockMakeData *data, v3s16 blockpos);
+ MapBlock* finishBlockMake(BlockMakeData *data,
+ core::map<v3s16, MapBlock*> &changed_blocks);
- /*MapSector * emergeSector(v2s16 p)
- {
- core::map<v3s16, MapBlock*> changed_blocks;
- return emergeSector(p, changed_blocks);
- }*/
-
+ // A non-threaded wrapper to the above
MapBlock * generateBlock(
v3s16 p,
- MapBlock *original_dummy,
- ServerMapSector *sector,
- core::map<v3s16, MapBlock*> &changed_blocks,
- core::map<v3s16, MapBlock*> &lighting_invalidated_blocks
+ core::map<v3s16, MapBlock*> &modified_blocks
);
/*
@@ -508,37 +378,17 @@ public:
- Create blank
*/
MapBlock * createBlock(v3s16 p);
-
- /*
- only_from_disk, changed_blocks and lighting_invalidated_blocks
- are not properly used by the new map generator.
- */
- MapBlock * emergeBlock(
- v3s16 p,
- bool only_from_disk,
- core::map<v3s16, MapBlock*> &changed_blocks,
- core::map<v3s16, MapBlock*> &lighting_invalidated_blocks
- );
#if 0
/*
+ NOTE: This comment might be outdated
+
Forcefully get a block from somewhere.
- Exceptions:
- - InvalidPositionException: possible if only_from_disk==true
-
- changed_blocks:
- - All already existing blocks that were modified are added.
- - If found on disk, nothing will be added.
- - If generated, the new block will not be included.
-
- lighting_invalidated_blocks:
- - All blocks that have heavy-to-calculate lighting changes
- are added.
- - updateLighting() should be called for these.
+ InvalidPositionException possible if only_from_disk==true
- - A block that is in changed_blocks may not be in
- lighting_invalidated_blocks.
+ Parameters:
+ changed_blocks: Blocks that have been modified
*/
MapBlock * emergeBlock(
v3s16 p,
@@ -561,6 +411,7 @@ public:
// dirname: final directory name
v2s16 getSectorPos(std::string dirname);
v3s16 getBlockPos(std::string sectordir, std::string blockfile);
+ static std::string getBlockFilename(v3s16 p);
void save(bool only_changed);
//void loadAll();
@@ -569,8 +420,8 @@ public:
void saveMapMeta();
void loadMapMeta();
- void saveChunkMeta();
- void loadChunkMeta();
+ /*void saveChunkMeta();
+ void loadChunkMeta();*/
// The sector mutex should be locked when calling most of these
@@ -579,6 +430,7 @@ public:
// DEPRECATED? Sectors have no metadata anymore.
void saveSectorMeta(ServerMapSector *sector);
MapSector* loadSectorMeta(std::string dirname, bool save_after_load);
+ bool loadSectorMeta(v2s16 p2d);
// Full load of a sector including all blocks.
// returns true on success, false on failure.
@@ -590,6 +442,7 @@ public:
void saveBlock(MapBlock *block);
// This will generate a sector with getSector if not found.
void loadBlock(std::string sectordir, std::string blockfile, MapSector *sector, bool save_after_load=false);
+ MapBlock* loadBlock(v3s16 p);
// For debug printing
virtual void PrintInfo(std::ostream &out);
@@ -605,11 +458,13 @@ private:
std::string m_savedir;
bool m_map_saving_enabled;
+#if 0
// Chunk size in MapSectors
// If 0, chunks are disabled.
s16 m_chunksize;
// Chunks
core::map<v2s16, MapChunk*> m_chunks;
+#endif
/*
Metadata is re-written on disk only if this is true.
@@ -815,6 +670,7 @@ protected:
bool m_create_area;
};
+#if 0
struct ChunkMakeData
{
bool no_op;
@@ -838,6 +694,24 @@ struct ChunkMakeData
};
void makeChunk(ChunkMakeData *data);
+#endif
+
+struct BlockMakeData
+{
+ bool no_op;
+ ManualMapVoxelManipulator vmanip;
+ u64 seed;
+ v3s16 blockpos;
+ UniqueQueue<v3s16> transforming_liquid;
+
+ BlockMakeData():
+ no_op(false),
+ vmanip(NULL),
+ seed(0)
+ {}
+};
+
+void makeBlock(BlockMakeData *data);
#endif