Array resize bug fixes.
This commit is contained in:
parent
e3dd4d62af
commit
239845a279
|
@ -78,6 +78,9 @@ extern void doDebris(void);
|
||||||
extern void drawDebris(void);
|
extern void drawDebris(void);
|
||||||
extern void doLocations(void);
|
extern void doLocations(void);
|
||||||
extern void drawLocations(void);
|
extern void drawLocations(void);
|
||||||
|
extern void destroyDebris(void);
|
||||||
|
extern void destroyBullets(void);
|
||||||
|
extern void destroyEffects(void);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
|
@ -78,7 +78,7 @@ void doBullets(void)
|
||||||
|
|
||||||
incomingMissile = 0;
|
incomingMissile = 0;
|
||||||
|
|
||||||
memset(bulletsToDraw, 0, sizeof(Bullet*) * MAX_BULLETS_TO_DRAW);
|
memset(bulletsToDraw, 0, sizeof(Bullet*) * drawCapacity);
|
||||||
|
|
||||||
for (b = battle.bulletHead.next ; b != NULL ; b = b->next)
|
for (b = battle.bulletHead.next ; b != NULL ; b = b->next)
|
||||||
{
|
{
|
||||||
|
@ -143,7 +143,7 @@ static void resizeDrawList(void)
|
||||||
|
|
||||||
n = drawCapacity + INITIAL_BULLET_DRAW_CAPACITY;
|
n = drawCapacity + INITIAL_BULLET_DRAW_CAPACITY;
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Resizing bullet draw capacity: %d -> %d\n", drawCapacity, n);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing bullet draw capacity: %d -> %d\n", drawCapacity, n);
|
||||||
|
|
||||||
bullets = malloc(sizeof(Bullet*) * n);
|
bullets = malloc(sizeof(Bullet*) * n);
|
||||||
memset(bullets, 0, sizeof(Bullet*) * n);
|
memset(bullets, 0, sizeof(Bullet*) * n);
|
||||||
|
@ -407,6 +407,10 @@ void fireMissile(Entity *owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyBulletDefs(void)
|
void destroyBulletDefs(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyBullets(void)
|
||||||
{
|
{
|
||||||
free(bulletsToDraw);
|
free(bulletsToDraw);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ void initDebris(void)
|
||||||
debrisTexture[4] = getTexture("gfx/debris/debris5.png");
|
debrisTexture[4] = getTexture("gfx/debris/debris5.png");
|
||||||
debrisTexture[5] = getTexture("gfx/debris/debris6.png");
|
debrisTexture[5] = getTexture("gfx/debris/debris6.png");
|
||||||
|
|
||||||
drawCapacity = INITIAL_BULLET_DRAW_CAPACITY;
|
drawCapacity = INITIAL_DEBRIS_DRAW_CAPACITY;
|
||||||
|
|
||||||
debrisToDraw = malloc(sizeof(Bullet*) * drawCapacity);
|
debrisToDraw = malloc(sizeof(Bullet*) * drawCapacity);
|
||||||
memset(debrisToDraw, 0, sizeof(Bullet*) * drawCapacity);
|
memset(debrisToDraw, 0, sizeof(Bullet*) * drawCapacity);
|
||||||
|
@ -71,7 +71,7 @@ void doDebris(void)
|
||||||
int i;
|
int i;
|
||||||
Debris *d, *prev;
|
Debris *d, *prev;
|
||||||
|
|
||||||
memset(debrisToDraw, 0, sizeof(Debris*) * MAX_DEBRIS_TO_DRAW);
|
memset(debrisToDraw, 0, sizeof(Debris*) * drawCapacity);
|
||||||
|
|
||||||
prev = &battle.debrisHead;
|
prev = &battle.debrisHead;
|
||||||
|
|
||||||
|
@ -124,9 +124,9 @@ static void resizeDrawList(void)
|
||||||
int i, n;
|
int i, n;
|
||||||
Debris **debris;
|
Debris **debris;
|
||||||
|
|
||||||
n = drawCapacity + INITIAL_BULLET_DRAW_CAPACITY;
|
n = drawCapacity + INITIAL_DEBRIS_DRAW_CAPACITY;
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Resizing debris draw capacity: %d -> %d\n", drawCapacity, n);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing debris draw capacity: %d -> %d\n", drawCapacity, n);
|
||||||
|
|
||||||
debris = malloc(sizeof(Debris*) * n);
|
debris = malloc(sizeof(Debris*) * n);
|
||||||
memset(debris, 0, sizeof(Debris*) * n);
|
memset(debris, 0, sizeof(Debris*) * n);
|
||||||
|
|
|
@ -22,11 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
static void setRandomFlameHue(Effect *e);
|
static void setRandomFlameHue(Effect *e);
|
||||||
static void setRandomShieldHue(Effect *e);
|
static void setRandomShieldHue(Effect *e);
|
||||||
|
static void resizeDrawList(void);
|
||||||
|
|
||||||
static SDL_Texture *explosionTexture;
|
static SDL_Texture *explosionTexture;
|
||||||
static SDL_Texture *shieldHitTexture;
|
static SDL_Texture *shieldHitTexture;
|
||||||
static SDL_Texture *haloTexture;
|
static SDL_Texture *haloTexture;
|
||||||
static Effect **effectsToDraw;
|
static Effect **effectsToDraw;
|
||||||
|
static int drawCapacity;
|
||||||
|
|
||||||
void initEffects(void)
|
void initEffects(void)
|
||||||
{
|
{
|
||||||
|
@ -34,16 +36,22 @@ void initEffects(void)
|
||||||
shieldHitTexture = getTexture("gfx/effects/shieldHit.png");
|
shieldHitTexture = getTexture("gfx/effects/shieldHit.png");
|
||||||
haloTexture = getTexture("gfx/effects/halo.png");
|
haloTexture = getTexture("gfx/effects/halo.png");
|
||||||
|
|
||||||
drawCapacity = INITIAL_EFFECTS_TO_DRAW;
|
drawCapacity = INITIAL_EFFECT_DRAW_CAPACITY;
|
||||||
|
|
||||||
effectsToDraw = malloc(sizeof(Effect*) * drawCapacity);
|
effectsToDraw = malloc(sizeof(Effect*) * drawCapacity);
|
||||||
|
memset(effectsToDraw, 0, sizeof(Effect*) * drawCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doEffects(void)
|
void doEffects(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
Effect *e;
|
Effect *e;
|
||||||
Effect *prev = &battle.effectHead;
|
Effect *prev = &battle.effectHead;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
memset(effectsToDraw, 0, sizeof(Effect*) * drawCapacity);
|
||||||
|
|
||||||
for (e = battle.effectHead.next ; e != NULL ; e = e->next)
|
for (e = battle.effectHead.next ; e != NULL ; e = e->next)
|
||||||
{
|
{
|
||||||
e->x += e->dx;
|
e->x += e->dx;
|
||||||
|
@ -69,7 +77,7 @@ void doEffects(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (e->type == EFFECT_LINE || collision(e->x - (e->size / 2) - battle.camera.x, e->y - (b->size / 2) - battle.camera.y, e->size * 2, e->size * 2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
if (e->type == EFFECT_LINE || collision(e->x - (e->size / 2) - battle.camera.x, e->y - (e->size / 2) - battle.camera.y, e->size * 2, e->size * 2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
{
|
{
|
||||||
effectsToDraw[i++] = e;
|
effectsToDraw[i++] = e;
|
||||||
|
|
||||||
|
@ -91,7 +99,7 @@ static void resizeDrawList(void)
|
||||||
|
|
||||||
n = drawCapacity + INITIAL_EFFECT_DRAW_CAPACITY;
|
n = drawCapacity + INITIAL_EFFECT_DRAW_CAPACITY;
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Resizing effect draw capacity: %d -> %d\n", drawCapacity, n);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing effect draw capacity: %d -> %d\n", drawCapacity, n);
|
||||||
|
|
||||||
effects = malloc(sizeof(Effect*) * n);
|
effects = malloc(sizeof(Effect*) * n);
|
||||||
memset(effects, 0, sizeof(Effect*) * n);
|
memset(effects, 0, sizeof(Effect*) * n);
|
||||||
|
|
|
@ -20,11 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
#define INITIAL_EFFECTS_TO_DRAW 128
|
#define INITIAL_EFFECT_DRAW_CAPACITY 128
|
||||||
|
|
||||||
extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h);
|
extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h);
|
||||||
extern SDL_Texture *getTexture(char *name);
|
extern SDL_Texture *getTexture(char *name);
|
||||||
extern void blit(SDL_Texture *t, int x, int y, int center);
|
extern void blit(SDL_Texture *t, int x, int y, int center);
|
||||||
|
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
|
@ -99,6 +99,9 @@ char **getFileList(char *dir, int *count)
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
char **filenames;
|
char **filenames;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
filenames = NULL;
|
||||||
|
|
||||||
if ((d = opendir(dir)) != NULL)
|
if ((d = opendir(dir)) != NULL)
|
||||||
{
|
{
|
||||||
while ((ent = readdir(d)) != NULL)
|
while ((ent = readdir(d)) != NULL)
|
||||||
|
@ -136,7 +139,10 @@ char **getFileList(char *dir, int *count)
|
||||||
|
|
||||||
*count = i;
|
*count = i;
|
||||||
|
|
||||||
qsort(filenames, i, sizeof(char*), stringComparator);
|
if (filenames)
|
||||||
|
{
|
||||||
|
qsort(filenames, i, sizeof(char*), stringComparator);
|
||||||
|
}
|
||||||
|
|
||||||
return filenames;
|
return filenames;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue