Leviathan  0.8.0.0
Leviathan game engine
Component.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2016 Henri Hyyryläinen
3 #pragma once
4 // ------------------------------------ //
5 #include "Define.h"
6 
7 #include "Common/ObjectPool.h"
8 #include "Common/SFMLPackets.h"
9 #include "EntityCommon.h"
10 
11 #include <limits>
12 
13 // No clue where this is coming from...
14 #ifdef _WIN32
15 #undef max
16 #endif
17 
18 namespace Leviathan{
19 
21 enum class COMPONENT_TYPE : uint16_t{
22 
23  Position,
24 
26  RenderNode,
27 
28  Sendable,
29 
30  Received,
31 
32  Physics,
33 
35 
36  Model,
37 
39 
40  Camera,
41 
42  Plane,
43 
44  Animated,
45 
47  Custom = 10000
48 };
49 
50 
52 class Component{
53 public:
54 
55  inline Component(COMPONENT_TYPE type) : Marked(true), Type(type){};
56 
60  bool Marked;
61 
64 
65  Component(const Component&) = delete;
66  Component& operator =(const Component&) = delete;
67 };
68 
72 struct ComponentData {
73 
74 
75 };
76 
79 public:
80 
84  template<typename T>
86 
88  inline PotentiallyUpdatedValue(const T &value) : Value(value), Updated(1){}
89 
91  inline operator bool(){
92  return Updated;
93  }
94 
96  inline PotentiallyUpdatedValue& operator=(const T &value){
97 
98  Updated = true;
99  Value = value;
100  return *this;
101  }
102 
104  inline bool IsBitSet(uint8_t BitNum = 0) const
105  {
106  return (Updated & (1 << BitNum)) == 1;
107  }
108 
110  inline void SetBit(uint8_t BitNum = 0)
111  {
112  Updated |= (1 << BitNum);
113  }
114 
117  inline bool BitsSetUntil(uint8_t BitNum) const
118  {
119  if(BitNum == 0){
120 
121  return IsBitSet(0);
122 
123  } else {
124 
125  return IsBitSet(0) && BitsSetUntil(BitNum - 1);
126  }
127  }
128 
129  inline void SetAllBitsInUpdated(){
130 
131  Updated = std::numeric_limits<uint8_t>::max();
132  }
133 
138  uint8_t Updated = 0;
139  T Value;
140  };
141 
142 
143 
144 public:
145 
146  template<typename T>
148 
149  inline ComponentState(int32_t tick, COMPONENT_TYPE componenttype) :
150  Tick(tick), ComponentType(componenttype){}
151  virtual ~ComponentState(){}
152 
156  DLLEXPORT virtual void CreateUpdatePacket(ComponentState* olderstate,
157  sf::Packet &packet) = 0;
158 
161  DLLEXPORT virtual bool FillMissingData(ComponentState &otherstate) = 0;
162 
164  const int32_t Tick;
165 
167 
168  ComponentState(const ComponentState &other) = delete;
169  void operator=(const ComponentState &other) = delete;
170 };
171 
172 
173 template<class ComponentType>
174  class ComponentHolder : public ObjectPoolTracked<ComponentType, ObjectID>{
175 public:
176 
177 
178 
179 
180 };
181 }
182 
183 #ifdef LEAK_INTO_GLOBAL
185 #endif //LEAK_INTO_GLOBAL
186 
All values above this are application specific types.
PotentiallyUpdatedValue & operator=(const T &value)
Sets a new value and sets as Updated.
Definition: Component.h:96
COMPONENT_TYPE
Must contain all valid Component types.
Definition: Component.h:21
ComponentState(int32_t tick, COMPONENT_TYPE componenttype)
Definition: Component.h:149
bool BitsSetUntil(uint8_t BitNum) const
Returns true if up and including BitNum is set in Updated.
Definition: Component.h:117
const COMPONENT_TYPE Type
Type of this component, used for network serialization.
Definition: Component.h:63
unsigned char uint8_t
Definition: core.h:38
Base class for storing component states.
Definition: Component.h:78
Creates objects in a shared memory region.
Definition: ObjectPool.h:267
unsigned short uint16_t
Definition: core.h:39
Used to hold data with an updated flag to support partial states.
Definition: Component.h:85
const int32_t Tick
The tick this delta state matches.
Definition: Component.h:164
#define DLLEXPORT
Definition: Include.h:118
const COMPONENT_TYPE ComponentType
Definition: Component.h:166
Base class for all components.
Definition: Component.h:52
bool IsBitSet(uint8_t BitNum=0) const
Returns true if BitNum bit is set in Updated.
Definition: Component.h:104
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
void SetBit(uint8_t BitNum=0)
Sets BitNum bit in Updated.
Definition: Component.h:110
Base class for all component data.
Definition: Component.h:72