aboutsummaryrefslogtreecommitdiff
path: root/src/map.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-04-03 12:14:23 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-04-03 12:14:23 +0300
commitee89e29ae10d58a2a3d00641f4e459600a49e09e (patch)
treec15415dae2e47243a5f89d754a646ef8b6ff65f1 /src/map.h
parent685a635aea4a5c61b899e36ef87ece3d5f9e25a9 (diff)
downloadhax-minetest-server-ee89e29ae10d58a2a3d00641f4e459600a49e09e.tar.gz
hax-minetest-server-ee89e29ae10d58a2a3d00641f4e459600a49e09e.zip
Revert mapgen to best working version (2)
Diffstat (limited to 'src/map.h')
-rw-r--r--src/map.h122
1 files changed, 73 insertions, 49 deletions
diff --git a/src/map.h b/src/map.h
index 39cd79f01..1cebef634 100644
--- a/src/map.h
+++ b/src/map.h
@@ -38,18 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapsector.h"
#include "constants.h"
#include "voxel.h"
-
-/*
- Some exposed functions
-*/
-
-double base_rock_level_2d(u64 seed, v2f p);
-bool get_have_sand_coast(u64 seed, v2f p);
-bool get_have_sand_ground(u64 seed, v2f p);
-double get_turbulence_factor_2d(u64 seed, v2f p);
-
-/*
-*/
+#include "mapchunk.h"
#define MAPTYPE_BASE 0
#define MAPTYPE_SERVER 1
@@ -335,29 +324,81 @@ public:
Map generation
*/
+ // Returns the position of the chunk where the sector is in
+ v2s16 sector_to_chunk(v2s16 sectorpos)
+ {
+ 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)
+ {
+ 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 block and its neighbors are fully generated.
- It means the block will not be touched in the future by the
- generator. If false, generateBlock will make it true.
+ 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 blockNonVolatile(v3s16 blockpos)
+ bool chunkNonVolatile(v2s16 chunkpos)
{
- for(s16 x=-1; x<=1; x++)
- for(s16 y=-1; y<=1; y++)
- for(s16 z=-1; z<=1; z++)
+ /*for(s16 x=-1; x<=1; x++)
+ for(s16 y=-1; y<=1; y++)*/
+ s16 x=0;
+ s16 y=0;
{
- v3s16 blockpos0 = blockpos + v3s16(x,y,z);
- MapBlock *block = getBlockNoCreateNoEx(blockpos);
- if(block == NULL)
+ v2s16 chunkpos0 = chunkpos + v2s16(x,y);
+ MapChunk *chunk = getChunk(chunkpos);
+ if(chunk == NULL)
return false;
- if(block->isFullyGenerated() == false)
+ if(chunk->getGenLevel() != GENERATED_FULLY)
return false;
}
return true;
}
/*
+ 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);
@@ -384,27 +425,6 @@ public:
return emergeSector(p, changed_blocks);
}
- /*MapBlock * generateBlock(
- v3s16 p,
- MapBlock *original_dummy,
- ServerMapSector *sector,
- core::map<v3s16, MapBlock*> &changed_blocks,
- core::map<v3s16, MapBlock*> &lighting_invalidated_blocks
- );*/
-
- /*
- Generate a block.
-
- All blocks touching this one can be altered also.
- */
- MapBlock* generateBlockRaw(v3s16 blockpos,
- core::map<v3s16, MapBlock*> &changed_blocks,
- bool force=false);
-
- /*
- Generate a block and its neighbors so that it won't be touched
- anymore.
- */
MapBlock * generateBlock(
v3s16 p,
MapBlock *original_dummy,
@@ -412,8 +432,6 @@ public:
core::map<v3s16, MapBlock*> &changed_blocks,
core::map<v3s16, MapBlock*> &lighting_invalidated_blocks
);
- /*MapBlock* generateBlock(v3s16 blockpos,
- core::map<v3s16, MapBlock*> &changed_blocks);*/
/*
Get a block from somewhere.
@@ -486,6 +504,9 @@ public:
void saveMapMeta();
void loadMapMeta();
+ void saveChunkMeta();
+ void loadChunkMeta();
+
// The sector mutex should be locked when calling most of these
// This only saves sector-specific data such as the heightmap
@@ -510,14 +531,17 @@ public:
bool isSavingEnabled(){ return m_map_saving_enabled; }
- u64 getSeed(){ return m_seed; }
-
private:
// Seed used for all kinds of randomness
u64 m_seed;
std::string m_savedir;
bool m_map_saving_enabled;
+
+ // Chunk size in MapSectors
+ s16 m_chunksize;
+ // Chunks
+ core::map<v2s16, MapChunk*> m_chunks;
};
/*
@@ -641,7 +665,7 @@ public:
void updateMeshes(v3s16 blockpos, u32 daynight_ratio);
// Update meshes that touch the node
- void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);
+ //void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);
// For debug printing
virtual void PrintInfo(std::ostream &out);