From 24c89e197aa730922b49ec5a61bdba5ab9a7e5e8 Mon Sep 17 00:00:00 2001 From: MotoLegacy Date: Sun, 14 Jan 2024 20:43:33 -0500 Subject: [PATCH] NX/VITA: Add nzp_screenflash builtin --- source/cl_parse.c | 8 ++++ source/gl_hud.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++- source/gl_hud.h | 6 +++ source/host_cmd.c | 1 - source/pr_cmds.c | 39 +++++++++++++++++++ source/protocol.h | 2 + 6 files changed, 150 insertions(+), 2 deletions(-) diff --git a/source/cl_parse.c b/source/cl_parse.c index 0dec621..05563dc 100644 --- a/source/cl_parse.c +++ b/source/cl_parse.c @@ -1612,6 +1612,14 @@ void CL_ParseServerMessage (void) doubletap_has_damage_buff = MSG_ReadByte(); break; + case svc_screenflash: + screenflash_color = MSG_ReadByte(); + screenflash_duration = sv.time + MSG_ReadByte(); + screenflash_type = MSG_ReadByte(); + screenflash_worktime = 0; + screenflash_starttime = sv.time; + break; + //case svc_bspdecal: // CL_ParseBSPDecal (); // break; diff --git a/source/gl_hud.c b/source/gl_hud.c index 4f037a6..aee4c75 100644 --- a/source/gl_hud.c +++ b/source/gl_hud.c @@ -67,6 +67,12 @@ int alphabling = 0; float round_center_x; float round_center_y; +int screenflash_color; +double screenflash_duration; +int screenflash_type; +double screenflash_worktime; +double screenflash_starttime; + extern qboolean paused_hack; qboolean domaxammo; qboolean has_chaptertitle; @@ -2084,11 +2090,91 @@ void HUD_PlayerName (void) Draw_ColoredStringScale(x, y, player_name, 255, 255, 255, alpha, scale); } +/* +=============== +HUD_Screenflash +=============== +*/ + +// +// Types of screen-flashes. +// + +// Colors +#define SCREENFLASH_COLOR_WHITE 0 +#define SCREENFLASH_COLOR_BLACK 1 + +// Types +#define SCREENFLASH_FADE_INANDOUT 0 +#define SCREENFLASH_FADE_IN 1 +#define SCREENFLASH_FADE_OUT 2 + +// +// invert float takes in float value between 0 and 1, inverts position +// eg: 0.1 returns 0.9, 0.34 returns 0.66 +float invertfloat(float input) { + if (input < 0) + return 0; // adjust to lower boundary + else if (input > 1) + return 1; // adjust to upper boundary + else + return (1 - input); +} + +void HUD_Screenflash (void) +{ + int r, g, b, a; + float flash_alpha; + + double percentage_complete = screenflash_worktime / (screenflash_duration - screenflash_starttime); + + // Fade Out + if (screenflash_type == SCREENFLASH_FADE_OUT) { + flash_alpha = invertfloat((float)percentage_complete); + } + // Fade In + else if (screenflash_type == SCREENFLASH_FADE_IN) { + flash_alpha = (float)percentage_complete; + } + // Fade In + Fade Out + else { + // Fade In + if (percentage_complete < 0.5) { + flash_alpha = (float)percentage_complete; + } + // Fade Out + else { + flash_alpha = invertfloat((float)percentage_complete); + } + } + + // Obtain the flash color + switch(screenflash_color) { + case SCREENFLASH_COLOR_BLACK: r = 0; g = 0; b = 0; a = (int)(flash_alpha * 255); break; + case SCREENFLASH_COLOR_WHITE: r = 255; g = 255; b = 255; a = (int)(flash_alpha * 255); break; + default: r = 255; g = 0; b = 0; a = 255; break; + } + + screenflash_worktime += host_frametime; + +#ifdef VITA + Draw_FillByColor(0, 0, vid.width, vid.height, r, g, b, a); +#else + Draw_FillByColor(0, vid.height * 0.5, vid.width/2, vid.height/2, r, g, b, a); +#endif +} + //============================================================================= void HUD_Draw (void) { - if (key_dest == key_menu_pause || paused_hack == true || m_state == m_exit) { + if (m_state == m_exit || paused_hack == true) + return; + + if (key_dest == key_menu_pause) { + // Make sure we still draw the screen flash. + if (screenflash_duration > sv.time) + HUD_Screenflash(); return; } @@ -2117,6 +2203,10 @@ void HUD_Draw (void) { if (cl.stats[STAT_HEALTH] <= 0) { HUD_EndScreen (); + + // Make sure we still draw the screen flash. + if (screenflash_duration > sv.time) + HUD_Screenflash(); return; } @@ -2156,5 +2246,9 @@ void HUD_Draw (void) { HUD_MaxAmmo(); } + // This should always come last! + if (screenflash_duration > sv.time) + HUD_Screenflash(); + GL_SetCanvas(CANVAS_DEFAULT); } \ No newline at end of file diff --git a/source/gl_hud.h b/source/gl_hud.h index 2d085cd..4e203b4 100644 --- a/source/gl_hud.h +++ b/source/gl_hud.h @@ -44,4 +44,10 @@ extern qpic_t *achievement_locked; extern char player_name[16]; extern double nameprint_time; +extern int screenflash_color; +extern double screenflash_duration; +extern int screenflash_type; +extern double screenflash_worktime; +extern double screenflash_starttime; + void HUD_Parse_Achievement (int ach); \ No newline at end of file diff --git a/source/host_cmd.c b/source/host_cmd.c index 0953f80..0da5ced 100644 --- a/source/host_cmd.c +++ b/source/host_cmd.c @@ -1660,7 +1660,6 @@ void Host_Spawn_f (void) Sys_Printf ("%s entered the game\n", host_client->name); PR_ExecuteProgram (pr_global_struct->PutClientInServer); - S_LocalSound ("sounds/rounds/splash.wav"); // since this won't execute in progs... } diff --git a/source/pr_cmds.c b/source/pr_cmds.c index 6cd362a..137e0d2 100644 --- a/source/pr_cmds.c +++ b/source/pr_cmds.c @@ -1330,6 +1330,44 @@ void PF_SetDoubleTapVersion(void) MSG_WriteByte (&client->message, state); } +/* +================= +PF_ScreenFlash + +Server tells client to flash on screen +for a short (but specified) moment. + +nzp_screenflash(target, color, duration, type) +================= +*/ +void PF_ScreenFlash(void) +{ + client_t *client; + int entnum; + int color, duration, type; + + entnum = G_EDICTNUM(OFS_PARM0); + color = G_FLOAT(OFS_PARM1); + duration = G_FLOAT(OFS_PARM2); + type = G_FLOAT(OFS_PARM3); + + // Specified world, or something. Send to everyone. + if (entnum < 1 || entnum > svs.maxclients) { + MSG_WriteByte(&sv.reliable_datagram, svc_screenflash); + MSG_WriteByte(&sv.reliable_datagram, color); + MSG_WriteByte(&sv.reliable_datagram, duration); + MSG_WriteByte(&sv.reliable_datagram, type); + } + // Send to specific user + else { + client = &svs.clients[entnum-1]; + MSG_WriteByte (&client->message, svc_screenflash); + MSG_WriteByte (&client->message, color); + MSG_WriteByte (&client->message, duration); + MSG_WriteByte (&client->message, type); + } +} + /* ================= PF_BettyPrompt @@ -3965,6 +4003,7 @@ static builtin_t pr_builtin[] = PF_BettyPrompt, // #504 PF_SetPlayerName, // #505 PF_SetDoubleTapVersion, // #506 + PF_ScreenFlash, // #507 }; builtin_t *pr_builtins = pr_builtin; diff --git a/source/protocol.h b/source/protocol.h index fb6333b..45b21f4 100644 --- a/source/protocol.h +++ b/source/protocol.h @@ -226,6 +226,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define svc_achievement 52 // [string] name [byte] decal_size [coords] pos #define svc_updatekills 53 // [string] to put in center of the screen +#define svc_screenflash 54 // [byte] color [byte] duration [byte] type + // // client to server //