2017-04-07 14:20:45 +02:00
|
|
|
/*
|
|
|
|
* This software is licensed under the terms of the MIT-License
|
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
2019-07-03 20:00:56 +02:00
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
2017-04-07 14:20:45 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "stagedraw.h"
|
|
|
|
#include "stagetext.h"
|
|
|
|
#include "video.h"
|
2018-04-12 16:08:48 +02:00
|
|
|
#include "resource/postprocess.h"
|
2018-04-13 21:13:48 +02:00
|
|
|
#include "entity.h"
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2017-12-11 19:56:46 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define GRAPHS_DEFAULT 1
|
2019-02-22 00:56:03 +01:00
|
|
|
#define OBJPOOLSTATS_DEFAULT 0
|
2017-12-11 19:56:46 +01:00
|
|
|
#else
|
|
|
|
#define GRAPHS_DEFAULT 0
|
2017-12-13 20:05:12 +01:00
|
|
|
#define OBJPOOLSTATS_DEFAULT 0
|
2017-12-11 19:56:46 +01:00
|
|
|
#endif
|
|
|
|
|
2018-08-11 21:13:48 +02:00
|
|
|
typedef struct CustomFramebuffer {
|
|
|
|
LIST_INTERFACE(struct CustomFramebuffer);
|
2018-09-14 09:37:20 +02:00
|
|
|
Framebuffer *fb;
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
struct {
|
|
|
|
float worst, best;
|
|
|
|
} scale;
|
|
|
|
|
2018-08-11 21:13:48 +02:00
|
|
|
StageFBPair scaling_base;
|
|
|
|
} CustomFramebuffer;
|
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
static struct {
|
|
|
|
struct {
|
2018-04-12 16:08:48 +02:00
|
|
|
ShaderProgram *shader;
|
2018-06-29 23:36:51 +02:00
|
|
|
Font *font;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
Color active;
|
|
|
|
Color inactive;
|
2019-02-22 00:56:03 +01:00
|
|
|
Color dark;
|
2018-06-29 23:36:51 +02:00
|
|
|
Color label;
|
2019-01-04 23:59:39 +01:00
|
|
|
Color label_power;
|
|
|
|
Color label_value;
|
|
|
|
Color label_graze;
|
2019-02-22 00:56:03 +01:00
|
|
|
Color label_voltage;
|
2018-06-29 23:36:51 +02:00
|
|
|
} color;
|
2017-11-23 03:25:53 +01:00
|
|
|
} hud_text;
|
2018-06-29 23:36:51 +02:00
|
|
|
|
2018-08-16 21:52:41 +02:00
|
|
|
struct {
|
|
|
|
ShaderProgram *fxaa;
|
|
|
|
ShaderProgram *copy_depth;
|
|
|
|
} shaders;
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
struct {
|
|
|
|
float alpha;
|
|
|
|
float target_alpha;
|
|
|
|
} clear_screen;
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
PostprocessShader *viewport_pp;
|
|
|
|
FBPair fb_pairs[NUM_FBPAIRS];
|
2019-02-22 00:56:03 +01:00
|
|
|
FBPair powersurge_fbpair;
|
2018-08-11 21:13:48 +02:00
|
|
|
CustomFramebuffer *custom_fbs;
|
2018-07-04 10:36:16 +02:00
|
|
|
|
2017-12-11 19:56:46 +01:00
|
|
|
bool framerate_graphs;
|
2017-12-13 20:05:12 +01:00
|
|
|
bool objpool_stats;
|
2018-05-08 15:02:08 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
Sprite dummy;
|
|
|
|
#endif
|
2018-06-29 23:36:51 +02:00
|
|
|
} stagedraw = {
|
|
|
|
.hud_text.color = {
|
2018-07-23 19:07:59 +02:00
|
|
|
// NOTE: premultiplied alpha
|
2019-02-22 00:56:03 +01:00
|
|
|
.active = { 1.00, 1.00, 1.00, 1.00 },
|
|
|
|
.inactive = { 0.50, 0.50, 0.50, 0.70 },
|
|
|
|
.dark = { 0.30, 0.30, 0.30, 0.70 },
|
|
|
|
.label = { 1.00, 1.00, 1.00, 1.00 },
|
|
|
|
.label_power = { 1.00, 0.50, 0.50, 1.00 },
|
|
|
|
.label_value = { 0.30, 0.60, 1.00, 1.00 },
|
|
|
|
.label_graze = { 0.50, 1.00, 0.50, 1.00 },
|
|
|
|
.label_voltage = { 0.80, 0.50, 1.00, 1.00 },
|
2018-06-29 23:36:51 +02:00
|
|
|
}
|
|
|
|
};
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
static double fb_scale(void) {
|
2019-04-04 01:43:03 +02:00
|
|
|
float vp_width, vp_height;
|
2018-07-04 10:36:16 +02:00
|
|
|
video_get_viewport_size(&vp_width, &vp_height);
|
|
|
|
return (double)vp_height / SCREEN_H;
|
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
static void set_fb_size(StageFBPair fb_id, int *w, int *h, float scale_worst, float scale_best) {
|
2018-07-04 10:36:16 +02:00
|
|
|
double scale = fb_scale();
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(fb_id == FBPAIR_FG_AUX || fb_id == FBPAIR_BG_AUX) {
|
2019-01-04 23:59:39 +01:00
|
|
|
scale_worst *= 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pp_qual = config_get_int(CONFIG_POSTPROCESS);
|
|
|
|
|
|
|
|
// We might lerp between these in the future
|
|
|
|
if(pp_qual < 2) {
|
|
|
|
scale *= scale_worst;
|
|
|
|
} else {
|
|
|
|
scale *= scale_best;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_debug("%u %f %f %f %i", fb_id, scale, scale_worst, scale_best, pp_qual);
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
switch(fb_id) {
|
|
|
|
case FBPAIR_BG:
|
|
|
|
scale *= config_get_float(CONFIG_BG_QUALITY);
|
2019-01-04 23:59:39 +01:00
|
|
|
// fallthrough
|
2018-07-04 10:36:16 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
scale *= config_get_float(CONFIG_FG_QUALITY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
scale = sanitize_scale(scale);
|
|
|
|
*w = round(VIEWPORT_W * scale);
|
|
|
|
*h = round(VIEWPORT_H * scale);
|
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
static inline void set_custom_fb_size(CustomFramebuffer *cfb, int *w, int *h) {
|
|
|
|
set_fb_size(cfb->scaling_base, w, h, cfb->scale.worst, cfb->scale.best);
|
|
|
|
}
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
static void update_fb_size(StageFBPair fb_id) {
|
|
|
|
int w, h;
|
2019-01-04 23:59:39 +01:00
|
|
|
set_fb_size(fb_id, &w, &h, 1, 1);
|
2018-07-04 10:36:16 +02:00
|
|
|
fbpair_resize_all(stagedraw.fb_pairs + fb_id, w, h);
|
|
|
|
fbpair_viewport(stagedraw.fb_pairs + fb_id, 0, 0, w, h);
|
2018-08-11 21:13:48 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(fb_id != FBPAIR_FG_AUX && fb_id != FBPAIR_BG_AUX) {
|
2018-08-11 21:13:48 +02:00
|
|
|
for(CustomFramebuffer *cfb = stagedraw.custom_fbs; cfb; cfb = cfb->next) {
|
|
|
|
if(cfb->scaling_base == fb_id) {
|
2019-01-04 23:59:39 +01:00
|
|
|
set_custom_fb_size(cfb, &w, &h);
|
2018-08-11 21:13:48 +02:00
|
|
|
|
|
|
|
for(uint i = 0; i < FRAMEBUFFER_MAX_ATTACHMENTS; ++i) {
|
2019-01-04 23:59:39 +01:00
|
|
|
fbutil_resize_attachment(cfb->fb, i, w, h);
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
r_framebuffer_viewport(cfb->fb, 0, 0, w, h);
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-04 10:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool stage_draw_event(SDL_Event *e, void *arg) {
|
|
|
|
if(!IS_TAISEI_EVENT(e->type)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(TAISEI_EVENT(e->type)) {
|
|
|
|
case TE_VIDEO_MODE_CHANGED: {
|
|
|
|
for(uint i = 0; i < NUM_FBPAIRS; ++i) {
|
|
|
|
update_fb_size(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TE_CONFIG_UPDATED: {
|
|
|
|
switch(e->user.code) {
|
2019-01-04 23:59:39 +01:00
|
|
|
case CONFIG_POSTPROCESS:
|
|
|
|
case CONFIG_BG_QUALITY:
|
|
|
|
update_fb_size(FBPAIR_BG);
|
2019-02-22 00:56:03 +01:00
|
|
|
update_fb_size(FBPAIR_BG_AUX);
|
2019-01-04 23:59:39 +01:00
|
|
|
// fallthrough
|
|
|
|
|
|
|
|
case CONFIG_FG_QUALITY:
|
2018-07-04 10:36:16 +02:00
|
|
|
update_fb_size(FBPAIR_FG);
|
|
|
|
update_fb_size(FBPAIR_FG_AUX);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-04-11 11:23:24 +02:00
|
|
|
|
|
|
|
case TE_FRAME: {
|
|
|
|
fapproach_p(&stagedraw.clear_screen.alpha, stagedraw.clear_screen.target_alpha, 0.01);
|
|
|
|
break;
|
|
|
|
}
|
2018-07-04 10:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stage_draw_setup_framebuffers(void) {
|
2019-02-22 00:56:03 +01:00
|
|
|
int fg_width, fg_height;
|
|
|
|
int bg_width, bg_height;
|
|
|
|
int fga_width, fga_height;
|
|
|
|
int bga_width, bga_height;
|
2018-07-04 10:36:16 +02:00
|
|
|
FBAttachmentConfig a[2], *a_color, *a_depth;
|
|
|
|
memset(a, 0, sizeof(a));
|
|
|
|
|
|
|
|
a_color = &a[0];
|
|
|
|
a_depth = &a[1];
|
|
|
|
|
|
|
|
a_color->attachment = FRAMEBUFFER_ATTACH_COLOR0;
|
|
|
|
a_depth->attachment = FRAMEBUFFER_ATTACH_DEPTH;
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
set_fb_size(FBPAIR_FG, &fg_width, &fg_height, 1, 1);
|
|
|
|
set_fb_size(FBPAIR_FG_AUX, &fga_width, &fga_height, 1, 1);
|
|
|
|
set_fb_size(FBPAIR_BG, &bg_width, &bg_height, 1, 1);
|
2019-02-22 00:56:03 +01:00
|
|
|
set_fb_size(FBPAIR_BG_AUX, &bga_width, &bga_height, 1, 1);
|
2018-07-04 10:36:16 +02:00
|
|
|
|
|
|
|
// Set up some parameters shared by all attachments
|
|
|
|
TextureParams tex_common = {
|
2018-07-10 11:14:29 +02:00
|
|
|
.filter.min = TEX_FILTER_LINEAR,
|
|
|
|
.filter.mag = TEX_FILTER_LINEAR,
|
2018-07-04 10:36:16 +02:00
|
|
|
.wrap.s = TEX_WRAP_MIRROR,
|
|
|
|
.wrap.t = TEX_WRAP_MIRROR,
|
|
|
|
};
|
|
|
|
|
|
|
|
memcpy(&a_color->tex_params, &tex_common, sizeof(tex_common));
|
|
|
|
memcpy(&a_depth->tex_params, &tex_common, sizeof(tex_common));
|
|
|
|
|
|
|
|
// Foreground: 1 RGB texture per FB
|
2019-01-04 23:59:39 +01:00
|
|
|
a_color->tex_params.type = TEX_TYPE_RGB_16;
|
2018-07-04 10:36:16 +02:00
|
|
|
a_color->tex_params.width = fg_width;
|
|
|
|
a_color->tex_params.height = fg_height;
|
2019-02-22 00:56:03 +01:00
|
|
|
fbpair_create(stagedraw.fb_pairs + FBPAIR_FG, 1, a, "Stage FG");
|
2018-07-04 10:36:16 +02:00
|
|
|
fbpair_viewport(stagedraw.fb_pairs + FBPAIR_FG, 0, 0, fg_width, fg_height);
|
|
|
|
|
|
|
|
// Foreground auxiliary: 1 RGBA texture per FB
|
|
|
|
a_color->tex_params.type = TEX_TYPE_RGBA;
|
2019-01-04 23:59:39 +01:00
|
|
|
a_color->tex_params.width = fga_width;
|
|
|
|
a_color->tex_params.height = fga_height;
|
2019-02-22 00:56:03 +01:00
|
|
|
fbpair_create(stagedraw.fb_pairs + FBPAIR_FG_AUX, 1, a, "Stage FG AUX");
|
2019-01-04 23:59:39 +01:00
|
|
|
fbpair_viewport(stagedraw.fb_pairs + FBPAIR_FG_AUX, 0, 0, fga_width, fga_height);
|
2018-07-04 10:36:16 +02:00
|
|
|
|
|
|
|
// Background: 1 RGB texture + depth per FB
|
|
|
|
a_color->tex_params.type = TEX_TYPE_RGB;
|
|
|
|
a_color->tex_params.width = bg_width;
|
|
|
|
a_color->tex_params.height = bg_height;
|
|
|
|
a_depth->tex_params.type = TEX_TYPE_DEPTH;
|
|
|
|
a_depth->tex_params.width = bg_width;
|
|
|
|
a_depth->tex_params.height = bg_height;
|
2019-02-22 00:56:03 +01:00
|
|
|
fbpair_create(stagedraw.fb_pairs + FBPAIR_BG, 2, a, "Stage BG");
|
2018-07-04 10:36:16 +02:00
|
|
|
fbpair_viewport(stagedraw.fb_pairs + FBPAIR_BG, 0, 0, bg_width, bg_height);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
// Background auxiliary: 1 RGBA texture per FB
|
|
|
|
a_color->tex_params.type = TEX_TYPE_RGBA_8;
|
|
|
|
a_color->tex_params.width = bga_width;
|
|
|
|
a_color->tex_params.height = bga_height;
|
|
|
|
fbpair_create(stagedraw.fb_pairs + FBPAIR_BG_AUX, 1, a, "Stage BG AUX");
|
|
|
|
fbpair_viewport(stagedraw.fb_pairs + FBPAIR_BG_AUX, 0, 0, bga_width, bga_height);
|
|
|
|
|
|
|
|
// CAUTION: should be at least 16-bit, lest the feedback shader do an oopsie!
|
|
|
|
a_color->tex_params.type = TEX_TYPE_RGBA_16;
|
|
|
|
stagedraw.powersurge_fbpair.front = stage_add_background_framebuffer("Powersurge effect FB 1", 0.125, 0.25, 1, a);
|
|
|
|
stagedraw.powersurge_fbpair.back = stage_add_background_framebuffer("Powersurge effect FB 2", 0.125, 0.25, 1, a);
|
2018-07-04 10:36:16 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
static Framebuffer* add_custom_framebuffer(const char *label, StageFBPair fbtype, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
2018-08-11 21:13:48 +02:00
|
|
|
CustomFramebuffer *cfb = calloc(1, sizeof(*cfb));
|
|
|
|
list_push(&stagedraw.custom_fbs, cfb);
|
|
|
|
|
|
|
|
FBAttachmentConfig cfg[num_attachments];
|
|
|
|
memcpy(cfg, attachments, sizeof(cfg));
|
|
|
|
|
|
|
|
int width, height;
|
2019-01-04 23:59:39 +01:00
|
|
|
cfb->scale.worst = scale_worst;
|
|
|
|
cfb->scale.best = scale_best;
|
|
|
|
cfb->scaling_base = fbtype;
|
|
|
|
set_custom_fb_size(cfb, &width, &height);
|
2018-08-11 21:13:48 +02:00
|
|
|
|
|
|
|
for(uint i = 0; i < num_attachments; ++i) {
|
|
|
|
cfg[i].tex_params.width = width;
|
|
|
|
cfg[i].tex_params.height = height;
|
|
|
|
}
|
|
|
|
|
2018-09-14 09:37:20 +02:00
|
|
|
cfb->fb = r_framebuffer_create();
|
2019-02-22 00:56:03 +01:00
|
|
|
r_framebuffer_set_debug_label(cfb->fb, label);
|
2018-09-14 09:37:20 +02:00
|
|
|
fbutil_create_attachments(cfb->fb, num_attachments, cfg);
|
|
|
|
r_framebuffer_viewport(cfb->fb, 0, 0, width, height);
|
|
|
|
r_framebuffer_clear(cfb->fb, CLEAR_ALL, RGBA(0, 0, 0, 0), 1);
|
2018-08-11 21:13:48 +02:00
|
|
|
|
2018-09-14 09:37:20 +02:00
|
|
|
return cfb->fb;
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
Framebuffer* stage_add_foreground_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
|
|
|
return add_custom_framebuffer(label, FBPAIR_FG, scale_worst, scale_best, num_attachments, attachments);
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
Framebuffer* stage_add_background_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
|
|
|
return add_custom_framebuffer(label, FBPAIR_BG, scale_worst, scale_best, num_attachments, attachments);
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void stage_draw_destroy_framebuffers(void) {
|
|
|
|
for(uint i = 0; i < NUM_FBPAIRS; ++i) {
|
|
|
|
fbpair_destroy(stagedraw.fb_pairs + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(CustomFramebuffer *cfb = stagedraw.custom_fbs, *next; cfb; cfb = next) {
|
|
|
|
next = cfb->next;
|
2018-09-14 09:37:20 +02:00
|
|
|
fbutil_destroy_attachments(cfb->fb);
|
|
|
|
r_framebuffer_destroy(cfb->fb);
|
2018-08-11 21:13:48 +02:00
|
|
|
free(list_unlink(&stagedraw.custom_fbs, cfb));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
void stage_draw_init(void) {
|
2018-04-12 16:08:48 +02:00
|
|
|
preload_resources(RES_POSTPROCESS, RESF_OPTIONAL,
|
|
|
|
"viewport",
|
|
|
|
NULL);
|
|
|
|
|
2018-02-06 07:19:25 +01:00
|
|
|
preload_resources(RES_SPRITE, RESF_PERMANENT,
|
2019-01-04 23:59:39 +01:00
|
|
|
"hud/heart",
|
|
|
|
"hud/star",
|
2017-11-23 03:25:53 +01:00
|
|
|
"star",
|
2018-02-06 07:19:25 +01:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
preload_resources(RES_TEXTURE, RESF_PERMANENT,
|
2019-02-22 00:56:03 +01:00
|
|
|
"powersurge_flow",
|
2017-11-23 03:25:53 +01:00
|
|
|
"titletransition",
|
2019-01-23 15:02:51 +01:00
|
|
|
"hud",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
preload_resources(RES_MODEL, RESF_PERMANENT,
|
|
|
|
"hud",
|
2017-11-23 03:25:53 +01:00
|
|
|
NULL);
|
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
preload_resources(RES_SHADER_PROGRAM, RESF_PERMANENT,
|
2019-02-22 00:56:03 +01:00
|
|
|
"copy_depth",
|
2017-11-23 03:25:53 +01:00
|
|
|
"ingame_menu",
|
2019-02-22 00:56:03 +01:00
|
|
|
"powersurge_effect",
|
|
|
|
"powersurge_feedback",
|
2018-04-12 16:08:48 +02:00
|
|
|
"sprite_circleclipped_indicator",
|
2019-02-22 00:56:03 +01:00
|
|
|
"text_hud",
|
|
|
|
"text_stagetext",
|
2018-08-16 21:52:41 +02:00
|
|
|
|
|
|
|
// TODO: Maybe don't preload this if FXAA is disabled.
|
|
|
|
// But then we also have to handle the edge case of it being enabled later mid-game.
|
|
|
|
"fxaa",
|
|
|
|
|
2018-05-08 15:02:08 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
"sprite_filled_circle",
|
|
|
|
#endif
|
2017-11-23 03:25:53 +01:00
|
|
|
NULL);
|
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
preload_resources(RES_FONT, RESF_PERMANENT,
|
|
|
|
"mono",
|
|
|
|
"small",
|
|
|
|
"monosmall",
|
|
|
|
NULL);
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2018-04-18 00:34:41 +02:00
|
|
|
stagedraw.framerate_graphs = env_get("TAISEI_FRAMERATE_GRAPHS", GRAPHS_DEFAULT);
|
|
|
|
stagedraw.objpool_stats = env_get("TAISEI_OBJPOOL_STATS", OBJPOOLSTATS_DEFAULT);
|
2017-12-14 16:07:24 +01:00
|
|
|
|
|
|
|
if(stagedraw.framerate_graphs) {
|
2018-04-12 16:08:48 +02:00
|
|
|
preload_resources(RES_SHADER_PROGRAM, RESF_PERMANENT,
|
2017-12-14 16:07:24 +01:00
|
|
|
"graph",
|
|
|
|
NULL);
|
|
|
|
}
|
2018-04-12 16:08:48 +02:00
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
if(stagedraw.objpool_stats) {
|
|
|
|
preload_resources(RES_FONT, RESF_PERMANENT,
|
|
|
|
"monotiny",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
stagedraw.viewport_pp = get_resource_data(RES_POSTPROCESS, "viewport", RESF_OPTIONAL);
|
2018-06-29 23:36:51 +02:00
|
|
|
stagedraw.hud_text.shader = r_shader_get("text_hud");
|
2019-01-04 23:59:39 +01:00
|
|
|
stagedraw.hud_text.font = get_font("standard");
|
2018-08-16 21:52:41 +02:00
|
|
|
stagedraw.shaders.fxaa = r_shader_get("fxaa");
|
|
|
|
stagedraw.shaders.copy_depth = r_shader_get("copy_depth");
|
2018-06-29 23:36:51 +02:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_shader_standard();
|
2018-05-08 15:02:08 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
stagedraw.dummy.tex = get_sprite("star")->tex;
|
|
|
|
stagedraw.dummy.w = 1;
|
|
|
|
stagedraw.dummy.h = 1;
|
|
|
|
#endif
|
2018-07-04 10:36:16 +02:00
|
|
|
|
|
|
|
stage_draw_setup_framebuffers();
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
stagedraw.clear_screen.alpha = 0;
|
|
|
|
stagedraw.clear_screen.target_alpha = 0;
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
events_register_handler(&(EventHandler) {
|
|
|
|
stage_draw_event, NULL, EPRIO_SYSTEM,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void stage_draw_shutdown(void) {
|
|
|
|
events_unregister_handler(stage_draw_event);
|
2018-08-11 21:13:48 +02:00
|
|
|
stage_draw_destroy_framebuffers();
|
2018-07-04 10:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FBPair* stage_get_fbpair(StageFBPair id) {
|
|
|
|
assert(id >= 0 && id < NUM_FBPAIRS);
|
|
|
|
return stagedraw.fb_pairs + id;
|
2018-05-08 15:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void stage_draw_collision_areas(void) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
static bool enabled, keystate_saved;
|
|
|
|
bool keystate = gamekeypressed(KEY_HITAREAS);
|
|
|
|
|
|
|
|
if(keystate ^ keystate_saved) {
|
|
|
|
if(keystate) {
|
|
|
|
enabled = !enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
keystate_saved = keystate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_shader("sprite_filled_circle");
|
|
|
|
r_uniform_vec4("color_inner", 0, 0, 0, 1);
|
2018-05-13 15:08:58 +02:00
|
|
|
r_uniform_vec4("color_outer", 1, 1, 1, 0.1);
|
2018-05-08 15:02:08 +02:00
|
|
|
|
2018-06-01 20:40:18 +02:00
|
|
|
for(Projectile *p = global.projs.first; p; p = p->next) {
|
2018-05-13 15:08:58 +02:00
|
|
|
complex gsize = projectile_graze_size(p);
|
|
|
|
|
|
|
|
if(creal(gsize)) {
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = RGB(0, 0.5, 0.5),
|
2018-05-13 15:08:58 +02:00
|
|
|
.sprite_ptr = &stagedraw.dummy,
|
|
|
|
.pos = { creal(p->pos), cimag(p->pos) },
|
|
|
|
.rotation.angle = p->angle + M_PI/2,
|
|
|
|
.scale = { .x = creal(gsize), .y = cimag(gsize) },
|
|
|
|
.blend = BLEND_SUB,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r_flush_sprites();
|
|
|
|
r_uniform_vec4("color_inner", 0.0, 1.0, 0.0, 0.75);
|
|
|
|
r_uniform_vec4("color_outer", 0.0, 0.5, 0.5, 0.75);
|
2018-05-08 15:02:08 +02:00
|
|
|
|
2018-06-01 20:40:18 +02:00
|
|
|
for(Projectile *p = global.projs.first; p; p = p->next) {
|
2018-05-08 15:02:08 +02:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = &stagedraw.dummy,
|
|
|
|
.pos = { creal(p->pos), cimag(p->pos) },
|
|
|
|
.rotation.angle = p->angle + M_PI/2,
|
2018-05-13 15:08:58 +02:00
|
|
|
.scale = { .x = creal(p->collision_size), .y = cimag(p->collision_size) },
|
|
|
|
.blend = BLEND_ALPHA,
|
2018-05-08 15:02:08 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:10:49 +01:00
|
|
|
for(Enemy *e = global.enemies.first; e; e = e->next) {
|
|
|
|
if(e->hp > ENEMY_IMMUNE && e->alpha >= 1.0) {
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = &stagedraw.dummy,
|
|
|
|
.pos = { creal(e->pos), cimag(e->pos) },
|
|
|
|
.scale = { .x = ENEMY_HURT_RADIUS * 2, .y = ENEMY_HURT_RADIUS * 2 },
|
|
|
|
.blend = BLEND_ALPHA,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
if(global.boss && global.boss->current && !dialog_is_active(global.dialog)) {
|
2019-03-01 17:10:49 +01:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = &stagedraw.dummy,
|
|
|
|
.pos = { creal(global.boss->pos), cimag(global.boss->pos) },
|
|
|
|
.scale = { .x = BOSS_HURT_RADIUS * 2, .y = BOSS_HURT_RADIUS * 2 },
|
|
|
|
.blend = BLEND_ALPHA,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-13 15:08:58 +02:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = &stagedraw.dummy,
|
|
|
|
.pos = { creal(global.plr.pos), cimag(global.plr.pos) },
|
|
|
|
.scale.both = 2, // NOTE: actual player is a singular point
|
|
|
|
});
|
|
|
|
|
2019-03-01 17:10:49 +01:00
|
|
|
// TODO: perhaps handle lasers somehow
|
2018-05-08 15:02:08 +02:00
|
|
|
|
|
|
|
r_flush_sprites();
|
|
|
|
#endif
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
static void apply_shader_rules(ShaderRule *shaderrules, FBPair *fbos) {
|
2017-10-01 10:58:45 +02:00
|
|
|
if(!shaderrules) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
for(ShaderRule *rule = shaderrules; *rule; ++rule) {
|
2018-07-04 10:36:16 +02:00
|
|
|
r_framebuffer(fbos->back);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
if((*rule)(fbos->front)) {
|
|
|
|
fbpair_swap(fbos);
|
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2017-10-01 10:58:45 +02:00
|
|
|
return;
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_wall_of_text(float f, const char *txt) {
|
2018-02-06 07:19:25 +01:00
|
|
|
Sprite spr;
|
2018-06-29 23:36:51 +02:00
|
|
|
BBox bbox;
|
|
|
|
|
2018-08-28 10:25:54 +02:00
|
|
|
char buf[strlen(txt) + 4];
|
|
|
|
memcpy(buf, txt, sizeof(buf) - 4);
|
|
|
|
memcpy(buf + sizeof(buf) - 4, " ~ ", 4);
|
|
|
|
|
|
|
|
text_render(buf, get_font("standard"), &spr, &bbox);
|
2018-06-29 23:36:51 +02:00
|
|
|
|
|
|
|
// FIXME: The shader currently assumes that the sprite takes up the entire texture.
|
2019-02-22 00:56:03 +01:00
|
|
|
// If it could handle any arbitrary sprite, then text_render wouldn't have to resize
|
|
|
|
// the texture per every new string of text.
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2017-04-14 10:42:09 +02:00
|
|
|
float w = VIEWPORT_W;
|
|
|
|
float h = VIEWPORT_H;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_push();
|
|
|
|
r_mat_translate(w/2, h/2, 0);
|
|
|
|
r_mat_scale(w, h, 1.0);
|
|
|
|
|
2018-09-14 09:37:20 +02:00
|
|
|
uint tw, th;
|
|
|
|
r_texture_get_size(spr.tex, 0, &tw, &th);
|
|
|
|
|
|
|
|
r_shader("spellcard_walloftext");
|
|
|
|
r_uniform_float("w", spr.tex_area.w / tw);
|
|
|
|
r_uniform_float("h", spr.tex_area.h / th);
|
2018-04-12 16:08:48 +02:00
|
|
|
r_uniform_float("ratio", h/w);
|
2018-08-28 10:25:54 +02:00
|
|
|
r_uniform_vec2("origin", creal(global.boss->pos)/h, cimag(global.boss->pos)/w); // what the fuck?
|
2018-04-12 16:08:48 +02:00
|
|
|
r_uniform_float("t", f);
|
2018-09-14 09:37:20 +02:00
|
|
|
r_uniform_sampler("tex", spr.tex);
|
2018-04-12 16:08:48 +02:00
|
|
|
r_draw_quad();
|
|
|
|
r_shader_standard();
|
|
|
|
|
|
|
|
r_mat_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_spellbg(int t) {
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_push();
|
2017-04-07 14:20:45 +02:00
|
|
|
|
|
|
|
Boss *b = global.boss;
|
2019-02-22 00:56:03 +01:00
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
b->current->draw_rule(b, t);
|
|
|
|
|
2019-01-24 21:21:08 +01:00
|
|
|
if(b->current->type == AT_ExtraSpell) {
|
2017-04-07 14:20:45 +02:00
|
|
|
draw_extraspell_bg(b, t);
|
2019-01-24 21:21:08 +01:00
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_push();
|
|
|
|
r_mat_translate(creal(b->pos), cimag(b->pos), 0);
|
|
|
|
r_mat_rotate_deg(global.frames*7.0, 0, 0, -1);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
|
|
|
if(t < 0) {
|
|
|
|
float f = 1.0 - t/(float)ATTACK_START_DELAY;
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_scale(f,f,f);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2018-02-06 07:19:25 +01:00
|
|
|
draw_sprite(0, 0, "boss_spellcircle0");
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_mat_pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_spellbg_overlay(int t) {
|
|
|
|
Boss *b = global.boss;
|
|
|
|
|
2017-04-19 19:44:49 +02:00
|
|
|
float delay = ATTACK_START_DELAY;
|
2019-01-24 21:21:08 +01:00
|
|
|
|
|
|
|
if(b->current->type == AT_ExtraSpell) {
|
2017-04-19 19:44:49 +02:00
|
|
|
delay = ATTACK_START_DELAY_EXTRA;
|
2019-01-24 21:21:08 +01:00
|
|
|
}
|
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
float f = (ATTACK_START_DELAY - t) / (delay + ATTACK_START_DELAY);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
if(f > 0) {
|
|
|
|
draw_wall_of_text(f, b->current->name);
|
2019-01-24 21:21:08 +01:00
|
|
|
}
|
2018-04-12 16:08:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool should_draw_stage_bg(void) {
|
2019-01-25 01:52:00 +01:00
|
|
|
if(!global.boss || !global.boss->current)
|
2019-01-04 23:59:39 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
int render_delay = 1.25*ATTACK_START_DELAY; // hand tuned... not ideal
|
|
|
|
if(global.boss->current->type == AT_ExtraSpell)
|
|
|
|
render_delay = 0;
|
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
return (
|
|
|
|
!global.boss
|
|
|
|
|| !global.boss->current
|
|
|
|
|| !global.boss->current->draw_rule
|
|
|
|
|| global.boss->current->endtime
|
2019-01-04 23:59:39 +01:00
|
|
|
|| (global.frames - global.boss->current->starttime) < render_delay
|
2018-04-12 16:08:48 +02:00
|
|
|
);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
static bool fxaa_rule(Framebuffer *fb) {
|
2018-08-16 21:52:41 +02:00
|
|
|
r_state_push();
|
|
|
|
r_enable(RCAP_DEPTH_TEST);
|
|
|
|
r_depth_func(DEPTH_ALWAYS);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_blend(BLEND_NONE);
|
2018-08-16 21:52:41 +02:00
|
|
|
r_shader_ptr(stagedraw.shaders.fxaa);
|
2018-09-14 09:37:20 +02:00
|
|
|
r_uniform_sampler("depth", r_framebuffer_get_attachment(fb, FRAMEBUFFER_ATTACH_DEPTH));
|
2018-08-16 21:52:41 +02:00
|
|
|
draw_framebuffer_tex(fb, VIEWPORT_W, VIEWPORT_H);
|
|
|
|
r_state_pop();
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
return true;
|
2018-08-16 21:52:41 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
static bool copydepth_rule(Framebuffer *fb) {
|
2018-08-16 21:52:41 +02:00
|
|
|
r_state_push();
|
|
|
|
r_enable(RCAP_DEPTH_TEST);
|
|
|
|
r_depth_func(DEPTH_ALWAYS);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_blend(BLEND_NONE);
|
2018-08-16 21:52:41 +02:00
|
|
|
r_shader_ptr(stagedraw.shaders.copy_depth);
|
|
|
|
draw_framebuffer_attachment(fb, VIEWPORT_W, VIEWPORT_H, FRAMEBUFFER_ATTACH_DEPTH);
|
|
|
|
r_state_pop();
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool powersurge_draw_predicate(EntityInterface *ent) {
|
|
|
|
uint layer = ent->draw_layer & ~LAYER_LOW_MASK;
|
|
|
|
|
|
|
|
if(player_is_powersurge_active(&global.plr)) {
|
|
|
|
switch(layer) {
|
|
|
|
case LAYER_PLAYER_SLAVE:
|
|
|
|
case LAYER_PLAYER_SHOT:
|
2019-04-15 07:37:01 +02:00
|
|
|
case LAYER_PLAYER_SHOT_HIGH:
|
2019-02-22 00:56:03 +01:00
|
|
|
case LAYER_PLAYER_FOCUS:
|
|
|
|
case LAYER_PLAYER:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ent->type == ENT_PROJECTILE) {
|
|
|
|
Projectile *p = ENT_CAST(ent, Projectile);
|
|
|
|
return p->flags & PFLAG_PLRSPECIALPARTICLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ent->type == ENT_ITEM) {
|
|
|
|
Item *i = ENT_CAST(ent, Item);
|
|
|
|
return i->type == ITEM_VOLTAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool draw_powersurge_effect(Framebuffer *target_fb, BlendMode blend) {
|
|
|
|
r_state_push();
|
|
|
|
r_blend(BLEND_NONE);
|
|
|
|
r_disable(RCAP_DEPTH_TEST);
|
|
|
|
|
|
|
|
// if(player_is_powersurge_active(&global.plr)) {
|
|
|
|
r_state_push();
|
|
|
|
r_framebuffer(stagedraw.powersurge_fbpair.front);
|
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
|
|
|
r_shader("sprite_default");
|
|
|
|
ent_draw(powersurge_draw_predicate);
|
|
|
|
r_state_pop();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TODO: Add heuristic to not run the effect if the buffer can be reasonably assumed to be empty.
|
|
|
|
|
|
|
|
r_shader("powersurge_feedback");
|
|
|
|
r_uniform_vec2("blur_resolution", 0.5*VIEWPORT_W, 0.5*VIEWPORT_H);
|
|
|
|
|
|
|
|
r_framebuffer(stagedraw.powersurge_fbpair.back);
|
|
|
|
r_uniform_vec2("blur_direction", 1, 0);
|
|
|
|
r_uniform_vec4("fade", 1, 1, 1, 1);
|
|
|
|
draw_framebuffer_tex(stagedraw.powersurge_fbpair.front, VIEWPORT_W, VIEWPORT_H);
|
|
|
|
fbpair_swap(&stagedraw.powersurge_fbpair);
|
|
|
|
|
|
|
|
r_framebuffer(stagedraw.powersurge_fbpair.back);
|
|
|
|
r_uniform_vec2("blur_direction", 0, 1);
|
|
|
|
r_uniform_vec4("fade", 0.9, 0.9, 0.9, 0.9);
|
|
|
|
draw_framebuffer_tex(stagedraw.powersurge_fbpair.front, VIEWPORT_W, VIEWPORT_H);
|
|
|
|
|
|
|
|
r_framebuffer(target_fb);
|
|
|
|
r_shader("powersurge_effect");
|
|
|
|
r_uniform_sampler("shotlayer", r_framebuffer_get_attachment(stagedraw.powersurge_fbpair.back, FRAMEBUFFER_ATTACH_COLOR0));
|
|
|
|
r_uniform_sampler("flowlayer", "powersurge_flow");
|
|
|
|
r_uniform_float("time", global.frames/60.0);
|
|
|
|
r_blend(blend);
|
|
|
|
r_cull(CULL_BACK);
|
|
|
|
r_mat_push();
|
|
|
|
r_mat_scale(VIEWPORT_W, VIEWPORT_H, 1);
|
|
|
|
r_mat_translate(0.5, 0.5, 0);
|
|
|
|
r_draw_quad();
|
|
|
|
r_mat_pop();
|
|
|
|
fbpair_swap(&stagedraw.powersurge_fbpair);
|
|
|
|
|
|
|
|
r_state_pop();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool boss_distortion_rule(Framebuffer *fb) {
|
|
|
|
if(global.boss == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_state_push();
|
|
|
|
r_blend(BLEND_NONE);
|
|
|
|
r_disable(RCAP_DEPTH_TEST);
|
|
|
|
|
|
|
|
complex fpos = global.boss->pos;
|
|
|
|
complex pos = fpos + 15*cexp(I*global.frames/4.5);
|
|
|
|
|
|
|
|
r_shader("boss_zoom");
|
|
|
|
r_uniform_vec2("blur_orig", creal(pos) / VIEWPORT_W, 1-cimag(pos) / VIEWPORT_H);
|
|
|
|
r_uniform_vec2("fix_orig", creal(fpos) / VIEWPORT_W, 1-cimag(fpos) / VIEWPORT_H);
|
|
|
|
r_uniform_float("blur_rad", 1.5*(0.2+0.025*sin(global.frames/15.0)));
|
|
|
|
r_uniform_float("rad", 0.24);
|
|
|
|
r_uniform_float("ratio", (float)VIEWPORT_H/VIEWPORT_W);
|
|
|
|
r_uniform_vec4_rgba("color", &global.boss->zoomcolor);
|
|
|
|
draw_framebuffer_tex(fb, VIEWPORT_W, VIEWPORT_H);
|
|
|
|
|
|
|
|
r_state_pop();
|
|
|
|
|
|
|
|
return true;
|
2018-08-16 21:52:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void finish_3d_scene(FBPair *fbpair) {
|
|
|
|
// Here we synchronize the depth buffers of both framebuffers in the pair.
|
|
|
|
// The FXAA shader has this built-in, so we don't need to do the copy_depth
|
|
|
|
// pass in that case.
|
|
|
|
|
|
|
|
// The reason for this is that, normally, depth testing is disabled during
|
|
|
|
// the stage-specific post-processing ping-pong. This applies to depth writes
|
|
|
|
// as well. Therefore, only one of the framebuffers will get a depth write in
|
|
|
|
// a given frame. In the worst case, this will be the same framebuffer every
|
|
|
|
// time, leaving the other one's depth buffer undefined. In the best case,
|
|
|
|
// they will alternate. If a shader down the post-processing pipeline happens
|
|
|
|
// to sample the "unlucky" buffer, it'll probably either completely destroy
|
|
|
|
// the background rendering, or the sample will lag 1 frame behind.
|
|
|
|
|
|
|
|
// This flew past the radar for a long time. Now that I actually had to waste
|
|
|
|
// my evening debugging this peculiarity, I figured I might as well document
|
|
|
|
// it here. It is possible to solve this problem without an additional pass,
|
|
|
|
// but that would require a bit of refactoring. This is the simplest solution
|
|
|
|
// as far as I can tell.
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
apply_shader_rules((ShaderRule[]) {
|
|
|
|
config_get_int(CONFIG_FXAA)
|
|
|
|
? fxaa_rule
|
|
|
|
: copydepth_rule,
|
|
|
|
NULL
|
|
|
|
}, fbpair);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_full_spellbg(int t, FBPair *fbos) {
|
|
|
|
BlendMode blend_old = r_blend_current();
|
|
|
|
r_framebuffer(fbos->back);
|
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
|
|
|
draw_spellbg(t);
|
|
|
|
fbpair_swap(fbos);
|
|
|
|
r_blend(BLEND_NONE);
|
|
|
|
apply_shader_rules((ShaderRule[]) { boss_distortion_rule, NULL }, fbos);
|
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
|
|
|
draw_spellbg_overlay(t);
|
|
|
|
r_blend(blend_old);
|
2018-08-16 21:52:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
static void apply_bg_shaders(ShaderRule *shaderrules, FBPair *fbos) {
|
2017-04-07 14:20:45 +02:00
|
|
|
Boss *b = global.boss;
|
2018-04-26 01:50:48 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_push();
|
|
|
|
r_blend(BLEND_NONE);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(should_draw_stage_bg()) {
|
|
|
|
finish_3d_scene(fbos);
|
|
|
|
apply_shader_rules(shaderrules, fbos);
|
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(b && b->current && b->current->draw_rule) {
|
|
|
|
int t = global.frames - b->current->starttime;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
bool trans_intro = t < ATTACK_START_DELAY;
|
|
|
|
bool trans_outro = b->current->endtime;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(!trans_intro && !trans_outro) {
|
|
|
|
draw_full_spellbg(t, fbos);
|
2017-04-07 14:20:45 +02:00
|
|
|
} else {
|
2019-02-22 00:56:03 +01:00
|
|
|
FBPair *aux = stage_get_fbpair(FBPAIR_BG_AUX);
|
|
|
|
draw_full_spellbg(t, aux);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
apply_shader_rules((ShaderRule[]) { boss_distortion_rule, NULL }, fbos);
|
|
|
|
fbpair_swap(fbos);
|
|
|
|
r_framebuffer(fbos->back);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
complex pos = b->pos;
|
|
|
|
float ratio = (float)VIEWPORT_H/VIEWPORT_W;
|
|
|
|
float delay;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(trans_intro) {
|
|
|
|
float duration = ATTACK_START_DELAY_EXTRA;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(b->current->type == AT_ExtraSpell) {
|
|
|
|
delay = ATTACK_START_DELAY_EXTRA;
|
|
|
|
} else {
|
|
|
|
delay = ATTACK_START_DELAY;
|
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_shader("spellcard_intro");
|
|
|
|
r_uniform_float("ratio", ratio);
|
|
|
|
r_uniform_vec2("origin", creal(pos) / VIEWPORT_W, 1 - cimag(pos) / VIEWPORT_H);
|
|
|
|
r_uniform_float("t", (t + delay) / duration);
|
|
|
|
} else {
|
|
|
|
int tn = global.frames - b->current->endtime;
|
|
|
|
delay = b->current->endtime - b->current->endtime_undelayed;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_shader("spellcard_outro");
|
|
|
|
r_uniform_float("ratio", ratio);
|
|
|
|
r_uniform_vec2("origin", creal(pos) / VIEWPORT_W, 1 - cimag(pos) / VIEWPORT_H);
|
|
|
|
r_uniform_float("t", max(0, tn / delay + 1));
|
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
|
|
|
draw_framebuffer_tex(aux->front, VIEWPORT_W, VIEWPORT_H);
|
|
|
|
r_blend(BLEND_NONE);
|
|
|
|
fbpair_swap(fbos);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
apply_shader_rules((ShaderRule[]) { boss_distortion_rule, NULL }, fbos);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2018-01-03 15:38:42 +01:00
|
|
|
static void stage_render_bg(StageInfo *stage) {
|
2018-07-04 10:36:16 +02:00
|
|
|
FBPair *background = stage_get_fbpair(FBPAIR_BG);
|
|
|
|
|
|
|
|
r_framebuffer(background->back);
|
2018-09-14 09:37:20 +02:00
|
|
|
r_clear(CLEAR_ALL, RGBA(0, 0, 0, 1), 1);
|
2018-04-12 16:08:48 +02:00
|
|
|
|
|
|
|
if(should_draw_stage_bg()) {
|
|
|
|
r_mat_push();
|
|
|
|
r_mat_translate(-(VIEWPORT_X+VIEWPORT_W/2), -(VIEWPORT_Y+VIEWPORT_H/2),0);
|
|
|
|
r_enable(RCAP_DEPTH_TEST);
|
2017-04-07 14:20:45 +02:00
|
|
|
stage->procs->draw();
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_pop();
|
2018-07-04 10:36:16 +02:00
|
|
|
fbpair_swap(background);
|
2018-04-12 16:08:48 +02:00
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
set_ortho(VIEWPORT_W, VIEWPORT_H);
|
|
|
|
r_disable(RCAP_DEPTH_TEST);
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
apply_bg_shaders(stage->procs->shader_rules, background);
|
2018-08-16 21:52:41 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
int pp = config_get_int(CONFIG_POSTPROCESS);
|
|
|
|
|
|
|
|
if(pp > 1) {
|
|
|
|
draw_powersurge_effect(background->front, BLEND_PREMUL_ALPHA);
|
|
|
|
} else if(pp > 0) {
|
|
|
|
Framebuffer *staging = stage_get_fbpair(FBPAIR_BG_AUX)->back;
|
|
|
|
|
|
|
|
r_state_push();
|
|
|
|
r_framebuffer_clear(staging, CLEAR_COLOR, RGBA(0, 0, 0, 0), 1);
|
|
|
|
draw_powersurge_effect(staging, BLEND_NONE);
|
|
|
|
r_shader_standard();
|
|
|
|
r_framebuffer(background->front);
|
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
|
|
|
draw_framebuffer_tex(staging, VIEWPORT_W, VIEWPORT_H);
|
|
|
|
r_state_pop();
|
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 21:40:46 +01:00
|
|
|
bool stage_should_draw_particle(Projectile *p) {
|
|
|
|
return (p->flags & PFLAG_REQUIREDPARTICLE) || config_get_int(CONFIG_PARTICLES);
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
static bool stage_draw_predicate(EntityInterface *ent) {
|
|
|
|
if(ent->type == ENT_PROJECTILE) {
|
|
|
|
Projectile *p = ENT_CAST(ent, Projectile);
|
|
|
|
|
2019-03-28 17:42:07 +01:00
|
|
|
if(p->type == PROJ_PARTICLE) {
|
2018-04-13 21:13:48 +02:00
|
|
|
return stage_should_draw_particle(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
static void stage_draw_objects(void) {
|
2018-04-12 16:08:48 +02:00
|
|
|
r_shader("sprite_default");
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
if(global.boss) {
|
2017-10-16 23:49:23 +02:00
|
|
|
draw_boss_background(global.boss);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
ent_draw(
|
2018-01-11 21:40:46 +01:00
|
|
|
config_get_int(CONFIG_PARTICLES)
|
|
|
|
? NULL
|
2018-04-13 21:13:48 +02:00
|
|
|
: stage_draw_predicate
|
2018-01-11 21:40:46 +01:00
|
|
|
);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2018-08-31 04:46:37 +02:00
|
|
|
if(global.boss) {
|
2019-02-22 00:56:03 +01:00
|
|
|
draw_boss_fake_overlay(global.boss);
|
2018-08-31 04:46:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-08 15:02:08 +02:00
|
|
|
stage_draw_collision_areas();
|
2018-04-12 16:08:48 +02:00
|
|
|
r_shader_standard();
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-11 11:27:21 +02:00
|
|
|
void stage_draw_overlay(void) {
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_push();
|
|
|
|
r_shader("sprite_default");
|
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
|
|
|
|
|
|
|
if(global.boss) {
|
|
|
|
draw_boss_overlay(global.boss);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stagedraw.clear_screen.alpha > 0) {
|
|
|
|
fade_out(stagedraw.clear_screen.alpha * 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
r_shader_standard();
|
2017-04-07 14:20:45 +02:00
|
|
|
stagetext_draw();
|
2019-07-03 19:50:43 +02:00
|
|
|
player_draw_overlay(&global.plr);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
static void postprocess_prepare(Framebuffer *fb, ShaderProgram *s) {
|
2018-04-12 16:08:48 +02:00
|
|
|
r_uniform_int("frames", global.frames);
|
2018-05-18 20:15:11 +02:00
|
|
|
r_uniform_vec2("viewport", VIEWPORT_W, VIEWPORT_H);
|
|
|
|
r_uniform_vec2("player", creal(global.plr.pos), VIEWPORT_H - cimag(global.plr.pos));
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 11:27:21 +02:00
|
|
|
static inline void begin_viewport_shake(void) {
|
|
|
|
if(global.shake_view) {
|
|
|
|
r_mat_push();
|
|
|
|
r_mat_translate(
|
|
|
|
global.shake_view * sin(global.frames),
|
|
|
|
global.shake_view * sin(global.frames * 1.1 + 3),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
r_mat_scale(
|
|
|
|
1 + 2 * global.shake_view / VIEWPORT_W,
|
|
|
|
1 + 2 * global.shake_view / VIEWPORT_H,
|
|
|
|
1
|
|
|
|
);
|
|
|
|
r_mat_translate(
|
|
|
|
-global.shake_view,
|
|
|
|
-global.shake_view,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void end_viewport_shake(void) {
|
|
|
|
if(global.shake_view) {
|
|
|
|
r_mat_pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-14 15:15:40 +02:00
|
|
|
/*
|
|
|
|
* Small helpers for entities draw code that might want to suppress viewport shake temporarily.
|
|
|
|
* This is mostly useful when multiple framebuffers are involved.
|
|
|
|
*/
|
|
|
|
static int shake_suppressed = 0;
|
|
|
|
|
|
|
|
void stage_draw_begin_noshake(void) {
|
|
|
|
assert(!shake_suppressed);
|
|
|
|
shake_suppressed = 1;
|
|
|
|
|
|
|
|
if(global.shake_view) {
|
|
|
|
shake_suppressed = 2;
|
|
|
|
MatrixMode mm = r_mat_mode_current();
|
|
|
|
r_mat_mode(MM_MODELVIEW);
|
|
|
|
r_mat_push();
|
|
|
|
r_mat_identity();
|
|
|
|
r_mat_mode(mm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void stage_draw_end_noshake(void) {
|
|
|
|
assert(shake_suppressed);
|
|
|
|
|
|
|
|
if(global.shake_view) {
|
|
|
|
// make sure shake_view doesn't change in-between the begin/end calls;
|
|
|
|
// that would've been *really* nasty to debug.
|
|
|
|
assert(shake_suppressed == 2);
|
|
|
|
MatrixMode mm = r_mat_mode_current();
|
|
|
|
r_mat_mode(MM_MODELVIEW);
|
|
|
|
r_mat_pop();
|
|
|
|
r_mat_mode(mm);
|
|
|
|
}
|
|
|
|
|
|
|
|
shake_suppressed = 0;
|
|
|
|
}
|
|
|
|
|
2019-04-11 11:27:21 +02:00
|
|
|
void stage_draw_viewport(void) {
|
|
|
|
FloatRect dest_vp;
|
|
|
|
r_framebuffer_viewport_current(r_framebuffer_current(), &dest_vp);
|
|
|
|
r_uniform_sampler("tex", r_framebuffer_get_attachment(stagedraw.fb_pairs[FBPAIR_FG].front, FRAMEBUFFER_ATTACH_COLOR0));
|
2017-04-19 09:56:18 +02:00
|
|
|
|
|
|
|
// CAUTION: Very intricate pixel perfect scaling that will ruin your day.
|
2019-04-11 11:27:21 +02:00
|
|
|
float facw = dest_vp.w / SCREEN_W;
|
|
|
|
float fach = dest_vp.h / SCREEN_H;
|
2019-04-04 01:43:03 +02:00
|
|
|
// fach is equal to facw up to roundoff error.
|
2017-04-19 10:06:39 +02:00
|
|
|
float scale = fach;
|
2017-04-19 09:56:18 +02:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_push();
|
2019-04-11 11:27:21 +02:00
|
|
|
r_mat_scale(1/facw, 1/fach, 1);
|
|
|
|
r_mat_translate(roundf(facw * VIEWPORT_X), roundf(fach * VIEWPORT_Y), 0);
|
|
|
|
r_mat_scale(roundf(scale * VIEWPORT_W), roundf(scale * VIEWPORT_H), 1);
|
|
|
|
r_mat_translate(0.5, 0.5, 0);
|
|
|
|
r_draw_quad();
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void stage_draw_scene(StageInfo *stage) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool key_nobg = gamekeypressed(KEY_NOBACKGROUND);
|
|
|
|
#else
|
|
|
|
bool key_nobg = false;
|
|
|
|
#endif
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
FBPair *background = stage_get_fbpair(FBPAIR_BG);
|
|
|
|
FBPair *foreground = stage_get_fbpair(FBPAIR_FG);
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
bool draw_bg = !config_get_int(CONFIG_NO_STAGEBG) && !key_nobg;
|
|
|
|
|
|
|
|
if(draw_bg) {
|
2018-01-03 15:38:42 +01:00
|
|
|
stage_render_bg(stage);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 01:50:48 +02:00
|
|
|
// prepare for 2D rendering into the game viewport framebuffer
|
2018-07-04 10:36:16 +02:00
|
|
|
r_framebuffer(foreground->back);
|
2018-04-26 01:50:48 +02:00
|
|
|
set_ortho(VIEWPORT_W, VIEWPORT_H);
|
|
|
|
r_disable(RCAP_DEPTH_TEST);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
|
|
|
r_cull(CULL_BACK);
|
|
|
|
r_shader_standard();
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-04-11 11:27:21 +02:00
|
|
|
begin_viewport_shake();
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
if(draw_bg) {
|
2019-02-22 00:56:03 +01:00
|
|
|
// blit the background
|
|
|
|
r_state_push();
|
|
|
|
r_blend(BLEND_NONE);
|
2018-07-04 10:36:16 +02:00
|
|
|
draw_framebuffer_tex(background->front, VIEWPORT_W, VIEWPORT_H);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2017-11-12 16:15:12 +01:00
|
|
|
// draw bomb background
|
2018-08-11 21:13:48 +02:00
|
|
|
// FIXME: we need a more flexible and consistent way for entities to hook
|
|
|
|
// into the various stages of scene drawing code.
|
|
|
|
if(global.plr.mode->procs.bombbg /*&& player_is_bomb_active(&global.plr)*/) {
|
2017-11-12 16:15:12 +01:00
|
|
|
global.plr.mode->procs.bombbg(&global.plr);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
} else if(!key_nobg) {
|
2018-09-14 09:37:20 +02:00
|
|
|
r_clear(CLEAR_COLOR, RGBA(0, 0, 0, 1), 1);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw the 2D objects
|
2017-04-14 10:42:09 +02:00
|
|
|
stage_draw_objects();
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-04-11 11:27:21 +02:00
|
|
|
end_viewport_shake();
|
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
// prepare to apply postprocessing
|
2018-07-04 10:36:16 +02:00
|
|
|
fbpair_swap(foreground);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_blend(BLEND_NONE);
|
2017-10-01 10:58:45 +02:00
|
|
|
|
2017-11-26 14:06:35 +01:00
|
|
|
// bomb effects shader if present and player bombing
|
2018-07-31 09:07:34 +02:00
|
|
|
if(global.plr.mode->procs.bomb_shader && player_is_bomb_active(&global.plr)) {
|
2018-04-26 01:50:48 +02:00
|
|
|
ShaderRule rules[] = { global.plr.mode->procs.bomb_shader, NULL };
|
2018-07-04 10:36:16 +02:00
|
|
|
apply_shader_rules(rules, foreground);
|
2017-11-26 14:06:35 +01:00
|
|
|
}
|
2018-01-03 15:38:42 +01:00
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
// draw overlay: in-viewport text and HUD elements, etc.
|
|
|
|
// this stuff is not affected by the screen shake effect
|
|
|
|
stage_draw_overlay();
|
|
|
|
|
|
|
|
// stage postprocessing
|
|
|
|
apply_shader_rules(global.stage->procs->postprocess_rules, foreground);
|
|
|
|
|
2017-10-01 10:58:45 +02:00
|
|
|
// custom postprocessing
|
|
|
|
postprocess(
|
2018-04-12 16:08:48 +02:00
|
|
|
stagedraw.viewport_pp,
|
2018-07-04 10:36:16 +02:00
|
|
|
foreground,
|
2017-04-07 14:20:45 +02:00
|
|
|
postprocess_prepare,
|
2018-07-04 10:36:16 +02:00
|
|
|
draw_framebuffer_tex,
|
|
|
|
VIEWPORT_W,
|
|
|
|
VIEWPORT_H
|
2017-04-07 14:20:45 +02:00
|
|
|
);
|
|
|
|
|
2018-04-26 01:50:48 +02:00
|
|
|
// prepare for 2D rendering into the main framebuffer (actual screen)
|
2018-07-04 10:36:16 +02:00
|
|
|
r_framebuffer(NULL);
|
2018-04-26 01:50:48 +02:00
|
|
|
set_ortho(SCREEN_W, SCREEN_H);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
// draw viewport contents
|
2019-04-11 11:27:21 +02:00
|
|
|
stage_draw_viewport();
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
// draw HUD
|
2017-04-07 14:20:45 +02:00
|
|
|
stage_draw_hud();
|
2019-07-03 19:50:43 +02:00
|
|
|
|
|
|
|
// draw dialog
|
2019-07-08 02:47:50 +02:00
|
|
|
dialog_draw(global.dialog);
|
2019-07-03 19:50:43 +02:00
|
|
|
|
|
|
|
// draw "bottom text" (FPS, replay info, etc.)
|
|
|
|
stage_draw_bottom_text();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
#define HUD_X_PADDING 16
|
|
|
|
#define HUD_X_OFFSET (VIEWPORT_W + VIEWPORT_X)
|
|
|
|
#define HUD_WIDTH (SCREEN_W - HUD_X_OFFSET)
|
|
|
|
#define HUD_EFFECTIVE_WIDTH (HUD_WIDTH - HUD_X_PADDING * 2)
|
|
|
|
#define HUD_X_SECONDARY_OFS_ICON 18
|
|
|
|
#define HUD_X_SECONDARY_OFS_LABEL (HUD_X_SECONDARY_OFS_ICON + 12)
|
|
|
|
#define HUD_X_SECONDARY_OFS_VALUE (HUD_X_SECONDARY_OFS_LABEL + 60)
|
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
struct glyphcb_state {
|
2019-02-22 00:56:03 +01:00
|
|
|
Color *color1, *color2;
|
2018-06-29 23:36:51 +02:00
|
|
|
};
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
static int draw_numeric_callback(Font *font, charcode_t charcode, SpriteParams *spr_params, void *userdata) {
|
2018-06-29 23:36:51 +02:00
|
|
|
struct glyphcb_state *st = userdata;
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
if(charcode != '0' && charcode != ',') {
|
2019-02-22 00:56:03 +01:00
|
|
|
st->color1 = st->color2;
|
2018-06-29 23:36:51 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
spr_params->color = st->color1;
|
2019-01-04 23:59:39 +01:00
|
|
|
return 0;
|
2018-06-29 23:36:51 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
static inline void stage_draw_hud_power_value(float xpos, float ypos) {
|
|
|
|
Font *fnt_int = get_font("standard");
|
|
|
|
Font *fnt_fract = get_font("small");
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
int pw = global.plr.power + global.plr.power_overflow;
|
|
|
|
|
2019-05-01 19:55:24 +02:00
|
|
|
Color *c_whole, c_whole_buf, *c_fract, c_fract_buf;
|
2019-02-22 00:56:03 +01:00
|
|
|
Color *c_op_mod = RGBA(1, 0.2 + 0.3 * psin(global.frames / 10.0), 0.2, 1.0);
|
|
|
|
|
|
|
|
if(pw <= PLR_MAX_POWER) {
|
|
|
|
c_whole = &stagedraw.hud_text.color.active;
|
|
|
|
c_fract = &stagedraw.hud_text.color.inactive;
|
|
|
|
} else if(pw - PLR_MAX_POWER < 100) {
|
|
|
|
c_whole = &stagedraw.hud_text.color.active;
|
2019-05-01 19:55:24 +02:00
|
|
|
c_fract = color_mul(color_copy(&c_fract_buf, &stagedraw.hud_text.color.inactive), c_op_mod);
|
2019-02-22 00:56:03 +01:00
|
|
|
} else {
|
2019-05-01 19:55:24 +02:00
|
|
|
c_whole = color_mul(color_copy(&c_whole_buf, &stagedraw.hud_text.color.active), c_op_mod);
|
|
|
|
c_fract = color_mul(color_copy(&c_fract_buf, &stagedraw.hud_text.color.inactive), c_op_mod);
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
xpos = draw_fraction(
|
2019-02-22 00:56:03 +01:00
|
|
|
pw / 100.0,
|
2019-01-04 23:59:39 +01:00
|
|
|
ALIGN_LEFT,
|
|
|
|
xpos,
|
|
|
|
ypos,
|
|
|
|
fnt_int,
|
|
|
|
fnt_fract,
|
2019-02-22 00:56:03 +01:00
|
|
|
c_whole,
|
|
|
|
c_fract,
|
2019-01-04 23:59:39 +01:00
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
xpos += text_draw(" / ", &(TextParams) {
|
|
|
|
.pos = { xpos, ypos },
|
|
|
|
.color = &stagedraw.hud_text.color.active,
|
|
|
|
.align = ALIGN_LEFT,
|
|
|
|
.font_ptr = fnt_int,
|
2018-06-29 23:36:51 +02:00
|
|
|
});
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
draw_fraction(
|
|
|
|
PLR_MAX_POWER / 100.0,
|
|
|
|
ALIGN_LEFT,
|
|
|
|
xpos,
|
|
|
|
ypos,
|
|
|
|
fnt_int,
|
|
|
|
fnt_fract,
|
|
|
|
&stagedraw.hud_text.color.active,
|
|
|
|
&stagedraw.hud_text.color.inactive,
|
|
|
|
false
|
|
|
|
);
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void stage_draw_hud_score(Alignment a, float xpos, float ypos, char *buf, size_t bufsize, uint32_t score) {
|
2019-01-04 23:59:39 +01:00
|
|
|
format_huge_num(10, score, bufsize, buf);
|
|
|
|
|
|
|
|
Font *fnt = get_font("standard");
|
|
|
|
bool kern_saved = font_get_kerning_enabled(fnt);
|
|
|
|
font_set_kerning_enabled(fnt, false);
|
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { xpos, ypos },
|
2019-01-04 23:59:39 +01:00
|
|
|
.font = "standard",
|
2018-06-29 23:36:51 +02:00
|
|
|
.align = ALIGN_RIGHT,
|
|
|
|
.glyph_callback = {
|
|
|
|
draw_numeric_callback,
|
2019-02-22 00:56:03 +01:00
|
|
|
&(struct glyphcb_state) { &stagedraw.hud_text.color.inactive, &stagedraw.hud_text.color.active },
|
2018-06-29 23:36:51 +02:00
|
|
|
}
|
|
|
|
});
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
font_set_kerning_enabled(fnt, kern_saved);
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void stage_draw_hud_scores(float ypos_hiscore, float ypos_score, char *buf, size_t bufsize) {
|
2019-02-22 00:56:03 +01:00
|
|
|
stage_draw_hud_score(ALIGN_RIGHT, HUD_EFFECTIVE_WIDTH, ypos_hiscore, buf, bufsize, progress.hiscore);
|
|
|
|
stage_draw_hud_score(ALIGN_RIGHT, HUD_EFFECTIVE_WIDTH, ypos_score, buf, bufsize, global.plr.points);
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
static void stage_draw_hud_objpool_stats(float x, float y, float width) {
|
2017-12-13 20:05:12 +01:00
|
|
|
ObjectPool **last = &stage_object_pools.first + (sizeof(StageObjectPools)/sizeof(ObjectPool*) - 1);
|
2018-06-29 23:36:51 +02:00
|
|
|
Font *font = get_font("monotiny");
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
ShaderProgram *sh_prev = r_shader_current();
|
|
|
|
r_shader("text_default");
|
2017-12-13 20:05:12 +01:00
|
|
|
for(ObjectPool **pool = &stage_object_pools.first; pool <= last; ++pool) {
|
|
|
|
ObjectPoolStats stats;
|
|
|
|
char buf[32];
|
|
|
|
objpool_get_stats(*pool, &stats);
|
|
|
|
|
2017-12-23 22:56:14 +01:00
|
|
|
snprintf(buf, sizeof(buf), "%zu | %5zu", stats.usage, stats.peak_usage);
|
2018-06-29 23:36:51 +02:00
|
|
|
// draw_text(ALIGN_LEFT | AL_Flag_NoAdjust, (int)x, (int)y, stats.tag, font);
|
|
|
|
// draw_text(ALIGN_RIGHT | AL_Flag_NoAdjust, (int)(x + width), (int)y, buf, font);
|
|
|
|
// y += stringheight(buf, font) * 1.1;
|
|
|
|
|
|
|
|
text_draw(stats.tag, &(TextParams) {
|
|
|
|
.pos = { x, y },
|
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_LEFT,
|
|
|
|
});
|
|
|
|
|
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { x + width, y },
|
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_RIGHT,
|
|
|
|
});
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
y += font_get_lineskip(font);
|
2017-12-13 20:05:12 +01:00
|
|
|
}
|
2018-06-29 23:36:51 +02:00
|
|
|
r_shader_ptr(sh_prev);
|
2017-12-13 20:05:12 +01:00
|
|
|
}
|
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
struct labels_s {
|
|
|
|
struct {
|
2019-02-22 00:56:03 +01:00
|
|
|
float next_life;
|
2019-03-19 03:51:45 +01:00
|
|
|
float next_bomb;
|
2017-11-23 03:25:53 +01:00
|
|
|
} x;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
float hiscore;
|
|
|
|
float score;
|
|
|
|
float lives;
|
|
|
|
float bombs;
|
|
|
|
float power;
|
2019-01-04 23:59:39 +01:00
|
|
|
float value;
|
2019-02-22 00:56:03 +01:00
|
|
|
float voltage;
|
2017-11-23 03:25:53 +01:00
|
|
|
float graze;
|
|
|
|
} y;
|
2019-02-22 00:56:03 +01:00
|
|
|
|
2019-03-19 03:51:45 +01:00
|
|
|
struct {
|
|
|
|
float lives_display;
|
|
|
|
float lives_text;
|
|
|
|
float bombs_display;
|
|
|
|
float bombs_text;
|
|
|
|
} y_ofs;
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
Color lb_baseclr;
|
2017-11-23 03:25:53 +01:00
|
|
|
};
|
|
|
|
|
2018-05-03 19:51:10 +02:00
|
|
|
static void draw_graph(float x, float y, float w, float h) {
|
|
|
|
r_mat_push();
|
|
|
|
r_mat_translate(x + w/2, y + h/2, 0);
|
|
|
|
r_mat_scale(w, h, 1);
|
|
|
|
r_draw_quad();
|
|
|
|
r_mat_pop();
|
|
|
|
}
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
static void draw_label(const char *label_str, double y_ofs, struct labels_s* labels, Color *clr) {
|
2018-06-29 23:36:51 +02:00
|
|
|
text_draw(label_str, &(TextParams) {
|
|
|
|
.font_ptr = stagedraw.hud_text.font,
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
2019-02-22 00:56:03 +01:00
|
|
|
.pos = { 0, y_ofs },
|
2019-01-04 23:59:39 +01:00
|
|
|
.color = clr,
|
2018-06-29 23:36:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-24 21:21:08 +01:00
|
|
|
static void stage_draw_hud_text(struct labels_s* labels) {
|
2017-11-23 03:25:53 +01:00
|
|
|
char buf[64];
|
2018-06-29 23:36:51 +02:00
|
|
|
Font *font;
|
2019-02-22 00:56:03 +01:00
|
|
|
bool kern_saved;
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_shader_ptr(stagedraw.hud_text.shader);
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
Color *lb_label_clr = color_mul(COLOR_COPY(&labels->lb_baseclr), &stagedraw.hud_text.color.label);
|
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
// Labels
|
2019-01-04 23:59:39 +01:00
|
|
|
draw_label("Hi-Score:", labels->y.hiscore, labels, &stagedraw.hud_text.color.label);
|
|
|
|
draw_label("Score:", labels->y.score, labels, &stagedraw.hud_text.color.label);
|
2019-02-22 00:56:03 +01:00
|
|
|
draw_label("Lives:", labels->y.lives, labels, lb_label_clr);
|
|
|
|
draw_label("Spell Cards:", labels->y.bombs, labels, lb_label_clr);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
r_mat_push();
|
2019-02-22 00:56:03 +01:00
|
|
|
r_mat_translate(HUD_X_SECONDARY_OFS_LABEL, 0, 0);
|
2019-01-04 23:59:39 +01:00
|
|
|
draw_label("Power:", labels->y.power, labels, &stagedraw.hud_text.color.label_power);
|
|
|
|
draw_label("Value:", labels->y.value, labels, &stagedraw.hud_text.color.label_value);
|
2019-02-22 00:56:03 +01:00
|
|
|
draw_label("Volts:", labels->y.voltage, labels, &stagedraw.hud_text.color.label_voltage);
|
2019-01-04 23:59:39 +01:00
|
|
|
draw_label("Graze:", labels->y.graze, labels, &stagedraw.hud_text.color.label_graze);
|
|
|
|
r_mat_pop();
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2017-12-13 20:05:12 +01:00
|
|
|
if(stagedraw.objpool_stats) {
|
2019-02-22 00:56:03 +01:00
|
|
|
stage_draw_hud_objpool_stats(0, 390, HUD_EFFECTIVE_WIDTH);
|
2017-12-13 20:05:12 +01:00
|
|
|
}
|
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
// Score/Hi-Score values
|
2019-01-04 23:59:39 +01:00
|
|
|
stage_draw_hud_scores(labels->y.hiscore, labels->y.score, buf, sizeof(buf));
|
2017-11-23 03:25:53 +01:00
|
|
|
|
|
|
|
// Lives and Bombs (N/A)
|
|
|
|
if(global.stage->type == STAGE_SPELL) {
|
2019-02-22 00:56:03 +01:00
|
|
|
r_color(color_mul_scalar(COLOR_COPY(&labels->lb_baseclr), 0.7));
|
|
|
|
text_draw("N/A", &(TextParams) { .pos = { HUD_EFFECTIVE_WIDTH, labels->y.lives }, .font_ptr = stagedraw.hud_text.font, .align = ALIGN_RIGHT });
|
|
|
|
text_draw("N/A", &(TextParams) { .pos = { HUD_EFFECTIVE_WIDTH, labels->y.bombs }, .font_ptr = stagedraw.hud_text.font, .align = ALIGN_RIGHT });
|
2018-04-12 16:08:48 +02:00
|
|
|
r_color4(1, 1, 1, 1.0);
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:51:45 +01:00
|
|
|
const float res_text_padding = 4;
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
// Score left to next extra life
|
|
|
|
if(labels->x.next_life > 0) {
|
|
|
|
Color *next_clr = color_mul(RGBA(0.5, 0.3, 0.4, 0.5), &labels->lb_baseclr);
|
|
|
|
format_huge_num(0, global.plr.extralife_threshold - global.plr.points, sizeof(buf), buf);
|
|
|
|
font = get_font("small");
|
|
|
|
|
|
|
|
text_draw("Next:", &(TextParams) {
|
2019-03-19 03:51:45 +01:00
|
|
|
.pos = { labels->x.next_life + res_text_padding, labels->y.lives + labels->y_ofs.lives_text },
|
2019-02-22 00:56:03 +01:00
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_LEFT,
|
|
|
|
.color = next_clr,
|
|
|
|
});
|
|
|
|
|
|
|
|
kern_saved = font_get_kerning_enabled(font);
|
|
|
|
font_set_kerning_enabled(font, false);
|
|
|
|
|
|
|
|
text_draw(buf, &(TextParams) {
|
2019-03-19 03:51:45 +01:00
|
|
|
.pos = { HUD_EFFECTIVE_WIDTH - res_text_padding, labels->y.lives + labels->y_ofs.lives_text },
|
2019-02-22 00:56:03 +01:00
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_RIGHT,
|
|
|
|
.color = next_clr,
|
|
|
|
});
|
|
|
|
|
|
|
|
font_set_kerning_enabled(font, kern_saved);
|
|
|
|
}
|
|
|
|
|
2019-03-19 03:51:45 +01:00
|
|
|
// Bomb fragments (numeric)
|
|
|
|
if(labels->x.next_bomb > 0) {
|
|
|
|
Color *next_clr = color_mul(RGBA(0.3, 0.5, 0.3, 0.5), &labels->lb_baseclr);
|
|
|
|
snprintf(buf, sizeof(buf), "%d / %d", global.plr.bomb_fragments, PLR_MAX_BOMB_FRAGMENTS);
|
|
|
|
font = get_font("small");
|
|
|
|
|
|
|
|
text_draw("Fragments:", &(TextParams) {
|
|
|
|
.pos = { labels->x.next_bomb + res_text_padding, labels->y.bombs + labels->y_ofs.bombs_text },
|
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_LEFT,
|
|
|
|
.color = next_clr,
|
|
|
|
});
|
|
|
|
|
|
|
|
kern_saved = font_get_kerning_enabled(font);
|
|
|
|
font_set_kerning_enabled(font, false);
|
|
|
|
|
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { HUD_EFFECTIVE_WIDTH - res_text_padding, labels->y.bombs + labels->y_ofs.bombs_text },
|
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_RIGHT,
|
|
|
|
.color = next_clr,
|
|
|
|
});
|
|
|
|
|
|
|
|
font_set_kerning_enabled(font, kern_saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
r_mat_push();
|
2019-02-22 00:56:03 +01:00
|
|
|
r_mat_translate(HUD_X_SECONDARY_OFS_VALUE, 0, 0);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
// Power value
|
2019-01-04 23:59:39 +01:00
|
|
|
stage_draw_hud_power_value(0, labels->y.power);
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
font = get_font("standard");
|
|
|
|
kern_saved = font_get_kerning_enabled(font);
|
|
|
|
font_set_kerning_enabled(font, false);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
// Point Item Value... value
|
2019-02-22 00:56:03 +01:00
|
|
|
format_huge_num(6, global.plr.point_item_value, sizeof(buf), buf);
|
2019-01-04 23:59:39 +01:00
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { 0, labels->y.value },
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
2019-02-22 00:56:03 +01:00
|
|
|
.font_ptr = font,
|
2019-01-04 23:59:39 +01:00
|
|
|
.glyph_callback = {
|
|
|
|
draw_numeric_callback,
|
|
|
|
&(struct glyphcb_state) { &stagedraw.hud_text.color.inactive },
|
|
|
|
}
|
|
|
|
});
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
// Voltage value
|
|
|
|
format_huge_num(4, global.plr.voltage, sizeof(buf), buf);
|
|
|
|
float volts_x = 0;
|
|
|
|
|
|
|
|
Color *voltage_tint = global.plr.voltage >= global.voltage_threshold
|
|
|
|
? RGB(1.0, 0.9, 0.7) // RGB(0.9, 0.7, 1.0)
|
|
|
|
: RGB(1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
volts_x += text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { volts_x, labels->y.voltage },
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
|
|
|
.font_ptr = font,
|
|
|
|
.glyph_callback = {
|
|
|
|
draw_numeric_callback,
|
|
|
|
&(struct glyphcb_state) {
|
|
|
|
color_mul(COLOR_COPY(&stagedraw.hud_text.color.inactive), voltage_tint),
|
|
|
|
color_mul(COLOR_COPY(&stagedraw.hud_text.color.active), voltage_tint),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
volts_x += text_draw("V", &(TextParams) {
|
|
|
|
.pos = { volts_x, labels->y.voltage },
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
|
|
|
.font_ptr = font,
|
|
|
|
.color = &stagedraw.hud_text.color.dark,
|
|
|
|
});
|
|
|
|
|
|
|
|
volts_x += text_draw(" / ", &(TextParams) {
|
|
|
|
.pos = { volts_x, labels->y.voltage },
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
|
|
|
.font_ptr = font,
|
|
|
|
.color = &stagedraw.hud_text.color.active,
|
|
|
|
});
|
|
|
|
|
|
|
|
format_huge_num(4, global.voltage_threshold, sizeof(buf), buf);
|
|
|
|
|
|
|
|
volts_x += text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { volts_x, labels->y.voltage },
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
|
|
|
.font_ptr = font,
|
|
|
|
.glyph_callback = {
|
|
|
|
draw_numeric_callback,
|
|
|
|
&(struct glyphcb_state) { &stagedraw.hud_text.color.inactive },
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
volts_x += text_draw("V", &(TextParams) {
|
|
|
|
.pos = { volts_x, labels->y.voltage },
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
|
|
|
.font_ptr = font,
|
|
|
|
.color = &stagedraw.hud_text.color.dark,
|
|
|
|
});
|
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
// Graze value
|
2019-01-04 23:59:39 +01:00
|
|
|
format_huge_num(6, global.plr.graze, sizeof(buf), buf);
|
2018-06-29 23:36:51 +02:00
|
|
|
text_draw(buf, &(TextParams) {
|
2019-01-04 23:59:39 +01:00
|
|
|
.pos = { 0, labels->y.graze },
|
2018-06-29 23:36:51 +02:00
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
2019-02-22 00:56:03 +01:00
|
|
|
.font_ptr = font,
|
2018-06-29 23:36:51 +02:00
|
|
|
.glyph_callback = {
|
|
|
|
draw_numeric_callback,
|
2018-07-23 19:07:59 +02:00
|
|
|
&(struct glyphcb_state) { &stagedraw.hud_text.color.inactive },
|
2018-06-29 23:36:51 +02:00
|
|
|
}
|
|
|
|
});
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
font_set_kerning_enabled(font, kern_saved);
|
2019-01-04 23:59:39 +01:00
|
|
|
r_mat_pop();
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
// God Mode indicator
|
|
|
|
if(global.plr.iddqd) {
|
|
|
|
text_draw("God Mode is enabled!", &(TextParams) {
|
|
|
|
.pos = { HUD_EFFECTIVE_WIDTH * 0.5, 450 },
|
|
|
|
.font_ptr = font,
|
|
|
|
.shader_ptr = stagedraw.hud_text.shader,
|
|
|
|
.align = ALIGN_CENTER,
|
|
|
|
.color = RGB(1.0, 0.5, 0.2),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
void stage_draw_bottom_text(void) {
|
2019-02-22 00:56:03 +01:00
|
|
|
char buf[64];
|
|
|
|
Font *font;
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2017-12-26 12:14:46 +01:00
|
|
|
#ifdef DEBUG
|
2017-12-26 12:07:40 +01:00
|
|
|
snprintf(buf, sizeof(buf), "%.2f lfps, %.2f rfps, timer: %d, frames: %d",
|
|
|
|
global.fps.logic.fps,
|
|
|
|
global.fps.render.fps,
|
|
|
|
global.timer,
|
|
|
|
global.frames
|
|
|
|
);
|
2017-11-23 03:25:53 +01:00
|
|
|
#else
|
2017-12-26 12:07:40 +01:00
|
|
|
if(get_effective_frameskip() > 1) {
|
|
|
|
snprintf(buf, sizeof(buf), "%.2f lfps, %.2f rfps",
|
|
|
|
global.fps.logic.fps,
|
|
|
|
global.fps.render.fps
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "%.2f fps",
|
|
|
|
global.fps.logic.fps
|
|
|
|
);
|
|
|
|
}
|
2017-11-23 03:25:53 +01:00
|
|
|
#endif
|
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
font = get_font("monosmall");
|
|
|
|
|
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.align = ALIGN_RIGHT,
|
|
|
|
.pos = { SCREEN_W, SCREEN_H - 0.5 * text_height(font, buf, 0) },
|
|
|
|
.font_ptr = font,
|
|
|
|
});
|
2017-11-23 03:25:53 +01:00
|
|
|
|
|
|
|
if(global.replaymode == REPLAY_PLAY) {
|
2019-01-04 23:59:39 +01:00
|
|
|
r_shader_ptr(stagedraw.hud_text.shader);
|
2017-11-23 03:25:53 +01:00
|
|
|
// XXX: does it make sense to use the monospace font here?
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "Replay: %s (%i fps)", global.replay.playername, global.replay_stage->fps);
|
2018-06-29 23:36:51 +02:00
|
|
|
int x = 0, y = SCREEN_H - 0.5 * text_height(font, buf, 0);
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
x += text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { x, y },
|
|
|
|
.font_ptr = font,
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = &stagedraw.hud_text.color.inactive,
|
2018-06-29 23:36:51 +02:00
|
|
|
});
|
2017-11-23 03:25:53 +01:00
|
|
|
|
|
|
|
if(global.replay_stage->desynced) {
|
|
|
|
strlcpy(buf, " (DESYNCED)", sizeof(buf));
|
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { x, y },
|
|
|
|
.font_ptr = font,
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = RGBA_MUL_ALPHA(1.00, 0.20, 0.20, 0.60),
|
2018-06-29 23:36:51 +02:00
|
|
|
});
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef PLR_DPS_STATS
|
|
|
|
else if(global.frames) {
|
2018-05-03 19:51:10 +02:00
|
|
|
int totaldmg = 0;
|
|
|
|
int framespan = sizeof(global.plr.dmglog)/sizeof(*global.plr.dmglog);
|
|
|
|
int graphspan = framespan;
|
|
|
|
static int max = 0;
|
|
|
|
float graph[framespan];
|
|
|
|
|
|
|
|
if(graphspan > 120) {
|
|
|
|
// shader limitation
|
|
|
|
graphspan = 120;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hack to update the graph every frame
|
2018-07-30 09:04:09 +02:00
|
|
|
player_register_damage(&global.plr, NULL, &(DamageInfo) { .amount = 0, .type = DMG_PLAYER_SHOT });
|
2018-05-03 19:51:10 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < framespan; ++i) {
|
|
|
|
totaldmg += global.plr.dmglog[i];
|
|
|
|
|
|
|
|
if(global.plr.dmglog[i] > max) {
|
|
|
|
max = global.plr.dmglog[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < graphspan; ++i) {
|
|
|
|
if(max > 0) {
|
|
|
|
graph[i] = (float)global.plr.dmglog[i] / max;
|
|
|
|
} else {
|
|
|
|
graph[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
snprintf(buf, sizeof(buf), "%.02f", totaldmg / (framespan / (double)FPS));
|
|
|
|
double text_h = text_height(font, buf, 0);
|
|
|
|
double x = 0, y = SCREEN_H - 0.5 * text_h;
|
|
|
|
|
|
|
|
x += text_draw("Avg DPS: ", &(TextParams) {
|
|
|
|
.pos = { x, y },
|
|
|
|
.font_ptr = font,
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = &stagedraw.hud_text.color.inactive,
|
2018-06-29 23:36:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { x, y },
|
|
|
|
.font_ptr = font,
|
2018-07-23 19:07:59 +02:00
|
|
|
.color = &stagedraw.hud_text.color.active,
|
2018-06-29 23:36:51 +02:00
|
|
|
});
|
2018-05-03 19:51:10 +02:00
|
|
|
|
|
|
|
r_shader("graph");
|
|
|
|
r_uniform_vec3("color_low", 1.0, 0.0, 0.0);
|
|
|
|
r_uniform_vec3("color_mid", 1.0, 1.0, 0.0);
|
|
|
|
r_uniform_vec3("color_high", 0.0, 1.0, 0.0);
|
2018-09-14 09:37:20 +02:00
|
|
|
r_uniform_float_array("points[0]", 0, graphspan, graph);
|
2018-05-03 19:51:10 +02:00
|
|
|
draw_graph(142, SCREEN_H - text_h, graphspan, text_h);
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_shader_standard();
|
2017-11-23 03:25:53 +01:00
|
|
|
}
|
|
|
|
|
2017-12-11 19:56:46 +01:00
|
|
|
static void fill_graph(int num_samples, float *samples, FPSCounter *fps) {
|
|
|
|
for(int i = 0; i < num_samples; ++i) {
|
2019-01-09 04:25:10 +01:00
|
|
|
samples[i] = fps->frametimes[i] / (2.0 * (HRTIME_RESOLUTION / (long double)FPS));
|
2017-12-11 19:56:46 +01:00
|
|
|
|
|
|
|
if(samples[i] > 1.0) {
|
|
|
|
samples[i] = 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
static void stage_draw_framerate_graphs(float x, float y, float w, float h) {
|
2017-12-11 19:56:46 +01:00
|
|
|
#define NUM_SAMPLES (sizeof(((FPSCounter){{0}}).frametimes) / sizeof(((FPSCounter){{0}}).frametimes[0]))
|
|
|
|
static float samples[NUM_SAMPLES];
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_push();
|
2018-04-12 16:08:48 +02:00
|
|
|
r_shader("graph");
|
2017-12-11 19:56:46 +01:00
|
|
|
|
2017-12-26 12:07:40 +01:00
|
|
|
fill_graph(NUM_SAMPLES, samples, &global.fps.logic);
|
2018-04-12 16:08:48 +02:00
|
|
|
r_uniform_vec3("color_low", 0.0, 1.0, 1.0);
|
|
|
|
r_uniform_vec3("color_mid", 1.0, 1.0, 0.0);
|
|
|
|
r_uniform_vec3("color_high", 1.0, 0.0, 0.0);
|
2018-09-14 09:37:20 +02:00
|
|
|
r_uniform_float_array("points[0]", 0, NUM_SAMPLES, samples);
|
2017-12-11 19:56:46 +01:00
|
|
|
draw_graph(x, y, w, h);
|
|
|
|
|
|
|
|
// x -= w * 1.1;
|
|
|
|
y += h + 1;
|
|
|
|
|
2017-12-26 12:07:40 +01:00
|
|
|
fill_graph(NUM_SAMPLES, samples, &global.fps.busy);
|
2018-04-12 16:08:48 +02:00
|
|
|
r_uniform_vec3("color_low", 0.0, 1.0, 0.0);
|
|
|
|
r_uniform_vec3("color_mid", 1.0, 0.0, 0.0);
|
|
|
|
r_uniform_vec3("color_high", 1.0, 0.0, 0.5);
|
2018-09-14 09:37:20 +02:00
|
|
|
r_uniform_float_array("points[0]", 0, NUM_SAMPLES, samples);
|
2017-12-11 19:56:46 +01:00
|
|
|
draw_graph(x, y, w, h);
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_pop();
|
2017-12-11 19:56:46 +01:00
|
|
|
}
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
void stage_draw_hud(void) {
|
2017-11-23 03:25:53 +01:00
|
|
|
// Background
|
2019-01-23 15:02:51 +01:00
|
|
|
r_mat_push();
|
|
|
|
r_mat_translate(SCREEN_W*0.5, SCREEN_H*0.5, 0);
|
|
|
|
r_shader_standard();
|
|
|
|
r_uniform_sampler("tex", "hud");
|
|
|
|
r_draw_model("hud");
|
|
|
|
r_mat_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_blend(BLEND_PREMUL_ALPHA);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
// Set up positions of most HUD elements
|
2019-02-22 00:56:03 +01:00
|
|
|
struct labels_s labels = { 0 };
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2019-03-19 03:51:45 +01:00
|
|
|
const float label_spacing = 32;
|
|
|
|
float label_ypos = 0;
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2019-03-19 03:51:45 +01:00
|
|
|
label_ypos = 16;
|
|
|
|
labels.y.hiscore = label_ypos += label_spacing;
|
|
|
|
labels.y.score = label_ypos += label_spacing;
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2019-03-19 03:51:45 +01:00
|
|
|
label_ypos = 108;
|
|
|
|
labels.y.lives = label_ypos += label_spacing;
|
|
|
|
labels.y.bombs = label_ypos += label_spacing * 1.25;
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2019-05-18 22:54:25 +02:00
|
|
|
label_ypos = 210;
|
2019-03-19 03:51:45 +01:00
|
|
|
labels.y.power = label_ypos += label_spacing;
|
|
|
|
labels.y.value = label_ypos += label_spacing;
|
|
|
|
labels.y.voltage = label_ypos += label_spacing;
|
|
|
|
labels.y.graze = label_ypos += label_spacing;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_push();
|
2019-02-22 00:56:03 +01:00
|
|
|
r_mat_translate(HUD_X_OFFSET + HUD_X_PADDING, 0, 0);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
// Set up Extra Spell indicator opacity early; some other elements depend on it
|
|
|
|
float extraspell_alpha = 0;
|
|
|
|
float extraspell_fadein = 1;
|
2017-09-13 07:24:29 +02:00
|
|
|
|
|
|
|
if(global.boss && global.boss->current && global.boss->current->type == AT_ExtraSpell) {
|
2019-02-22 00:56:03 +01:00
|
|
|
extraspell_fadein = min(1, -min(0, global.frames - global.boss->current->starttime) / (float)ATTACK_START_DELAY);
|
|
|
|
float fadeout = global.boss->current->finished * (1 - (global.boss->current->endtime - global.frames) / (float)ATTACK_END_DELAY_EXTRA) / 0.74;
|
|
|
|
float fade = max(extraspell_fadein, fadeout);
|
|
|
|
extraspell_alpha = 1 - fade;
|
2017-09-13 07:24:29 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
labels.lb_baseclr.r = 1 - extraspell_alpha;
|
|
|
|
labels.lb_baseclr.g = 1 - extraspell_alpha;
|
|
|
|
labels.lb_baseclr.b = 1 - extraspell_alpha;
|
|
|
|
labels.lb_baseclr.a = 1 - extraspell_alpha * 0.5;
|
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
// Lives and Bombs
|
|
|
|
if(global.stage->type != STAGE_SPELL) {
|
2019-01-04 23:59:39 +01:00
|
|
|
r_mat_push();
|
2019-05-18 22:46:39 +02:00
|
|
|
r_mat_translate(0, font_get_descent(get_font("standard")), 0);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
Sprite *spr_life = get_sprite("hud/heart");
|
|
|
|
Sprite *spr_bomb = get_sprite("hud/star");
|
|
|
|
|
|
|
|
float spacing = 1;
|
2019-02-22 00:56:03 +01:00
|
|
|
float pos_lives = HUD_EFFECTIVE_WIDTH - spr_life->w * (PLR_MAX_LIVES - 0.5) - spacing * (PLR_MAX_LIVES - 1);
|
|
|
|
float pos_bombs = HUD_EFFECTIVE_WIDTH - spr_bomb->w * (PLR_MAX_BOMBS - 0.5) - spacing * (PLR_MAX_BOMBS - 1);
|
|
|
|
|
2019-03-19 03:51:45 +01:00
|
|
|
labels.y_ofs.lives_display = 0 /* spr_life->h * -0.25 */;
|
|
|
|
labels.y_ofs.bombs_display = 0 /* spr_bomb->h * -0.25 */;
|
|
|
|
|
|
|
|
labels.y_ofs.lives_text = labels.y_ofs.lives_display + spr_life->h;
|
|
|
|
labels.y_ofs.bombs_text = labels.y_ofs.bombs_display + spr_bomb->h;
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
labels.x.next_life = pos_lives - spr_life->w * 0.5;
|
2019-03-19 03:51:45 +01:00
|
|
|
labels.x.next_bomb = pos_bombs - spr_bomb->w * 0.5;
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
draw_fragments(&(DrawFragmentsParams) {
|
|
|
|
.fill = spr_life,
|
2019-03-19 03:51:45 +01:00
|
|
|
.pos = { pos_lives, labels.y.lives + labels.y_ofs.lives_display },
|
2019-01-04 23:59:39 +01:00
|
|
|
.origin_offset = { 0, 0 },
|
|
|
|
.limits = { PLR_MAX_LIVES, PLR_MAX_LIFE_FRAGMENTS },
|
|
|
|
.filled = { global.plr.lives, global.plr.life_fragments },
|
2019-02-22 00:56:03 +01:00
|
|
|
.alpha = 1,
|
|
|
|
.spacing = spacing,
|
2019-01-04 23:59:39 +01:00
|
|
|
.color = {
|
2019-02-22 00:56:03 +01:00
|
|
|
.fill = color_mul(RGBA(1, 1, 1, 1), &labels.lb_baseclr),
|
2019-01-04 23:59:39 +01:00
|
|
|
.back = RGBA(0, 0, 0, 0.5),
|
|
|
|
.frag = RGBA(0.5, 0.5, 0.6, 0.5),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
draw_fragments(&(DrawFragmentsParams) {
|
|
|
|
.fill = spr_bomb,
|
2019-03-19 03:51:45 +01:00
|
|
|
.pos = { pos_bombs, labels.y.bombs + labels.y_ofs.bombs_display },
|
2019-01-04 23:59:39 +01:00
|
|
|
.origin_offset = { 0, 0.05 },
|
|
|
|
.limits = { PLR_MAX_BOMBS, PLR_MAX_BOMB_FRAGMENTS },
|
|
|
|
.filled = { global.plr.bombs, global.plr.bomb_fragments },
|
2019-02-22 00:56:03 +01:00
|
|
|
.alpha = 1,
|
|
|
|
.spacing = spacing,
|
2019-01-04 23:59:39 +01:00
|
|
|
.color = {
|
2019-02-22 00:56:03 +01:00
|
|
|
.fill = color_mul(RGBA(1, 1, 1, 1), &labels.lb_baseclr),
|
|
|
|
.back = color_mul(RGBA(0, 0, 0, 0.5), &labels.lb_baseclr),
|
|
|
|
.frag = color_mul(RGBA(0.5, 0.5, 0.6, 0.5), &labels.lb_baseclr),
|
2019-01-04 23:59:39 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
r_mat_pop();
|
2017-09-13 07:24:29 +02:00
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
// Difficulty indicator
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite = difficulty_sprite_name(global.diff),
|
2019-02-22 00:56:03 +01:00
|
|
|
.pos = { HUD_EFFECTIVE_WIDTH * 0.5, 400 },
|
2019-01-04 23:59:39 +01:00
|
|
|
.scale.both = 0.6,
|
|
|
|
.shader = "sprite_default",
|
|
|
|
});
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
// Power/Item/Voltage icons
|
2019-01-04 23:59:39 +01:00
|
|
|
r_mat_push();
|
2019-05-18 22:54:25 +02:00
|
|
|
r_mat_translate(HUD_X_SECONDARY_OFS_ICON, font_get_descent(get_font("standard")) * 0.5 - 1, 0);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 2, labels.y.power + 2 },
|
|
|
|
.sprite = "item/power",
|
|
|
|
.shader = "sprite_default",
|
|
|
|
.color = RGBA(0, 0, 0, 0.5),
|
|
|
|
});
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 0, labels.y.power },
|
|
|
|
.sprite = "item/power",
|
|
|
|
.shader = "sprite_default",
|
|
|
|
});
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 2, labels.y.value + 2 },
|
|
|
|
.sprite = "item/point",
|
|
|
|
.shader = "sprite_default",
|
|
|
|
.color = RGBA(0, 0, 0, 0.5),
|
|
|
|
});
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 0, labels.y.value },
|
|
|
|
.sprite = "item/point",
|
|
|
|
.shader = "sprite_default",
|
|
|
|
});
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 2, labels.y.voltage + 2 },
|
|
|
|
.sprite = "item/voltage",
|
|
|
|
.shader = "sprite_default",
|
|
|
|
.color = RGBA(0, 0, 0, 0.5),
|
|
|
|
});
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 0, labels.y.voltage },
|
|
|
|
.sprite = "item/voltage",
|
|
|
|
.shader = "sprite_default",
|
|
|
|
});
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_mat_pop();
|
|
|
|
stage_draw_hud_text(&labels);
|
2017-11-23 03:25:53 +01:00
|
|
|
|
|
|
|
// Extra Spell indicator
|
2019-02-22 00:56:03 +01:00
|
|
|
if(extraspell_alpha > 0) {
|
|
|
|
float s2 = max(0, swing(extraspell_alpha, 3));
|
|
|
|
r_state_push();
|
|
|
|
r_shader("text_default");
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_push();
|
2019-04-23 22:14:14 +02:00
|
|
|
r_mat_translate(lerp(-HUD_X_OFFSET - HUD_X_PADDING, HUD_EFFECTIVE_WIDTH * 0.5, pow(2*extraspell_fadein-1, 2)), 128, 0);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_color(RGBA_MUL_ALPHA(0.3, 0.6, 0.7, 0.7 * extraspell_alpha));
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_rotate_deg(-25 + 360 * (1-s2), 0, 0, 1);
|
|
|
|
r_mat_scale(s2, s2, 0);
|
2018-06-29 23:36:51 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
Font *font = get_font("big");
|
|
|
|
|
2019-01-04 23:59:39 +01:00
|
|
|
// TODO: replace this with a shader
|
2019-04-23 22:14:14 +02:00
|
|
|
text_draw("Voltage \n Overdrive!", &(TextParams) { .pos = { 1, 1 }, .font_ptr = font, .align = ALIGN_CENTER });
|
|
|
|
text_draw("Voltage \n Overdrive!", &(TextParams) { .pos = { -1, -1 }, .font_ptr = font, .align = ALIGN_CENTER });
|
2019-02-22 00:56:03 +01:00
|
|
|
r_color4(extraspell_alpha, extraspell_alpha, extraspell_alpha, extraspell_alpha);
|
2019-04-23 22:14:14 +02:00
|
|
|
text_draw("Voltage \n Overdrive!", &(TextParams) { .pos = { 0, 0 }, .font_ptr = font, .align = ALIGN_CENTER });
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
r_mat_pop();
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-11 19:56:46 +01:00
|
|
|
if(stagedraw.framerate_graphs) {
|
2019-02-22 00:56:03 +01:00
|
|
|
stage_draw_framerate_graphs(0, 360, HUD_EFFECTIVE_WIDTH, 30);
|
2017-12-11 19:56:46 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_mat_pop();
|
|
|
|
|
2017-11-23 03:25:53 +01:00
|
|
|
// Boss indicator ("Enemy")
|
2017-09-27 11:08:32 +02:00
|
|
|
if(global.boss) {
|
|
|
|
float red = 0.5*exp(-0.5*(global.frames-global.boss->lastdamageframe)); // hit indicator
|
|
|
|
if(red > 1)
|
|
|
|
red = 0;
|
2018-04-12 16:08:48 +02:00
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite = "boss_indicator",
|
|
|
|
.shader = "sprite_default",
|
|
|
|
.pos = { VIEWPORT_X+creal(global.boss->pos), 590 },
|
|
|
|
.color = RGBA(1 - red, 1 - red, 1 - red, 1 - red),
|
|
|
|
});
|
2017-09-27 11:08:32 +02:00
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
void stage_display_clear_screen(const StageClearBonus *bonus) {
|
|
|
|
StageTextTable tbl;
|
|
|
|
stagetext_begin_table(&tbl, bonus->all_clear ? "All Clear!" : "Stage Clear!", RGB(1, 1, 1), RGB(1, 1, 1), VIEWPORT_W/2,
|
|
|
|
20, 5184000, 60, 60);
|
|
|
|
stagetext_table_add_numeric_nonzero(&tbl, "Clear bonus", bonus->base);
|
|
|
|
stagetext_table_add_numeric_nonzero(&tbl, "Life bonus", bonus->lives);
|
|
|
|
stagetext_table_add_numeric_nonzero(&tbl, "Voltage bonus", bonus->voltage);
|
|
|
|
stagetext_table_add_numeric_nonzero(&tbl, "Graze bonus", bonus->graze);
|
|
|
|
stagetext_table_add_separator(&tbl);
|
|
|
|
stagetext_table_add_numeric(&tbl, "Total", bonus->total);
|
|
|
|
stagetext_end_table(&tbl);
|
|
|
|
|
|
|
|
stagetext_add(
|
|
|
|
"Press Fire to continue",
|
|
|
|
VIEWPORT_W/2 + VIEWPORT_H*0.7*I,
|
|
|
|
ALIGN_CENTER,
|
|
|
|
get_font("standard"),
|
|
|
|
RGB(1, 0.5, 0),
|
|
|
|
tbl.delay,
|
|
|
|
tbl.lifetime,
|
|
|
|
tbl.fadeintime,
|
|
|
|
tbl.fadeouttime
|
|
|
|
);
|
|
|
|
|
|
|
|
stagedraw.clear_screen.target_alpha = 1;
|
|
|
|
}
|