Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
l_noise.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "irr_v3d.h"
8#include "lua_api/l_base.h"
9#include "noise.h"
10
11/*
12 LuaPerlinNoise
13*/
15{
16private:
18
19 static luaL_Reg methods[];
20
21 // Exported functions
22
23 // garbage collector
24 static int gc_object(lua_State *L);
25
26 static int l_get_2d(lua_State *L);
27 static int l_get_3d(lua_State *L);
28
29public:
30 LuaPerlinNoise(const NoiseParams *params);
31 ~LuaPerlinNoise() = default;
32
33 // LuaPerlinNoise(seed, octaves, persistence, scale)
34 // Creates an LuaPerlinNoise and leaves it on top of stack
35 static int create_object(lua_State *L);
36
37 static void *packIn(lua_State *L, int idx);
38 static void packOut(lua_State *L, void *ptr);
39
40 static void Register(lua_State *L);
41
42 static const char className[];
43};
44
45/*
46 LuaPerlinNoiseMap
47*/
49{
51
52 static luaL_Reg methods[];
53
54 // Exported functions
55
56 // garbage collector
57 static int gc_object(lua_State *L);
58
59 static int l_get_2d_map(lua_State *L);
60 static int l_get_2d_map_flat(lua_State *L);
61 static int l_get_3d_map(lua_State *L);
62 static int l_get_3d_map_flat(lua_State *L);
63
64 static int l_calc_2d_map(lua_State *L);
65 static int l_calc_3d_map(lua_State *L);
66 static int l_get_map_slice(lua_State *L);
67
68public:
69 LuaPerlinNoiseMap(const NoiseParams *np, s32 seed, v3s16 size);
71
72 inline bool is3D() const { return noise->sz > 1; }
73
74 // LuaPerlinNoiseMap(np, size)
75 // Creates an LuaPerlinNoiseMap and leaves it on top of stack
76 static int create_object(lua_State *L);
77
78 static void *packIn(lua_State *L, int idx);
79 static void packOut(lua_State *L, void *ptr);
80
81 static void Register(lua_State *L);
82
83 static const char className[];
84};
85
86/*
87 LuaPseudoRandom
88*/
90{
91private:
93
94 static const luaL_Reg methods[];
95
96 // Exported functions
97
98 // garbage collector
99 static int gc_object(lua_State *L);
100
101 // next(self, min=0, max=32767) -> get next value
102 static int l_next(lua_State *L);
103
104 // save state
105 static int l_get_state(lua_State *L);
106public:
107 LuaPseudoRandom(s32 seed) : m_pseudo(seed) {}
108
109 // LuaPseudoRandom(seed)
110 // Creates an LuaPseudoRandom and leaves it on top of stack
111 static int create_object(lua_State *L);
112
113 static void Register(lua_State *L);
114
115 static const char className[];
116};
117
118/*
119 LuaPcgRandom
120*/
122{
123private:
125
126 static const luaL_Reg methods[];
127
128 // Exported functions
129
130 // garbage collector
131 static int gc_object(lua_State *L);
132
133 // next(self, min=-2147483648, max=2147483647) -> get next value
134 static int l_next(lua_State *L);
135
136 // rand_normal_dist(self, min=-2147483648, max=2147483647, num_trials=6) ->
137 // get next normally distributed random value
138 static int l_rand_normal_dist(lua_State *L);
139
140 // save and restore state
141 static int l_get_state(lua_State *L);
142 static int l_set_state(lua_State *L);
143public:
144 LuaPcgRandom(u64 seed) : m_rnd(seed) {}
145 LuaPcgRandom(u64 seed, u64 seq) : m_rnd(seed, seq) {}
146
147 // LuaPcgRandom(seed)
148 // Creates an LuaPcgRandom and leaves it on top of stack
149 static int create_object(lua_State *L);
150
151 static void Register(lua_State *L);
152
153 static const char className[];
154};
155
156/*
157 LuaSecureRandom
158*/
160{
161private:
162 static const size_t RAND_BUF_SIZE = 2048;
163 static const luaL_Reg methods[];
164
167
168 // Exported functions
169
170 // garbage collector
171 static int gc_object(lua_State *L);
172
173 // next_bytes(self, count) -> get count many bytes
174 static int l_next_bytes(lua_State *L);
175
176public:
177 bool fillRandBuf();
178
179 // LuaSecureRandom()
180 // Creates an LuaSecureRandom and leaves it on top of stack
181 static int create_object(lua_State *L);
182
183 static void Register(lua_State *L);
184
185 static const char className[];
186};
Definition l_noise.h:122
static const char className[]
Definition l_noise.h:153
LuaPcgRandom(u64 seed, u64 seq)
Definition l_noise.h:145
PcgRandom m_rnd
Definition l_noise.h:124
static int l_set_state(lua_State *L)
Definition l_noise.cpp:513
LuaPcgRandom(u64 seed)
Definition l_noise.h:144
static int l_next(lua_State *L)
Definition l_noise.cpp:470
static int l_get_state(lua_State *L)
Definition l_noise.cpp:496
static const luaL_Reg methods[]
Definition l_noise.h:572
static int gc_object(lua_State *L)
Definition l_noise.cpp:551
static int create_object(lua_State *L)
Definition l_noise.cpp:536
static int l_rand_normal_dist(lua_State *L)
Definition l_noise.cpp:483
Definition l_noise.h:49
static void * packIn(lua_State *L, int idx)
Definition l_noise.cpp:334
static int l_calc_2d_map(lua_State *L)
Definition l_noise.cpp:250
static luaL_Reg methods[]
Definition l_noise.h:372
static int l_get_3d_map(lua_State *L)
Definition l_noise.cpp:190
static void packOut(lua_State *L, void *ptr)
Definition l_noise.cpp:344
static int l_calc_3d_map(lua_State *L)
Definition l_noise.cpp:263
static int l_get_3d_map_flat(lua_State *L)
Definition l_noise.cpp:221
static int l_get_2d_map_flat(lua_State *L)
Definition l_noise.cpp:164
Noise * noise
Definition l_noise.h:50
static int l_get_2d_map(lua_State *L)
Definition l_noise.cpp:140
static int create_object(lua_State *L)
Definition l_noise.cpp:305
~LuaPerlinNoiseMap()
Definition l_noise.cpp:134
static const char className[]
Definition l_noise.h:83
LuaPerlinNoiseMap(const NoiseParams *np, s32 seed, v3s16 size)
Definition l_noise.cpp:124
static int l_get_map_slice(lua_State *L)
Definition l_noise.cpp:280
static int gc_object(lua_State *L)
Definition l_noise.cpp:320
bool is3D() const
Definition l_noise.h:72
Definition l_noise.h:15
static void packOut(lua_State *L, void *ptr)
Definition l_noise.cpp:85
NoiseParams np
Definition l_noise.h:17
static const char className[]
Definition l_noise.h:42
static int create_object(lua_State *L)
Definition l_noise.cpp:47
~LuaPerlinNoise()=default
static void * packIn(lua_State *L, int idx)
Definition l_noise.cpp:79
static luaL_Reg methods[]
Definition l_noise.h:113
static int l_get_2d(lua_State *L)
Definition l_noise.cpp:25
static int gc_object(lua_State *L)
Definition l_noise.cpp:71
static int l_get_3d(lua_State *L)
Definition l_noise.cpp:36
LuaPerlinNoise(const NoiseParams *params)
Definition l_noise.cpp:19
Definition l_noise.h:90
static const char className[]
Definition l_noise.h:115
PseudoRandom m_pseudo
Definition l_noise.h:92
static int gc_object(lua_State *L)
Definition l_noise.cpp:438
LuaPseudoRandom(s32 seed)
Definition l_noise.h:107
static int create_object(lua_State *L)
Definition l_noise.cpp:425
static int l_get_state(lua_State *L)
Definition l_noise.cpp:413
static const luaL_Reg methods[]
Definition l_noise.h:459
static int l_next(lua_State *L)
Definition l_noise.cpp:388
Definition l_noise.h:160
static const char className[]
Definition l_noise.h:185
static int l_next_bytes(lua_State *L)
Definition l_noise.cpp:590
static int create_object(lua_State *L)
Definition l_noise.cpp:625
static const size_t RAND_BUF_SIZE
Definition l_noise.h:162
static const luaL_Reg methods[]
Definition l_noise.h:661
bool fillRandBuf()
Definition l_noise.cpp:585
static int gc_object(lua_State *L)
Definition l_noise.cpp:641
char m_rand_buf[RAND_BUF_SIZE]
Definition l_noise.h:166
u32 m_rand_idx
Definition l_noise.h:165
Definition l_base.h:28
Definition noise.h:146
u32 sz
Definition noise.h:152
Definition noise.h:89
Definition noise.h:43
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
#define idx(x, y)
Definition noise.cpp:490
Definition noise.h:119