Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Received Class Reference

Entity is received from a server. More...

#include <Components.h>

+ Inheritance diagram for Leviathan::Received:

Classes

class  StoredState
 Storage class for ObjectDeltaStateData. More...
 

Public Member Functions

 Received ()
 
DLLEXPORT void GetServerSentStates (StoredState const **first, StoredState const **second, int tick, float &progress) const
 
 REFERENCE_HANDLE_UNCOUNTED_TYPE (Received)
 
- Public Member Functions inherited from Leviathan::Component
 Component (COMPONENT_TYPE type)
 
 Component (const Component &)=delete
 
Componentoperator= (const Component &)=delete
 

Public Attributes

boost::circular_buffer< StoredStateClientStateBuffer
 Client side buffer of past states. More...
 
bool LocallyControlled = false
 If true this uses local control and will send updates to the server. More...
 
- Public Attributes inherited from Leviathan::Component
bool Marked
 
const COMPONENT_TYPE Type
 Type of this component, used for network serialization. More...
 

Static Public Attributes

static constexpr auto TYPE = COMPONENT_TYPE::Received
 

Detailed Description

Entity is received from a server.

Sendable counterpart on the client

Definition at line 161 of file Components.h.

Constructor & Destructor Documentation

◆ Received()

Leviathan::Received::Received ( )
inline

Definition at line 182 of file Components.h.

183  {
184  }
constexpr auto BASESENDABLE_STORED_RECEIVED_STATES
Definition: Define.h:34
boost::circular_buffer< StoredState > ClientStateBuffer
Client side buffer of past states.
Definition: Components.h:192
Component(COMPONENT_TYPE type)
Definition: Component.h:55
static constexpr auto TYPE
Definition: Components.h:197

Member Function Documentation

◆ GetServerSentStates()

DLLEXPORT void Received::GetServerSentStates ( StoredState const **  first,
StoredState const **  second,
int  tick,
float &  progress 
) const

Definition at line 671 of file Components.cpp.

673 {
674  // Used to find the first tick before or on tick //
675  int firstinpast = std::numeric_limits<int>::max();
676  int secondfound = 0;
677 
678  for(auto& obj : ClientStateBuffer) {
679 
680  if(tick - obj.Tick < firstinpast && tick - obj.Tick >= 0) {
681 
682  // This is (potentially) the first state //
683  firstinpast = tick - obj.Tick;
684 
685  *first = &obj;
686  }
687 
688  // For this to be found the client should be around 50-100 milliseconds in the past
689  if(obj.Tick > tick && (secondfound == 0 || obj.Tick - tick < secondfound)) {
690 
691  // The second state //
692  *second = &obj;
693 
694  secondfound = obj.Tick - tick;
695  continue;
696  }
697  }
698 
699  if(firstinpast == std::numeric_limits<int>::max() || secondfound == 0) {
700 
701  throw InvalidState("No stored server states around tick");
702  }
703 
704  // If the range is not 1, meaning firstinpast != 0 || secondfound > 1 we need to adjust
705  // progress
706  int range = firstinpast + secondfound;
707 
708  if(range == 1)
709  return;
710 
711  progress = ((tick + progress) - (*first)->Tick) / range;
712 }
boost::circular_buffer< StoredState > ClientStateBuffer
Client side buffer of past states.
Definition: Components.h:192

◆ REFERENCE_HANDLE_UNCOUNTED_TYPE()

Leviathan::Received::REFERENCE_HANDLE_UNCOUNTED_TYPE ( Received  )

Member Data Documentation

◆ ClientStateBuffer

boost::circular_buffer<StoredState> Leviathan::Received::ClientStateBuffer

Client side buffer of past states.

Definition at line 192 of file Components.h.

◆ LocallyControlled

bool Leviathan::Received::LocallyControlled = false

If true this uses local control and will send updates to the server.

Definition at line 195 of file Components.h.

◆ TYPE

constexpr auto Leviathan::Received::TYPE = COMPONENT_TYPE::Received
static

Definition at line 197 of file Components.h.


The documentation for this class was generated from the following files: