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"); SpriteGroupPool _spritegroup_pool("SpriteGroup");
INSTANTIATE_POOL_METHODS(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); auto profiler = std::ranges::find(_newgrf_profilers, grf, &NewGRFProfiler::grffile);
if (profiler == _newgrf_profilers.end() || !profiler->active) { if (profiler == _newgrf_profilers.end() || !profiler->active) {
if (top_level) _temp_store.ClearChanges();
return group->Resolve(object); return group->Resolve(object);
} else if (top_level) { } else if (top_level) {
profiler->BeginResolve(object); profiler->BeginResolve(object);
_temp_store.ClearChanges();
auto result = group->Resolve(object); auto result = group->Resolve(object);
profiler->EndResolve(result); profiler->EndResolve(result);
return result; return result;

View File

@ -293,6 +293,10 @@ struct ScopeResolver {
* to get the results of callbacks, rerandomisations or normal sprite lookups. * to get the results of callbacks, rerandomisations or normal sprite lookups.
*/ */
struct ResolverObject { struct ResolverObject {
private:
static TemporaryStorageArray<int32_t, 0x110> temp_store;
public:
/** /**
* Resolver constructor. * Resolver constructor.
* @param grffile NewGRF file associated with the object (or \c nullptr if none). * @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 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) 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. CallbackID callback{}; ///< Callback being resolved.
@ -438,6 +440,7 @@ public:
*/ */
void ResetState() void ResetState()
{ {
temp_store.ClearChanges();
this->last_value = 0; this->last_value = 0;
this->waiting_random_triggers = 0; this->waiting_random_triggers = 0;
this->used_random_triggers = 0; this->used_random_triggers = 0;