[Change] Cleaned up some variable/function names, also added -Wshadow CFLAG.
This commit is contained in:
parent
5eff5317c6
commit
185039ae62
@ -29,7 +29,7 @@ ifeq ($(OS),LINUX)
|
|||||||
CFLAGS += -D_POSIX_SOURCE
|
CFLAGS += -D_POSIX_SOURCE
|
||||||
endif
|
endif
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
CFLAGS += -W -Wall -Wextra -Wpointer-arith -Wmissing-prototypes -Winline -Wcast-align \
|
CFLAGS += -W -Wall -Wextra -Wshadow -Wpointer-arith -Wmissing-prototypes -Winline -Wcast-align \
|
||||||
-Wmissing-declarations -fno-inline -g3 -DDEBUG -DLUA_USE_APICHECK -std=c99
|
-Wmissing-declarations -fno-inline -g3 -DDEBUG -DLUA_USE_APICHECK -std=c99
|
||||||
else
|
else
|
||||||
CFLAGS += -O2 -funroll-loops -pipe -std=c99
|
CFLAGS += -O2 -funroll-loops -pipe -std=c99
|
||||||
|
19
src/ai.c
19
src/ai.c
@ -68,8 +68,6 @@
|
|||||||
/* AI profiles. */
|
/* AI profiles. */
|
||||||
static AI_Profile* profiles = NULL;
|
static AI_Profile* profiles = NULL;
|
||||||
static int nprofiles = 0;
|
static int nprofiles = 0;
|
||||||
/* Current AI Lua interpreter. */
|
|
||||||
static lua_State* L = NULL;
|
|
||||||
|
|
||||||
/* Extern pilot hacks. */
|
/* Extern pilot hacks. */
|
||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
@ -79,7 +77,7 @@ static int ai_minbrakedist(lua_State* L); /* Minimal breaking distance. */
|
|||||||
static int ai_accel(lua_State* L); /* Accelerate. */
|
static int ai_accel(lua_State* L); /* Accelerate. */
|
||||||
|
|
||||||
/* Internal C routines. */
|
/* Internal C routines. */
|
||||||
static void ai_run(const char* funcname);
|
static void ai_run(lua_State* L, const char* funcname);
|
||||||
static int ai_loadProfile(char* filename);
|
static int ai_loadProfile(char* filename);
|
||||||
static void ai_freetask(Task* t);
|
static void ai_freetask(Task* t);
|
||||||
/* External C routines. */
|
/* External C routines. */
|
||||||
@ -208,7 +206,7 @@ static int pilot_target = 0;
|
|||||||
static int ai_status = AI_STATUS_NORMAL;
|
static int ai_status = AI_STATUS_NORMAL;
|
||||||
|
|
||||||
/* Attempt to run a function. */
|
/* Attempt to run a function. */
|
||||||
static void ai_run(const char* funcname) {
|
static void ai_run(lua_State* L, const char* funcname) {
|
||||||
lua_getglobal(L, funcname);
|
lua_getglobal(L, funcname);
|
||||||
if(lua_pcall(L, 0, 0, 0))
|
if(lua_pcall(L, 0, 0, 0))
|
||||||
/* Errors accured. */
|
/* Errors accured. */
|
||||||
@ -252,6 +250,7 @@ int ai_init(void) {
|
|||||||
static int ai_loadProfile(char* filename) {
|
static int ai_loadProfile(char* filename) {
|
||||||
char* buf = NULL;
|
char* buf = NULL;
|
||||||
uint32_t bufsize = 0;
|
uint32_t bufsize = 0;
|
||||||
|
lua_State* L;
|
||||||
|
|
||||||
profiles = realloc(profiles, sizeof(AI_Profile)*(++nprofiles));
|
profiles = realloc(profiles, sizeof(AI_Profile)*(++nprofiles));
|
||||||
|
|
||||||
@ -321,6 +320,8 @@ void ai_exit(void) {
|
|||||||
|
|
||||||
/* Heart of hearts of the ai!! Brains of the pilot. */
|
/* Heart of hearts of the ai!! Brains of the pilot. */
|
||||||
void ai_think(Pilot* pilot) {
|
void ai_think(Pilot* pilot) {
|
||||||
|
lua_State* L;
|
||||||
|
|
||||||
cur_pilot = pilot; /* Set current pilot being processed. */
|
cur_pilot = pilot; /* Set current pilot being processed. */
|
||||||
L = cur_pilot->ai->L; /* Set the AI profile to the current pilot's. */
|
L = cur_pilot->ai->L; /* Set the AI profile to the current pilot's. */
|
||||||
|
|
||||||
@ -332,13 +333,13 @@ void ai_think(Pilot* pilot) {
|
|||||||
|
|
||||||
/* Control function if pilot is idle or tick is up. */
|
/* Control function if pilot is idle or tick is up. */
|
||||||
if((cur_pilot->tcontrol < SDL_GetTicks()) || (cur_pilot->task == NULL)) {
|
if((cur_pilot->tcontrol < SDL_GetTicks()) || (cur_pilot->task == NULL)) {
|
||||||
ai_run("control"); /* Run control. */
|
ai_run(L, "control"); /* Run control. */
|
||||||
lua_getglobal(L, "control_rate");
|
lua_getglobal(L, "control_rate");
|
||||||
cur_pilot->tcontrol = SDL_GetTicks() + 1000*(int)lua_tonumber(L, -1);
|
cur_pilot->tcontrol = SDL_GetTicks() + 1000*(int)lua_tonumber(L, -1);
|
||||||
}
|
}
|
||||||
if(cur_pilot->task)
|
if(cur_pilot->task)
|
||||||
/* Pilot has a currently running task. */
|
/* Pilot has a currently running task. */
|
||||||
ai_run(cur_pilot->task->name);
|
ai_run(L, cur_pilot->task->name);
|
||||||
|
|
||||||
/* Make sure pilot_acc and pilot_turn are legal moves. */
|
/* Make sure pilot_acc and pilot_turn are legal moves. */
|
||||||
if(pilot_acc > 1.) pilot_acc = 1.; /* Value must be <= 1. */
|
if(pilot_acc > 1.) pilot_acc = 1.; /* Value must be <= 1. */
|
||||||
@ -358,6 +359,8 @@ void ai_think(Pilot* pilot) {
|
|||||||
|
|
||||||
/* Pilot is attacked. */
|
/* Pilot is attacked. */
|
||||||
void ai_attacked(Pilot* attacked, const unsigned int attacker) {
|
void ai_attacked(Pilot* attacked, const unsigned int attacker) {
|
||||||
|
lua_State* L;
|
||||||
|
|
||||||
cur_pilot = attacked;
|
cur_pilot = attacked;
|
||||||
L = cur_pilot->ai->L;
|
L = cur_pilot->ai->L;
|
||||||
lua_getglobal(L, "attacked");
|
lua_getglobal(L, "attacked");
|
||||||
@ -367,10 +370,12 @@ void ai_attacked(Pilot* attacked, const unsigned int attacker) {
|
|||||||
|
|
||||||
/* Pilot was just created. */
|
/* Pilot was just created. */
|
||||||
void ai_create(Pilot* pilot) {
|
void ai_create(Pilot* pilot) {
|
||||||
|
lua_State* L;
|
||||||
|
|
||||||
cur_pilot = pilot;
|
cur_pilot = pilot;
|
||||||
L = cur_pilot->ai->L;
|
L = cur_pilot->ai->L;
|
||||||
ai_status = AI_STATUS_CREATE;
|
ai_status = AI_STATUS_CREATE;
|
||||||
ai_run("create");
|
ai_run(L, "create");
|
||||||
ai_status = AI_STATUS_NORMAL;
|
ai_status = AI_STATUS_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,12 +138,12 @@ int input_getKeybind(char* keybind, KeybindType* type, int* reverse) {
|
|||||||
(player && !pilot_isFlag(player, PILOT_HYP_PREP) && \
|
(player && !pilot_isFlag(player, PILOT_HYP_PREP) && \
|
||||||
!pilot_isFlag(player, PILOT_HYP_BEGIN) && \
|
!pilot_isFlag(player, PILOT_HYP_BEGIN) && \
|
||||||
!pilot_isFlag(player, PILOT_HYPERSPACE))
|
!pilot_isFlag(player, PILOT_HYPERSPACE))
|
||||||
static void input_key(int keynum, double value, int abs) {
|
static void input_key(int keynum, double value, int kabs) {
|
||||||
unsigned int t;
|
unsigned int t;
|
||||||
|
|
||||||
/* Accelerating. */
|
/* Accelerating. */
|
||||||
if(KEY("accel")) {
|
if(KEY("accel")) {
|
||||||
if(abs)player_accel(value);
|
if(kabs)player_accel(value);
|
||||||
else {
|
else {
|
||||||
/* Prevent it from getting stuck. */
|
/* Prevent it from getting stuck. */
|
||||||
if(value == KEY_PRESS) player_accel(1.);
|
if(value == KEY_PRESS) player_accel(1.);
|
||||||
@ -166,7 +166,7 @@ static void input_key(int keynum, double value, int abs) {
|
|||||||
if(value == KEY_PRESS) { player_setFlag(PLAYER_TURN_LEFT); }
|
if(value == KEY_PRESS) { player_setFlag(PLAYER_TURN_LEFT); }
|
||||||
else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_LEFT); }
|
else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_LEFT); }
|
||||||
|
|
||||||
if(abs) { player_turn = -value; }
|
if(kabs) { player_turn = -value; }
|
||||||
else { player_turn -= value; }
|
else { player_turn -= value; }
|
||||||
if(player_turn < -1.) { player_turn = -1.; }/* Make sure value is sane. */
|
if(player_turn < -1.) { player_turn = -1.; }/* Make sure value is sane. */
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ static void input_key(int keynum, double value, int abs) {
|
|||||||
if(value == KEY_PRESS) { player_setFlag(PLAYER_TURN_RIGHT); }
|
if(value == KEY_PRESS) { player_setFlag(PLAYER_TURN_RIGHT); }
|
||||||
else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_RIGHT); }
|
else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_RIGHT); }
|
||||||
|
|
||||||
if(abs) { player_turn = value; }
|
if(kabs) { player_turn = value; }
|
||||||
else { player_turn += value; }
|
else { player_turn += value; }
|
||||||
|
|
||||||
if(player_turn < -1.) { player_turn = -1.; } /* Make sure value is sane. */
|
if(player_turn < -1.) { player_turn = -1.; } /* Make sure value is sane. */
|
||||||
|
58
src/land.c
58
src/land.c
@ -75,13 +75,13 @@ static int secondary_wid = 0;
|
|||||||
static int terciary_wid = 0; /* For fancy things like news, your ship etc.. */
|
static int terciary_wid = 0; /* For fancy things like news, your ship etc.. */
|
||||||
|
|
||||||
/* Commodity excahnge. */
|
/* Commodity excahnge. */
|
||||||
static void commodity_exchange(void);
|
static void commodity_exchange_open(void);
|
||||||
static void commodity_exchange_close(char* str);
|
static void commodity_exchange_close(char* str);
|
||||||
static void commodity_update(char* str);
|
static void commodity_update(char* str);
|
||||||
static void commodity_buy(char* str);
|
static void commodity_buy(char* str);
|
||||||
static void commodity_sell(char* str);
|
static void commodity_sell(char* str);
|
||||||
/* Outfits. */
|
/* Outfits. */
|
||||||
static void outfits(void);
|
static void outfits_open(void);
|
||||||
static void outfits_close(char* str);
|
static void outfits_close(char* str);
|
||||||
static void outfits_update(char* str);
|
static void outfits_update(char* str);
|
||||||
static int outfit_canBuy(Outfit* outfit, int q, int errmsg);
|
static int outfit_canBuy(Outfit* outfit, int q, int errmsg);
|
||||||
@ -91,26 +91,26 @@ static void outfits_sell(char* str);
|
|||||||
static int outfits_getMod(void);
|
static int outfits_getMod(void);
|
||||||
static void outfits_renderMod(double bx, double by, double w, double h);
|
static void outfits_renderMod(double bx, double by, double w, double h);
|
||||||
/* Shipyard. */
|
/* Shipyard. */
|
||||||
static void shipyard(void);
|
static void shipyard_open(void);
|
||||||
static void shipyard_close(char* str);
|
static void shipyard_close(char* str);
|
||||||
static void shipyard_update(char* str);
|
static void shipyard_update(char* str);
|
||||||
static void shipyard_info(char* str);
|
static void shipyard_info(char* str);
|
||||||
static void shipyard_buy(char* str);
|
static void shipyard_buy(char* str);
|
||||||
/* Your ship. */
|
/* Your ship. */
|
||||||
static void shipyard_yours(char* str);
|
static void shipyard_yours_open(char* str);
|
||||||
static void shipyard_yoursClose(char* str);
|
static void shipyard_yours_close(char* str);
|
||||||
static void shipyard_yoursUpdate(char* str);
|
static void shipyard_yoursUpdate(char* str);
|
||||||
static void shipyard_yoursChange(char* str);
|
static void shipyard_yoursChange(char* str);
|
||||||
static void shipyard_yoursTransport(char* str);
|
static void shipyard_yoursTransport(char* str);
|
||||||
static int shipyard_yoursTransportPrice(char* shipname);
|
static int shipyard_yoursTransportPrice(char* shipname);
|
||||||
/* Spaceport bar. */
|
/* Spaceport bar. */
|
||||||
static void spaceport_bar(void);
|
static void spaceport_bar_open(void);
|
||||||
static void spaceport_bar_close(char* str);
|
static void spaceport_bar_close(char* str);
|
||||||
/* News. */
|
/* News. */
|
||||||
static void news(void);
|
static void news_open(void);
|
||||||
static void news_close(char* str);
|
static void news_close(char* str);
|
||||||
/* Mission computer. */
|
/* Mission computer. */
|
||||||
static void misn(void);
|
static void misn_open(void);
|
||||||
static void misn_close(char* str);
|
static void misn_close(char* str);
|
||||||
static void misn_accept(char* str);
|
static void misn_accept(char* str);
|
||||||
static void misn_genList(int first);
|
static void misn_genList(int first);
|
||||||
@ -120,7 +120,7 @@ static int refuel_price(void);
|
|||||||
static void spaceport_refuel(char* str);
|
static void spaceport_refuel(char* str);
|
||||||
|
|
||||||
/* The local market. */
|
/* The local market. */
|
||||||
static void commodity_exchange(void) {
|
static void commodity_exchange_open(void) {
|
||||||
int i;
|
int i;
|
||||||
char** goods;
|
char** goods;
|
||||||
secondary_wid = window_create("Commodity Exchange", -1, -1,
|
secondary_wid = window_create("Commodity Exchange", -1, -1,
|
||||||
@ -236,8 +236,8 @@ static void commodity_sell(char* str) {
|
|||||||
commodity_update(NULL);
|
commodity_update(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void outfits(void) {
|
static void outfits_open(void) {
|
||||||
char** outfits;
|
char** soutfits;
|
||||||
int noutfits;
|
int noutfits;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
@ -289,10 +289,10 @@ static void outfits(void) {
|
|||||||
&gl_smallFont, NULL, NULL);
|
&gl_smallFont, NULL, NULL);
|
||||||
|
|
||||||
/* Set up the outfits to buy/sell. */
|
/* Set up the outfits to buy/sell. */
|
||||||
outfits = outfit_getTech(&noutfits, land_planet->tech, PLANET_TECH_MAX);
|
soutfits = outfit_getTech(&noutfits, land_planet->tech, PLANET_TECH_MAX);
|
||||||
window_addList(secondary_wid, 20, 40,
|
window_addList(secondary_wid, 20, 40,
|
||||||
200, OUTFITS_HEIGHT-80, "lstOutfits",
|
200, OUTFITS_HEIGHT-80, "lstOutfits",
|
||||||
outfits, noutfits, 0, outfits_update);
|
soutfits, noutfits, 0, outfits_update);
|
||||||
|
|
||||||
/* Write the outfits stuff. */
|
/* Write the outfits stuff. */
|
||||||
outfits_update(NULL);
|
outfits_update(NULL);
|
||||||
@ -483,7 +483,7 @@ static void outfits_renderMod(double bx, double by, double w, double h) {
|
|||||||
&cBlack, buf);
|
&cBlack, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shipyard(void) {
|
static void shipyard_open(void) {
|
||||||
char** ships;
|
char** ships;
|
||||||
int nships;
|
int nships;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
@ -498,7 +498,7 @@ static void shipyard(void) {
|
|||||||
|
|
||||||
window_addButton(secondary_wid, -20, 40+BUTTON_HEIGHT,
|
window_addButton(secondary_wid, -20, 40+BUTTON_HEIGHT,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnYourShips",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnYourShips",
|
||||||
"Your Ships", shipyard_yours);
|
"Your Ships", shipyard_yours_open);
|
||||||
|
|
||||||
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 20,
|
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyShip",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyShip",
|
||||||
@ -624,7 +624,7 @@ static void shipyard_buy(char* str) {
|
|||||||
shipyard_update(NULL);
|
shipyard_update(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shipyard_yours(char* str) {
|
static void shipyard_yours_open(char* str) {
|
||||||
(void)str;
|
(void)str;
|
||||||
char** ships;
|
char** ships;
|
||||||
int nships;
|
int nships;
|
||||||
@ -634,7 +634,7 @@ static void shipyard_yours(char* str) {
|
|||||||
|
|
||||||
window_addButton(terciary_wid, -20, 20,
|
window_addButton(terciary_wid, -20, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseYourShips",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseYourShips",
|
||||||
"Shipyard", shipyard_yoursClose);
|
"Shipyard", shipyard_yours_close);
|
||||||
|
|
||||||
window_addButton(terciary_wid, -40-BUTTON_WIDTH, 20,
|
window_addButton(terciary_wid, -40-BUTTON_WIDTH, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnChangeShip",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnChangeShip",
|
||||||
@ -682,7 +682,7 @@ static void shipyard_yours(char* str) {
|
|||||||
shipyard_yoursUpdate(NULL);
|
shipyard_yoursUpdate(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shipyard_yoursClose(char* str) {
|
static void shipyard_yours_close(char* str) {
|
||||||
(void)str;
|
(void)str;
|
||||||
window_destroy(terciary_wid);
|
window_destroy(terciary_wid);
|
||||||
terciary_wid = 0;
|
terciary_wid = 0;
|
||||||
@ -781,8 +781,8 @@ static void shipyard_yoursChange(char* str) {
|
|||||||
player_swapShip(shipname);
|
player_swapShip(shipname);
|
||||||
|
|
||||||
/* Recreate the window. */
|
/* Recreate the window. */
|
||||||
shipyard_yoursClose(NULL);
|
shipyard_yours_close(NULL);
|
||||||
shipyard_yours(NULL);
|
shipyard_yours_open(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shipyard_yoursTransport(char* str) {
|
static void shipyard_yoursTransport(char* str) {
|
||||||
@ -834,7 +834,7 @@ static int shipyard_yoursTransportPrice(char* shipname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Spaceport bar. */
|
/* Spaceport bar. */
|
||||||
static void spaceport_bar(void) {
|
static void spaceport_bar_open(void) {
|
||||||
secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);
|
secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);
|
||||||
|
|
||||||
window_addButton(secondary_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
window_addButton(secondary_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
@ -842,7 +842,7 @@ static void spaceport_bar(void) {
|
|||||||
|
|
||||||
window_addButton(secondary_wid, 20, 20,
|
window_addButton(secondary_wid, 20, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
|
||||||
"News", (void(*)(char*))news);
|
"News", (void(*)(char*))news_open);
|
||||||
|
|
||||||
window_addText(secondary_wid, 20, -30,
|
window_addText(secondary_wid, 20, -30,
|
||||||
BAR_WIDTH-40, BAR_HEIGHT - 40 - BUTTON_HEIGHT, 0,
|
BAR_WIDTH-40, BAR_HEIGHT - 40 - BUTTON_HEIGHT, 0,
|
||||||
@ -862,7 +862,7 @@ static void spaceport_bar_close(char* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Planet news reports. */
|
/* Planet news reports. */
|
||||||
static void news(void) {
|
static void news_open(void) {
|
||||||
terciary_wid = window_create("News Reports",
|
terciary_wid = window_create("News Reports",
|
||||||
-1, -1, NEWS_WIDTH, NEWS_HEIGHT);
|
-1, -1, NEWS_WIDTH, NEWS_HEIGHT);
|
||||||
|
|
||||||
@ -883,7 +883,7 @@ static void news_close(char* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mission computer, cos' missions rule! */
|
/* Mission computer, cos' missions rule! */
|
||||||
static void misn(void) {
|
static void misn_open(void) {
|
||||||
secondary_wid = window_create("Mission Computer",
|
secondary_wid = window_create("Mission Computer",
|
||||||
-1, -1, MISSION_WIDTH, MISSION_HEIGHT);
|
-1, -1, MISSION_WIDTH, MISSION_HEIGHT);
|
||||||
|
|
||||||
@ -1035,27 +1035,27 @@ void land(Planet* p) {
|
|||||||
if(planet_hasService(land_planet, PLANET_SERVICE_COMMODITY))
|
if(planet_hasService(land_planet, PLANET_SERVICE_COMMODITY))
|
||||||
window_addButton(land_wid, -20, 20 + BUTTON_HEIGHT + 20,
|
window_addButton(land_wid, -20, 20 + BUTTON_HEIGHT + 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodity",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodity",
|
||||||
"Commodity Exchange", (void(*)(char*))commodity_exchange);
|
"Commodity Exchange", (void(*)(char*))commodity_exchange_open);
|
||||||
|
|
||||||
if(planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD))
|
if(planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD))
|
||||||
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20,
|
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnShipyard",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnShipyard",
|
||||||
"Shipyard", (void(*)(char*))shipyard);
|
"Shipyard", (void(*)(char*))shipyard_open);
|
||||||
|
|
||||||
if(planet_hasService(land_planet, PLANET_SERVICE_OUTFITS))
|
if(planet_hasService(land_planet, PLANET_SERVICE_OUTFITS))
|
||||||
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20 + BUTTON_HEIGHT + 20,
|
window_addButton(land_wid, -20 - BUTTON_WIDTH - 20, 20 + BUTTON_HEIGHT + 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnOutfits",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnOutfits",
|
||||||
"Outfits", (void(*)(char*))outfits);
|
"Outfits", (void(*)(char*))outfits_open);
|
||||||
|
|
||||||
/* Third column. */
|
/* Third column. */
|
||||||
if(planet_hasService(land_planet, PLANET_SERVICE_BASIC)) {
|
if(planet_hasService(land_planet, PLANET_SERVICE_BASIC)) {
|
||||||
window_addButton(land_wid, 20, 20,
|
window_addButton(land_wid, 20, 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
|
||||||
"Mission Terminal", (void(*)(char*))misn);
|
"Mission Terminal", (void(*)(char*))misn_open);
|
||||||
|
|
||||||
window_addButton(land_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
window_addButton(land_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBar",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBar",
|
||||||
"Spaceport Bar", (void(*)(char*))spaceport_bar);
|
"Spaceport Bar", (void(*)(char*))spaceport_bar_open);
|
||||||
|
|
||||||
if(player->fuel < player->fuel_max) {
|
if(player->fuel < player->fuel_max) {
|
||||||
credits2str(cred, refuel_price(), 2);
|
credits2str(cred, refuel_price(), 2);
|
||||||
|
@ -269,7 +269,7 @@ void main_loop(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static double fps_dt = 1.;
|
static double fps_dt = 1.;
|
||||||
static double dt = 0.;
|
static double cur_dt = 0.;
|
||||||
/**
|
/**
|
||||||
* @brief Controls the FPS.
|
* @brief Controls the FPS.
|
||||||
*/
|
*/
|
||||||
@ -278,14 +278,14 @@ static void fps_control(void) {
|
|||||||
|
|
||||||
/* dt in ms/1000. */
|
/* dt in ms/1000. */
|
||||||
t = SDL_GetTicks();
|
t = SDL_GetTicks();
|
||||||
dt = (double)(t-gtime)/1000.;
|
cur_dt = (double)(t-gtime)/1000.;
|
||||||
gtime = t;
|
gtime = t;
|
||||||
|
|
||||||
if(paused) SDL_Delay(10); /* Drop paused FPS to be nice to the CPU. */
|
if(paused) SDL_Delay(10); /* Drop paused FPS to be nice to the CPU. */
|
||||||
|
|
||||||
/* If the fps is limited.. */
|
/* If the fps is limited.. */
|
||||||
if((max_fps != 0) && (dt < 1./max_fps)) {
|
if((max_fps != 0) && (cur_dt < 1./max_fps)) {
|
||||||
double delay = 1./max_fps - dt;
|
double delay = 1./max_fps - cur_dt;
|
||||||
SDL_Delay(delay);
|
SDL_Delay(delay);
|
||||||
fps_dt += delay; /* Make sure it displays the propper FPS. */
|
fps_dt += delay; /* Make sure it displays the propper FPS. */
|
||||||
}
|
}
|
||||||
@ -298,13 +298,13 @@ const double fps_min = 1./50.0;
|
|||||||
static void update_all(void) {
|
static void update_all(void) {
|
||||||
double tmpdt;
|
double tmpdt;
|
||||||
|
|
||||||
if(dt > 0.25) { /* Slow timers down and rerun calculations */
|
if(cur_dt > 0.25) { /* Slow timers down and rerun calculations */
|
||||||
pause_delay((unsigned int)dt*1000.);
|
pause_delay((unsigned int)cur_dt*1000.);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* We'll force a minimum of 50 FPS. */
|
/* We'll force a minimum of 50 FPS. */
|
||||||
else if(dt > fps_min) {
|
else if(cur_dt > fps_min) {
|
||||||
tmpdt = dt - fps_min;
|
tmpdt = cur_dt - fps_min;
|
||||||
pause_delay((unsigned int)(tmpdt*1000));
|
pause_delay((unsigned int)(tmpdt*1000));
|
||||||
update_routine(fps_min);
|
update_routine(fps_min);
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ static void update_all(void) {
|
|||||||
tmpdt -= fps_min;
|
tmpdt -= fps_min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_routine(dt);
|
update_routine(cur_dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -348,9 +348,9 @@ static void update_routine(double dt) {
|
|||||||
*/
|
*/
|
||||||
static void render_all(void) {
|
static void render_all(void) {
|
||||||
/* Setup. */
|
/* Setup. */
|
||||||
spfx_start(dt);
|
spfx_start(cur_dt);
|
||||||
/* BG. */
|
/* BG. */
|
||||||
space_render(dt);
|
space_render(cur_dt);
|
||||||
planets_render();
|
planets_render();
|
||||||
player_renderBG();
|
player_renderBG();
|
||||||
weapons_render(WEAPON_LAYER_BG);
|
weapons_render(WEAPON_LAYER_BG);
|
||||||
@ -361,7 +361,7 @@ static void render_all(void) {
|
|||||||
/* FG. */
|
/* FG. */
|
||||||
player_render();
|
player_render();
|
||||||
spfx_render(SPFX_LAYER_FRONT);
|
spfx_render(SPFX_LAYER_FRONT);
|
||||||
display_fps(dt);
|
display_fps(cur_dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,13 +153,13 @@ static int space_getPlanet(lua_State* L) {
|
|||||||
|
|
||||||
static int space_getSystem(lua_State* L) {
|
static int space_getSystem(lua_State* L) {
|
||||||
LLUA_MIN_ARGS(1);
|
LLUA_MIN_ARGS(1);
|
||||||
char* planetname, *system;
|
char* planetname, *sysname;
|
||||||
|
|
||||||
if(lua_isstring(L, -1)) planetname = (char*) lua_tostring(L, -1);
|
if(lua_isstring(L, -1)) planetname = (char*) lua_tostring(L, -1);
|
||||||
else return 0;
|
else return 0;
|
||||||
|
|
||||||
system = planet_getSystem(planetname);
|
sysname = planet_getSystem(planetname);
|
||||||
lua_pushstring(L, system);
|
lua_pushstring(L, sysname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ static int mission_init(Mission* mission, MissionData* misn, int load);
|
|||||||
static void mission_freeData(MissionData* mission);
|
static void mission_freeData(MissionData* mission);
|
||||||
static int mission_alreadyRunning(MissionData* misn);
|
static int mission_alreadyRunning(MissionData* misn);
|
||||||
static int mission_meetCond(MissionData* misn);
|
static int mission_meetCond(MissionData* misn);
|
||||||
static int mission_meetReq(int mission, int faction, char* planet, char* system);
|
static int mission_meetReq(int mission, int faction, char* planet, char* sysname);
|
||||||
static int mission_matchFaction(MissionData* misn, int faction);
|
static int mission_matchFaction(MissionData* misn, int faction);
|
||||||
static int mission_location(char* loc);
|
static int mission_location(char* loc);
|
||||||
static MissionData* mission_parse(const xmlNodePtr parent);
|
static MissionData* mission_parse(const xmlNodePtr parent);
|
||||||
@ -199,14 +199,14 @@ static int mission_meetCond(MissionData* misn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Does the mission meet the minimum requirements? */
|
/* Does the mission meet the minimum requirements? */
|
||||||
static int mission_meetReq(int mission, int faction, char* planet, char* system) {
|
static int mission_meetReq(int mission, int faction, char* planet, char* sysname) {
|
||||||
MissionData* misn;
|
MissionData* misn;
|
||||||
|
|
||||||
misn = &mission_stack[mission];
|
misn = &mission_stack[mission];
|
||||||
|
|
||||||
/* Must match planet, system or faction. */
|
/* Must match planet, system or faction. */
|
||||||
if(!(((misn->avail.planet && strcmp(misn->avail.planet, planet)==0)) ||
|
if(!(((misn->avail.planet && strcmp(misn->avail.planet, planet)==0)) ||
|
||||||
(misn->avail.system && (strcmp(misn->avail.system, system)==0)) ||
|
(misn->avail.system && (strcmp(misn->avail.system, sysname)==0)) ||
|
||||||
mission_matchFaction(misn, faction)))
|
mission_matchFaction(misn, faction)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ static int mission_meetReq(int mission, int faction, char* planet, char* system)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Runs bar missions, all lua side and one-shot. */
|
/* Runs bar missions, all lua side and one-shot. */
|
||||||
void missions_bar(int faction, char* planet, char* system) {
|
void missions_bar(int faction, char* planet, char* sysname) {
|
||||||
MissionData* misn;
|
MissionData* misn;
|
||||||
Mission mission;
|
Mission mission;
|
||||||
int i;
|
int i;
|
||||||
@ -232,7 +232,7 @@ void missions_bar(int faction, char* planet, char* system) {
|
|||||||
for(i = 0; i < mission_nstack; i++) {
|
for(i = 0; i < mission_nstack; i++) {
|
||||||
misn = &mission_stack[i];
|
misn = &mission_stack[i];
|
||||||
if(misn->avail.loc == MIS_AVAIL_BAR) {
|
if(misn->avail.loc == MIS_AVAIL_BAR) {
|
||||||
if(!mission_meetReq(i, faction, planet, system))
|
if(!mission_meetReq(i, faction, planet, sysname))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
chance = (double)(misn->avail.chance % 100)/100.;
|
chance = (double)(misn->avail.chance % 100)/100.;
|
||||||
@ -350,7 +350,7 @@ static int mission_matchFaction(MissionData* misn, int faction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate missions for the computer - special case. */
|
/* Generate missions for the computer - special case. */
|
||||||
Mission* missions_computer(int* n, int faction, char* planet, char* system) {
|
Mission* missions_computer(int* n, int faction, char* planet, char* sysname) {
|
||||||
int i, j, m;
|
int i, j, m;
|
||||||
double chance;
|
double chance;
|
||||||
int rep;
|
int rep;
|
||||||
@ -362,7 +362,7 @@ Mission* missions_computer(int* n, int faction, char* planet, char* system) {
|
|||||||
for(i = 0; i < mission_nstack; i++) {
|
for(i = 0; i < mission_nstack; i++) {
|
||||||
misn = &mission_stack[i];
|
misn = &mission_stack[i];
|
||||||
if(misn->avail.loc == MIS_AVAIL_COMPUTER) {
|
if(misn->avail.loc == MIS_AVAIL_COMPUTER) {
|
||||||
if(!mission_meetReq(i, faction, planet, system))
|
if(!mission_meetReq(i, faction, planet, sysname))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
chance = (double)(misn->avail.chance % 100)/100.;
|
chance = (double)(misn->avail.chance % 100)/100.;
|
||||||
|
@ -64,10 +64,10 @@ typedef struct Mission_ {
|
|||||||
extern Mission player_missions[MISSION_MAX];
|
extern Mission player_missions[MISSION_MAX];
|
||||||
|
|
||||||
/* For mission computer. */
|
/* For mission computer. */
|
||||||
Mission* missions_computer(int* n, int faction, char* planet, char* system);
|
Mission* missions_computer(int* n, int faction, char* planet, char* sysname);
|
||||||
/* Player accepted mission - mission computer. */
|
/* Player accepted mission - mission computer. */
|
||||||
int mission_accept(Mission* mission);
|
int mission_accept(Mission* mission);
|
||||||
void missions_bar(int faction, char* planet, char* system);
|
void missions_bar(int faction, char* planet, char* sysname);
|
||||||
|
|
||||||
/* Misc. */
|
/* Misc. */
|
||||||
int mission_getID(char* name);
|
int mission_getID(char* name);
|
||||||
|
13
src/music.c
13
src/music.c
@ -102,7 +102,7 @@ int music_thread(void* unused) {
|
|||||||
(void)unused;
|
(void)unused;
|
||||||
|
|
||||||
int active; /* Active buffer. */
|
int active; /* Active buffer. */
|
||||||
ALint stat;
|
ALint state;
|
||||||
|
|
||||||
/* Main loop. */
|
/* Main loop. */
|
||||||
while(!music_is(MUSIC_KILL)) {
|
while(!music_is(MUSIC_KILL)) {
|
||||||
@ -134,8 +134,9 @@ int music_thread(void* unused) {
|
|||||||
while(music_is(MUSIC_PLAYING)) {
|
while(music_is(MUSIC_PLAYING)) {
|
||||||
soundLock();
|
soundLock();
|
||||||
|
|
||||||
alGetSourcei(music_source, AL_BUFFERS_PROCESSED, &stat);
|
alGetSourcei(music_source, AL_BUFFERS_PROCESSED, &state);
|
||||||
if(stat > 0) {
|
|
||||||
|
if(state > 0) {
|
||||||
/* Refill active buffer. */
|
/* Refill active buffer. */
|
||||||
alSourceUnqueueBuffers(music_source, 1, &music_buffer[active]);
|
alSourceUnqueueBuffers(music_source, 1, &music_buffer[active]);
|
||||||
if(stream_loadBuffer(music_buffer[active])) music_rm(MUSIC_PLAYING);
|
if(stream_loadBuffer(music_buffer[active])) music_rm(MUSIC_PLAYING);
|
||||||
@ -163,14 +164,14 @@ int music_thread(void* unused) {
|
|||||||
|
|
||||||
static int stream_loadBuffer(ALuint buffer) {
|
static int stream_loadBuffer(ALuint buffer) {
|
||||||
int size, section, result;
|
int size, section, result;
|
||||||
char data[BUFFER_SIZE]; /* Buffer to hold the data. */
|
char dat[BUFFER_SIZE]; /* Buffer to hold the data. */
|
||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
while(size < BUFFER_SIZE) {
|
while(size < BUFFER_SIZE) {
|
||||||
/* Fill up the entire data buffer. */
|
/* Fill up the entire data buffer. */
|
||||||
result = ov_read(
|
result = ov_read(
|
||||||
&music_vorbis.stream, /* Stream. */
|
&music_vorbis.stream, /* Stream. */
|
||||||
data + size, /* Data. */
|
dat + size, /* Data. */
|
||||||
BUFFER_SIZE - size, /* Amount to read. */
|
BUFFER_SIZE - size, /* Amount to read. */
|
||||||
0, /* Big endian?. */
|
0, /* Big endian?. */
|
||||||
2, /* 16 bit. */
|
2, /* 16 bit. */
|
||||||
@ -191,7 +192,7 @@ static int stream_loadBuffer(ALuint buffer) {
|
|||||||
if(size == BUFFER_SIZE) break; /* Buffer is full. */
|
if(size == BUFFER_SIZE) break; /* Buffer is full. */
|
||||||
}
|
}
|
||||||
/* Load the buffer. */
|
/* Load the buffer. */
|
||||||
alBufferData(buffer, music_vorbis.format, data, BUFFER_SIZE,
|
alBufferData(buffer, music_vorbis.format, dat, BUFFER_SIZE,
|
||||||
music_vorbis.info->rate);
|
music_vorbis.info->rate);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
52
src/player.c
52
src/player.c
@ -208,12 +208,16 @@ void player_new(void) {
|
|||||||
/* Create a new player. */
|
/* Create a new player. */
|
||||||
static void player_newMake(void) {
|
static void player_newMake(void) {
|
||||||
Ship* ship;
|
Ship* ship;
|
||||||
char system[20];
|
char* sysname;
|
||||||
uint32_t bufsize;
|
uint32_t bufsize;
|
||||||
char* buf = pack_readfile(DATA, START_DATA, &bufsize);
|
char* buf;
|
||||||
int l, h, tl, th;
|
int l, h, tl, th;
|
||||||
double x, y;
|
double x, y;
|
||||||
|
|
||||||
|
sysname = NULL;
|
||||||
|
|
||||||
|
buf = pack_readfile(DATA, START_DATA, &bufsize);
|
||||||
|
|
||||||
xmlNodePtr node, cur, tmp;
|
xmlNodePtr node, cur, tmp;
|
||||||
xmlDocPtr doc = xmlParseMemory(buf, bufsize);
|
xmlDocPtr doc = xmlParseMemory(buf, bufsize);
|
||||||
|
|
||||||
@ -246,7 +250,8 @@ static void player_newMake(void) {
|
|||||||
tmp = cur->children;
|
tmp = cur->children;
|
||||||
do {
|
do {
|
||||||
/* System name. TODO: Chance based on percentage. */
|
/* System name. TODO: Chance based on percentage. */
|
||||||
if(xml_isNode(tmp, "name")) snprintf(system, 20, xml_get(tmp));
|
if(xml_isNode(tmp, "name"))
|
||||||
|
sysname = strdup(xml_get(tmp));
|
||||||
/* Position. */
|
/* Position. */
|
||||||
xmlr_float(tmp, "x", x);
|
xmlr_float(tmp, "x", x);
|
||||||
xmlr_float(tmp, "y", y);
|
xmlr_float(tmp, "y", y);
|
||||||
@ -280,7 +285,8 @@ static void player_newMake(void) {
|
|||||||
|
|
||||||
/* Create the player and start the game. */
|
/* Create the player and start the game. */
|
||||||
player_newShip(ship, x, y, 0., 0., RNG(0, 359)/180.*M_PI);
|
player_newShip(ship, x, y, 0., 0., RNG(0, 359)/180.*M_PI);
|
||||||
space_init(system);
|
space_init(sysname);
|
||||||
|
free(sysname);
|
||||||
|
|
||||||
/* Clear the map. */
|
/* Clear the map. */
|
||||||
map_clear();
|
map_clear();
|
||||||
@ -1156,11 +1162,11 @@ void gui_free(void) {
|
|||||||
|
|
||||||
/* Used in pilot.c */
|
/* Used in pilot.c */
|
||||||
/* Basically uses keyboard input instead of AI input. */
|
/* Basically uses keyboard input instead of AI input. */
|
||||||
void player_think(Pilot* player) {
|
void player_think(Pilot* pplayer) {
|
||||||
/* Last I checked, the dead didn't think.. */
|
/* Last I checked, the dead didn't think.. */
|
||||||
if(pilot_isFlag(player, PILOT_DEAD)) {
|
if(pilot_isFlag(pplayer, PILOT_DEAD)) {
|
||||||
/* No point in accelerating or turning. */
|
/* No point in accelerating or turning. */
|
||||||
player->solid->dir_vel = 0.;
|
pplayer->solid->dir_vel = 0.;
|
||||||
vect_pset(&player->solid->force, 0., 0.);
|
vect_pset(&player->solid->force, 0., 0.);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1168,42 +1174,42 @@ void player_think(Pilot* player) {
|
|||||||
/* PLAYER_FACE will take over navigation. */
|
/* PLAYER_FACE will take over navigation. */
|
||||||
if(player_isFlag(PLAYER_FACE)) {
|
if(player_isFlag(PLAYER_FACE)) {
|
||||||
if(player_target != PLAYER_ID)
|
if(player_target != PLAYER_ID)
|
||||||
pilot_face(player,
|
pilot_face(pplayer,
|
||||||
vect_angle(&player->solid->pos,
|
vect_angle(&player->solid->pos,
|
||||||
&pilot_get(player_target)->solid->pos));
|
&pilot_get(player_target)->solid->pos));
|
||||||
else if(planet_target != -1)
|
else if(planet_target != -1)
|
||||||
pilot_face(player,
|
pilot_face(pplayer,
|
||||||
vect_angle(&player->solid->pos,
|
vect_angle(&player->solid->pos,
|
||||||
&cur_system->planets[planet_target].pos));
|
&cur_system->planets[planet_target].pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PLAYER_REVERSE will take over navigation. */
|
/* PLAYER_REVERSE will take over navigation. */
|
||||||
else if(player_isFlag(PLAYER_REVERSE) && (VMOD(player->solid->vel) > 0.))
|
else if(player_isFlag(PLAYER_REVERSE) && (VMOD(pplayer->solid->vel) > 0.))
|
||||||
pilot_face(player, VANGLE(player->solid->vel) + M_PI);
|
pilot_face(pplayer, VANGLE(player->solid->vel) + M_PI);
|
||||||
|
|
||||||
/* Normal navigation sheme. */
|
/* Normal navigation sheme. */
|
||||||
else {
|
else {
|
||||||
player->solid->dir_vel = 0.;
|
pplayer->solid->dir_vel = 0.;
|
||||||
if(player_turn)
|
if(player_turn)
|
||||||
player->solid->dir_vel -= player->turn * player_turn;
|
pplayer->solid->dir_vel -= player->turn * player_turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(player_isFlag(PLAYER_PRIMARY)) pilot_shoot(player, player_target, 0);
|
if(player_isFlag(PLAYER_PRIMARY)) pilot_shoot(pplayer, player_target, 0);
|
||||||
if(player_isFlag(PLAYER_SECONDARY)) /* Needs a target. */
|
if(player_isFlag(PLAYER_SECONDARY)) /* Needs a target. */
|
||||||
pilot_shoot(player, player_target, 1);
|
pilot_shoot(pplayer, player_target, 1);
|
||||||
|
|
||||||
if(player_isFlag(PLAYER_AFTERBURNER))
|
if(player_isFlag(PLAYER_AFTERBURNER))
|
||||||
vect_pset(&player->solid->force,
|
vect_pset(&pplayer->solid->force,
|
||||||
player->thrust * player->afterburner->outfit->u.afb.thrust_perc +
|
pplayer->thrust * pplayer->afterburner->outfit->u.afb.thrust_perc +
|
||||||
player->afterburner->outfit->u.afb.thrust_abs, player->solid->dir);
|
pplayer->afterburner->outfit->u.afb.thrust_abs, pplayer->solid->dir);
|
||||||
else
|
else
|
||||||
vect_pset(&player->solid->force, player->thrust * player_acc,
|
vect_pset(&pplayer->solid->force, pplayer->thrust * player_acc,
|
||||||
player->solid->dir);
|
pplayer->solid->dir);
|
||||||
|
|
||||||
/* Set the listener stuff. */
|
/* Set the listener stuff. */
|
||||||
sound_listener(player->solid->dir,
|
sound_listener(pplayer->solid->dir,
|
||||||
player->solid->pos.x, player->solid->pos.y,
|
pplayer->solid->pos.x, pplayer->solid->pos.y,
|
||||||
player->solid->vel.x, player->solid->vel.y);
|
pplayer->solid->vel.x, pplayer->solid->vel.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Modify the radar resolution. */
|
/* Modify the radar resolution. */
|
||||||
|
20
src/sound.c
20
src/sound.c
@ -368,7 +368,7 @@ static void sound_free(alSound* snd) {
|
|||||||
|
|
||||||
/* Update the sounds and prioritize them. */
|
/* Update the sounds and prioritize them. */
|
||||||
void sound_update(void) {
|
void sound_update(void) {
|
||||||
ALint stat;
|
ALint state;
|
||||||
alVoice* voice, *prev, *next;
|
alVoice* voice, *prev, *next;
|
||||||
|
|
||||||
if(sound_lock == NULL) return; /* Sound system is off. */
|
if(sound_lock == NULL) return; /* Sound system is off. */
|
||||||
@ -383,9 +383,9 @@ void sound_update(void) {
|
|||||||
next = voice->next;
|
next = voice->next;
|
||||||
|
|
||||||
/* Get status. */
|
/* Get status. */
|
||||||
stat = -1;
|
state = -1;
|
||||||
if(voice->source != 0)
|
if(voice->source != 0)
|
||||||
alGetSourcei(voice->source, AL_SOURCE_STATE, &stat);
|
alGetSourcei(voice->source, AL_SOURCE_STATE, &state);
|
||||||
|
|
||||||
if(!voice_is(voice, VOICE_DONE)) { /* Still working. */
|
if(!voice_is(voice, VOICE_DONE)) { /* Still working. */
|
||||||
/* Voice has a source. */
|
/* Voice has a source. */
|
||||||
@ -401,7 +401,7 @@ void sound_update(void) {
|
|||||||
prev = voice;
|
prev = voice;
|
||||||
}else {
|
}else {
|
||||||
/* Delete them. */
|
/* Delete them. */
|
||||||
if(stat != AL_PLAYING)
|
if(state != AL_PLAYING)
|
||||||
voice_rm(prev, voice); /* Do not set prev to voice. */
|
voice_rm(prev, voice); /* Do not set prev to voice. */
|
||||||
else
|
else
|
||||||
prev = voice;
|
prev = voice;
|
||||||
@ -414,12 +414,12 @@ void sound_update(void) {
|
|||||||
|
|
||||||
/* Remove a voice. */
|
/* Remove a voice. */
|
||||||
static void voice_rm(alVoice* prev, alVoice* voice) {
|
static void voice_rm(alVoice* prev, alVoice* voice) {
|
||||||
ALint stat;
|
ALint state;
|
||||||
|
|
||||||
if(voice->source != 0) { /* Source must exist. */
|
if(voice->source != 0) { /* Source must exist. */
|
||||||
/* Stop it if playing. */
|
/* Stop it if playing. */
|
||||||
alGetSourcei(voice->source, AL_SOURCE_STATE, &stat);
|
alGetSourcei(voice->source, AL_SOURCE_STATE, &state);
|
||||||
if(stat == AL_PLAYING) alSourceStop(voice->source);
|
if(state == AL_PLAYING) alSourceStop(voice->source);
|
||||||
|
|
||||||
/* Clear it and get rid of it. */
|
/* Clear it and get rid of it. */
|
||||||
source_stack[source_nstack++] = voice->source; /* Throw it back. */
|
source_stack[source_nstack++] = voice->source; /* Throw it back. */
|
||||||
@ -588,12 +588,12 @@ static void voice_parseFlags(alVoice* voice, const unsigned int flags) {
|
|||||||
/* Make a voice play. Must lock before calling. */
|
/* Make a voice play. Must lock before calling. */
|
||||||
static int voice_play(alVoice* voice) {
|
static int voice_play(alVoice* voice) {
|
||||||
ALenum err;
|
ALenum err;
|
||||||
ALint stat;
|
ALint state;
|
||||||
|
|
||||||
/* Must have buffer. */
|
/* Must have buffer. */
|
||||||
if(voice->buffer != 0) {
|
if(voice->buffer != 0) {
|
||||||
alGetSourcei(voice->source, AL_SOURCE_STATE, &stat);
|
alGetSourcei(voice->source, AL_SOURCE_STATE, &state);
|
||||||
if(stat == AL_PLAYING)
|
if(state == AL_PLAYING)
|
||||||
alSourceStop(voice->source);
|
alSourceStop(voice->source);
|
||||||
/* Set buffer. */
|
/* Set buffer. */
|
||||||
alSourcei(voice->source, AL_BUFFER, voice->buffer);
|
alSourcei(voice->source, AL_BUFFER, voice->buffer);
|
||||||
|
30
src/space.c
30
src/space.c
@ -51,7 +51,7 @@ static int spacename_nstack = 0;
|
|||||||
/* Star system stack and co. */
|
/* Star system stack and co. */
|
||||||
StarSystem* systems_stack = NULL; /* Star system stack. */
|
StarSystem* systems_stack = NULL; /* Star system stack. */
|
||||||
int systems_nstack = 0; /* Number of star systems. */
|
int systems_nstack = 0; /* Number of star systems. */
|
||||||
static int nplanets = 0; /* Total number of loaded planets - A little silly. */
|
static int total_planets = 0; /* Total number of loaded planets - A little silly. */
|
||||||
StarSystem* cur_system = NULL; /* Current star system. */
|
StarSystem* cur_system = NULL; /* Current star system. */
|
||||||
|
|
||||||
/* Fleet spawn rate. */
|
/* Fleet spawn rate. */
|
||||||
@ -309,15 +309,15 @@ char* planet_getSystem(char* planetname) {
|
|||||||
/* Get a planet based on it's name. */
|
/* Get a planet based on it's name. */
|
||||||
Planet* planet_get(char* planetname) {
|
Planet* planet_get(char* planetname) {
|
||||||
int i;
|
int i;
|
||||||
char* sys;
|
char* sysname;
|
||||||
StarSystem* system;
|
StarSystem* sys;
|
||||||
|
|
||||||
sys = planet_getSystem(planetname);
|
sysname = planet_getSystem(planetname);
|
||||||
system = system_get(sys);
|
sys = system_get(sysname);
|
||||||
|
|
||||||
for(i = 0; i < system->nplanets; i++)
|
for(i = 0; i < sys->nplanets; i++)
|
||||||
if(strcmp(planetname, system->planets[i].name)==0)
|
if(strcmp(planetname, sys->planets[i].name)==0)
|
||||||
return &system->planets[i];
|
return &sys->planets[i];
|
||||||
DEBUG("Planet '%s' not found in the universe", planetname);
|
DEBUG("Planet '%s' not found in the universe", planetname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -640,7 +640,7 @@ static StarSystem* system_parse(const xmlNodePtr parent) {
|
|||||||
do {
|
do {
|
||||||
if(cur && xml_isNode(cur, "planet")) {
|
if(cur && xml_isNode(cur, "planet")) {
|
||||||
/* Add planet to system. */
|
/* Add planet to system. */
|
||||||
nplanets++; /* Increase planet counter. */
|
total_planets++; /* Increase planet counter. */
|
||||||
planet = planet_pull(xml_get(cur));
|
planet = planet_pull(xml_get(cur));
|
||||||
tmp->planets = realloc(tmp->planets, sizeof(Planet)*(++tmp->nplanets));
|
tmp->planets = realloc(tmp->planets, sizeof(Planet)*(++tmp->nplanets));
|
||||||
memcpy(tmp->planets+(tmp->nplanets-1), planet, sizeof(Planet));
|
memcpy(tmp->planets+(tmp->nplanets-1), planet, sizeof(Planet));
|
||||||
@ -701,14 +701,14 @@ static StarSystem* system_parse(const xmlNodePtr parent) {
|
|||||||
/* Load the jumps into a system. */
|
/* Load the jumps into a system. */
|
||||||
static void system_parseJumps(const xmlNodePtr parent) {
|
static void system_parseJumps(const xmlNodePtr parent) {
|
||||||
int i;
|
int i;
|
||||||
StarSystem* system;
|
StarSystem* sys;
|
||||||
char* name;
|
char* name;
|
||||||
xmlNodePtr cur, node;
|
xmlNodePtr cur, node;
|
||||||
|
|
||||||
name = xml_nodeProp(parent, "name"); /* Already mallocs. */
|
name = xml_nodeProp(parent, "name"); /* Already mallocs. */
|
||||||
for(i = 0; i < systems_nstack; i++)
|
for(i = 0; i < systems_nstack; i++)
|
||||||
if(strcmp(systems_stack[i].name, name)==0) {
|
if(strcmp(systems_stack[i].name, name)==0) {
|
||||||
system = &systems_stack[i];
|
sys = &systems_stack[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(i == systems_nstack)
|
if(i == systems_nstack)
|
||||||
@ -725,9 +725,9 @@ static void system_parseJumps(const xmlNodePtr parent) {
|
|||||||
if(xml_isNode(cur, "jump")) {
|
if(xml_isNode(cur, "jump")) {
|
||||||
for(i = 0; i < systems_nstack; i++)
|
for(i = 0; i < systems_nstack; i++)
|
||||||
if(strcmp(systems_stack[i].name, xml_get(cur))==0) {
|
if(strcmp(systems_stack[i].name, xml_get(cur))==0) {
|
||||||
system->njumps++;
|
sys->njumps++;
|
||||||
system->jumps = realloc(system->jumps, system->njumps*sizeof(int));
|
sys->jumps = realloc(sys->jumps, sys->njumps*sizeof(int));
|
||||||
system->jumps[system->njumps-1] = i;
|
sys->jumps[sys->njumps-1] = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(i == systems_nstack)
|
if(i == systems_nstack)
|
||||||
@ -783,7 +783,7 @@ int space_load(void) {
|
|||||||
|
|
||||||
DEBUG("Loaded %d star system%s with %d planet%s",
|
DEBUG("Loaded %d star system%s with %d planet%s",
|
||||||
systems_nstack, (systems_nstack==1) ? "" : "s",
|
systems_nstack, (systems_nstack==1) ? "" : "s",
|
||||||
nplanets, (nplanets==1) ? "" : "s");
|
total_planets, (total_planets==1) ? "" : "s");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user