NX/VITA: Add nzp_screenflash builtin

This commit is contained in:
MotoLegacy 2024-01-14 20:43:33 -05:00
parent 1b622cf24f
commit 24c89e197a
6 changed files with 150 additions and 2 deletions

View file

@ -1612,6 +1612,14 @@ void CL_ParseServerMessage (void)
doubletap_has_damage_buff = MSG_ReadByte(); doubletap_has_damage_buff = MSG_ReadByte();
break; 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: //case svc_bspdecal:
// CL_ParseBSPDecal (); // CL_ParseBSPDecal ();
// break; // break;

View file

@ -67,6 +67,12 @@ int alphabling = 0;
float round_center_x; float round_center_x;
float round_center_y; float round_center_y;
int screenflash_color;
double screenflash_duration;
int screenflash_type;
double screenflash_worktime;
double screenflash_starttime;
extern qboolean paused_hack; extern qboolean paused_hack;
qboolean domaxammo; qboolean domaxammo;
qboolean has_chaptertitle; qboolean has_chaptertitle;
@ -2084,11 +2090,91 @@ void HUD_PlayerName (void)
Draw_ColoredStringScale(x, y, player_name, 255, 255, 255, alpha, scale); 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) { 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; return;
} }
@ -2117,6 +2203,10 @@ void HUD_Draw (void) {
if (cl.stats[STAT_HEALTH] <= 0) { if (cl.stats[STAT_HEALTH] <= 0) {
HUD_EndScreen (); HUD_EndScreen ();
// Make sure we still draw the screen flash.
if (screenflash_duration > sv.time)
HUD_Screenflash();
return; return;
} }
@ -2156,5 +2246,9 @@ void HUD_Draw (void) {
HUD_MaxAmmo(); HUD_MaxAmmo();
} }
// This should always come last!
if (screenflash_duration > sv.time)
HUD_Screenflash();
GL_SetCanvas(CANVAS_DEFAULT); GL_SetCanvas(CANVAS_DEFAULT);
} }

View file

@ -44,4 +44,10 @@ extern qpic_t *achievement_locked;
extern char player_name[16]; extern char player_name[16];
extern double nameprint_time; 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); void HUD_Parse_Achievement (int ach);

View file

@ -1660,7 +1660,6 @@ void Host_Spawn_f (void)
Sys_Printf ("%s entered the game\n", host_client->name); Sys_Printf ("%s entered the game\n", host_client->name);
PR_ExecuteProgram (pr_global_struct->PutClientInServer); PR_ExecuteProgram (pr_global_struct->PutClientInServer);
S_LocalSound ("sounds/rounds/splash.wav"); // since this won't execute in progs...
} }

View file

@ -1330,6 +1330,44 @@ void PF_SetDoubleTapVersion(void)
MSG_WriteByte (&client->message, state); 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 PF_BettyPrompt
@ -3965,6 +4003,7 @@ static builtin_t pr_builtin[] =
PF_BettyPrompt, // #504 PF_BettyPrompt, // #504
PF_SetPlayerName, // #505 PF_SetPlayerName, // #505
PF_SetDoubleTapVersion, // #506 PF_SetDoubleTapVersion, // #506
PF_ScreenFlash, // #507
}; };
builtin_t *pr_builtins = pr_builtin; builtin_t *pr_builtins = pr_builtin;

View file

@ -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_achievement 52 // [string] name [byte] decal_size [coords] pos
#define svc_updatekills 53 // [string] to put in center of the screen #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 // client to server
// //