1 /* 2 script/lua_api/l_noise.h 3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com> 4 */ 5 6 /* 7 This file is part of Freeminer. 8 9 Freeminer is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Freeminer is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Freeminer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef L_NOISE_H_ 24 #define L_NOISE_H_ 25 26 #include "lua_api/l_base.h" 27 #include "irr_v3d.h" 28 #include "noise.h" 29 30 /* 31 LuaPerlinNoise 32 */ 33 class LuaPerlinNoise : public ModApiBase { 34 private: 35 int seed; 36 int octaves; 37 float persistence; 38 float scale; 39 static const char className[]; 40 static const luaL_reg methods[]; 41 42 // Exported functions 43 44 // garbage collector 45 static int gc_object(lua_State *L); 46 47 static int l_get2d(lua_State *L); 48 static int l_get3d(lua_State *L); 49 50 public: 51 LuaPerlinNoise(int a_seed, int a_octaves, float a_persistence, 52 float a_scale); 53 54 ~LuaPerlinNoise(); 55 56 // LuaPerlinNoise(seed, octaves, persistence, scale) 57 // Creates an LuaPerlinNoise and leaves it on top of stack 58 static int create_object(lua_State *L); 59 60 static LuaPerlinNoise* checkobject(lua_State *L, int narg); 61 62 static void Register(lua_State *L); 63 }; 64 65 /* 66 LuaPerlinNoiseMap 67 */ 68 class LuaPerlinNoiseMap : public ModApiBase { 69 private: 70 Noise *noise; 71 static const char className[]; 72 static const luaL_reg methods[]; 73 74 static int gc_object(lua_State *L); 75 76 static int l_get2dMap(lua_State *L); 77 static int l_get2dMap_flat(lua_State *L); 78 static int l_get3dMap(lua_State *L); 79 static int l_get3dMap_flat(lua_State *L); 80 81 public: 82 LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size); 83 84 ~LuaPerlinNoiseMap(); 85 86 // LuaPerlinNoiseMap(np, size) 87 // Creates an LuaPerlinNoiseMap and leaves it on top of stack 88 static int create_object(lua_State *L); 89 90 static LuaPerlinNoiseMap *checkobject(lua_State *L, int narg); 91 92 static void Register(lua_State *L); 93 }; 94 95 /* 96 LuaPseudoRandom 97 */ 98 class LuaPseudoRandom : public ModApiBase { 99 private: 100 PseudoRandom m_pseudo; 101 102 static const char className[]; 103 static const luaL_reg methods[]; 104 105 // Exported functions 106 107 // garbage collector 108 static int gc_object(lua_State *L); 109 110 // next(self, min=0, max=32767) -> get next value 111 static int l_next(lua_State *L); 112 113 public: 114 LuaPseudoRandom(int seed); 115 116 ~LuaPseudoRandom(); 117 118 const PseudoRandom& getItem() const; 119 PseudoRandom& getItem(); 120 121 // LuaPseudoRandom(seed) 122 // Creates an LuaPseudoRandom and leaves it on top of stack 123 static int create_object(lua_State *L); 124 125 static LuaPseudoRandom* checkobject(lua_State *L, int narg); 126 127 static void Register(lua_State *L); 128 }; 129 130 #endif /* L_NOISE_H_ */ 131