2017-04-07 14:20:45 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2017-04-07 14:20:45 +02:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2024-05-16 23:30:41 +02:00
|
|
|
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
|
2017-04-07 14:20:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stagedraw.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
|
2018-04-13 21:13:48 +02:00
|
|
|
#include "entity.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "events.h"
|
|
|
|
#include "global.h"
|
2021-05-30 03:26:21 +02:00
|
|
|
#include "replay/struct.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "resource/postprocess.h"
|
|
|
|
#include "stageobjects.h"
|
|
|
|
#include "stagetext.h"
|
|
|
|
#include "util/env.h"
|
|
|
|
#include "util/fbmgr.h"
|
|
|
|
#include "util/graphics.h"
|
|
|
|
#include "video.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
|
|
|
|
|
2021-05-14 05:28:16 +02:00
|
|
|
#define SPELL_INTRO_DURATION 120
|
|
|
|
#define SPELL_INTRO_TIME_FACTOR 0.8
|
|
|
|
|
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;
|
|
|
|
} shaders;
|
|
|
|
|
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;
|
2020-04-13 13:26:14 +02:00
|
|
|
FBPair *current_postprocess_fbpair;
|
2018-07-04 10:36:16 +02:00
|
|
|
|
2019-08-25 01:28:46 +02:00
|
|
|
ManagedFramebufferGroup *mfb_group;
|
2020-03-25 07:52:18 +01:00
|
|
|
StageDrawEvents events;
|
|
|
|
|
2020-05-16 22:42:22 +02:00
|
|
|
struct {
|
|
|
|
float alpha;
|
|
|
|
float target_alpha;
|
|
|
|
} clear_screen;
|
|
|
|
|
|
|
|
bool framerate_graphs;
|
|
|
|
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
|
|
|
|
2024-04-29 00:42:33 +02:00
|
|
|
bool stage_draw_is_initialized(void) {
|
|
|
|
return stagedraw.mfb_group;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-09-23 21:56:34 +02:00
|
|
|
scale = max(0.1, scale);
|
2018-07-04 10:36:16 +02:00
|
|
|
*w = round(VIEWPORT_W * scale);
|
|
|
|
*h = round(VIEWPORT_H * scale);
|
|
|
|
}
|
|
|
|
|
2019-08-25 01:28:46 +02:00
|
|
|
typedef struct StageFramebufferResizeParams {
|
|
|
|
struct { float worst, best; } scale;
|
|
|
|
StageFBPair scaling_base;
|
|
|
|
int refs;
|
|
|
|
} StageFramebufferResizeParams;
|
2018-08-11 21:13:48 +02:00
|
|
|
|
2019-08-25 01:28:46 +02:00
|
|
|
static void stage_framebuffer_resize_strategy(void *userdata, IntExtent *out_dimensions, FloatRect *out_viewport) {
|
|
|
|
StageFramebufferResizeParams *rp = userdata;
|
|
|
|
set_fb_size(rp->scaling_base, &out_dimensions->w, &out_dimensions->h, rp->scale.worst, rp->scale.best);
|
|
|
|
*out_viewport = (FloatRect) { 0, 0, out_dimensions->w, out_dimensions->h };
|
|
|
|
}
|
2018-08-11 21:13:48 +02:00
|
|
|
|
2019-08-25 01:28:46 +02:00
|
|
|
static void stage_framebuffer_resize_strategy_cleanup(void *userdata) {
|
|
|
|
StageFramebufferResizeParams *rp = userdata;
|
|
|
|
if(--rp->refs <= 0) {
|
2023-01-09 04:19:31 +01:00
|
|
|
mem_free(rp);
|
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)) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-25 01:28:46 +02:00
|
|
|
static void stage_draw_fbpair_create(
|
|
|
|
FBPair *pair,
|
|
|
|
int num_attachments,
|
|
|
|
FBAttachmentConfig *attachments,
|
|
|
|
const StageFramebufferResizeParams *resize_params,
|
|
|
|
const char *name
|
|
|
|
) {
|
|
|
|
StageFramebufferResizeParams *rp = memdup(resize_params, sizeof(*resize_params));
|
|
|
|
rp->refs = 2;
|
|
|
|
|
|
|
|
FramebufferConfig fbconf = { 0 };
|
|
|
|
fbconf.attachments = attachments;
|
|
|
|
fbconf.num_attachments = num_attachments;
|
|
|
|
fbconf.resize_strategy.resize_func = stage_framebuffer_resize_strategy;
|
|
|
|
fbconf.resize_strategy.userdata = rp;
|
|
|
|
fbconf.resize_strategy.cleanup_func = stage_framebuffer_resize_strategy_cleanup;
|
|
|
|
fbmgr_group_fbpair_create(stagedraw.mfb_group, name, &fbconf, pair);
|
|
|
|
}
|
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
static void stage_draw_setup_framebuffers(void) {
|
|
|
|
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-08-25 01:28:46 +02:00
|
|
|
StageFramebufferResizeParams rp_fg = { .scaling_base = FBPAIR_FG, .scale.best = 1, .scale.worst = 1 };
|
|
|
|
StageFramebufferResizeParams rp_fg_aux = { .scaling_base = FBPAIR_FG_AUX, .scale.best = 1, .scale.worst = 1 };
|
|
|
|
StageFramebufferResizeParams rp_bg = { .scaling_base = FBPAIR_BG, .scale.best = 1, .scale.worst = 1 };
|
|
|
|
StageFramebufferResizeParams rp_bg_aux = { .scaling_base = FBPAIR_BG_AUX, .scale.best = 1, .scale.worst = 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));
|
|
|
|
|
2020-08-15 13:51:12 +02:00
|
|
|
a_depth->tex_params.type = TEX_TYPE_DEPTH;
|
2019-08-25 01:28:46 +02:00
|
|
|
|
2018-07-04 10:36:16 +02:00
|
|
|
// Foreground: 1 RGB texture per FB
|
2019-01-04 23:59:39 +01:00
|
|
|
a_color->tex_params.type = TEX_TYPE_RGB_16;
|
2019-08-25 01:28:46 +02:00
|
|
|
stage_draw_fbpair_create(stagedraw.fb_pairs + FBPAIR_FG, 1, a, &rp_fg, "Stage FG");
|
2018-07-04 10:36:16 +02:00
|
|
|
|
|
|
|
// Foreground auxiliary: 1 RGBA texture per FB
|
2019-08-25 01:28:46 +02:00
|
|
|
a_color->tex_params.type = TEX_TYPE_RGBA_8;
|
|
|
|
stage_draw_fbpair_create(stagedraw.fb_pairs + FBPAIR_FG_AUX, 1, a, &rp_fg_aux, "Stage FG AUX");
|
2018-07-04 10:36:16 +02:00
|
|
|
|
2021-10-20 22:53:24 +02:00
|
|
|
// Background: 1 HDR RGBA texture + depth per FB
|
|
|
|
a_color->tex_params.type = TEX_TYPE_RGBA_16_FLOAT;
|
2019-08-25 01:28:46 +02:00
|
|
|
stage_draw_fbpair_create(stagedraw.fb_pairs + FBPAIR_BG, 2, a, &rp_bg, "Stage BG");
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
// Background auxiliary: 1 RGBA texture per FB
|
|
|
|
a_color->tex_params.type = TEX_TYPE_RGBA_8;
|
2019-08-25 01:28:46 +02:00
|
|
|
stage_draw_fbpair_create(stagedraw.fb_pairs + FBPAIR_BG_AUX, 1, a, &rp_bg_aux, "Stage BG AUX");
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
// 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-08-25 01:28:46 +02:00
|
|
|
static Framebuffer *add_custom_framebuffer(
|
|
|
|
const char *label,
|
|
|
|
StageFBPair fbtype,
|
|
|
|
float scale_worst,
|
|
|
|
float scale_best,
|
|
|
|
uint num_attachments,
|
|
|
|
FBAttachmentConfig attachments[num_attachments]
|
|
|
|
) {
|
|
|
|
StageFramebufferResizeParams rp = { 0 };
|
|
|
|
rp.scaling_base = fbtype;
|
|
|
|
rp.scale.worst = scale_worst;
|
|
|
|
rp.scale.best = scale_best;
|
|
|
|
|
|
|
|
FramebufferConfig fbconf = { 0 };
|
|
|
|
fbconf.attachments = attachments;
|
|
|
|
fbconf.num_attachments = num_attachments;
|
|
|
|
fbconf.resize_strategy.resize_func = stage_framebuffer_resize_strategy;
|
|
|
|
fbconf.resize_strategy.userdata = memdup(&rp, sizeof(rp));
|
|
|
|
fbconf.resize_strategy.cleanup_func = stage_framebuffer_resize_strategy_cleanup;
|
|
|
|
return fbmgr_group_framebuffer_create(stagedraw.mfb_group, label, &fbconf);
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2020-04-24 00:10:20 +02:00
|
|
|
Framebuffer *stage_add_foreground_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
2019-01-04 23:59:39 +01:00
|
|
|
return add_custom_framebuffer(label, FBPAIR_FG, scale_worst, scale_best, num_attachments, attachments);
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2020-04-24 00:10:20 +02:00
|
|
|
Framebuffer *stage_add_background_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
2019-01-04 23:59:39 +01:00
|
|
|
return add_custom_framebuffer(label, FBPAIR_BG, scale_worst, scale_best, num_attachments, attachments);
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2020-04-24 00:10:20 +02:00
|
|
|
Framebuffer *stage_add_static_framebuffer(const char *label, uint num_attachments, FBAttachmentConfig attachments[num_attachments]) {
|
|
|
|
FramebufferConfig fbconf = { 0 };
|
|
|
|
fbconf.attachments = attachments;
|
|
|
|
fbconf.num_attachments = num_attachments;
|
|
|
|
return fbmgr_group_framebuffer_create(stagedraw.mfb_group, label, &fbconf);
|
|
|
|
}
|
|
|
|
|
2018-08-11 21:13:48 +02:00
|
|
|
static void stage_draw_destroy_framebuffers(void) {
|
2019-08-25 01:28:46 +02:00
|
|
|
fbmgr_group_destroy(stagedraw.mfb_group);
|
|
|
|
stagedraw.mfb_group = NULL;
|
2018-08-11 21:13:48 +02:00
|
|
|
}
|
|
|
|
|
2023-03-22 23:41:32 +01:00
|
|
|
void stage_draw_preload(ResourceGroup *rg) {
|
|
|
|
res_group_preload(rg, RES_POSTPROCESS, RESF_OPTIONAL,
|
2018-04-12 16:08:48 +02:00
|
|
|
"viewport",
|
|
|
|
NULL);
|
|
|
|
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_SPRITE, RESF_DEFAULT,
|
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);
|
|
|
|
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_TEXTURE, RESF_DEFAULT,
|
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);
|
|
|
|
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_MODEL, RESF_DEFAULT,
|
2019-01-23 15:02:51 +01:00
|
|
|
"hud",
|
2017-11-23 03:25:53 +01:00
|
|
|
NULL);
|
|
|
|
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_SHADER_PROGRAM, RESF_DEFAULT,
|
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);
|
|
|
|
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_FONT, RESF_DEFAULT,
|
2018-06-29 23:36:51 +02:00
|
|
|
"mono",
|
|
|
|
"small",
|
|
|
|
"monosmall",
|
|
|
|
NULL);
|
2017-11-23 03:25:53 +01:00
|
|
|
|
2023-04-07 07:57:49 +02:00
|
|
|
if(stage_is_demo_mode()) {
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_SHADER_PROGRAM, RESF_DEFAULT,
|
2023-04-07 07:57:49 +02:00
|
|
|
"text_demo",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
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) {
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_SHADER_PROGRAM, RESF_DEFAULT,
|
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) {
|
2023-03-22 23:41:32 +01:00
|
|
|
res_group_preload(rg, RES_FONT, RESF_DEFAULT,
|
2018-06-29 23:36:51 +02:00
|
|
|
"monotiny",
|
|
|
|
NULL);
|
|
|
|
}
|
2019-08-25 01:28:46 +02:00
|
|
|
}
|
2018-06-29 23:36:51 +02:00
|
|
|
|
2019-08-25 01:28:46 +02:00
|
|
|
void stage_draw_init(void) {
|
2023-03-22 23:41:32 +01:00
|
|
|
stagedraw.mfb_group = fbmgr_group_create();
|
|
|
|
|
2023-03-22 23:14:10 +01:00
|
|
|
stagedraw.viewport_pp = res_get_data(RES_POSTPROCESS, "viewport", RESF_OPTIONAL);
|
2020-06-09 03:33:22 +02:00
|
|
|
stagedraw.hud_text.shader = res_shader("text_hud");
|
|
|
|
stagedraw.hud_text.font = res_font("standard");
|
|
|
|
stagedraw.shaders.fxaa = res_shader("fxaa");
|
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
|
2020-06-09 03:33:22 +02:00
|
|
|
stagedraw.dummy.tex = res_sprite("star")->tex;
|
2018-05-08 15:02:08 +02:00
|
|
|
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,
|
|
|
|
});
|
2020-03-25 07:52:18 +01:00
|
|
|
|
|
|
|
COEVENT_INIT_ARRAY(stagedraw.events);
|
2018-07-04 10:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void stage_draw_shutdown(void) {
|
2020-03-25 07:52:18 +01:00
|
|
|
COEVENT_CANCEL_ARRAY(stagedraw.events);
|
2018-07-04 10:36:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-04-13 13:26:14 +02:00
|
|
|
FBPair *stage_get_fbpair(StageFBPair id) {
|
2018-07-04 10:36:16 +02:00
|
|
|
assert(id >= 0 && id < NUM_FBPAIRS);
|
|
|
|
return stagedraw.fb_pairs + id;
|
2018-05-08 15:02:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 13:26:14 +02:00
|
|
|
FBPair *stage_get_postprocess_fbpair(void) {
|
|
|
|
return NOT_NULL(stagedraw.current_postprocess_fbpair);
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-11-22 04:37:11 +01:00
|
|
|
cmplx gsize = projectile_graze_size(p);
|
2018-05-13 15:08:58 +02:00
|
|
|
|
2023-09-20 04:14:15 +02:00
|
|
|
if(re(gsize)) {
|
2018-05-13 15:08:58 +02:00
|
|
|
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,
|
2023-09-20 04:14:15 +02:00
|
|
|
.pos = { re(p->pos), im(p->pos) },
|
2018-05-13 15:08:58 +02:00
|
|
|
.rotation.angle = p->angle + M_PI/2,
|
2023-09-20 04:14:15 +02:00
|
|
|
.scale = { .x = re(gsize), .y = im(gsize) },
|
2018-05-13 15:08:58 +02:00
|
|
|
.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,
|
2023-09-20 04:14:15 +02:00
|
|
|
.pos = { re(p->pos), im(p->pos) },
|
2018-05-08 15:02:08 +02:00
|
|
|
.rotation.angle = p->angle + M_PI/2,
|
2023-09-20 04:14:15 +02:00
|
|
|
.scale = { .x = re(p->collision_size), .y = im(p->collision_size) },
|
2018-05-13 15:08:58 +02:00
|
|
|
.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) {
|
2020-07-09 14:07:40 +02:00
|
|
|
float hurt_radius = enemy_get_hurt_radius(e);
|
|
|
|
|
|
|
|
if(hurt_radius > 0) {
|
2019-03-01 17:10:49 +01:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = &stagedraw.dummy,
|
2023-09-20 04:14:15 +02:00
|
|
|
.pos = { re(e->pos), im(e->pos) },
|
2020-07-09 14:07:40 +02:00
|
|
|
.scale = { .x = hurt_radius * 2, .y = hurt_radius * 2 },
|
2019-03-01 17:10:49 +01:00
|
|
|
.blend = BLEND_ALPHA,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-01 13:01:00 +02:00
|
|
|
if(global.boss && boss_is_player_collision_active(global.boss)) {
|
2019-03-01 17:10:49 +01:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.sprite_ptr = &stagedraw.dummy,
|
2023-09-20 04:14:15 +02:00
|
|
|
.pos = { re(global.boss->pos), im(global.boss->pos) },
|
2019-03-01 17:10:49 +01:00
|
|
|
.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,
|
2023-09-20 04:14:15 +02:00
|
|
|
.pos = { re(global.plr.pos), im(global.plr.pos) },
|
2018-05-13 15:08:58 +02:00
|
|
|
.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;
|
2023-05-09 02:50:48 +02:00
|
|
|
TextBBox bbox;
|
2018-06-29 23:36:51 +02:00
|
|
|
|
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);
|
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
text_render(buf, res_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
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_translate(w/2, h/2, 0);
|
|
|
|
r_mat_mv_scale(w, h, 1.0);
|
2018-04-12 16:08:48 +02:00
|
|
|
|
2018-09-14 09:37:20 +02:00
|
|
|
uint tw, th;
|
|
|
|
r_texture_get_size(spr.tex, 0, &tw, &th);
|
|
|
|
|
|
|
|
r_shader("spellcard_walloftext");
|
2020-04-25 04:35:22 +02:00
|
|
|
r_uniform_float("w", spr.tex_area.w);
|
|
|
|
r_uniform_float("h", spr.tex_area.h);
|
2018-04-12 16:08:48 +02:00
|
|
|
r_uniform_float("ratio", h/w);
|
2023-09-20 04:14:15 +02:00
|
|
|
r_uniform_vec2("origin", re(global.boss->pos)/h, im(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();
|
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_spellbg(int t) {
|
|
|
|
Boss *b = global.boss;
|
2019-02-22 00:56:03 +01:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_state_push();
|
2017-04-07 14:20:45 +02:00
|
|
|
b->current->draw_rule(b, t);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_state_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
|
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
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
float scale = 1;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
|
|
|
if(t < 0) {
|
2021-05-14 05:28:16 +02:00
|
|
|
scale = 1.0 - t/attacktype_start_delay(b->current->type);
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("boss_spellcircle0"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2023-09-20 04:14:15 +02:00
|
|
|
.pos = { re(b->pos), im(b->pos) },
|
2019-10-12 14:02:15 +02:00
|
|
|
.rotation.angle = global.frames * 7.0 * DEG2RAD,
|
|
|
|
.rotation.vector = { 0, 0, -1 },
|
|
|
|
.scale.both = scale,
|
|
|
|
});
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_spellbg_overlay(int t) {
|
|
|
|
Boss *b = global.boss;
|
|
|
|
|
2021-05-14 05:28:16 +02:00
|
|
|
float delay = attacktype_start_delay(b->current->type);
|
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;
|
|
|
|
|
2018-04-12 16:08:48 +02:00
|
|
|
return (
|
2021-05-14 05:28:16 +02:00
|
|
|
!global.boss->current->draw_rule
|
|
|
|
|| !attack_is_active(global.boss->current)
|
|
|
|
|| global.frames - global.boss->current->starttime < SPELL_INTRO_DURATION
|
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);
|
2024-08-28 12:54:37 +02:00
|
|
|
Texture *tex = r_framebuffer_get_attachment(fb, FRAMEBUFFER_ATTACH_COLOR0);
|
|
|
|
uint w, h;
|
|
|
|
r_texture_get_size(tex, 0, &w, &h);
|
|
|
|
r_uniform_vec2("tex_size", w, h);
|
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) {
|
2020-08-15 13:51:12 +02:00
|
|
|
Framebuffer *target_fb = r_framebuffer_current();
|
2023-04-09 04:02:31 +02:00
|
|
|
r_framebuffer_copy(target_fb, fb, BUFFER_DEPTH);
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-17 09:18:53 +02:00
|
|
|
if(ent->type == ENT_TYPE_ID(Projectile)) {
|
2019-02-22 00:56:03 +01:00
|
|
|
Projectile *p = ENT_CAST(ent, Projectile);
|
|
|
|
return p->flags & PFLAG_PLRSPECIALPARTICLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 09:18:53 +02:00
|
|
|
if(ent->type == ENT_TYPE_ID(Item)) {
|
2019-02-22 00:56:03 +01:00
|
|
|
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);
|
2024-10-03 20:12:39 +02:00
|
|
|
r_disable(RCAP_CULL_FACE);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
// 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);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_scale(VIEWPORT_W, VIEWPORT_H, 1);
|
|
|
|
r_mat_mv_translate(0.5, 0.5, 0);
|
2019-02-22 00:56:03 +01:00
|
|
|
r_draw_quad();
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2019-02-22 00:56:03 +01:00
|
|
|
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);
|
2024-10-03 20:12:39 +02:00
|
|
|
r_disable(RCAP_CULL_FACE);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
2020-04-28 02:53:08 +02:00
|
|
|
cmplx fpos = global.boss->pos;;
|
2021-12-12 11:38:55 +01:00
|
|
|
cmplx pos = fpos;
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
r_shader("boss_zoom");
|
2023-09-20 04:14:15 +02:00
|
|
|
r_uniform_vec2("blur_orig", re(pos) / VIEWPORT_W, 1-im(pos) / VIEWPORT_H);
|
|
|
|
r_uniform_vec2("fix_orig", re(fpos) / VIEWPORT_W, 1-im(fpos) / VIEWPORT_H);
|
2019-02-22 00:56:03 +01:00
|
|
|
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[]) {
|
2020-02-01 00:37:13 +01:00
|
|
|
/*
|
2019-02-22 00:56:03 +01:00
|
|
|
config_get_int(CONFIG_FXAA)
|
|
|
|
? fxaa_rule
|
|
|
|
: copydepth_rule,
|
|
|
|
NULL
|
2020-02-01 00:37:13 +01:00
|
|
|
*/
|
|
|
|
copydepth_rule, NULL
|
2019-02-22 00:56:03 +01:00
|
|
|
}, 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);
|
2020-02-01 00:37:13 +01:00
|
|
|
|
|
|
|
// anti-aliasing
|
|
|
|
if(config_get_int(CONFIG_FXAA)) {
|
|
|
|
apply_shader_rules((ShaderRule[]) { fxaa_rule, NULL } , fbos);
|
|
|
|
}
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2021-05-14 05:28:16 +02:00
|
|
|
if(b && b->current && b->current->draw_rule && b->current->starttime > 0) {
|
2019-02-22 00:56:03 +01:00
|
|
|
int t = global.frames - b->current->starttime;
|
2021-05-14 05:28:16 +02:00
|
|
|
int delay = attacktype_start_delay(b->current->type);
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2021-05-14 05:28:16 +02:00
|
|
|
bool trans_intro = t + delay < SPELL_INTRO_DURATION;
|
|
|
|
bool trans_outro = attack_has_finished(b->current);
|
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-11-22 04:37:11 +01:00
|
|
|
cmplx pos = b->pos;
|
2019-02-22 00:56:03 +01:00
|
|
|
float ratio = (float)VIEWPORT_H/VIEWPORT_W;
|
2017-04-07 14:20:45 +02:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(trans_intro) {
|
|
|
|
r_shader("spellcard_intro");
|
|
|
|
r_uniform_float("ratio", ratio);
|
2023-09-20 04:14:15 +02:00
|
|
|
r_uniform_vec2("origin", re(pos) / VIEWPORT_W, 1 - im(pos) / VIEWPORT_H);
|
2021-05-14 05:28:16 +02:00
|
|
|
r_uniform_float("t", SPELL_INTRO_TIME_FACTOR * (t + delay) / (float)SPELL_INTRO_DURATION);
|
2019-02-22 00:56:03 +01:00
|
|
|
} 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);
|
2023-09-20 04:14:15 +02:00
|
|
|
r_uniform_vec2("origin", re(pos) / VIEWPORT_W, 1 - im(pos) / VIEWPORT_H);
|
2023-09-23 21:56:34 +02:00
|
|
|
r_uniform_float("t", max(0, tn / (float)delay + 1));
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
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);
|
2023-04-09 04:00:00 +02:00
|
|
|
r_clear(BUFFER_ALL, RGBA(0, 0, 0, 1), 1);
|
2018-04-12 16:08:48 +02:00
|
|
|
|
|
|
|
if(should_draw_stage_bg()) {
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
2018-04-12 16:08:48 +02:00
|
|
|
r_enable(RCAP_DEPTH_TEST);
|
2024-10-03 20:12:39 +02:00
|
|
|
r_enable(RCAP_CULL_FACE);
|
2017-04-07 14:20:45 +02:00
|
|
|
stage->procs->draw();
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_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);
|
2024-10-03 20:12:39 +02:00
|
|
|
r_disable(RCAP_CULL_FACE);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
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();
|
2023-04-09 04:00:00 +02:00
|
|
|
r_framebuffer_clear(staging, BUFFER_COLOR, RGBA(0, 0, 0, 0), 1);
|
2019-02-22 00:56:03 +01:00
|
|
|
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) {
|
2020-04-17 09:18:53 +02:00
|
|
|
if(ent->type == ENT_TYPE_ID(Projectile)) {
|
2018-04-13 21:13:48 +02:00
|
|
|
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_blend(BLEND_PREMUL_ALPHA);
|
2024-10-03 19:57:11 +02:00
|
|
|
r_disable(RCAP_CULL_FACE);
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
if(global.boss) {
|
|
|
|
draw_boss_overlay(global.boss);
|
|
|
|
}
|
|
|
|
|
2024-10-03 19:57:11 +02:00
|
|
|
player_draw_overlay(&global.plr);
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
if(stagedraw.clear_screen.alpha > 0) {
|
|
|
|
fade_out(stagedraw.clear_screen.alpha * 0.5);
|
|
|
|
}
|
|
|
|
|
2017-04-07 14:20:45 +02:00
|
|
|
stagetext_draw();
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_pop();
|
2017-04-07 14:20:45 +02:00
|
|
|
}
|
|
|
|
|
2019-08-09 20:42:04 +02:00
|
|
|
static void postprocess_prepare(Framebuffer *fb, ShaderProgram *s, void *arg) {
|
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);
|
2023-09-20 04:14:15 +02:00
|
|
|
r_uniform_vec2("player", re(global.plr.pos), VIEWPORT_H - im(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) {
|
2020-05-16 22:42:22 +02:00
|
|
|
float s = stage_get_view_shake_strength();
|
|
|
|
|
|
|
|
if(s > 0) {
|
|
|
|
// s = log1pf(s);
|
|
|
|
s = sqrtf(s);
|
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_translate(
|
2020-05-16 22:42:22 +02:00
|
|
|
s * sin(global.frames),
|
|
|
|
s * sin(global.frames * 1.1 + 3),
|
2019-04-11 11:27:21 +02:00
|
|
|
0
|
|
|
|
);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_scale(
|
2020-05-16 22:42:22 +02:00
|
|
|
1 + 2 * s / VIEWPORT_W,
|
|
|
|
1 + 2 * s / VIEWPORT_H,
|
2019-04-11 11:27:21 +02:00
|
|
|
1
|
|
|
|
);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_translate(
|
2020-05-16 22:42:22 +02:00
|
|
|
-s,
|
|
|
|
-s,
|
2019-04-11 11:27:21 +02:00
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void end_viewport_shake(void) {
|
2020-05-16 22:42:22 +02:00
|
|
|
if(stage_get_view_shake_strength() > 0) {
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2019-04-11 11:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2020-05-16 22:42:22 +02:00
|
|
|
if(stage_get_view_shake_strength() > 0) {
|
2019-04-14 15:15:40 +02:00
|
|
|
shake_suppressed = 2;
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push_identity();
|
2019-04-14 15:15:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void stage_draw_end_noshake(void) {
|
|
|
|
assert(shake_suppressed);
|
|
|
|
|
2020-05-16 22:42:22 +02:00
|
|
|
if(stage_get_view_shake_strength() > 0) {
|
2019-04-14 15:15:40 +02:00
|
|
|
// 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);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2019-04-14 15:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_scale(1/facw, 1/fach, 1);
|
|
|
|
r_mat_mv_translate(roundf(facw * VIEWPORT_X), roundf(fach * VIEWPORT_Y), 0);
|
|
|
|
r_mat_mv_scale(roundf(scale * VIEWPORT_W), roundf(scale * VIEWPORT_H), 1);
|
|
|
|
r_mat_mv_translate(0.5, 0.5, 0);
|
2019-04-11 11:27:21 +02:00
|
|
|
r_draw_quad();
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_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
|
|
|
|
2020-03-25 07:52:18 +01:00
|
|
|
coevent_signal(&stagedraw.events.background_drawn);
|
2017-04-07 14:20:45 +02:00
|
|
|
} else if(!key_nobg) {
|
2023-04-09 04:00:00 +02:00
|
|
|
r_clear(BUFFER_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
|
|
|
|
2020-04-13 13:26:14 +02:00
|
|
|
stagedraw.current_postprocess_fbpair = foreground;
|
|
|
|
|
|
|
|
coevent_signal(&stagedraw.events.postprocess_before_overlay);
|
|
|
|
|
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();
|
|
|
|
|
2020-04-13 13:26:14 +02:00
|
|
|
coevent_signal(&stagedraw.events.postprocess_after_overlay);
|
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
// 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,
|
2019-08-09 20:42:04 +02:00
|
|
|
VIEWPORT_H,
|
|
|
|
NULL
|
2017-04-07 14:20:45 +02:00
|
|
|
);
|
|
|
|
|
2020-04-13 13:26:14 +02:00
|
|
|
stagedraw.current_postprocess_fbpair = NULL;
|
|
|
|
|
2018-04-26 01:50:48 +02:00
|
|
|
// prepare for 2D rendering into the main framebuffer (actual screen)
|
2019-08-09 20:42:04 +02:00
|
|
|
r_framebuffer(video_get_screen_framebuffer());
|
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
|
|
|
};
|
|
|
|
|
2023-05-09 02:50:48 +02:00
|
|
|
static void draw_numeric_callback(Font *font, charcode_t charcode, SpriteInstanceAttribs *spr_attribs, 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-10-03 01:49:10 +02:00
|
|
|
spr_attribs->rgba = *st->color1;
|
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) {
|
2020-06-09 03:33:22 +02:00
|
|
|
Font *fnt_int = res_font("standard");
|
|
|
|
Font *fnt_fract = res_font("small");
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2022-10-03 20:36:21 +02:00
|
|
|
int pw = global.plr.power_stored;
|
2019-02-22 00:56:03 +01:00
|
|
|
|
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);
|
|
|
|
|
2022-10-03 20:36:21 +02:00
|
|
|
if(pw <= PLR_MAX_POWER_EFFECTIVE) {
|
2019-02-22 00:56:03 +01:00
|
|
|
c_whole = &stagedraw.hud_text.color.active;
|
|
|
|
c_fract = &stagedraw.hud_text.color.inactive;
|
2022-10-03 20:36:21 +02:00
|
|
|
} else if(pw - PLR_MAX_POWER_EFFECTIVE < 100) {
|
2019-02-22 00:56:03 +01:00
|
|
|
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(
|
2022-10-03 20:36:21 +02:00
|
|
|
PLR_MAX_POWER_EFFECTIVE / 100.0,
|
2019-01-04 23:59:39 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-07-30 06:22:14 +02:00
|
|
|
static void stage_draw_hud_score(Alignment a, float xpos, float ypos, char *buf, size_t bufsize, uint64_t score) {
|
2019-01-04 23:59:39 +01:00
|
|
|
format_huge_num(10, score, bufsize, buf);
|
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
Font *fnt = res_font("standard");
|
2019-01-04 23:59:39 +01:00
|
|
|
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) {
|
2023-04-03 03:49:39 +02:00
|
|
|
char buf[128];
|
2024-06-05 21:58:58 +02:00
|
|
|
auto objpools = &stage_objects.pools.as_array;
|
|
|
|
MemArena *arena = &stage_objects.arena;
|
2023-04-03 03:49:39 +02:00
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
Font *font = res_font("monotiny");
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2018-06-29 23:36:51 +02:00
|
|
|
ShaderProgram *sh_prev = r_shader_current();
|
2023-04-03 03:49:39 +02:00
|
|
|
r_shader("text_hud");
|
|
|
|
|
|
|
|
float lineskip = font_get_lineskip(font);
|
|
|
|
|
|
|
|
text_draw("Arena memory:", &(TextParams) {
|
|
|
|
.pos = { x, y },
|
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_LEFT,
|
|
|
|
});
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"%zukb | %5zukb",
|
|
|
|
arena->total_used / 1024,
|
|
|
|
arena->total_allocated / 1024
|
|
|
|
);
|
|
|
|
|
|
|
|
text_draw(buf, &(TextParams) {
|
|
|
|
.pos = { x + width, y },
|
|
|
|
.font_ptr = font,
|
|
|
|
.align = ALIGN_RIGHT,
|
|
|
|
});
|
|
|
|
|
|
|
|
y += lineskip * 1.5;
|
|
|
|
|
2024-06-05 21:16:02 +02:00
|
|
|
const char *const names[] = {
|
2024-06-05 21:58:58 +02:00
|
|
|
#define GET_POOL_NAME(t, n) #t,
|
|
|
|
OBJECT_POOLS(GET_POOL_NAME)
|
|
|
|
#undef GET_POOL_NAME
|
2024-06-05 21:16:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(ARRAY_SIZE(*objpools) == ARRAY_SIZE(names));
|
|
|
|
|
2023-04-03 03:49:39 +02:00
|
|
|
for(int i = 0; i < ARRAY_SIZE(*objpools); ++i) {
|
2024-06-05 18:35:08 +02:00
|
|
|
MemPool *p = &(*objpools)[i];
|
2023-04-03 03:49:39 +02:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%u | %7u", p->num_used, p->num_allocated);
|
|
|
|
|
2024-06-05 21:16:02 +02:00
|
|
|
text_draw(names[i], &(TextParams) {
|
2018-06-29 23:36:51 +02:00
|
|
|
.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
|
|
|
|
2023-04-03 03:49:39 +02:00
|
|
|
y += lineskip;
|
2017-12-13 20:05:12 +01:00
|
|
|
}
|
2023-04-03 03:49:39 +02: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) {
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_translate(x + w/2, y + h/2, 0);
|
|
|
|
r_mat_mv_scale(w, h, 1);
|
2018-05-03 19:51:10 +02:00
|
|
|
r_draw_quad();
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2018-05-03 19:51:10 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_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);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
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);
|
2020-06-09 03:33:22 +02:00
|
|
|
font = res_font("small");
|
2019-02-22 00:56:03 +01:00
|
|
|
|
|
|
|
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);
|
2020-06-09 03:33:22 +02:00
|
|
|
font = res_font("small");
|
2019-03-19 03:51:45 +01:00
|
|
|
|
|
|
|
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-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_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);
|
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
font = res_font("standard");
|
2019-02-22 00:56:03 +01:00
|
|
|
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,
|
2019-10-03 01:49:10 +02:00
|
|
|
&(struct glyphcb_state) { &stagedraw.hud_text.color.inactive, &stagedraw.hud_text.color.active },
|
2019-01-04 23:59:39 +01:00
|
|
|
}
|
|
|
|
});
|
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,
|
2019-10-03 01:49:10 +02:00
|
|
|
&(struct glyphcb_state) { &stagedraw.hud_text.color.inactive, &stagedraw.hud_text.color.active },
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2019-10-03 01:49:10 +02:00
|
|
|
&(struct glyphcb_state) { &stagedraw.hud_text.color.inactive, &stagedraw.hud_text.color.active },
|
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-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2019-01-04 23:59:39 +01:00
|
|
|
|
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),
|
|
|
|
});
|
|
|
|
}
|
2023-04-03 03:49:39 +02:00
|
|
|
|
|
|
|
if(stagedraw.objpool_stats) {
|
|
|
|
stage_draw_hud_objpool_stats(0, 440, HUD_EFFECTIVE_WIDTH);
|
|
|
|
}
|
2019-02-22 00:56:03 +01:00
|
|
|
}
|
|
|
|
|
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
|
2023-05-26 00:58:32 +02:00
|
|
|
snprintf(buf, sizeof(buf), "%.2f lfps, %.2f rfps, frames: %d (%d:%02d) ",
|
2017-12-26 12:07:40 +01:00
|
|
|
global.fps.logic.fps,
|
|
|
|
global.fps.render.fps,
|
2020-02-01 00:37:13 +01:00
|
|
|
global.frames,
|
|
|
|
global.frames / 3600,
|
|
|
|
(global.frames % 3600) / 60
|
2017-12-26 12:07:40 +01:00
|
|
|
);
|
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
|
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
font = res_font("monosmall");
|
2018-06-29 23:36:51 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-04-07 07:57:49 +02:00
|
|
|
ReplayState *rst = &global.replay.input;
|
|
|
|
if(rst->replay != NULL && (!stage_is_demo_mode() || rst->play.desync_frame >= 0)) {
|
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?
|
|
|
|
|
2021-05-30 03:26:21 +02:00
|
|
|
snprintf(buf, sizeof(buf), "Replay: %s (%i fps)", rst->replay->playername, rst->play.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
|
|
|
|
2021-05-30 03:26:21 +02:00
|
|
|
if(rst->play.desync_frame >= 0) {
|
|
|
|
snprintf(buf, sizeof(buf), " (DESYNCED near frame #%i)", rst->play.desync_frame);
|
2017-11-23 03:25:53 +01:00
|
|
|
|
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);
|
2024-08-22 13:31:53 +02:00
|
|
|
r_uniform_float_array("points", 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) {
|
2020-05-09 08:25:38 +02: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);
|
2024-08-22 13:31:53 +02:00
|
|
|
r_uniform_float_array("points", 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);
|
2024-08-22 13:31:53 +02:00
|
|
|
r_uniform_float_array("points", 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-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
2020-06-06 17:27:08 +02:00
|
|
|
r_mat_mv_translate(SCREEN_W * 0.5, SCREEN_H * 0.5, 0);
|
|
|
|
r_mat_mv_scale(SCREEN_W, SCREEN_W, 1);
|
2019-01-23 15:02:51 +01:00
|
|
|
r_shader_standard();
|
|
|
|
r_uniform_sampler("tex", "hud");
|
|
|
|
r_draw_model("hud");
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_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
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_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) {
|
2023-09-23 21:56:34 +02:00
|
|
|
extraspell_fadein = min(1, -min(0, global.frames - global.boss->current->starttime) / (float)ATTACK_START_DELAY);
|
2021-05-14 05:28:16 +02:00
|
|
|
|
|
|
|
float fadeout;
|
|
|
|
|
|
|
|
if(attack_has_finished(global.boss->current)) {
|
|
|
|
fadeout = (1 - (global.boss->current->endtime - global.frames) / (float)ATTACK_END_DELAY_EXTRA) / 0.74;
|
|
|
|
} else {
|
|
|
|
fadeout = 0;
|
|
|
|
}
|
|
|
|
|
2023-09-23 21:56:34 +02:00
|
|
|
float fade = max(extraspell_fadein, fadeout);
|
2019-02-22 00:56:03 +01:00
|
|
|
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-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
2020-06-09 03:33:22 +02:00
|
|
|
r_mat_mv_translate(0, font_get_descent(res_font("standard")), 0);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
Sprite *spr_life = res_sprite("hud/heart");
|
|
|
|
Sprite *spr_bomb = res_sprite("hud/star");
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_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) {
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_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,
|
2024-09-22 21:06:57 +02:00
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2019-01-04 23:59:39 +01:00
|
|
|
});
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
// Power/Item/Voltage icons
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
2020-06-09 03:33:22 +02:00
|
|
|
r_mat_mv_translate(HUD_X_SECONDARY_OFS_ICON, font_get_descent(res_font("standard")) * 0.5 - 1, 0);
|
2019-01-04 23:59:39 +01:00
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 2, labels.y.power + 2 },
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("item/power"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2019-01-04 23:59:39 +01:00
|
|
|
.color = RGBA(0, 0, 0, 0.5),
|
|
|
|
});
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 0, labels.y.power },
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("item/power"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2019-01-04 23:59:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 2, labels.y.value + 2 },
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("item/point"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2019-01-04 23:59:39 +01:00
|
|
|
.color = RGBA(0, 0, 0, 0.5),
|
|
|
|
});
|
|
|
|
|
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 0, labels.y.value },
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("item/point"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2019-01-04 23:59:39 +01:00
|
|
|
});
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.pos = { 2, labels.y.voltage + 2 },
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("item/voltage"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2019-02-22 00:56:03 +01:00
|
|
|
.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 },
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("item/voltage"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2019-02-22 00:56:03 +01:00
|
|
|
});
|
2019-01-04 23:59:39 +01:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2019-02-22 00:56:03 +01:00
|
|
|
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) {
|
2023-09-23 21:56:34 +02:00
|
|
|
float s2 = max(0, swing(extraspell_alpha, 3));
|
2019-02-22 00:56:03 +01:00
|
|
|
r_state_push();
|
|
|
|
r_shader("text_default");
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_translate(lerp(-HUD_X_OFFSET - HUD_X_PADDING, HUD_EFFECTIVE_WIDTH * 0.5, pow(2*extraspell_fadein-1, 2)), 128, 0);
|
|
|
|
r_mat_mv_rotate((360 * (1-s2) - 25) * DEG2RAD, 0, 0, 1);
|
|
|
|
r_mat_mv_scale(s2, s2, 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-06-29 23:36:51 +02:00
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
Font *font = res_font("big");
|
2019-02-22 00:56:03 +01:00
|
|
|
|
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
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_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-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2019-02-22 00:56:03 +01:00
|
|
|
|
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;
|
2019-08-09 20:42:04 +02:00
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
2024-09-22 21:06:57 +02:00
|
|
|
.sprite_ptr = res_sprite("boss_indicator"),
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
2023-09-20 04:14:15 +02:00
|
|
|
.pos = { VIEWPORT_X+re(global.boss->pos), 590 },
|
2019-07-03 19:50:43 +02:00
|
|
|
.color = RGBA(1 - red, 1 - red, 1 - red, 1 - red),
|
|
|
|
});
|
2017-09-27 11:08:32 +02:00
|
|
|
}
|
2023-04-07 07:57:49 +02:00
|
|
|
|
|
|
|
// Demo indicator
|
|
|
|
if(stage_is_demo_mode()) {
|
|
|
|
cmplxf pos = CMPLXF(
|
|
|
|
VIEWPORT_X + VIEWPORT_W * 0.5f,
|
|
|
|
VIEWPORT_Y + VIEWPORT_H * 0.5f - 75
|
|
|
|
);
|
|
|
|
|
|
|
|
float bg_width = 250;
|
|
|
|
float bg_height = 60;
|
|
|
|
|
|
|
|
Sprite *bg = res_sprite("part/smoke");
|
|
|
|
|
|
|
|
SpriteParams sp = {
|
|
|
|
.sprite_ptr = bg,
|
|
|
|
.shader_ptr = res_shader("sprite_default"),
|
|
|
|
.color = RGBA(0.1, 0.1, 0.2, 0.07),
|
|
|
|
};
|
|
|
|
|
|
|
|
r_mat_mv_push();
|
2023-09-20 04:14:15 +02:00
|
|
|
r_mat_mv_translate(re(pos), im(pos), 0);
|
2023-04-07 07:57:49 +02:00
|
|
|
r_mat_mv_scale(bg_width / bg->w, bg_height / bg->h, 1);
|
|
|
|
|
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_rotate(global.frames * 0.5 * DEG2RAD, 0, 0, 1);
|
|
|
|
r_draw_sprite(&sp);
|
|
|
|
r_mat_mv_pop();
|
|
|
|
|
|
|
|
sp.color = RGBA(0.2, 0.1, 0.1, 0.07);
|
|
|
|
|
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_rotate(global.frames * -0.93 * DEG2RAD, 0, 0, 1);
|
|
|
|
r_draw_sprite(&sp);
|
|
|
|
r_mat_mv_pop();
|
|
|
|
|
|
|
|
r_mat_mv_pop();
|
|
|
|
|
|
|
|
text_draw("Demo", &(TextParams) {
|
|
|
|
.align = ALIGN_CENTER,
|
|
|
|
.font = "big",
|
2024-09-22 21:06:57 +02:00
|
|
|
.shader_ptr = res_shader("text_demo"),
|
2023-04-07 07:57:49 +02:00
|
|
|
.shader_params = &(ShaderCustomParams) { global.frames / 60.0f },
|
|
|
|
.pos.as_cmplx = pos,
|
|
|
|
});
|
|
|
|
}
|
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;
|
2023-09-07 21:50:56 +02:00
|
|
|
|
|
|
|
bool all_clear = bonus->all_clear.base;
|
|
|
|
const char *title = all_clear ? "All Clear!" : "Stage Clear!";
|
|
|
|
|
|
|
|
stagetext_begin_table(&tbl, title, RGB(1, 1, 1), RGB(1, 1, 1), 2*VIEWPORT_W/3,
|
2019-02-22 00:56:03 +01:00
|
|
|
20, 5184000, 60, 60);
|
2023-09-07 21:50:56 +02:00
|
|
|
stagetext_table_add_numeric_nonzero(&tbl, "Stage Clear bonus", bonus->base);
|
2019-02-22 00:56:03 +01:00
|
|
|
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);
|
2023-09-07 21:50:56 +02:00
|
|
|
|
|
|
|
if(all_clear) {
|
|
|
|
stagetext_table_add_separator(&tbl);
|
|
|
|
stagetext_table_add_numeric_nonzero(&tbl, "All Clear bonus", bonus->all_clear.base);
|
|
|
|
|
|
|
|
if(bonus->all_clear.diff_bonus) {
|
|
|
|
char tmp[128];
|
|
|
|
int percent = (bonus->all_clear.diff_multiplier - 1.0) * 100;
|
|
|
|
snprintf(tmp, sizeof(tmp), "Difficulty bonus (+%i%%)", percent);
|
|
|
|
stagetext_table_add_numeric_nonzero(&tbl, tmp, bonus->all_clear.diff_bonus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
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,
|
2020-06-09 03:33:22 +02:00
|
|
|
res_font("standard"),
|
2019-02-22 00:56:03 +01:00
|
|
|
RGB(1, 0.5, 0),
|
|
|
|
tbl.delay,
|
|
|
|
tbl.lifetime,
|
|
|
|
tbl.fadeintime,
|
|
|
|
tbl.fadeouttime
|
|
|
|
);
|
|
|
|
|
|
|
|
stagedraw.clear_screen.target_alpha = 1;
|
|
|
|
}
|
2020-03-25 07:52:18 +01:00
|
|
|
|
|
|
|
StageDrawEvents *stage_get_draw_events(void) {
|
|
|
|
return &stagedraw.events;
|
|
|
|
}
|