Finished conversion to malloc/free.
This commit is contained in:
parent
0ba13df0d7
commit
8fc30e61f3
|
@ -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->next = NULL;
|
||||||
collectable->active = 1;
|
collectable->active = 1;
|
||||||
|
|
|
@ -68,15 +68,27 @@ void engine_init()
|
||||||
engine.bulletHead->next = NULL;
|
engine.bulletHead->next = NULL;
|
||||||
engine.bulletTail = engine.bulletHead;
|
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.explosionHead->next = NULL;
|
||||||
engine.explosionTail = engine.explosionHead;
|
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.collectableHead->next = NULL;
|
||||||
engine.collectableTail = engine.collectableHead;
|
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.debrisHead->next = NULL;
|
||||||
engine.debrisTail = engine.debrisHead;
|
engine.debrisTail = engine.debrisHead;
|
||||||
|
|
||||||
|
@ -322,7 +334,7 @@ void engine_resetLists()
|
||||||
{
|
{
|
||||||
ob2 = ob;
|
ob2 = ob;
|
||||||
ob = ob->next;
|
ob = ob->next;
|
||||||
delete ob2;
|
free(ob2);
|
||||||
}
|
}
|
||||||
engine.bulletHead->next = NULL;
|
engine.bulletHead->next = NULL;
|
||||||
engine.bulletTail = engine.bulletHead;
|
engine.bulletTail = engine.bulletHead;
|
||||||
|
@ -332,7 +344,7 @@ void engine_resetLists()
|
||||||
{
|
{
|
||||||
ob2 = ob;
|
ob2 = ob;
|
||||||
ob = ob->next;
|
ob = ob->next;
|
||||||
delete ob2;
|
free(ob2);
|
||||||
}
|
}
|
||||||
engine.explosionHead->next = NULL;
|
engine.explosionHead->next = NULL;
|
||||||
engine.explosionTail = engine.explosionHead;
|
engine.explosionTail = engine.explosionHead;
|
||||||
|
@ -342,7 +354,7 @@ void engine_resetLists()
|
||||||
{
|
{
|
||||||
c2 = c1;
|
c2 = c1;
|
||||||
c1 = c1->next;
|
c1 = c1->next;
|
||||||
delete c2;
|
free(c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.collectableHead->next = NULL;
|
engine.collectableHead->next = NULL;
|
||||||
|
@ -353,7 +365,7 @@ void engine_resetLists()
|
||||||
{
|
{
|
||||||
r2 = r1;
|
r2 = r1;
|
||||||
r1 = r1->next;
|
r1 = r1->next;
|
||||||
delete r2;
|
free(r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_bufferHead->next = NULL;
|
screen_bufferHead->next = NULL;
|
||||||
|
@ -364,7 +376,7 @@ void engine_resetLists()
|
||||||
{
|
{
|
||||||
ob2 = ob;
|
ob2 = ob;
|
||||||
ob = ob->next;
|
ob = ob->next;
|
||||||
delete ob2;
|
free(ob2);
|
||||||
}
|
}
|
||||||
engine.debrisHead->next = NULL;
|
engine.debrisHead->next = NULL;
|
||||||
engine.debrisTail = engine.debrisHead;
|
engine.debrisTail = engine.debrisHead;
|
||||||
|
@ -382,9 +394,9 @@ void engine_cleanup()
|
||||||
audio_free();
|
audio_free();
|
||||||
engine_resetLists();
|
engine_resetLists();
|
||||||
free(engine.bulletHead);
|
free(engine.bulletHead);
|
||||||
delete(engine.explosionHead);
|
free(engine.explosionHead);
|
||||||
delete(engine.collectableHead);
|
free(engine.collectableHead);
|
||||||
delete(screen_bufferHead);
|
free(screen_bufferHead);
|
||||||
|
|
||||||
for (int i = 0 ; i < FONT_MAX ; i++)
|
for (int i = 0 ; i < FONT_MAX ; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,12 @@ to change frames on a 21, 14, 7 basis.
|
||||||
*/
|
*/
|
||||||
void explosion_add(float x, float y, int type)
|
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->next = NULL;
|
||||||
explosion->active = 1;
|
explosion->active = 1;
|
||||||
|
|
10
src/game.cpp
10
src/game.cpp
|
@ -233,7 +233,7 @@ static void game_addDebris(int x, int y, int amount)
|
||||||
|
|
||||||
for (int i = 0 ; i < amount ; i++)
|
for (int i = 0 ; i < amount ; i++)
|
||||||
{
|
{
|
||||||
debris = new Object;
|
debris = (Object*)malloc(sizeof(Object));
|
||||||
|
|
||||||
debris->next = NULL;
|
debris->next = NULL;
|
||||||
debris->x = x;
|
debris->x = x;
|
||||||
|
@ -589,7 +589,7 @@ static void game_doCollectables()
|
||||||
(collectable->y <= screen->h))
|
(collectable->y <= screen->h))
|
||||||
collectable_explode(collectable);
|
collectable_explode(collectable);
|
||||||
prevCollectable->next = collectable->next;
|
prevCollectable->next = collectable->next;
|
||||||
delete collectable;
|
free(collectable);
|
||||||
collectable = prevCollectable;
|
collectable = prevCollectable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -897,7 +897,7 @@ static void game_doBullets()
|
||||||
{
|
{
|
||||||
collectable_explode(collectable);
|
collectable_explode(collectable);
|
||||||
prevCollectable->next = collectable->next;
|
prevCollectable->next = collectable->next;
|
||||||
delete collectable;
|
free(collectable);
|
||||||
collectable = prevCollectable;
|
collectable = prevCollectable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1638,7 +1638,7 @@ static void game_doDebris()
|
||||||
if (debris->thinktime < 1)
|
if (debris->thinktime < 1)
|
||||||
{
|
{
|
||||||
prevDebris->next = debris->next;
|
prevDebris->next = debris->next;
|
||||||
delete debris;
|
free(debris);
|
||||||
debris = prevDebris;
|
debris = prevDebris;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1697,7 +1697,7 @@ void game_doExplosions()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prevExplosion->next = explosion->next;
|
prevExplosion->next = explosion->next;
|
||||||
delete explosion;
|
free(explosion);
|
||||||
explosion = prevExplosion;
|
explosion = prevExplosion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,11 @@ SDL_Surface *gfx_messageBox;
|
||||||
|
|
||||||
void gfx_init()
|
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_bufferHead->next = NULL;
|
||||||
screen_bufferTail = screen_bufferHead;
|
screen_bufferTail = screen_bufferHead;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void screen_drawBackground()
|
||||||
|
|
||||||
void screen_addBuffer(int x, int y, int w, int h)
|
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->next = NULL;
|
||||||
rect->x = x;
|
rect->x = x;
|
||||||
|
@ -79,7 +79,7 @@ void screen_flushBuffer()
|
||||||
rect = rect->next;
|
rect = rect->next;
|
||||||
|
|
||||||
prevRect->next = rect->next;
|
prevRect->next = rect->next;
|
||||||
delete rect;
|
free(rect);
|
||||||
rect = prevRect;
|
rect = prevRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ void screen_unBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
prevRect->next = rect->next;
|
prevRect->next = rect->next;
|
||||||
delete rect;
|
free(rect);
|
||||||
rect = prevRect;
|
rect = prevRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue