Noise: Prevent unittest crash caused by division by zero
[oweals/minetest.git] / src / mg_decoration.h
index 056748918c2dc0d24b73551b08e880154a0d9325..a7fdb97fe907e92607db9af27a4208c0d4879802 100644 (file)
@@ -1,6 +1,7 @@
 /*
 Minetest
-Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2015-2017 paramat
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -20,14 +21,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef MG_DECORATION_HEADER
 #define MG_DECORATION_HEADER
 
-#include <set>
+#include <unordered_set>
 #include "objdef.h"
 #include "noise.h"
 #include "nodedef.h"
 
 class Mapgen;
 class MMVManip;
-class PseudoRandom;
+class PcgRandom;
 class Schematic;
 
 enum DecorationType {
@@ -41,6 +42,7 @@ enum DecorationType {
 #define DECO_PLACE_CENTER_Z  0x04
 #define DECO_USE_NOISE       0x08
 #define DECO_FORCE_PLACEMENT 0x10
+#define DECO_LIQUID_SURFACE  0x20
 
 extern FlagDesc flagdesc_deco[];
 
@@ -62,55 +64,54 @@ struct CutoffData {
 
 class Decoration : public ObjDef, public NodeResolver {
 public:
-       Decoration();
-       virtual ~Decoration();
+       Decoration() {};
+       virtual ~Decoration() {};
 
        virtual void resolveNodeNames();
 
-       size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+       bool canPlaceDecoration(MMVManip *vm, v3s16 p);
+       size_t placeDeco(Mapgen *mg, u32 blockseed,
+               v3s16 nmin, v3s16 nmax, s16 deco_zero_level);
        //size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
 
-       virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p) = 0;
+       virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
        virtual int getHeight() = 0;
 
-       u32 flags;
-       int mapseed;
+       u32 flags = 0;
+       int mapseed = 0;
        std::vector<content_t> c_place_on;
-       s16 sidelen;
+       s16 sidelen = 1;
        s16 y_min;
        s16 y_max;
-       float fill_ratio;
+       float fill_ratio = 0.0f;
        NoiseParams np;
+       std::vector<content_t> c_spawnby;
+       s16 nspawnby;
 
-       std::set<u8> biomes;
-       //std::list<CutoffData> cutoffs;
-       //JMutex cutoff_mutex;
+       std::unordered_set<u8> biomes;
 };
 
 class DecoSimple : public Decoration {
 public:
-       virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p);
-       bool canPlaceDecoration(MMVManip *vm, v3s16 p);
-       virtual int getHeight();
-
        virtual void resolveNodeNames();
+       virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
+       virtual int getHeight();
 
        std::vector<content_t> c_decos;
-       std::vector<content_t> c_spawnby;
        s16 deco_height;
        s16 deco_height_max;
-       s16 nspawnby;
+       u8 deco_param2;
 };
 
 class DecoSchematic : public Decoration {
 public:
-       DecoSchematic();
+       DecoSchematic() {};
 
-       virtual size_t generate(MMVManip *vm, PseudoRandom *pr, v3s16 p);
+       virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p);
        virtual int getHeight();
 
        Rotation rotation;
-       Schematic *schematic;
+       Schematic *schematic = nullptr;
 };
 
 
@@ -145,7 +146,8 @@ public:
                }
        }
 
-       size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+       size_t placeAllDecos(Mapgen *mg, u32 blockseed,
+               v3s16 nmin, v3s16 nmax, s16 deco_zero_level = 0);
 };
 
 #endif