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 (int32_t tick, 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

int32_t TickNumber
 
COMPONENT_TYPE ComponentType
 
uint8_t UpdatedFields = std::numeric_limits<uint8_t>::max()
 

Detailed Description

Base for all component state classes.

Definition at line 40 of file ComponentState.h.

Constructor & Destructor Documentation

◆ BaseComponentState() [1/3]

Leviathan::BaseComponentState::BaseComponentState ( int32_t  tick,
COMPONENT_TYPE  componenttype 
)
inline

Definition at line 42 of file ComponentState.h.

42  :
43  TickNumber(tick), ComponentType(componenttype)
44  {}

◆ ~BaseComponentState()

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

Definition at line 45 of file ComponentState.h.

45 {}

◆ BaseComponentState() [2/3]

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

Definition at line 47 of file ComponentState.h.

47  :
48  TickNumber(other.TickNumber), ComponentType(other.ComponentType),
49  UpdatedFields(other.UpdatedFields)
50  {}

◆ BaseComponentState() [3/3]

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

Definition at line 52 of file ComponentState.h.

52  :
53  TickNumber(other.TickNumber), ComponentType(other.ComponentType),
54  UpdatedFields(other.UpdatedFields)
55  {}

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 89 of file ComponentState.h.

90  {
91  return (UpdatedFields & (1 << bitnum)) == 1;
92  }

◆ operator=() [1/2]

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

Definition at line 57 of file ComponentState.h.

58  {
59  TickNumber = other.TickNumber;
60  ComponentType = other.ComponentType;
61  UpdatedFields = other.UpdatedFields;
62  return *this;
63  }

◆ operator=() [2/2]

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

Definition at line 65 of file ComponentState.h.

66  {
67  TickNumber = other.TickNumber;
68  ComponentType = other.ComponentType;
69  UpdatedFields = other.UpdatedFields;
70  return *this;
71  }

◆ SetAllBitsInUpdated()

void Leviathan::BaseComponentState::SetAllBitsInUpdated ( )
inline

Definition at line 101 of file ComponentState.h.

102  {
103  UpdatedFields = std::numeric_limits<uint8_t>::max();
104  }

◆ SetBit()

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

Sets bitnum bit in Updated.

See also
IsBitSet

Definition at line 96 of file ComponentState.h.

97  {
98  UpdatedFields |= (1 << bitnum);
99  }

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 113 of file ComponentState.h.

◆ TickNumber

int32_t Leviathan::BaseComponentState::TickNumber

The tick this state was captured on This is used for rebuilding delta states

Definition at line 109 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 118 of file ComponentState.h.


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