Do some more precalculation of alliances and redefine aiCheckAlliances() as a macro. This achieves

approximately 8% speedup on some large games.


git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9503 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2010-01-25 17:36:46 +00:00 committed by Git SVN Gateway
parent 3a783743a4
commit 7d210588c3
3 changed files with 9 additions and 24 deletions

View File

@ -45,7 +45,7 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
static BOOL updateAttackTarget(BASE_OBJECT * psAttacker, SDWORD weapon_slot); static BOOL updateAttackTarget(BASE_OBJECT * psAttacker, SDWORD weapon_slot);
// alliances // alliances
UBYTE alliances[MAX_PLAYERS][MAX_PLAYERS]; UBYTE alliances[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
// see if a structure has the range to fire on a target // see if a structure has the range to fire on a target
@ -120,32 +120,17 @@ static BOOL aiObjHasRange(BASE_OBJECT *psObj, BASE_OBJECT *psTarget, int weapon_
return false; return false;
} }
/* alliance code for ai. return true if an alliance has formed. */
BOOL aiCheckAlliances(UDWORD s1,UDWORD s2)
{
// features have their player number set to (MAX_PLAYERS + 1)
if (s1 == (MAX_PLAYERS + 1) || s2 == (MAX_PLAYERS + 1))
{
return false;
}
if (s1 == s2 || alliances[s1][s2] == ALLIANCE_FORMED)
{
return true;
}
return false;
}
/* Initialise the AI system */ /* Initialise the AI system */
BOOL aiInitialise(void) BOOL aiInitialise(void)
{ {
SDWORD i,j; SDWORD i,j;
for(i=0; i<MAX_PLAYERS; i++) // The +1 is for features, that are owned by player 9 for hackish reasons
for (i = 0; i < MAX_PLAYERS + 1; i++)
{ {
for(j=0; j<MAX_PLAYERS; j++) for (j = 0; j < MAX_PLAYERS + 1; j++)
{ {
alliances[i][j] = ALLIANCE_BROKEN; alliances[i][j] = (i == j) ? ALLIANCE_FORMED : ALLIANCE_BROKEN;
} }
} }

View File

@ -74,10 +74,10 @@ extern "C"
#define WEIGHT_CMD_SAME_TARGET WEIGHT_DIST_TILE //Don't want this to be too high, since a commander can have many units assigned #define WEIGHT_CMD_SAME_TARGET WEIGHT_DIST_TILE //Don't want this to be too high, since a commander can have many units assigned
// alliances // alliances
extern UBYTE alliances[MAX_PLAYERS][MAX_PLAYERS]; extern UBYTE alliances[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
/* Check no alliance has formed*/ /** Check no alliance has formed. This is a define to make sure we inline it. */
extern BOOL aiCheckAlliances(UDWORD s1,UDWORD s2); #define aiCheckAlliances(_s1, _s2) (alliances[_s1][_s2] == ALLIANCE_FORMED)
/* Initialise the AI system */ /* Initialise the AI system */
extern BOOL aiInitialise(void); extern BOOL aiInitialise(void);

View File

@ -149,7 +149,7 @@ static int visObjHeight(const BASE_OBJECT * psObject)
* once. Note that there is both a limit to how many objects can watch any given * once. Note that there is both a limit to how many objects can watch any given
* tile, and a limit to how many tiles each object can watch. Strange but non fatal * tile, and a limit to how many tiles each object can watch. Strange but non fatal
* things will happen if these limits are exceeded. This function uses icky globals. */ * things will happen if these limits are exceeded. This function uses icky globals. */
static void visMarkTile(int mapX, int mapY, MAPTILE *psTile) static inline void visMarkTile(int mapX, int mapY, MAPTILE *psTile)
{ {
bool alreadySeen = false; bool alreadySeen = false;
int i; int i;