World items patch (by Asdow).

Adds timing logs to savegame function, similar to how we already had in loading a save file. 
Uses a global struct for unloaded sectors' inventory instead of using map item temp files every time unloaded inventory is accessed.
From timing loading and saving functions with a save that has dozens of sectors with hundreds of items each, saving is a little bit slower than before, because map item temp files have to be written to disk just before the save, when that wasn't the case before (from ~0.3 s -> ~0.5s). It is offset by a decrease in loading a game (from ~1.1s -> 0.745s), once an older save is saved at least once. Any unloaded sector inventory access during gameplay is considerably faster and for example the autoresolve lag when militia is using sector equipment is completely gone for me.
Preserves save game compatibility

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9277 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Sevenfm
2022-01-26 01:02:30 +00:00
parent be14552e32
commit 0fdaba84f6
13 changed files with 590 additions and 599 deletions
+13 -15
View File
@@ -40,6 +40,7 @@
//forward declarations of common classes to eliminate includes
class OBJECTTYPE;
class SOLDIERTYPE;
extern WorldItems gAllWorldItems;
#define MEDUNA_ITEM_DROP_OFF_GRIDNO 10959
@@ -427,9 +428,6 @@ void HandleDelayedItemsArrival( UINT32 uiReason )
// This function moves all the items that Pablos has stolen
// (or items that were delayed) to the arrival location for new shipments,
INT32 sStartGridNo;
UINT32 uiNumWorldItems, uiLoop;
BOOLEAN fOk;
std::vector<WORLDITEM> pTemp;//dnl ch75 271013
UINT8 ubLoop;
if (uiReason == NPC_SYSTEM_EVENT_ACTION_PARAM_BONUS + NPC_ACTION_RETURN_STOLEN_SHIPMENT_ITEMS )
@@ -502,24 +500,24 @@ void HandleDelayedItemsArrival( UINT32 uiReason )
else
{
// otherwise load the saved items from the item file and change the records of their locations
fOk = GetNumberOfWorldItemsFromTempItemFile( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, &uiNumWorldItems, FALSE );
if (!fOk)
std::vector<WORLDITEM> pTemp;
UINT32 uiNumWorldItems = 0;
const auto ii = FindWorldItemSector(BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z);
if (ii != -1)
{
return;
uiNumWorldItems = gAllWorldItems.NumItems[ii];
pTemp = gAllWorldItems.Items[ii];
}
pTemp.resize(uiNumWorldItems);//dnl ch75 271013
fOk = LoadWorldItemsFromTempItemFile( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, pTemp );
if (fOk)
for (UINT32 uiLoop = 0; uiLoop < uiNumWorldItems; uiLoop++)
{
for (uiLoop = 0; uiLoop < uiNumWorldItems; uiLoop++)
if (pTemp[uiLoop].sGridNo == PABLOS_STOLEN_DEST_GRIDNO)
{
if (pTemp[uiLoop].sGridNo == PABLOS_STOLEN_DEST_GRIDNO)
{
pTemp[uiLoop].sGridNo = BOBBYR_SHIPPING_DEST_GRIDNO;
}
pTemp[uiLoop].sGridNo = BOBBYR_SHIPPING_DEST_GRIDNO;
}
AddWorldItemsToUnLoadedSector( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, 0, uiNumWorldItems, pTemp, TRUE );
}
AddWorldItemsToUnLoadedSector( BOBBYR_SHIPPING_DEST_SECTOR_X, BOBBYR_SHIPPING_DEST_SECTOR_Y, BOBBYR_SHIPPING_DEST_SECTOR_Z, 0, uiNumWorldItems, pTemp, TRUE );
}
}