1
0
Fork 0

Codechange: Make temporary storage a member of ResolverObject.

pull/14224/head
frosch 2025-05-05 21:35:47 +02:00 committed by frosch
parent eb9bbb2456
commit f8c928ed98
2 changed files with 8 additions and 7 deletions

View File

@ -18,7 +18,7 @@
SpriteGroupPool _spritegroup_pool("SpriteGroup");
INSTANTIATE_POOL_METHODS(SpriteGroup)
TemporaryStorageArray<int32_t, 0x110> _temp_store;
/* static */ TemporaryStorageArray<int32_t, 0x110> ResolverObject::temp_store;
/**
@ -39,11 +39,9 @@ TemporaryStorageArray<int32_t, 0x110> _temp_store;
auto profiler = std::ranges::find(_newgrf_profilers, grf, &NewGRFProfiler::grffile);
if (profiler == _newgrf_profilers.end() || !profiler->active) {
if (top_level) _temp_store.ClearChanges();
return group->Resolve(object);
} else if (top_level) {
profiler->BeginResolve(object);
_temp_store.ClearChanges();
auto result = group->Resolve(object);
profiler->EndResolve(result);
return result;

View File

@ -293,6 +293,10 @@ struct ScopeResolver {
* to get the results of callbacks, rerandomisations or normal sprite lookups.
*/
struct ResolverObject {
private:
static TemporaryStorageArray<int32_t, 0x110> temp_store;
public:
/**
* Resolver constructor.
* @param grffile NewGRF file associated with the object (or \c nullptr if none).
@ -323,8 +327,7 @@ struct ResolverObject {
*/
inline int32_t GetRegister(uint i) const
{
extern TemporaryStorageArray<int32_t, 0x110> _temp_store;
return _temp_store.GetValue(i);
return temp_store.GetValue(i);
}
/**
@ -335,8 +338,7 @@ struct ResolverObject {
*/
inline void SetRegister(uint i, int32_t value)
{
extern TemporaryStorageArray<int32_t, 0x110> _temp_store;
_temp_store.StoreValue(i, value);
temp_store.StoreValue(i, value);
}
CallbackID callback{}; ///< Callback being resolved.
@ -438,6 +440,7 @@ public:
*/
void ResetState()
{
temp_store.ClearChanges();
this->last_value = 0;
this->waiting_random_triggers = 0;
this->used_random_triggers = 0;