mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
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:
+16
-32
@@ -55,6 +55,7 @@ void HourlyFactoryUpdate(); // Flugente: update factories
|
||||
void HourlySnitchUpdate(); // anv: decreasing cooldown after exposition
|
||||
|
||||
extern SECTOR_EXT_DATA SectorExternalData[256][4];
|
||||
extern WorldItems gAllWorldItems;
|
||||
|
||||
extern INT32 GetCurrentBalance( void );
|
||||
extern void PayOffSkyriderDebtIfAny( );
|
||||
@@ -841,37 +842,30 @@ void HourlyStealUpdate()
|
||||
|
||||
BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usItem, UINT32 usNumToRemove )
|
||||
{
|
||||
// open sector inv
|
||||
UINT32 uiTotalNumberOfRealItems = 0;
|
||||
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
|
||||
BOOLEAN fReturn = FALSE;
|
||||
|
||||
// open sector inventory
|
||||
if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) )
|
||||
{
|
||||
uiTotalNumberOfRealItems = guiNumWorldItems;
|
||||
|
||||
pWorldItem = gWorldItems;
|
||||
}
|
||||
else
|
||||
{
|
||||
// not loaded, load
|
||||
// get total number, visable and invisible
|
||||
fReturn = GetNumberOfWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, &( uiTotalNumberOfRealItems ), FALSE );
|
||||
Assert( fReturn );
|
||||
|
||||
if ( uiTotalNumberOfRealItems > 0 )
|
||||
// Check for unloaded sector
|
||||
const auto i = FindWorldItemSector( sSectorX, sSectorY, bSectorZ);
|
||||
if (i != -1)
|
||||
{
|
||||
// allocate space for the list
|
||||
pWorldItem.resize( uiTotalNumberOfRealItems );//dnl ch75 271013
|
||||
|
||||
// now load into mem
|
||||
LoadWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, pWorldItem );
|
||||
uiTotalNumberOfRealItems = gAllWorldItems.NumItems[i];
|
||||
pWorldItem = gAllWorldItems.Items[i];
|
||||
}
|
||||
}
|
||||
|
||||
if ( !uiTotalNumberOfRealItems )
|
||||
return FALSE;
|
||||
|
||||
|
||||
BOOLEAN removedsth = FALSE;
|
||||
OBJECTTYPE* pObj = NULL;
|
||||
for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems && usNumToRemove > 0; ++uiCount ) // ... for all items in the world ...
|
||||
@@ -906,7 +900,6 @@ BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT1
|
||||
if ( removedsth )
|
||||
{
|
||||
// save the changed inventory
|
||||
// open sector inv
|
||||
if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) )
|
||||
{
|
||||
guiNumWorldItems = uiTotalNumberOfRealItems;
|
||||
@@ -914,8 +907,7 @@ BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT1
|
||||
}
|
||||
else
|
||||
{
|
||||
//Save the Items to the the file
|
||||
SaveWorldItemsToTempItemFile( sSectorX, sSectorY, bSectorZ, uiTotalNumberOfRealItems, pWorldItem );
|
||||
UpdateWorldItems(sSectorX, sSectorY, bSectorZ, uiTotalNumberOfRealItems, pWorldItem);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -927,35 +919,27 @@ BOOLEAN RemoveItemInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT1
|
||||
UINT32 CountAccessibleItemsInSector( INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ, UINT16 usItem )
|
||||
{
|
||||
UINT32 numfound = 0;
|
||||
|
||||
// open sector inv
|
||||
UINT32 uiTotalNumberOfRealItems = 0;
|
||||
std::vector<WORLDITEM> pWorldItem;//dnl ch75 271013
|
||||
BOOLEAN fReturn = FALSE;
|
||||
|
||||
// open sector inv
|
||||
if ( ( gWorldSectorX == sSectorX ) && ( gWorldSectorY == sSectorY ) && ( gbWorldSectorZ == bSectorZ ) )
|
||||
{
|
||||
uiTotalNumberOfRealItems = guiNumWorldItems;
|
||||
|
||||
pWorldItem = gWorldItems;
|
||||
}
|
||||
else
|
||||
{
|
||||
// not loaded, load
|
||||
// get total number, visable and invisible
|
||||
fReturn = GetNumberOfWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, &( uiTotalNumberOfRealItems ), FALSE );
|
||||
Assert( fReturn );
|
||||
|
||||
if ( uiTotalNumberOfRealItems > 0 )
|
||||
// Check for unloaded sector
|
||||
const auto i = FindWorldItemSector(sSectorX, sSectorY, bSectorZ);
|
||||
if (i != -1)
|
||||
{
|
||||
// allocate space for the list
|
||||
pWorldItem.resize( uiTotalNumberOfRealItems );//dnl ch75 271013
|
||||
|
||||
// now load into mem
|
||||
LoadWorldItemsFromTempItemFile( sSectorX, sSectorY, bSectorZ, pWorldItem );
|
||||
uiTotalNumberOfRealItems = gAllWorldItems.NumItems[i];
|
||||
pWorldItem = gAllWorldItems.Items[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OBJECTTYPE* pObj = NULL;
|
||||
for ( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems; ++uiCount ) // ... for all items in the world ...
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user