summaryrefslogtreecommitdiffstats
path: root/source/ChunkMap.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/ChunkMap.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp
index af8f09820..671eac708 100644
--- a/source/ChunkMap.cpp
+++ b/source/ChunkMap.cpp
@@ -10,6 +10,7 @@
#include "Pickup.h"
#include "Chunk.h"
#include "Generating/Trees.h" // used in cChunkMap::ReplaceTreeBlocks() for tree block discrimination
+#include "BlockArea.h"
#ifndef _WIN32
#include <cstdlib> // abs
@@ -1493,6 +1494,44 @@ bool cChunkMap::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinCh
+bool cChunkMap::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
+{
+ // Convert block coords to chunks coords:
+ int MinChunkX, MaxChunkX;
+ int MinChunkZ, MaxChunkZ;
+ int MinBlockX = a_MinBlockX;
+ int MinBlockY = a_MinBlockY;
+ int MinBlockZ = a_MinBlockZ;
+ int MaxBlockX = a_MinBlockX + a_Area.GetSizeX();
+ int MaxBlockY = a_MinBlockY + a_Area.GetSizeY();
+ int MaxBlockZ = a_MinBlockZ + a_Area.GetSizeZ();
+ cChunkDef::AbsoluteToRelative(MinBlockX, MinBlockY, MinBlockZ, MinChunkX, MinChunkZ);
+ cChunkDef::AbsoluteToRelative(MaxBlockX, MaxBlockY, MaxBlockZ, MaxChunkX, MaxChunkZ);
+
+ // Iterate over chunks, write data into each:
+ bool Result = true;
+ cCSLock Lock(m_CSLayers);
+ for (int z = MinChunkZ; z <= MaxChunkZ; z++)
+ {
+ for (int x = MinChunkX; x <= MaxChunkX; x++)
+ {
+ cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z);
+ if ((Chunk == NULL) || (!Chunk->IsValid()))
+ {
+ // Not present / not valid
+ Result = false;
+ continue;
+ }
+ Chunk->WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
+ } // for x
+ } // for z
+ return Result;
+}
+
+
+
+
+
void cChunkMap::GetChunkStats(int & a_NumChunksValid, int & a_NumChunksDirty)
{
a_NumChunksValid = 0;