Shared: Optimise player.qc's prediction attribute code with the new macros.

This commit is contained in:
Marco Cawthorne 2021-05-10 08:15:13 +02:00
parent e858860db2
commit 42379ac7ac
12 changed files with 91 additions and 102 deletions

View File

@ -19,10 +19,10 @@ ClientGame_EntityUpdate(float id, float new)
{
switch (id) {
default:
return FALSE;
return (0);
}
return TRUE;
return (1);
}
void

View File

@ -3,7 +3,7 @@
flags.h
events.h
player.qc
../../../valve/src/shared/weapon_common.h
../../../base/src/shared/weapon_common.h
../../../valve/src/shared/animations.h
../../../valve/src/shared/animations.qc
pmove.qc
@ -32,6 +32,6 @@ w_legolauncher.qc
w_machette.qc
w_sodalauncher.qc
weapons.qc
../../../valve/src/shared/weapon_common.qc
../../../base/src/shared/weapon_common.qc
input.qc
#endlist

View File

@ -14,14 +14,8 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
=================
Input_Handle
Handles impulse and whatnot
=================
*/
void Game_Input(void)
void
Game_Input(void)
{
#ifdef SERVER
CGameRules rules = (CGameRules)g_grMode;
@ -31,17 +25,14 @@ void Game_Input(void)
return;
}
if (input_buttons & INPUT_BUTTON5) {
if (input_buttons & INPUT_BUTTON5)
Player_UseDown();
} else {
else
Player_UseUp();
}
if (self.impulse == 100) {
if (self.impulse == 100)
Flashlight_Toggle();
}
/* Uncomment rune weapons if you desire */
if (cvar("sv_cheats") == 1) {
player pl = (player)self;
if (self.impulse == 101) {
@ -60,17 +51,16 @@ void Game_Input(void)
Weapons_AddItem(pl, WEAPON_SODALAUNCHER, -1);
}
}
self.impulse = 0;
#endif
if (input_buttons & INPUT_BUTTON0) {
if (input_buttons & INPUT_BUTTON0)
Weapons_Primary();
} else if (input_buttons & INPUT_BUTTON4) {
else if (input_buttons & INPUT_BUTTON4)
Weapons_Reload();
} else if (input_buttons & INPUT_BUTTON3) {
else if (input_buttons & INPUT_BUTTON3)
Weapons_Secondary();
} else {
else
Weapons_Release();
}
}

View File

@ -45,19 +45,18 @@ enumflags
noref int input_sequence;
class player:base_player
{
/* Weapon specific */
int ammo_forks; int ammo_forks_net;
int ammo_knives; int ammo_knives_net;
int ammo_legogrenade; int ammo_legogrenade_net;
int ammo_legos; int ammo_legos_net;
int ammo_soda; int ammo_soda_net;
int ammo_spray; int ammo_spray_net;
PREDICTED_INT(anim_top);
PREDICTED_FLOAT(anim_top_time);
PREDICTED_FLOAT(anim_top_delay);
PREDICTED_INT(anim_bottom);
PREDICTED_FLOAT(anim_bottom_time);
float anim_top; float anim_top_net;
float anim_top_time; float anim_top_time_net;
float anim_top_delay; float anim_top_delay_net;
float anim_bottom; float anim_bottom_net;
float anim_bottom_time; float anim_bottom_time_net;
PREDICTED_INT(ammo_forks);
PREDICTED_INT(ammo_knives);
PREDICTED_INT(ammo_legogrenade);
PREDICTED_INT(ammo_legos);
PREDICTED_INT(ammo_soda);
PREDICTED_INT(ammo_spray);
#ifdef CLIENT
/* External model */
@ -137,18 +136,18 @@ player::PredictPreFrame(void)
{
base_player::PredictPreFrame();
ammo_forks_net = ammo_forks;
ammo_knives_net = ammo_knives;
ammo_legogrenade_net = ammo_legogrenade;
ammo_legos_net = ammo_legos;
ammo_soda_net = ammo_soda;
ammo_spray_net = ammo_spray;
SAVE_STATE(anim_top);
SAVE_STATE(anim_top_time);
SAVE_STATE(anim_top_delay);
SAVE_STATE(anim_bottom);
SAVE_STATE(anim_bottom_time);
anim_top_net = anim_top;
anim_top_delay_net = anim_top_delay;
anim_top_time_net = anim_top_time;
anim_bottom_net = anim_bottom;
anim_bottom_time_net = anim_bottom_time;
SAVE_STATE(ammo_forks);
SAVE_STATE(ammo_knives);
SAVE_STATE(ammo_legogrenade);
SAVE_STATE(ammo_legos);
SAVE_STATE(ammo_soda);
SAVE_STATE(ammo_spray);
}
/*
@ -163,18 +162,18 @@ player::PredictPostFrame(void)
{
base_player::PredictPostFrame();
ammo_forks = ammo_forks_net;
ammo_knives = ammo_knives_net;
ammo_legogrenade = ammo_legogrenade_net;
ammo_legos = ammo_legos_net;
ammo_soda = ammo_soda_net;
ammo_spray = ammo_spray_net;
ROLL_BACK(anim_top);
ROLL_BACK(anim_top_time);
ROLL_BACK(anim_top_delay);
ROLL_BACK(anim_bottom);
ROLL_BACK(anim_bottom_time);
anim_top = anim_top_net;
anim_top_delay = anim_top_delay_net;
anim_top_time = anim_top_time_net;
anim_bottom = anim_bottom_net;
anim_bottom_time = anim_bottom_time_net;
ROLL_BACK(ammo_forks);
ROLL_BACK(ammo_knives);
ROLL_BACK(ammo_legogrenade);
ROLL_BACK(ammo_legos);
ROLL_BACK(ammo_soda);
ROLL_BACK(ammo_spray);
}
#else
@ -183,37 +182,37 @@ player::EvaluateEntity(void)
{
base_player::EvaluateEntity();
if (ammo_forks_net == ammo_forks)
SendFlags |= PLAYER_AMMO2;
if (ammo_knives_net == ammo_knives)
SendFlags |= PLAYER_AMMO2;
if (ammo_legogrenade_net == ammo_legogrenade)
SendFlags |= PLAYER_AMMO2;
if (ammo_legos_net == ammo_legos)
SendFlags |= PLAYER_AMMO2;
if (ammo_soda_net == ammo_soda)
SendFlags |= PLAYER_AMMO2;
if (ammo_spray_net == ammo_spray)
SendFlags |= PLAYER_AMMO2;
ammo_forks_net = ammo_forks;
ammo_knives_net = ammo_knives;
ammo_legogrenade_net = ammo_legogrenade;
ammo_legos_net = ammo_legos;
ammo_soda_net = ammo_soda;
ammo_spray_net = ammo_spray;
/* animation */
if (anim_bottom_net != anim_bottom || anim_bottom_time != anim_bottom_time_net)
if (ATTR_CHANGED(anim_bottom) || ATTR_CHANGED(anim_bottom_time))
SendFlags |= PLAYER_BOTTOMFRAME;
if (anim_top_net != anim_top || anim_top_time != anim_top_time_net || anim_top_delay != anim_top_delay_net)
if (ATTR_CHANGED(anim_top) || ATTR_CHANGED(anim_top_time) || ATTR_CHANGED(anim_top_delay))
SendFlags |= PLAYER_TOPFRAME;
anim_top_net = anim_top;
anim_top_delay_net = anim_top_delay;
anim_top_time_net = anim_top_time;
anim_bottom_net = anim_bottom;
anim_bottom_time_net = anim_bottom_time;
if (ATTR_CHANGED(ammo_forks))
SendFlags |= PLAYER_AMMO2;
if (ATTR_CHANGED(ammo_knives))
SendFlags |= PLAYER_AMMO2;
if (ATTR_CHANGED(ammo_legogrenade))
SendFlags |= PLAYER_AMMO2;
if (ATTR_CHANGED(ammo_legos))
SendFlags |= PLAYER_AMMO2;
if (ATTR_CHANGED(ammo_soda))
SendFlags |= PLAYER_AMMO2;
if (ATTR_CHANGED(ammo_spray))
SendFlags |= PLAYER_AMMO2;
SAVE_STATE(anim_top);
SAVE_STATE(anim_top_time);
SAVE_STATE(anim_top_delay);
SAVE_STATE(anim_bottom);
SAVE_STATE(anim_bottom_time);
SAVE_STATE(ammo_forks);
SAVE_STATE(ammo_knives);
SAVE_STATE(ammo_legogrenade);
SAVE_STATE(ammo_legos);
SAVE_STATE(ammo_soda);
SAVE_STATE(ammo_spray);
}
/*
@ -225,11 +224,11 @@ float
player::SendEntity(entity ePEnt, float fChanged)
{
if (health <= 0 && ePEnt != this) {
return FALSE;
return (0);
}
if (clienttype(ePEnt) != CLIENTTYPE_REAL) {
return FALSE;
return (0);
}
if (ePEnt != self) {
@ -272,6 +271,6 @@ player::SendEntity(entity ePEnt, float fChanged)
if (fChanged & PLAYER_AMMO3) {
}
return TRUE;
return (1);
}
#endif

View File

@ -85,10 +85,10 @@ w_forks_pickup(int new, int startammo)
if (pl.ammo_forks < MAX_A_FORKS) {
pl.ammo_forks = bound(0, pl.ammo_forks + 6, MAX_A_FORKS);
} else {
return FALSE;
return (0);
}
#endif
return TRUE;
return (1);
}
void
w_forks_draw(void)

View File

@ -101,7 +101,7 @@ w_glove_pickup(int new, int startammo)
Sound_Play(self, CHAN_ITEM, "weapon_glove.pickup");
#endif
return TRUE;
return (1);
}
void

View File

@ -78,10 +78,10 @@ w_hairspray_pickup(int new, int startammo)
if (pl.ammo_spray < MAX_A_SPRAY) {
pl.ammo_spray = bound(0, pl.ammo_spray + 20, MAX_A_SPRAY);
} else {
return FALSE;
return (0);
}
#endif
return TRUE;
return (1);
}
void

View File

@ -83,10 +83,10 @@ w_knife_pickup(int new, int startammo)
if (pl.ammo_knives < MAX_A_KNIVES) {
pl.ammo_knives = bound(0, pl.ammo_knives + 1, MAX_A_KNIVES);
} else {
return FALSE;
return (0);
}
#endif
return TRUE;
return (1);
}
void

View File

@ -78,10 +78,10 @@ w_lego_pickup(int new, int startammo)
if (pl.ammo_legogrenade < MAX_A_LEGOGRENADE) {
pl.ammo_legogrenade = bound(0, pl.ammo_legogrenade + 1, MAX_A_LEGOGRENADE);
} else {
return FALSE;
return (0);
}
#endif
return TRUE;
return (1);
}
#ifdef SERVER

View File

@ -79,10 +79,10 @@ w_legolauncher_pickup(int new, int startammo)
if (pl.ammo_legos < MAX_A_LEGOS) {
pl.ammo_legos = bound(0, pl.ammo_legos + 40, MAX_A_LEGOS);
} else {
return FALSE;
return (0);
}
#endif
return TRUE;
return (1);
}
void

View File

@ -71,7 +71,7 @@ w_machette_pickup(int new, int startammo)
Sound_Play(self, CHAN_ITEM, "weapon_machette.pickup");
env_message_single(self, "Activating Rune STALKER!");
#endif
return TRUE;
return (1);
}
void

View File

@ -61,10 +61,10 @@ w_sodalauncher_pickup(int new, int startammo)
if (pl.ammo_soda < MAX_A_SODA) {
pl.ammo_soda = bound(0, pl.ammo_soda + 3, MAX_A_SODA);
} else {
return FALSE;
return (0);
}
#endif
return TRUE;
return (1);
}
void