Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 :
5 : This program is free software; you can redistribute it and/or modify
6 : it under the terms of the GNU Lesser General Public License as published by
7 : the Free Software Foundation; either version 2.1 of the License, or
8 : (at your option) any later version.
9 :
10 : This program is distributed in the hope that it will be useful,
11 : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU Lesser General Public License for more details.
14 :
15 : You should have received a copy of the GNU Lesser General Public License along
16 : with this program; if not, write to the Free Software Foundation, Inc.,
17 : 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #ifndef L_NOISE_H_
21 : #define L_NOISE_H_
22 :
23 : #include "lua_api/l_base.h"
24 : #include "irr_v3d.h"
25 : #include "noise.h"
26 :
27 : /*
28 : LuaPerlinNoise
29 : */
30 : class LuaPerlinNoise : public ModApiBase {
31 : private:
32 : NoiseParams np;
33 : static const char className[];
34 : static const luaL_reg methods[];
35 :
36 : // Exported functions
37 :
38 : // garbage collector
39 : static int gc_object(lua_State *L);
40 :
41 : static int l_get2d(lua_State *L);
42 : static int l_get3d(lua_State *L);
43 :
44 : public:
45 : LuaPerlinNoise(NoiseParams *params);
46 : ~LuaPerlinNoise();
47 :
48 : // LuaPerlinNoise(seed, octaves, persistence, scale)
49 : // Creates an LuaPerlinNoise and leaves it on top of stack
50 : static int create_object(lua_State *L);
51 :
52 : static LuaPerlinNoise *checkobject(lua_State *L, int narg);
53 :
54 : static void Register(lua_State *L);
55 : };
56 :
57 : /*
58 : LuaPerlinNoiseMap
59 : */
60 : class LuaPerlinNoiseMap : public ModApiBase {
61 : NoiseParams np;
62 : Noise *noise;
63 : bool m_is3d;
64 : static const char className[];
65 : static const luaL_reg methods[];
66 :
67 : // Exported functions
68 :
69 : // garbage collector
70 : static int gc_object(lua_State *L);
71 :
72 : static int l_get2dMap(lua_State *L);
73 : static int l_get2dMap_flat(lua_State *L);
74 : static int l_get3dMap(lua_State *L);
75 : static int l_get3dMap_flat(lua_State *L);
76 :
77 : static int l_calc2dMap(lua_State *L);
78 : static int l_calc3dMap(lua_State *L);
79 : static int l_getMapSlice(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 0 : LuaPseudoRandom(int seed) :
115 0 : m_pseudo(seed) {}
116 :
117 : // LuaPseudoRandom(seed)
118 : // Creates an LuaPseudoRandom and leaves it on top of stack
119 : static int create_object(lua_State *L);
120 :
121 : static LuaPseudoRandom *checkobject(lua_State *L, int narg);
122 :
123 : static void Register(lua_State *L);
124 : };
125 :
126 : /*
127 : LuaPcgRandom
128 : */
129 : class LuaPcgRandom : public ModApiBase {
130 : private:
131 : PcgRandom m_rnd;
132 :
133 : static const char className[];
134 : static const luaL_reg methods[];
135 :
136 : // Exported functions
137 :
138 : // garbage collector
139 : static int gc_object(lua_State *L);
140 :
141 : // next(self, min=-2147483648, max=2147483647) -> get next value
142 : static int l_next(lua_State *L);
143 :
144 : // rand_normal_dist(self, min=-2147483648, max=2147483647, num_trials=6) ->
145 : // get next normally distributed random value
146 : static int l_rand_normal_dist(lua_State *L);
147 :
148 : public:
149 0 : LuaPcgRandom(u64 seed) :
150 0 : m_rnd(seed) {}
151 0 : LuaPcgRandom(u64 seed, u64 seq) :
152 0 : m_rnd(seed, seq) {}
153 :
154 : // LuaPcgRandom(seed)
155 : // Creates an LuaPcgRandom and leaves it on top of stack
156 : static int create_object(lua_State *L);
157 :
158 : static LuaPcgRandom *checkobject(lua_State *L, int narg);
159 :
160 : static void Register(lua_State *L);
161 : };
162 :
163 : #endif /* L_NOISE_H_ */
|