Merge branch 'master' of git.savannah.nongnu.org:/srv/git/starfighter
This commit is contained in:
commit
9014be8678
|
@ -1073,7 +1073,12 @@ int alien_add()
|
|||
int *alienArray;
|
||||
int numberOfAliens = 1;
|
||||
|
||||
alienArray = new int[8];
|
||||
alienArray = (int*)malloc(8 * sizeof(int));
|
||||
if (alienArray == NULL)
|
||||
{
|
||||
engine_warn("WARNING: Failed to allocate memory for aliens");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(game.area)
|
||||
{
|
||||
|
@ -1192,7 +1197,7 @@ int alien_add()
|
|||
randEnemy = CD_TRANSPORTSHIP;
|
||||
}
|
||||
|
||||
delete[] alienArray;
|
||||
free(alienArray);
|
||||
|
||||
aliens[index] = alien_defs[randEnemy];
|
||||
aliens[index].active = 1;
|
||||
|
|
|
@ -34,7 +34,9 @@ void bullet_add(Object *theWeapon, Object *attacker, int y, int dy)
|
|||
int imageIndex;
|
||||
int tempX, tempY, steps;
|
||||
|
||||
bullet = new Object;
|
||||
bullet = (Object*)malloc(sizeof(Object));
|
||||
if (bullet == NULL)
|
||||
return;
|
||||
|
||||
if (attacker == &player)
|
||||
game.shots++;
|
||||
|
|
|
@ -143,7 +143,12 @@ void collectable_add(float x, float y, int type, int value, int life)
|
|||
}
|
||||
}
|
||||
|
||||
Collectable *collectable = new Collectable;
|
||||
Collectable *collectable = (Collectable*)malloc(sizeof(Collectable));
|
||||
if (collectable == NULL)
|
||||
{
|
||||
engine_warn("Failed to allocate memory for collectable");
|
||||
return;
|
||||
}
|
||||
|
||||
collectable->next = NULL;
|
||||
collectable->active = 1;
|
||||
|
|
|
@ -60,19 +60,35 @@ void engine_init()
|
|||
engine.smx = 0;
|
||||
engine.smy = 0;
|
||||
|
||||
engine.bulletHead = new Object;
|
||||
engine.bulletHead = (Object*)malloc(sizeof(Object));
|
||||
if (engine.bulletHead == NULL)
|
||||
{
|
||||
engine_error("Failed to allocate memory for bullet head.");
|
||||
}
|
||||
engine.bulletHead->next = NULL;
|
||||
engine.bulletTail = engine.bulletHead;
|
||||
|
||||
engine.explosionHead = new Object;
|
||||
engine.explosionHead = (Object*)malloc(sizeof(Object));
|
||||
if (engine.explosionHead == NULL)
|
||||
{
|
||||
engine_error("Failed to allocate memory for explosion head.");
|
||||
}
|
||||
engine.explosionHead->next = NULL;
|
||||
engine.explosionTail = engine.explosionHead;
|
||||
|
||||
engine.collectableHead = new Collectable;
|
||||
engine.collectableHead = (Collectable*)malloc(sizeof(Collectable));
|
||||
if (engine.collectableHead == NULL)
|
||||
{
|
||||
engine_error("Failed to allocate memory for collectable head.");
|
||||
}
|
||||
engine.collectableHead->next = NULL;
|
||||
engine.collectableTail = engine.collectableHead;
|
||||
|
||||
engine.debrisHead = new Object;
|
||||
engine.debrisHead = (Object*)malloc(sizeof(Object));
|
||||
if (engine.debrisHead == NULL)
|
||||
{
|
||||
engine_error("Failed to allocate memory for debris head.");
|
||||
}
|
||||
engine.debrisHead->next = NULL;
|
||||
engine.debrisTail = engine.debrisHead;
|
||||
|
||||
|
@ -154,6 +170,24 @@ void engine_showError(int errorId, const char *name)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
Show a warning. Used when non-fatal things go wrong.
|
||||
*/
|
||||
void engine_warn(const char *msg)
|
||||
{
|
||||
printf("WARNING: %s", msg);
|
||||
}
|
||||
|
||||
/*
|
||||
Show an error and exit. Used for critical errors that should definitely
|
||||
never happen.
|
||||
*/
|
||||
void engine_error(const char *msg)
|
||||
{
|
||||
printf("ERROR: %s\nAborting", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
This gets the user's home directory, then creates the config directory.
|
||||
*/
|
||||
|
@ -300,7 +334,7 @@ void engine_resetLists()
|
|||
{
|
||||
ob2 = ob;
|
||||
ob = ob->next;
|
||||
delete ob2;
|
||||
free(ob2);
|
||||
}
|
||||
engine.bulletHead->next = NULL;
|
||||
engine.bulletTail = engine.bulletHead;
|
||||
|
@ -310,7 +344,7 @@ void engine_resetLists()
|
|||
{
|
||||
ob2 = ob;
|
||||
ob = ob->next;
|
||||
delete ob2;
|
||||
free(ob2);
|
||||
}
|
||||
engine.explosionHead->next = NULL;
|
||||
engine.explosionTail = engine.explosionHead;
|
||||
|
@ -320,7 +354,7 @@ void engine_resetLists()
|
|||
{
|
||||
c2 = c1;
|
||||
c1 = c1->next;
|
||||
delete c2;
|
||||
free(c2);
|
||||
}
|
||||
|
||||
engine.collectableHead->next = NULL;
|
||||
|
@ -331,7 +365,7 @@ void engine_resetLists()
|
|||
{
|
||||
r2 = r1;
|
||||
r1 = r1->next;
|
||||
delete r2;
|
||||
free(r2);
|
||||
}
|
||||
|
||||
screen_bufferHead->next = NULL;
|
||||
|
@ -342,7 +376,7 @@ void engine_resetLists()
|
|||
{
|
||||
ob2 = ob;
|
||||
ob = ob->next;
|
||||
delete ob2;
|
||||
free(ob2);
|
||||
}
|
||||
engine.debrisHead->next = NULL;
|
||||
engine.debrisTail = engine.debrisHead;
|
||||
|
@ -359,10 +393,10 @@ void engine_cleanup()
|
|||
SDL_FreeSurface(gfx_background);
|
||||
audio_free();
|
||||
engine_resetLists();
|
||||
delete(engine.bulletHead);
|
||||
delete(engine.explosionHead);
|
||||
delete(engine.collectableHead);
|
||||
delete(screen_bufferHead);
|
||||
free(engine.bulletHead);
|
||||
free(engine.explosionHead);
|
||||
free(engine.collectableHead);
|
||||
free(screen_bufferHead);
|
||||
|
||||
for (int i = 0 ; i < FONT_MAX ; i++)
|
||||
{
|
||||
|
|
|
@ -108,6 +108,8 @@ extern Engine engine;
|
|||
|
||||
void engine_init();
|
||||
void engine_showError(int errorId, const char *name);
|
||||
void engine_warn(const char *msg);
|
||||
void engine_error(const char *msg);
|
||||
void engine_setupConfigDirectory();
|
||||
void engine_setMode();
|
||||
void engine_resetLists();
|
||||
|
|
|
@ -33,7 +33,12 @@ to change frames on a 21, 14, 7 basis.
|
|||
*/
|
||||
void explosion_add(float x, float y, int type)
|
||||
{
|
||||
Object *explosion = new Object;
|
||||
Object *explosion = (Object*)malloc(sizeof(Object));
|
||||
if (explosion == NULL)
|
||||
{
|
||||
engine_warn("Failed to allocate memory for explosion.");
|
||||
return;
|
||||
}
|
||||
|
||||
explosion->next = NULL;
|
||||
explosion->active = 1;
|
||||
|
|
12
src/game.cpp
12
src/game.cpp
|
@ -233,7 +233,7 @@ static void game_addDebris(int x, int y, int amount)
|
|||
|
||||
for (int i = 0 ; i < amount ; i++)
|
||||
{
|
||||
debris = new Object;
|
||||
debris = (Object*)malloc(sizeof(Object));
|
||||
|
||||
debris->next = NULL;
|
||||
debris->x = x;
|
||||
|
@ -589,7 +589,7 @@ static void game_doCollectables()
|
|||
(collectable->y <= screen->h))
|
||||
collectable_explode(collectable);
|
||||
prevCollectable->next = collectable->next;
|
||||
delete collectable;
|
||||
free(collectable);
|
||||
collectable = prevCollectable;
|
||||
}
|
||||
}
|
||||
|
@ -897,7 +897,7 @@ static void game_doBullets()
|
|||
{
|
||||
collectable_explode(collectable);
|
||||
prevCollectable->next = collectable->next;
|
||||
delete collectable;
|
||||
free(collectable);
|
||||
collectable = prevCollectable;
|
||||
}
|
||||
}
|
||||
|
@ -926,7 +926,7 @@ static void game_doBullets()
|
|||
else
|
||||
{
|
||||
prevBullet->next = bullet->next;
|
||||
delete bullet;
|
||||
free(bullet);
|
||||
bullet = prevBullet;
|
||||
}
|
||||
}
|
||||
|
@ -1638,7 +1638,7 @@ static void game_doDebris()
|
|||
if (debris->thinktime < 1)
|
||||
{
|
||||
prevDebris->next = debris->next;
|
||||
delete debris;
|
||||
free(debris);
|
||||
debris = prevDebris;
|
||||
}
|
||||
else
|
||||
|
@ -1697,7 +1697,7 @@ void game_doExplosions()
|
|||
else
|
||||
{
|
||||
prevExplosion->next = explosion->next;
|
||||
delete explosion;
|
||||
free(explosion);
|
||||
explosion = prevExplosion;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,11 @@ SDL_Surface *gfx_messageBox;
|
|||
|
||||
void gfx_init()
|
||||
{
|
||||
screen_bufferHead = new LinkedRect;
|
||||
screen_bufferHead = (LinkedRect*)malloc(sizeof(LinkedRect));
|
||||
if (screen_bufferHead == NULL)
|
||||
{
|
||||
engine_error("Failed to allocate memory for buffer head.");
|
||||
}
|
||||
screen_bufferHead->next = NULL;
|
||||
screen_bufferTail = screen_bufferHead;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ void screen_drawBackground()
|
|||
|
||||
void screen_addBuffer(int x, int y, int w, int h)
|
||||
{
|
||||
LinkedRect *rect = new LinkedRect;
|
||||
LinkedRect *rect = (LinkedRect*)malloc(sizeof(LinkedRect));
|
||||
|
||||
rect->next = NULL;
|
||||
rect->x = x;
|
||||
|
@ -79,7 +79,7 @@ void screen_flushBuffer()
|
|||
rect = rect->next;
|
||||
|
||||
prevRect->next = rect->next;
|
||||
delete rect;
|
||||
free(rect);
|
||||
rect = prevRect;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ void screen_unBuffer()
|
|||
}
|
||||
|
||||
prevRect->next = rect->next;
|
||||
delete rect;
|
||||
free(rect);
|
||||
rect = prevRect;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue