]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_noise.h
56d2d59f8fb1a335f602727096dc552a0011b460
[dragonfireclient.git] / src / script / lua_api / l_noise.h
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 public:
78         LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size);
79
80         ~LuaPerlinNoiseMap();
81
82         // LuaPerlinNoiseMap(np, size)
83         // Creates an LuaPerlinNoiseMap and leaves it on top of stack
84         static int create_object(lua_State *L);
85
86         static LuaPerlinNoiseMap *checkobject(lua_State *L, int narg);
87
88         static void Register(lua_State *L);
89 };
90
91 /*
92         LuaPseudoRandom
93 */
94 class LuaPseudoRandom : public ModApiBase {
95 private:
96         PseudoRandom m_pseudo;
97
98         static const char className[];
99         static const luaL_reg methods[];
100
101         // Exported functions
102
103         // garbage collector
104         static int gc_object(lua_State *L);
105
106         // next(self, min=0, max=32767) -> get next value
107         static int l_next(lua_State *L);
108
109 public:
110         LuaPseudoRandom(int seed) :
111                 m_pseudo(seed) {}
112
113         // LuaPseudoRandom(seed)
114         // Creates an LuaPseudoRandom and leaves it on top of stack
115         static int create_object(lua_State *L);
116
117         static LuaPseudoRandom *checkobject(lua_State *L, int narg);
118
119         static void Register(lua_State *L);
120 };
121
122 /*
123         LuaPcgRandom
124 */
125 class LuaPcgRandom : public ModApiBase {
126 private:
127         PcgRandom m_rnd;
128
129         static const char className[];
130         static const luaL_reg methods[];
131
132         // Exported functions
133
134         // garbage collector
135         static int gc_object(lua_State *L);
136
137         // next(self, min=-2147483648, max=2147483647) -> get next value
138         static int l_next(lua_State *L);
139
140         // rand_normal_dist(self, min=-2147483648, max=2147483647, num_trials=6) ->
141         // get next normally distributed random value
142         static int l_rand_normal_dist(lua_State *L);
143
144 public:
145         LuaPcgRandom(u64 seed) :
146                 m_rnd(seed) {}
147         LuaPcgRandom(u64 seed, u64 seq) :
148                 m_rnd(seed, seq) {}
149
150         // LuaPcgRandom(seed)
151         // Creates an LuaPcgRandom and leaves it on top of stack
152         static int create_object(lua_State *L);
153
154         static LuaPcgRandom *checkobject(lua_State *L, int narg);
155
156         static void Register(lua_State *L);
157 };
158
159 #endif /* L_NOISE_H_ */