Codechange: make no assumptions on how the internals of TileIndex work (#11183)

Basically, avoid ".value", and just cast it to its original type
if you want to retrieve this.
pull/603/merge
Patric Stout 10 months ago committed by GitHub
parent 6190f48df0
commit 5fba47b0f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -426,7 +426,7 @@ debug_inline static TileIndex TileVirtXY(uint x, uint y)
*/
debug_inline static uint TileX(TileIndex tile)
{
return tile.value & Map::MaxX();
return static_cast<uint32_t>(tile) & Map::MaxX();
}
/**
@ -436,7 +436,7 @@ debug_inline static uint TileX(TileIndex tile)
*/
debug_inline static uint TileY(TileIndex tile)
{
return tile.value >> Map::LogX();
return static_cast<uint32_t>(tile) >> Map::LogX();
}
/**

@ -53,7 +53,7 @@ public:
if constexpr (std::is_enum_v<T>) {
this->Write(static_cast<std::underlying_type_t<const T>>(data));
} else if constexpr (std::is_base_of_v<StrongTypedefBase, T>) {
this->Write(data.value);
this->Write(static_cast<typename T::Type>(data));
} else {
this->Write(data);
}
@ -146,7 +146,7 @@ public:
if constexpr (std::is_enum_v<T>) {
data = static_cast<T>(this->Read<std::underlying_type_t<T>>());
} else if constexpr (std::is_base_of_v<StrongTypedefBase, T>) {
data.value = this->Read<decltype(data.value)>();
data = this->Read<typename T::Type>();
} else {
data = this->Read<T>();
}

@ -37,7 +37,7 @@ namespace SQConvert {
template <> struct Return<int32_t> { static inline int Set(HSQUIRRELVM vm, int32_t res) { sq_pushinteger(vm, res); return 1; } };
template <> struct Return<int64_t> { static inline int Set(HSQUIRRELVM vm, int64_t res) { sq_pushinteger(vm, res); return 1; } };
template <> struct Return<Money> { static inline int Set(HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, res); return 1; } };
template <> struct Return<TileIndex> { static inline int Set(HSQUIRRELVM vm, TileIndex res) { sq_pushinteger(vm, (int32_t)res.value); return 1; } };
template <> struct Return<TileIndex> { static inline int Set(HSQUIRRELVM vm, TileIndex res) { sq_pushinteger(vm, (int32_t)static_cast<uint32_t>(res)); return 1; } };
template <> struct Return<bool> { static inline int Set(HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; } };
template <> struct Return<char *> { /* Do not use char *, use std::optional<std::string> instead. */ };
template <> struct Return<const char *> { /* Do not use const char *, use std::optional<std::string> instead. */ };

Loading…
Cancel
Save