Re-add jungles, apple trees
[oweals/minetest.git] / src / scriptapi_noise.h
1 /*
2 Minetest-c55
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 LUA_PERLIN_H_
21 #define LUA_PERLIN_H_
22
23 extern "C" {
24 #include <lua.h>
25 #include <lauxlib.h>
26 }
27
28 #include "noise.h"
29
30 class LuaPerlinNoise
31 {
32 private:
33         int seed;
34         int octaves;
35         float persistence;
36         float scale;
37         static const char className[];
38         static const luaL_reg methods[];
39
40         // Exported functions
41
42         // garbage collector
43         static int gc_object(lua_State *L);
44
45         static int l_get2d(lua_State *L);
46         static int l_get3d(lua_State *L);
47
48 public:
49         LuaPerlinNoise(int a_seed, int a_octaves, float a_persistence,
50                         float a_scale);
51
52         ~LuaPerlinNoise();
53
54         // LuaPerlinNoise(seed, octaves, persistence, scale)
55         // Creates an LuaPerlinNoise and leaves it on top of stack
56         static int create_object(lua_State *L);
57
58         static LuaPerlinNoise* checkobject(lua_State *L, int narg);
59
60         static void Register(lua_State *L);
61 };
62
63 /*
64   PerlinNoiseMap
65  */
66 class LuaPerlinNoiseMap
67 {
68 private:
69         Noise *noise;
70         static const char className[];
71         static const luaL_reg methods[];
72
73         static int gc_object(lua_State *L);
74
75         static int l_get2dMap(lua_State *L);
76
77         static int l_get3dMap(lua_State *L);
78
79 public:
80         LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size);
81
82         ~LuaPerlinNoiseMap();
83
84         // LuaPerlinNoiseMap(np, size)
85         // Creates an LuaPerlinNoiseMap and leaves it on top of stack
86         static int create_object(lua_State *L);
87
88         static LuaPerlinNoiseMap *checkobject(lua_State *L, int narg);
89
90         static void Register(lua_State *L);
91 };
92
93 /*
94         LuaPseudoRandom
95 */
96
97
98 class LuaPseudoRandom
99 {
100 private:
101         PseudoRandom m_pseudo;
102
103         static const char className[];
104         static const luaL_reg methods[];
105
106         // Exported functions
107
108         // garbage collector
109         static int gc_object(lua_State *L);
110
111         // next(self, min=0, max=32767) -> get next value
112         static int l_next(lua_State *L);
113
114 public:
115         LuaPseudoRandom(int seed);
116
117         ~LuaPseudoRandom();
118
119         const PseudoRandom& getItem() const;
120         PseudoRandom& getItem();
121
122         // LuaPseudoRandom(seed)
123         // Creates an LuaPseudoRandom and leaves it on top of stack
124         static int create_object(lua_State *L);
125
126         static LuaPseudoRandom* checkobject(lua_State *L, int narg);
127
128         static void Register(lua_State *L);
129 };
130
131 NoiseParams *read_noiseparams(lua_State *L, int index);
132
133 #endif /* LUA_PERLIN_H_ */