From 00e5c1df18449992cc974b99c61a44d1385bf4a7 Mon Sep 17 00:00:00 2001 From: terkhen Date: Sun, 12 Jun 2011 20:47:45 +0000 Subject: (svn r22567) -Codechange: Store persistent storages inside a pool. --- src/newgrf_industries.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/newgrf_industries.cpp') diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index d2a56f8ac..7a06fbc38 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -283,7 +283,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par } /* Get a variable from the persistent storage */ - case 0x7C: return industry->psa.GetValue(parameter); + case 0x7C: return (industry->psa != NULL) ? industry->psa->GetValue(parameter) : 0; /* Industry structure access*/ case 0x80: return industry->location.tile; @@ -386,7 +386,19 @@ void IndustryStorePSA(ResolverObject *object, uint pos, int32 value) { Industry *ind = object->u.industry.ind; if (object->scope != VSG_SCOPE_SELF || ind->index == INVALID_INDUSTRY) return; - ind->psa.StoreValue(pos, value); + + if (ind->psa == NULL) { + /* There is no need to create a storage if the value is zero. */ + if (value == 0) return; + + /* Create storage on first modification. */ + const IndustrySpec *indsp = GetIndustrySpec(ind->type); + uint32 grfid = (indsp->grf_prop.grffile != NULL) ? indsp->grf_prop.grffile->grfid : 0; + assert(PersistentStorage::CanAllocateItem()); + ind->psa = new PersistentStorage(grfid); + } + + ind->psa->StoreValue(pos, value); } static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type) -- cgit v1.2.3-54-g00ecf