2020-04-22 18:56:21 +02:00
|
|
|
//========= Copyright Valve Corporation, All rights reserved. ============//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $Workfile: $
|
|
|
|
// $Date: $
|
|
|
|
// $NoKeywords: $
|
|
|
|
//=============================================================================//
|
2024-08-23 00:37:28 +02:00
|
|
|
#include "baseentity_shared.h"
|
|
|
|
#include "c_baseentity.h"
|
|
|
|
#include "const.h"
|
|
|
|
#include "datamodel/dmelementhandle.h"
|
2024-09-05 23:31:50 +02:00
|
|
|
#include "platform.h"
|
2024-08-23 00:37:28 +02:00
|
|
|
#include "touchlink.h"
|
|
|
|
#include "utlvector.h"
|
2020-04-22 18:56:21 +02:00
|
|
|
#if !defined( PREDICTION_H )
|
|
|
|
#define PREDICTION_H
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma once
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mathlib/vector.h"
|
|
|
|
#include "iprediction.h"
|
|
|
|
#include "c_baseplayer.h"
|
|
|
|
#include "cdll_bounded_cvars.h"
|
|
|
|
|
|
|
|
class CMoveData;
|
|
|
|
class CUserCmd;
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Implements prediction in the client .dll
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
class CPrediction : public IPrediction
|
|
|
|
{
|
|
|
|
// Construction
|
|
|
|
public:
|
|
|
|
DECLARE_CLASS_GAMEROOT( CPrediction, IPrediction );
|
|
|
|
|
|
|
|
CPrediction( void );
|
|
|
|
virtual ~CPrediction( void );
|
|
|
|
|
|
|
|
virtual void Init( void );
|
|
|
|
virtual void Shutdown( void );
|
|
|
|
|
|
|
|
// Implement IPrediction
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void Update
|
|
|
|
(
|
|
|
|
int startframe, // World update ( un-modded ) most recently received
|
|
|
|
bool validframe, // Is frame data valid
|
|
|
|
int incoming_acknowledged, // Last command acknowledged to have been run by server (un-modded)
|
|
|
|
int outgoing_command // Last command (most recent) sent to server (un-modded)
|
|
|
|
);
|
|
|
|
|
|
|
|
virtual void OnReceivedUncompressedPacket( void );
|
|
|
|
|
|
|
|
virtual void PreEntityPacketReceived( int commands_acknowledged, int current_world_update_packet );
|
|
|
|
virtual void PostEntityPacketReceived( void );
|
|
|
|
virtual void PostNetworkDataReceived( int commands_acknowledged );
|
|
|
|
|
|
|
|
virtual bool InPrediction( void ) const;
|
|
|
|
virtual bool IsFirstTimePredicted( void ) const;
|
|
|
|
|
|
|
|
#if !defined( NO_ENTITY_PREDICTION )
|
|
|
|
virtual int GetIncomingPacketNumber( void ) const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
float GetIdealPitch( void ) const
|
|
|
|
{
|
|
|
|
return m_flIdealPitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The engine needs to be able to access a few predicted values
|
|
|
|
virtual void GetViewOrigin( Vector& org );
|
|
|
|
virtual void SetViewOrigin( Vector& org );
|
|
|
|
virtual void GetViewAngles( QAngle& ang );
|
|
|
|
virtual void SetViewAngles( QAngle& ang );
|
|
|
|
|
|
|
|
virtual void GetLocalViewAngles( QAngle& ang );
|
|
|
|
virtual void SetLocalViewAngles( QAngle& ang );
|
|
|
|
|
|
|
|
virtual void RunCommand( C_BasePlayer *player, CUserCmd *ucmd, IMoveHelper *moveHelper );
|
|
|
|
|
|
|
|
// Internal
|
|
|
|
protected:
|
|
|
|
virtual void SetupMove( C_BasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
|
|
|
|
virtual void FinishMove( C_BasePlayer *player, CUserCmd *ucmd, CMoveData *move );
|
|
|
|
virtual void SetIdealPitch ( C_BasePlayer *player, const Vector& origin, const QAngle& angles, const Vector& viewheight );
|
|
|
|
|
|
|
|
void CheckError( int commands_acknowledged );
|
|
|
|
|
|
|
|
// Called before and after any movement processing
|
|
|
|
void StartCommand( C_BasePlayer *player, CUserCmd *cmd );
|
|
|
|
void FinishCommand( C_BasePlayer *player );
|
|
|
|
|
|
|
|
// Helpers to call pre and post think for player, and to call think if a think function is set
|
|
|
|
void RunPreThink( C_BasePlayer *player );
|
|
|
|
void RunThink (C_BasePlayer *ent, double frametime );
|
2024-09-04 22:30:47 +02:00
|
|
|
void StartInterpolatingPlayer( C_BasePlayer* player );
|
|
|
|
void FinishInterpolatingPlayer( C_BasePlayer* player );
|
2020-04-22 18:56:21 +02:00
|
|
|
void RunPostThink( C_BasePlayer *player );
|
2024-07-13 19:18:03 +02:00
|
|
|
void CheckMovingGround( CBasePlayer *player, double frametime );
|
2020-04-22 18:56:21 +02:00
|
|
|
private:
|
|
|
|
virtual void _Update
|
|
|
|
(
|
|
|
|
bool received_new_world_update,
|
|
|
|
bool validframe, // Is frame data valid
|
|
|
|
int incoming_acknowledged, // Last command acknowledged to have been run by server (un-modded)
|
|
|
|
int outgoing_command // Last command (most recent) sent to server (un-modded)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Actually does the prediction work, returns false if an error occurred
|
|
|
|
bool PerformPrediction( bool received_new_world_update, C_BasePlayer *localPlayer, int incoming_acknowledged, int outgoing_command );
|
|
|
|
|
|
|
|
void ShiftIntermediateDataForward( int slots_to_remove, int previous_last_slot );
|
|
|
|
void RestoreEntityToPredictedFrame( int predicted_frame );
|
|
|
|
int ComputeFirstCommandToExecute( bool received_new_world_update, int incoming_acknowledged, int outgoing_command );
|
|
|
|
|
|
|
|
void DumpEntity( C_BaseEntity *ent, int commands_acknowledged );
|
|
|
|
|
|
|
|
void ShutdownPredictables( void );
|
|
|
|
void ReinitPredictables( void );
|
|
|
|
|
|
|
|
void RemoveStalePredictedEntities( int last_command_packet );
|
|
|
|
void RestoreOriginalEntityState( void );
|
|
|
|
void RunSimulation( int current_command, float curtime, CUserCmd *cmd, C_BasePlayer *localPlayer );
|
2024-08-23 00:37:28 +02:00
|
|
|
void RestorePredictedTouched( int current_command );
|
|
|
|
void StorePredictedTouched( int current_command );
|
2020-04-22 18:56:21 +02:00
|
|
|
void Untouch( void );
|
|
|
|
void StorePredictionResults( int predicted_frame );
|
|
|
|
bool ShouldDumpEntity( C_BaseEntity *ent );
|
|
|
|
|
|
|
|
void SmoothViewOnMovingPlatform( C_BasePlayer *pPlayer, Vector& offset );
|
|
|
|
|
|
|
|
#if !defined( NO_ENTITY_PREDICTION )
|
|
|
|
// Data
|
|
|
|
protected:
|
|
|
|
// Last object the player was standing on
|
|
|
|
CHandle< C_BaseEntity > m_hLastGround;
|
|
|
|
private:
|
|
|
|
bool m_bInPrediction;
|
|
|
|
bool m_bFirstTimePredicted;
|
|
|
|
bool m_bOldCLPredictValue;
|
|
|
|
bool m_bEnginePaused;
|
|
|
|
|
|
|
|
// Last network origin for local player
|
|
|
|
int m_nPreviousStartFrame;
|
|
|
|
|
|
|
|
int m_nCommandsPredicted;
|
|
|
|
int m_nServerCommandsAcknowledged;
|
|
|
|
int m_bPreviousAckHadErrors;
|
|
|
|
int m_nIncomingPacketNumber;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
float m_flIdealPitch;
|
|
|
|
|
2024-08-23 00:37:28 +02:00
|
|
|
struct SavedTouch_t
|
|
|
|
{
|
|
|
|
int entityTouched;
|
|
|
|
int touchStamp;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TouchedHistory
|
|
|
|
{
|
|
|
|
CUtlVector<SavedTouch_t> savedTouches;
|
|
|
|
CUtlVector<EHANDLE> touchedTriggerEntities;
|
|
|
|
};
|
|
|
|
|
2024-09-05 23:31:50 +02:00
|
|
|
struct EventQueueForHistory
|
|
|
|
{
|
|
|
|
float m_flFireTime;
|
|
|
|
char m_iTarget[MAX_PATH]; // TODO_ENHANCED: We need to rename this to some hash here ...
|
|
|
|
char m_iTargetInput[MAX_PATH]; // TODO_ENHANCED: We need to rename this to some hash here ...
|
|
|
|
EHANDLE m_pActivator;
|
|
|
|
EHANDLE m_pCaller;
|
|
|
|
int m_iOutputID;
|
|
|
|
EHANDLE m_pEntTarget;
|
|
|
|
variant_t m_VariantValue;
|
|
|
|
};
|
|
|
|
|
2024-08-23 00:37:28 +02:00
|
|
|
TouchedHistory m_touchedHistory[MULTIPLAYER_BACKUP][MAX_EDICTS];
|
2024-09-05 23:31:50 +02:00
|
|
|
CUtlVector<EventQueueForHistory> m_eventQueueHistory[MULTIPLAYER_BACKUP];
|
2024-09-04 22:30:47 +02:00
|
|
|
|
|
|
|
// TODO_ENHANCED: checks if this affects vehicles properly too! It should.
|
|
|
|
enum INTERPOLATION_CONTEXT
|
|
|
|
{
|
|
|
|
BEFORE_MOVEMENT,
|
|
|
|
AFTER_MOVEMENT,
|
|
|
|
INTERPOLATION_CONTEXT_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InterpolationContext
|
|
|
|
{
|
2024-09-06 00:25:17 +02:00
|
|
|
Vector m_vecLocalOrigin;
|
2024-09-04 22:30:47 +02:00
|
|
|
Vector m_vecViewOffset;
|
|
|
|
} InterpolationContexts[INTERPOLATION_CONTEXT_MAX];
|
2020-04-22 18:56:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CPrediction *prediction;
|
|
|
|
|
|
|
|
#endif // PREDICTION_H
|