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