From 50c1aced6e17a43064dc968faa40a755341730a4 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Wed, 4 Sep 2019 03:56:36 +0200 Subject: [PATCH] Handle muzzleflashes differently. Originally I thought that the model event calls would decide which muzzleflash to use. It WORKED close enough for CS afterall. It turns out that the numbers must relate to size or something else which I have yet to figure out. Either way this unbreaks muzzleflashes in Half-Life and soon when I port the weapons from CS' system over to the predicted weapon system from FreeHL, they'll get it too. --- src/client/defs.h | 10 ++++++-- src/client/events.c | 16 ++++++------- src/client/view.c | 46 ++++++++++++++++++++---------------- src/shared/valve/w_glock.c | 9 +++---- src/shared/valve/w_mp5.c | 11 +++++---- src/shared/valve/w_python.c | 1 + src/shared/valve/w_shotgun.c | 1 + 7 files changed, 55 insertions(+), 39 deletions(-) diff --git a/src/client/defs.h b/src/client/defs.h index 74389423..aa7e39d0 100644 --- a/src/client/defs.h +++ b/src/client/defs.h @@ -56,6 +56,11 @@ var float PARTICLE_SPARK; var float DECAL_SHOT; var float DECAL_GLASS; +/* muzzleflash indices */ +var int MUZZLE_SMALL; +var int MUZZLE_RIFLE; +var int MUZZLE_WEIRD; + /* misc globals */ vector video_mins; vector video_res; @@ -65,7 +70,8 @@ vector mouse_pos; float clframetime; /* prototypes */ +void View_SetMuzzleflash(int); void View_UpdateWeapon(entity, entity); -void View_AddPunchAngle( vector vAdd ); -void View_PlayAnimation( int iSequence ); +void View_AddPunchAngle(vector); +void View_PlayAnimation(int); void Game_Input(void); diff --git a/src/client/events.c b/src/client/events.c index 100a51fc..31bc1dc0 100644 --- a/src/client/events.c +++ b/src/client/events.c @@ -64,27 +64,27 @@ void Event_ProcessModel(float fTimeStamp, int iCode, string sData) localsound(sData, CHAN_AUTO, 1.0); } else if (iCode == 5001) { pSeat->eMuzzleflash.alpha = 1.0f; - pSeat->eMuzzleflash.scale = 0.5; + pSeat->eMuzzleflash.scale = 0.25; pSeat->eMuzzleflash.skin = pSeat->fNumBones; - setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); + //setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); Event_EjectShell(); } else if(iCode == 5011) { pSeat->eMuzzleflash.alpha = 1.0f; - pSeat->eMuzzleflash.scale = 0.5; + pSeat->eMuzzleflash.scale = 0.25; pSeat->eMuzzleflash.skin = pSeat->fNumBones + 1; - setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); + //setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); Event_EjectShell(); } else if (iCode == 5021) { pSeat->eMuzzleflash.alpha = 1.0f; - pSeat->eMuzzleflash.scale = 0.5; + pSeat->eMuzzleflash.scale = 0.25; pSeat->eMuzzleflash.skin = pSeat->fNumBones + 2; - setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); + //setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); Event_EjectShell(); } else if (iCode == 5031) { pSeat->eMuzzleflash.alpha = 1.0f; - pSeat->eMuzzleflash.scale = 0.5; + pSeat->eMuzzleflash.scale = 0.25; pSeat->eMuzzleflash.skin = pSeat->fNumBones + 3; - setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); + //setmodel(pSeat->eMuzzleflash, sprintf("sprites/muzzleflash%s.spr", substring(sData, 1, 1))); Event_EjectShell(); } } diff --git a/src/client/view.c b/src/client/view.c index 78e1913b..2425c8e0 100644 --- a/src/client/view.c +++ b/src/client/view.c @@ -17,7 +17,8 @@ var int autocvar_v_cambob = FALSE; var int autocvar_v_camroll = TRUE; -void View_Init(void) +void +View_Init(void) { #ifdef CSTRIKE string wm; @@ -39,9 +40,21 @@ void View_Init(void) pSeat->eMuzzleflash.renderflags = RF_ADDITIVE; } } + + /* there's also muzzleflash.spr, but that's just MUZZLE_SMALL again */ + MUZZLE_RIFLE = (int)getmodelindex("sprites/muzzleflash1.spr"); + MUZZLE_SMALL = (int)getmodelindex("sprites/muzzleflash2.spr"); + MUZZLE_WEIRD = (int)getmodelindex("sprites/muzzleflash3.spr"); } -void View_CalcViewport(int s, float fWinWidth, float fWinHeight) +void +View_SetMuzzleflash(int index) +{ + pSeat->eMuzzleflash.modelindex = (float)index; +} + +void +View_CalcViewport(int s, float fWinWidth, float fWinHeight) { //FIXME: this is awkward. renderscene internally rounds to pixels. //on the other hand, drawpic uses linear filtering and multisample and stuff. @@ -67,12 +80,8 @@ void View_CalcViewport(int s, float fWinWidth, float fWinHeight) } } -/* -==================== -View_CalcBob -==================== -*/ -void View_CalcBob(void) +void +View_CalcBob(void) { float cycle; @@ -100,7 +109,8 @@ void View_CalcBob(void) pSeat->fBob = bound(-7, fBob, 4); } -float View_CalcRoll(void) +float +View_CalcRoll(void) { float roll; makevectors(view_angles); @@ -110,13 +120,8 @@ float View_CalcRoll(void) return autocvar_v_camroll ? roll : 0; } -/* -================= -View_CalcCameraBob -================= -*/ - -void View_CalcCamBob(void) +void +View_CalcCamBob(void) { float flPlayerSpeed; @@ -210,8 +215,9 @@ void View_DrawViewModel(void) float fBaseTime = eViewModel.frame1time; eViewModel.frame2time = pl.weapontime; eViewModel.frame1time = pl.weapontime; - processmodelevents(eViewModel.modelindex, eViewModel.frame, fBaseTime, eViewModel.frame1time, Event_ProcessModel); - + processmodelevents(eViewModel.modelindex, eViewModel.frame, fBaseTime, + eViewModel.frame1time, Event_ProcessModel); + makevectors(view_angles); eViewModel.angles = view_angles; eViewModel.origin = pSeat->vPlayerOrigin + pl.view_ofs; @@ -219,7 +225,7 @@ void View_DrawViewModel(void) + (v_forward * autocvar_v_gunofs[0]) + (v_right * autocvar_v_gunofs[1]) + (v_up * autocvar_v_gunofs[2]); - + // Left-handed weapons if (autocvar_v_lefthanded) { v_right *= -1; @@ -231,7 +237,7 @@ void View_DrawViewModel(void) eViewModel.renderflags -= RF_USEAXIS; } } - + // Give the gun a tilt effect like in old HL/CS versions if (autocvar_v_bobclassic == 1) { eViewModel.angles[2] = -pSeat->fBob; diff --git a/src/shared/valve/w_glock.c b/src/shared/valve/w_glock.c index 0f2f1ff4..84acfb37 100644 --- a/src/shared/valve/w_glock.c +++ b/src/shared/valve/w_glock.c @@ -87,6 +87,7 @@ void w_glock_primary(void) return; } + View_SetMuzzleflash(MUZZLE_SMALL); Weapons_ViewPunchAngle([-2,0,0]); #else if (!pl.glock_mag) { @@ -107,10 +108,10 @@ void w_glock_primary(void) #endif if (pl.a_ammo1) { - Weapons_ViewAnimation(GLOCK_SHOOT); - } else { - Weapons_ViewAnimation(GLOCK_SHOOT_EMPTY); - } + Weapons_ViewAnimation(GLOCK_SHOOT); + } else { + Weapons_ViewAnimation(GLOCK_SHOOT_EMPTY); + } pl.w_attack_next = 0.3f; pl.w_idle_next = 5.0f; diff --git a/src/shared/valve/w_mp5.c b/src/shared/valve/w_mp5.c index 75ff904e..808896e3 100644 --- a/src/shared/valve/w_mp5.c +++ b/src/shared/valve/w_mp5.c @@ -99,14 +99,15 @@ void w_mp5_primary(void) #endif if (random() < 0.5) { - Weapons_ViewAnimation(MP5_FIRE1); - } else { - Weapons_ViewAnimation(MP5_FIRE2); - } + Weapons_ViewAnimation(MP5_FIRE1); + } else { + Weapons_ViewAnimation(MP5_FIRE2); + } - /* Actual firing */ + /* Actual firing */ #ifdef CSQC pl.a_ammo1--; + View_SetMuzzleflash(MUZZLE_RIFLE); Weapons_ViewPunchAngle([random(-2, 2),0,0]); #else /* Singleplayer is more accurate */ diff --git a/src/shared/valve/w_python.c b/src/shared/valve/w_python.c index 7a83b948..4cd48486 100644 --- a/src/shared/valve/w_python.c +++ b/src/shared/valve/w_python.c @@ -105,6 +105,7 @@ void w_python_primary(void) Weapons_UpdateAmmo(pl, pl.python_mag, pl.ammo_357, __NULL__); #else pl.a_ammo1--; + View_SetMuzzleflash(MUZZLE_SMALL); Weapons_ViewPunchAngle([-10,0,0]); #endif Weapons_ViewAnimation(PYTHON_FIRE1); diff --git a/src/shared/valve/w_shotgun.c b/src/shared/valve/w_shotgun.c index fc7ac0c9..2c28d010 100644 --- a/src/shared/valve/w_shotgun.c +++ b/src/shared/valve/w_shotgun.c @@ -120,6 +120,7 @@ void w_shotgun_primary(void) pl.shotgun_mag--; Weapons_UpdateAmmo(pl, pl.shotgun_mag, pl.ammo_buckshot, __NULL__); #else + View_SetMuzzleflash(MUZZLE_WEIRD); Weapons_ViewPunchAngle([-5,0,0]); pl.a_ammo1--; #endif