mirror of
https://github.com/1dot13/source.git
synced 2026-09-16 14:47:17 +02:00
speed up item movement by lowering the number of inventory accesses
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6282 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+46
-14
@@ -5915,6 +5915,8 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
|
|||||||
CHAR16 wSectorName[ 64 ];
|
CHAR16 wSectorName[ 64 ];
|
||||||
GetShortSectorString( sMapX, sMapY, wSectorName );
|
GetShortSectorString( sMapX, sMapY, wSectorName );
|
||||||
|
|
||||||
|
WORLDITEM* pWorldItem_Target = NULL;
|
||||||
|
|
||||||
// now loop over all sectors from which we take stuff, and move the equipment
|
// now loop over all sectors from which we take stuff, and move the equipment
|
||||||
std::map<UINT8, UINT8>::iterator itend = sectormercmap.end();
|
std::map<UINT8, UINT8>::iterator itend = sectormercmap.end();
|
||||||
for (std::map<UINT8, UINT8>::iterator it = sectormercmap.begin(); it != itend; ++it)
|
for (std::map<UINT8, UINT8>::iterator it = sectormercmap.begin(); it != itend; ++it)
|
||||||
@@ -5942,7 +5944,13 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
|
|||||||
// open the inventory of the sector we are taking stuff from
|
// open the inventory of the sector we are taking stuff from
|
||||||
SECTORINFO *pSectorInfo_Target = &( SectorInfo[ SECTOR(targetX, targetY) ] );
|
SECTORINFO *pSectorInfo_Target = &( SectorInfo[ SECTOR(targetX, targetY) ] );
|
||||||
UINT32 uiTotalNumberOfRealItems_Target = 0;
|
UINT32 uiTotalNumberOfRealItems_Target = 0;
|
||||||
WORLDITEM* pWorldItem_Target = NULL;
|
|
||||||
|
// use the new map
|
||||||
|
if ( pWorldItem_Target )
|
||||||
|
{
|
||||||
|
delete[] pWorldItem_Target;
|
||||||
|
pWorldItem_Target = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if( ( gWorldSectorX == targetX )&&( gWorldSectorY == targetY ) && (gbWorldSectorZ == bZ ) )
|
if( ( gWorldSectorX == targetX )&&( gWorldSectorY == targetY ) && (gbWorldSectorZ == bZ ) )
|
||||||
{
|
{
|
||||||
@@ -5969,6 +5977,9 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
|
|||||||
// move items from Target to Here
|
// move items from Target to Here
|
||||||
UINT16 moveditems = 0;
|
UINT16 moveditems = 0;
|
||||||
UINT32 movedweight = 0;
|
UINT32 movedweight = 0;
|
||||||
|
OBJECTTYPE* pObjectToMove = new OBJECTTYPE[uiTotalNumberOfRealItems_Target];
|
||||||
|
UINT8 moveobjectcounter = 0;
|
||||||
|
|
||||||
for( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems_Target; ++uiCount ) // ... for all items in the world ...
|
for( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems_Target; ++uiCount ) // ... for all items in the world ...
|
||||||
{
|
{
|
||||||
if( pWorldItem_Target[ uiCount ].fExists ) // ... if item exists ...
|
if( pWorldItem_Target[ uiCount ].fExists ) // ... if item exists ...
|
||||||
@@ -5982,16 +5993,8 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
|
|||||||
{
|
{
|
||||||
moveditems += pObj->ubNumberOfObjects;
|
moveditems += pObj->ubNumberOfObjects;
|
||||||
movedweight += CalculateObjectWeight(pObj);
|
movedweight += CalculateObjectWeight(pObj);
|
||||||
|
|
||||||
// move
|
pObjectToMove[moveobjectcounter++] = *pObj;
|
||||||
if( ( gWorldSectorX == sMapX )&&( gWorldSectorY == sMapY ) && (gbWorldSectorZ == bZ ) )
|
|
||||||
{
|
|
||||||
AddItemToPool( RandomGridNo(), pObj, 1 , 0, (WOLRD_ITEM_FIND_SWEETSPOT_FROM_GRIDNO|WORLD_ITEM_REACHABLE), -1 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AddItemsToUnLoadedSector( sMapX, sMapY, bZ, RandomGridNo(), 1, pObj, 0, WORLD_ITEM_REACHABLE, 0, 1, FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
pWorldItem_Target[ uiCount ].fExists = FALSE;
|
pWorldItem_Target[ uiCount ].fExists = FALSE;
|
||||||
|
|
||||||
@@ -6004,13 +6007,32 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move
|
||||||
|
if( ( gWorldSectorX == sMapX )&&( gWorldSectorY == sMapY ) && (gbWorldSectorZ == bZ ) )
|
||||||
|
{
|
||||||
|
for (UINT16 i = 0; i < moveobjectcounter; ++i )
|
||||||
|
{
|
||||||
|
AddItemToPool( RandomGridNo(), &(pObjectToMove[i]), 1 , 0, (WOLRD_ITEM_FIND_SWEETSPOT_FROM_GRIDNO|WORLD_ITEM_REACHABLE), -1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddItemsToUnLoadedSector( sMapX, sMapY, bZ, RandomGridNo(), moveobjectcounter, pObjectToMove, 0, WORLD_ITEM_REACHABLE, 0, 1, FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( pObjectToMove )
|
||||||
|
{
|
||||||
|
delete[] pObjectToMove;
|
||||||
|
pObjectToMove = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CHAR16 wSectorName_Target[ 64 ];
|
CHAR16 wSectorName_Target[ 64 ];
|
||||||
GetShortSectorString( targetX, targetY, wSectorName_Target );
|
GetShortSectorString( targetX, targetY, wSectorName_Target );
|
||||||
|
|
||||||
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"%d items moved from %s to %s", moveditems, wSectorName_Target, wSectorName );
|
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"%d items moved from %s to %s", moveditems, wSectorName_Target, wSectorName );
|
||||||
|
|
||||||
// if we didn't move any item, no need to save a chanted inventory etc.
|
// if we didn't move any item, no need to save a changed inventory etc.
|
||||||
if ( !moveditems )
|
if ( !moveditems )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -6029,6 +6051,12 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use the new map
|
// use the new map
|
||||||
|
if ( pWorldItem_Target )
|
||||||
|
{
|
||||||
|
delete[] pWorldItem_Target;
|
||||||
|
pWorldItem_Target = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pWorldItem_Target = pWorldItem_tmp;
|
pWorldItem_Target = pWorldItem_tmp;
|
||||||
|
|
||||||
// save the changed inventory
|
// save the changed inventory
|
||||||
@@ -6042,8 +6070,12 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ )
|
|||||||
//Save the Items to the the file
|
//Save the Items to the the file
|
||||||
SaveWorldItemsToTempItemFile( targetX, targetY, bZ, uiTotalNumberOfRealItems_Target, pWorldItem_Target );
|
SaveWorldItemsToTempItemFile( targetX, targetY, bZ, uiTotalNumberOfRealItems_Target, pWorldItem_Target );
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] pWorldItem_tmp;
|
if ( pWorldItem_tmp )
|
||||||
|
{
|
||||||
|
delete[] pWorldItem_tmp;
|
||||||
|
pWorldItem_tmp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// award a bit of experience to the movers
|
// award a bit of experience to the movers
|
||||||
UINT16 itemsperperson = moveditems / (*it).second;
|
UINT16 itemsperperson = moveditems / (*it).second;
|
||||||
|
|||||||
Reference in New Issue
Block a user