From c068f22329d5cc722622a2183bbb22eef2093df7 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 24 Aug 2026 11:16:07 +0200 Subject: initial import --- src/parsec/include/net_prediction.h | 93 +++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/parsec/include/net_prediction.h (limited to 'src/parsec/include/net_prediction.h') diff --git a/src/parsec/include/net_prediction.h b/src/parsec/include/net_prediction.h new file mode 100644 index 0000000..05795ea --- /dev/null +++ b/src/parsec/include/net_prediction.h @@ -0,0 +1,93 @@ +#ifndef NET_PredICTIONMANAGER_H_ +#define NET_PredICTIONMANAGER_H_ + +// forward decls -------------------------------------------------------------- +// +class NET_Stream; + +// constants ------------------------------------------------------------------ +// +#define MAX_NUM_PREDICTIONS 1000 + +// virtual base class for all prediction events ------------------------------- +// +class NET_PredEvent +{ +public: + NET_PredEvent() : m_nMessageId( 0 ), m_nDoCount(0) {} + virtual ~NET_PredEvent() {}; + virtual void Do() { m_nDoCount++; } + void SetMessageId( dword nMessageId ) { m_nMessageId = nMessageId; } + dword GetMessageId() { return m_nMessageId; } + int GetDoCount() { return m_nDoCount; } +protected: + dword m_nMessageId; + int m_nDoCount; +}; + + +// typedefs ------------------------------------------------------------------- +// +typedef UTL_listentry_s LE_PredEvt; + + +// special implementation for an extra collect prediction event --------------- +// +class G_PredEventExtraCollect : public NET_PredEvent +{ +public: + G_PredEventExtraCollect( ExtraObject* pExtra ); + void Do(); + +protected: + ExtraObject* m_pExtra; +}; + + +// the prediction manager ----------------------------------------------------- +// +class NET_PredictionManager +{ +public: + //NOTE: stores information about events that were predicted in the game-engine + // whenever the game-engine modifies the local world, we save a prediction that includes a checkpoint ( = next outgoing message id ) + // whenever we receive a packet, we clear all predictions inserted before the ACK checkpoint + // and we re-apply all pending predictions not yet ACK ( checkpoint # is synonym for message id ) + + // INITIALIZERS + // standard ctor + NET_PredictionManager( NET_Stream* pStream ); + + // standard dtor + ~NET_PredictionManager(); + + + // MODIFIERS + // reset all data + void Reset(); + + // clear all predictions up to the message# and reapply all predictions after the message# + void DoCheckpoint( dword MessageId ); + + // predictions + void PredictExtraCollect( ExtraObject* pExtra ); + + // ACCESSORS + // return the # of predictions pending + int GetNumPredictions() { return m_predictions->GetNumEntries(); } + +protected: + UTL_List* m_predictions; + NET_Stream* m_pStream; + +protected: + // add a predictionevent + // ensures that MAX_NUM_PREDICTIONS is not exceeded + void _AddPrediction( NET_PredEvent* pEvent ); +}; + +// external global ------------------------------------------------------------ +// +extern NET_PredictionManager ThePredictionManager; + +#endif // NET_PredICTIONMANAGER_H_ -- cgit v1.2.3