diff options
author | kwolekr <kwolekr@minetest.net> | 2015-10-04 02:50:04 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-10-04 04:00:16 -0400 |
commit | f0cd5da687ca216b4bdd9abe7bc8038a679d3763 (patch) | |
tree | 329909b22c4494a2df2249c5697acb961b0fc527 | |
parent | b12bdcce348323247811b9a0299e2e9294991d13 (diff) | |
download | minetest-f0cd5da687ca216b4bdd9abe7bc8038a679d3763.tar.gz minetest-f0cd5da687ca216b4bdd9abe7bc8038a679d3763.tar.bz2 minetest-f0cd5da687ca216b4bdd9abe7bc8038a679d3763.zip |
Define and use limit constants for Irrlicht fixed-width types
-rw-r--r-- | src/irrlichttypes.h | 15 | ||||
-rw-r--r-- | src/map.cpp | 2 | ||||
-rw-r--r-- | src/mapgen.cpp | 2 | ||||
-rw-r--r-- | src/mapgen_v5.cpp | 8 | ||||
-rw-r--r-- | src/mapgen_v6.cpp | 2 | ||||
-rw-r--r-- | src/mapgen_v7.cpp | 8 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 2 | ||||
-rw-r--r-- | src/server.cpp | 2 | ||||
-rw-r--r-- | src/staticobject.cpp | 2 | ||||
-rw-r--r-- | src/unittest/test_utilities.cpp | 2 |
11 files changed, 31 insertions, 16 deletions
diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h index bead64407..dedebd45b 100644 --- a/src/irrlichttypes.h +++ b/src/irrlichttypes.h @@ -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 diff --git a/src/map.cpp b/src/map.cpp index fd796734e..e3cafd673 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -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; diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 31d394fa4..a94b071c5 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -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); diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index dbbd72936..d534249a5 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -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; } diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 8492adfd9..5a04a2d17 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -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); diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index 92f3f49c4..7ed4bc516 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -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; } diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 784ceabcc..44af7892f 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -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"); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 3ac8eeefb..2bd5299dc 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -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; } diff --git a/src/server.cpp b/src/server.cpp index fbdaa5918..b0f69f1c3 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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); } /* diff --git a/src/staticobject.cpp b/src/staticobject.cpp index e226f0b2e..d656b6221 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -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; diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp index df90d37bd..3c000e760 100644 --- a/src/unittest/test_utilities.cpp +++ b/src/unittest/test_utilities.cpp @@ -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() |