(svn r27984) -Codechange: Make ScopeResolver constructors/destructors inlineable. Speedup sprite resolving by about 8 percent.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
frosch 6 years ago
parent 7c406f0d9d
commit d9d669dcf8

@ -26,7 +26,18 @@ struct AirportScopeResolver : public ScopeResolver {
byte layout; ///< Layout of the airport to build.
TileIndex tile; ///< Tile for the callback, only valid for airporttile callbacks.
AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout);
/**
* Constructor of the scope resolver for an airport.
* @param ro Surrounding resolver.
* @param tile %Tile for the callback, only valid for airporttile callbacks.
* @param st %Station of the airport for which the callback is run, or \c NULL for build gui.
* @param airport_id Type of airport for which the callback is run.
* @param layout Layout of the airport to build.
*/
AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout)
: ScopeResolver(ro), st(st), airport_id(airport_id), layout(layout), tile(tile)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
@ -242,22 +253,6 @@ AirportResolverObject::AirportResolverObject(TileIndex tile, Station *st, byte a
this->root_spritegroup = AirportSpec::Get(airport_id)->grf_prop.spritegroup[0];
}
/**
* Constructor of the scope resolver for an airport.
* @param ro Surrounding resolver.
* @param tile %Tile for the callback, only valid for airporttile callbacks.
* @param st %Station of the airport for which the callback is run, or \c NULL for build gui.
* @param airport_id Type of airport for which the callback is run.
* @param layout Layout of the airport to build.
*/
AirportScopeResolver::AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout) : ScopeResolver(ro)
{
this->st = st;
this->airport_id = airport_id;
this->layout = layout;
this->tile = tile;
}
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout)
{
AirportResolverObject object(INVALID_TILE, NULL, as->GetIndex(), layout);

@ -222,21 +222,6 @@ AirportTileResolverObject::AirportTileResolverObject(const AirportTileSpec *ats,
this->root_spritegroup = ats->grf_prop.spritegroup[0];
}
/**
* Constructor of the scope resolver specific for airport tiles.
* @param ats Specification of the airport tiles.
* @param tile %Tile for the callback, only valid for airporttile callbacks.
* @param st Station of the airport for which the callback is run, or \c NULL for build gui.
*/
AirportTileScopeResolver::AirportTileScopeResolver(ResolverObject &ro, const AirportTileSpec *ats, TileIndex tile, Station *st) : ScopeResolver(ro)
{
assert(st != NULL);
this->st = st;
this->airport_id = st->airport.type;
this->tile = tile;
}
uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2, const AirportTileSpec *ats, Station *st, TileIndex tile, int extra_data = 0)
{
AirportTileResolverObject object(ats, tile, st, callback, param1, param2);

@ -17,6 +17,7 @@
#include "newgrf_animation_type.h"
#include "newgrf_commons.h"
#include "newgrf_spritegroup.h"
#include "station_base.h"
/** Scope resolver for handling the tiles of an airport. */
struct AirportTileScopeResolver : public ScopeResolver {
@ -24,7 +25,18 @@ struct AirportTileScopeResolver : public ScopeResolver {
byte airport_id; ///< Type of airport for which the callback is run.
TileIndex tile; ///< Tile for the callback, only valid for airporttile callbacks.
AirportTileScopeResolver(ResolverObject &ro, const AirportTileSpec *ats, TileIndex tile, Station *st);
/**
* Constructor of the scope resolver specific for airport tiles.
* @param ats Specification of the airport tiles.
* @param tile %Tile for the callback, only valid for airporttile callbacks.
* @param st Station of the airport for which the callback is run, or \c NULL for build gui.
*/
AirportTileScopeResolver(ResolverObject &ro, const AirportTileSpec *ats, TileIndex tile, Station *st)
: ScopeResolver(ro), st(st), tile(tile)
{
assert(st != NULL);
this->airport_id = st->airport.type;
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

@ -25,7 +25,10 @@ WaterFeature _water_feature[CF_END];
struct CanalScopeResolver : public ScopeResolver {
TileIndex tile; ///< Tile containing the canal.
CanalScopeResolver(ResolverObject &ro, TileIndex tile);
CanalScopeResolver(ResolverObject &ro, TileIndex tile)
: ScopeResolver(ro), tile(tile)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
@ -110,11 +113,6 @@ struct CanalResolverObject : public ResolverObject {
return group->loaded[0];
}
CanalScopeResolver::CanalScopeResolver(ResolverObject &ro, TileIndex tile) : ScopeResolver(ro)
{
this->tile = tile;
}
/**
* Canal resolver constructor.
* @param feature Which canal feature we want.

@ -937,21 +937,6 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
return in_motion ? group->loaded[set] : group->loading[set];
}
/**
* Scope resolver of a single vehicle.
* @param ro Surrounding resolver.
* @param engine_type Engine type
* @param v %Vehicle being resolved.
* @param info_view Indicates if the item is being drawn in an info window.
*/
VehicleScopeResolver::VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view)
: ScopeResolver(ro)
{
this->v = v;
this->self_type = engine_type;
this->info_view = info_view;
}
/**
* Get the grf file associated with an engine type.
* @param engine_type Engine to query.

@ -26,7 +26,17 @@ struct VehicleScopeResolver : public ScopeResolver {
EngineID self_type; ///< Type of the vehicle.
bool info_view; ///< Indicates if the item is being drawn in an info window.
VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view);
/**
* Scope resolver of a single vehicle.
* @param ro Surrounding resolver.
* @param engine_type Engine type
* @param v %Vehicle being resolved.
* @param info_view Indicates if the item is being drawn in an info window.
*/
VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view)
: ScopeResolver(ro), v(v), self_type(engine_type), info_view(info_view)
{
}
void SetVehicle(const Vehicle *v) { this->v = v; }

@ -31,7 +31,16 @@ struct GenericScopeResolver : public ScopeResolver {
uint8 count;
uint8 station_size;
GenericScopeResolver(ResolverObject &ro, bool ai_callback);
/**
* Generic scope resolver.
* @param ro Surrounding resolver.
* @param ai_callback Callback comes from the AI.
*/
GenericScopeResolver(ResolverObject &ro, bool ai_callback)
: ScopeResolver(ro), cargo_type(0), default_selection(0), src_industry(0), dst_industry(0), distance(0),
event(), count(0), station_size(0), ai_callback(ai_callback)
{
}
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
@ -145,24 +154,6 @@ GenericResolverObject::GenericResolverObject(bool ai_callback, CallbackID callba
{
}
/**
* Generic scope resolver.
* @param ro Surrounding resolver.
* @param ai_callback Callback comes from the AI.
*/
GenericScopeResolver::GenericScopeResolver(ResolverObject &ro, bool ai_callback) : ScopeResolver(ro)
{
this->cargo_type = 0;
this->default_selection = 0;
this->src_industry = 0;
this->dst_industry = 0;
this->distance = 0;
this->event = (AIConstructionEvent)0;
this->count = 0;
this->station_size = 0;
this->ai_callback = ai_callback;
}
/**
* Follow a generic feature callback list and return the first successful

@ -31,28 +31,6 @@ static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, NUM_HOUSES, INVALID_HOUSE_ID);
/**
* Constructor of a house scope resolver.
* @param ro Surrounding resolver.
* @param house_id House type being queried.
* @param tile %Tile containing the house.
* @param town %Town containing the house.
* @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.
*/
HouseScopeResolver::HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
: ScopeResolver(ro)
{
this->house_id = house_id;
this->tile = tile;
this->town = town;
this->not_yet_constructed = not_yet_constructed;
this->initial_random_bits = initial_random_bits;
this->watched_cargo_triggers = watched_cargo_triggers;
}
/**
* Retrieve the grf file associated with a house.
* @param house_id House to query.

@ -27,8 +27,22 @@ struct HouseScopeResolver : public ScopeResolver {
uint16 initial_random_bits; ///< Random bits during construction checks.
uint32 watched_cargo_triggers; ///< Cargo types that triggered the watched cargo callback.
/**
* Constructor of a house scope resolver.
* @param ro Surrounding resolver.
* @param house_id House type being queried.
* @param tile %Tile containing the house.
* @param town %Town containing the house.
* @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.
*/
HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers);
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
: ScopeResolver(ro), house_id(house_id), tile(tile), town(town), not_yet_constructed(not_yet_constructed),
initial_random_bits(initial_random_bits), watched_cargo_triggers(watched_cargo_triggers)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

@ -457,23 +457,6 @@ TownScopeResolver *IndustriesResolverObject::GetTown()
return this->town_scope;
}
/**
* Scope resolver for industries.
* @param ro Surrounding resolver.
* @param tile %Tile owned by the industry.
* @param industry %Industry being resolved.
* @param type Type of the industry.
* @param random_bits Random bits of the new industry.
*/
IndustriesScopeResolver::IndustriesScopeResolver(ResolverObject &ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits)
: ScopeResolver(ro)
{
this->tile = tile;
this->industry = industry;
this->type = type;
this->random_bits = random_bits;
}
/**
* Perform an industry callback.
* @param callback The callback to perform.

@ -21,7 +21,18 @@ struct IndustriesScopeResolver : public ScopeResolver {
IndustryType type; ///< Type of the industry.
uint32 random_bits; ///< Random bits of the new industry.
IndustriesScopeResolver(ResolverObject &ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits = 0);
/**
* Scope resolver for industries.
* @param ro Surrounding resolver.
* @param tile %Tile owned by the industry.
* @param industry %Industry being resolved.
* @param type Type of the industry.
* @param random_bits Random bits of the new industry.
*/
IndustriesScopeResolver(ResolverObject &ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits = 0)
: ScopeResolver(ro), tile(tile), industry(industry), type(type), random_bits(random_bits)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

@ -146,18 +146,6 @@ IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileInde
this->root_spritegroup = GetIndustryTileSpec(gfx)->grf_prop.spritegroup[0];
}
/**
* Constructor of the scope resolver for the industry tile.
* @param ro Surrounding resolver.
* @param industry %Industry owning the tile.
* @param tile %Tile of the industry.
*/
IndustryTileScopeResolver::IndustryTileScopeResolver(ResolverObject &ro, Industry *industry, TileIndex tile) : ScopeResolver(ro)
{
this->industry = industry;
this->tile = tile;
}
static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage, IndustryGfx gfx)
{
const DrawTileSprites *dts = group->ProcessRegisters(&stage);

@ -21,7 +21,16 @@ struct IndustryTileScopeResolver : public ScopeResolver {
Industry *industry; ///< Industry owning the tiles.
TileIndex tile; ///< %Tile being resolved.
IndustryTileScopeResolver(ResolverObject &ro, Industry *industry, TileIndex tile);
/**
* Constructor of the scope resolver for the industry tile.
* @param ro Surrounding resolver.
* @param industry %Industry owning the tile.
* @param tile %Tile of the industry.
*/
IndustryTileScopeResolver(ResolverObject &ro, Industry *industry, TileIndex tile)
: ScopeResolver(ro), industry(industry), tile(tile)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

@ -128,21 +128,6 @@ bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint index) const
INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectClass, ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX)
/**
* Constructor of an object scope resolver.
* @param ro Surrounding resolver.
* @param obj Object being resolved.
* @param tile %Tile of the object.
* @param view View of the object.
*/
ObjectScopeResolver::ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view)
: ScopeResolver(ro)
{
this->obj = obj;
this->tile = tile;
this->view = view;
}
/* virtual */ uint32 ObjectScopeResolver::GetRandomBits() const
{
return IsValidTile(this->tile) && IsTileType(this->tile, MP_OBJECT) ? GetObjectRandomBits(this->tile) : 0;

@ -104,7 +104,17 @@ struct ObjectScopeResolver : public ScopeResolver {
TileIndex tile; ///< The tile related to the object.
uint8 view; ///< The view of the object.
ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0);
/**
* Constructor of an object scope resolver.
* @param ro Surrounding resolver.
* @param obj Object being resolved.
* @param tile %Tile of the object.
* @param view View of the object.
*/
ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0)
: ScopeResolver(ro), obj(obj), tile(tile), view(view)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

@ -67,18 +67,6 @@
return NULL;
}
/**
* Constructor of the railtype scope resolvers.
* @param ro Surrounding resolver.
* @param tile %Tile containing the track. For track on a bridge this is the southern bridgehead.
* @param context Are we resolving sprites for the upper halftile, or on a bridge?
*/
RailTypeScopeResolver::RailTypeScopeResolver(ResolverObject &ro, TileIndex tile, TileContext context) : ScopeResolver(ro)
{
this->tile = tile;
this->context = context;
}
/**
* Resolver object for rail types.
* @param rti Railtype. NULL in NewGRF Inspect window.

@ -21,7 +21,16 @@ struct RailTypeScopeResolver : public ScopeResolver {
TileIndex tile; ///< Tracktile. For track on a bridge this is the southern bridgehead.
TileContext context; ///< Are we resolving sprites for the upper halftile, or on a bridge?
RailTypeScopeResolver(ResolverObject &ro, TileIndex tile, TileContext context);
/**
* Constructor of the railtype scope resolvers.
* @param ro Surrounding resolver.
* @param tile %Tile containing the track. For track on a bridge this is the southern bridgehead.
* @param context Are we resolving sprites for the upper halftile, or on a bridge?
*/
RailTypeScopeResolver(ResolverObject &ro, TileIndex tile, TileContext context)
: ScopeResolver(ro), tile(tile), context(context)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;

@ -83,13 +83,6 @@ static inline uint32 GetVariable(const ResolverObject &object, ScopeResolver *sc
}
}
ScopeResolver::ScopeResolver(ResolverObject &ro)
: ro(ro)
{
}
ScopeResolver::~ScopeResolver() {}
/**
* Get a few random bits. Default implementation has no random bits.
* @return Random bits.
@ -129,27 +122,6 @@ ScopeResolver::~ScopeResolver() {}
*/
/* virtual */ void ScopeResolver::StorePSA(uint reg, int32 value) {}
/**
* Resolver constructor.
* @param grffile NewGRF file associated with the object (or \c NULL if none).
* @param callback Callback code being resolved (default value is #CBID_NO_CALLBACK).
* @param callback_param1 First parameter (var 10) of the callback (only used when \a callback is also set).
* @param callback_param2 Second parameter (var 18) of the callback (only used when \a callback is also set).
*/
ResolverObject::ResolverObject(const GRFFile *grffile, CallbackID callback, uint32 callback_param1, uint32 callback_param2)
: default_scope(*this)
{
this->callback = callback;
this->callback_param1 = callback_param1;
this->callback_param2 = callback_param2;
this->ResetState();
this->grffile = grffile;
this->root_spritegroup = NULL;
}
ResolverObject::~ResolverObject() {}
/**
* Get the real sprites of the grf.
* @param group Group to get.

@ -288,8 +288,8 @@ struct IndustryProductionSpriteGroup : SpriteGroup {
struct ScopeResolver {
ResolverObject &ro; ///< Surrounding resolver object.
ScopeResolver(ResolverObject &ro);
virtual ~ScopeResolver();
ScopeResolver(ResolverObject &ro) : ro(ro) {}
virtual ~ScopeResolver() {}
virtual uint32 GetRandomBits() const;
virtual uint32 GetTriggers() const;
@ -305,8 +305,20 @@ struct ScopeResolver {
* to get the results of callbacks, rerandomisations or normal sprite lookups.
*/
struct ResolverObject {
ResolverObject(const GRFFile *grffile, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
virtual ~ResolverObject();
/**
* Resolver constructor.
* @param grffile NewGRF file associated with the object (or \c NULL if none).
* @param callback Callback code being resolved (default value is #CBID_NO_CALLBACK).
* @param callback_param1 First parameter (var 10) of the callback (only used when \a callback is also set).
* @param callback_param2 Second parameter (var 18) of the callback (only used when \a callback is also set).
*/
ResolverObject(const GRFFile *grffile, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0)
: default_scope(*this), callback(callback), callback_param1(callback_param1), callback_param2(callback_param2), grffile(grffile), root_spritegroup(NULL)
{
this->ResetState();
}
virtual ~ResolverObject() {}
ScopeResolver default_scope; ///< Default implementation of the grf scope.

@ -578,23 +578,6 @@ StationResolverObject::~StationResolverObject()
delete this->town_scope;
}
/**
* Constructor for station scopes.
* @param ro Surrounding resolver.
* @param statspec Station (type) specification.
* @param st Instance of the station.
* @param tile %Tile of the station.
*/
StationScopeResolver::StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
: ScopeResolver(ro)
{
this->tile = tile;
this->st = st;
this->statspec = statspec;
this->cargo_type = CT_INVALID;
this->axis = INVALID_AXIS;
}
/**
* Resolve sprites for drawing a station tile.
* @param statspec Station spec

@ -30,7 +30,17 @@ struct StationScopeResolver : public ScopeResolver {
CargoID cargo_type; ///< Type of cargo of the station.
Axis axis; ///< Station axis, used only for the slope check callback.
StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile);
/**
* Constructor for station scopes.
* @param ro Surrounding resolver.
* @param statspec Station (type) specification.
* @param st Instance of the station.
* @param tile %Tile of the station.
*/
StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
: ScopeResolver(ro), tile(tile), st(st), statspec(statspec), cargo_type(CT_INVALID), axis(INVALID_AXIS)
{
}
/* virtual */ uint32 GetRandomBits() const;
/* virtual */ uint32 GetTriggers() const;

@ -16,18 +16,6 @@
#include "safeguards.h"
/**
* Resolver of a town scope.
* @param ro Surrounding resolver.
* @param t %Town of the scope.
* @param readonly Scope may change persistent storage of the town.
*/
TownScopeResolver::TownScopeResolver(ResolverObject &ro, Town *t, bool readonly) : ScopeResolver(ro)
{
this->t = t;
this->readonly = readonly;
}
/* virtual */ uint32 TownScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
{
switch (variable) {

@ -25,7 +25,16 @@ struct TownScopeResolver : public ScopeResolver {
Town *t; ///< %Town of the scope.
bool readonly; ///< When set, persistent storage of the town is read-only,
TownScopeResolver(ResolverObject &ro, Town *t, bool readonly);
/**
* Resolver of a town scope.
* @param ro Surrounding resolver.
* @param t %Town of the scope.
* @param readonly Scope may change persistent storage of the town.
*/
TownScopeResolver(ResolverObject &ro, Town *t, bool readonly)
: ScopeResolver(ro), t(t), readonly(readonly)
{
}
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
virtual void StorePSA(uint reg, int32 value);

Loading…
Cancel
Save