Leviathan  0.8.0.0
Leviathan game engine
ComponentState.cpp
Go to the documentation of this file.
1 // ------------------------------------ //
2 #include "ComponentState.h"
3 
4 using namespace Leviathan;
5 // ------------------------------------ //
6 
7 // ------------------------------------ //
8 // EntityState
9 DLLEXPORT void EntityState::CreateUpdatePacket(EntityState& olderstate, sf::Packet& packet)
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 }
44 
45 DLLEXPORT void EntityState::AddDataToPacket(sf::Packet& packet)
46 {
47  for(const auto& component : ComponentStates)
48  component->AddDataToPacket(packet, nullptr);
49 }
std::vector< std::unique_ptr< BaseComponentState > > ComponentStates
Base for all component state classes.
DLLEXPORT void AddDataToPacket(sf::Packet &packet)
Adds full data to packet.
virtual DLLEXPORT void AddDataToPacket(sf::Packet &packet, BaseComponentState *olderstate) const =0
Adds update data to a packet.
DLLEXPORT void CreateUpdatePacket(EntityState &olderstate, sf::Packet &packet)
Creates a delta update to packet.
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
Holder of state for a whole entity.