Brief: //dnl ch75

- More map editor fixes and map inventory pool performance improvement for big maps.
Details:
- Fix not showing expected messagebox on exit (ALT+x) which also throw exception and goes to improper mapeditor exit.
- Fix second annoying sticky message which shouldn't popup during map loading and performing RemoveProhibitedAttachments.
- Fix CTD when delete all enemies or civilians or all of them in map.
- Fix some std exception when reporting for missing optional xml file.
- Fix memory and map corruption in old mapeditors if loaded old map has item with invalid attachment and we try to attach something else.
- As years ago pInventoryPoolList had migrated from WORLDITEM* array to std::vector<WORLDITEM> it was time to do that with gWorldItems too, all necessary functions which need to be adopted to gWorldItems std::vector type are also changed.
- Resize code for gWorldItems is changed hoping will lead into less corruption problems as now could occur in mapeditor and game when code automatically doing attachment changes.
- Change code for handling map inventory which now should be fast enough to support AIMNAS project which will probably deal with thousands of items per map.


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6554 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Kriplo
2013-11-03 16:26:30 +00:00
parent 0c82c1845f
commit b91bc7b209
24 changed files with 593 additions and 711 deletions
+28 -40
View File
@@ -30,7 +30,7 @@
#endif
//Global dynamic array of all of the items in a loaded map.
WORLDITEM * gWorldItems = NULL;
std::vector<WORLDITEM> gWorldItems;//dnl ch75 261013
UINT32 guiNumWorldItems = 0;
WORLDBOMB * gWorldBombs = NULL;
@@ -393,43 +393,16 @@ void FindPanicBombsAndTriggers( void )
}
}
INT32 GetFreeWorldItemIndex( void )
UINT32 GetFreeWorldItemIndex(void)//dnl ch75 271013
{
UINT32 uiCount;
WORLDITEM *newWorldItems;
UINT32 uiOldNumWorldItems;
for(uiCount=0; uiCount < guiNumWorldItems; uiCount++)
{
if ( gWorldItems[ uiCount ].fExists == FALSE )
return( (INT32)uiCount );
}
uiOldNumWorldItems = guiNumWorldItems;
// grow by 3/2 as a better strategy, minimum 10
guiNumWorldItems = max(10, guiNumWorldItems * 3 / 2);
//Allocate new table with max+10 items.
newWorldItems = new WORLDITEM [ guiNumWorldItems ];
if (newWorldItems == NULL)
{
return( -1 );
}
if (gWorldItems)
{
for (unsigned int x = 0; x < uiOldNumWorldItems; ++x)
{
newWorldItems[x] = gWorldItems[x];
}
delete[] gWorldItems;
}
gWorldItems = newWorldItems;
// Return uiCount.....
return( uiCount );
for(uiCount=0; uiCount<gWorldItems.size(); uiCount++)
if(gWorldItems[uiCount].fExists == FALSE)
return(uiCount);
ResizeWorldItems();
return(uiCount);
}
UINT32 GetNumUsedWorldItems( void )
{
UINT32 uiCount, uiNumItems;
@@ -446,7 +419,22 @@ UINT32 GetNumUsedWorldItems( void )
return( uiNumItems );
}
void ResizeWorldItems(void)//dnl ch75 271013
{
#ifdef INVFIX_Moa
// grow by 3/2 as a better strategy, minimum 10
guiNumWorldItems = max(10, guiNumWorldItems * 3 / 2);
//Allocate new table with max+10 items.
gWorldItems.resize(guiNumWorldItems);
#else
guiNumWorldItems = gWorldItems.size();
if(guiNumWorldItems - GetNumUsedWorldItems() < 100)
{
gWorldItems.resize(guiNumWorldItems + 100);
guiNumWorldItems = gWorldItems.size();
}
#endif
}
INT32 AddItemToWorld( INT32 sGridNo, OBJECTTYPE *pObject, UINT8 ubLevel, UINT16 usFlags, INT8 bRenderZHeightAboveLevel, INT8 bVisible, INT8 soldierID )
{
@@ -538,7 +526,7 @@ void RemoveItemFromWorld( INT32 iItemIndex )
void TrashWorldItems()
{
UINT32 i;
if( gWorldItems )
if( !gWorldItems.empty() )//dnl ch75 271013
{
for( i = 0; i < guiNumWorldItems; i++ )
{
@@ -547,9 +535,9 @@ void TrashWorldItems()
RemoveItemFromPool( gWorldItems[ i ].sGridNo, i, gWorldItems[ i ].ubLevel );
}
}
delete[] gWorldItems;
gWorldItems = NULL;
guiNumWorldItems = 0;
#ifdef INVFIX_Moa//dnl ch75 311013
gWorldItems.clear();
#endif
}
if ( gWorldBombs )
{
@@ -847,7 +835,7 @@ void DeleteWorldItemsBelongingToQueenIfThere( void )
// Refresh item pools
void RefreshWorldItemsIntoItemPools( WORLDITEM * pItemList, INT32 iNumberOfItems )
void RefreshWorldItemsIntoItemPools( std::vector<WORLDITEM>& pItemList, INT32 iNumberOfItems )//dnl ch75 271013
{
INT32 i;