NSClient: Rename ClientInput() method in NSClient to ProcessInput(), as well as add SharedInputFrame() that can be overriden by the game.

This commit is contained in:
Marco Cawthorne 2022-12-28 16:47:44 -08:00
parent ce7cf4519f
commit 633046d28e
Signed by: eukara
GPG key ID: CE2032F0A2882A22
9 changed files with 138 additions and 82 deletions

View file

@ -389,6 +389,7 @@ CSQC_Input_Frame(void)
if (me.classname == "player" || me.classname == "spectator") {
NSClient pl = (NSClient)me;
pl.SharedInputFrame();
pl.ClientInputFrame();
}
}

View file

@ -44,8 +44,10 @@ ClientConnect(void)
{
int playercount = 0;
/* don't carry over team settings from a previous session */
forceinfokey(self, "*team", "0");
/* bot needs special init */
#ifdef BOT_INCLUDED
if (clienttype(self) == CLIENTTYPE_BOT) {
spawnfunc_bot();
@ -63,9 +65,8 @@ ClientConnect(void)
for (entity a = world; (a = find(a, ::classname, "player"));)
playercount++;
/* we're the only one. respawn all entities */
/* Force node init */
if (playercount == 1) {
Nodes_Init();
}
}
@ -101,8 +102,6 @@ The `self` global refers to one of any given amount of spectator.
void
SpectatorThink(void)
{
Game_SpectatorThink();
if (self.classname == "spectator") {
NSClientSpectator spec = (NSClientSpectator)self;
spec.PreFrame();
@ -117,7 +116,6 @@ The `self` global is the connecting NSClientSpectator in question.
void
SpectatorConnect(void)
{
Game_SpectatorConnect();
spawnfunc_NSClientSpectator();
}
@ -128,7 +126,6 @@ Attributes cleared when this function is done executing.
void
SpectatorDisconnect(void)
{
Game_SpectatorDisconnect();
}
/** Called when a player enters the game, having fully connected and loaded into
@ -153,6 +150,7 @@ PutClientInServer(void)
t.Trigger(self, TRIG_TOGGLE);
}
/* the game and its triggers start when the player is ready to see it */
trigger_auto_trigger();
}
@ -249,10 +247,9 @@ with the input_X globals being set to the appropriate data.
void
SV_RunClientCommand(void)
{
if (self.classname == "spectator") {
NSClientSpectator spec = (NSClientSpectator)self;
spec.RunClientCommand();
}
NSClient cl = (NSClient)self;
cl.SharedInputFrame();
cl.ServerInputFrame();
if (self.classname != "player") {
return;

View file

@ -22,6 +22,56 @@ and spectating clients alike.
class
NSClient:NSNavAI
{
public:
void NSClient(void);
/** Called to deal with the final input handling of the client. */
virtual void ProcessInput(void);
/** Run once, every frame, before physics are run on the player. */
virtual void PreFrame(void);
/** Run once, every frame, after physics are run on the player. */
virtual void PostFrame(void);
/** Returns if we're a 'fake' spectator. This is a regular player acting as a spectator. */
virtual bool IsFakeSpectator(void);
/** Returns if we're a 'real' spectator. That is a client that can only spectate. */
virtual bool IsRealSpectator(void);
/** Returns if we're considered 'dead'. NSClient, NSClientSpectator will always return false. */
virtual bool IsDead(void);
/** Returns if we're a player. That is a type of client that is built on top of NSClientPlayer. */
virtual bool IsPlayer(void);
/** Like ClientInputFrame and ServerInputFrame. However it's run on both. */
virtual void SharedInputFrame(void);
/* overrides */
virtual void OnRemoveEntity(void);
#ifdef CLIENT
/** Client: Called on the client to give a chance to override input variables before networking */
virtual void ClientInputFrame(void);
/** Client: Called every single client frame when this client is alive */
virtual void UpdateAliveCam(void);
/** Client: Called every single client frame when this client is dead */
virtual void UpdateDeathcam(void);
/** Client: Called every single client frame during intermission */
virtual void UpdateIntermissionCam(void);
/* overrides */
virtual float predraw(void);
#endif
#ifdef SERVER
/** Server: Like ClientInputFrame, but run on the server.
It's the first method to be called after receiving the input variables from the client.*/
virtual void ServerInputFrame(void);
/* overrides */
virtual void Save(float);
virtual void Restore(string,string);
#endif
private:
vector origin_net;
vector velocity_net;
@ -30,37 +80,4 @@ private:
NSXRInput m_xrInputHead;
NSXRInput m_xrInputLeft;
NSXRInput m_xrInputRight;
public:
void NSClient(void);
/* final input handling of the client */
virtual void ClientInput(void);
virtual void PreFrame(void);
virtual void PostFrame(void);
virtual bool IsFakeSpectator(void);
virtual bool IsRealSpectator(void);
virtual bool IsDead(void);
virtual bool IsPlayer(void);
virtual void OnRemoveEntity(void);
#ifdef CLIENT
/** Called to give a chance to override input variables before networking */
virtual void ClientInputFrame(void);
/** Called every single client frame when this client is alive */
virtual void UpdateAliveCam(void);
/** Called every single client frame when this client is dead */
virtual void UpdateDeathcam(void);
/** Called every single client frame during intermission */
virtual void UpdateIntermissionCam(void);
/* run every frame before renderscene() */
virtual float predraw(void);
#else
virtual void Save(float);
virtual void Restore(string,string);
#endif
};

View file

@ -36,8 +36,19 @@ NSClient::Restore(string strKey, string strValue)
super::Restore(strKey, strValue);
}
}
void
NSClient::ServerInputFrame(void)
{
}
#endif
void
NSClient::SharedInputFrame(void)
{
}
void
NSClient::OnRemoveEntity(void)
{
@ -45,7 +56,7 @@ NSClient::OnRemoveEntity(void)
}
void
NSClient::ClientInput(void)
NSClient::ProcessInput(void)
{
}

View file

@ -25,7 +25,7 @@ NSClientPlayer:NSClientSpectator
public:
void NSClientPlayer(void);
virtual void ClientInput(void);
virtual void ProcessInput(void);
virtual void PreFrame(void);
virtual void PostFrame(void);
@ -59,28 +59,38 @@ public:
virtual void ClientInputFrame(void);
virtual void UpdateAliveCam(void);
virtual float predraw(void);
virtual void postdraw(void);
/** Empty. Updates the bone controller responsible for mouth movement. */
virtual void UpdatePlayerJaw(float);
/** Empty. This is run on every player, every frame to update attachments. */
virtual void UpdatePlayerAttachments(bool);
#else
virtual float predraw(void);
virtual void postdraw(void);
#endif
#ifdef SERVER
/* overrides */
virtual void Save(float);
virtual void Restore(string,string);
virtual void Respawn(void);
virtual void EvaluateEntity(void);
virtual float SendEntity(entity,float);
virtual float OptimiseChangedFlags(entity,float);
virtual void Death(void);
virtual void ServerInputFrame(void);
/** Helper function that will optimise the changed-flags of your player entity. */
virtual float OptimiseChangedFlags(entity,float);
/** When called, will turn the client into a proper player. */
virtual void MakePlayer(void);
/** When called, will turn the client into a spectator. */
virtual void MakeTempSpectator(void);
/** Called when we press the button bound to +use. */
virtual void InputUse_Down(void);
/** Called when we let go of the button bound to +use. */
virtual void InputUse_Up(void);
#endif
@ -89,12 +99,15 @@ public:
private:
#ifdef SERVER
PREDICTED_INT_N(weaponframe)
#else
#ifdef CLIENT
PREDICTED_INT(weaponframe)
PREDICTED_FLOAT(vehicle_entnum)
#endif
#ifdef SERVER
PREDICTED_INT_N(weaponframe)
#endif
PREDICTED_FLOAT(health)
PREDICTED_FLOAT(armor)
@ -141,7 +154,9 @@ private:
int p_hand_bone;
int p_model_bone;
float lastweapon;
#else
#endif
#ifdef SERVER
int voted;
int step;
float step_time;

View file

@ -111,9 +111,8 @@ NSClientPlayer::PostFrame(void)
#endif
}
void
NSClientPlayer::ClientInput(void)
NSClientPlayer::ProcessInput(void)
{
if (Util_IsPaused())
return;
@ -121,7 +120,7 @@ NSClientPlayer::ClientInput(void)
XR_InputFrame(this);
if (!Client_InIntermission() && IsFakeSpectator()) {
NSClientSpectator::ClientInput();
NSClientSpectator::ProcessInput();
SpectatorTrackPlayer();
return;
}
@ -546,6 +545,12 @@ NSClientPlayer::PredictPostFrame(void)
ROLL_BACK(spec_flags)
}
#else
void
NSClientPlayer::ServerInputFrame(void)
{
}
void
NSClientPlayer::Save(float handle)
{

View file

@ -60,34 +60,42 @@ private:
public:
void NSClientSpectator(void);
virtual void ClientInput(void);
virtual void InputNext(void);
virtual void InputPrevious(void);
virtual void InputMode(void);
virtual void WarpToTarget(void);
/* overrides */
virtual void ProcessInput(void);
virtual void PreFrame(void);
virtual void PostFrame(void);
virtual void SpectatorTrackPlayer(void);
virtual bool IsFakeSpectator(void);
virtual bool IsRealSpectator(void);
virtual bool IsDead(void);
virtual bool IsPlayer(void);
/** Call to spectate the next spectating target. */
virtual void InputNext(void);
/** Call to spectate the previous player target. */
virtual void InputPrevious(void);
/** Call to change the spectating mode. */
virtual void InputMode(void);
/** Re-teleport to the target we're spectating.
Called once by InputNext/Previous. */
virtual void WarpToTarget(void);
/** Called every frame to track with our target player. */
virtual void SpectatorTrackPlayer(void);
#ifdef CLIENT
virtual void ClientInputFrame(void);
virtual void ReceiveEntity(float,float);
virtual float predraw(void);
#endif
#ifdef SERVER
#ifdef SERVER
virtual void Save(float);
virtual void Restore(string,string);
virtual void EvaluateEntity(void);
virtual float SendEntity(entity,float);
virtual void RunClientCommand(void);
#else
virtual void ClientInputFrame(void);
virtual void ReceiveEntity(float,float);
virtual float predraw(void);
#endif
virtual void ServerInputFrame(void);
#endif
};
#ifdef CLIENT

View file

@ -62,7 +62,7 @@ NSClientSpectator::IsFakeSpectator(void)
}
void
NSClientSpectator::ClientInput(void)
NSClientSpectator::ProcessInput(void)
{
if (input_buttons & INPUT_BUTTON0) {
InputNext();
@ -126,10 +126,12 @@ NSClientSpectator::SendEntity(entity ePVSent, float flChangedFlags)
}
void
NSClientSpectator::RunClientCommand(void)
NSClientSpectator::ServerInputFrame(void)
{
runstandardplayerphysics(this);
ClientInput();
/* since we are not using Physics_Run(), we have to call this manually */
ProcessInput();
}
#else
@ -168,7 +170,7 @@ NSClientSpectator::ReceiveEntity(float new, float fl)
}
input_sequence = i;
runstandardplayerphysics(this);
ClientInput();
ProcessInput();
}
/* any differences in things that are read below are now
@ -391,7 +393,7 @@ NSClientSpectator::PreFrame(void)
/* run our custom physics */
runstandardplayerphysics(this);
ClientInput();
ProcessInput();
}
#endif

View file

@ -366,7 +366,7 @@ NSClientPlayer::Physics_InputPostMove(void)
UpdatePlayerAnimation(input_timelength);
RemoveFlags(FL_FROZEN);
ClientInput();
ProcessInput();
}
/* the main physics routine, the head */