Compare commits

..

5 Commits

Author SHA1 Message Date
Jace 36477abc63 WTF? 2016-03-08 18:26:03 +01:00
Jace 5d53fc74cb Merge branch 'Dirtybit' of github.com:teamfisk/TacticalZ into Dirtybit 2016-03-08 15:46:21 +01:00
Jace ecc8d998cf Added ComponentInfo::Field_t::Index 2016-03-08 15:46:14 +01:00
William Moberg e3c0fb2178 Added SetDirty function. 2016-03-08 15:44:02 +01:00
William Moberg 090bd806ce Added DirtyBit enum to Dirty getter in ComponentWrapper. 2016-03-08 15:39:16 +01:00
23 changed files with 2357 additions and 3285 deletions
+12
View File
@@ -2,6 +2,7 @@
#define ComponentInfo_h__
#include "../Common.h"
#include "Entity.h"
#include <boost/shared_array.hpp>
struct ComponentInfo
@@ -21,6 +22,7 @@ struct ComponentInfo
{
std::string Name;
std::string Type;
unsigned char Index;
unsigned int Offset;
unsigned int Stride;
};
@@ -32,6 +34,16 @@ struct ComponentInfo
unsigned int Stride = 0;
boost::shared_array<char> Defaults = nullptr;
std::shared_ptr<Meta_t> Meta = nullptr;
std::size_t GetHeaderSize() const
{
std::size_t size = 0;
// A component block starts with an entity ID
size += sizeof(EntityID);
return size;
}
};
template<>
+11 -8
View File
@@ -5,16 +5,15 @@
#include "MemoryPool.h"
#include "ComponentInfo.h"
#include "ComponentWrapper.h"
#include "DirtySet.h"
class ComponentPool;
class ComponentPoolForwardIterator
: public std::iterator<std::forward_iterator_tag, ComponentWrapper>
{
public:
ComponentPoolForwardIterator(const ComponentInfo& componentInfo, const MemoryPool<char>::iterator begin, const MemoryPool<char>::iterator end)
: m_ComponentInfo(componentInfo)
, m_MemoryPoolIterator(begin)
, m_MemoryPoolEnd(end)
{ }
ComponentPoolForwardIterator(ComponentPool* pool);
ComponentPoolForwardIterator(const ComponentPoolForwardIterator& other) = default;
ComponentPoolForwardIterator(ComponentPoolForwardIterator&& other) = default;
@@ -27,6 +26,7 @@ public:
ComponentWrapper operator*() const;
private:
ComponentPool* m_ComponentPool;
const ComponentInfo& m_ComponentInfo;
MemoryPool<char>::iterator m_MemoryPoolIterator;
const MemoryPool<char>::iterator m_MemoryPoolEnd;
@@ -34,6 +34,7 @@ private:
class ComponentPool
{
friend class ComponentPoolForwardIterator;
public:
typedef ComponentPoolForwardIterator iterator;
typedef ptrdiff_t difference_type;
@@ -41,10 +42,11 @@ public:
typedef ComponentWrapper value_type;
typedef ComponentWrapper* pointer;
typedef ComponentWrapper& reference;
typedef std::unordered_map<EntityID, std::set<decltype(ComponentInfo::Field_t::Index)>> DirtySet_t;
ComponentPool(const ::ComponentInfo& ci)
: m_ComponentInfo(ci)
, m_Pool(ci.Meta->Allocation, sizeof(EntityID) + ci.Stride)
, m_Pool(ci.Meta->Allocation, ci.GetHeaderSize() + ci.Stride)
{ }
~ComponentPool();
ComponentPool(const ComponentPool& other);
@@ -61,8 +63,8 @@ public:
// Delete a component and free its memory
void Delete(ComponentWrapper& wrapper);
iterator begin() const;
iterator end() const;
iterator begin();
iterator end();
size_t size() const;
//Dumps information about what the pool memory looks like right now
@@ -80,6 +82,7 @@ private:
::ComponentInfo m_ComponentInfo;
MemoryPool<char> m_Pool;
std::unordered_map<EntityID, char*> m_EntityToComponent;
DirtySet m_DirtySet;
};
#endif
+43 -31
View File
@@ -6,44 +6,54 @@
#include "../Common.h"
#include "Entity.h"
#include "ComponentInfo.h"
#include "DirtySet.h"
#include "Util/Any.h"
template <typename T, typename Enable = void>
struct ComponentField { };
template <typename T>
struct ComponentField<T, typename std::enable_if<std::is_trivially_copyable<T>::value>::type>
{
static T& Get(const ComponentInfo::Field_t& info, char* data) { return *reinterpret_cast<T*>(data); }
static void Set(const ComponentInfo::Field_t& info, char* data, const T& value) { Get(data) = value; }
};
template <>
struct ComponentField<std::string, void>
{
static std::string& Get(const ComponentInfo::Field_t& info, char* data) { return **reinterpret_cast<std::string**>(data); }
static void Set(const ComponentInfo::Field_t& info, char* data, const std::string& value) { Get(info, data) = value; }
};
struct ComponentWrapper
{
ComponentWrapper(const ComponentInfo& componentInfo, char* data)
ComponentWrapper(const ComponentInfo& componentInfo, char* data, ::DirtyBitField* dirtyBitField)
: Info(componentInfo)
, EntityID(*reinterpret_cast<::EntityID*>(data))
, Data(data + sizeof(::EntityID))
, Data(data + componentInfo.GetHeaderSize())
, DirtyBitField(dirtyBitField)
{ }
const ComponentInfo& Info;
const ::EntityID EntityID;
char* Data;
::DirtyBitField* DirtyBitField = nullptr;
ComponentInfo::EnumType Enum(const char* fieldName, const char* enumKey)
{
return Info.Meta->FieldEnumDefinitions.at(fieldName).at(enumKey);
}
bool Dirty(DirtySetType type, const std::string& fieldName)
{
if (DirtyBitField == nullptr) {
return true;
} else {
auto& field = Info.Fields.at(fieldName);
return DirtyBitField->operator[](type).count(field.Index) == 1;
}
}
void SetDirty(DirtySetType type, const std::string& fieldName, bool dirty = true)
{
if (DirtyBitField == nullptr) {
return;
}
auto& field = Info.Fields.at(fieldName);
if (dirty) {
DirtyBitField->operator[](type).insert(field.Index);
} else {
DirtyBitField->operator[](type).erase(field.Index);
}
}
template <typename T>
T& Field(std::string name)
T& Field(const std::string& name)
{
const ComponentInfo::Field_t& field = Info.Fields.at(name);
if (sizeof(T) > field.Stride) {
@@ -55,13 +65,13 @@ struct ComponentWrapper
}
template <typename T>
void SetField(std::string name, const T value) { Field<T>(name) = value; }
void SetField(const std::string& name, const T value) { Field<T>(name) = value; }
//template <typename T>
//void SetField(std::string name, T& value) { Field<T>(name) = value; }
// Specialization for string literals
template <std::size_t N>
void SetField(std::string name, const char(&value)[N]) { Field<std::string>(name) = std::string(value); }
void SetField(const std::string& name, const char(&value)[N]) { Field<std::string>(name) = std::string(value); }
void Copy(ComponentWrapper& destination)
{
@@ -96,39 +106,41 @@ struct ComponentWrapper
{
friend struct ComponentWrapper;
private:
SubscriptProxy(ComponentWrapper* component, std::string propertyName)
SubscriptProxy(ComponentWrapper* component, std::string fieldName)
: m_Component(component)
, m_PropertyName(propertyName)
, m_FieldName(fieldName)
{ }
ComponentWrapper* m_Component;
std::string m_PropertyName;
std::string m_FieldName;
public:
// Return the integer value of an enum type key for this field
ComponentInfo::EnumType Enum(const char* enumKey) { return m_Component->Enum(m_PropertyName.c_str(), enumKey); }
ComponentInfo::EnumType Enum(const char* enumKey) { return m_Component->Enum(m_FieldName.c_str(), enumKey); }
bool Dirty(DirtySetType type) { return m_Component->Dirty(type, m_FieldName); }
void SetDirty(DirtySetType type, bool dirty = true) { m_Component->SetDirty(type, m_FieldName, dirty); }
template <typename T>
operator T&() { return m_Component->Field<T>(m_PropertyName); }
operator T&() { return m_Component->Field<T>(m_FieldName); }
template <typename T>
void operator=(const T val) { m_Component->SetField<T>(m_PropertyName, val); }
void operator=(const T val) { m_Component->SetField<T>(m_FieldName, val); }
// TODO: Pass by reference and rvalue (universal reference?)
//template <typename T>
//void operator=(T& val) { m_Component->SetField<T>(m_PropertyName, val); }
// Specialization for string literals
template <std::size_t N>
void operator=(const char(&val)[N]) { m_Component->SetField<N>(m_PropertyName, val); }
void operator=(const char(&val)[N]) { m_Component->SetField<N>(m_FieldName, val); }
};
SubscriptProxy operator[](std::string propertyName) { return SubscriptProxy(this, propertyName); }
SubscriptProxy operator[](const std::string& propertyName) { return SubscriptProxy(this, propertyName); }
};
// A component wrapper that "owns" its data through a shared pointer
struct SharedComponentWrapper : ComponentWrapper
{
SharedComponentWrapper(const ComponentInfo& componentInfo, boost::shared_array<char> data)
: ComponentWrapper(componentInfo, data.get())
: ComponentWrapper(componentInfo, data.get(), nullptr)
, m_DataReference(data)
{ }
+16
View File
@@ -0,0 +1,16 @@
#ifndef DirtySet_h__
#define DirtySet_h__
#include <set>
#include "ComponentInfo.h"
enum class DirtySetType
{
Transform,
Network
};
typedef std::unordered_map<DirtySetType, std::set<decltype(ComponentInfo::Field_t::Index)>> DirtyBitField;
typedef std::unordered_map<EntityID, DirtyBitField> DirtySet;
#endif
+1 -1
View File
@@ -81,7 +81,7 @@ public:
for (auto& pair : group.PureSystems) {
const std::string& componentName = pair.first;
auto& systems = pair.second;
const ComponentPool* pool = m_World->GetComponents(componentName);
ComponentPool* pool = m_World->GetComponents(componentName);
if (pool == nullptr) {
continue;
}
+1 -1
View File
@@ -35,7 +35,7 @@ public:
// Delete a component off an entity
void DeleteComponent(EntityID entity, const std::string& componentType);
// Get all components of the specified type
const ComponentPool* GetComponents(const std::string& componentType);
ComponentPool* GetComponents(const std::string& componentType);
// Get entity parent
EntityID GetParent(EntityID entity);
// Change the parent of an entity
-3
View File
@@ -24,10 +24,7 @@ private:
bool OnPlayerDeath(Events::PlayerDeath& e);
EventRelay<PlayerDeathSystem, Events::EntityDeleted> m_EEntityDeleted;
bool OnEntityDeleted(Events::EntityDeleted& e);
EventRelay<PlayerDeathSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(Events::InputCommand& e);
void setSpectatorCamera();
void createDeathEffect(EntityWrapper player);
};
-9
View File
@@ -15,19 +15,10 @@ public:
virtual void Update(double dt) override;
private:
// This enum must correspond to the command values for PickTeam buttons.
enum class PlayerClass
{
None = 0,
Assault,
Defender,
Sniper
};
struct SpawnRequest
{
int PlayerID;
ComponentInfo::EnumType Team;
PlayerClass Class;
};
bool m_NetworkEnabled = false;
@@ -1,22 +0,0 @@
#ifndef SpectatorCameraSystem_h__
#define SpectatorCameraSystem_h__
#include "Core/System.h"
#include "Input/EInputCommand.h"
class SpectatorCameraSystem : public ImpureSystem
{
public:
SpectatorCameraSystem(SystemParams params);
virtual void Update(double dt) override;
private:
int m_PickedTeam;
bool m_CamSetToTeamPick;
EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
};
#endif
+1 -2
View File
@@ -28,5 +28,4 @@ P=SwitchToPlayer
K=TakeDamage,1500
F2=PerformanceTimingResetAllTimers
F3=PerformanceTimingCreateExcelData
Comma=SwapToClassPick
Period=SwapToTeamPick
F4=SwapToClassPick
@@ -13,80 +13,6 @@
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="0.811270177" Y="0.440691769" Z="-0.100000001"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePointHUD>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="1.62788737" Y="0.919596612" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>4</CapturePointNumber>
</c:CapturePointHUD>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
@@ -96,21 +22,84 @@
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="0.811270177" Y="0.440691769" Z="-0.100000001"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:CapturePointHUD>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Percentage>0.80222018197612788</Percentage>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="1.62788737" Y="0.919596612" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:CapturePointHUD>
<CapturePointNumber>4</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
</c:Transform>
</Components>
<Children/>
@@ -121,8 +110,6 @@
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
@@ -132,21 +119,19 @@
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
</c:Transform>
</Components>
<Children/>
@@ -157,9 +142,7 @@
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.699999988" B="0" G="0" R="1"/>
<Color A="0.699999988" B="0" G="0.200000003" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="-1.58304751" Y="0.919596612" Z="0"/>
@@ -168,19 +151,17 @@
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:CapturePointHUD/>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
</c:Transform>
</Components>
<Children/>
File diff suppressed because it is too large Load Diff
+142 -539
View File
@@ -8,7 +8,6 @@
</c:RaptorCopter>
<c:Transform>
<Position X="0" Y="-4" Z="0"/>
<Orientation X="0" Y="55.3495064" Z="0"/>
</c:Transform>
</Components>
@@ -21,369 +20,6 @@
</c:Transform>
</Components>
<Children>
<Entity name="PickClassCamera">
<Components>
<c:Camera/>
<c:Transform/>
</Components>
<Children>
<Entity name="PickClassHUD">
<Components>
<c:Transform>
<Position X="0" Y="-0" Z="-0.5"/>
</c:Transform>
</Components>
<Children>
<Entity name="DefenderClassPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Icons/Classes/Defender-01.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:InputCmdButton>
<Command>PickClass</Command>
<PressValue>2</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0" Y="-0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="DefenderText">
<Components>
<c:Text>
<Content>Defender</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="1" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0.800000012" Z="0"/>
<Scale X="0.310000002" Y="0.310000002" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="SniperClassPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Icons/Classes/Sniper-01.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:InputCmdButton>
<Command>PickClass</Command>
<PressValue>3</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0.150000006" Y="-0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="SniperText">
<Components>
<c:Text>
<Content>Sniper</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="1" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0.800000012" Z="0"/>
<Scale X="0.310000002" Y="0.310000002" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="AssaultClassPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Icons/Classes/Assault-01.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:InputCmdButton>
<Command>PickClass</Command>
<PressValue>1</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="-0.150000006" Y="-0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="AssaultText">
<Components>
<c:Text>
<Content>Assault</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="1" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0.800000012" Z="0"/>
<Scale X="0.310000002" Y="0.310000002" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="ClassPickText">
<Components>
<c:Text>
<Content>Pick Class</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="1" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0.0799999982" Z="0"/>
<Scale X="0.0250000004" Y="0.0250000004" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ToTeamPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0" G="1" R="0.509803951"/>
</c:Sprite>
<c:InputCmdButton>
<Command>SwapToTeamPick</Command>
<PressValue>1</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0.349999994" Y="-0.180000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="ChangeText">
<Components>
<c:Text>
<Content>Change</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="0" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="TeamText">
<Components>
<c:Text>
<Content>Team</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.224999994" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity name="PickTeamCamera">
<Components>
<c:Camera/>
<c:Transform/>
</Components>
<Children>
<Entity name="PickTeamHUD">
<Components>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
</c:Transform>
</Components>
<Children>
<Entity name="TeamPickText">
<Components>
<c:Text>
<Content>Pick Team</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="1" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0.0799999982" Z="0"/>
<Scale X="0.0250000004" Y="0.0250000004" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="SpectatorPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0" G="1" R="0.509803951"/>
</c:Sprite>
<c:InputCmdButton>
<Command>PickTeam</Command>
<PressValue>1</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0" Y="-0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="SpectatorText">
<Components>
<c:Text>
<Content>Spectator</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.0450000018" Z="0.00200000009"/>
<Scale X="0.200000003" Y="0.200000003" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="TeamRedPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0" G="0.294117659" R="0.980392158"/>
</c:Sprite>
<c:InputCmdButton>
<Command>PickTeam</Command>
<PressValue>2</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0.150000006" Y="-0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="RedText">
<Components>
<c:Text>
<Content>Red</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.0850000009" Z="0.00249999994"/>
<Scale X="0.310000002" Y="0.310000002" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="TeamBluePick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0.980392158" G="0.294117659" R="0"/>
</c:Sprite>
<c:InputCmdButton>
<Command>PickTeam</Command>
<PressValue>3</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="-0.150000006" Y="-0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="BlueText">
<Components>
<c:Text>
<Content>Blue</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.0850000009" Z="0.00200000009"/>
<Scale X="0.310000002" Y="0.310000002" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="ToClassPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0" G="1" R="0.509803951"/>
<Visible>false</Visible>
</c:Sprite>
<c:InputCmdButton>
<Command>SwapToClassPick</Command>
<PressValue>1</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0.349999994" Y="-0.0800000057" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="ChangeText">
<Components>
<c:Text>
<Content>Change</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Visible>false</Visible>
</c:Text>
<c:Transform>
<Position X="0" Y="0" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ClassText">
<Components>
<c:Text>
<Content>Class</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Visible>false</Visible>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.224999994" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity name="SpectatorCamera">
<Components>
<c:Camera/>
@@ -397,20 +33,6 @@
</c:Transform>
</Components>
<Children>
<Entity name="RespawnTimer">
<Components>
<c:Text>
<Content>7</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="1" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0.178199276" Z="0"/>
<Scale X="0.0250000004" Y="0.0250000004" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="CapturePointHUD">
<Components>
<c:Transform>
@@ -424,79 +46,6 @@
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="0.811270177" Y="0.440691769" Z="-0.100000001"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePointHUD>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="1.62788737" Y="0.919596612" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>4</CapturePointNumber>
</c:CapturePointHUD>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
@@ -506,16 +55,83 @@
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>2</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="0.811270177" Y="0.440691769" Z="-0.100000001"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:CapturePointHUD>
<CapturePointNumber>3</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
<Orientation X="0" Y="0" Z="1.57079637"/>
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="BackgroundHexagon">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="1.62788737" Y="0.919596612" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:CapturePointHUD>
<CapturePointNumber>4</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
@@ -532,7 +148,6 @@
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.300000012" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
@@ -542,17 +157,16 @@
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:CapturePointHUD>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePointHUD>
<c:Fill>
<Percentage>0.10332605343919568</Percentage>
<Color A="0.699999988" B="0" G="0" R="1"/>
</c:Fill>
<c:CapturePointHUD>
<CapturePointNumber>1</CapturePointNumber>
</c:CapturePointHUD>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
@@ -569,7 +183,6 @@
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.699999988" B="0" G="0" R="1"/>
</c:Sprite>
<c:Transform>
@@ -579,14 +192,13 @@
<Children>
<Entity name="ProgressionHexagon">
<Components>
<c:CapturePointHUD/>
<c:Fill>
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
</c:Fill>
<c:CapturePointHUD/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="0.00999999978"/>
@@ -600,99 +212,90 @@
</Entity>
</Children>
</Entity>
<Entity name="ToTeamPick">
<Entity name="RespawnTimer">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0" G="1" R="0.509803951"/>
</c:Sprite>
<c:InputCmdButton>
<Command>SwapToTeamPick</Command>
<PressValue>1</PressValue>
</c:InputCmdButton>
<c:Text>
<Content>16</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="1" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0.349999994" Y="-0.180000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
<Position X="0" Y="0.178199276" Z="0"/>
<Scale X="0.0250000004" Y="0.0250000004" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="ChangeText">
<Components>
<c:Text>
<Content>Change</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="0" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="TeamText">
<Components>
<c:Text>
<Content>Team</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.224999994" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
<Children/>
</Entity>
<Entity name="ToClassPick">
</Children>
</Entity>
</Children>
</Entity>
<Entity name="PickClassCamera">
<Components>
<c:Camera/>
<c:Transform/>
</Components>
<Children>
<Entity name="PickClassHUD">
<Components>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
</c:Transform>
</Components>
<Children>
<Entity name="DefenderClassPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0" G="1" R="0.509803951"/>
</c:Sprite>
<c:InputCmdButton>
<Command>SwapToClassPick</Command>
<PressValue>1</PressValue>
<Command>PickClass</Command>
<PressValue>2</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0.349999994" Y="-0.0800000057" Z="0"/>
<Position X="0.349999994" Y="0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity name="ChangeText">
<Components>
<c:Text>
<Content>Change</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="0" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ClassText">
<Components>
<c:Text>
<Content>Class</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.224999994" Z="0.00200000009"/>
<Scale X="0.25" Y="0.25" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
<Children/>
</Entity>
<Entity name="AssaultClassPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitRaptor.png</DiffuseTexture>
<GlowMap></GlowMap>
</c:Sprite>
<c:InputCmdButton>
<Command>PickClass</Command>
<PressValue>1</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0.349999994" Y="0.149504215" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="SniperClassPick">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Test/aM4ME4GR.png</DiffuseTexture>
<GlowMap></GlowMap>
</c:Sprite>
<c:InputCmdButton>
<Command>PickClass</Command>
<PressValue>3</PressValue>
</c:InputCmdButton>
<c:Transform>
<Position X="0.349999994" Y="-0.0500000007" Z="0"/>
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+18 -7
View File
@@ -1,9 +1,17 @@
#include "Core/ComponentPool.h"
ComponentPoolForwardIterator::ComponentPoolForwardIterator(ComponentPool* pool)
: m_ComponentPool(pool)
, m_ComponentInfo(pool->m_ComponentInfo)
, m_MemoryPoolIterator(pool->m_Pool.begin())
, m_MemoryPoolEnd(pool->m_Pool.end())
{ }
ComponentWrapper ComponentPoolForwardIterator::operator*() const
{
char* data = &(*m_MemoryPoolIterator);
ComponentWrapper wrapper(m_ComponentInfo, data);
EntityID entity = *reinterpret_cast<EntityID*>(data);
ComponentWrapper wrapper(m_ComponentInfo, data, &m_ComponentPool->m_DirtySet[entity]);
return wrapper;
}
@@ -71,7 +79,7 @@ ComponentWrapper ComponentPool::Allocate(EntityID entity)
memcpy(data, &entity, sizeof(EntityID));
m_EntityToComponent[entity] = data;
ComponentWrapper component(m_ComponentInfo, data);
ComponentWrapper component(m_ComponentInfo, data, &m_DirtySet[entity]);
// Copy defaults
memcpy(component.Data, m_ComponentInfo.Defaults.get(), m_ComponentInfo.Stride);
@@ -82,7 +90,9 @@ ComponentWrapper ComponentPool::Allocate(EntityID entity)
ComponentWrapper ComponentPool::GetByEntity(EntityID ent)
{
return ComponentWrapper(m_ComponentInfo, m_EntityToComponent.at(ent));
auto data = m_EntityToComponent.at(ent);
auto bitField = &m_DirtySet[ent];
return ComponentWrapper(m_ComponentInfo, data, bitField);
}
bool ComponentPool::KnowsEntity(EntityID ent)
@@ -95,16 +105,17 @@ void ComponentPool::Delete(ComponentWrapper& wrapper)
ComponentWrapper::Destroy(wrapper.Info, wrapper.Data);
m_EntityToComponent.erase(wrapper.EntityID);
m_Pool.Free(wrapper.Data - sizeof(EntityID));
m_DirtySet.erase(wrapper.EntityID);
}
ComponentPool::iterator ComponentPool::begin() const
ComponentPool::iterator ComponentPool::begin()
{
return iterator(m_ComponentInfo, m_Pool.begin(), m_Pool.end());
return iterator(this);
}
ComponentPool::iterator ComponentPool::end() const
ComponentPool::iterator ComponentPool::end()
{
return iterator(m_ComponentInfo, m_Pool.end(), m_Pool.end());
return iterator(this);
}
size_t ComponentPool::size() const
@@ -125,6 +125,7 @@ void EntityXMLFilePreprocessor::parseComponentInfo()
auto modelGroup = modelGroupParticle->getModelGroupTerm();
// <xs:element...
unsigned char fieldIndex = 0;
unsigned int fieldOffset = 0;
auto particles = modelGroup->getParticles();
for (unsigned int i = 0; i < particles->size(); ++i) {
@@ -182,12 +183,14 @@ void EntityXMLFilePreprocessor::parseComponentInfo()
auto& field = compInfo.Fields[name];
field.Name = name;
field.Type = effectiveType;
field.Index = fieldIndex;
field.Offset = fieldOffset;
field.Stride = stride;
compInfo.FieldsInOrder.push_back(name);
if (field.Type == "string") {
compInfo.StringFields.push_back(name);
}
fieldIndex += 1;
fieldOffset += stride;
}
+1 -1
View File
@@ -95,7 +95,7 @@ void World::DeleteComponent(EntityID entity, const std::string& componentType)
}
}
const ComponentPool* World::GetComponents(const std::string& componentType)
ComponentPool* World::GetComponents(const std::string& componentType)
{
auto it = m_ComponentPools.find(componentType);
return (it != m_ComponentPools.end()) ? it->second : nullptr;
+2 -2
View File
@@ -40,7 +40,7 @@ bool ButtonSystem::OnMousePress(const Events::MousePress& e)
//You have clicked on a button entity, send pressed event.
if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) {
Events::InputCommand eInputCmd;
eInputCmd.PlayerID = -1;
eInputCmd.PlayerID = LocalPlayer.ID;
eInputCmd.Player = LocalPlayer;
EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity);
eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"];
@@ -68,7 +68,7 @@ bool ButtonSystem::OnMouseRelease(const Events::MouseRelease& e)
if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) {
Events::InputCommand eInputCmd;
eInputCmd.PlayerID = -1;
eInputCmd.PlayerID = LocalPlayer.ID;
eInputCmd.Player = LocalPlayer;
EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity);
eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"];
-2
View File
@@ -35,7 +35,6 @@
#include "Game/Systems/BoostSystem.h"
#include "Game/Systems/BoostIconsHUDSystem.h"
#include "Game/Systems/ScoreScreenSystem.h"
#include "Game/Systems/SpectatorCameraSystem.h"
#include "GUI/ButtonSystem.h"
#include "GUI/MainMenuSystem.h"
@@ -150,7 +149,6 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<BoostIconsHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ScoreScreenSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<SpectatorCameraSystem>(updateOrderLevel);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
+7 -30
View File
@@ -1,12 +1,10 @@
#include "Systems/PlayerDeathSystem.h"
#include "Core/ELockMouse.h"
PlayerDeathSystem::PlayerDeathSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerDeathSystem::OnPlayerDeath);
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &PlayerDeathSystem::OnEntityDeleted);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &PlayerDeathSystem::OnInputCommand);
}
void PlayerDeathSystem::Update(double dt)
@@ -35,10 +33,10 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
//components that we need from player
auto playerModel = player.FirstChildByName("PlayerModel");
if (!playerModel.Valid()) {
return;
}
if (!playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) {
if (player == LocalPlayer) {
setSpectatorCamera();
}
return;
}
auto playerEntityModel = playerModel["Model"];
@@ -70,35 +68,14 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) {
return false;
}
// If the player hasn't spawned already, activate the spectator camera.
if (!LocalPlayer.Valid()) {
setSpectatorCamera();
}
return true;
}
void PlayerDeathSystem::setSpectatorCamera()
{
// Look for the spectator camera entity in the level.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
if (!spectatorCam.HasComponent("Camera")) {
return;
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) {
return false;
}
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
bool PlayerDeathSystem::OnInputCommand(Events::InputCommand& e)
{
if (e.Value == 0 || e.Command != "SwapToTeamPick" && e.Command != "SwapToClassPick") {
return false;
}
// Ensure that we don't set spectator camera if the player deliberately changes to class/team pick.
m_LocalPlayerDeathEffect = EntityWrapper::Invalid;
return true;
}
}
+1 -1
View File
@@ -29,7 +29,7 @@ void PlayerMovementSystem::Update(double dt)
return;
}
m_SprintEffectTimer = 0.f;
const ComponentPool* pool = m_World->GetComponents("SprintAbility");
auto pool = m_World->GetComponents("SprintAbility");
if (pool == nullptr) {
return;
}
+40 -61
View File
@@ -1,5 +1,4 @@
#include "Systems/PlayerSpawnSystem.h"
#include "Core/ELockMouse.h"
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
: System(params)
@@ -60,15 +59,7 @@ void PlayerSpawnSystem::Update(double dt)
}
int numSpawnedPlayers = 0;
int playersSpectating = 0;
const int numRequestsToHandle = (int)m_SpawnRequests.size();
for (auto it = m_SpawnRequests.begin(); it != m_SpawnRequests.end(); ++it) {
// It is valid if they didn't pick class yet
// but don't spawn anything, goto next spawnrequest.
if (it->Class == PlayerClass::None) {
++playersSpectating;
continue;
}
for (auto& req : m_SpawnRequests) {
for (auto& cPlayerSpawn : *playerSpawns) {
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
if (!spawner.HasComponent("Spawner")) {
@@ -78,49 +69,43 @@ void PlayerSpawnSystem::Update(double dt)
// If the spawner has a team affiliation, check it
if (spawner.HasComponent("Team")) {
auto cSpawnerTeam = spawner["Team"];
if ((int)cSpawnerTeam["Team"] != it->Team) {
// If they somehow has a valid class as spectator, don't spawn them.
if (it->Team == cSpawnerTeam["Team"].Enum("Spectator")) {
++playersSpectating;
if ((int)cSpawnerTeam["Team"] != req.Team) {
// Increase num spawned players if someone picks spectator, since it is valid to pick spectator
// but don't spawn anything, goto next spawnrequest.
if (req.Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) {
++numSpawnedPlayers;
break;
}
continue;
}
}
// TODO: Choose a different spawner depending on class picked?
// Spawn the player!
EntityWrapper player = SpawnerSystem::Spawn(spawner, EntityWrapper::Invalid, "Player");
// Set the player team affiliation
player["Team"]["Team"] = it->Team;
player["Team"]["Team"] = req.Team;
// Publish a PlayerSpawned event
Events::PlayerSpawned e;
e.PlayerID = it->PlayerID;
e.PlayerID = req.PlayerID;
e.Player = player;
e.Spawner = spawner;
m_EventBroker->Publish(e);
++numSpawnedPlayers;
it = m_SpawnRequests.erase(it);
break;
}
if (it == m_SpawnRequests.end()) {
break;
}
}
if (numSpawnedPlayers != numRequestsToHandle - playersSpectating) {
LOG_DEBUG("%i players were supposed to be spawned, but only %i was successfully.", numRequestsToHandle - playersSpectating, numSpawnedPlayers);
if (numSpawnedPlayers != (int)m_SpawnRequests.size()) {
LOG_DEBUG("%i players were supposed to be spawned or set as spectator, but only %i was handled.", (int)m_SpawnRequests.size(), numSpawnedPlayers);
} else {
std::string dbg = numSpawnedPlayers != 0 ? std::to_string(numSpawnedPlayers) + " players were spawned. " : "";
dbg += playersSpectating != 0 ? std::to_string(playersSpectating) + " players are spectating/picking class. " : "";
LOG_DEBUG(dbg.c_str());
LOG_DEBUG("%i players were spawned or set as spectator.", numSpawnedPlayers);
}
m_SpawnRequests.clear();
}
bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
{
if (e.Command != "PickTeam" && e.Command != "PickClass" && e.Command != "SwapToTeamPick" && e.Command != "SwapToClassPick") {
if (e.Command != "PickTeam" && e.Command != "SwapToClassPick") {
return false;
}
@@ -128,6 +113,19 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
return false;
}
// A dead client should be able to swap to the overwatch camera.
if (IsClient && !LocalPlayer.Valid()) {
// Set the camera as active, if it exists.
// Find the respawn camera or class pick camera.
std::string camName = e.Command == "SwapToClassPick" ? "PickClassCamera" : "SpectatorCamera";
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) {
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
}
}
// Team picks should be processed ONLY server-side!
// Don't make a spawn request if we're the client.
if (!IsServer && m_NetworkEnabled) {
@@ -138,38 +136,27 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
auto iter = m_SpawnRequests.begin();
for (; iter != m_SpawnRequests.end(); ++iter) {
if (iter->PlayerID == e.PlayerID) {
// If player wants to switch team or class , remove their selected class so they don't spawn.
if (e.Command == "SwapToTeamPick" || e.Command == "SwapToClassPick") {
iter->Class = PlayerClass::None;
return true;
// If player wants to switch class, remove their spawn request.
if (e.Command == "SwapToClassPick") {
m_SpawnRequests.erase(iter);
}
break;
}
}
//If we get here we got a PickTeam or PickClass, so add or alter a spawn request.
if (e.Command == "SwapToClassPick") {
return true;
}
if (iter != m_SpawnRequests.end()) {
// If player is in queue to spawn, then change their team affiliation or class in the request.
if (e.Command == "PickTeam") {
iter->Team = (ComponentInfo::EnumType)e.Value;
} else {
iter->Class = static_cast<PlayerClass>((int)e.Value);
}
// If player is in queue to spawn, then change their team affiliation in the request.
iter->Team = (ComponentInfo::EnumType)e.Value;
} else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) {
// If player is not in queue to spawn, then create a spawn request,
// but only if they are spectating and/or just connected.
SpawnRequest req;
req.PlayerID = e.PlayerID;
if (e.Command == "PickTeam") {
req.Team = (ComponentInfo::EnumType)e.Value;
req.Class = PlayerClass::None;
} else {
// Should never get here, since you should have picked a team before you ever get a chance to pick class.
LOG_WARNING("Sequence error: Should not be able to pick class before team");
req.Team = 1; // TODO: 1 Signifies spectator, should probably have real enum here later.
req.Class = static_cast<PlayerClass>((int)e.Value);
}
req.Team = (ComponentInfo::EnumType)e.Value;
m_SpawnRequests.push_back(req);
} else {
return false;
@@ -204,8 +191,6 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
Events::SetCamera e;
e.CameraEntity = cameraEntity;
m_EventBroker->Publish(e);
Events::LockMouse lock;
m_EventBroker->Publish(lock);
}
// HACK: Set the player model color to team color
@@ -225,7 +210,7 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
{
// Only spawn request if network is disabled or we are server.
//Only spawn request if network is disabled or we are server.
if (!IsServer && m_NetworkEnabled) {
return false;
}
@@ -233,6 +218,10 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
return false;
}
ComponentWrapper cTeam = e.Player["Team"];
//A spectator can't die anyway
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Spectator")) {
return false;
}
if (m_PlayerIDs.count(e.Player.ID) == 0) {
return false;
@@ -241,16 +230,6 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
SpawnRequest req;
req.PlayerID = m_PlayerIDs.at(e.Player.ID);
req.Team = cTeam["Team"];
// TODO: Something better than temp class state code, if we ever add class enums in .xml
if (e.Player.HasComponent("DashAbility")) {
req.Class = PlayerClass::Assault;
} else if (e.Player.HasComponent("SprintAbility")) {
req.Class = PlayerClass::Sniper;
} else if (e.Player.HasComponent("ShieldAbility")) {
req.Class = PlayerClass::Defender;
} else {
req.Class = PlayerClass::None;
}
m_SpawnRequests.push_back(req);
return true;
+1 -1
View File
@@ -86,7 +86,7 @@ bool SpawnerSystem::spawnedEntityIsColliding(EntityWrapper spawnedEntity, Entity
transformEntityToSpawnPoint(spawnedEntity, spawnPoint);
//Check if the spawned entity collides with anything, and if so, continue to the next spawnpoint.
EntityAABB spawnedBox = *Collision::EntityAbsoluteAABB(spawnedEntity);
const ComponentPool* otherSpawnedEntities = spawnPoint.World->GetComponents(dontCollideComponent);
auto otherSpawnedEntities = spawnPoint.World->GetComponents(dontCollideComponent);
for (const auto& obj : *otherSpawnedEntities) {
if (spawnedEntity.ID == obj.EntityID) {
continue;
@@ -1,90 +0,0 @@
#include "Systems/SpectatorCameraSystem.h"
#include "Rendering/ESetCamera.h"
#include "Core/ELockMouse.h"
SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
: System(params)
, m_CamSetToTeamPick(false)
, m_PickedTeam(-1)
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
}
void SpectatorCameraSystem::Update(double dt)
{
if (!m_CamSetToTeamPick && IsClient) {
// Find the class pick camera and set them to it, since they need to pick a team before they can leave the screen.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("PickTeamCamera");
if (spectatorCam.HasComponent("Camera")) {
m_CamSetToTeamPick = true;
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
}
}
bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
{
// Only the client should do this, and only if player is not spawned.
if (!IsClient || LocalPlayer.Valid()) {
return false;
}
bool swapToClass = e.Command == "PickTeam" || e.Command == "SwapToClassPick";
if (e.Value == 0 || !swapToClass && e.Command != "SwapToTeamPick" && e.Command != "PickClass") {
return false;
}
if (e.Command == "PickTeam") {
m_PickedTeam = e.Value;
}
// If a team has not been picked, they may not exit the pick team screen.
if (m_PickedTeam == -1) {
return false;
}
// A dead client should be able to swap to and between the overwatch cameras.
std::string camName;
// TODO: 1 Signifies spectator, should probably have real enum here later.
// Spectators should never end up at the class select, instead put them at the SpectatorCamera.
if (swapToClass && m_PickedTeam != 1) {
camName = "PickClassCamera";
} else if (e.Command == "SwapToTeamPick") {
camName = "PickTeamCamera";
} else {
camName = "SpectatorCamera";
}
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
// Set the camera as active, if it exists.
if (spectatorCam.HasComponent("Camera")) {
// Set the class pick button visible if a blue or red team is picked, else invisible.
EntityWrapper HUD;
if (camName == "SpectatorCamera") {
HUD = spectatorCam.FirstChildByName("SpectatorHUD");
} else if (camName == "PickTeamCamera") {
HUD = spectatorCam.FirstChildByName("PickTeamHUD");
}
// If we are at the class pick already, or if HUD is invalid for any other reason, do nothing.
if (HUD.Valid()) {
EntityWrapper toClassButton = spectatorCam.FirstChildByName("ToClassPick");
if (toClassButton.Valid()) {
// Set ClassButton as invisible if spectator, else visible.
bool visible = m_PickedTeam != 1; // TODO: 1 Signifies spectator.
toClassButton["Sprite"]["Visible"] = visible;
for (auto& child : toClassButton.ChildrenWithComponent("Text")) {
child["Text"]["Visible"] = visible;
}
}
}
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
return true;
}