Skip to content

Commit 9a17b65

Browse files
authoredJul 26, 2017
VoxelManip cleanups (const ref, const move) + function removal (#6169)
* VoxelManip cleanups (const ref, const move) permitting to improve a little bit performance * VoxelArea: precalculate extent (performance enhancement) This permits to reduce extend high cost to zero and drop many v3s16 object creation/removal to calculate extent It rebalance the client thread update to updateFastFaceRow instead of MapBlockMesh generation This will also benefits to mapgen
1 parent 0c99da4 commit 9a17b65

13 files changed

+85
-198
lines changed
 

‎src/cavegen.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
7373
noise_cave1->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);
7474
noise_cave2->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);
7575

76-
v3s16 em = vm->m_area.getExtent();
76+
const v3s16 &em = vm->m_area.getExtent();
7777
u32 index2d = 0; // Biomemap index
7878

7979
for (s16 z = nmin.Z; z <= nmax.Z; z++)
@@ -208,7 +208,7 @@ bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax)
208208

209209
//// Place nodes
210210
bool near_cavern = false;
211-
v3s16 em = vm->m_area.getExtent();
211+
const v3s16 &em = vm->m_area.getExtent();
212212
u32 index2d = 0;
213213

214214
for (s16 z = nmin.Z; z <= nmax.Z; z++)

‎src/dungeongen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax)
151151

152152
void DungeonGen::makeDungeon(v3s16 start_padding)
153153
{
154-
v3s16 areasize = vm->m_area.getExtent();
154+
const v3s16 &areasize = vm->m_area.getExtent();
155155
v3s16 roomsize;
156156
v3s16 roomplace;
157157

‎src/mapblock_mesh.cpp

+12-20
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ u16 getFaceLight(MapNode n, MapNode n2, v3s16 face_dir, INodeDefManager *ndef)
202202
Calculate smooth lighting at the XYZ- corner of p.
203203
Both light banks
204204
*/
205-
static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data)
205+
static u16 getSmoothLightCombined(const v3s16 &p, MeshMakeData *data)
206206
{
207207
static const v3s16 dirs8[8] = {
208208
v3s16(0,0,0),
@@ -855,11 +855,10 @@ static void getTileInfo(
855855
*/
856856
static void updateFastFaceRow(
857857
MeshMakeData *data,
858-
v3s16 startpos,
858+
const v3s16 &&startpos,
859859
v3s16 translate_dir,
860-
v3f translate_dir_f,
861-
v3s16 face_dir,
862-
v3f face_dir_f,
860+
const v3f &&translate_dir_f,
861+
const v3s16 &&face_dir,
863862
std::vector<FastFace> &dest)
864863
{
865864
v3s16 p = startpos;
@@ -966,7 +965,6 @@ static void updateAllFastFaceRows(MeshMakeData *data,
966965
v3s16(1,0,0), //dir
967966
v3f (1,0,0),
968967
v3s16(0,1,0), //face dir
969-
v3f (0,1,0),
970968
dest);
971969
}
972970
}
@@ -981,7 +979,6 @@ static void updateAllFastFaceRows(MeshMakeData *data,
981979
v3s16(0,0,1), //dir
982980
v3f (0,0,1),
983981
v3s16(1,0,0), //face dir
984-
v3f (1,0,0),
985982
dest);
986983
}
987984
}
@@ -996,7 +993,6 @@ static void updateAllFastFaceRows(MeshMakeData *data,
996993
v3s16(1,0,0), //dir
997994
v3f (1,0,0),
998995
v3s16(0,0,1), //face dir
999-
v3f (0,0,1),
1000996
dest);
1001997
}
1002998
}
@@ -1525,14 +1521,12 @@ void MeshCollector::applyTileColors()
15251521
{
15261522
if (m_use_tangent_vertices)
15271523
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
1528-
std::vector<PreMeshBuffer> *p = &prebuffers[layer];
1529-
for (std::vector<PreMeshBuffer>::iterator it = p->begin();
1530-
it != p->end(); ++it) {
1531-
video::SColor tc = it->layer.color;
1524+
for (auto &pmb : prebuffers[layer]) {
1525+
video::SColor tc = pmb.layer.color;
15321526
if (tc == video::SColor(0xFFFFFFFF))
15331527
continue;
1534-
for (u32 index = 0; index < it->tangent_vertices.size(); index++) {
1535-
video::SColor *c = &it->tangent_vertices[index].Color;
1528+
for (auto &tangent_vertice : pmb.tangent_vertices) {
1529+
video::SColor *c = &tangent_vertice.Color;
15361530
c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
15371531
c->getGreen() * tc.getGreen() / 255,
15381532
c->getBlue() * tc.getBlue() / 255);
@@ -1541,14 +1535,12 @@ void MeshCollector::applyTileColors()
15411535
}
15421536
else
15431537
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
1544-
std::vector<PreMeshBuffer> *p = &prebuffers[layer];
1545-
for (std::vector<PreMeshBuffer>::iterator it = p->begin();
1546-
it != p->end(); ++it) {
1547-
video::SColor tc = it->layer.color;
1538+
for (auto &pmb : prebuffers[layer]) {
1539+
video::SColor tc = pmb.layer.color;
15481540
if (tc == video::SColor(0xFFFFFFFF))
15491541
continue;
1550-
for (u32 index = 0; index < it->vertices.size(); index++) {
1551-
video::SColor *c = &it->vertices[index].Color;
1542+
for (auto &vertice : pmb.vertices) {
1543+
video::SColor *c = &vertice.Color;
15521544
c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
15531545
c->getGreen() * tc.getGreen() / 255,
15541546
c->getBlue() * tc.getBlue() / 255);

‎src/mapgen.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ u32 Mapgen::getBlockSeed2(v3s16 p, s32 seed)
237237
// Returns Y one under area minimum if not found
238238
s16 Mapgen::findGroundLevelFull(v2s16 p2d)
239239
{
240-
v3s16 em = vm->m_area.getExtent();
240+
const v3s16 &em = vm->m_area.getExtent();
241241
s16 y_nodes_max = vm->m_area.MaxEdge.Y;
242242
s16 y_nodes_min = vm->m_area.MinEdge.Y;
243243
u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
@@ -257,7 +257,7 @@ s16 Mapgen::findGroundLevelFull(v2s16 p2d)
257257
// Returns -MAX_MAP_GENERATION_LIMIT if not found
258258
s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
259259
{
260-
v3s16 em = vm->m_area.getExtent();
260+
const v3s16 &em = vm->m_area.getExtent();
261261
u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
262262
s16 y;
263263

@@ -275,7 +275,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
275275
// Returns -MAX_MAP_GENERATION_LIMIT if not found or if ground is found first
276276
s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
277277
{
278-
v3s16 em = vm->m_area.getExtent();
278+
const v3s16 &em = vm->m_area.getExtent();
279279
u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
280280
s16 y;
281281

@@ -344,7 +344,7 @@ inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3s16 em)
344344
void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax)
345345
{
346346
bool isignored, isliquid, wasignored, wasliquid, waschecked, waspushed;
347-
v3s16 em = vm->m_area.getExtent();
347+
const v3s16 &em = vm->m_area.getExtent();
348348

349349
for (s16 z = nmin.Z + 1; z <= nmax.Z - 1; z++)
350350
for (s16 x = nmin.X + 1; x <= nmax.X - 1; x++) {
@@ -467,7 +467,7 @@ void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow)
467467
//TimeTaker t("propagateSunlight");
468468
VoxelArea a(nmin, nmax);
469469
bool block_is_underground = (water_level >= nmax.Y);
470-
v3s16 em = vm->m_area.getExtent();
470+
const v3s16 &em = vm->m_area.getExtent();
471471

472472
// NOTE: Direct access to the low 4 bits of param1 is okay here because,
473473
// by definition, sunlight will never be in the night lightbank.
@@ -627,7 +627,7 @@ MgStoneType MapgenBasic::generateBiomes(s16 biome_zero_level)
627627
assert(biomegen);
628628
assert(biomemap);
629629

630-
v3s16 em = vm->m_area.getExtent();
630+
const v3s16 &em = vm->m_area.getExtent();
631631
u32 index = 0;
632632
MgStoneType stone_type = MGSTONE_STONE;
633633

@@ -764,7 +764,7 @@ void MapgenBasic::dustTopNodes()
764764
if (node_max.Y < water_level)
765765
return;
766766

767-
v3s16 em = vm->m_area.getExtent();
767+
const v3s16 &em = vm->m_area.getExtent();
768768
u32 index = 0;
769769

770770
for (s16 z = node_min.Z; z <= node_max.Z; z++)

‎src/mapgen_flat.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ s16 MapgenFlat::generateTerrain()
230230
MapNode n_stone(c_stone);
231231
MapNode n_water(c_water_source);
232232

233-
v3s16 em = vm->m_area.getExtent();
233+
const v3s16 &em = vm->m_area.getExtent();
234234
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
235235
u32 ni2d = 0;
236236

‎src/mapgen_v6.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void MapgenV6Params::writeParams(Settings *settings) const
206206
// Returns Y one under area minimum if not found
207207
s16 MapgenV6::find_stone_level(v2s16 p2d)
208208
{
209-
v3s16 em = vm->m_area.getExtent();
209+
const v3s16 &em = vm->m_area.getExtent();
210210
s16 y_nodes_max = vm->m_area.MaxEdge.Y;
211211
s16 y_nodes_min = vm->m_area.MinEdge.Y;
212212
u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
@@ -681,7 +681,7 @@ int MapgenV6::generateGround()
681681
BiomeV6Type bt = getBiome(v2s16(x, z));
682682

683683
// Fill ground with stone
684-
v3s16 em = vm->m_area.getExtent();
684+
const v3s16 &em = vm->m_area.getExtent();
685685
u32 i = vm->m_area.index(x, node_min.Y, z);
686686
for (s16 y = node_min.Y; y <= node_max.Y; y++) {
687687
if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
@@ -750,7 +750,7 @@ void MapgenV6::addMud()
750750

751751
// Add mud on ground
752752
s16 mudcount = 0;
753-
v3s16 em = vm->m_area.getExtent();
753+
const v3s16 &em = vm->m_area.getExtent();
754754
s16 y_start = surface_y + 1;
755755
u32 i = vm->m_area.index(x, y_start, z);
756756
for (s16 y = y_start; y <= node_max.Y; y++) {
@@ -784,7 +784,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
784784
// Node position in 2d
785785
v2s16 p2d = v2s16(node_min.X, node_min.Z) + v2s16(x, z);
786786

787-
v3s16 em = vm->m_area.getExtent();
787+
const v3s16 &em = vm->m_area.getExtent();
788788
u32 i = vm->m_area.index(p2d.X, node_max.Y, p2d.Y);
789789
s16 y = node_max.Y;
790790

@@ -947,7 +947,7 @@ void MapgenV6::placeTreesAndJungleGrass()
947947
if (c_junglegrass == CONTENT_IGNORE)
948948
c_junglegrass = CONTENT_AIR;
949949
MapNode n_junglegrass(c_junglegrass);
950-
v3s16 em = vm->m_area.getExtent();
950+
const v3s16 &em = vm->m_area.getExtent();
951951

952952
// Divide area into parts
953953
s16 div = 8;
@@ -1055,7 +1055,7 @@ void MapgenV6::growGrass() // Add surface nodes
10551055
MapNode n_dirt_with_snow(c_dirt_with_snow);
10561056
MapNode n_snowblock(c_snowblock);
10571057
MapNode n_snow(c_snow);
1058-
v3s16 em = vm->m_area.getExtent();
1058+
const v3s16 &em = vm->m_area.getExtent();
10591059

10601060
u32 index = 0;
10611061
for (s16 z = full_node_min.Z; z <= full_node_max.Z; z++)

‎src/mapgen_v7.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ int MapgenV7::generateTerrain()
489489
}
490490

491491
//// Place nodes
492-
v3s16 em = vm->m_area.getExtent();
492+
const v3s16 &em = vm->m_area.getExtent();
493493
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
494494
u32 index2d = 0;
495495

‎src/mapgen_valleys.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ int MapgenValleys::generateTerrain()
475475
MapNode n_stone(c_stone);
476476
MapNode n_water(c_water_source);
477477

478-
v3s16 em = vm->m_area.getExtent();
478+
const v3s16 &em = vm->m_area.getExtent();
479479
s16 surface_max_y = -MAX_MAP_GENERATION_LIMIT;
480480
u32 index_2d = 0;
481481

@@ -597,7 +597,7 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth)
597597
MapNode n_lava(c_lava_source);
598598
MapNode n_water(c_river_water_source);
599599

600-
v3s16 em = vm->m_area.getExtent();
600+
const v3s16 &em = vm->m_area.getExtent();
601601

602602
// Cave blend distance near YMIN, YMAX
603603
const float massive_cave_blend = 128.f;

‎src/mg_decoration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
299299

300300
bool force_placement = (flags & DECO_FORCE_PLACEMENT);
301301

302-
v3s16 em = vm->m_area.getExtent();
302+
const v3s16 &em = vm->m_area.getExtent();
303303
u32 vi = vm->m_area.index(p);
304304
for (int i = 0; i < height; i++) {
305305
vm->m_area.add_y(em, vi, 1);

‎src/minimap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void Minimap::updateActiveMarkers()
606606
//// MinimapMapblock
607607
////
608608

609-
void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, v3s16 pos)
609+
void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos)
610610
{
611611

612612
for (s16 x = 0; x < MAP_BLOCKSIZE; x++)

‎src/minimap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct MinimapPixel {
6363
};
6464

6565
struct MinimapMapblock {
66-
void getMinimapNodes(VoxelManipulator *vmanip, v3s16 pos);
66+
void getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos);
6767

6868
MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
6969
};

‎src/voxel.cpp

+3-34
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void VoxelManipulator::clear()
5555
void VoxelManipulator::print(std::ostream &o, INodeDefManager *ndef,
5656
VoxelPrintMode mode)
5757
{
58-
v3s16 em = m_area.getExtent();
58+
const v3s16 &em = m_area.getExtent();
5959
v3s16 of = m_area.MinEdge;
6060
o<<"size: "<<em.X<<"x"<<em.Y<<"x"<<em.Z
6161
<<" offset: ("<<of.X<<","<<of.Y<<","<<of.Z<<")"<<std::endl;
@@ -208,7 +208,7 @@ void VoxelManipulator::addArea(const VoxelArea &area)
208208
}
209209

210210
void VoxelManipulator::copyFrom(MapNode *src, const VoxelArea& src_area,
211-
v3s16 from_pos, v3s16 to_pos, v3s16 size)
211+
v3s16 from_pos, v3s16 to_pos, const v3s16 &size)
212212
{
213213
/* The reason for this optimised code is that we're a member function
214214
* and the data type/layout of m_data is know to us: it's stored as
@@ -256,7 +256,7 @@ void VoxelManipulator::copyFrom(MapNode *src, const VoxelArea& src_area,
256256
}
257257

258258
void VoxelManipulator::copyTo(MapNode *dst, const VoxelArea& dst_area,
259-
v3s16 dst_pos, v3s16 from_pos, v3s16 size)
259+
v3s16 dst_pos, v3s16 from_pos, const v3s16 &size)
260260
{
261261
for(s16 z=0; z<size.Z; z++)
262262
for(s16 y=0; y<size.Y; y++)
@@ -384,37 +384,6 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
384384
}
385385
}
386386

387-
/*
388-
Goes recursively through the neighbours of the node.
389-
390-
Alters only transparent nodes.
391-
392-
If the lighting of the neighbour is lower than the lighting of
393-
the node was (before changing it to 0 at the step before), the
394-
lighting of the neighbour is set to 0 and then the same stuff
395-
repeats for the neighbour.
396-
397-
The ending nodes of the routine are stored in light_sources.
398-
This is useful when a light is removed. In such case, this
399-
routine can be called for the light node and then again for
400-
light_sources to re-light the area without the removed light.
401-
402-
values of from_nodes are lighting values.
403-
*/
404-
void VoxelManipulator::unspreadLight(enum LightBank bank,
405-
std::map<v3s16, u8> & from_nodes,
406-
std::set<v3s16> & light_sources, INodeDefManager *nodemgr)
407-
{
408-
if(from_nodes.empty())
409-
return;
410-
411-
for(std::map<v3s16, u8>::iterator j = from_nodes.begin();
412-
j != from_nodes.end(); ++j)
413-
{
414-
unspreadLight(bank, j->first, j->second, light_sources, nodemgr);
415-
}
416-
}
417-
418387
void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p,
419388
INodeDefManager *nodemgr)
420389
{

‎src/voxel.h

+47-121
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include "mapnode.h"
2929
#include <set>
3030
#include <list>
31-
#include <map>
31+
#include "util/basic_macros.h"
3232

3333
class INodeDefManager;
3434

@@ -62,15 +62,18 @@ class VoxelArea
6262
// Starts as zero sized
6363
VoxelArea() {}
6464

65-
VoxelArea(v3s16 min_edge, v3s16 max_edge):
65+
VoxelArea(const v3s16 &min_edge, const v3s16 &max_edge):
6666
MinEdge(min_edge),
6767
MaxEdge(max_edge)
6868
{
69+
cacheExtent();
6970
}
70-
VoxelArea(v3s16 p):
71+
72+
VoxelArea(const v3s16 &p):
7173
MinEdge(p),
7274
MaxEdge(p)
7375
{
76+
cacheExtent();
7477
}
7578

7679
/*
@@ -90,13 +93,16 @@ class VoxelArea
9093
if(a.MaxEdge.X > MaxEdge.X) MaxEdge.X = a.MaxEdge.X;
9194
if(a.MaxEdge.Y > MaxEdge.Y) MaxEdge.Y = a.MaxEdge.Y;
9295
if(a.MaxEdge.Z > MaxEdge.Z) MaxEdge.Z = a.MaxEdge.Z;
96+
cacheExtent();
9397
}
98+
9499
void addPoint(const v3s16 &p)
95100
{
96101
if(hasEmptyExtent())
97102
{
98103
MinEdge = p;
99104
MaxEdge = p;
105+
cacheExtent();
100106
return;
101107
}
102108
if(p.X < MinEdge.X) MinEdge.X = p.X;
@@ -105,6 +111,7 @@ class VoxelArea
105111
if(p.X > MaxEdge.X) MaxEdge.X = p.X;
106112
if(p.Y > MaxEdge.Y) MaxEdge.Y = p.Y;
107113
if(p.Z > MaxEdge.Z) MaxEdge.Z = p.Z;
114+
cacheExtent();
108115
}
109116

110117
// Pad with d nodes
@@ -114,25 +121,13 @@ class VoxelArea
114121
MaxEdge += d;
115122
}
116123

117-
/*void operator+=(v3s16 off)
118-
{
119-
MinEdge += off;
120-
MaxEdge += off;
121-
}
122-
123-
void operator-=(v3s16 off)
124-
{
125-
MinEdge -= off;
126-
MaxEdge -= off;
127-
}*/
128-
129124
/*
130125
const methods
131126
*/
132127

133-
v3s16 getExtent() const
128+
const v3s16 &getExtent() const
134129
{
135-
return MaxEdge - MinEdge + v3s16(1,1,1);
130+
return m_cache_extent;
136131
}
137132

138133
/* Because MaxEdge and MinEdge are included in the voxel area an empty extent
@@ -145,9 +140,9 @@ class VoxelArea
145140

146141
s32 getVolume() const
147142
{
148-
v3s16 e = getExtent();
149-
return (s32)e.X * (s32)e.Y * (s32)e.Z;
143+
return (s32)m_cache_extent.X * (s32)m_cache_extent.Y * (s32)m_cache_extent.Z;
150144
}
145+
151146
bool contains(const VoxelArea &a) const
152147
{
153148
// No area contains an empty area
@@ -179,12 +174,12 @@ class VoxelArea
179174
&& MaxEdge == other.MaxEdge);
180175
}
181176

182-
VoxelArea operator+(v3s16 off) const
177+
VoxelArea operator+(const v3s16 &off) const
183178
{
184179
return VoxelArea(MinEdge+off, MaxEdge+off);
185180
}
186181

187-
VoxelArea operator-(v3s16 off) const
182+
VoxelArea operator-(const v3s16 &off) const
188183
{
189184
return VoxelArea(MinEdge-off, MaxEdge-off);
190185
}
@@ -273,10 +268,9 @@ class VoxelArea
273268
*/
274269
s32 index(s16 x, s16 y, s16 z) const
275270
{
276-
v3s16 em = getExtent();
277-
v3s16 off = MinEdge;
278-
s32 i = (s32)(z-off.Z)*em.Y*em.X + (y-off.Y)*em.X + (x-off.X);
279-
//dstream<<" i("<<x<<","<<y<<","<<z<<")="<<i<<" ";
271+
s32 i = (s32)(z - MinEdge.Z) * m_cache_extent.Y * m_cache_extent.X
272+
+ (y - MinEdge.Y) * m_cache_extent.X
273+
+ (x - MinEdge.X);
280274
return i;
281275
}
282276
s32 index(v3s16 p) const
@@ -310,20 +304,21 @@ class VoxelArea
310304
*/
311305
void print(std::ostream &o) const
312306
{
313-
v3s16 e = getExtent();
314-
o<<"("<<MinEdge.X
315-
<<","<<MinEdge.Y
316-
<<","<<MinEdge.Z
317-
<<")("<<MaxEdge.X
318-
<<","<<MaxEdge.Y
319-
<<","<<MaxEdge.Z
320-
<<")"
321-
<<"="<<e.X<<"x"<<e.Y<<"x"<<e.Z<<"="<<getVolume();
307+
o << PP(MinEdge) << PP(MaxEdge) << "="
308+
<< m_cache_extent.X << "x" << m_cache_extent.Y << "x" << m_cache_extent.Z
309+
<< "=" << getVolume();
322310
}
323311

324312
// Edges are inclusive
325313
v3s16 MinEdge = v3s16(1,1,1);
326314
v3s16 MaxEdge;
315+
private:
316+
void cacheExtent()
317+
{
318+
m_cache_extent = MaxEdge - MinEdge + v3s16(1,1,1);
319+
}
320+
321+
v3s16 m_cache_extent = v3s16(0,0,0);
327322
};
328323

329324
// unused
@@ -347,36 +342,22 @@ enum VoxelPrintMode
347342
VOXELPRINT_LIGHT_DAY,
348343
};
349344

350-
class VoxelManipulator /*: public NodeContainer*/
345+
class VoxelManipulator
351346
{
352347
public:
353348
VoxelManipulator();
354349
virtual ~VoxelManipulator();
355350

356-
/*
357-
Virtuals from NodeContainer
358-
*/
359-
/*virtual u16 nodeContainerId() const
360-
{
361-
return NODECONTAINER_ID_VOXELMANIPULATOR;
362-
}
363-
bool isValidPosition(v3s16 p)
364-
{
365-
addArea(p);
366-
return !(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA);
367-
}*/
368-
369351
/*
370352
These are a bit slow and shouldn't be used internally.
371353
Use m_data[m_area.index(p)] instead.
372354
*/
373-
MapNode getNode(v3s16 p)
355+
MapNode getNode(const v3s16 &p)
374356
{
375357
VoxelArea voxel_area(p);
376358
addArea(voxel_area);
377359

378-
if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA)
379-
{
360+
if (m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) {
380361
/*dstream<<"EXCEPT: VoxelManipulator::getNode(): "
381362
<<"p=("<<p.X<<","<<p.Y<<","<<p.Z<<")"
382363
<<", index="<<m_area.index(p)
@@ -388,23 +369,22 @@ class VoxelManipulator /*: public NodeContainer*/
388369

389370
return m_data[m_area.index(p)];
390371
}
391-
MapNode getNodeNoEx(v3s16 p)
372+
MapNode getNodeNoEx(const v3s16 &p)
392373
{
393374
VoxelArea voxel_area(p);
394375
addArea(voxel_area);
395376

396-
if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA)
397-
{
377+
if (m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) {
398378
return MapNode(CONTENT_IGNORE);
399379
}
400380

401381
return m_data[m_area.index(p)];
402382
}
403-
MapNode getNodeNoExNoEmerge(v3s16 p)
383+
MapNode getNodeNoExNoEmerge(const v3s16 &p)
404384
{
405-
if(m_area.contains(p) == false)
385+
if (!m_area.contains(p))
406386
return MapNode(CONTENT_IGNORE);
407-
if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA)
387+
if (m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA)
408388
return MapNode(CONTENT_IGNORE);
409389
return m_data[m_area.index(p)];
410390
}
@@ -425,32 +405,18 @@ class VoxelManipulator /*: public NodeContainer*/
425405
return m_data[index];
426406
}
427407

428-
u8 & getFlagsRefUnsafe(v3s16 p)
408+
u8 & getFlagsRefUnsafe(const v3s16 &p)
429409
{
430410
return m_flags[m_area.index(p)];
431411
}
432-
bool exists(v3s16 p)
412+
413+
bool exists(const v3s16 &p)
433414
{
434415
return m_area.contains(p) &&
435416
!(getFlagsRefUnsafe(p) & VOXELFLAG_NO_DATA);
436417
}
437-
MapNode & getNodeRef(v3s16 p)
438-
{
439-
VoxelArea voxel_area(p);
440-
addArea(voxel_area);
441-
if(getFlagsRefUnsafe(p) & VOXELFLAG_NO_DATA)
442-
{
443-
/*dstream<<"EXCEPT: VoxelManipulator::getNode(): "
444-
<<"p=("<<p.X<<","<<p.Y<<","<<p.Z<<")"
445-
<<", index="<<m_area.index(p)
446-
<<", flags="<<(int)getFlagsRefUnsafe(p)
447-
<<" is inexistent"<<std::endl;*/
448-
throw InvalidPositionException
449-
("VoxelManipulator: getNode: inexistent");
450-
}
451-
return getNodeRefUnsafe(p);
452-
}
453-
void setNode(v3s16 p, const MapNode &n)
418+
419+
void setNode(const v3s16 &p, const MapNode &n)
454420
{
455421
VoxelArea voxel_area(p);
456422
addArea(voxel_area);
@@ -459,57 +425,24 @@ class VoxelManipulator /*: public NodeContainer*/
459425
m_flags[m_area.index(p)] &= ~VOXELFLAG_NO_DATA;
460426
}
461427
// TODO: Should be removed and replaced with setNode
462-
void setNodeNoRef(v3s16 p, const MapNode &n)
428+
void setNodeNoRef(const v3s16 &p, const MapNode &n)
463429
{
464430
setNode(p, n);
465431
}
466432

467-
/*void setExists(VoxelArea a)
468-
{
469-
addArea(a);
470-
for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
471-
for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++)
472-
for(s32 x=a.MinEdge.X; x<=a.MaxEdge.X; x++)
473-
{
474-
m_flags[m_area.index(x,y,z)] &= ~VOXELFLAG_NO_DATA;
475-
}
476-
}*/
477-
478-
/*MapNode & operator[](v3s16 p)
479-
{
480-
//dstream<<"operator[] p=("<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;
481-
if(isValidPosition(p) == false)
482-
addArea(VoxelArea(p));
483-
484-
return m_data[m_area.index(p)];
485-
}*/
486-
487433
/*
488434
Set stuff if available without an emerge.
489435
Return false if failed.
490436
This is convenient but slower than playing around directly
491437
with the m_data table with indices.
492438
*/
493-
bool setNodeNoEmerge(v3s16 p, MapNode n)
439+
bool setNodeNoEmerge(const v3s16 &p, MapNode n)
494440
{
495-
if(m_area.contains(p) == false)
441+
if(!m_area.contains(p))
496442
return false;
497443
m_data[m_area.index(p)] = n;
498444
return true;
499445
}
500-
bool setNodeNoEmerge(s32 i, MapNode n)
501-
{
502-
if(m_area.contains(i) == false)
503-
return false;
504-
m_data[i] = n;
505-
return true;
506-
}
507-
/*bool setContentNoEmerge(v3s16 p, u8 c)
508-
{
509-
if(isValidPosition(p) == false)
510-
return false;
511-
m_data[m_area.index(p)].d = c;
512-
}*/
513446

514447
/*
515448
Control
@@ -527,11 +460,11 @@ class VoxelManipulator /*: public NodeContainer*/
527460
dst_area.getExtent() <= src_area.getExtent()
528461
*/
529462
void copyFrom(MapNode *src, const VoxelArea& src_area,
530-
v3s16 from_pos, v3s16 to_pos, v3s16 size);
463+
v3s16 from_pos, v3s16 to_pos, const v3s16 &size);
531464

532465
// Copy data
533466
void copyTo(MapNode *dst, const VoxelArea& dst_area,
534-
v3s16 dst_pos, v3s16 from_pos, v3s16 size);
467+
v3s16 dst_pos, v3s16 from_pos, const v3s16 &size);
535468

536469
/*
537470
Algorithms
@@ -543,18 +476,11 @@ class VoxelManipulator /*: public NodeContainer*/
543476

544477
void unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
545478
std::set<v3s16> & light_sources, INodeDefManager *nodemgr);
546-
void unspreadLight(enum LightBank bank,
547-
std::map<v3s16, u8> & from_nodes,
548-
std::set<v3s16> & light_sources, INodeDefManager *nodemgr);
549479

550480
void spreadLight(enum LightBank bank, v3s16 p, INodeDefManager *nodemgr);
551481
void spreadLight(enum LightBank bank,
552482
std::set<v3s16> & from_nodes, INodeDefManager *nodemgr);
553483

554-
/*
555-
Virtual functions
556-
*/
557-
558484
/*
559485
Member variables
560486
*/

0 commit comments

Comments
 (0)
Please sign in to comment.