[Change] Don't always preload comms graphics for ships, load only as

needed.
This commit is contained in:
Allanis 2014-07-23 20:07:45 +01:00
parent 0faad008b5
commit 25d001d05b
3 changed files with 49 additions and 19 deletions

View File

@ -12,14 +12,17 @@
#include "rng.h" #include "rng.h"
#include "llua.h" #include "llua.h"
#include "player.h" #include "player.h"
#include "opengl.h"
#include "comm.h" #include "comm.h"
#define BUTTON_WIDTH 80 /**< Button width. */ #define BUTTON_WIDTH 80 /**< Button width. */
#define BUTTON_HEIGHT 30 /*<< Button height. */ #define BUTTON_HEIGHT 30 /*<< Button height. */
static Pilot* comm_pilot = NULL; /**< Pilot currently talking to. */ static Pilot* comm_pilot = NULL; /**< Pilot currently talking to. */
static glTexture* comm_graphic = NULL; /**< Pilot graphic. */
/* Static. */ /* Static. */
static void comm_close(unsigned int wid, char* unused);
static void comm_bribe(unsigned int wid, char* unused); static void comm_bribe(unsigned int wid, char* unused);
static unsigned int comm_getBribeAmount(void); static unsigned int comm_getBribeAmount(void);
static char* comm_getBribeString(char* str); static char* comm_getBribeString(char* str);
@ -33,7 +36,7 @@ extern void ai_setPilot(Pilot* p); /**< From ai.c. */
*/ */
int comm_open(unsigned int pilot) { int comm_open(unsigned int pilot) {
int x, y, w; int x, y, w;
glTexture* logo, *gfx_comm; glTexture* logo;
char* name, *stand; char* name, *stand;
unsigned int wid; unsigned int wid;
glColour* c; glColour* c;
@ -49,7 +52,7 @@ int comm_open(unsigned int pilot) {
} }
/* Get graphics and text. */ /* Get graphics and text. */
gfx_comm = comm_pilot->ship->gfx_comm; comm_graphic = ship_loadCommGFX(comm_pilot->ship);
logo = faction_logoSmall(comm_pilot->faction); logo = faction_logoSmall(comm_pilot->faction);
name = comm_pilot->name; name = comm_pilot->name;
/* Get standing colour / text. */ /* Get standing colour / text. */
@ -66,36 +69,36 @@ int comm_open(unsigned int pilot) {
w += logo->w; w += logo->w;
y = MAX(y, logo->w); y = MAX(y, logo->w);
} }
x = (gfx_comm->w - w) / 2; x = (comm_graphic->w - w) / 2;
/* Create the window. */ /* Create the window. */
wid = window_create("Communication Channel", -1, -1, wid = window_create("Communication Channel", -1, -1,
20 + gfx_comm->w + 20 + BUTTON_WIDTH + 20, 30 + gfx_comm->h + y + 5 + 20); 20 + comm_graphic->w + 20 + BUTTON_WIDTH + 20, 30 + comm_graphic->h + y + 5 + 20);
/* Create the ship image. */ /* Create the ship image. */
window_addRect(wid, 20, -30, gfx_comm->w, gfx_comm->h + y + 5, "rctShip", &cGrey10, 1); window_addRect(wid, 20, -30, comm_graphic->w, comm_graphic->h + y + 5, "rctShip", &cGrey10, 1);
window_addImage(wid, 20, -30, "imgShip", gfx_comm, 0); window_addImage(wid, 20, -30, "imgShip", comm_graphic, 0);
/* Faction logo. */ /* Faction logo. */
if(logo != NULL) { if(logo != NULL) {
window_addImage(wid, x, -30 - gfx_comm->h - 5, window_addImage(wid, x, -30 - comm_graphic->h - 5,
"imgFaction", logo, 0); "imgFaction", logo, 0);
x += logo->w + 10; x += logo->w + 10;
y -= (logo->w - (gl_defFont.h*2 + 15)) / 2; y -= (logo->w - (gl_defFont.h*2 + 15)) / 2;
} }
/* Name. */ /* Name. */
window_addText(wid, x, -30 - gfx_comm->h - y + gl_defFont.h*2 + 10, window_addText(wid, x, -30 - comm_graphic->h - y + gl_defFont.h*2 + 10,
gfx_comm->w - x, 20, 0, "txtName", comm_graphic->w - x, 20, 0, "txtName",
NULL, &cDConsole, name); NULL, &cDConsole, name);
/* Standing. */ /* Standing. */
window_addText(wid, x, -30 - gfx_comm->h - y + gl_defFont.h + 5, window_addText(wid, x, -30 - comm_graphic->h - y + gl_defFont.h + 5,
gfx_comm->w - x, 20, 0, "txtStanding", NULL, c, stand); comm_graphic->w - x, 20, 0, "txtStanding", NULL, c, stand);
/* Buttons. */ /* Buttons. */
window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
"btnClose", "Close Channel", window_close); "btnClose", "Close Channel", comm_close);
window_addButton(wid, -20, 20 + BUTTON_HEIGHT + 20, window_addButton(wid, -20, 20 + BUTTON_HEIGHT + 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnGreet", "Greet", NULL); BUTTON_WIDTH, BUTTON_HEIGHT, "btnGreet", "Greet", NULL);
@ -111,6 +114,22 @@ int comm_open(unsigned int pilot) {
return 0; return 0;
} }
/**
* @brief Close the comm window.
* @param wid ID of window calling the function.
* @param unused Unused.
*/
static void comm_close(unsigned int wid, char* unused) {
/* Clean up a but after ourselves. */
if(comm_graphic != NULL) {
gl_freeTexture(comm_graphic);
comm_graphic = NULL;
}
comm_pilot = NULL;
/* Close the window. */
window_close(wid, unused);
}
/** /**
* @brief Try to bribe the pilot. * @brief Try to bribe the pilot.
* @param wid ID of window calling the function. * @param wid ID of window calling the function.

View File

@ -268,6 +268,17 @@ int ship_basePrice(Ship* s) {
return price; return price;
} }
/**
* @brief Load the ships comm graphic.
*
* Must be freed afterwards.
*/
glTexture* ship_loadCommGFX(Ship* s) {
char buf[PATH_MAX];
snprintf(buf, PATH_MAX, SHIP_GFX"%s"SHIP_COMM SHIP_EXT, s->gfx_comm);
return gl_newImage(buf, 0);
}
/** /**
* @brief Extracts the ingame ship from an XML node. * @brief Extracts the ingame ship from an XML node.
* @param tmp Ship to load data into. * @param tmp Ship to load data into.
@ -308,9 +319,8 @@ static int ship_parse(Ship* tmp, xmlNodePtr parent) {
tmp->mangle = 2.*M_PI; tmp->mangle = 2.*M_PI;
tmp->mangle /= tmp->gfx_space->sx * tmp->gfx_space->sy; tmp->mangle /= tmp->gfx_space->sx * tmp->gfx_space->sy;
/* Load the comm graphic. */ /* Get the comm graphic for future loading. */
tmp->gfx_comm = xml_parseTexture(node, tmp->gfx_comm = xml_getStrd(node);
SHIP_GFX"%s"SHIP_COMM SHIP_EXT, 1, 1, 0);
/* Load the target graphic. */ /* Load the target graphic. */
xmlr_attr(node, "target", stmp); xmlr_attr(node, "target", stmp);
@ -532,8 +542,8 @@ void ships_free(void) {
/* Free graphics. */ /* Free graphics. */
gl_freeTexture(s->gfx_space); gl_freeTexture(s->gfx_space);
gl_freeTexture(s->gfx_comm);
gl_freeTexture(ship_stack[i].gfx_target); gl_freeTexture(ship_stack[i].gfx_target);
free(s->gfx_comm);
} }
free(ship_stack); free(ship_stack);
ship_stack = NULL; ship_stack = NULL;

View File

@ -71,9 +71,9 @@ typedef struct Ship_ {
double thrust, turn, speed; double thrust, turn, speed;
/* Graphics. */ /* Graphics. */
glTexture* gfx_space; glTexture* gfx_space; /**< Space sprite sheet. */
glTexture* gfx_target; glTexture* gfx_target; /**< Targetting window graphic. */
glTexture* gfx_comm; char* gfx_comm; /**< Name of graphic for communication. */
/* GUI interface. */ /* GUI interface. */
char* gui; char* gui;
@ -114,6 +114,7 @@ Ship** ship_getTech(int* n, const int* tech, const int techmax);
char* ship_class(Ship* p); char* ship_class(Ship* p);
ShipClass ship_classFromString(char* str); ShipClass ship_classFromString(char* str);
int ship_basePrice(Ship* s); int ship_basePrice(Ship* s);
glTexture* ship_loadCommGFX(Ship* s);
/* Toolkit. */ /* Toolkit. */
void ship_view(unsigned int unused, char* shipname); void ship_view(unsigned int unused, char* shipname);