VoxelArea: add_{x,y,z,p} must be static

Fix some documentations issues
Use getNodeNoCheck(v3s16, ...) in some cases instead of getNodeNoCheck(x, y, z, ...)
This commit is contained in:
Loic Blot 2018-03-09 08:49:00 +01:00 committed by Loïc Blot
parent 3b27cf30d9
commit 12d1e4ff04
11 changed files with 72 additions and 61 deletions

@ -100,7 +100,7 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
// This 'roof' is removed when the mapchunk above is generated.
for (s16 y = nmax.Y; y >= nmin.Y - 1; y--,
index3d -= m_ystride,
vm->m_area.add_y(em, vi, -1)) {
VoxelArea::add_y(em, vi, -1)) {
content_t c = vm->m_data[vi].getContent();
if (c == CONTENT_AIR || c == biome->c_water_top ||
@ -245,7 +245,7 @@ bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax)
// This 'roof' is excavated when the mapchunk above is generated.
for (s16 y = nmax.Y; y >= nmin.Y - 1; y--,
index3d -= m_ystride,
vm->m_area.add_y(em, vi, -1),
VoxelArea::add_y(em, vi, -1),
cavern_amp_index++) {
content_t c = vm->m_data[vi].getContent();
float n_absamp_cavern = fabs(noise_cavern->result[index3d]) *

@ -238,7 +238,7 @@ s16 Mapgen::findGroundLevelFull(v2s16 p2d)
if (ndef->get(n).walkable)
break;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
}
return (y >= y_nodes_min) ? y : y_nodes_min - 1;
}
@ -256,7 +256,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
if (ndef->get(n).walkable)
break;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
}
return (y >= ymin) ? y : -MAX_MAP_GENERATION_LIMIT;
}
@ -277,7 +277,7 @@ s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
if (ndef->get(n).isLiquid())
break;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
}
return (y >= ymin) ? y : -MAX_MAP_GENERATION_LIMIT;
}
@ -309,7 +309,7 @@ void Mapgen::getSurfaces(v2s16 p2d, s16 ymin, s16 ymax,
u32 vi = vm->m_area.index(p2d.X, ymax, p2d.Y);
MapNode mn_max = vm->m_data[vi];
bool walkable_above = ndef->get(mn_max).walkable;
vm->m_area.add_y(em, vi, -1);
VoxelArea::add_y(em, vi, -1);
for (s16 y = ymax - 1; y >= ymin; y--) {
MapNode mn = vm->m_data[vi];
@ -321,7 +321,7 @@ void Mapgen::getSurfaces(v2s16 p2d, s16 ymin, s16 ymax,
ceilings.push_back(y + 1);
}
vm->m_area.add_y(em, vi, -1);
VoxelArea::add_y(em, vi, -1);
walkable_above = is_walkable;
}
}
@ -330,28 +330,28 @@ void Mapgen::getSurfaces(v2s16 p2d, s16 ymin, s16 ymax,
inline bool Mapgen::isLiquidHorizontallyFlowable(u32 vi, v3s16 em)
{
u32 vi_neg_x = vi;
vm->m_area.add_x(em, vi_neg_x, -1);
VoxelArea::add_x(em, vi_neg_x, -1);
if (vm->m_data[vi_neg_x].getContent() != CONTENT_IGNORE) {
const ContentFeatures &c_nx = ndef->get(vm->m_data[vi_neg_x]);
if (c_nx.floodable && !c_nx.isLiquid())
return true;
}
u32 vi_pos_x = vi;
vm->m_area.add_x(em, vi_pos_x, +1);
VoxelArea::add_x(em, vi_pos_x, +1);
if (vm->m_data[vi_pos_x].getContent() != CONTENT_IGNORE) {
const ContentFeatures &c_px = ndef->get(vm->m_data[vi_pos_x]);
if (c_px.floodable && !c_px.isLiquid())
return true;
}
u32 vi_neg_z = vi;
vm->m_area.add_z(em, vi_neg_z, -1);
VoxelArea::add_z(em, vi_neg_z, -1);
if (vm->m_data[vi_neg_z].getContent() != CONTENT_IGNORE) {
const ContentFeatures &c_nz = ndef->get(vm->m_data[vi_neg_z]);
if (c_nz.floodable && !c_nz.isLiquid())
return true;
}
u32 vi_pos_z = vi;
vm->m_area.add_z(em, vi_pos_z, +1);
VoxelArea::add_z(em, vi_pos_z, +1);
if (vm->m_data[vi_pos_z].getContent() != CONTENT_IGNORE) {
const ContentFeatures &c_pz = ndef->get(vm->m_data[vi_pos_z]);
if (c_pz.floodable && !c_pz.isLiquid())
@ -395,7 +395,7 @@ void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nm
} else {
// This is the topmost node below a liquid column
u32 vi_above = vi;
vm->m_area.add_y(em, vi_above, 1);
VoxelArea::add_y(em, vi_above, 1);
if (!waspushed && (ndef->get(vm->m_data[vi]).floodable ||
(!waschecked && isLiquidHorizontallyFlowable(vi_above, em)))) {
// Push back the lowest node in the column which is one
@ -406,7 +406,7 @@ void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nm
wasliquid = isliquid;
wasignored = isignored;
vm->m_area.add_y(em, vi, -1);
VoxelArea::add_y(em, vi, -1);
}
}
}
@ -502,14 +502,14 @@ void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow)
propagate_shadow) {
continue;
}
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
for (int y = a.MaxEdge.Y; y >= a.MinEdge.Y; y--) {
MapNode &n = vm->m_data[i];
if (!ndef->get(n).sunlight_propagates)
break;
n.param1 = LIGHT_SUN;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
}
}
}
@ -773,7 +773,7 @@ void MapgenBasic::generateBiomes(MgStoneType *mgstone_type,
water_above = false;
}
vm->m_area.add_y(em, vi, -1);
VoxelArea::add_y(em, vi, -1);
}
}
@ -820,7 +820,7 @@ void MapgenBasic::dustTopNodes()
if (vm->m_data[vi].getContent() != CONTENT_AIR)
break;
vm->m_area.add_y(em, vi, -1);
VoxelArea::add_y(em, vi, -1);
}
content_t c = vm->m_data[vi].getContent();
@ -834,7 +834,7 @@ void MapgenBasic::dustTopNodes()
dtype == NDT_GLASSLIKE_FRAMED ||
dtype == NDT_ALLFACES) &&
ndef->get(c).walkable && c != biome->c_dust) {
vm->m_area.add_y(em, vi, 1);
VoxelArea::add_y(em, vi, 1);
vm->m_data[vi] = MapNode(biome->c_dust);
}
}

@ -273,7 +273,7 @@ s16 MapgenFlat::generateTerrain()
vm->m_data[vi] = n_air;
}
}
vm->m_area.add_y(em, vi, 1);
VoxelArea::add_y(em, vi, 1);
}
}

@ -223,7 +223,7 @@ s16 MapgenV6::find_stone_level(v2s16 p2d)
if (c != CONTENT_IGNORE && (c == c_stone || c == c_desert_stone))
break;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
}
return (y >= y_nodes_min) ? y : y_nodes_min - 1;
}
@ -696,7 +696,7 @@ int MapgenV6::generateGround()
vm->m_data[i] = n_air;
}
}
vm->m_area.add_y(em, i, 1);
VoxelArea::add_y(em, i, 1);
}
}
@ -759,7 +759,7 @@ void MapgenV6::addMud()
vm->m_data[i] = addnode;
mudcount++;
vm->m_area.add_y(em, i, 1);
VoxelArea::add_y(em, i, 1);
}
}
}
@ -799,7 +799,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
n->getContent() == c_gravel)
break;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
}
// Stop if out of area
@ -815,7 +815,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
// Don't flow it if the stuff under it is not mud
{
u32 i2 = i;
vm->m_area.add_y(em, i2, -1);
VoxelArea::add_y(em, i2, -1);
// Cancel if out of area
if (!vm->m_area.contains(i2))
continue;
@ -826,7 +826,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
}
}
v3s16 dirs4[4] = {
static const v3s16 dirs4[4] = {
v3s16(0, 0, 1), // back
v3s16(1, 0, 0), // right
v3s16(0, 0, -1), // front
@ -836,7 +836,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
// Check that upper is walkable. Cancel
// dropping if upper keeps it in place.
u32 i3 = i;
vm->m_area.add_y(em, i3, 1);
VoxelArea::add_y(em, i3, 1);
MapNode *n3 = NULL;
if (vm->m_area.contains(i3)) {
@ -849,7 +849,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
for (const v3s16 &dirp : dirs4) {
u32 i2 = i;
// Move to side
vm->m_area.add_p(em, i2, dirp);
VoxelArea::add_p(em, i2, dirp);
// Fail if out of area
if (!vm->m_area.contains(i2))
continue;
@ -858,7 +858,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
if (ndef->get(*n2).walkable)
continue;
// Check that under side is air
vm->m_area.add_y(em, i2, -1);
VoxelArea::add_y(em, i2, -1);
if (!vm->m_area.contains(i2))
continue;
n2 = &vm->m_data[i2];
@ -867,7 +867,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
// Loop further down until not air
bool dropped_to_unknown = false;
do {
vm->m_area.add_y(em, i2, -1);
VoxelArea::add_y(em, i2, -1);
n2 = &vm->m_data[i2];
// if out of known area
if (!vm->m_area.contains(i2) ||
@ -877,7 +877,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
}
} while (!ndef->get(*n2).walkable);
// Loop one up so that we're in air
vm->m_area.add_y(em, i2, 1);
VoxelArea::add_y(em, i2, 1);
// Move mud to new place. Outside mapchunk remove
// any decorations above removed or placed mud.
@ -917,17 +917,17 @@ void MapgenV6::moveMud(u32 remove_index, u32 place_index,
vm->m_data[above_remove_index].getContent() != c_water_source &&
vm->m_data[above_remove_index].getContent() != CONTENT_IGNORE) {
vm->m_data[above_remove_index] = n_air;
vm->m_area.add_y(em, above_remove_index, 1);
VoxelArea::add_y(em, above_remove_index, 1);
}
// Mud placed may have partially-buried a stacked decoration, search
// above and remove.
vm->m_area.add_y(em, place_index, 1);
VoxelArea::add_y(em, place_index, 1);
while (vm->m_area.contains(place_index) &&
vm->m_data[place_index].getContent() != CONTENT_AIR &&
vm->m_data[place_index].getContent() != c_water_source &&
vm->m_data[place_index].getContent() != CONTENT_IGNORE) {
vm->m_data[place_index] = n_air;
vm->m_area.add_y(em, place_index, 1);
VoxelArea::add_y(em, place_index, 1);
}
}
}
@ -1001,7 +1001,7 @@ void MapgenV6::placeTreesAndJungleGrass()
u32 vi = vm->m_area.index(x, y, z);
// place on dirt_with_grass, since we know it is exposed to sunlight
if (vm->m_data[vi].getContent() == c_dirt_with_grass) {
vm->m_area.add_y(em, vi, 1);
VoxelArea::add_y(em, vi, 1);
vm->m_data[vi] = n_junglegrass;
}
}
@ -1071,7 +1071,7 @@ void MapgenV6::growGrass() // Add surface nodes
ndef->get(n).liquid_type != LIQUID_NONE ||
n.getContent() == c_ice)
break;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
}
surface_y = (y >= full_node_min.Y) ? y : full_node_min.Y;
}
@ -1085,10 +1085,10 @@ void MapgenV6::growGrass() // Add surface nodes
} else if (bt == BT_TUNDRA) {
if (c == c_dirt) {
vm->m_data[i] = n_snowblock;
vm->m_area.add_y(em, i, -1);
VoxelArea::add_y(em, i, -1);
vm->m_data[i] = n_dirt_with_snow;
} else if (c == c_stone && surface_y < node_max.Y) {
vm->m_area.add_y(em, i, 1);
VoxelArea::add_y(em, i, 1);
vm->m_data[i] = n_snowblock;
}
} else if (c == c_dirt) {

@ -539,7 +539,7 @@ int MapgenV7::generateTerrain()
vm->m_data[vi] = n_air;
}
}
vm->m_area.add_y(em, vi, 1);
VoxelArea::add_y(em, vi, 1);
index3d += ystride;
}
}

@ -540,7 +540,7 @@ int MapgenValleys::generateTerrain()
}
}
vm->m_area.add_y(em, index_data, 1);
VoxelArea::add_y(em, index_data, 1);
index_3d += ystride;
}
@ -668,7 +668,7 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth)
// This 'roof' is removed when the mapchunk above is generated.
for (s16 y = node_max.Y; y >= node_min.Y - 1; y--,
index_3d -= ystride,
vm->m_area.add_y(em, index_data, -1)) {
VoxelArea::add_y(em, index_data, -1)) {
float terrain = noise_terrain_height->result[index_2d];
@ -705,7 +705,7 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth)
// at the tunnel floor
s16 sr = ps.range(0, 39);
u32 j = index_data;
vm->m_area.add_y(em, j, 1);
VoxelArea::add_y(em, j, 1);
if (sr > terrain - y) {
// Put biome nodes in tunnels near the surface

@ -301,10 +301,10 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
if (ceiling) {
// Ceiling decorations
// 'place offset y' is inverted
vm->m_area.add_y(em, vi, -place_offset_y);
VoxelArea::add_y(em, vi, -place_offset_y);
for (int i = 0; i < height; i++) {
vm->m_area.add_y(em, vi, -1);
VoxelArea::add_y(em, vi, -1);
content_t c = vm->m_data[vi].getContent();
if (c != CONTENT_AIR && c != CONTENT_IGNORE && !force_placement)
break;
@ -312,10 +312,10 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)
vm->m_data[vi] = MapNode(c_place, 0, param2);
}
} else { // Heightmap and floor decorations
vm->m_area.add_y(em, vi, place_offset_y);
VoxelArea::add_y(em, vi, place_offset_y);
for (int i = 0; i < height; i++) {
vm->m_area.add_y(em, vi, 1);
VoxelArea::add_y(em, vi, 1);
content_t c = vm->m_data[vi].getContent();
if (c != CONTENT_AIR && c != CONTENT_IGNORE && !force_placement)
break;

@ -1430,8 +1430,8 @@ bool ServerEnvironment::isFreeServerActiveObjectId(u16 id) const
}
/**
* Retrieve the next free activeobject ID
* @return free activeobject ID or zero if not free ID found
* Retrieve the first free ActiveObject ID
* @return free activeobject ID or 0 if none was found
*/
u16 ServerEnvironment::getFreeServerActiveObjectId()
{

@ -265,8 +265,8 @@ public:
bool isFreeServerActiveObjectId(u16 id) const;
/**
* Retrieve the next free activeobject ID
* @return free activeobject ID or zero if not free ID found
* Retrieve the first free ActiveObject ID
* @return free activeobject ID or 0 if none was found
*/
u16 getFreeServerActiveObjectId();

@ -277,25 +277,36 @@ public:
return index(p.X, p.Y, p.Z);
}
// Translate index in the X coordinate
void add_x(const v3s16 &extent, u32 &i, s16 a)
/**
* Translate index in the X coordinate
*/
static void add_x(const v3s16 &extent, u32 &i, s16 a)
{
i += a;
}
// Translate index in the Y coordinate
void add_y(const v3s16 &extent, u32 &i, s16 a)
/**
* Translate index in the Y coordinate
*/
static void add_y(const v3s16 &extent, u32 &i, s16 a)
{
i += a * extent.X;
}
// Translate index in the Z coordinate
void add_z(const v3s16 &extent, u32 &i, s16 a)
/**
* Translate index in the Z coordinate
*/
static void add_z(const v3s16 &extent, u32 &i, s16 a)
{
i += a * extent.X*extent.Y;
i += a * extent.X * extent.Y;
}
// Translate index in space
void add_p(const v3s16 &extent, u32 &i, v3s16 a)
/**
* Translate index in space
*/
static void add_p(const v3s16 &extent, u32 &i, v3s16 a)
{
i += a.Z*extent.X*extent.Y + a.Y*extent.X + a.X;
i += a.Z * extent.X * extent.Y + a.Y * extent.X + a.X;
}
/*

@ -1111,7 +1111,7 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm,
for (relpos.Y = a.MinEdge.Y; relpos.Y <= a.MaxEdge.Y; relpos.Y++) {
// Get old and new node
MapNode oldnode = block->getNodeNoCheck(relpos.X, relpos.Y, relpos.Z, &is_valid);
MapNode oldnode = block->getNodeNoCheck(relpos, &is_valid);
const ContentFeatures &oldf = ndef->get(oldnode);
MapNode newnode = vm->getNodeNoExNoEmerge(relpos + offset);
const ContentFeatures &newf = oldnode == newnode ? oldf :
@ -1240,7 +1240,7 @@ void repair_block_light(ServerMap *map, MapBlock *block,
for (relpos.Y = a.MinEdge.Y; relpos.Y <= a.MaxEdge.Y; relpos.Y++) {
// Get node
MapNode node = block->getNodeNoCheck(relpos.X, relpos.Y, relpos.Z, &is_valid);
MapNode node = block->getNodeNoCheck(relpos, &is_valid);
const ContentFeatures &f = ndef->get(node);
// For each light bank
for (size_t b = 0; b < 2; b++) {