]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_noise.h
Merge pull request #59 from PrairieAstronomer/readme_irrlicht_change
[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 #pragma once
21
22 #include "irr_v3d.h"
23 #include "lua_api/l_base.h"
24 #include "noise.h"
25
26 /*
27         LuaPerlinNoise
28 */
29 class LuaPerlinNoise : public ModApiBase
30 {
31 private:
32         NoiseParams np;
33
34         static const char className[];
35         static luaL_Reg methods[];
36
37         // Exported functions
38
39         // garbage collector
40         static int gc_object(lua_State *L);
41
42         static int l_get_2d(lua_State *L);
43         static int l_get_3d(lua_State *L);
44
45 public:
46         LuaPerlinNoise(const NoiseParams *params);
47         ~LuaPerlinNoise() = default;
48
49         // LuaPerlinNoise(seed, octaves, persistence, scale)
50         // Creates an LuaPerlinNoise and leaves it on top of stack
51         static int create_object(lua_State *L);
52
53         static LuaPerlinNoise *checkobject(lua_State *L, int narg);
54
55         static void *packIn(lua_State *L, int idx);
56         static void packOut(lua_State *L, void *ptr);
57
58         static void Register(lua_State *L);
59 };
60
61 /*
62         LuaPerlinNoiseMap
63 */
64 class LuaPerlinNoiseMap : public ModApiBase
65 {
66         Noise *noise;
67
68         static const char className[];
69         static luaL_Reg methods[];
70
71         // Exported functions
72
73         // garbage collector
74         static int gc_object(lua_State *L);
75
76         static int l_get_2d_map(lua_State *L);
77         static int l_get_2d_map_flat(lua_State *L);
78         static int l_get_3d_map(lua_State *L);
79         static int l_get_3d_map_flat(lua_State *L);
80
81         static int l_calc_2d_map(lua_State *L);
82         static int l_calc_3d_map(lua_State *L);
83         static int l_get_map_slice(lua_State *L);
84
85 public:
86         LuaPerlinNoiseMap(const NoiseParams *np, s32 seed, v3s16 size);
87         ~LuaPerlinNoiseMap();
88
89         inline bool is3D() const { return noise->sz > 1; }
90
91         // LuaPerlinNoiseMap(np, size)
92         // Creates an LuaPerlinNoiseMap and leaves it on top of stack
93         static int create_object(lua_State *L);
94
95         static LuaPerlinNoiseMap *checkobject(lua_State *L, int narg);
96
97         static void *packIn(lua_State *L, int idx);
98         static void packOut(lua_State *L, void *ptr);
99
100         static void Register(lua_State *L);
101 };
102
103 /*
104         LuaPseudoRandom
105 */
106 class LuaPseudoRandom : public ModApiBase
107 {
108 private:
109         PseudoRandom m_pseudo;
110
111         static const char className[];
112         static const luaL_Reg methods[];
113
114         // Exported functions
115
116         // garbage collector
117         static int gc_object(lua_State *L);
118
119         // next(self, min=0, max=32767) -> get next value
120         static int l_next(lua_State *L);
121
122 public:
123         LuaPseudoRandom(s32 seed) : m_pseudo(seed) {}
124
125         // LuaPseudoRandom(seed)
126         // Creates an LuaPseudoRandom and leaves it on top of stack
127         static int create_object(lua_State *L);
128
129         static LuaPseudoRandom *checkobject(lua_State *L, int narg);
130
131         static void Register(lua_State *L);
132 };
133
134 /*
135         LuaPcgRandom
136 */
137 class LuaPcgRandom : public ModApiBase
138 {
139 private:
140         PcgRandom m_rnd;
141
142         static const char className[];
143         static const luaL_Reg methods[];
144
145         // Exported functions
146
147         // garbage collector
148         static int gc_object(lua_State *L);
149
150         // next(self, min=-2147483648, max=2147483647) -> get next value
151         static int l_next(lua_State *L);
152
153         // rand_normal_dist(self, min=-2147483648, max=2147483647, num_trials=6) ->
154         // get next normally distributed random value
155         static int l_rand_normal_dist(lua_State *L);
156
157 public:
158         LuaPcgRandom(u64 seed) : m_rnd(seed) {}
159         LuaPcgRandom(u64 seed, u64 seq) : m_rnd(seed, seq) {}
160
161         // LuaPcgRandom(seed)
162         // Creates an LuaPcgRandom and leaves it on top of stack
163         static int create_object(lua_State *L);
164
165         static LuaPcgRandom *checkobject(lua_State *L, int narg);
166
167         static void Register(lua_State *L);
168 };
169
170 /*
171         LuaSecureRandom
172 */
173 class LuaSecureRandom : public ModApiBase
174 {
175 private:
176         static const size_t RAND_BUF_SIZE = 2048;
177         static const char className[];
178         static const luaL_Reg methods[];
179
180         u32 m_rand_idx;
181         char m_rand_buf[RAND_BUF_SIZE];
182
183         // Exported functions
184
185         // garbage collector
186         static int gc_object(lua_State *L);
187
188         // next_bytes(self, count) -> get count many bytes
189         static int l_next_bytes(lua_State *L);
190
191 public:
192         bool fillRandBuf();
193
194         // LuaSecureRandom()
195         // Creates an LuaSecureRandom and leaves it on top of stack
196         static int create_object(lua_State *L);
197
198         static LuaSecureRandom *checkobject(lua_State *L, int narg);
199
200         static void Register(lua_State *L);
201 };