Leviathan  0.8.0.0
Leviathan game engine
Leviathan::EntityState Class Reference

Holder of state for a whole entity. More...

#include <ComponentState.h>

Public Member Functions

DLLEXPORT void CreateUpdatePacket (EntityState &olderstate, sf::Packet &packet)
 Creates a delta update to packet. More...
 
DLLEXPORT void AddDataToPacket (sf::Packet &packet)
 Adds full data to packet. More...
 
void Append (std::unique_ptr< BaseComponentState > &&state)
 

Public Attributes

std::vector< std::unique_ptr< BaseComponentState > > ComponentStates
 

Detailed Description

Holder of state for a whole entity.

Definition at line 126 of file ComponentState.h.

Member Function Documentation

◆ AddDataToPacket()

DLLEXPORT void EntityState::AddDataToPacket ( sf::Packet &  packet)

Adds full data to packet.

Note
This is a separate method from CreateUpdatePacket because this is more efficient as this doesn't try to match up the different component states

Definition at line 45 of file ComponentState.cpp.

46 {
47  for(const auto& component : ComponentStates)
48  component->AddDataToPacket(packet, nullptr);
49 }
std::vector< std::unique_ptr< BaseComponentState > > ComponentStates

◆ Append()

void Leviathan::EntityState::Append ( std::unique_ptr< BaseComponentState > &&  state)
inline

Definition at line 137 of file ComponentState.h.

138  {
139  ComponentStates.push_back(std::move(state));
140  }
std::vector< std::unique_ptr< BaseComponentState > > ComponentStates

◆ CreateUpdatePacket()

DLLEXPORT void EntityState::CreateUpdatePacket ( EntityState olderstate,
sf::Packet &  packet 
)

Creates a delta update to packet.

Definition at line 9 of file ComponentState.cpp.

10 {
11  // We need to match up the components from us to the old states
12  const bool checkSameIndexFirst =
13  olderstate.ComponentStates.size() == ComponentStates.size();
14 
15  for(size_t i = 0; i < ComponentStates.size(); ++i) {
16 
17  const auto& component = ComponentStates[i];
18 
19  BaseComponentState* olderMatchingState = nullptr;
20 
21  if(checkSameIndexFirst) {
22 
23  if(olderstate.ComponentStates[i]->ComponentType == component->ComponentType) {
24 
25  olderMatchingState = olderstate.ComponentStates[i].get();
26  }
27  }
28 
29  if(!olderMatchingState) {
30 
31  for(const auto& oldComponent : olderstate.ComponentStates) {
32 
33  if(oldComponent->ComponentType == component->ComponentType) {
34 
35  olderMatchingState = oldComponent.get();
36  break;
37  }
38  }
39  }
40 
41  component->AddDataToPacket(packet, olderMatchingState);
42  }
43 }
std::vector< std::unique_ptr< BaseComponentState > > ComponentStates
Base for all component state classes.
virtual DLLEXPORT void AddDataToPacket(sf::Packet &packet, BaseComponentState *olderstate) const =0
Adds update data to a packet.

Member Data Documentation

◆ ComponentStates

std::vector<std::unique_ptr<BaseComponentState> > Leviathan::EntityState::ComponentStates

Definition at line 142 of file ComponentState.h.


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