Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 36477abc63 | |||
| 5d53fc74cb | |||
| ecc8d998cf | |||
| e3c0fb2178 | |||
| 090bd806ce | |||
| 3436ba6656 | |||
| fc3a3a8f2e | |||
| 3edc2f4819 | |||
| 9c3fa25834 | |||
| 3eaad275ba | |||
| 64df3fd7ad |
@@ -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<>
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+3962
-3974
File diff suppressed because it is too large
Load Diff
@@ -4,14 +4,39 @@
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:CapturePoint/>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitSphere.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Team/>
|
||||
<c:Transform/>
|
||||
<c:Trigger/>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
|
||||
<Children/>
|
||||
<Children>
|
||||
<Entity name="Red">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="Blue">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="Spectator">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
</Entity>
|
||||
|
||||
@@ -92,15 +92,15 @@
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:PlayerSpawn/>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/Player.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Red/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:PlayerSpawn/>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/Player.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
@@ -143,15 +143,15 @@
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:PlayerSpawn/>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/Player.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Blue/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:PlayerSpawn/>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/Player.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
@@ -209,24 +209,26 @@
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:CapturePoint>
|
||||
<CaptureTimer>-15</CaptureTimer>
|
||||
<HomePointForTeam>
|
||||
<Blue/>
|
||||
</HomePointForTeam>
|
||||
</c:CapturePoint>
|
||||
<c:Model>
|
||||
<Resource>Models\Core\UnitCube.mesh</Resource>
|
||||
<Color A="1" B="1" G="0.200000003" R="0"/>
|
||||
</c:Model>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Blue/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:Trigger/>
|
||||
<c:Model>
|
||||
<Resource>Models\Core\UnitCube.mesh</Resource>
|
||||
<Color A="0.300000012" B="1" G="0" R="0"/>
|
||||
<Transparent>true</Transparent>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.773066521" Z="-18.975975"/>
|
||||
<Scale X="4.9000001" Y="0.600000024" Z="3.50000024"/>
|
||||
</c:Transform>
|
||||
<c:Trigger/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
@@ -234,25 +236,27 @@
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:CapturePoint>
|
||||
<CaptureTimer>15</CaptureTimer>
|
||||
<HomePointForTeam>
|
||||
<Red/>
|
||||
</HomePointForTeam>
|
||||
<CapturePointNumber>1</CapturePointNumber>
|
||||
</c:CapturePoint>
|
||||
<c:Model>
|
||||
<Resource>Models\Core\UnitCube.mesh</Resource>
|
||||
<Color A="1" B="1" G="1" R="0"/>
|
||||
</c:Model>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Red/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:Trigger/>
|
||||
<c:Model>
|
||||
<Resource>Models\Core\UnitCube.mesh</Resource>
|
||||
<Color A="0.300000012" B="0" G="0" R="1"/>
|
||||
<Transparent>true</Transparent>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.452868998" Z="18.5607414"/>
|
||||
<Scale X="4.60000038" Y="0.900000036" Z="4.10000038"/>
|
||||
</c:Transform>
|
||||
<c:Trigger/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
||||
|
||||
<Components>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:Collidable/>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
<Color A="1" B="0.980392158" G="1" R="1"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="-0.100000001" Y="0" Z="0"/>
|
||||
<Scale X="50" Y="1" Z="51.1000023"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:Collidable/>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
<Color A="1" B="0" G="0" R="1"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="-14.500001" Y="1.50000012" Z="16.9222012"/>
|
||||
<Scale X="14.4000006" Y="5.30000019" Z="4.5"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:DirectionalLight/>
|
||||
<c:Transform>
|
||||
<Orientation X="4.38500023" Y="0" Z="0.458000034"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:Collidable/>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
<Color A="1" B="1" G="0" R="0"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="-14.500001" Y="1.50000012" Z="-17.6888409"/>
|
||||
<Scale X="14.4000006" Y="5.30000019" Z="4.5"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:Collidable/>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
<Color A="1" B="0" G="0" R="1"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="12.1000004" Y="1.50000012" Z="16.9222012"/>
|
||||
<Scale X="14.4000006" Y="5.30000019" Z="4.5"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:Collidable/>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
<Color A="1" B="1" G="0" R="0"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="12.1228638" Y="1.50000012" Z="-17.9642811"/>
|
||||
<Scale X="14.4000006" Y="5.30000019" Z="4.5"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Red/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:PlayerSpawn/>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/Player.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:SpawnPoint/>
|
||||
<c:Transform>
|
||||
<Position X="-20.6000004" Y="1" Z="21.7150002"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:PlayerSpawn/>
|
||||
<c:Transform>
|
||||
<Position X="-12.2000008" Y="1" Z="21.5000019"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="15.4000006" Y="1" Z="21.6000004"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:SpawnPoint/>
|
||||
<c:Transform>
|
||||
<Position X="10.500001" Y="0" Z="21.9000015"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Blue/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:PlayerSpawn/>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/Player.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:SpawnPoint/>
|
||||
<c:Transform>
|
||||
<Position X="-9.70000076" Y="1" Z="-23.4000015"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:SpawnPoint/>
|
||||
<c:Transform>
|
||||
<Position X="-18.8000011" Y="1" Z="-22.3000011"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:SpawnPoint/>
|
||||
<c:Transform>
|
||||
<Position X="8.10000038" Y="1" Z="-23.2000008"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:SpawnPoint/>
|
||||
<c:Transform>
|
||||
<Position X="16.2000008" Y="1" Z="-23.2000008"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
<Color A="1" B="39.2156868" G="0" R="3.13725495"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Scale X="-70" Y="-70" Z="-70"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity name="-">
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:CapturePoint>
|
||||
<CaptureTimer>15</CaptureTimer>
|
||||
<HomePointForTeam>
|
||||
<Red/>
|
||||
</HomePointForTeam>
|
||||
</c:CapturePoint>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Red/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:Trigger/>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="-4.10000038"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity name="Red">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Scale X="2.70000005" Y="3.4000001" Z="4.60000038"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="Blue">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Scale X="3.4000001" Y="4.70000029" Z="0.700000048"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="Spectator">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Scale X="1" Y="5.70000029" Z="1"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity name="-">
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:CapturePoint>
|
||||
<CaptureTimer>-15</CaptureTimer>
|
||||
<HomePointForTeam>
|
||||
<Blue/>
|
||||
</HomePointForTeam>
|
||||
<CapturePointNumber>1</CapturePointNumber>
|
||||
</c:CapturePoint>
|
||||
<c:Team>
|
||||
<Team>
|
||||
<Blue/>
|
||||
</Team>
|
||||
</c:Team>
|
||||
<c:Trigger/>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="4"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity name="Red">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Scale X="4.4000001" Y="2" Z="3.70000029"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="Blue">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Orientation X="0" Y="2.95000005" Z="0"/>
|
||||
<Scale X="4.70000029" Y="3.60000014" Z="3.60000014"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="Spectator">
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>models/core/unitcube.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Scale X="5.50000048" Y="2.5" Z="3.80000019"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
</Entity>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -162,7 +162,7 @@ void Server::unreliableBroadcast(Packet& packet)
|
||||
{
|
||||
for (auto& kv : m_ConnectedPlayers) {
|
||||
packet.ChangePacketID(kv.second.PacketID);
|
||||
// m_Unreliable.Send(packet, kv.second);
|
||||
// m_Unreliable.Send(packet, kv.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,13 +649,14 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return childEntity.HasComponent("Player")
|
||||
return childEntity.HasComponent("Player")
|
||||
|| childEntity.FirstParentWithComponent("Player").Valid()
|
||||
|| childEntity.HasComponent("CapturePoint")
|
||||
|| childEntity.HasComponent("CapturePoint")
|
||||
|| childEntity.HasComponent("HealthPickup")
|
||||
|| childEntity.HasComponent("AmmoPickup")
|
||||
|| childEntity.HasComponent("ScoreScreen")
|
||||
|| childEntity.FirstParentWithComponent("ScoreScreen").Valid();
|
||||
|| childEntity.FirstParentWithComponent("ScoreScreen").Valid()
|
||||
|| childEntity.FirstParentWithComponent("CapturePoint").Valid();
|
||||
}
|
||||
|
||||
PlayerID Server::getPlayerIDFromEndpoint()
|
||||
@@ -674,7 +675,7 @@ PlayerID Server::getPlayerIDFromEndpoint()
|
||||
|
||||
PlayerID Server::getPlayerIDFromEntityID(EntityID entityID)
|
||||
{
|
||||
for(auto& kv : m_ConnectedPlayers) {
|
||||
for (auto& kv : m_ConnectedPlayers) {
|
||||
if (entityID == kv.second.EntityID) {
|
||||
return kv.first;
|
||||
}
|
||||
|
||||
@@ -137,20 +137,13 @@ Game::Game(int argc, char* argv[])
|
||||
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<AbilityCooldownHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointArrowHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<BoostSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
|
||||
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
|
||||
|
||||
@@ -96,6 +96,7 @@ bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e)
|
||||
}
|
||||
|
||||
currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -114,8 +115,11 @@ bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
||||
}
|
||||
|
||||
void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
||||
//trigger should be valid but if it isnt we just return (to avoid crash)
|
||||
if (!trigger.Valid()) {
|
||||
return;
|
||||
}
|
||||
int maxWeaponAmmo = (int)player["AssaultWeapon"]["MaxAmmo"];
|
||||
int& currentAmmo = (int)player["AssaultWeapon"]["Ammo"];
|
||||
int ammoGiven = 0.01*(double)trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo;
|
||||
|
||||
Events::AmmoPickup ePlayerAmmoPickup;
|
||||
@@ -123,9 +127,6 @@ void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
||||
ePlayerAmmoPickup.Player = player;
|
||||
m_EventBroker->Publish(ePlayerAmmoPickup);
|
||||
|
||||
//immediately give the player the ammo (on server)
|
||||
currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo);
|
||||
|
||||
//copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
|
||||
//we need to copy all values since each value can be different for each ammoPickup
|
||||
m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"], trigger["AmmoPickup"]["AmmoGain"],
|
||||
|
||||
@@ -69,6 +69,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
||||
int ownedBy = teamComponent["Team"];
|
||||
int redTeamPlayersStandingInside = 0;
|
||||
int blueTeamPlayersStandingInside = 0;
|
||||
//note: old color system
|
||||
if (capturePointEntity.HasComponent("Model")) {
|
||||
//Now sets team color to the capturepoint, or white if it is uncaptured.
|
||||
capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.0f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.0f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3);
|
||||
@@ -102,7 +103,18 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
||||
nextPossibleCapturePoint["Blue"] = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_RecentlyCapturedNeedNextCapturePointNow) {
|
||||
//change what model is displaying (change all in case 2 capturepoints has been captured on the same frame)
|
||||
for (int i = 0; i < m_NumberOfCapturePoints; i++) {
|
||||
auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"];
|
||||
if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) {
|
||||
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false;
|
||||
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false;
|
||||
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false;
|
||||
}
|
||||
}
|
||||
//save the next cap points and publish the captured event
|
||||
m_CapturedEvent.BlueTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]];
|
||||
m_CapturedEvent.RedTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]];
|
||||
m_EventBroker->Publish(m_CapturedEvent);
|
||||
|
||||
@@ -83,6 +83,10 @@ bool PickupSpawnSystem::OnTriggerLeave(Events::TriggerLeave& e)
|
||||
}
|
||||
void PickupSpawnSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger)
|
||||
{
|
||||
//trigger should be valid but if it isnt we just return (to avoid crash)
|
||||
if (!trigger.Valid()) {
|
||||
return;
|
||||
}
|
||||
double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"];
|
||||
|
||||
//only the server will increase the players hp and set it in the next delta
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user