[Change] Split player rendering properly into GUI and player.
This commit is contained in:
parent
092b48651d
commit
497081b3ed
@ -356,10 +356,11 @@ static void render_all(void) {
|
|||||||
pilots_render();
|
pilots_render();
|
||||||
weapons_render(WEAPON_LAYER_FG);
|
weapons_render(WEAPON_LAYER_FG);
|
||||||
spfx_render(SPFX_LAYER_BACK);
|
spfx_render(SPFX_LAYER_BACK);
|
||||||
space_renderOverlay(cur_dt);
|
|
||||||
/* FG. */
|
/* FG. */
|
||||||
player_render();
|
player_render();
|
||||||
spfx_render(SPFX_LAYER_FRONT);
|
spfx_render(SPFX_LAYER_FRONT);
|
||||||
|
space_renderOverlay(cur_dt);
|
||||||
|
player_renderGUI();
|
||||||
display_fps(cur_dt);
|
display_fps(cur_dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,12 +10,14 @@
|
|||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "pause.h"
|
||||||
#include "perlin.h"
|
#include "perlin.h"
|
||||||
|
|
||||||
#define NEBULAE_Z 16 /* Z plane. */
|
#define NEBULAE_Z 16 /* Z plane. */
|
||||||
#define NEBULAE_PUFFS 32 /* Amount of puffs to generate. */
|
#define NEBULAE_PUFFS 32 /* Amount of puffs to generate. */
|
||||||
#define NEBULAE_PATH_BG "gen/nebu_bg_%dx%d_%02d.png"
|
#define NEBULAE_PATH_BG "gen/nebu_bg_%dx%d_%02d.png"
|
||||||
#define NEBULAE_PATH_PUFF "gen/nebu_puff_%02d.png"
|
|
||||||
|
#define NEBULAE_PUFF_BUFFER 300 /* Nebulae buffer. */
|
||||||
|
|
||||||
/* Extern. */
|
/* Extern. */
|
||||||
extern double gui_xoff, gui_yoff;
|
extern double gui_xoff, gui_yoff;
|
||||||
@ -36,19 +38,14 @@ static double nebu_view = 0.;
|
|||||||
static double nebu_dt = 0.;
|
static double nebu_dt = 0.;
|
||||||
|
|
||||||
/* Puff textures. */
|
/* Puff textures. */
|
||||||
typedef struct NebulaePuffTex_ {
|
static glTexture* nebu_pufftexs[NEBULAE_PUFFS];
|
||||||
GLuint tex; /* Actualy texture. */
|
|
||||||
double w, h; /* Real dimensions. */
|
|
||||||
double pw, ph; /* Padding. */
|
|
||||||
} NebulaePuffTex;
|
|
||||||
static NebulaePuffTex nebu_pufftexs[NEBULAE_PUFFS];
|
|
||||||
|
|
||||||
/* Puff handling. */
|
/* Puff handling. */
|
||||||
typedef struct NebulaePuff_ {
|
typedef struct NebulaePuff_ {
|
||||||
double x, y; /* Position. */
|
double x, y; /* Position. */
|
||||||
double a, va; /* Alpha, alpha velocity. */
|
double a, va; /* Alpha, alpha velocity. */
|
||||||
double height; /* Height vs player. */
|
double height; /* Height vs player. */
|
||||||
NebulaePuffTex* tex; /* Texture. */
|
int tex; /* Texture. */
|
||||||
} NebulaePuff;
|
} NebulaePuff;
|
||||||
static NebulaePuff* nebu_puffs = NULL;
|
static NebulaePuff* nebu_puffs = NULL;
|
||||||
static int nebu_npuffs = 0;
|
static int nebu_npuffs = 0;
|
||||||
@ -142,21 +139,21 @@ void nebu_exit(void) {
|
|||||||
glDeleteTextures(NEBULAE_Z, nebu_textures);
|
glDeleteTextures(NEBULAE_Z, nebu_textures);
|
||||||
|
|
||||||
for(i = 0; i < NEBULAE_PUFFS; i++)
|
for(i = 0; i < NEBULAE_PUFFS; i++)
|
||||||
glDeleteTextures(1, &nebu_pufftexs[i].tex);
|
gl_freeTexture(nebu_pufftexs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Render the nebulae. */
|
/* Render the nebulae. */
|
||||||
void nebu_render(void) {
|
void nebu_render(const double dt) {
|
||||||
unsigned int t;
|
unsigned int t;
|
||||||
double dt;
|
double ndt;
|
||||||
double tw, th;
|
double tw, th;
|
||||||
GLfloat col[4];
|
GLfloat col[4];
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
/* Calculate frame to draw. */
|
/* Calculate frame to draw. */
|
||||||
t = SDL_GetTicks();
|
t = SDL_GetTicks();
|
||||||
dt = (t - last_render) / 1000.;
|
ndt = (t - last_render) / 1000.;
|
||||||
if(dt > nebu_dt) { /* Time to change. */
|
if(ndt > nebu_dt) { /* Time to change. */
|
||||||
tmp = cur_nebu[0];
|
tmp = cur_nebu[0];
|
||||||
cur_nebu[0] += cur_nebu[0] - cur_nebu[1];
|
cur_nebu[0] += cur_nebu[0] - cur_nebu[1];
|
||||||
cur_nebu[1] = tmp;
|
cur_nebu[1] = tmp;
|
||||||
@ -166,13 +163,14 @@ void nebu_render(void) {
|
|||||||
cur_nebu[0] = 1;
|
cur_nebu[0] = 1;
|
||||||
|
|
||||||
last_render = t;
|
last_render = t;
|
||||||
dt = 0.;
|
ndt = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set colour. */
|
||||||
col[0] = cPurple.r;
|
col[0] = cPurple.r;
|
||||||
col[1] = cPurple.g;
|
col[1] = cPurple.g;
|
||||||
col[2] = cPurple.b;
|
col[2] = cPurple.b;
|
||||||
col[3] = dt / nebu_dt;
|
col[3] = ndt / nebu_dt;
|
||||||
|
|
||||||
tw = (double)nebu_w / (double)nebu_pw;
|
tw = (double)nebu_w / (double)nebu_pw;
|
||||||
th = (double)nebu_h / (double)nebu_ph;
|
th = (double)nebu_h / (double)nebu_ph;
|
||||||
@ -240,6 +238,7 @@ void nebu_render(void) {
|
|||||||
|
|
||||||
glPopMatrix(); /* GL_PROJECTION */
|
glPopMatrix(); /* GL_PROJECTION */
|
||||||
|
|
||||||
|
/* Set values to defaults. */
|
||||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
@ -248,6 +247,9 @@ void nebu_render(void) {
|
|||||||
|
|
||||||
/* Did anything fail? */
|
/* Did anything fail? */
|
||||||
gl_checkErr();
|
gl_checkErr();
|
||||||
|
|
||||||
|
/* Now render the puffs. */
|
||||||
|
nebu_renderPuffs(dt, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nebu_renderOverlay(const double dt) {
|
void nebu_renderOverlay(const double dt) {
|
||||||
@ -343,27 +345,39 @@ void nebu_renderOverlay(const double dt) {
|
|||||||
/* Render the puffs. */
|
/* Render the puffs. */
|
||||||
void nebu_renderPuffs(const double dt, int below_player) {
|
void nebu_renderPuffs(const double dt, int below_player) {
|
||||||
int i;
|
int i;
|
||||||
|
glColour cPuff;
|
||||||
|
|
||||||
glPushMatrix(); /* GL_PROJECTION */
|
cPuff.r = cPurple.r;
|
||||||
glTranslated(-(double)SCREEN_W/2., -(double)SCREEN_H/2., 0.);
|
cPuff.g = cPurple.g;
|
||||||
|
cPuff.b = cPurple.b;
|
||||||
|
|
||||||
for(i = 0; i < nebu_npuffs; i++) {
|
for(i = 0; i < nebu_npuffs; i++) {
|
||||||
if((below_player && (nebu_puffs[i].height < 1.)) ||
|
if((below_player && (nebu_puffs[i].height < 1.)) ||
|
||||||
(!below_player && (nebu_puffs[i].height > 1.))) {
|
(!below_player && (nebu_puffs[i].height > 1.))) {
|
||||||
|
|
||||||
/* Calculate new position. */
|
/* Calculate new position. */
|
||||||
nebu_puffs[i].x -= player->solid->vel.x * nebu_puffs[i].height * dt;
|
if(!paused) {
|
||||||
nebu_puffs[i].y -= player->solid->vel.y * nebu_puffs[i].height * dt;
|
nebu_puffs[i].x -= player->solid->vel.x * nebu_puffs[i].height * dt;
|
||||||
|
nebu_puffs[i].y -= player->solid->vel.y * nebu_puffs[i].height * dt;
|
||||||
|
}
|
||||||
|
|
||||||
/* Calculate new alpha. */
|
/* Calculate new alpha. */
|
||||||
/*nebu_puffs[i].a += nebu_puffs[i].va * dt;*/
|
/*nebu_puffs[i].a += nebu_puffs[i].va * dt;*/
|
||||||
|
cPuff.a = nebu_puffs[i].a;
|
||||||
|
|
||||||
/* Check boundaries. */
|
/* Check boundaries. */
|
||||||
|
if(nebu_puffs[i].x > SCREEN_W + NEBULAE_PUFF_BUFFER)
|
||||||
|
nebu_puffs[i].x = -NEBULAE_PUFF_BUFFER;
|
||||||
|
else if(nebu_puffs[i].y > SCREEN_H + NEBULAE_PUFF_BUFFER)
|
||||||
|
nebu_puffs[i].y = -NEBULAE_PUFF_BUFFER;
|
||||||
|
else if(nebu_puffs[i].x < -NEBULAE_PUFF_BUFFER)
|
||||||
|
nebu_puffs[i].x = SCREEN_W + NEBULAE_PUFF_BUFFER;
|
||||||
|
else if(nebu_puffs[i].y < -NEBULAE_PUFF_BUFFER)
|
||||||
|
nebu_puffs[i].y = SCREEN_H + NEBULAE_PUFF_BUFFER;
|
||||||
|
|
||||||
/* Render. */
|
/* Render. */
|
||||||
ACOLOUR(cPurple, nebu_puffs[i].a);
|
gl_blitStatic(nebu_pufftexs[nebu_puffs[i].tex],
|
||||||
glBegin(GL_QUADS);
|
nebu_puffs[i].x, nebu_puffs[i].y, &cPuff);
|
||||||
glEnd(); /* GL_QUADS */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,8 +385,22 @@ void nebu_renderPuffs(const double dt, int below_player) {
|
|||||||
/* Prepare the nebulae. */
|
/* Prepare the nebulae. */
|
||||||
void nebu_prep(double density, double volatility) {
|
void nebu_prep(double density, double volatility) {
|
||||||
(void)volatility;
|
(void)volatility;
|
||||||
|
int i;
|
||||||
|
|
||||||
nebu_view = 1000. - density; /* At density 1000 you're blind. */
|
nebu_view = 1000. - density; /* At density 1000 you're blind. */
|
||||||
nebu_dt = 2000. / (density + 100.); /* Faster at higher density. */
|
nebu_dt = 2000. / (density + 100.); /* Faster at higher density. */
|
||||||
|
|
||||||
|
nebu_npuffs = density/4.;
|
||||||
|
nebu_puffs = realloc(nebu_puffs, sizeof(NebulaePuff)*nebu_npuffs);
|
||||||
|
for(i = 0; i < nebu_npuffs; i++) {
|
||||||
|
nebu_puffs[i].tex = RNG(0, NEBULAE_PUFFS-1);
|
||||||
|
nebu_puffs[i].x = (double)RNG(-NEBULAE_PUFF_BUFFER,
|
||||||
|
SCREEN_W + NEBULAE_PUFF_BUFFER);
|
||||||
|
nebu_puffs[i].y = (double)RNG(-NEBULAE_PUFF_BUFFER,
|
||||||
|
SCREEN_H + NEBULAE_PUFF_BUFFER);
|
||||||
|
nebu_puffs[i].a = (double)RNG(20,100)/100.;
|
||||||
|
nebu_puffs[i].height = RNGF()*2.;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Force generation of new nebulae. */
|
/* Force generation of new nebulae. */
|
||||||
@ -419,15 +447,8 @@ static void nebu_generatePuffs(void) {
|
|||||||
sur = nebu_surfaceFromNebulaeMap(nebu, w, h);
|
sur = nebu_surfaceFromNebulaeMap(nebu, w, h);
|
||||||
free(nebu);
|
free(nebu);
|
||||||
|
|
||||||
/* Set dimensions. */
|
/* Load the textures. */
|
||||||
nebu_pufftexs[i].w = w;
|
nebu_pufftexs[i] = gl_loadImage(sur);
|
||||||
nebu_pufftexs[i].h = h;
|
|
||||||
nebu_pufftexs[i].pw = gl_pot(w);
|
|
||||||
nebu_pufftexs[i].ph = gl_pot(h);
|
|
||||||
|
|
||||||
/* Actually create the texture. */
|
|
||||||
glGenTextures(1, &nebu_pufftexs[i].tex);
|
|
||||||
nebu_loadTexture(sur, 0, 0, nebu_pufftexs[i].tex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,12 +466,14 @@ static void saveNebulae(float* map, const uint32_t w, const uint32_t h,
|
|||||||
char file_path[PATH_MAX];
|
char file_path[PATH_MAX];
|
||||||
SDL_Surface* sur;
|
SDL_Surface* sur;
|
||||||
|
|
||||||
|
/* Fix surface. */
|
||||||
sur = nebu_surfaceFromNebulaeMap(map, w, h);
|
sur = nebu_surfaceFromNebulaeMap(map, w, h);
|
||||||
|
|
||||||
|
/* Save. */
|
||||||
snprintf(file_path, PATH_MAX, "%s%s", lfile_basePath(), file);
|
snprintf(file_path, PATH_MAX, "%s%s", lfile_basePath(), file);
|
||||||
|
|
||||||
SDL_savePNG(sur, file_path);
|
SDL_savePNG(sur, file_path);
|
||||||
|
|
||||||
|
/* Cleanup. */
|
||||||
SDL_FreeSurface(sur);
|
SDL_FreeSurface(sur);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,6 +482,7 @@ static SDL_Surface* loadNebulae(const char* file) {
|
|||||||
char file_path[PATH_MAX];
|
char file_path[PATH_MAX];
|
||||||
SDL_Surface* sur;
|
SDL_Surface* sur;
|
||||||
|
|
||||||
|
/* Load the file. */
|
||||||
snprintf(file_path, PATH_MAX, "%s%s", lfile_basePath(), file);
|
snprintf(file_path, PATH_MAX, "%s%s", lfile_basePath(), file);
|
||||||
|
|
||||||
sur = IMG_Load(file_path);
|
sur = IMG_Load(file_path);
|
||||||
@ -477,6 +501,7 @@ SDL_Surface* nebu_surfaceFromNebulaeMap(float* map, const int w, const int h) {
|
|||||||
uint32_t* pix;
|
uint32_t* pix;
|
||||||
double c;
|
double c;
|
||||||
|
|
||||||
|
/* The good surface. */
|
||||||
sur = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RGBAMASK);
|
sur = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RGBAMASK);
|
||||||
pix = sur->pixels;
|
pix = sur->pixels;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ void nebu_init(void);
|
|||||||
void nebu_exit(void);
|
void nebu_exit(void);
|
||||||
|
|
||||||
/* Render. */
|
/* Render. */
|
||||||
void nebu_render(void);
|
void nebu_render(const double dt);
|
||||||
void nebu_renderOverlay(const double dt);
|
void nebu_renderOverlay(const double dt);
|
||||||
void nebu_renderPuffs(const double dt, int below_player);
|
void nebu_renderPuffs(const double dt, int below_player);
|
||||||
|
|
||||||
|
11
src/player.c
11
src/player.c
@ -567,6 +567,12 @@ void player_renderBG(void) {
|
|||||||
|
|
||||||
/* Render the player. */
|
/* Render the player. */
|
||||||
void player_render(void) {
|
void player_render(void) {
|
||||||
|
if((player != NULL) && !player_isFlag(PLAYER_CREATING))
|
||||||
|
pilot_render(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Render the player's GUI. */
|
||||||
|
void player_renderGUI(void) {
|
||||||
int i, j;
|
int i, j;
|
||||||
double x, y;
|
double x, y;
|
||||||
char str[10];
|
char str[10];
|
||||||
@ -585,9 +591,6 @@ void player_render(void) {
|
|||||||
menu_death();
|
menu_death();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!player_isFlag(PLAYER_CREATING))
|
|
||||||
pilot_render(player);
|
|
||||||
|
|
||||||
/* Fancy cinematic scene borders. */
|
/* Fancy cinematic scene borders. */
|
||||||
spfx_cinematic();
|
spfx_cinematic();
|
||||||
|
|
||||||
@ -619,8 +622,6 @@ void player_render(void) {
|
|||||||
x -= p->ship->gfx_space->sw * PILOT_SIZE_APROX;
|
x -= p->ship->gfx_space->sw * PILOT_SIZE_APROX;
|
||||||
gl_blitSprite(gui.gfx_targetPilot, x, y, 0, 1, c); /* Bottom left. */
|
gl_blitSprite(gui.gfx_targetPilot, x, y, 0, 1, c); /* Bottom left. */
|
||||||
}
|
}
|
||||||
/* Render the player. */
|
|
||||||
pilot_render(player);
|
|
||||||
|
|
||||||
/* Lockon warning. */
|
/* Lockon warning. */
|
||||||
if(player->lockons > 0)
|
if(player->lockons > 0)
|
||||||
|
@ -40,7 +40,8 @@ int gui_load(const char* name);
|
|||||||
int gui_init(void);
|
int gui_init(void);
|
||||||
void gui_free(void);
|
void gui_free(void);
|
||||||
void player_render(void);
|
void player_render(void);
|
||||||
void player_renderBG(void); /* Render BG layer. */
|
void player_renderBG(void); /* Render BG layer. */
|
||||||
|
void player_renderGUI(void); /* Render the GUI stuff. */
|
||||||
|
|
||||||
/* Misc. */
|
/* Misc. */
|
||||||
void player_message(const char* fmt, ...);
|
void player_message(const char* fmt, ...);
|
||||||
|
@ -809,7 +809,7 @@ void space_render(const double dt) {
|
|||||||
if(cur_system == NULL) return;
|
if(cur_system == NULL) return;
|
||||||
|
|
||||||
if(cur_system->nebu_density > 0.)
|
if(cur_system->nebu_density > 0.)
|
||||||
nebu_render();
|
nebu_render(dt);
|
||||||
else
|
else
|
||||||
space_renderStars(dt);
|
space_renderStars(dt);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user