Skip to content

Commit 51002b1

Browse files
committedSep 10, 2017
Schematic decorations: Add 'place_offset_y' placement parameter
For precise control of schematic vertical position relative to the 'place_on' node. Avoids workarounds that add empty nodes to a schematic and therefore reduce performance. Also remove long-unused decoration cutoff code.
1 parent 557bbc6 commit 51002b1

File tree

4 files changed

+27
-83
lines changed

4 files changed

+27
-83
lines changed
 

Diff for: ‎doc/lua_api.txt

+7
Original file line numberDiff line numberDiff line change
@@ -4743,6 +4743,13 @@ The Biome API is still in an experimental phase and subject to change.
47434743
-- ^ Flags for schematic decorations. See 'Schematic attributes'.
47444744
rotation = "90" -- rotate schematic 90 degrees on placement
47454745
-- ^ Rotation can be "0", "90", "180", "270", or "random".
4746+
place_offset_y = 0,
4747+
-- ^ Y offset of the schematic base node layer relative to the 'place_on'
4748+
-- ^ node.
4749+
-- ^ Can be positive or negative. Default is 0.
4750+
-- ^ If the flag 'place_center_y' is set this parameter is ignored.
4751+
-- ^ If absent or 0 the schematic base node layer will be placed level
4752+
-- ^ with the 'place_on' node.
47464753
}
47474754

47484755
### Chat command definition (`register_chatcommand`)

Diff for: ‎src/mg_decoration.cpp

+14-67
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed,
6767

6868
///////////////////////////////////////////////////////////////////////////////
6969

70+
7071
void Decoration::resolveNodeNames()
7172
{
7273
getIdsFromNrBacklog(&c_place_on);
@@ -192,15 +193,8 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed,
192193
if (y < y_min_disp || y > y_max_disp || y < nmin.Y || y > nmax.Y)
193194
continue;
194195

195-
if (y + getHeight() > mg->vm->m_area.MaxEdge.Y) {
196+
if (y + getHeight() > mg->vm->m_area.MaxEdge.Y)
196197
continue;
197-
#if 0
198-
printf("Decoration at (%d %d %d) cut off\n", x, y, z);
199-
//add to queue
200-
MutexAutoLock cutofflock(cutoff_mutex);
201-
cutoffs.push_back(CutoffData(x, y, z, height));
202-
#endif
203-
}
204198

205199
if (mg->biomemap && !biomes.empty()) {
206200
std::unordered_set<u8>::const_iterator iter =
@@ -219,60 +213,6 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed,
219213
}
220214

221215

222-
#if 0
223-
void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
224-
{
225-
PcgRandom pr(blockseed + 53);
226-
std::vector<CutoffData> handled_cutoffs;
227-
228-
// Copy over the cutoffs we're interested in so we don't needlessly hold a lock
229-
{
230-
MutexAutoLock cutofflock(cutoff_mutex);
231-
for (std::list<CutoffData>::iterator i = cutoffs.begin();
232-
i != cutoffs.end(); ++i) {
233-
CutoffData cutoff = *i;
234-
v3s16 p = cutoff.p;
235-
s16 height = cutoff.height;
236-
if (p.X < nmin.X || p.X > nmax.X ||
237-
p.Z < nmin.Z || p.Z > nmax.Z)
238-
continue;
239-
if (p.Y + height < nmin.Y || p.Y > nmax.Y)
240-
continue;
241-
242-
handled_cutoffs.push_back(cutoff);
243-
}
244-
}
245-
246-
// Generate the cutoffs
247-
for (size_t i = 0; i != handled_cutoffs.size(); i++) {
248-
v3s16 p = handled_cutoffs[i].p;
249-
s16 height = handled_cutoffs[i].height;
250-
251-
if (p.Y + height > nmax.Y) {
252-
//printf("Decoration at (%d %d %d) cut off again!\n", p.X, p.Y, p.Z);
253-
cuttoffs.push_back(v3s16(p.X, p.Y, p.Z));
254-
}
255-
256-
generate(mg, &pr, nmax.Y, nmin.Y - p.Y, v3s16(p.X, nmin.Y, p.Z));
257-
}
258-
259-
// Remove cutoffs that were handled from the cutoff list
260-
{
261-
MutexAutoLock cutofflock(cutoff_mutex);
262-
for (std::list<CutoffData>::iterator i = cutoffs.begin();
263-
i != cutoffs.end(); ++i) {
264-
265-
for (size_t j = 0; j != handled_cutoffs.size(); j++) {
266-
CutoffData coff = *i;
267-
if (coff.p == handled_cutoffs[j].p)
268-
i = cutoffs.erase(i);
269-
}
270-
}
271-
}
272-
}
273-
#endif
274-
275-
276216
///////////////////////////////////////////////////////////////////////////////
277217

278218

@@ -324,6 +264,7 @@ int DecoSimple::getHeight()
324264

325265
///////////////////////////////////////////////////////////////////////////////
326266

267+
327268
size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
328269
{
329270
// Schematic could have been unloaded but not the decoration
@@ -336,11 +277,17 @@ size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
336277

337278
if (flags & DECO_PLACE_CENTER_X)
338279
p.X -= (schematic->size.X - 1) / 2;
339-
if (flags & DECO_PLACE_CENTER_Y)
340-
p.Y -= (schematic->size.Y - 1) / 2;
341280
if (flags & DECO_PLACE_CENTER_Z)
342281
p.Z -= (schematic->size.Z - 1) / 2;
343282

283+
if (flags & DECO_PLACE_CENTER_Y)
284+
p.Y -= (schematic->size.Y - 1) / 2;
285+
else
286+
p.Y += place_offset_y;
287+
// Check shifted schematic base is in voxelmanip
288+
if (p.Y < vm->m_area.MinEdge.Y)
289+
return 0;
290+
344291
Rotation rot = (rotation == ROTATE_RAND) ?
345292
(Rotation)pr->range(ROTATE_0, ROTATE_270) : rotation;
346293

@@ -355,8 +302,8 @@ size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
355302
int DecoSchematic::getHeight()
356303
{
357304
// Account for a schematic being sunk into the ground by flag.
358-
// When placed normally account for how a schematic is placed
359-
// sunk 1 node into the ground.
305+
// When placed normally account for how a schematic is by default placed
306+
// sunk 1 node into the ground or is vertically shifted by 'y_offset'.
360307
return (flags & DECO_PLACE_CENTER_Y) ?
361-
(schematic->size.Y - 1) / 2 : schematic->size.Y - 1;
308+
(schematic->size.Y - 1) / 2 : schematic->size.Y - 1 + place_offset_y;
362309
}

Diff for: ‎src/mg_decoration.h

+4-16
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ enum DecorationType {
4646
extern FlagDesc flagdesc_deco[];
4747

4848

49-
#if 0
50-
struct CutoffData {
51-
VoxelArea a;
52-
Decoration *deco;
53-
//v3s16 p;
54-
//v3s16 size;
55-
//s16 height;
56-
57-
CutoffData(s16 x, s16 y, s16 z, s16 h) {
58-
p = v3s16(x, y, z);
59-
height = h;
60-
}
61-
};
62-
#endif
63-
6449
class Decoration : public ObjDef, public NodeResolver {
6550
public:
6651
Decoration() = default;
@@ -71,7 +56,6 @@ class Decoration : public ObjDef, public NodeResolver {
7156
bool canPlaceDecoration(MMVManip *vm, v3s16 p);
7257
size_t placeDeco(Mapgen *mg, u32 blockseed,
7358
v3s16 nmin, v3s16 nmax, s16 deco_zero_level);
74-
//size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
7559

7660
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
7761
virtual int getHeight() = 0;
@@ -90,6 +74,7 @@ class Decoration : public ObjDef, public NodeResolver {
9074
std::unordered_set<u8> biomes;
9175
};
9276

77+
9378
class DecoSimple : public Decoration {
9479
public:
9580
virtual void resolveNodeNames();
@@ -102,6 +87,7 @@ class DecoSimple : public Decoration {
10287
u8 deco_param2;
10388
};
10489

90+
10591
class DecoSchematic : public Decoration {
10692
public:
10793
DecoSchematic() = default;
@@ -110,6 +96,7 @@ class DecoSchematic : public Decoration {
11096
virtual int getHeight();
11197

11298
Rotation rotation;
99+
s16 place_offset_y = 0;
113100
Schematic *schematic = nullptr;
114101
};
115102

@@ -121,6 +108,7 @@ class DecoLSystem : public Decoration {
121108
};
122109
*/
123110

111+
124112
class DecorationManager : public ObjDefManager {
125113
public:
126114
DecorationManager(IGameDef *gamedef);

Diff for: ‎src/script/lua_api/l_mapgen.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic
10181018
deco->rotation = (Rotation)getenumfield(L, index, "rotation",
10191019
ModApiMapgen::es_Rotation, ROTATE_0);
10201020

1021+
deco->place_offset_y = getintfield_default(L, index, "place_offset_y", 0);
1022+
10211023
StringMap replace_names;
10221024
lua_getfield(L, index, "replacements");
10231025
if (lua_istable(L, -1))

0 commit comments

Comments
 (0)
Please sign in to comment.