[Add] Parametize chunks to realloc. Grow pilot and weapon stack.

This commit is contained in:
Allanis 2013-05-22 23:57:04 +01:00
parent f271a2cbb8
commit 878172d32a
4 changed files with 8 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -17,6 +17,8 @@
#define FLEET_DATA "../dat/fleet.xml" #define FLEET_DATA "../dat/fleet.xml"
#define PILOT_CHUNK 32 // Chunks to increment pilot_stack by.
// Stack of pilot id's to assure uniqueness. // Stack of pilot id's to assure uniqueness.
static unsigned int pilot_id = PLAYER_ID; static unsigned int pilot_id = PLAYER_ID;
@ -864,7 +866,7 @@ unsigned int pilot_create(Ship* ship, char* name, int faction,
if(pilots >= mpilots) { if(pilots >= mpilots) {
// Need to grow. About 20 at a time. // Need to grow. About 20 at a time.
mpilots += 20; mpilots += PILOT_CHUNK;
tp = pilot_stack; tp = pilot_stack;
pilot_stack = realloc(pilot_stack, mpilots*sizeof(Pilot*)); pilot_stack = realloc(pilot_stack, mpilots*sizeof(Pilot*));
if((pilot_stack != tp) && player) if((pilot_stack != tp) && player)

View File

@ -18,9 +18,7 @@
#define VOICE_PRIORITY_BOLT 10 // Default. #define VOICE_PRIORITY_BOLT 10 // Default.
#define VOICE_PRIORITY_AMMO 8 // Higher. #define VOICE_PRIORITY_AMMO 8 // Higher.
// PID values. #define WEAPON_CHUNK 32
#define IMIN -50000
#define IMAX 50000
// Some stuff from pilot. // Some stuff from pilot.
extern Pilot** pilot_stack; extern Pilot** pilot_stack;
@ -441,10 +439,12 @@ void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos,
else { // Need to allocate more memory. else { // Need to allocate more memory.
switch(layer) { switch(layer) {
case WEAPON_LAYER_BG: case WEAPON_LAYER_BG:
curLayer = wbackLayer = realloc(curLayer, (++(*mLayer))*sizeof(Weapon*)); (*mLayer) += WEAPON_CHUNK;
curLayer = wbackLayer = realloc(curLayer, (*mLayer)*sizeof(Weapon*));
break; break;
case WEAPON_LAYER_FG: case WEAPON_LAYER_FG:
curLayer = wfrontLayer = realloc(curLayer, (++(*mLayer))*sizeof(Weapon*)); (*mLayer) += WEAPON_CHUNK;
curLayer = wfrontLayer = realloc(curLayer, (*mLayer)*sizeof(Weapon*));
break; break;
} }
curLayer[(*nLayer)++] = w; curLayer[(*nLayer)++] = w;