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
@@ -50,6 +50,7 @@
class OBJECTTYPE;
class SOLDIERTYPE;
extern UILayout_Map UI_MAP;
extern WorldItems gAllWorldItems;
// Flugente: external sector data
extern SECTOR_EXT_DATA SectorExternalData[256][4];
@@ -1175,8 +1176,7 @@ void SaveSeenAndUnseenItems( void )
}
else
{
Assert(SaveWorldItemsToTempItemFile(sSelMapX, sSelMapY, iCurrentMapSectorZ, uiNumberOfSeenItems + uiNumberOfUnSeenItems, pInventoryPoolList, FALSE));
SetNumberOfVisibleWorldItemsInSectorStructureForSector(sSelMapX, sSelMapY, iCurrentMapSectorZ, uiTotalNumberOfVisibleItems);
UpdateWorldItems(sSelMapX, sSelMapY, iCurrentMapSectorZ, uiNumberOfSeenItems + uiNumberOfUnSeenItems, pInventoryPoolList);
}
#endif
}
@@ -2345,13 +2345,23 @@ void BuildStashForSelectedSector( INT16 sMapX, INT16 sMapY, INT16 sMapZ )
}
else// if map not loaded, use tempfile to build lists
{
Assert(GetNumberOfWorldItemsFromTempItemFile(sMapX, sMapY, (INT8)sMapZ, &uiTotalNumberOfItems, FALSE));
const auto ii = FindWorldItemSector(sMapX, sMapY, (INT8)sMapZ);
if (ii == -1)
{
uiTotalNumberOfItems = 0;
}
else
{
uiTotalNumberOfItems = gAllWorldItems.NumItems[ii];
pInventoryPoolList = gAllWorldItems.Items[ii];
}
uiNumOfSlots = (uiTotalNumberOfItems / MAP_INVENTORY_POOL_SLOT_COUNT + 1) * MAP_INVENTORY_POOL_SLOT_COUNT;
if(pInventoryPoolList.size() < uiNumOfSlots)
pInventoryPoolList.resize(uiNumOfSlots);
if(pUnSeenItems.size() < uiNumOfSlots)
pUnSeenItems.resize(uiNumOfSlots);
Assert(LoadWorldItemsFromTempItemFile(sMapX, sMapY, (INT8)sMapZ, pInventoryPoolList));
uiNumberOfSeenItems = uiTotalNumberOfItems;
uiNumberOfUnSeenItems = 0;
pipl = &pInventoryPoolList.front();