[Change] Cleaned up some code.

This commit is contained in:
Allanis 2014-07-20 21:49:39 +01:00
parent b4edcb5f27
commit 62f31aa8c4
7 changed files with 48 additions and 34 deletions

View File

@ -355,7 +355,7 @@ void gui_render(double dt) {
NULL, "%s", cur_system->planets[planet_target]->name);
}
else if(hyperspace_target >= 0) { /* Hyperspace target. */
sys = &systems_stack[cur_system->jumps[hyperspace_target]];
sys = system_getIndex(cur_system->jumps[hyperspace_target]);
/* Determine if we have to play the "enter hyperspace range" sound. */
i = space_canHyperspace(player);

View File

@ -529,7 +529,7 @@ static void render_all(void) {
player_render(dt);
spfx_render(SPFX_LAYER_FRONT);
space_renderOverlay(dt);
gui_render(dt);
//gui_render(dt);
display_fps(dt); /* Exception. */
}

View File

@ -51,7 +51,9 @@ static void map_selectCur(void);
*/
void map_open(void) {
unsigned int wid;
StarSystem* cur;
/* Destroy window if exitsts. */
wid = window_get(MAP_WDWNAME);
if(wid > 0) {
window_destroy(wid);
@ -69,6 +71,10 @@ void map_open(void) {
if(map_selected == -1)
map_selectCur();
/* Get the selected system. */
cur = system_getIndex(map_selected);
/* Create the window. */
wid = window_create("Star Map", -1, -1, WINDOW_WIDTH, WINDOW_HEIGHT);
/*
@ -95,7 +101,7 @@ void map_open(void) {
/* System name. */
window_addText(wid, -20, -20, 100, 20, 1, "txtSysname",
&gl_defFont, &cDConsole, systems_stack[map_selected].name);
&gl_defFont, &cDConsole, cur->name);
/* Faction. */
window_addText(wid, -20, -60, 90, 20, 0, "txtSFaction",
@ -160,6 +166,8 @@ static void map_update(unsigned int wid) {
if(!map_isOpen())
return;
sys = system_getIndex(map_selected);
sys = &systems_stack[map_selected];
/* Right text. */
@ -330,7 +338,7 @@ static int map_inPath(StarSystem* sys) {
static void map_render(double bx, double by, double w, double h) {
int i, j, n, m;
double x, y, r, tx, ty;
StarSystem* sys;
StarSystem* sys, *jsys, *hsys;
glColour* col;
r = 5.;
@ -347,7 +355,7 @@ static void map_render(double bx, double by, double w, double h) {
/* Render the star systems. */
for(i = 0; i < systems_nstack; i++) {
sys = &systems_stack[i];
sys = system_getIndex(i);
/* Check to make sure system is known of adjacent to known (or marked). */
if(!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED) && !space_sysReachable(sys))
@ -394,13 +402,16 @@ static void map_render(double bx, double by, double w, double h) {
/* Cheaply use transparency instead of actually */
/* calculating from x to y the line must go. :) */
for(j = 0; j < sys->njumps; j++) {
n = map_inPath(&systems_stack[sys->jumps[j]]);
jsys = system_getIndex(sys->jumps[j]);
hsys = system_getIndex(cur_system->jumps[hyperspace_target]);
n = map_inPath(jsys);
m = map_inPath(sys);
/* Set the colours, is the route the current one? */
if((hyperspace_target != -1) &&
(((cur_system == sys) && (j == hyperspace_target)) ||
((cur_system == &systems_stack[sys->jumps[j]]) &&
(sys==&systems_stack[cur_system->jumps[hyperspace_target]])))) {
((cur_system == jsys) &&
(sys == hsys)))) {
if(player->fuel < HYPERSPACE_FUEL)
col = &cRed;
else
@ -420,12 +431,12 @@ static void map_render(double bx, double by, double w, double h) {
ty = y + sys->pos.y * map_zoom;
glVertex2d(tx, ty);
COLOUR(*col);
tx += (systems_stack[sys->jumps[j]].pos.x - sys->pos.x)/2. * map_zoom;
ty += (systems_stack[sys->jumps[j]].pos.y - sys->pos.y)/2. * map_zoom;
tx += (jsys->pos.x - sys->pos.x)/2. * map_zoom;
ty += (jsys->pos.y - sys->pos.y)/2. * map_zoom;
glVertex2d(tx, ty);
ACOLOUR(*col, 0.);
tx = x + systems_stack[sys->jumps[j]].pos.x * map_zoom;
ty = y + systems_stack[sys->jumps[j]].pos.y * map_zoom;
tx = x + jsys->pos.x * map_zoom;
ty = y + jsys->pos.y * map_zoom;
glVertex2d(tx, ty);
glEnd();
}
@ -433,7 +444,7 @@ static void map_render(double bx, double by, double w, double h) {
}
/* Selected planet. */
if(map_selected != -1) {
sys = &systems_stack[map_selected];
sys = system_getIndex(map_selected);
COLOUR(cRed);
gl_drawCircleInRect(x + sys->pos.x*map_zoom, y + sys->pos.y*map_zoom,
r+3., bx, by, w, h);
@ -461,7 +472,7 @@ static void map_mouse(unsigned int wid, SDL_Event* event, double mx, double my)
/* Selecting star system. */
else {
for(i = 0; i < systems_nstack; i++) {
sys = &systems_stack[i];
sys = system_getIndex(i);
/* Must be reachable. */
if(!space_sysReachable(sys))
@ -482,9 +493,9 @@ static void map_mouse(unsigned int wid, SDL_Event* event, double mx, double my)
if(map_npath == 0)
hyperspace_target = -1;
else
/* See if it a valid hyperspace target. */
/* See if it is a valid hyperspace target. */
for(j = 0; j < cur_system->njumps; j++) {
if(map_path[0] == &systems_stack[cur_system->jumps[j]]) {
if(map_path[0] == system_getIndex(cur_system->jumps[j])) {
planet_target = -1; /* Override planet_target. */
hyperspace_target = j;
break;
@ -596,7 +607,7 @@ void map_jump(void) {
/* Set the next jump to be the next in path. */
for(j = 0; j < cur_system->njumps; j++) {
if(map_path[0] == &systems_stack[cur_system->jumps[j]]) {
if(map_path[0] == system_getIndex(cur_system->jumps[j])) {
planet_target = -1; /* Override planet_target. */
hyperspace_target = j;
break;
@ -806,7 +817,7 @@ StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int igno
cost = A_g(cur) + 1;
for(i = 0; i < cur->sys->njumps; i++) {
sys = &systems_stack[cur->sys->jumps[i]];
sys = system_getIndex(cur->sys->jumps[i]);
/* Make sure it's reachable. */
if(!ignore_known && (!sys_isKnown(sys) && !space_sysReachable(esys)))
@ -875,7 +886,7 @@ int map_map(char* targ_sys, int r) {
/* Check it's jumps. */
for(i = 0; i < sys->njumps; i++) {
jsys = &systems_stack[cur->sys->jumps[i]];
jsys = system_getIndex(cur->sys->jumps[i]);
/* System has already been parsed or is too deep. */
if((A_in(closed, jsys) != NULL) || (dep+1 > r))
@ -919,7 +930,7 @@ int map_isMapped(char* targ_sys, int r) {
/* Check it's jumps. */
for(i = 0; i < sys->njumps; i++) {
jsys = &systems_stack[cur->sys->jumps[i]];
jsys = system_getIndex(cur->sys->jumps[i]);
/* System has already been parsed or is too deep. */
if((A_in(closed, jsys) != NULL) || (dep+1 > r))

View File

@ -32,10 +32,6 @@ Mission player_missions[MISSION_MAX];
static MissionData* mission_stack = NULL; /* Unmuteable after creation. */
static int mission_nstack = 0;
/* External space stack. */
extern StarSystem* systems_stack;
extern int systems_nstack;
/* Static. */
static unsigned int mission_genID(void);
static int mission_init(Mission* mission, MissionData* misn, int load);

View File

@ -101,9 +101,6 @@ static int missions_ndone = 0; /**< Number of completed missions. */
extern Pilot** pilot_stack;
extern int pilot_nstack;
/* Stuff for autonav etc. */
extern StarSystem* systems_stack;
/* Map stuff for autonav. */
extern int map_npath;
@ -1016,7 +1013,7 @@ void player_targetHyperspace(void) {
if(hyperspace_target == -1)
map_select(NULL);
else
map_select(&systems_stack[cur_system->jumps[hyperspace_target]]);
map_select(system_getIndex(cur_system->jumps[hyperspace_target]));
}
}
@ -1069,7 +1066,7 @@ void player_brokeHyperspace(void) {
ltime_inc(RNG(tl, th));
/* Enter the new system. */
space_init(systems_stack[cur_system->jumps[hyperspace_target]].name);
space_init(system_getIndex(cur_system->jumps[hyperspace_target])->name);
/* Set position, pilot_update will handle the lowering of velocity. */
d = RNGF()*(HYPERSPACE_ENTER_MAX-HYPERSPACE_ENTER_MIN) + HYPERSPACE_ENTER_MIN;
@ -1107,10 +1104,10 @@ void player_brokeHyperspace(void) {
*/
double player_faceHyperspace(void) {
double a;
a = ANGLE(systems_stack[cur_system->jumps[hyperspace_target]].pos.x -
cur_system->pos.x,
systems_stack[cur_system->jumps[hyperspace_target]].pos.y -
cur_system->pos.y);
StarSystem* sys;
sys = system_getIndex(cur_system->jumps[hyperspace_target]);
a = ANGLE(sys->pos.x - cur_system->pos.x, sys->pos.y - cur_system->pos.y);
return pilot_face(player, a);
}

View File

@ -374,7 +374,7 @@ int space_sysReachable(StarSystem* sys) {
/* Check to see if it is adjacent to known. */
for(i = 0; i < sys->njumps; i++)
if(sys_isKnown(&systems_stack[sys->jumps[i]]))
if(sys_isKnown(system_getIndex(sys->jumps[i])))
return 1;
return 0;
}
@ -391,6 +391,15 @@ StarSystem* system_get(const char* sysname) {
return NULL;
}
/**
* @brief Get the system by its index.
* @param id Index to match.
* @return Systems matching index.
*/
StarSystem* system_getIndex(int id) {
return &systems_stack[id];
}
/* Get the name of a system from a planetname. */
char* planet_getSystem(char* planetname) {
int i;

View File

@ -168,6 +168,7 @@ void space_update(const double dt);
/* Misc. */
StarSystem* system_get(const char* sysname);
StarSystem* system_getIndex(int id);
int space_canHyperspace(Pilot* p);
int space_hyperspace(Pilot* p);
int space_sysReachable(StarSystem* sys);