mirror of https://github.com/OpenTTD/OpenTTD
(svn r22565) -Codechange: Use helper functions for getting the persistent storage in the NewGRF debug GUI.
parent
0749c65d74
commit
281bed03f4
|
@ -156,6 +156,28 @@ public:
|
|||
return ro.GetVariable(&ro, var, param, avail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to know the size of the persistent storage.
|
||||
* @param index Unused.
|
||||
* @param grfid Unused.
|
||||
* @return Size of the persistent storage in indices.
|
||||
*/
|
||||
virtual uint GetPSASize(uint index, uint32 grfid) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first position of the array containing the persistent storage.
|
||||
* @param index Unused.
|
||||
* @param grfid Unused.
|
||||
* @return Pointer to the first position of the storage array or NULL if not present.
|
||||
*/
|
||||
virtual int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Actually execute the real resolving for a given (instance) index.
|
||||
|
@ -199,8 +221,6 @@ struct NIFeature {
|
|||
const NICallback *callbacks; ///< The callbacks associated with this feature.
|
||||
const NIVariable *variables; ///< The variables associated with this feature.
|
||||
const NIHelper *helper; ///< The class container all helper functions.
|
||||
uint psa_size; ///< The size of the persistent storage in indices.
|
||||
size_t psa_offset; ///< Offset to the array in the PSA.
|
||||
};
|
||||
|
||||
/* Load all the NewGRF debug data; externalised as it is just a huge bunch of tables. */
|
||||
|
@ -348,11 +368,12 @@ struct NewGRFInspectWindow : Window {
|
|||
}
|
||||
}
|
||||
|
||||
if (nif->psa_size != 0) {
|
||||
uint psa_size = nih->GetPSASize(0, 0);
|
||||
if (psa_size != 0) {
|
||||
this->DrawString(r, i++, "Persistent storage:");
|
||||
assert(nif->psa_size % 4 == 0);
|
||||
int32 *psa = (int32*)((byte*)base + nif->psa_offset);
|
||||
for (uint j = 0; j < nif->psa_size; j += 4, psa += 4) {
|
||||
assert(psa_size % 4 == 0);
|
||||
int32 *psa = nih->GetPSAFirstPosition(0, 0);
|
||||
for (uint j = 0; j < psa_size; j += 4, psa += 4) {
|
||||
this->DrawString(r, i++, " %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,6 @@ static const NIFeature _nif_vehicle = {
|
|||
_nic_vehicles,
|
||||
_niv_vehicles,
|
||||
new NIHVehicle(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
@ -132,8 +130,6 @@ static const NIFeature _nif_station = {
|
|||
_nic_stations,
|
||||
_niv_stations,
|
||||
new NIHStation(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
@ -193,8 +189,6 @@ static const NIFeature _nif_house = {
|
|||
_nic_house,
|
||||
_niv_house,
|
||||
new NIHHouse(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
@ -239,8 +233,6 @@ static const NIFeature _nif_industrytile = {
|
|||
_nic_industrytiles,
|
||||
_niv_industrytiles,
|
||||
new NIHIndustryTile(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
@ -299,6 +291,13 @@ class NIHIndustry : public NIHelper {
|
|||
const void *GetSpec(uint index) const { return GetIndustrySpec(Industry::Get(index)->type); }
|
||||
void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); }
|
||||
void Resolve(ResolverObject *ro, uint32 index) const { extern void GetIndustryResolver(ResolverObject *ro, uint index); GetIndustryResolver(ro, index); }
|
||||
uint GetPSASize(uint index, uint32 grfid) const { return cpp_lengthof(Industry, psa.storage); }
|
||||
|
||||
int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
|
||||
{
|
||||
const void *base = this->GetInstance(index);
|
||||
return (int32*)((byte*)base + cpp_offsetof(Industry, psa.storage));
|
||||
}
|
||||
};
|
||||
|
||||
static const NIFeature _nif_industry = {
|
||||
|
@ -306,8 +305,6 @@ static const NIFeature _nif_industry = {
|
|||
_nic_industries,
|
||||
_niv_industries,
|
||||
new NIHIndustry(),
|
||||
cpp_lengthof(Industry, psa.storage),
|
||||
cpp_offsetof(Industry, psa.storage)
|
||||
};
|
||||
|
||||
|
||||
|
@ -357,8 +354,6 @@ static const NIFeature _nif_object = {
|
|||
_nic_objects,
|
||||
_niv_objects,
|
||||
new NIHObject(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
@ -385,8 +380,6 @@ static const NIFeature _nif_railtype = {
|
|||
NULL,
|
||||
_niv_railtypes,
|
||||
new NIHRailType(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
@ -415,8 +408,6 @@ static const NIFeature _nif_airporttile = {
|
|||
_nic_airporttiles,
|
||||
_niv_industrytiles, // Yes, they share this (at least now)
|
||||
new NIHAirportTile(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
|
@ -449,8 +440,6 @@ static const NIFeature _nif_town = {
|
|||
NULL,
|
||||
_niv_towns,
|
||||
new NIHTown(),
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
/** Table with all NIFeatures. */
|
||||
|
|
Loading…
Reference in New Issue