diff options
Diffstat (limited to 'src/mg_decoration.cpp')
-rw-r--r-- | src/mg_decoration.cpp | 84 |
1 files changed, 44 insertions, 40 deletions
diff --git a/src/mg_decoration.cpp b/src/mg_decoration.cpp index a67c3cd8c..0d6693929 100644 --- a/src/mg_decoration.cpp +++ b/src/mg_decoration.cpp @@ -25,12 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "util/numeric.h" -const char *DecorationManager::ELEMENT_TITLE = "decoration"; - FlagDesc flagdesc_deco[] = { {"place_center_x", DECO_PLACE_CENTER_X}, {"place_center_y", DECO_PLACE_CENTER_Y}, {"place_center_z", DECO_PLACE_CENTER_Z}, + {"force_placement", DECO_FORCE_PLACEMENT}, {NULL, 0} }; @@ -39,7 +38,7 @@ FlagDesc flagdesc_deco[] = { DecorationManager::DecorationManager(IGameDef *gamedef) : - GenElementManager(gamedef) + ObjDefManager(gamedef, OBJDEF_DECORATION) { } @@ -49,8 +48,8 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed, { size_t nplaced = 0; - for (size_t i = 0; i != m_elements.size(); i++) { - Decoration *deco = (Decoration *)m_elements[i]; + for (size_t i = 0; i != m_objects.size(); i++) { + Decoration *deco = (Decoration *)m_objects[i]; if (!deco) continue; @@ -62,16 +61,6 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed, } -void DecorationManager::clear() -{ - for (size_t i = 0; i < m_elements.size(); i++) { - Decoration *deco = (Decoration *)m_elements[i]; - delete deco; - } - m_elements.clear(); -} - - /////////////////////////////////////////////////////////////////////////////// @@ -89,9 +78,9 @@ Decoration::~Decoration() } -void Decoration::resolveNodeNames(NodeResolveInfo *nri) +void Decoration::resolveNodeNames() { - m_ndef->getIdsFromResolveInfo(nri, c_place_on); + getIdsFromNrBacklog(&c_place_on); } @@ -145,9 +134,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) y < y_min || y > y_max) continue; - int height = getHeight(); - int max_y = nmax.Y;// + MAP_BLOCKSIZE - 1; - if (y + 1 + height > max_y) { + if (y + getHeight() >= mg->vm->m_area.MaxEdge.Y) { continue; #if 0 printf("Decoration at (%d %d %d) cut off\n", x, y, z); @@ -168,8 +155,8 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) } v3s16 pos(x, y, z); - if (generate(mg->vm, &ps, max_y, pos)) - mg->gennotify.addEvent(GENNOTIFY_DECORATION, pos, id); + if (generate(mg->vm, &ps, pos)) + mg->gennotify.addEvent(GENNOTIFY_DECORATION, pos, index); } } @@ -234,11 +221,11 @@ void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) /////////////////////////////////////////////////////////////////////////////// -void DecoSimple::resolveNodeNames(NodeResolveInfo *nri) +void DecoSimple::resolveNodeNames() { - Decoration::resolveNodeNames(nri); - m_ndef->getIdsFromResolveInfo(nri, c_decos); - m_ndef->getIdsFromResolveInfo(nri, c_spawnby); + Decoration::resolveNodeNames(); + getIdsFromNrBacklog(&c_decos); + getIdsFromNrBacklog(&c_spawnby); } @@ -259,7 +246,7 @@ bool DecoSimple::canPlaceDecoration(MMVManip *vm, v3s16 p) return true; int nneighs = 0; - v3s16 dirs[8] = { + v3s16 dirs[16] = { v3s16( 0, 0, 1), v3s16( 0, 0, -1), v3s16( 1, 0, 0), @@ -267,7 +254,16 @@ bool DecoSimple::canPlaceDecoration(MMVManip *vm, v3s16 p) v3s16( 1, 0, 1), v3s16(-1, 0, 1), v3s16(-1, 0, -1), - v3s16( 1, 0, -1) + v3s16( 1, 0, -1), + + v3s16( 0, 1, 1), + v3s16( 0, 1, -1), + v3s16( 1, 1, 0), + v3s16(-1, 1, 0), + v3s16( 1, 1, 1), + v3s16(-1, 1, 1), + v3s16(-1, 1, -1), + v3s16( 1, 1, -1) }; // Check a Moore neighborhood if there are enough spawnby nodes @@ -287,7 +283,7 @@ bool DecoSimple::canPlaceDecoration(MMVManip *vm, v3s16 p) } -size_t DecoSimple::generate(MMVManip *vm, PseudoRandom *pr, s16 max_y, v3s16 p) +size_t DecoSimple::generate(MMVManip *vm, PseudoRandom *pr, v3s16 p) { if (!canPlaceDecoration(vm, p)) return 0; @@ -297,8 +293,6 @@ size_t DecoSimple::generate(MMVManip *vm, PseudoRandom *pr, s16 max_y, v3s16 p) s16 height = (deco_height_max > 0) ? pr->range(deco_height, deco_height_max) : deco_height; - height = MYMIN(height, max_y - p.Y); - v3s16 em = vm->m_area.getExtent(); u32 vi = vm->m_area.index(p); for (int i = 0; i < height; i++) { @@ -324,16 +318,17 @@ int DecoSimple::getHeight() /////////////////////////////////////////////////////////////////////////////// -size_t DecoSchematic::generate(MMVManip *vm, PseudoRandom *pr, s16 max_y, v3s16 p) +DecoSchematic::DecoSchematic() { - if (flags & DECO_PLACE_CENTER_X) - p.X -= (schematic->size.X + 1) / 2; - if (flags & DECO_PLACE_CENTER_Y) - p.Y -= (schematic->size.Y + 1) / 2; - if (flags & DECO_PLACE_CENTER_Z) - p.Z -= (schematic->size.Z + 1) / 2; + schematic = NULL; +} + - if (!vm->m_area.contains(p)) +size_t DecoSchematic::generate(MMVManip *vm, PseudoRandom *pr, v3s16 p) +{ + // Schematic could have been unloaded but not the decoration + // In this case generate() does nothing (but doesn't *fail*) + if (schematic == NULL) return 0; u32 vi = vm->m_area.index(p); @@ -341,10 +336,19 @@ size_t DecoSchematic::generate(MMVManip *vm, PseudoRandom *pr, s16 max_y, v3s16 if (!CONTAINS(c_place_on, c)) return 0; + if (flags & DECO_PLACE_CENTER_X) + p.X -= (schematic->size.X - 1) / 2; + if (flags & DECO_PLACE_CENTER_Y) + p.Y -= (schematic->size.Y - 1) / 2; + if (flags & DECO_PLACE_CENTER_Z) + p.Z -= (schematic->size.Z - 1) / 2; + Rotation rot = (rotation == ROTATE_RAND) ? (Rotation)pr->range(ROTATE_0, ROTATE_270) : rotation; - schematic->blitToVManip(p, vm, rot, false, m_ndef); + bool force_placement = (flags & DECO_FORCE_PLACEMENT); + + schematic->blitToVManip(p, vm, rot, force_placement); return 1; } |