[Change] Some code cleanup.
This commit is contained in:
parent
5a84266a4f
commit
08a3fe6c9c
2
src/ai.c
2
src/ai.c
@ -662,7 +662,7 @@ static int ai_pushtask(lua_State* L) {
|
|||||||
if(lua_isstring(L, 2)) func = (char*)lua_tostring(L, 2);
|
if(lua_isstring(L, 2)) func = (char*)lua_tostring(L, 2);
|
||||||
else LLUA_INVALID_PARAMETER();
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
|
||||||
t = MALLOC_L(Task);
|
t = malloc(sizeof(Task));
|
||||||
t->next = NULL;
|
t->next = NULL;
|
||||||
t->name = strdup(func);
|
t->name = strdup(func);
|
||||||
t->dtype = TYPE_NULL;
|
t->dtype = TYPE_NULL;
|
||||||
|
@ -179,7 +179,7 @@ void input_init(void) {
|
|||||||
|
|
||||||
/* Create a null keybinding for each. */
|
/* Create a null keybinding for each. */
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++) {
|
for(i = 0; strcmp(keybindNames[i], "end"); i++) {
|
||||||
tmp = MALLOC_L(Keybind);
|
tmp = malloc(sizeof(Keybind));
|
||||||
tmp->name = (char*)keybindNames[i];
|
tmp->name = (char*)keybindNames[i];
|
||||||
tmp->type = KEYBIND_NULL;
|
tmp->type = KEYBIND_NULL;
|
||||||
tmp->key = SDLK_UNKNOWN;
|
tmp->key = SDLK_UNKNOWN;
|
||||||
|
@ -8,9 +8,6 @@
|
|||||||
|
|
||||||
#define APPNAME "Lephisto" /**< Application name. */
|
#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 ABS(x) (((x)<0)?-(x):(x)) /**< Return absulute value. */
|
||||||
#define FABS(x) (((x)<0.)?-(x):(x)) /**< Return float absolute value. */
|
#define FABS(x) (((x)<0.)?-(x):(x)) /**< Return float absolute value. */
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ glTexture* gl_loadImage(SDL_Surface* surface) {
|
|||||||
int rw, rh;
|
int rw, rh;
|
||||||
|
|
||||||
/* Set up the texture defaults. */
|
/* Set up the texture defaults. */
|
||||||
glTexture* texture = MALLOC_L(glTexture);
|
glTexture* texture = malloc(sizeof(glTexture));
|
||||||
texture->w = (double)surface->w;
|
texture->w = (double)surface->w;
|
||||||
texture->h = (double)surface->h;
|
texture->h = (double)surface->h;
|
||||||
texture->sx = 1.;
|
texture->sx = 1.;
|
||||||
|
@ -270,7 +270,7 @@ void solid_init(Solid* dest, const double mass, const double dir,
|
|||||||
/* Create a new solid. */
|
/* Create a new solid. */
|
||||||
Solid* solid_create(const double mass, const double dir,
|
Solid* solid_create(const double mass, const double dir,
|
||||||
const Vec2* pos, const Vec2* vel) {
|
const Vec2* pos, const Vec2* vel) {
|
||||||
Solid* dyn = MALLOC_L(Solid);
|
Solid* dyn = malloc(sizeof(Solid));
|
||||||
if(dyn == NULL) ERR("Out of memory");
|
if(dyn == NULL) ERR("Out of memory");
|
||||||
solid_init(dyn, mass, dir, pos, vel);
|
solid_init(dyn, mass, dir, pos, vel);
|
||||||
return dyn;
|
return dyn;
|
||||||
|
@ -1602,7 +1602,7 @@ unsigned int pilot_create(Ship* ship, char* name, int faction,
|
|||||||
|
|
||||||
Pilot* dyn;
|
Pilot* dyn;
|
||||||
|
|
||||||
dyn = MALLOC_L(Pilot);
|
dyn = malloc(sizeof(Pilot));
|
||||||
if(dyn == NULL) {
|
if(dyn == NULL) {
|
||||||
WARN("Unable to allocate memory.");
|
WARN("Unable to allocate memory.");
|
||||||
return 0;
|
return 0;
|
||||||
@ -1635,7 +1635,7 @@ Pilot* pilot_createEmpty(Ship* ship, char* name,
|
|||||||
int faction, char* ai, const unsigned int flags) {
|
int faction, char* ai, const unsigned int flags) {
|
||||||
|
|
||||||
Pilot* dyn;
|
Pilot* dyn;
|
||||||
dyn = MALLOC_L(Pilot);
|
dyn = malloc(sizeof(Pilot));
|
||||||
pilot_init(dyn, ship, name, faction, ai, 0., NULL, NULL, flags | PILOT_EMPTY);
|
pilot_init(dyn, ship, name, faction, ai, 0., NULL, NULL, flags | PILOT_EMPTY);
|
||||||
return dyn;
|
return dyn;
|
||||||
}
|
}
|
||||||
@ -1714,6 +1714,10 @@ void pilot_free(Pilot* p) {
|
|||||||
solid_free(p->solid);
|
solid_free(p->solid);
|
||||||
if(p->mounted != NULL) free(p->mounted);
|
if(p->mounted != NULL) free(p->mounted);
|
||||||
if(p->escorts) free(p->escorts);
|
if(p->escorts) free(p->escorts);
|
||||||
|
|
||||||
|
#ifdef DEBUGGING
|
||||||
|
memset(p, 0, sizeof(Pilot));
|
||||||
|
#endif
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2549,11 +2549,10 @@ int player_save(xmlTextWriterPtr writer) {
|
|||||||
|
|
||||||
/* Mission the player has done. */
|
/* Mission the player has done. */
|
||||||
xmlw_startElem(writer, "missions_done");
|
xmlw_startElem(writer, "missions_done");
|
||||||
|
|
||||||
for(i = 0; i < missions_ndone; i++) {
|
for(i = 0; i < missions_ndone; i++) {
|
||||||
m = mission_get(missions_done[i]);
|
m = mission_get(missions_done[i]);
|
||||||
if(m != NULL) /* In case mission name changes between versions. */
|
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. */
|
xmlw_endElem(writer); /* missions_done. */
|
||||||
|
@ -375,7 +375,7 @@ static int ship_parse(Ship* tmp, xmlNodePtr parent) {
|
|||||||
cur = node->children;
|
cur = node->children;
|
||||||
do {
|
do {
|
||||||
if(xml_isNode(cur, "outfit")) {
|
if(xml_isNode(cur, "outfit")) {
|
||||||
otmp = MALLOC_L(ShipOutfit);
|
otmp = malloc(sizeof(ShipOutfit));
|
||||||
otmp->data = outfit_get(xml_get(cur));
|
otmp->data = outfit_get(xml_get(cur));
|
||||||
stmp = xml_nodeProp(cur, "quantity");
|
stmp = xml_nodeProp(cur, "quantity");
|
||||||
if(!stmp)
|
if(!stmp)
|
||||||
|
@ -729,7 +729,8 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
|
|||||||
Weapon* w;
|
Weapon* w;
|
||||||
|
|
||||||
/* Create basic features. */
|
/* 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->faction = pilot_get(parent)->faction; /*Non-Changeable. */
|
||||||
w->parent = parent; /* Non-Changeable. */
|
w->parent = parent; /* Non-Changeable. */
|
||||||
w->target = target; /* 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) {
|
static void weapon_free(Weapon* w) {
|
||||||
solid_free(w->solid);
|
solid_free(w->solid);
|
||||||
|
|
||||||
|
#ifdef DEBUGGING
|
||||||
|
memset(w, 0, sizeof(Weapon));
|
||||||
|
#endif
|
||||||
|
|
||||||
free(w);
|
free(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user