Skip to content

Commit

Permalink
Add nzp_screenflash builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
MotoLegacy committed Jan 15, 2024
1 parent 73543dd commit 7792b98
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 3 deletions.
88 changes: 87 additions & 1 deletion source/cl_hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ char player_name[16];

extern cvar_t waypoint_mode;

int screenflash_color;
double screenflash_duration;
int screenflash_type;
double screenflash_worktime;
double screenflash_starttime;

int old_points;
int current_points;
Expand Down Expand Up @@ -1458,6 +1463,75 @@ void HUD_PlayerName (void)
Draw_ColoredString(70, 203, player_name, 255, 255, 255, alpha, 1);
}

/*
===============
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)
{
ScePspRGBA8888 color;
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: color = GU_RGBA(0, 0, 0, (int)(flash_alpha * 255)); break;
case SCREENFLASH_COLOR_WHITE: color = GU_RGBA(255, 255, 255, (int)(flash_alpha * 255)); break;
default: color = GU_RGBA(255, 0, 0, 255); break;
}

screenflash_worktime += host_frametime;
Draw_FillByColor(0, 0, vid.width, vid.height, color);
}

/*
===============
HUD_Draw
Expand All @@ -1468,8 +1542,12 @@ void HUD_Draw (void)
if (scr_con_current == vid.height)
return; // console is full screen

if (key_dest == key_menu_pause)
if (key_dest == key_menu_pause) {
// Make sure we still draw the screen flash.
if (screenflash_duration > sv.time)
HUD_Screenflash();
return;
}

scr_copyeverything = 1;

Expand All @@ -1489,6 +1567,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;
}

Expand Down Expand Up @@ -1521,4 +1603,8 @@ void HUD_Draw (void)
}
HUD_MaxAmmo();
}

// This should always come last!
if (screenflash_duration > sv.time)
HUD_Screenflash();
}
6 changes: 6 additions & 0 deletions source/cl_hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,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);
8 changes: 8 additions & 0 deletions source/cl_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,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_bettyprompt:
bettyprompt_time = sv.time + 4;
break;
Expand Down
1 change: 0 additions & 1 deletion source/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,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...
}

// send all current names, colors, and frag counts
Expand Down
41 changes: 40 additions & 1 deletion source/pr_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,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
Expand Down Expand Up @@ -3752,7 +3790,8 @@ ebfs_builtin_t pr_ebfs_builtins[] =
{ 503, "nzp_maxai", PF_MaxZombies },
{ 504, "nzp_bettyprompt", PF_BettyPrompt },
{ 505, "nzp_setplayername", PF_SetPlayerName },
{ 506, "nzp_setdoubletapver", PF_SetDoubleTapVersion }
{ 506, "nzp_setdoubletapver", PF_SetDoubleTapVersion },
{ 507, "nzp_screenflash", PF_ScreenFlash }

// 2001-11-15 DarkPlaces general builtin functions by Lord Havoc end

Expand Down
1 change: 1 addition & 0 deletions source/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define svc_bettyprompt 47
#define svc_playername 48
#define svc_doubletap 49
#define svc_screenflash 50 // [byte] color [byte] duration [byte] type

//
// client to server
Expand Down

0 comments on commit 7792b98

Please sign in to comment.