1
0
Fork 0

Codechange: strongly type ObjectID

pull/13511/head
Rubidium 2025-01-31 21:46:25 +01:00 committed by rubidium42
parent c311e6e4a9
commit cb3db3cedd
4 changed files with 9 additions and 7 deletions

View File

@ -16,7 +16,7 @@
#include "town_type.h" #include "town_type.h"
#include "timer/timer_game_calendar.h" #include "timer/timer_game_calendar.h"
typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool; using ObjectPool = Pool<Object, ObjectID, 64, ObjectID::End().base()>;
extern ObjectPool _object_pool; extern ObjectPool _object_pool;
/** An object, such as transmitter, on the map. */ /** An object, such as transmitter, on the map. */

View File

@ -47,7 +47,7 @@ inline bool IsObjectTypeTile(Tile t, ObjectType type)
inline ObjectID GetObjectIndex(Tile t) inline ObjectID GetObjectIndex(Tile t)
{ {
assert(IsTileType(t, MP_OBJECT)); assert(IsTileType(t, MP_OBJECT));
return t.m2() | t.m5() << 16; return ObjectID(t.m2() | t.m5() << 16);
} }
/** /**
@ -76,10 +76,10 @@ inline void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, uint8_t r
SetTileType(t, MP_OBJECT); SetTileType(t, MP_OBJECT);
SetTileOwner(t, o); SetTileOwner(t, o);
SetWaterClass(t, wc); SetWaterClass(t, wc);
t.m2() = index; t.m2() = index.base();
t.m3() = random; t.m3() = random;
t.m4() = 0; t.m4() = 0;
t.m5() = index >> 16; t.m5() = index.base() >> 16;
SB(t.m6(), 2, 4, 0); SB(t.m6(), 2, 4, 0);
t.m7() = 0; t.m7() = 0;
} }

View File

@ -10,6 +10,8 @@
#ifndef OBJECT_TYPE_H #ifndef OBJECT_TYPE_H
#define OBJECT_TYPE_H #define OBJECT_TYPE_H
#include "core/pool_type.hpp"
/** Types of objects. */ /** Types of objects. */
typedef uint16_t ObjectType; typedef uint16_t ObjectType;
@ -25,11 +27,11 @@ static const ObjectType NUM_OBJECTS_PER_GRF = NUM_OBJECTS; ///< Number of suppor
static const ObjectType INVALID_OBJECT_TYPE = 0xFFFF; ///< An invalid object static const ObjectType INVALID_OBJECT_TYPE = 0xFFFF; ///< An invalid object
/** Unique identifier for an object. */ /** Unique identifier for an object. */
typedef uint32_t ObjectID; using ObjectID = PoolID<uint32_t, struct ObjectIDTag, 0xFF0000, 0xFFFFFFFF>;
struct Object; struct Object;
struct ObjectSpec; struct ObjectSpec;
static const ObjectID INVALID_OBJECT = 0xFFFFFFFF; ///< An invalid object static constexpr ObjectID INVALID_OBJECT = ObjectID::Invalid(); ///< An invalid object
#endif /* OBJECT_TYPE_H */ #endif /* OBJECT_TYPE_H */

View File

@ -2113,7 +2113,7 @@ bool AfterLoadGame()
o->location.h = size; o->location.h = size;
o->build_date = TimerGameCalendar::date; o->build_date = TimerGameCalendar::date;
o->town = type == OBJECT_STATUE ? Town::Get(t.m2()) : CalcClosestTownFromTile(t, UINT_MAX); o->town = type == OBJECT_STATUE ? Town::Get(t.m2()) : CalcClosestTownFromTile(t, UINT_MAX);
t.m2() = o->index; t.m2() = o->index.base();
Object::IncTypeCount(type); Object::IncTypeCount(type);
} else { } else {
/* We're at an offset, so get the ID from our "root". */ /* We're at an offset, so get the ID from our "root". */