Define and use limit constants for Irrlicht fixed-width types master
authorkwolekr <kwolekr@minetest.net>
Sun, 4 Oct 2015 06:50:04 +0000 (02:50 -0400)
committerkwolekr <kwolekr@minetest.net>
Sun, 4 Oct 2015 08:00:16 +0000 (04:00 -0400)
src/irrlichttypes.h
src/map.cpp
src/mapgen.cpp
src/mapgen_v5.cpp
src/mapgen_v6.cpp
src/mapgen_v7.cpp
src/script/lua_api/l_mapgen.cpp
src/script/lua_api/l_object.cpp
src/server.cpp
src/staticobject.cpp
src/unittest/test_utilities.cpp

index bead64407ed1717e7df21f7758fb27bbc0f28483..dedebd45b4a87c67bceecbb6ba6413a572644a13 100644 (file)
@@ -48,4 +48,19 @@ using namespace irr;
 #endif
 #endif
 
+#define S8_MIN  (-0x7F - 1)
+#define S16_MIN (-0x7FFF - 1)
+#define S32_MIN (-0x7FFFFFFF - 1)
+#define S64_MIN (-0x7FFFFFFFFFFFFFFF - 1)
+
+#define S8_MAX  0x7F
+#define S16_MAX 0x7FFF
+#define S32_MAX 0x7FFFFFFF
+#define S64_MAX 0x7FFFFFFFFFFFFFFF
+
+#define U8_MAX  0xFF
+#define U16_MAX 0xFFFF
+#define U32_MAX 0xFFFFFFFF
+#define U64_MAX 0xFFFFFFFFFFFFFFFF
+
 #endif
index fd796734e84136922f8b3590c257246073902865..e3cafd6731ae8b66a84fc9df9a5ab263447cc357 100644 (file)
@@ -1434,7 +1434,7 @@ void Map::timerUpdate(float dtime, float unload_timeout, u32 max_loaded_blocks,
        beginSave();
 
        // If there is no practical limit, we spare creation of mapblock_queue
-       if (max_loaded_blocks == (u32)-1) {
+       if (max_loaded_blocks == U32_MAX) {
                for (std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
                                si != m_sectors.end(); ++si) {
                        MapSector *sector = si->second;
index 31d394fa4a5e0a6d72ae44033ffac8f8fdaf9983..a94b071c566c1d28dfa0c5840278f43f19ab4938 100644 (file)
@@ -441,7 +441,7 @@ void MapgenParams::save(Settings &settings) const
        settings.setU64("seed", seed);
        settings.setS16("water_level", water_level);
        settings.setS16("chunksize", chunksize);
-       settings.setFlagStr("mg_flags", flags, flagdesc_mapgen, (u32)-1);
+       settings.setFlagStr("mg_flags", flags, flagdesc_mapgen, U32_MAX);
        settings.setNoiseParams("mg_biome_np_heat", np_biome_heat);
        settings.setNoiseParams("mg_biome_np_heat_blend", np_biome_heat_blend);
        settings.setNoiseParams("mg_biome_np_humidity", np_biome_humidity);
index dbbd729361316c713e5bfbfd24338bac0f5f1f09..d534249a5c8cf66861839d8b8574cee51d0e8080 100644 (file)
@@ -160,7 +160,7 @@ void MapgenV5Params::readParams(const Settings *settings)
 
 void MapgenV5Params::writeParams(Settings *settings) const
 {
-       settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5, (u32)-1);
+       settings->setFlagStr("mgv5_spflags", spflags, flagdesc_mapgen_v5, U32_MAX);
 
        settings->setNoiseParams("mgv5_np_filler_depth", np_filler_depth);
        settings->setNoiseParams("mgv5_np_factor",       np_factor);
@@ -429,7 +429,7 @@ MgStoneType MapgenV5::generateBiomes(float *heat_map, float *humidity_map)
 
                // If there is air or water above enable top/filler placement, otherwise force
                // nplaced to stone level by setting a number exceeding any possible filler depth.
-               u16 nplaced = (air_above || water_above) ? 0 : (u16)-1;
+               u16 nplaced = (air_above || water_above) ? 0 : U16_MAX;
 
                for (s16 y = node_max.Y; y >= node_min.Y; y--) {
                        content_t c = vm->m_data[vi].getContent();
@@ -466,7 +466,7 @@ MgStoneType MapgenV5::generateBiomes(float *heat_map, float *humidity_map)
                                // This is done by aborting the cycle of top/filler placement
                                // immediately by forcing nplaced to stone level.
                                if (c_below == CONTENT_AIR || c_below == c_water_source)
-                                       nplaced = (u16)-1;
+                                       nplaced = U16_MAX;
 
                                if (nplaced < depth_top) {
                                        vm->m_data[vi] = MapNode(biome->c_top);
@@ -491,7 +491,7 @@ MgStoneType MapgenV5::generateBiomes(float *heat_map, float *humidity_map)
                                air_above = true;
                                water_above = false;
                        } else {  // Possible various nodes overgenerated from neighbouring mapchunks
-                               nplaced = (u16)-1;  // Disable top/filler placement
+                               nplaced = U16_MAX;  // Disable top/filler placement
                                air_above = false;
                                water_above = false;
                        }
index 8492adfd92a3ead5c82b4a93ffc462763d0e0604..5a04a2d1786934f29e7a7d55bac9a6d973d5754d 100644 (file)
@@ -175,7 +175,7 @@ void MapgenV6Params::readParams(const Settings *settings)
 
 void MapgenV6Params::writeParams(Settings *settings) const
 {
-       settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6, (u32)-1);
+       settings->setFlagStr("mgv6_spflags", spflags, flagdesc_mapgen_v6, U32_MAX);
        settings->setFloat("mgv6_freq_desert", freq_desert);
        settings->setFloat("mgv6_freq_beach",  freq_beach);
 
index 92f3f49c4458002b080b2aee3ad420b4c9392d75..7ed4bc5165233645d33bbe211c34afa486bb58da 100644 (file)
@@ -181,7 +181,7 @@ void MapgenV7Params::readParams(const Settings *settings)
 
 void MapgenV7Params::writeParams(Settings *settings) const
 {
-       settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1);
+       settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, U32_MAX);
 
        settings->setNoiseParams("mgv7_np_terrain_base",    np_terrain_base);
        settings->setNoiseParams("mgv7_np_terrain_alt",     np_terrain_alt);
@@ -636,7 +636,7 @@ MgStoneType MapgenV7::generateBiomes(float *heat_map, float *humidity_map)
 
                // If there is air or water above enable top/filler placement, otherwise force
                // nplaced to stone level by setting a number exceeding any possible filler depth.
-               u16 nplaced = (air_above || water_above) ? 0 : (u16)-1;
+               u16 nplaced = (air_above || water_above) ? 0 : U16_MAX;
 
                for (s16 y = node_max.Y; y >= node_min.Y; y--) {
                        content_t c = vm->m_data[vi].getContent();
@@ -673,7 +673,7 @@ MgStoneType MapgenV7::generateBiomes(float *heat_map, float *humidity_map)
                                // This is done by aborting the cycle of top/filler placement
                                // immediately by forcing nplaced to stone level.
                                if (c_below == CONTENT_AIR || c_below == c_water_source)
-                                       nplaced = (u16)-1;
+                                       nplaced = U16_MAX;
 
                                if (nplaced < depth_top) {
                                        vm->m_data[vi] = MapNode(biome->c_top);
@@ -698,7 +698,7 @@ MgStoneType MapgenV7::generateBiomes(float *heat_map, float *humidity_map)
                                air_above = true;
                                water_above = false;
                        } else {  // Possible various nodes overgenerated from neighbouring mapchunks
-                               nplaced = (u16)-1;  // Disable top/filler placement
+                               nplaced = U16_MAX;  // Disable top/filler placement
                                air_above = false;
                                water_above = false;
                        }
index 784ceabcc493a152e060fe625f710aa96f2a819a..44af7892f76689cfb1403b2b0027932bc9bf87ad 100644 (file)
@@ -604,7 +604,7 @@ int ModApiMapgen::l_get_mapgen_params(lua_State *L)
        lua_pushinteger(L, params->chunksize);
        lua_setfield(L, -2, "chunksize");
 
-       std::string flagstr = writeFlagString(params->flags, flagdesc_mapgen, (u32)-1);
+       std::string flagstr = writeFlagString(params->flags, flagdesc_mapgen, U32_MAX);
        lua_pushstring(L, flagstr.c_str());
        lua_setfield(L, -2, "flags");
 
index 3ac8eeefbfa2c7a08148a9c20c83e12c6dcb02ba..2bd5299dc2e7fd49e51c8abfbe3b503219bba55d 100644 (file)
@@ -1187,7 +1187,7 @@ int ObjectRef::l_hud_add(lua_State *L)
        }
 
        u32 id = getServer(L)->hudAdd(player, elem);
-       if (id == (u32)-1) {
+       if (id == U32_MAX) {
                delete elem;
                return 0;
        }
index fbdaa59180a66679a92f93defafc8d2f26429bf3..b0f69f1c384fc472badeac8fe6ae2abf0400f6bd 100644 (file)
@@ -589,7 +589,7 @@ void Server::AsyncRunStep(bool initial_step)
                ScopeProfiler sp(g_profiler, "Server: map timer and unload");
                m_env->getMap().timerUpdate(map_timer_and_unload_dtime,
                        g_settings->getFloat("server_unload_unused_data_timeout"),
-                       (u32)-1);
+                       U32_MAX);
        }
 
        /*
index e226f0b2e681f4dd219649a586b4ec458fafa90a..d656b62214950c47cb95ab59d7f233a842b77933 100644 (file)
@@ -50,7 +50,7 @@ void StaticObjectList::serialize(std::ostream &os)
        size_t count = m_stored.size() + m_active.size();
        // Make sure it fits into u16, else it would get truncated and cause e.g.
        // issue #2610 (Invalid block data in database: unsupported NameIdMapping version).
-       if (count > (u16)-1) {
+       if (count > U16_MAX) {
                errorstream << "StaticObjectList::serialize(): "
                        << "too many objects (" << count << ") in list, "
                        << "not writing them to disk." << std::endl;
index df90d37bd3eacd3d9b80007e0a822658a306840c..3c000e76052627fe7488f0b665c9b25fe80ffb6f 100644 (file)
@@ -282,7 +282,7 @@ void TestUtilities::testIsPowerOfTwo()
                UASSERT(is_power_of_two((1 << exponent)) == true);
                UASSERT(is_power_of_two((1 << exponent) + 1) == false);
        }
-       UASSERT(is_power_of_two((u32)-1) == false);
+       UASSERT(is_power_of_two(U32_MAX) == false);
 }
 
 void TestUtilities::testMyround()