Mercurial > hg > openttd
changeset 17780:6da2ed3e68e4 draft
(svn r22565) -Codechange: Use helper functions for getting the persistent storage in the NewGRF debug GUI.
author | terkhen <terkhen@openttd.org> |
---|---|
date | Sun, 12 Jun 2011 20:41:17 +0000 |
parents | c4ca794c8396 |
children | dceca5355f39 |
files | src/newgrf_debug_gui.cpp src/table/newgrf_debug_data.h |
diffstat | 2 files changed, 34 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -156,6 +156,28 @@ 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 @@ 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 @@ } } - 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]); } }
--- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -74,8 +74,6 @@ _nic_vehicles, _niv_vehicles, new NIHVehicle(), - 0, - 0 }; @@ -132,8 +130,6 @@ _nic_stations, _niv_stations, new NIHStation(), - 0, - 0 }; @@ -193,8 +189,6 @@ _nic_house, _niv_house, new NIHHouse(), - 0, - 0 }; @@ -239,8 +233,6 @@ _nic_industrytiles, _niv_industrytiles, new NIHIndustryTile(), - 0, - 0 }; @@ -299,6 +291,13 @@ 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 @@ _nic_industries, _niv_industries, new NIHIndustry(), - cpp_lengthof(Industry, psa.storage), - cpp_offsetof(Industry, psa.storage) }; @@ -357,8 +354,6 @@ _nic_objects, _niv_objects, new NIHObject(), - 0, - 0 }; @@ -385,8 +380,6 @@ NULL, _niv_railtypes, new NIHRailType(), - 0, - 0 }; @@ -415,8 +408,6 @@ _nic_airporttiles, _niv_industrytiles, // Yes, they share this (at least now) new NIHAirportTile(), - 0, - 0 }; @@ -449,8 +440,6 @@ NULL, _niv_towns, new NIHTown(), - 0, - 0 }; /** Table with all NIFeatures. */