aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/give_initial_stuff/init.lua
blob: 29b835c7d42244c99a0b6cd4fb47a2ee016eaf8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
minetest.register_on_newplayer(function(player)
	print("[minimal] giving initial stuff to player")
	player:get_inventory():add_item('main', 'default:pick_stone')
	player:get_inventory():add_item('main', 'default:torch 99')
	player:get_inventory():add_item('main', 'default:cobble 99')
	player:get_inventory():add_item('main', 'default:wood 99')
	player:get_inventory():add_item('main', 'default:axe_steel')
	player:get_inventory():add_item('main', 'default:shovel_steel')
	player:get_inventory():add_item('main', 'default:pick_wood')
	player:get_inventory():add_item('main', 'default:pick_steel')
	player:get_inventory():add_item('main', 'default:pick_mese')
	player:get_inventory():add_item('main', 'default:mese 99')
	player:get_inventory():add_item('main', 'default:water_source 99')
	player:get_inventory():add_item('main',
 * in all copies or substantial portions of the Software.
 *
 * THE SOFT

l com"> * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "ieee_float.h" #include "log.h" #include "porting.h" #include <limits> #include <cmath> // Given an unsigned 32-bit integer representing an IEEE-754 single-precision // float, return the float. f32 u32Tof32Slow(u32 i) { // clang-format off int exp = (i >> 23) & 0xFF; u32 sign = i & 0x80000000UL; u32 imant = i & 0x7FFFFFUL; if (exp == 0xFF) { // Inf/NaN if (imant == 0) { if (std::numeric_limits<f32>::has_infinity) return sign ? -std::numeric_limits<f32>::infinity() : std::numeric_limits<f32>::infinity(); return sign ? std::numeric_limits<f32>::max() : std::numeric_limits<f32>::lowest(); } return std::numeric_limits<f32>::has_quiet_NaN ? std::numeric_limits<f32>::quiet_NaN() : -0.f; } if (!exp) { // Denormal or zero return sign ? -ldexpf((f32)imant, -149) : ldexpf((f32)imant, -149); } return sign ? -ldexpf((f32)(imant | 0x800000UL), exp - 150) : ldexpf((f32)(imant | 0x800000UL), exp - 150); // clang-format on } // Given a float, return an unsigned 32-bit integer representing the f32 // in IEEE-754 single-precision format. u32 f32Tou32Slow(f32 f) { u32 signbit = std::copysign(1.0f, f) == 1.0f ? 0 : 0x80000000UL; if (f == 0.f) return signbit; if (std::isnan(f)) return signbit | 0x7FC00000UL; if (std::isinf(f)) return signbit | 0x7F800000UL; int exp = 0; // silence warning f32 mant = frexpf(f, &exp); u32 imant = (u32)std::floor((signbit ? -16777216.f : 16777216.f) * mant); exp += 126; if (exp <= 0) { // Denormal return signbit | (exp <= -31 ? 0 : imant >> (1 - exp)); } if (exp >= 255) { // Overflow due to the platform having exponents bigger than IEEE ones. // Return signed infinity. return signbit | 0x7F800000UL; } // Regular number return signbit | (exp << 23) | (imant & 0x7FFFFFUL); } // This test needs the following requisites in order to work: // - The float type must be a 32 bits IEEE-754 single-precision float. // - The endianness of f32s and integers must match. FloatType getFloatSerializationType() { // clang-format off const f32 cf = -22220490.f; const u32 cu = 0xCBA98765UL; if (std::numeric_limits<f32>::is_iec559 && sizeof(cf) == 4 &&