Remove fake/real indirection in HouseResolverObject
This commit is contained in:
@@ -46,7 +46,7 @@ static const GRFFile *GetHouseSpecGrf(HouseID house_id)
|
||||
/**
|
||||
* Construct a resolver for a house.
|
||||
* @param house_id House to query.
|
||||
* @param tile %Tile containing the house. INVALID_TILE to query a house type rather then a certian house tile.
|
||||
* @param tile %Tile containing the house.
|
||||
* @param town %Town containing the house.
|
||||
* @param callback Callback ID.
|
||||
* @param param1 First parameter (var 10) of the callback.
|
||||
@@ -58,28 +58,13 @@ static const GRFFile *GetHouseSpecGrf(HouseID house_id)
|
||||
HouseResolverObject::HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
|
||||
CallbackID callback, uint32 param1, uint32 param2,
|
||||
bool not_yet_constructed, uint8 initial_random_bits, CargoTypes watched_cargo_triggers)
|
||||
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2)
|
||||
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2),
|
||||
house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
|
||||
town_scope(*this, town, not_yet_constructed) // Don't access StorePSA if house is not yet constructed.
|
||||
{
|
||||
assert((tile != INVALID_TILE) == (town != nullptr));
|
||||
assert(tile == INVALID_TILE || (not_yet_constructed ? IsValidTile(tile) : GetHouseType(tile) == house_id && Town::GetByTile(tile) == town));
|
||||
|
||||
this->house_scope = (tile != INVALID_TILE) ?
|
||||
(CommonHouseScopeResolver*)new HouseScopeResolver(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers) :
|
||||
(CommonHouseScopeResolver*)new FakeHouseScopeResolver(*this, house_id);
|
||||
|
||||
this->town_scope = (town != nullptr) ?
|
||||
(ScopeResolver*)new TownScopeResolver(*this, town, not_yet_constructed) : // Don't access StorePSA if house is not yet constructed.
|
||||
(ScopeResolver*)new FakeTownScopeResolver(*this);
|
||||
|
||||
this->root_spritegroup = HouseSpec::Get(house_id)->grf_prop.spritegroup[0];
|
||||
}
|
||||
|
||||
/* virtual */ HouseResolverObject::~HouseResolverObject()
|
||||
{
|
||||
delete this->house_scope;
|
||||
delete this->town_scope;
|
||||
}
|
||||
|
||||
GrfSpecFeature HouseResolverObject::GetFeature() const
|
||||
{
|
||||
return GSF_HOUSES;
|
||||
@@ -87,7 +72,36 @@ GrfSpecFeature HouseResolverObject::GetFeature() const
|
||||
|
||||
uint32 HouseResolverObject::GetDebugID() const
|
||||
{
|
||||
return HouseSpec::Get(this->house_scope->house_id)->grf_prop.local_id;
|
||||
return HouseSpec::Get(this->house_scope.house_id)->grf_prop.local_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a resolver for a fake house.
|
||||
* @param house_id House to query.
|
||||
* @param callback Callback ID.
|
||||
* @param param1 First parameter (var 10) of the callback.
|
||||
* @param param2 Second parameter (var 18) of the callback.
|
||||
* @param not_yet_constructed House is still under construction.
|
||||
* @param initial_random_bits Random bits during construction checks.
|
||||
* @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
|
||||
*/
|
||||
FakeHouseResolverObject::FakeHouseResolverObject(HouseID house_id,
|
||||
CallbackID callback, uint32 param1, uint32 param2)
|
||||
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2),
|
||||
house_scope(*this, house_id),
|
||||
town_scope(*this) // Don't access StorePSA if house is not yet constructed.
|
||||
{
|
||||
this->root_spritegroup = HouseSpec::Get(house_id)->grf_prop.spritegroup[0];
|
||||
}
|
||||
|
||||
GrfSpecFeature FakeHouseResolverObject::GetFeature() const
|
||||
{
|
||||
return GSF_HOUSES;
|
||||
}
|
||||
|
||||
uint32 FakeHouseResolverObject::GetDebugID() const
|
||||
{
|
||||
return HouseSpec::Get(this->house_scope.house_id)->grf_prop.local_id;
|
||||
}
|
||||
|
||||
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
|
||||
@@ -608,7 +622,7 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
|
||||
|
||||
void DrawNewHouseTileInGUI(int x, int y, HouseID house_id, bool ground)
|
||||
{
|
||||
HouseResolverObject object(house_id);
|
||||
FakeHouseResolverObject object(house_id);
|
||||
const SpriteGroup *group = object.Resolve();
|
||||
if (group != nullptr && group->type == SGT_TILELAYOUT) {
|
||||
DrawTileLayoutInGUI(x, y, (const TileLayoutSpriteGroup*)group, house_id, ground);
|
||||
|
@@ -75,20 +75,39 @@ struct FakeHouseScopeResolver : public CommonHouseScopeResolver {
|
||||
|
||||
/** Resolver object to be used for houses (feature 07 spritegroups). */
|
||||
struct HouseResolverObject : public ResolverObject {
|
||||
CommonHouseScopeResolver *house_scope;
|
||||
ScopeResolver *town_scope;
|
||||
HouseScopeResolver house_scope;
|
||||
TownScopeResolver town_scope;
|
||||
|
||||
HouseResolverObject(HouseID house_id, TileIndex tile = INVALID_TILE, Town *town = nullptr,
|
||||
HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
|
||||
CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0,
|
||||
bool not_yet_constructed = false, uint8 initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0);
|
||||
|
||||
~HouseResolverObject();
|
||||
|
||||
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
|
||||
{
|
||||
switch (scope) {
|
||||
case VSG_SCOPE_SELF: return this->house_scope;
|
||||
case VSG_SCOPE_PARENT: return this->town_scope;
|
||||
case VSG_SCOPE_SELF: return &this->house_scope;
|
||||
case VSG_SCOPE_PARENT: return &this->town_scope;
|
||||
default: return ResolverObject::GetScope(scope, relative);
|
||||
}
|
||||
}
|
||||
|
||||
GrfSpecFeature GetFeature() const override;
|
||||
uint32 GetDebugID() const override;
|
||||
};
|
||||
|
||||
/** Resolver object to be used for fake houses (feature 07 spritegroups). */
|
||||
struct FakeHouseResolverObject : public ResolverObject {
|
||||
FakeHouseScopeResolver house_scope;
|
||||
FakeTownScopeResolver town_scope;
|
||||
|
||||
FakeHouseResolverObject(HouseID house_id,
|
||||
CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
|
||||
|
||||
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
|
||||
{
|
||||
switch (scope) {
|
||||
case VSG_SCOPE_SELF: return &this->house_scope;
|
||||
case VSG_SCOPE_PARENT: return &this->town_scope;
|
||||
default: return ResolverObject::GetScope(scope, relative);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user