Leviathan  0.8.0.0
Leviathan game engine
Leviathan::BaseComponentState Class Referenceabstract

Base for all component state classes. More...

#include <ComponentState.h>

+ Inheritance diagram for Leviathan::BaseComponentState:

Public Member Functions

 BaseComponentState (float time, COMPONENT_TYPE componenttype)
 
virtual ~BaseComponentState ()
 
 BaseComponentState (const BaseComponentState &other) noexcept
 
 BaseComponentState (BaseComponentState &&other) noexcept
 
BaseComponentStateoperator= (const BaseComponentState &other) noexcept
 
BaseComponentStateoperator= (BaseComponentState &&other) noexcept
 
virtual DLLEXPORT void AddDataToPacket (sf::Packet &packet, BaseComponentState *olderstate) const =0
 Adds update data to a packet. More...
 
virtual DLLEXPORT bool FillMissingData (BaseComponentState &otherstate)=0
 Copies data to missing values in this state from another state. More...
 
bool IsBitSet (uint8_t bitnum=0) const
 Returns true if bitnum bit is set in UpdatedFields. More...
 
void SetBit (uint8_t bitnum=0)
 Sets bitnum bit in Updated. More...
 
void SetAllBitsInUpdated ()
 

Public Attributes

float StateTime
 
COMPONENT_TYPE ComponentType
 
uint8_t UpdatedFields = std::numeric_limits<uint8_t>::max()
 

Detailed Description

Base for all component state classes.

Definition at line 30 of file ComponentState.h.

Constructor & Destructor Documentation

◆ BaseComponentState() [1/3]

Leviathan::BaseComponentState::BaseComponentState ( float  time,
COMPONENT_TYPE  componenttype 
)
inline

Definition at line 32 of file ComponentState.h.

32  :
33  StateTime(time), ComponentType(componenttype)
34  {}

◆ ~BaseComponentState()

virtual Leviathan::BaseComponentState::~BaseComponentState ( )
inlinevirtual

Definition at line 35 of file ComponentState.h.

35 {}

◆ BaseComponentState() [2/3]

Leviathan::BaseComponentState::BaseComponentState ( const BaseComponentState other)
inlinenoexcept

Definition at line 37 of file ComponentState.h.

37  :
38  StateTime(other.StateTime), ComponentType(other.ComponentType),
39  UpdatedFields(other.UpdatedFields)
40  {}

◆ BaseComponentState() [3/3]

Leviathan::BaseComponentState::BaseComponentState ( BaseComponentState &&  other)
inlinenoexcept

Definition at line 42 of file ComponentState.h.

42  :
43  StateTime(other.StateTime), ComponentType(other.ComponentType),
44  UpdatedFields(other.UpdatedFields)
45  {}

Member Function Documentation

◆ AddDataToPacket()

virtual DLLEXPORT void Leviathan::BaseComponentState::AddDataToPacket ( sf::Packet &  packet,
BaseComponentState olderstate 
) const
pure virtual

Adds update data to a packet.

Parameters
olderstateThe state against which this is compared. Or null if a full update is wanted
Warning
olderstate MUST BE of the same child class as this. Otherwise everything will explode

◆ FillMissingData()

virtual DLLEXPORT bool Leviathan::BaseComponentState::FillMissingData ( BaseComponentState otherstate)
pure virtual

Copies data to missing values in this state from another state.

Returns
True if all missing values have been filled
Warning
otherstate MUST BE of the same child class as this. Otherwise everything will explode

◆ IsBitSet()

bool Leviathan::BaseComponentState::IsBitSet ( uint8_t  bitnum = 0) const
inline

Returns true if bitnum bit is set in UpdatedFields.

Parameters
BitNumthe index of the bit to set. Starts at 0 and last valid is 7

Definition at line 79 of file ComponentState.h.

80  {
81  return (UpdatedFields & (1 << bitnum)) == 1;
82  }

◆ operator=() [1/2]

BaseComponentState& Leviathan::BaseComponentState::operator= ( const BaseComponentState other)
inlinenoexcept

Definition at line 47 of file ComponentState.h.

48  {
49  StateTime = other.StateTime;
50  ComponentType = other.ComponentType;
51  UpdatedFields = other.UpdatedFields;
52  return *this;
53  }

◆ operator=() [2/2]

BaseComponentState& Leviathan::BaseComponentState::operator= ( BaseComponentState &&  other)
inlinenoexcept

Definition at line 55 of file ComponentState.h.

56  {
57  StateTime = other.StateTime;
58  ComponentType = other.ComponentType;
59  UpdatedFields = other.UpdatedFields;
60  return *this;
61  }

◆ SetAllBitsInUpdated()

void Leviathan::BaseComponentState::SetAllBitsInUpdated ( )
inline

Definition at line 91 of file ComponentState.h.

92  {
93  UpdatedFields = std::numeric_limits<uint8_t>::max();
94  }

◆ SetBit()

void Leviathan::BaseComponentState::SetBit ( uint8_t  bitnum = 0)
inline

Sets bitnum bit in Updated.

See also
IsBitSet

Definition at line 86 of file ComponentState.h.

87  {
88  UpdatedFields |= (1 << bitnum);
89  }

Member Data Documentation

◆ ComponentType

COMPONENT_TYPE Leviathan::BaseComponentState::ComponentType

The component type. This is needed to handle the actual subclasses that have data without having to do virtual method calls to find matching types

Definition at line 104 of file ComponentState.h.

◆ StateTime

float Leviathan::BaseComponentState::StateTime

The time this state was captured at This is used for rebuilding delta states. And on the client for interpolating between states

Definition at line 100 of file ComponentState.h.

◆ UpdatedFields

uint8_t Leviathan::BaseComponentState::UpdatedFields = std::numeric_limits<uint8_t>::max()

Some components have properties that don't change very often so here is reserved 8 bits to let the state object have more granularity as to which parts of it need to be sent over the network

Definition at line 109 of file ComponentState.h.


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