Define and use limit constants for Irrlicht fixed-width types

This commit is contained in:
kwolekr 2015-10-04 02:50:04 -04:00
parent b12bdcce34
commit f0cd5da687
11 changed files with 31 additions and 16 deletions

View 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

View 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;

View 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);

View 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;
}

View 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);

View 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;
}

View 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");

View 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;
}

View 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);
}
/*

View 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;

View 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()