[Change] Some code cleanup.

This commit is contained in:
Allanis 2014-05-22 20:43:46 +01:00
parent 5a84266a4f
commit 08a3fe6c9c
9 changed files with 19 additions and 13 deletions

View File

@ -662,7 +662,7 @@ static int ai_pushtask(lua_State* L) {
if(lua_isstring(L, 2)) func = (char*)lua_tostring(L, 2);
else LLUA_INVALID_PARAMETER();
t = MALLOC_L(Task);
t = malloc(sizeof(Task));
t->next = NULL;
t->name = strdup(func);
t->dtype = TYPE_NULL;

View File

@ -179,7 +179,7 @@ void input_init(void) {
/* Create a null keybinding for each. */
for(i = 0; strcmp(keybindNames[i], "end"); i++) {
tmp = MALLOC_L(Keybind);
tmp = malloc(sizeof(Keybind));
tmp->name = (char*)keybindNames[i];
tmp->type = KEYBIND_NULL;
tmp->key = SDLK_UNKNOWN;

View File

@ -8,9 +8,6 @@
#define APPNAME "Lephisto" /**< Application name. */
#define MALLOC_L(type)(malloc(sizeof(type))) /**< Deprecated. */
#define CALLOC_L(type)(calloc(1, sizeof(type))) /**< Deprecated. */
#define ABS(x) (((x)<0)?-(x):(x)) /**< Return absulute value. */
#define FABS(x) (((x)<0.)?-(x):(x)) /**< Return float absolute value. */

View File

@ -405,7 +405,7 @@ glTexture* gl_loadImage(SDL_Surface* surface) {
int rw, rh;
/* Set up the texture defaults. */
glTexture* texture = MALLOC_L(glTexture);
glTexture* texture = malloc(sizeof(glTexture));
texture->w = (double)surface->w;
texture->h = (double)surface->h;
texture->sx = 1.;

View File

@ -270,7 +270,7 @@ void solid_init(Solid* dest, const double mass, const double dir,
/* Create a new solid. */
Solid* solid_create(const double mass, const double dir,
const Vec2* pos, const Vec2* vel) {
Solid* dyn = MALLOC_L(Solid);
Solid* dyn = malloc(sizeof(Solid));
if(dyn == NULL) ERR("Out of memory");
solid_init(dyn, mass, dir, pos, vel);
return dyn;

View File

@ -1602,7 +1602,7 @@ unsigned int pilot_create(Ship* ship, char* name, int faction,
Pilot* dyn;
dyn = MALLOC_L(Pilot);
dyn = malloc(sizeof(Pilot));
if(dyn == NULL) {
WARN("Unable to allocate memory.");
return 0;
@ -1635,7 +1635,7 @@ Pilot* pilot_createEmpty(Ship* ship, char* name,
int faction, char* ai, const unsigned int flags) {
Pilot* dyn;
dyn = MALLOC_L(Pilot);
dyn = malloc(sizeof(Pilot));
pilot_init(dyn, ship, name, faction, ai, 0., NULL, NULL, flags | PILOT_EMPTY);
return dyn;
}
@ -1714,6 +1714,10 @@ void pilot_free(Pilot* p) {
solid_free(p->solid);
if(p->mounted != NULL) free(p->mounted);
if(p->escorts) free(p->escorts);
#ifdef DEBUGGING
memset(p, 0, sizeof(Pilot));
#endif
free(p);
}

View File

@ -2549,11 +2549,10 @@ int player_save(xmlTextWriterPtr writer) {
/* Mission the player has done. */
xmlw_startElem(writer, "missions_done");
for(i = 0; i < missions_ndone; i++) {
m = mission_get(missions_done[i]);
if(m != NULL) /* In case mission name changes between versions. */
xmlw_elem(writer, "done", mission_get(missions_done[i])->name);
xmlw_elem(writer, "done", m->name);
}
xmlw_endElem(writer); /* missions_done. */

View File

@ -375,7 +375,7 @@ static int ship_parse(Ship* tmp, xmlNodePtr parent) {
cur = node->children;
do {
if(xml_isNode(cur, "outfit")) {
otmp = MALLOC_L(ShipOutfit);
otmp = malloc(sizeof(ShipOutfit));
otmp->data = outfit_get(xml_get(cur));
stmp = xml_nodeProp(cur, "quantity");
if(!stmp)

View File

@ -729,7 +729,8 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
Weapon* w;
/* Create basic features. */
w = CALLOC_L(Weapon);
w = malloc(sizeof(Weapon));
memset(w, 0, sizeof(Weapon));
w->faction = pilot_get(parent)->faction; /*Non-Changeable. */
w->parent = parent; /* Non-Changeable. */
w->target = target; /* Non-Changeable. */
@ -1119,6 +1120,11 @@ static void weapon_destroy(Weapon* w, WeaponLayer layer) {
*/
static void weapon_free(Weapon* w) {
solid_free(w->solid);
#ifdef DEBUGGING
memset(w, 0, sizeof(Weapon));
#endif
free(w);
}