Compare commits

...

8 Commits

46 changed files with 507 additions and 289 deletions
+12
View File
@@ -2,6 +2,7 @@
#define ComponentInfo_h__ #define ComponentInfo_h__
#include "../Common.h" #include "../Common.h"
#include "Entity.h"
#include <boost/shared_array.hpp> #include <boost/shared_array.hpp>
struct ComponentInfo struct ComponentInfo
@@ -21,6 +22,7 @@ struct ComponentInfo
{ {
std::string Name; std::string Name;
std::string Type; std::string Type;
unsigned char Index;
unsigned int Offset; unsigned int Offset;
unsigned int Stride; unsigned int Stride;
}; };
@@ -32,6 +34,16 @@ struct ComponentInfo
unsigned int Stride = 0; unsigned int Stride = 0;
boost::shared_array<char> Defaults = nullptr; boost::shared_array<char> Defaults = nullptr;
std::shared_ptr<Meta_t> Meta = 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<> template<>
+10 -8
View File
@@ -5,16 +5,15 @@
#include "MemoryPool.h" #include "MemoryPool.h"
#include "ComponentInfo.h" #include "ComponentInfo.h"
#include "ComponentWrapper.h" #include "ComponentWrapper.h"
#include "DirtySet.h"
class ComponentPool;
class ComponentPoolForwardIterator class ComponentPoolForwardIterator
: public std::iterator<std::forward_iterator_tag, ComponentWrapper> : public std::iterator<std::forward_iterator_tag, ComponentWrapper>
{ {
public: public:
ComponentPoolForwardIterator(const ComponentInfo& componentInfo, const MemoryPool<char>::iterator begin, const MemoryPool<char>::iterator end) ComponentPoolForwardIterator(ComponentPool* pool, const MemoryPool<char>::iterator begin, const MemoryPool<char>::iterator end);
: m_ComponentInfo(componentInfo)
, m_MemoryPoolIterator(begin)
, m_MemoryPoolEnd(end)
{ }
ComponentPoolForwardIterator(const ComponentPoolForwardIterator& other) = default; ComponentPoolForwardIterator(const ComponentPoolForwardIterator& other) = default;
ComponentPoolForwardIterator(ComponentPoolForwardIterator&& other) = default; ComponentPoolForwardIterator(ComponentPoolForwardIterator&& other) = default;
@@ -27,6 +26,7 @@ public:
ComponentWrapper operator*() const; ComponentWrapper operator*() const;
private: private:
ComponentPool* m_ComponentPool;
const ComponentInfo& m_ComponentInfo; const ComponentInfo& m_ComponentInfo;
MemoryPool<char>::iterator m_MemoryPoolIterator; MemoryPool<char>::iterator m_MemoryPoolIterator;
const MemoryPool<char>::iterator m_MemoryPoolEnd; const MemoryPool<char>::iterator m_MemoryPoolEnd;
@@ -34,6 +34,7 @@ private:
class ComponentPool class ComponentPool
{ {
friend class ComponentPoolForwardIterator;
public: public:
typedef ComponentPoolForwardIterator iterator; typedef ComponentPoolForwardIterator iterator;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
@@ -44,7 +45,7 @@ public:
ComponentPool(const ::ComponentInfo& ci) ComponentPool(const ::ComponentInfo& ci)
: m_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();
ComponentPool(const ComponentPool& other); ComponentPool(const ComponentPool& other);
@@ -61,8 +62,8 @@ public:
// Delete a component and free its memory // Delete a component and free its memory
void Delete(ComponentWrapper& wrapper); void Delete(ComponentWrapper& wrapper);
iterator begin() const; iterator begin();
iterator end() const; iterator end();
size_t size() const; size_t size() const;
//Dumps information about what the pool memory looks like right now //Dumps information about what the pool memory looks like right now
@@ -80,6 +81,7 @@ private:
::ComponentInfo m_ComponentInfo; ::ComponentInfo m_ComponentInfo;
MemoryPool<char> m_Pool; MemoryPool<char> m_Pool;
std::unordered_map<EntityID, char*> m_EntityToComponent; std::unordered_map<EntityID, char*> m_EntityToComponent;
DirtySet m_DirtySet;
}; };
#endif #endif
+181 -37
View File
@@ -4,46 +4,66 @@
#include <boost/shared_array.hpp> #include <boost/shared_array.hpp>
#include <boost/any.hpp> #include <boost/any.hpp>
#include "../Common.h" #include "../Common.h"
#include "../GLM.h"
#include "Entity.h" #include "Entity.h"
#include "ComponentInfo.h" #include "ComponentInfo.h"
#include "DirtySet.h"
#include "Util/Any.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 struct ComponentWrapper
{ {
ComponentWrapper(const ComponentInfo& componentInfo, char* data) ComponentWrapper(const ComponentInfo& componentInfo, char* data, ::DirtyBitField* dirtyBitField)
: Info(componentInfo) : Info(componentInfo)
, EntityID(*reinterpret_cast<::EntityID*>(data)) , EntityID(*reinterpret_cast<::EntityID*>(data))
, Data(data + sizeof(::EntityID)) , Data(data + componentInfo.GetHeaderSize())
, DirtyBitField(dirtyBitField)
{ } { }
const ComponentInfo& Info; const ComponentInfo& Info;
const ::EntityID EntityID; const ::EntityID EntityID;
char* Data; char* Data;
::DirtyBitField* DirtyBitField = nullptr;
ComponentInfo::EnumType Enum(const char* fieldName, const char* enumKey) ComponentInfo::EnumType Enum(const char* fieldName, const char* enumKey)
{ {
return Info.Meta->FieldEnumDefinitions.at(fieldName).at(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);
}
}
void SetAllDirty(const std::string& fieldName, bool dirty = true)
{
LOG_DEBUG("DIRTY: %s %s", Info.Name.c_str(), fieldName.c_str());
for (auto& kv : *DirtyBitField) {
SetDirty(kv.first, fieldName);
}
}
template <typename T> template <typename T>
T& Field(std::string name) T& Field(const std::string& name)
{ {
const ComponentInfo::Field_t& field = Info.Fields.at(name); const ComponentInfo::Field_t& field = Info.Fields.at(name);
if (sizeof(T) > field.Stride) { if (sizeof(T) > field.Stride) {
@@ -55,13 +75,15 @@ struct ComponentWrapper
} }
template <typename T> template <typename T>
void SetField(std::string name, const T value) { Field<T>(name) = value; } void SetField(const std::string& name, const T& value)
//template <typename T> {
//void SetField(std::string name, T& value) { Field<T>(name) = value; } Field<T>(name) = value;
SetAllDirty(name);
}
// Specialization for string literals // Specialization for string literals
template <std::size_t N> 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]) { SetField(name, std::string(value)); }
void Copy(ComponentWrapper& destination) void Copy(ComponentWrapper& destination)
{ {
@@ -95,40 +117,162 @@ struct ComponentWrapper
struct SubscriptProxy struct SubscriptProxy
{ {
friend struct ComponentWrapper; friend struct ComponentWrapper;
private:
SubscriptProxy(ComponentWrapper* component, std::string propertyName) public:
SubscriptProxy(ComponentWrapper* component, std::string fieldName)
: m_Component(component) : m_Component(component)
, m_PropertyName(propertyName) , m_FieldName(fieldName)
{ } { }
ComponentWrapper* m_Component; ComponentWrapper* m_Component;
std::string m_PropertyName; std::string m_FieldName;
public: public:
// Return the integer value of an enum type key for this field // 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); }
void SetAllDirty(bool dirty = true) { m_Component->SetAllDirty(m_FieldName, dirty); }
template <typename T> operator const double&() { return m_Component->Field<double>(m_FieldName); }
operator T&() { return m_Component->Field<T>(m_PropertyName); } operator const float&() { return m_Component->Field<float>(m_FieldName); }
operator const int&() { return m_Component->Field<int>(m_FieldName); }
operator const glm::vec3&() { return m_Component->Field<glm::vec3>(m_FieldName); }
operator const glm::vec4&() { return m_Component->Field<glm::vec4>(m_FieldName); }
operator const glm::quat&() { return m_Component->Field<glm::quat>(m_FieldName); }
operator const bool&() { return m_Component->Field<bool>(m_FieldName); }
operator const std::string&() { return m_Component->Field<std::string>(m_FieldName); }
// Don't allow non-const references
// If this wasn't deleted, the above overloads would still get called for some reason...
template <
typename T,
typename = typename std::enable_if<!std::is_base_of<::FIELDLOL, T>::value>::type
>
operator T&() = delete;
// Value assignment
template <typename T> 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 // Specialization for string literals
template <std::size_t N> 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); }
}; };
struct FIELDLOL { }; // lol
template <typename T>
struct FieldBase : FIELDLOL
{
FieldBase(ComponentWrapper::SubscriptProxy& Proxy)
: Proxy(Proxy)
, Data(Proxy.m_Component->Field<T>(Proxy.m_FieldName))
{ }
void SetAllDirty() { Proxy.SetAllDirty(); }
FieldBase& operator=(const FieldBase& rhs) { Data = rhs.Data; SetAllDirty(); return *this; }
FieldBase& operator=(const T& rhs) { Data = rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator+=(const T2& rhs) { Data += rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator-=(const T2& rhs) { Data -= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator*=(const T2& rhs) { Data *= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator/=(const T2& rhs) { Data /= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator%=(const T2& rhs) { Data %= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator&=(const T2& rhs) { Data &= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator|=(const T2& rhs) { Data |= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator^=(const T2& rhs) { Data ^= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator<<=(const T2& rhs) { Data <<= rhs; SetAllDirty(); return *this; }
template <typename T2> FieldBase& operator>>=(const T2& rhs) { Data >>= rhs; SetAllDirty(); return *this; }
T operator+() const { return +Data; }
T operator-() const { return -Data; }
T operator~() const { return ~Data; }
FieldBase& operator++() { Data++; SetAllDirty(); return *this; }
T operator++(int) { T tmp = Data; operator++(); return tmp; }
FieldBase& operator--() { Data--; SetAllDirty(); return *this; }
T operator--(int) { T tmp = Data; operator--(); return tmp; }
operator const T&() const { return Data; }
const T& operator*() const { return operator const T&(); }
protected:
ComponentWrapper::SubscriptProxy Proxy;
T& Data;
};
template <typename T>
struct Field : FieldBase<T>
{
using FieldBase<T>::FieldBase;
using FieldBase<T>::operator=;
};
template <>
struct Field<glm::vec3> : FieldBase<glm::vec3>
{
using FieldBase<glm::vec3>::FieldBase;
using FieldBase<glm::vec3>::operator=;
glm::vec3::value_type x() const { return Data.x; }
void x(glm::vec3::value_type val) { Data.x = val; SetAllDirty(); }
glm::vec3::value_type y() const { return Data.y; }
void y(glm::vec3::value_type val) { Data.y = val; SetAllDirty(); }
glm::vec3::value_type z() const { return Data.z; }
void z(glm::vec3::value_type val) { Data.z = val; SetAllDirty(); }
template <typename T> friend glm::vec3 operator+(const Field<glm::vec3>& lhs, const T& rhs) { return static_cast<glm::vec3>(lhs) + glm::vec3(rhs); }
template <typename T> friend glm::vec3 operator-(const Field<glm::vec3>& lhs, const T& rhs) { return static_cast<glm::vec3>(lhs) - glm::vec3(rhs); }
template <typename T> friend glm::vec3 operator*(const Field<glm::vec3>& lhs, const T& rhs) { return static_cast<glm::vec3>(lhs) * glm::vec3(rhs); }
template <typename T> friend glm::vec3 operator/(const Field<glm::vec3>& lhs, const T& rhs) { return static_cast<glm::vec3>(lhs) / glm::vec3(rhs); }
template <typename T> friend glm::vec3 operator+(const T& lhs, const Field<glm::vec3>& rhs) { return glm::vec3(lhs) + static_cast<glm::vec3>(rhs); }
template <typename T> friend glm::vec3 operator-(const T& lhs, const Field<glm::vec3>& rhs) { return glm::vec3(lhs) - static_cast<glm::vec3>(rhs); }
template <typename T> friend glm::vec3 operator*(const T& lhs, const Field<glm::vec3>& rhs) { return glm::vec3(lhs) * static_cast<glm::vec3>(rhs); }
template <typename T> friend glm::vec3 operator/(const T& lhs, const Field<glm::vec3>& rhs) { return glm::vec3(lhs) / static_cast<glm::vec3>(rhs); }
friend glm::vec3& operator+=(glm::vec3& lhs, const Field<glm::vec3>& rhs) { lhs += *rhs; return lhs; }
};
template <>
struct Field<glm::vec4> : FieldBase<glm::vec4>
{
//Field(glm::vec4& Data)
// : FieldBase(Data)
//{ }
using FieldBase<glm::vec4>::FieldBase;
using FieldBase<glm::vec4>::operator=;
glm::vec4::value_type x() const { return Data.x; }
void x(glm::vec4::value_type val) { Data.x = val; SetAllDirty(); }
glm::vec4::value_type y() const { return Data.y; }
void y(glm::vec4::value_type val) { Data.y = val; SetAllDirty(); }
glm::vec4::value_type z() const { return Data.z; }
void z(glm::vec4::value_type val) { Data.z = val; SetAllDirty(); }
glm::vec4::value_type w() const { return Data.w; }
void w(glm::vec4::value_type val) { Data.w = val; SetAllDirty(); }
template <typename T> friend glm::vec4 operator+(const Field<glm::vec4>& lhs, const T& rhs) { return static_cast<glm::vec4>(lhs) + glm::vec4(rhs); }
template <typename T> friend glm::vec4 operator-(const Field<glm::vec4>& lhs, const T& rhs) { return static_cast<glm::vec4>(lhs) - glm::vec4(rhs); }
template <typename T> friend glm::vec4 operator*(const Field<glm::vec4>& lhs, const T& rhs) { return static_cast<glm::vec4>(lhs) * glm::vec4(rhs); }
template <typename T> friend glm::vec4 operator/(const Field<glm::vec4>& lhs, const T& rhs) { return static_cast<glm::vec4>(lhs) / glm::vec4(rhs); }
template <typename T> friend glm::vec4 operator+(const T& lhs, const Field<glm::vec4>& rhs) { return glm::vec4(lhs) + static_cast<glm::vec4>(rhs); }
template <typename T> friend glm::vec4 operator-(const T& lhs, const Field<glm::vec4>& rhs) { return glm::vec4(lhs) - static_cast<glm::vec4>(rhs); }
template <typename T> friend glm::vec4 operator*(const T& lhs, const Field<glm::vec4>& rhs) { return glm::vec4(lhs) * static_cast<glm::vec4>(rhs); }
template <typename T> friend glm::vec4 operator/(const T& lhs, const Field<glm::vec4>& rhs) { return glm::vec4(lhs) / static_cast<glm::vec4>(rhs); }
friend glm::vec4& operator+=(glm::vec4& lhs, const Field<glm::vec4>& rhs) { lhs += *rhs; return lhs; }
};
// A component wrapper that "owns" its data through a shared pointer // A component wrapper that "owns" its data through a shared pointer
struct SharedComponentWrapper : ComponentWrapper struct SharedComponentWrapper : ComponentWrapper
{ {
SharedComponentWrapper(const ComponentInfo& componentInfo, boost::shared_array<char> data) SharedComponentWrapper(const ComponentInfo& componentInfo, boost::shared_array<char> data)
: ComponentWrapper(componentInfo, data.get()) : ComponentWrapper(componentInfo, data.get(), nullptr)
, m_DataReference(data) , 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) { for (auto& pair : group.PureSystems) {
const std::string& componentName = pair.first; const std::string& componentName = pair.first;
auto& systems = pair.second; auto& systems = pair.second;
const ComponentPool* pool = m_World->GetComponents(componentName); ComponentPool* pool = m_World->GetComponents(componentName);
if (pool == nullptr) { if (pool == nullptr) {
continue; continue;
} }
+1 -1
View File
@@ -35,7 +35,7 @@ public:
// Delete a component off an entity // Delete a component off an entity
void DeleteComponent(EntityID entity, const std::string& componentType); void DeleteComponent(EntityID entity, const std::string& componentType);
// Get all components of the specified type // Get all components of the specified type
const ComponentPool* GetComponents(const std::string& componentType); ComponentPool* GetComponents(const std::string& componentType);
// Get entity parent // Get entity parent
EntityID GetParent(EntityID entity); EntityID GetParent(EntityID entity);
// Change the parent of an entity // Change the parent of an entity
@@ -28,7 +28,7 @@ public:
virtual bool OnCommand(const Events::InputCommand& e) override; virtual bool OnCommand(const Events::InputCommand& e) override;
virtual void Reset(); virtual void Reset();
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID); void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, Field<double> assaultDashCoolDownTimer, EntityID playerID);
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
bool SpecialAbilityKeyDown() const { return m_SpecialAbilityKeyDown; } bool SpecialAbilityKeyDown() const { return m_SpecialAbilityKeyDown; }
@@ -286,7 +286,7 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
} }
template <typename EventContext> template <typename EventContext>
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID) { void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, Field<double> assaultDashCoolDownTimer, EntityID playerID) {
m_AssaultDashDoubleTapDeltaTime += dt; m_AssaultDashDoubleTapDeltaTime += dt;
m_DashEffectResetTimer += dt; m_DashEffectResetTimer += dt;
assaultDashCoolDownTimer -= dt; assaultDashCoolDownTimer -= dt;
@@ -18,15 +18,15 @@ struct ExplosionEffectJob : ModelJob
ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage, bool isShielded) ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialProperties matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage, bool isShielded)
: ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage, isShielded) : ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage, isShielded)
{ {
ExplosionOrigin = (glm::vec3)explosionEffectComponent["ExplosionOrigin"]; ExplosionOrigin = (Field<glm::vec3>)explosionEffectComponent["ExplosionOrigin"];
TimeSinceDeath = (double)explosionEffectComponent["TimeSinceDeath"]; TimeSinceDeath = (Field<double>)explosionEffectComponent["TimeSinceDeath"];
ExplosionDuration = (double)explosionEffectComponent["ExplosionDuration"]; ExplosionDuration = (Field<double>)explosionEffectComponent["ExplosionDuration"];
EndColor = (glm::vec4)explosionEffectComponent["EndColor"]; EndColor = (Field<glm::vec4>)explosionEffectComponent["EndColor"];
Randomness = (bool)explosionEffectComponent["Randomness"]; Randomness = (Field<bool>)explosionEffectComponent["Randomness"];
RandomnessScalar = (double)explosionEffectComponent["RandomnessScalar"]; RandomnessScalar = (Field<double>)explosionEffectComponent["RandomnessScalar"];
Velocity = (glm::vec2)explosionEffectComponent["Velocity"]; Velocity = (Field<glm::vec2>)explosionEffectComponent["Velocity"];
ColorByDistance = (bool)explosionEffectComponent["ColorByDistance"]; ColorByDistance = (Field<bool>)explosionEffectComponent["ColorByDistance"];
ExponentialAccelaration = (bool)explosionEffectComponent["ExponentialAccelaration"]; ExponentialAccelaration = (Field<bool>)explosionEffectComponent["ExponentialAccelaration"];
}; };
glm::vec3 ExplosionOrigin; glm::vec3 ExplosionOrigin;
+2 -2
View File
@@ -17,8 +17,8 @@ struct TextJob : RenderJob
: RenderJob() : RenderJob()
{ {
Matrix = matrix; Matrix = matrix;
Color = (glm::vec4)textComponent["Color"]; Color = (const glm::vec4&)textComponent["Color"];
Content = (std::string)textComponent["Content"]; Content = (const std::string&)textComponent["Content"];
Resource = font; Resource = font;
if ((int)textComponent["Alignment"] == textComponent["Alignment"].Enum("Left")) { if ((int)textComponent["Alignment"] == textComponent["Alignment"].Enum("Left")) {
+2 -2
View File
@@ -12,8 +12,8 @@ public:
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override
{ {
ComponentWrapper& transform = m_World->GetComponent(component.EntityID, "Transform"); ComponentWrapper& transform = m_World->GetComponent(component.EntityID, "Transform");
(double&)component["Time"] += dt; (Field<double>)component["Time"] += dt;
(glm::vec3&)transform["Position"] = (float)(double)component["Amplitude"] * glm::sin((glm::two_pi<float>() / (float)(double)component["Period"]) * (float)(double)component["Time"]) * (glm::vec3)component["Axis"]; (Field<glm::vec3>)transform["Position"] = (float)(double)component["Amplitude"] * glm::sin((glm::two_pi<float>() / (float)(double)component["Period"]) * (float)(double)component["Time"]) * (glm::vec3)component["Axis"];
} }
}; };
+24 -3
View File
@@ -1,6 +1,25 @@
#include "Common.h" #include "Common.h"
#include "Core/System.h" #include "Core/System.h"
//struct FSubscriptProxy
// {
// friend struct ComponentWrapper;
// FSubscriptProxy(ComponentWrapper* component, std::string fieldName)
// : m_Component(component)
// , m_FieldName(fieldName)
// { }
// ComponentWrapper* m_Component;
// std::string m_FieldName;
// public:
// template <typename T>
// operator Field<T>() { return Field<T>(m_Component->Field<T>(m_FieldName)); }
// };
class RaptorCopterSystem : public PureSystem class RaptorCopterSystem : public PureSystem
{ {
public: public:
@@ -9,9 +28,11 @@ public:
, PureSystem("RaptorCopter") , PureSystem("RaptorCopter")
{ } { }
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRaptorCopter, double dt) override
{ {
ComponentWrapper& transform = m_World->GetComponent(component.EntityID, "Transform"); ComponentWrapper& cTransform = entity["Transform"];
(glm::vec3&)transform["Orientation"] += (float)(double)component["Speed"] * (float)dt * (glm::vec3)component["Axis"]; //FSubscriptProxy subOri(&cTransform, "Orientation");
//Field<glm::vec3> orientation = subOri;
(Field<glm::vec3>)cTransform["Orientation"] += (float)(const double&)cRaptorCopter["Speed"] * (float)dt * (glm::vec3)cRaptorCopter["Axis"];
} }
}; };
@@ -269,7 +269,8 @@ private:
EntityWrapper thirdPersonAttachment; EntityWrapper thirdPersonAttachment;
for (auto& attachment : weaponAttachments) { for (auto& attachment : weaponAttachments) {
ComponentWrapper cWeaponAttachment = attachment["WeaponAttachment"]; ComponentWrapper cWeaponAttachment = attachment["WeaponAttachment"];
if ((std::string&)cWeaponAttachment["Weapon"] == m_ComponentType) { Field<std::string> weaponType = cWeaponAttachment["Weapon"];
if (*weaponType == m_ComponentType) {
ComponentWrapper::SubscriptProxy person = cWeaponAttachment["Person"]; ComponentWrapper::SubscriptProxy person = cWeaponAttachment["Person"];
if ((ComponentInfo::EnumType)person == person.Enum("FirstPerson")) { if ((ComponentInfo::EnumType)person == person.Enum("FirstPerson")) {
firstPersonAttachment = attachment; firstPersonAttachment = attachment;
+3 -3
View File
@@ -619,9 +619,9 @@ boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeM
AABB modelSpaceBox; AABB modelSpaceBox;
if (entity.HasComponent("AABB") && !takeModelBox) { if (entity.HasComponent("AABB") && !takeModelBox) {
ComponentWrapper& cAABB = entity["AABB"]; ComponentWrapper& cAABB = entity["AABB"];
modelSpaceBox = EntityAABB::FromOriginSize((glm::vec3)cAABB["Origin"], (glm::vec3)cAABB["Size"]); modelSpaceBox = EntityAABB::FromOriginSize((const glm::vec3&)cAABB["Origin"], (const glm::vec3&)cAABB["Size"]);
} else if (entity.HasComponent("Model")) { } else if (entity.HasComponent("Model")) {
std::string res = entity["Model"]["Resource"]; const std::string& res = entity["Model"]["Resource"];
if (res.empty()) { if (res.empty()) {
return boost::none; return boost::none;
} }
@@ -667,7 +667,7 @@ boost::optional<EntityAABB> AbsoluteAABBExplosionEffect(EntityWrapper& entity)
if (!modelBox) { if (!modelBox) {
return boost::none; return boost::none;
} }
bool isRandom = (bool)entity["ExplosionEffect"]["Randomness"]; Field<bool> isRandom = entity["ExplosionEffect"]["Randomness"];
float random = isRandom ? (float)(double)entity["ExplosionEffect"]["RandomnessScalar"] : 0; float random = isRandom ? (float)(double)entity["ExplosionEffect"]["RandomnessScalar"] : 0;
glm::vec3 origin = (glm::vec3)entity["ExplosionEffect"]["ExplosionOrigin"]; glm::vec3 origin = (glm::vec3)entity["ExplosionEffect"]["ExplosionOrigin"];
glm::vec3 randomVel = (glm::vec3)entity["ExplosionEffect"]["Velocity"]; glm::vec3 randomVel = (glm::vec3)entity["ExplosionEffect"]["Velocity"];
+6 -6
View File
@@ -54,12 +54,12 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
//TODO: Perhaps this should be done slightly more properly. //TODO: Perhaps this should be done slightly more properly.
glm::vec3 newOriginPos = ray.Origin() + (dist - 0.707107f*diameter) * ray.Direction(); glm::vec3 newOriginPos = ray.Origin() + (dist - 0.707107f*diameter) * ray.Direction();
glm::vec3 resolve = newOriginPos - boxA.Origin(); glm::vec3 resolve = newOriginPos - boxA.Origin();
(glm::vec3&)cTransform["Position"] += resolve; (Field<glm::vec3>)cTransform["Position"] += resolve;
boxA = *Collision::EntityAbsoluteAABB(entity); boxA = *Collision::EntityAbsoluteAABB(entity);
if (resolve.y > 0) { if (resolve.y > 0) {
everHitTheGround = true; everHitTheGround = true;
(bool)cPhysics["IsOnGround"] = true; cPhysics["IsOnGround"] = true;
((glm::vec3&)cPhysics["Velocity"]).y = 0.f; ((Field<glm::vec3>)cPhysics["Velocity"]).y(0.f);
} }
break; break;
} }
@@ -93,7 +93,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"]; float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) { if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector. //Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector; (Field<glm::vec3>)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity); boxA = *Collision::EntityAbsoluteAABB(entity);
cPhysics["Velocity"] = inOutVelocity; cPhysics["Velocity"] = inOutVelocity;
if (isOnGround) { if (isOnGround) {
@@ -103,12 +103,12 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
} }
} else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) { } else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) {
//Enter here if boxB has no Model. //Enter here if boxB has no Model.
(glm::vec3&)cTransform["Position"] += resolutionVector; (Field<glm::vec3>)cTransform["Position"] += resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity); boxA = *Collision::EntityAbsoluteAABB(entity);
if (resolutionVector.y > 0) { if (resolutionVector.y > 0) {
everHitTheGround = true; everHitTheGround = true;
(bool)cPhysics["IsOnGround"] = true; (bool)cPhysics["IsOnGround"] = true;
((glm::vec3&)cPhysics["Velocity"]).y = 0.f; ((Field<glm::vec3>)cPhysics["Velocity"]).y(0.f);
} }
} }
} }
+19 -8
View File
@@ -1,9 +1,17 @@
#include "Core/ComponentPool.h" #include "Core/ComponentPool.h"
ComponentPoolForwardIterator::ComponentPoolForwardIterator(ComponentPool* pool, const MemoryPool<char>::iterator begin, const MemoryPool<char>::iterator end)
: m_ComponentPool(pool)
, m_ComponentInfo(pool->m_ComponentInfo)
, m_MemoryPoolIterator(begin)
, m_MemoryPoolEnd(end)
{ }
ComponentWrapper ComponentPoolForwardIterator::operator*() const ComponentWrapper ComponentPoolForwardIterator::operator*() const
{ {
char* data = &(*m_MemoryPoolIterator); 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; return wrapper;
} }
@@ -44,7 +52,7 @@ ComponentPool::ComponentPool(const ComponentPool& other)
// Duplicate strings // Duplicate strings
for (auto& name : m_ComponentInfo.StringFields) { for (auto& name : m_ComponentInfo.StringFields) {
for (auto& c : *this) { for (auto& c : *this) {
std::string& val = c[name]; Field<std::string> val = c[name];
ComponentWrapper::SolidifyStrings(c); ComponentWrapper::SolidifyStrings(c);
} }
} }
@@ -71,7 +79,7 @@ ComponentWrapper ComponentPool::Allocate(EntityID entity)
memcpy(data, &entity, sizeof(EntityID)); memcpy(data, &entity, sizeof(EntityID));
m_EntityToComponent[entity] = data; m_EntityToComponent[entity] = data;
ComponentWrapper component(m_ComponentInfo, data); ComponentWrapper component(m_ComponentInfo, data, &m_DirtySet[entity]);
// Copy defaults // Copy defaults
memcpy(component.Data, m_ComponentInfo.Defaults.get(), m_ComponentInfo.Stride); memcpy(component.Data, m_ComponentInfo.Defaults.get(), m_ComponentInfo.Stride);
@@ -82,7 +90,9 @@ ComponentWrapper ComponentPool::Allocate(EntityID entity)
ComponentWrapper ComponentPool::GetByEntity(EntityID ent) 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) bool ComponentPool::KnowsEntity(EntityID ent)
@@ -95,16 +105,17 @@ void ComponentPool::Delete(ComponentWrapper& wrapper)
ComponentWrapper::Destroy(wrapper.Info, wrapper.Data); ComponentWrapper::Destroy(wrapper.Info, wrapper.Data);
m_EntityToComponent.erase(wrapper.EntityID); m_EntityToComponent.erase(wrapper.EntityID);
m_Pool.Free(wrapper.Data - sizeof(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, m_Pool.begin(), m_Pool.end());
} }
ComponentPool::iterator ComponentPool::end() const ComponentPool::iterator ComponentPool::end()
{ {
return iterator(m_ComponentInfo, m_Pool.end(), m_Pool.end()); return iterator(this, m_Pool.end(), m_Pool.end());
} }
size_t ComponentPool::size() const size_t ComponentPool::size() const
@@ -125,6 +125,7 @@ void EntityXMLFilePreprocessor::parseComponentInfo()
auto modelGroup = modelGroupParticle->getModelGroupTerm(); auto modelGroup = modelGroupParticle->getModelGroupTerm();
// <xs:element... // <xs:element...
unsigned char fieldIndex = 0;
unsigned int fieldOffset = 0; unsigned int fieldOffset = 0;
auto particles = modelGroup->getParticles(); auto particles = modelGroup->getParticles();
for (unsigned int i = 0; i < particles->size(); ++i) { for (unsigned int i = 0; i < particles->size(); ++i) {
@@ -182,12 +183,14 @@ void EntityXMLFilePreprocessor::parseComponentInfo()
auto& field = compInfo.Fields[name]; auto& field = compInfo.Fields[name];
field.Name = name; field.Name = name;
field.Type = effectiveType; field.Type = effectiveType;
field.Index = fieldIndex;
field.Offset = fieldOffset; field.Offset = fieldOffset;
field.Stride = stride; field.Stride = stride;
compInfo.FieldsInOrder.push_back(name); compInfo.FieldsInOrder.push_back(name);
if (field.Type == "string") { if (field.Type == "string") {
compInfo.StringFields.push_back(name); compInfo.StringFields.push_back(name);
} }
fieldIndex += 1;
fieldOffset += stride; fieldOffset += stride;
} }
+3 -3
View File
@@ -5,7 +5,7 @@ glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
glm::mat4 t = glm::mat4(1.f); glm::mat4 t = glm::mat4(1.f);
while (entity.Valid()) { while (entity.Valid()) {
t = glm::translate((glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((glm::vec3&)entity["Transform"]["Scale"]) * t; t = glm::translate((const glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((const glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((const glm::vec3&)entity["Transform"]["Scale"]) * t;
entity = entity.Parent(); entity = entity.Parent();
} }
@@ -24,7 +24,7 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
while (entity != EntityID_Invalid) { while (entity != EntityID_Invalid) {
ComponentWrapper transform = world->GetComponent(entity, "Transform"); ComponentWrapper transform = world->GetComponent(entity, "Transform");
EntityID parent = world->GetParent(entity); EntityID parent = world->GetParent(entity);
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]; position += Transform::AbsoluteOrientation(world, parent) * (const glm::vec3&)transform["Position"];
entity = parent; entity = parent;
} }
@@ -37,7 +37,7 @@ glm::vec3 Transform::AbsoluteOrientationEuler(EntityWrapper entity)
while (entity.Valid()) { while (entity.Valid()) {
ComponentWrapper transform = entity["Transform"]; ComponentWrapper transform = entity["Transform"];
orientation += (glm::vec3)transform["Orientation"]; orientation += (Field<glm::vec3>)transform["Orientation"];
entity = entity.Parent(); entity = entity.Parent();
} }
+2 -2
View File
@@ -13,8 +13,8 @@ void UniformScaleSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
return; return;
} }
float distance = glm::length((glm::vec3)entity["Transform"]["Position"] - (glm::vec3&)m_Camera["Transform"]["Position"]); float distance = glm::length((glm::vec3)entity["Transform"]["Position"] - (const glm::vec3&)m_Camera["Transform"]["Position"]);
entity["Transform"]["Scale"] = (glm::vec3&)cUniformScale["Scale"] * distance; entity["Transform"]["Scale"] = (const glm::vec3&)cUniformScale["Scale"] * distance;
} }
bool UniformScaleSystem::OnSetCamera(const Events::SetCamera& e) bool UniformScaleSystem::OnSetCamera(const Events::SetCamera& e)
+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); auto it = m_ComponentPools.find(componentType);
return (it != m_ComponentPools.end()) ? it->second : nullptr; return (it != m_ComponentPools.end()) ? it->second : nullptr;
+10 -10
View File
@@ -71,21 +71,21 @@ void EditorSystem::Update(double dt)
m_EditorStats->Draw(actualDelta); m_EditorStats->Draw(actualDelta);
if (m_CurrentSelection.Valid() && m_Widget.Valid()) { if (m_CurrentSelection.Valid() && m_Widget.Valid()) {
(glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection); m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection);
if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) { if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
(glm::vec3&)m_Widget["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(m_CurrentSelection); m_Widget["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(m_CurrentSelection);
} else { } else {
(glm::vec3&)m_Widget["Transform"]["Orientation"] = glm::vec3(0, 0, 0); m_Widget["Transform"]["Orientation"] = glm::vec3(0, 0, 0);
} }
} }
m_EditorWorldSystemPipeline->Update(actualDelta); m_EditorWorldSystemPipeline->Update(actualDelta);
ComponentWrapper& cameraTransform = m_EditorCamera["Transform"]; ComponentWrapper& cameraTransform = m_EditorCamera["Transform"];
glm::vec3& ori = cameraTransform["Orientation"]; Field<glm::vec3> ori = cameraTransform["Orientation"];
ori.x = m_EditorCameraInputController->Rotation().x; ori.x(m_EditorCameraInputController->Rotation().x);
ori.y = m_EditorCameraInputController->Rotation().y; ori.y(m_EditorCameraInputController->Rotation().y);
glm::vec3& pos = cameraTransform["Position"]; Field<glm::vec3> pos = cameraTransform["Position"];
pos += m_EditorCameraInputController->Movement() * glm::inverse(glm::quat(ori)) * (float)actualDelta; pos += m_EditorCameraInputController->Movement() * glm::inverse(glm::quat(ori)) * (float)actualDelta;
} }
} }
@@ -101,7 +101,7 @@ void EditorSystem::Enable()
eSetCamera.CameraEntity = m_EditorCamera; eSetCamera.CameraEntity = m_EditorCamera;
m_EventBroker->Publish(eSetCamera); m_EventBroker->Publish(eSetCamera);
if (m_ActualCamera.Valid()) { if (m_ActualCamera.Valid()) {
(glm::vec3&)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera); (Field<glm::vec3>)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera);
} }
// Pause the world we're editing // Pause the world we're editing
@@ -208,11 +208,11 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
if (parent.Valid()) { if (parent.Valid()) {
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent)); parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
} }
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation; (Field<glm::vec3>)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) { } else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]); glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
glm::vec3 localTranslation = selectionOri * e.Translation; glm::vec3 localTranslation = selectionOri * e.Translation;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation; (Field<glm::vec3>)m_CurrentSelection["Transform"]["Position"] += localTranslation;
} }
m_EditorGUI->SetDirty(m_CurrentSelection); m_EditorGUI->SetDirty(m_CurrentSelection);
} }
+2 -2
View File
@@ -596,8 +596,8 @@ void Client::sendLocalPlayerTransform()
Packet packet(MessageType::PlayerTransform, m_SendPacketID); Packet packet(MessageType::PlayerTransform, m_SendPacketID);
ComponentWrapper cTransform = m_LocalPlayer["Transform"]; ComponentWrapper cTransform = m_LocalPlayer["Transform"];
glm::vec3& position = cTransform["Position"]; const glm::vec3& position = cTransform["Position"];
glm::vec3& orientation = cTransform["Orientation"]; const glm::vec3& orientation = cTransform["Orientation"];
packet.WritePrimitive(position.x); packet.WritePrimitive(position.x);
packet.WritePrimitive(position.y); packet.WritePrimitive(position.y);
packet.WritePrimitive(position.z); packet.WritePrimitive(position.z);
+2 -2
View File
@@ -222,7 +222,7 @@ void Server::addPlayersToPacket(Packet & packet, EntityID entityID)
for (auto& componentField : componentWrapper.Info.FieldsInOrder) { for (auto& componentField : componentWrapper.Info.FieldsInOrder) {
ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField); ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField);
if (fieldInfo.Type == "string") { if (fieldInfo.Type == "string") {
std::string& value = componentWrapper[componentField]; const std::string& value = componentWrapper[componentField];
packet.WriteString(value); packet.WriteString(value);
} else { } else {
packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride); packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride);
@@ -266,7 +266,7 @@ void Server::addChildrenToPacket(Packet & packet, EntityID entityID)
for (auto& componentField : componentWrapper.Info.FieldsInOrder) { for (auto& componentField : componentWrapper.Info.FieldsInOrder) {
ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField); ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField);
if (fieldInfo.Type == "string") { if (fieldInfo.Type == "string") {
std::string& value = componentWrapper[componentField]; const std::string& value = componentWrapper[componentField];
packet.WriteString(value); packet.WriteString(value);
} else { } else {
packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride); packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride);
+13 -12
View File
@@ -71,7 +71,8 @@ void AnimationSystem::UpdateAnimations(double dt)
Model* model; Model* model;
try { try {
model = ResourceManager::Load<::Model, true>(modelEntity["Model"]["Resource"]); Field<std::string> res = modelEntity["Model"]["Resource"];
model = ResourceManager::Load<::Model, true>(res);
} catch (const std::exception&) { } catch (const std::exception&) {
return; return;
} }
@@ -87,23 +88,23 @@ void AnimationSystem::UpdateAnimations(double dt)
continue;; continue;;
} }
double animationSpeed = (double)animationC["Speed"]; double animationSpeed = (const double&)animationC["Speed"];
if((bool)animationC["Reverse"]) { if((const bool&)animationC["Reverse"]) {
animationSpeed *= -1; animationSpeed *= -1;
} }
if ((bool)animationC["Play"]) { if ((const bool&)animationC["Play"]) {
double nextTime = (double)animationC["Time"] + animationSpeed * dt; double nextTime = (Field<double>)animationC["Time"] + animationSpeed * dt;
if (!(bool)animationC["Loop"]) { if (!(Field<bool>)animationC["Loop"]) {
if (nextTime > animation->Duration) { if (nextTime > animation->Duration) {
nextTime = animation->Duration; nextTime = animation->Duration;
(bool&)animationC["Play"] = false; (Field<bool>)animationC["Play"] = false;
} else if (nextTime < 0) { } else if (nextTime < 0) {
nextTime = 0; nextTime = 0;
(bool&)animationC["Play"] = false; (Field<bool>)animationC["Play"] = false;
} }
} else { } else {
if (nextTime > animation->Duration) { if (nextTime > animation->Duration) {
@@ -117,7 +118,7 @@ void AnimationSystem::UpdateAnimations(double dt)
} }
} }
} }
(double&)animationC["Time"] = nextTime; (Field<double>)animationC["Time"] = nextTime;
} }
} }
} }
@@ -202,15 +203,15 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
if (nodeEntity.Valid()) { if (nodeEntity.Valid()) {
if (nodeEntity.HasComponent("Animation")) { if (nodeEntity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]); const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]);
(bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse; (Field<bool>)nodeEntity["Animation"]["Reverse"] = e.Reverse;
if (e.Restart) { if (e.Restart) {
if (animation != nullptr) { if (animation != nullptr) {
if (e.Restart) { if (e.Restart) {
if (e.Reverse) { if (e.Reverse) {
(double&)nodeEntity["Animation"]["Time"] = animation->Duration; (Field<double>)nodeEntity["Animation"]["Time"] = animation->Duration;
} else { } else {
(double&)nodeEntity["Animation"]["Time"] = 0.0; (Field<double>)nodeEntity["Animation"]["Time"] = 0.0;
} }
} }
} }
+12 -12
View File
@@ -16,7 +16,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
m_Root = new Node(); m_Root = new Node();
m_Root->Entity = ModelEntity; m_Root->Entity = ModelEntity;
m_Root->Name = ModelEntity.Name(); m_Root->Name = ModelEntity.Name();
m_Root->Pose = m_Skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]); m_Root->Pose = m_Skeleton->GetFrameBones(animation, (const double&)ModelEntity["Animation"]["Time"], (const bool&)ModelEntity["Animation"]["Additive"]);
m_Root->Parent = nullptr; m_Root->Parent = nullptr;
m_Root->Type = NodeType::Animation; m_Root->Type = NodeType::Animation;
@@ -26,9 +26,9 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
m_Root->Name = ModelEntity.Name(); m_Root->Name = ModelEntity.Name();
m_Root->Parent = nullptr; m_Root->Parent = nullptr;
m_Root->Type = NodeType::Blend; m_Root->Type = NodeType::Blend;
m_Root->Weight = (double)ModelEntity["Blend"]["Weight"]; m_Root->Weight = (const double&)ModelEntity["Blend"]["Weight"];
m_Root->SubTreeRoot = (bool)ModelEntity["Blend"]["SubTreeRoot"]; m_Root->SubTreeRoot = (const bool&)ModelEntity["Blend"]["SubTreeRoot"];
(double&)ModelEntity["Blend"]["Weight"] = glm::clamp((double)ModelEntity["Blend"]["Weight"], 0.0, 1.0); ModelEntity["Blend"]["Weight"] = glm::clamp((const double&)ModelEntity["Blend"]["Weight"], 0.0, 1.0);
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity); m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity);
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity); m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity);
@@ -120,7 +120,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
Node* node = new Node(); Node* node = new Node();
node->Entity = childEntity; node->Entity = childEntity;
node->Name = childEntity.Name(); node->Name = childEntity.Name();
node->Pose = m_Skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]); node->Pose = m_Skeleton->GetFrameBones(animation, (const double&)childEntity["Animation"]["Time"], (const bool&)childEntity["Animation"]["Additive"]);
node->Parent = parentNode; node->Parent = parentNode;
node->Type = NodeType::Animation; node->Type = NodeType::Animation;
return node; return node;
@@ -131,9 +131,9 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
node->Name = childEntity.Name(); node->Name = childEntity.Name();
node->Parent = parentNode; node->Parent = parentNode;
node->Type = NodeType::Blend; node->Type = NodeType::Blend;
(double&)childEntity["Blend"]["Weight"] = glm::clamp((double)childEntity["Blend"]["Weight"], 0.0, 1.0); childEntity["Blend"]["Weight"] = glm::clamp((const double&)childEntity["Blend"]["Weight"], 0.0, 1.0);
node->Weight = (double)childEntity["Blend"]["Weight"]; node->Weight = (const double&)childEntity["Blend"]["Weight"];
node->SubTreeRoot = (bool)childEntity["Blend"]["SubTreeRoot"]; node->SubTreeRoot = (const bool&)childEntity["Blend"]["SubTreeRoot"];
//if (node->Weight < 1.f && node->Weight > 0.f) { //if (node->Weight < 1.f && node->Weight > 0.f) {
node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity); node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity);
node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity); node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity);
@@ -213,7 +213,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
if (entity.Valid()) { if (entity.Valid()) {
if (entity.HasComponent("Blend")) { if (entity.HasComponent("Blend")) {
(double&)entity["Blend"]["Weight"] = blendInfo.Weight; entity["Blend"]["Weight"] = blendInfo.Weight;
} }
} }
} }
@@ -229,7 +229,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
if (entity.Valid()) { if (entity.Valid()) {
if (entity.HasComponent("Animation")) { if (entity.HasComponent("Animation")) {
(bool&)entity["Animation"]["Play"] = true; entity["Animation"]["Play"] = true;
} }
} }
} }
@@ -263,7 +263,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
} }
double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight; double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight;
(double&)currentNode->Entity["Blend"]["Weight"] = weight; currentNode->Entity["Blend"]["Weight"] = weight;
currentNode->Weight = weight; currentNode->Weight = weight;
lastNode = currentNode; lastNode = currentNode;
@@ -326,7 +326,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
} }
double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight; double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight;
(double&)currentNode->Entity["Blend"]["Weight"] = weight; currentNode->Entity["Blend"]["Weight"] = weight;
currentNode->Weight = weight; currentNode->Weight = weight;
lastNode = currentNode; lastNode = currentNode;
@@ -53,13 +53,13 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation)); glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation));
if ((bool)entity["BoneAttachment"]["InheritPosition"]) { if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"]; entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
} }
if ((bool)entity["BoneAttachment"]["InheritOrientation"]) { if ((bool)entity["BoneAttachment"]["InheritOrientation"]) {
(glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"]; entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"];
} }
if ((bool)entity["BoneAttachment"]["InheritScale"]) { if ((bool)entity["BoneAttachment"]["InheritScale"]) {
(glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"]; entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
} }
} }
+11 -11
View File
@@ -123,8 +123,8 @@ void SoundManager::updateEmitters(double dt)
setSoundProperties(it->second, &emitter); setSoundProperties(it->second, &emitter);
// Path changed // Path changed
if (it->second->SoundResource->Path() != (std::string)emitter["FilePath"]) { if (it->second->SoundResource->Path() != (const std::string&)emitter["FilePath"]) {
it->second->SoundResource = ResourceManager::Load<Sound>((std::string)emitter["FilePath"]); it->second->SoundResource = ResourceManager::Load<Sound>((const std::string&)emitter["FilePath"]);
if (it->second->SoundResource->Buffer() != 0) { if (it->second->SoundResource->Buffer() != 0) {
playSound(it->second); playSound(it->second);
} }
@@ -205,14 +205,14 @@ bool SoundManager::OnPlaySoundOnPosition(const Events::PlaySoundOnPosition & e)
Source* source = createSource(e.FilePath); Source* source = createSource(e.FilePath);
auto emitterID = m_World->CreateEntity(); auto emitterID = m_World->CreateEntity();
auto transform = m_World->AttachComponent(emitterID, "Transform"); auto transform = m_World->AttachComponent(emitterID, "Transform");
(glm::vec3&)transform["Position"] = e.Position; transform["Position"] = e.Position;
auto emitter = m_World->AttachComponent(emitterID, "SoundEmitter"); auto emitter = m_World->AttachComponent(emitterID, "SoundEmitter");
(float&)(double)emitter["Gain"] = e.Gain; emitter["Gain"] = e.Gain;
(float&)(double)emitter["Pitch"] = e.Pitch; emitter["Pitch"] = e.Pitch;
(bool&)emitter["Loop"] = e.Loop; emitter["Loop"] = e.Loop;
(float&)(double)emitter["MaxDistance"] = e.MaxDistance; emitter["MaxDistance"] = e.MaxDistance;
(float&)(double)emitter["RollOffFactor"] = e.RollOffFactor; emitter["RollOffFactor"] = e.RollOffFactor;
(float&)(double)emitter["ReferenceDistance"] = e.ReferenceDistance; emitter["ReferenceDistance"] = e.ReferenceDistance;
source->Type = SoundType::SFX; source->Type = SoundType::SFX;
m_Sources[emitterID] = source; m_Sources[emitterID] = source;
playSound(source); playSound(source);
@@ -246,8 +246,8 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
} }
auto emitterChild = m_World->CreateEntity((*it).EntityID); auto emitterChild = m_World->CreateEntity((*it).EntityID);
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter"); auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
(bool&)emitter["Loop"] = true; emitter["Loop"] = true;
(std::string&)emitter["FilePath"] = e.FilePath; emitter["FilePath"] = e.FilePath;
m_World->AttachComponent(emitterChild, "Transform"); m_World->AttachComponent(emitterChild, "Transform");
Source* source = createSource(e.FilePath); Source* source = createSource(e.FilePath);
source->Type = SoundType::BGM; source->Type = SoundType::BGM;
@@ -28,21 +28,21 @@ void AbilityCooldownHUDSystem::Update(double dt)
//If we have a shield ability, we set the right icon //If we have a shield ability, we set the right icon
abilityName = "ShieldAbility"; abilityName = "ShieldAbility";
if (entity.HasComponent("Sprite")) { if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\SheildDots-01.png"; entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\SheildDots-01.png";
} }
} }
} else { } else {
//If we do have a sprint ability, we change the icon //If we do have a sprint ability, we change the icon
abilityName = "SprintAbility"; abilityName = "SprintAbility";
if (entity.HasComponent("Sprite")) { if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Dash-01.png"; entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Dash-01.png";
} }
} }
} else { } else {
//If we have a dash ability, we set the icon to the correct one. //If we have a dash ability, we set the icon to the correct one.
abilityName = "DashAbility"; abilityName = "DashAbility";
if (entity.HasComponent("Sprite")) { if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Superman-01.png"; entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Superman-01.png";
} }
} }
@@ -57,7 +57,7 @@ void AbilityCooldownHUDSystem::Update(double dt)
if (cooldownTextEntity.Valid()) { if (cooldownTextEntity.Valid()) {
if (cooldownTextEntity.HasComponent("Text")) { if (cooldownTextEntity.HasComponent("Text")) {
std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3); cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3);
} }
} }
} }
+6 -6
View File
@@ -10,9 +10,9 @@ void BoostIconsHUDSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
if (assaultEntity.HasComponent("Fill")) { if (assaultEntity.HasComponent("Fill")) {
EntityWrapper parentWithAssaultBoost = assaultEntity.FirstParentWithComponent("BoostAssault"); EntityWrapper parentWithAssaultBoost = assaultEntity.FirstParentWithComponent("BoostAssault");
if (parentWithAssaultBoost.Valid()) { if (parentWithAssaultBoost.Valid()) {
(double&)assaultEntity["Fill"]["Percentage"] = 1.0; assaultEntity["Fill"]["Percentage"] = 1.0;
} else { } else {
(double&)assaultEntity["Fill"]["Percentage"] = 0.0; assaultEntity["Fill"]["Percentage"] = 0.0;
} }
} }
} }
@@ -21,9 +21,9 @@ void BoostIconsHUDSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
if (defenderEntity.HasComponent("Fill")) { if (defenderEntity.HasComponent("Fill")) {
EntityWrapper parentWithAssaultBoost = defenderEntity.FirstParentWithComponent("BoostDefender"); EntityWrapper parentWithAssaultBoost = defenderEntity.FirstParentWithComponent("BoostDefender");
if (parentWithAssaultBoost.Valid()) { if (parentWithAssaultBoost.Valid()) {
(double&)defenderEntity["Fill"]["Percentage"] = 1.0; defenderEntity["Fill"]["Percentage"] = 1.0;
} else { } else {
(double&)defenderEntity["Fill"]["Percentage"] = 0.0; defenderEntity["Fill"]["Percentage"] = 0.0;
} }
} }
} }
@@ -32,9 +32,9 @@ void BoostIconsHUDSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
if (sniperEntity.HasComponent("Fill")) { if (sniperEntity.HasComponent("Fill")) {
EntityWrapper parentWithAssaultBoost = sniperEntity.FirstParentWithComponent("BoostSniper"); EntityWrapper parentWithAssaultBoost = sniperEntity.FirstParentWithComponent("BoostSniper");
if (parentWithAssaultBoost.Valid()) { if (parentWithAssaultBoost.Valid()) {
(double&)sniperEntity["Fill"]["Percentage"] = 1.0; sniperEntity["Fill"]["Percentage"] = 1.0;
} else { } else {
(double&)sniperEntity["Fill"]["Percentage"] = 0.0; sniperEntity["Fill"]["Percentage"] = 0.0;
} }
} }
} }
@@ -155,13 +155,13 @@ void CapturePointArrowHUDSystem::Update(double dt)
pos = m_BlueTeamCurrentTarget; pos = m_BlueTeamCurrentTarget;
} }
glm::vec3& arrowOri = arrowEntity["Transform"]["Orientation"]; Field<glm::vec3> arrowOri = arrowEntity["Transform"]["Orientation"];
glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead
float pitch = std::asin(-lookVector.y); float pitch = std::asin(-lookVector.y);
float yaw = std::atan2(lookVector.x, lookVector.z); float yaw = std::atan2(lookVector.x, lookVector.z);
arrowOri.x = pitch; arrowOri.x(pitch);
arrowOri.y = yaw; arrowOri.y(yaw);
arrowOri.z = 0.f; arrowOri.z(0.f);
EntityWrapper parent = arrowEntity.Parent(); EntityWrapper parent = arrowEntity.Parent();
if (parent.Valid()) { if (parent.Valid()) {
arrowOri -= Transform::AbsoluteOrientationEuler(parent); arrowOri -= Transform::AbsoluteOrientationEuler(parent);
+2 -1
View File
@@ -49,7 +49,8 @@ void CapturePointHUDSystem::Update(double dt)
double currentCaptureTime = (double)entityCP["CapturePoint"]["CaptureTimer"]; double currentCaptureTime = (double)entityCP["CapturePoint"]["CaptureTimer"];
double progress = glm::abs(currentCaptureTime)/15.0; double progress = glm::abs(currentCaptureTime)/15.0;
int currentCapturingTeam = currentCaptureTime > 0 ? redTeam : currentCaptureTime < 0 ? blueTeam : spectatorTeam; int currentCapturingTeam = currentCaptureTime > 0 ? redTeam : currentCaptureTime < 0 ? blueTeam : spectatorTeam;
((glm::vec3&)entityHUD["Transform"]["Orientation"]).z = currentCapturingTeam == redTeam ? glm::half_pi<float>()+glm::pi<float>() : glm::half_pi<float>(); Field<glm::vec3> orientation = entityHUD["Transform"]["Orientation"];
orientation.z(currentCapturingTeam == redTeam ? glm::half_pi<float>()+glm::pi<float>() : glm::half_pi<float>());
glm::vec4 fillColor = currentCapturingTeam == redTeam ? glm::vec4(1, 0.f, 0, 0.7f) : glm::vec4(0, 0.2f, 1, 0.7f); glm::vec4 fillColor = currentCapturingTeam == redTeam ? glm::vec4(1, 0.f, 0, 0.7f) : glm::vec4(0, 0.2f, 1, 0.7f);
entityHUD["Fill"]["Color"] = fillColor; entityHUD["Fill"]["Color"] = fillColor;
entityHUD["Fill"]["Percentage"] = progress; entityHUD["Fill"]["Percentage"] = progress;
+3 -3
View File
@@ -109,9 +109,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
for (int i = 0; i < m_NumberOfCapturePoints; i++) { for (int i = 0; i < m_NumberOfCapturePoints; i++) {
auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"]; auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"];
if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) { if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) {
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false; m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false; m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false; m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false;
} }
} }
//save the next cap points and publish the captured event //save the next cap points and publish the captured event
+4 -3
View File
@@ -2,10 +2,11 @@
void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
{ {
if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) { Field<double> timeSinceDeath = component["TimeSinceDeath"];
(double)component["TimeSinceDeath"] = 0.f; if (timeSinceDeath > (double)component["ExplosionDuration"]) {
timeSinceDeath = 0.f;
} }
(double&)component["TimeSinceDeath"] += dt; timeSinceDeath += dt;
//if ((bool)Component["Gravity"] == true) { //if ((bool)Component["Gravity"] == true) {
// (bool)Component["ExponentialAccelaration"] = false; // (bool)Component["ExponentialAccelaration"] = false;
+11 -7
View File
@@ -22,19 +22,23 @@ void HealthHUDSystem::Update(double dt)
if (entityIDParent.HasComponent("Health")) { if (entityIDParent.HasComponent("Health")) {
if (entity.HasComponent("Text")) { if (entity.HasComponent("Text")) {
Field<double> health = entityIDParent["Health"]["Health"];
Field<double> maxHealth = entityIDParent["Health"]["Health"];
std::string s = ""; std::string s = "";
s = s + std::to_string((int)(double)entityIDParent["Health"]["Health"]); s = s + std::to_string((int)health);
s = s + "/"; s = s + "/";
s = s + std::to_string((int)(double)entityIDParent["Health"]["MaxHealth"]); s = s + std::to_string((int)maxHealth);
float healthPercentage = (double)entityIDParent["Health"]["Health"]/(double)entityIDParent["Health"]["MaxHealth"]; float healthPercentage = health/maxHealth;
//(glm::vec4&)entity["Text"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Text"]["Color"]).a); //(Field<glm::vec4>)entity["Text"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Text"]["Color"]).a);
entity["Text"]["Content"] = s; entity["Text"]["Content"] = s;
} }
if(entity.HasComponent("Fill")) { if(entity.HasComponent("Fill")) {
float healthPercentage = (double)entityIDParent["Health"]["Health"]/(double)entityIDParent["Health"]["MaxHealth"]; Field<double> health = entityIDParent["Health"]["Health"];
(glm::vec4&)entity["Fill"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Fill"]["Color"]).a); Field<double> maxHealth = entityIDParent["Health"]["Health"];
(double&)entity["Fill"]["Percentage"] = healthPercentage; float healthPercentage = health/maxHealth;
entity["Fill"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Fill"]["Color"]).a);
entity["Fill"]["Percentage"] = (double)healthPercentage;
} }
} }
+3 -3
View File
@@ -21,7 +21,7 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
} }
ComponentWrapper cHealth = e.Victim["Health"]; ComponentWrapper cHealth = e.Victim["Health"];
double& health = cHealth["Health"]; Field<double> health = cHealth["Health"];
//if player has the boost from a defender, subtract the damage taken by StrengthOfEffect amount //if player has the boost from a defender, subtract the damage taken by StrengthOfEffect amount
auto playerBoostDefenderEntity = e.Victim.FirstChildByName("BoostDefender"); auto playerBoostDefenderEntity = e.Victim.FirstChildByName("BoostDefender");
if (playerBoostDefenderEntity.Valid()) { if (playerBoostDefenderEntity.Valid()) {
@@ -56,9 +56,9 @@ bool HealthSystem::OnInputCommand(Events::InputCommand& e)
bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e) bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e)
{ {
ComponentWrapper cHealth = e.Player["Health"]; ComponentWrapper cHealth = e.Player["Health"];
double& health = cHealth["Health"]; Field<double> health = cHealth["Health"];
health += e.HealthAmount; health += e.HealthAmount;
health = std::min(health, (double)cHealth["MaxHealth"]); health = std::min((double)health, (double)cHealth["MaxHealth"]);
return true; return true;
} }
+5 -5
View File
@@ -17,7 +17,7 @@ void InterpolationSystem::Update(double dt)
continue; continue;
} }
auto& iPosition = kv.second; auto& iPosition = kv.second;
glm::vec3& position = iPosition.Component[iPosition.Field]; Field<glm::tvec3<float, glm::highp>> position = iPosition.Component[iPosition.Field];
iPosition.Alpha += dt; iPosition.Alpha += dt;
float alpha = glm::min(iPosition.Alpha / m_SnapshotInterval, 1.0); float alpha = glm::min(iPosition.Alpha / m_SnapshotInterval, 1.0);
@@ -31,7 +31,7 @@ void InterpolationSystem::Update(double dt)
continue; continue;
} }
auto& iOrientation = kv.second; auto& iOrientation = kv.second;
glm::vec3& orientation = iOrientation.Component[iOrientation.Field]; Field<glm::vec3> orientation = iOrientation.Component[iOrientation.Field];
iOrientation.Alpha += dt / m_SnapshotInterval; iOrientation.Alpha += dt / m_SnapshotInterval;
iOrientation.Alpha = glm::min(iOrientation.Alpha, 1.0); iOrientation.Alpha = glm::min(iOrientation.Alpha, 1.0);
@@ -45,7 +45,7 @@ void InterpolationSystem::Update(double dt)
continue; continue;
} }
auto& iVelocity = kv.second; auto& iVelocity = kv.second;
glm::vec3& position = iVelocity.Component[iVelocity.Field]; Field<glm::vec3> position = iVelocity.Component[iVelocity.Field];
iVelocity.Alpha += dt; iVelocity.Alpha += dt;
float alpha = glm::min(iVelocity.Alpha / m_SnapshotInterval, 1.0); float alpha = glm::min(iVelocity.Alpha / m_SnapshotInterval, 1.0);
@@ -72,8 +72,8 @@ bool InterpolationSystem::OnInterpolate(Events::Interpolate& e)
Interpolation<glm::quat> iOrientation( Interpolation<glm::quat> iOrientation(
cTransform, cTransform,
"Orientation", "Orientation",
glm::quat((glm::vec3&)cTransform["Orientation"]), glm::quat((Field<glm::vec3>)cTransform["Orientation"]),
glm::quat((glm::vec3&)e.Component["Orientation"]) glm::quat((Field<glm::vec3>)e.Component["Orientation"])
); );
m_InterpolateOrientation.erase(e.Entity); m_InterpolateOrientation.erase(e.Entity);
m_InterpolateOrientation.insert(std::make_pair(e.Entity, iOrientation)); m_InterpolateOrientation.insert(std::make_pair(e.Entity, iOrientation));
+5 -5
View File
@@ -13,7 +13,7 @@ void KillFeedSystem::Update(double dt)
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(i)); EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(i));
if (child.HasComponent("Text")) { if (child.HasComponent("Text")) {
(std::string&)child["Text"]["Content"] = ""; (Field<std::string>)child["Text"]["Content"] = "";
} }
} }
@@ -27,14 +27,14 @@ void KillFeedSystem::Update(double dt)
EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(feedIndex)); EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(feedIndex));
if (child.HasComponent("Text")) { if (child.HasComponent("Text")) {
(std::string&)child["Text"]["Content"] = (*it).Content; (Field<std::string>)child["Text"]["Content"] = (*it).Content;
(glm::vec4&)child["Text"]["Color"] = (*it).Color; (Field<glm::vec4>)child["Text"]["Color"] = (*it).Color;
(*it).TimeToLive -= dt; (*it).TimeToLive -= dt;
if ((*it).TimeToLive <= 0.f) { if ((*it).TimeToLive <= 0.f) {
(std::string&)child["Text"]["Content"] = ""; (Field<std::string>)child["Text"]["Content"] = "";
(glm::vec4&)child["Text"]["Color"] = (*it).Color; (Field<glm::vec4>)child["Text"]["Color"] = (*it).Color;
remove = true; remove = true;
} }
} }
+1 -1
View File
@@ -18,7 +18,7 @@ void LifetimeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cL
return; return;
} }
double& lifetime = cLifetime["Lifetime"]; Field<double> lifetime = cLifetime["Lifetime"];
lifetime -= dt; lifetime -= dt;
if (lifetime <= 0.0) { if (lifetime <= 0.0) {
+31 -30
View File
@@ -29,7 +29,7 @@ void PlayerMovementSystem::Update(double dt)
return; return;
} }
m_SprintEffectTimer = 0.f; m_SprintEffectTimer = 0.f;
const ComponentPool* pool = m_World->GetComponents("SprintAbility"); auto pool = m_World->GetComponents("SprintAbility");
if (pool == nullptr) { if (pool == nullptr) {
return; return;
} }
@@ -54,7 +54,7 @@ void PlayerMovementSystem::Update(double dt)
playerEntityModel.Copy(sprintEffect["Model"]); playerEntityModel.Copy(sprintEffect["Model"]);
playerEntityAnimation.Copy(sprintEffect["Animation"]); playerEntityAnimation.Copy(sprintEffect["Animation"]);
sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
((glm::vec4&)sprintEffect["ExplosionEffect"]["EndColor"]).w = 0.f; ((Field<glm::vec4>)sprintEffect["ExplosionEffect"]["EndColor"]).w(0.f);
sprintEffect["Animation"]["Speed1"] = 0.0; sprintEffect["Animation"]["Speed1"] = 0.0;
sprintEffect["Animation"]["Speed2"] = 0.0; sprintEffect["Animation"]["Speed2"] = 0.0;
sprintEffect["Animation"]["Speed3"] = 0.0; sprintEffect["Animation"]["Speed3"] = 0.0;
@@ -77,10 +77,10 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
// Aim pitch // Aim pitch
EntityWrapper cameraEntity = player.FirstChildByName("Camera"); EntityWrapper cameraEntity = player.FirstChildByName("Camera");
if (cameraEntity.Valid()) { if (cameraEntity.Valid()) {
glm::vec3& cameraOrientation = cameraEntity["Transform"]["Orientation"]; Field<glm::vec3> cameraOrientation = cameraEntity["Transform"]["Orientation"];
cameraOrientation.x += controller->Rotation().x; cameraOrientation.x(cameraOrientation.x() + controller->Rotation().x);
// Limit camera pitch so we don't break our necks // Limit camera pitch so we don't break our necks
cameraOrientation.x = glm::clamp(cameraOrientation.x, -glm::half_pi<float>(), glm::half_pi<float>()); cameraOrientation.x(glm::clamp(cameraOrientation.x(), -glm::half_pi<float>(), glm::half_pi<float>()));
// Set third person model aim pitch // Set third person model aim pitch
EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
@@ -89,29 +89,29 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("AimPrimary"); EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("AimPrimary");
if(aimPrimaryEntity.Valid()){ if(aimPrimaryEntity.Valid()){
if(aimPrimaryEntity.HasComponent("Animation")) { if(aimPrimaryEntity.HasComponent("Animation")) {
float pitch = cameraOrientation.x + 0.2f; float pitch = cameraOrientation.x() + 0.2f;
double time = (pitch + glm::half_pi<float>()) / glm::pi<float>(); double time = (pitch + glm::half_pi<float>()) / glm::pi<float>();
(double&)aimPrimaryEntity["Animation"]["Time"] = time; (Field<double>)aimPrimaryEntity["Animation"]["Time"] = time;
} }
} }
EntityWrapper aimSecondaryEntity = playerModel.FirstChildByName("AimSecondary"); EntityWrapper aimSecondaryEntity = playerModel.FirstChildByName("AimSecondary");
if (aimSecondaryEntity.Valid()) { if (aimSecondaryEntity.Valid()) {
if (aimSecondaryEntity.HasComponent("Animation")) { if (aimSecondaryEntity.HasComponent("Animation")) {
float pitch = cameraOrientation.x + 0.2f; float pitch = cameraOrientation.x() + 0.2f;
double time = (pitch + glm::half_pi<float>()) / glm::pi<float>(); double time = (pitch + glm::half_pi<float>()) / glm::pi<float>();
(double&)aimSecondaryEntity["Animation"]["Time"] = time; (Field<double>)aimSecondaryEntity["Animation"]["Time"] = time;
} }
} }
} }
} }
ComponentWrapper& cTransform = player["Transform"]; ComponentWrapper& cTransform = player["Transform"];
glm::vec3& ori = cTransform["Orientation"]; Field<glm::vec3> ori = cTransform["Orientation"];
ori.y += controller->Rotation().y; ori.y(ori.y() + controller->Rotation().y);
float playerMovementSpeed = player["Player"]["MovementSpeed"]; float playerMovementSpeed = player["Player"]["MovementSpeed"];
float playerCrouchSpeed = player["Player"]["CrouchSpeed"]; float playerCrouchSpeed = player["Player"]["CrouchSpeed"];
glm::vec3& wishDirection = player["Player"]["CurrentWishDirection"]; Field<glm::vec3> wishDirection = player["Player"]["CurrentWishDirection"];
auto playerBoostAssaultEntity = player.FirstChildByName("BoostAssault"); auto playerBoostAssaultEntity = player.FirstChildByName("BoostAssault");
if (playerBoostAssaultEntity.Valid()) { if (playerBoostAssaultEntity.Valid()) {
playerMovementSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"]; playerMovementSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"];
@@ -131,7 +131,8 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
ComponentWrapper cPhysics = player["Physics"]; ComponentWrapper cPhysics = player["Physics"];
//Assault Dash Check //Assault Dash Check
if (player.HasComponent("DashAbility")) { if (player.HasComponent("DashAbility")) {
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player.ID); Field<double> coolDownTimer = player["DashAbility"]["CoolDownTimer"];
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], coolDownTimer, player.ID);
} }
wishDirection = controller->Movement() * glm::inverse(glm::quat(ori)); wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
//this makes sure you can only dash in the 4 directions: forw,backw,left,right //this makes sure you can only dash in the 4 directions: forw,backw,left,right
@@ -145,21 +146,21 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
wishSpeed = playerMovementSpeed; wishSpeed = playerMovementSpeed;
} }
if (player.ID == m_LocalPlayer.ID) { if (player.ID == m_LocalPlayer.ID) {
if (glm::length(wishDirection) == 0) { if (glm::length((glm::vec3)wishDirection) == 0) {
// If no key is pressed, reset the distance moved since last step. // If no key is pressed, reset the distance moved since last step.
m_DistanceMoved = 0; m_DistanceMoved = 0;
} }
} }
glm::vec3& velocity = cPhysics["Velocity"]; Field<glm::vec3> velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"]; bool isOnGround = (bool)cPhysics["IsOnGround"];
//ImGui::Text(isOnGround ? "On ground" : "In air"); //ImGui::Text(isOnGround ? "On ground" : "In air");
//ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); //ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
glm::vec3 groundVelocity(0.f, 0.f, 0.f); glm::vec3 groundVelocity(0.f, 0.f, 0.f);
groundVelocity.x = velocity.x; groundVelocity.x = velocity.x();
groundVelocity.z = velocity.z; groundVelocity.z = velocity.z();
//ImGui::Text("groundVelocity: (%f, %f, %f) |%f|", groundVelocity.x, groundVelocity.y, groundVelocity.z, glm::length(groundVelocity)); //ImGui::Text("groundVelocity: (%f, %f, %f) |%f|", groundVelocity.x, groundVelocity.y, groundVelocity.z, glm::length(groundVelocity));
//ImGui::Text("wishDirection: (%f, %f, %f) |%f|", wishDirection.x, wishDirection.y, wishDirection.z, glm::length(wishDirection)); //ImGui::Text("wishDirection: (%f, %f, %f) |%f|", wishDirection.x, wishDirection.y, wishDirection.z, glm::length(wishDirection));
float currentSpeedProj = glm::dot(groundVelocity, wishDirection); float currentSpeedProj = glm::dot(groundVelocity, (glm::vec3)wishDirection);
float addSpeed = wishSpeed - currentSpeedProj; float addSpeed = wishSpeed - currentSpeedProj;
//ImGui::Text("currentSpeedProj: %f", currentSpeedProj); //ImGui::Text("currentSpeedProj: %f", currentSpeedProj);
//ImGui::Text("wishSpeed: %f", wishSpeed); //ImGui::Text("wishSpeed: %f", wishSpeed);
@@ -184,8 +185,8 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (sniperSprinting) { if (sniperSprinting) {
accelerationSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; accelerationSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"];
} }
velocity += accelerationSpeed * wishDirection; velocity += accelerationSpeed * (glm::vec3)wishDirection;
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x(), velocity.y(), velocity.z(), glm::length((glm::vec3)velocity));
} }
if (isOnGround) { if (isOnGround) {
@@ -195,7 +196,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (controller->Jumping() && !controller->Crouching()) { if (controller->Jumping() && !controller->Crouching()) {
if (isOnGround) { if (isOnGround) {
(bool)cPhysics["IsOnGround"] = false; (bool)cPhysics["IsOnGround"] = false;
velocity.y = player["Player"]["JumpSpeed"]; velocity.y(player["Player"]["JumpSpeed"]);
if (player.Valid()) { if (player.Valid()) {
@@ -227,7 +228,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
} else if (player.HasComponent("DoubleJump") && !controller->DoubleJumping()) { } else if (player.HasComponent("DoubleJump") && !controller->DoubleJumping()) {
//Enter here if player can double jump and is doing so. //Enter here if player can double jump and is doing so.
(bool)cPhysics["IsOnGround"] = false; (bool)cPhysics["IsOnGround"] = false;
velocity.y = player["DoubleJump"]["DoubleJumpSpeed"]; velocity.y(player["DoubleJump"]["DoubleJumpSpeed"]);
if (player.Valid()) { if (player.Valid()) {
EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
@@ -268,7 +269,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
} }
if (player.HasComponent("AABB")) { if (player.HasComponent("AABB")) {
glm::vec3& size = player["AABB"]["Size"]; Field<glm::vec3> size = player["AABB"]["Size"];
if (controller->Crouching()) { if (controller->Crouching()) {
size = glm::vec3(1.f, 1.f, 1.f); size = glm::vec3(1.f, 1.f, 1.f);
} else { } else {
@@ -290,11 +291,11 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
// Only apply velocity to local player // Only apply velocity to local player
ComponentWrapper& cTransform = player["Transform"]; ComponentWrapper& cTransform = player["Transform"];
ComponentWrapper& cPhysics = player["Physics"]; ComponentWrapper& cPhysics = player["Physics"];
glm::vec3& velocity = cPhysics["Velocity"]; Field<glm::vec3> velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"]; bool isOnGround = (bool)cPhysics["IsOnGround"];
// Ground friction // Ground friction
float speed = glm::length(velocity); float speed = glm::length((glm::vec3)velocity);
static float groundFriction = 7.f; static float groundFriction = 7.f;
ImGui::InputFloat("groundFriction", &groundFriction); ImGui::InputFloat("groundFriction", &groundFriction);
static float airFriction = 2.f; static float airFriction = 2.f;
@@ -304,16 +305,16 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
if (speed > 0) { if (speed > 0) {
float drop = speed * friction * (float)dt; float drop = speed * friction * (float)dt;
float multiplier = glm::max(speed - drop, 0.f) / speed; float multiplier = glm::max(speed - drop, 0.f) / speed;
velocity.x *= multiplier; velocity.x(velocity.x() * multiplier);
velocity.z *= multiplier; velocity.z(velocity.z() * multiplier);
} }
// Gravity // Gravity
if (cPhysics["Gravity"]) { if (cPhysics["Gravity"]) {
velocity.y -= 9.82f * (float)dt; velocity.y(velocity.y() - (9.82f * (float)dt));
} }
glm::vec3& position = cTransform["Position"]; Field<glm::vec3> position = cTransform["Position"];
position += velocity * (float)dt; position += velocity * (float)dt;
} }
@@ -495,7 +496,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
playerEntityModel.Copy(dashEffect["Model"]); playerEntityModel.Copy(dashEffect["Model"]);
playerEntityAnimation.Copy(dashEffect["Animation"]); playerEntityAnimation.Copy(dashEffect["Animation"]);
dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"]; dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
((glm::vec4&)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f; ((Field<glm::vec4>)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f;
*/ */
+2 -2
View File
@@ -24,10 +24,10 @@ void PlayerSpawnSystem::Update(double dt)
// Take the first CapturePointGameMode component found. // Take the first CapturePointGameMode component found.
ComponentWrapper& modeComponent = *pool->begin(); ComponentWrapper& modeComponent = *pool->begin();
// Increase timer. // Increase timer.
double& timer = (double&)modeComponent["RespawnTime"]; Field<double> timer = modeComponent["RespawnTime"];
timer += dt; timer += dt;
if (m_DbgConfigForceRespawn) { if (m_DbgConfigForceRespawn) {
(double&)modeComponent["MaxRespawnTime"] = m_ForcedRespawnTime; (Field<double>)modeComponent["MaxRespawnTime"] = m_ForcedRespawnTime;
} }
double maxRespawnTime = (double)modeComponent["MaxRespawnTime"]; double maxRespawnTime = (double)modeComponent["MaxRespawnTime"];
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
+10 -10
View File
@@ -40,13 +40,13 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
if (it->first == ID) { if (it->first == ID) {
if (it->second.Team != currentTeam) { if (it->second.Team != currentTeam) {
m_World->DeleteEntity(child.ID); m_World->DeleteEntity(child.ID);
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1; (Field<int>)entity["ScoreScreen"]["TotalIdentities"] -= 1;
break; break;
} }
for (auto it2 = m_DisconnectedIdentities.begin(); it2 != m_DisconnectedIdentities.end(); ++it2) { for (auto it2 = m_DisconnectedIdentities.begin(); it2 != m_DisconnectedIdentities.end(); ++it2) {
if (ID == *it2) { if (ID == *it2) {
m_World->DeleteEntity(child.ID); m_World->DeleteEntity(child.ID);
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1; (Field<int>)entity["ScoreScreen"]["TotalIdentities"] -= 1;
it2 = m_DisconnectedIdentities.erase(it2); it2 = m_DisconnectedIdentities.erase(it2);
it = m_PlayerIdentities.erase(it); it = m_PlayerIdentities.erase(it);
@@ -59,17 +59,17 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
break; break;
} }
//Update Deaths for child //Update Deaths for child
(int&)child["ScoreIdentity"]["Kills"] = it->second.Kills; (Field<int>)child["ScoreIdentity"]["Kills"] = it->second.Kills;
//Update Kills for child //Update Kills for child
(int&)child["ScoreIdentity"]["Deaths"] = it->second.Deaths; (Field<int>)child["ScoreIdentity"]["Deaths"] = it->second.Deaths;
//KD is not updated at the moment. //KD is not updated at the moment.
if (it->second.Deaths != 0) { if (it->second.Deaths != 0) {
(double&)child["ScoreIdentity"]["KD"] = it->second.Kills/it->second.Deaths; (Field<double>)child["ScoreIdentity"]["KD"] = it->second.Kills/it->second.Deaths;
} }
//Update position for child //Update position for child
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"]; glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
(glm::vec3&) child["Transform"]["Position"] = offset * position; (Field<glm::vec3>) child["Transform"]["Position"] = offset * position;
position += 1.f; position += 1.f;
break; break;
@@ -90,16 +90,16 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
EntityWrapper scoreIdentity = entityFile->MergeInto(m_World); EntityWrapper scoreIdentity = entityFile->MergeInto(m_World);
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"]; glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
int newPosition = (int)entity["ScoreScreen"]["TotalIdentities"]; int newPosition = (int)entity["ScoreScreen"]["TotalIdentities"];
(glm::vec3&) scoreIdentity["Transform"]["Position"] = offset * (float)newPosition; (Field<glm::vec3>) scoreIdentity["Transform"]["Position"] = offset * (float)newPosition;
auto cScoreIdentity = scoreIdentity["ScoreIdentity"]; auto cScoreIdentity = scoreIdentity["ScoreIdentity"];
auto data = it->second; auto data = it->second;
(std::string&)cScoreIdentity["Name"] = data.Name; (Field<std::string>)cScoreIdentity["Name"] = data.Name;
(int&)cScoreIdentity["ID"] = data.ID; (Field<int>)cScoreIdentity["ID"] = data.ID;
m_World->SetParent(scoreIdentity.ID, entity.ID); m_World->SetParent(scoreIdentity.ID, entity.ID);
(int&)entity["ScoreScreen"]["TotalIdentities"] += 1; (Field<int>)entity["ScoreScreen"]["TotalIdentities"] += 1;
} }
} }
+1 -1
View File
@@ -86,7 +86,7 @@ bool SpawnerSystem::spawnedEntityIsColliding(EntityWrapper spawnedEntity, Entity
transformEntityToSpawnPoint(spawnedEntity, spawnPoint); transformEntityToSpawnPoint(spawnedEntity, spawnPoint);
//Check if the spawned entity collides with anything, and if so, continue to the next spawnpoint. //Check if the spawned entity collides with anything, and if so, continue to the next spawnpoint.
EntityAABB spawnedBox = *Collision::EntityAbsoluteAABB(spawnedEntity); EntityAABB spawnedBox = *Collision::EntityAbsoluteAABB(spawnedEntity);
const ComponentPool* otherSpawnedEntities = spawnPoint.World->GetComponents(dontCollideComponent); auto otherSpawnedEntities = spawnPoint.World->GetComponents(dontCollideComponent);
for (const auto& obj : *otherSpawnedEntities) { for (const auto& obj : *otherSpawnedEntities) {
if (spawnedEntity.ID == obj.EntityID) { if (spawnedEntity.ID == obj.EntityID) {
continue; continue;
+1 -1
View File
@@ -30,7 +30,7 @@ void TextFieldReader::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
} }
const ComponentInfo::Field_t& field = component.Info.Fields.at(fieldName); const ComponentInfo::Field_t& field = component.Info.Fields.at(fieldName);
std::string& text = entity["Text"]["Content"]; Field<std::string> text = entity["Text"]["Content"];
if (field.Type == "int") { if (field.Type == "int") {
text = boost::lexical_cast<std::string>((const int&)component[fieldName]); text = boost::lexical_cast<std::string>((const int&)component[fieldName]);
@@ -2,7 +2,7 @@
void AssaultWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) void AssaultWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{ {
double& fireCooldown = cWeapon["FireCooldown"]; Field<double> fireCooldown = cWeapon["FireCooldown"];
fireCooldown = glm::max(0.0, fireCooldown - dt); fireCooldown = glm::max(0.0, fireCooldown - dt);
WeaponBehaviour::UpdateComponent(entity, cWeapon, dt); WeaponBehaviour::UpdateComponent(entity, cWeapon, dt);
@@ -11,33 +11,33 @@ void AssaultWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWra
void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt)
{ {
// Start reloading automatically if at 0 mag ammo // Start reloading automatically if at 0 mag ammo
int& magAmmo = cWeapon["MagazineAmmo"]; Field<int> magAmmo = cWeapon["MagazineAmmo"];
if (m_ConfigAutoReload && magAmmo <= 0) { if (m_ConfigAutoReload && magAmmo <= 0) {
OnReload(cWeapon, wi); OnReload(cWeapon, wi);
} }
// Only start reloading once we're done firing // Only start reloading once we're done firing
bool& reloadQueued = cWeapon["ReloadQueued"]; Field<bool> reloadQueued = cWeapon["ReloadQueued"];
double& fireCooldown = cWeapon["FireCooldown"]; Field<double> fireCooldown = cWeapon["FireCooldown"];
bool& isReloading = cWeapon["IsReloading"]; Field<bool> isReloading = cWeapon["IsReloading"];
if (reloadQueued && fireCooldown <= 0) { if (reloadQueued && fireCooldown <= 0) {
reloadQueued = fireCooldown; reloadQueued = fireCooldown;
isReloading = true; isReloading = true;
} }
// Decrement reload timer // Decrement reload timer
double& reloadTimer = cWeapon["ReloadTimer"]; Field<double> reloadTimer = cWeapon["ReloadTimer"];
if (isReloading) { if (isReloading) {
reloadTimer = glm::max(0.0, reloadTimer - dt); reloadTimer = glm::max(0.0, reloadTimer - dt);
} }
// Handle reloading // Handle reloading
if (isReloading && reloadTimer <= 0.0) { if (isReloading && reloadTimer <= 0.0) {
int& magSize = cWeapon["MagazineSize"]; Field<int> magSize = cWeapon["MagazineSize"];
int& ammo = cWeapon["Ammo"]; Field<int> ammo = cWeapon["Ammo"];
ammo = glm::max(0, ammo - (magSize - magAmmo)); ammo = glm::max(0, ammo - (magSize - magAmmo));
magAmmo = glm::min(magSize, ammo); magAmmo = glm::min(*magSize, *ammo);
isReloading = false; isReloading = false;
if (wi.FirstPersonEntity.Valid()) { if (wi.FirstPersonEntity.Valid()) {
wi.FirstPersonEntity["Model"]["Visible"] = true; wi.FirstPersonEntity["Model"]["Visible"] = true;
@@ -49,15 +49,15 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
// Restore view angle // Restore view angle
if (IsClient) { if (IsClient) {
float& currentTravel = cWeapon["CurrentTravel"]; Field<float> currentTravel = cWeapon["CurrentTravel"];
float& returnSpeed = cWeapon["ViewReturnSpeed"]; Field<float> returnSpeed = cWeapon["ViewReturnSpeed"];
if (currentTravel > 0) { if (currentTravel > 0) {
float change = returnSpeed * dt; float change = returnSpeed * dt;
currentTravel = glm::max(0.f, currentTravel - change); currentTravel = glm::max(0.f, currentTravel - change);
EntityWrapper camera = wi.Player.FirstChildByName("Camera"); EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) { if (camera.Valid()) {
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
cameraOrientation.x -= change; cameraOrientation.x(cameraOrientation.x() - change);
} }
} }
} }
@@ -72,7 +72,7 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
if (rootNode.Valid()) { if (rootNode.Valid()) {
EntityWrapper blend = rootNode.FirstChildByName("MovementBlend"); EntityWrapper blend = rootNode.FirstChildByName("MovementBlend");
if (blend.Valid()) { if (blend.Valid()) {
(double&)blend["Blend"]["Weight"] = animationWeight; (Field<double>)blend["Blend"]["Weight"] = animationWeight;
} }
} }
@@ -97,24 +97,24 @@ void AssaultWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, Weapon
void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
{ {
bool& reloadQueued = cWeapon["ReloadQueued"]; Field<bool> reloadQueued = cWeapon["ReloadQueued"];
bool& isReloading = cWeapon["IsReloading"]; Field<bool> isReloading = cWeapon["IsReloading"];
if (reloadQueued || isReloading) { if (reloadQueued || isReloading) {
return; return;
} }
int& magAmmo = cWeapon["MagazineAmmo"]; Field<int> magAmmo = cWeapon["MagazineAmmo"];
int& magSize = cWeapon["MagazineSize"]; Field<int> magSize = cWeapon["MagazineSize"];
if (magAmmo >= magSize) { if (magAmmo >= magSize) {
return; return;
} }
int& ammo = cWeapon["Ammo"]; Field<int> ammo = cWeapon["Ammo"];
if (ammo <= 0) { if (ammo <= 0) {
return; return;
} }
double reloadTime = cWeapon["ReloadTime"]; Field<double> reloadTime = cWeapon["ReloadTime"];
double& reloadTimer = cWeapon["ReloadTimer"]; Field<double> reloadTimer = cWeapon["ReloadTimer"];
// Start reload // Start reload
reloadQueued = true; reloadQueued = true;
@@ -163,7 +163,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"]; cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"];
// Ammo // Ammo
int& magAmmo = cWeapon["MagazineAmmo"]; Field<int> magAmmo = cWeapon["MagazineAmmo"];
if (magAmmo <= 0) { if (magAmmo <= 0) {
return; return;
} else { } else {
@@ -174,16 +174,16 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
if (IsClient) { if (IsClient) {
EntityWrapper camera = wi.Player.FirstChildByName("Camera"); EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) { if (camera.Valid()) {
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
float viewPunch = cWeapon["ViewPunch"]; float viewPunch = cWeapon["ViewPunch"];
float maxTravelAngle = cWeapon["MaxTravelAngle"]; float maxTravelAngle = cWeapon["MaxTravelAngle"];
float& currentTravel = cWeapon["CurrentTravel"]; Field<float> currentTravel = cWeapon["CurrentTravel"];
if (currentTravel < maxTravelAngle) { if (currentTravel < maxTravelAngle) {
float change = viewPunch; float change = viewPunch;
if (currentTravel + change > maxTravelAngle) { if (currentTravel + change > maxTravelAngle) {
change = maxTravelAngle - currentTravel; change = maxTravelAngle - currentTravel;
} }
cameraOrientation.x += change; cameraOrientation.x(cameraOrientation.x() + change);
currentTravel += change; currentTravel += change;
} }
} }
@@ -203,7 +203,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
float distance = traceRayDistance(origin, direction); float distance = traceRayDistance(origin, direction);
EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner); EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner);
if (ray.Valid()) { if (ray.Valid()) {
((glm::vec3&)ray["Transform"]["Scale"]).z = distance; ((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance);
} }
} }
@@ -2,7 +2,7 @@
void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{ {
double& fireCooldown = cWeapon["FireCooldown"]; Field<double> fireCooldown = cWeapon["FireCooldown"];
fireCooldown = glm::max(0.0, fireCooldown - dt); fireCooldown = glm::max(0.0, fireCooldown - dt);
WeaponBehaviour::UpdateComponent(entity, cWeapon, dt); WeaponBehaviour::UpdateComponent(entity, cWeapon, dt);
@@ -11,21 +11,21 @@ void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWr
void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt)
{ {
// Decrement reload timer // Decrement reload timer
double& reloadTimer = cWeapon["ReloadTimer"]; Field<double> reloadTimer = cWeapon["ReloadTimer"];
reloadTimer = glm::max(0.0, reloadTimer - dt); reloadTimer = glm::max(0.0, reloadTimer - dt);
// Start reloading automatically if at 0 mag ammo // Start reloading automatically if at 0 mag ammo
int& magAmmo = cWeapon["MagazineAmmo"]; Field<int> magAmmo = cWeapon["MagazineAmmo"];
if (m_ConfigAutoReload && magAmmo <= 0) { if (m_ConfigAutoReload && magAmmo <= 0) {
OnReload(cWeapon, wi); OnReload(cWeapon, wi);
} }
// Handle reloading // Handle reloading
bool& isReloading = cWeapon["IsReloading"]; Field<bool> isReloading = cWeapon["IsReloading"];
if (isReloading && reloadTimer <= 0.0) { if (isReloading && reloadTimer <= 0.0) {
double reloadTime = cWeapon["ReloadTime"]; double reloadTime = cWeapon["ReloadTime"];
int& magSize = cWeapon["MagazineSize"]; Field<int> magSize = cWeapon["MagazineSize"];
int& ammo = cWeapon["Ammo"]; Field<int> ammo = cWeapon["Ammo"];
if (magAmmo < magSize && ammo > 0) { if (magAmmo < magSize && ammo > 0) {
ammo -= 1; ammo -= 1;
magAmmo += 1; magAmmo += 1;
@@ -42,15 +42,15 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
// Restore view angle // Restore view angle
if (IsClient) { if (IsClient) {
float& currentTravel = cWeapon["CurrentTravel"]; Field<float> currentTravel = cWeapon["CurrentTravel"];
float& returnSpeed = cWeapon["ViewReturnSpeed"]; Field<float> returnSpeed = cWeapon["ViewReturnSpeed"];
if (currentTravel > 0) { if (currentTravel > 0) {
float change = returnSpeed * dt; float change = returnSpeed * dt;
currentTravel = glm::max(0.f, currentTravel - change); currentTravel = glm::max(0.f, currentTravel - change);
EntityWrapper camera = wi.Player.FirstChildByName("Camera"); EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) { if (camera.Valid()) {
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
cameraOrientation.x -= change; cameraOrientation.x(cameraOrientation.x() - change);
} }
} }
} }
@@ -76,23 +76,23 @@ void DefenderWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, Weapo
void DefenderWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) void DefenderWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
{ {
bool& isReloading = cWeapon["IsReloading"]; Field<bool> isReloading = cWeapon["IsReloading"];
if (isReloading) { if (isReloading) {
return; return;
} }
int& magAmmo = cWeapon["MagazineAmmo"]; Field<int> magAmmo = cWeapon["MagazineAmmo"];
int& magSize = cWeapon["MagazineSize"]; Field<int> magSize = cWeapon["MagazineSize"];
if (magAmmo >= magSize) { if (magAmmo >= magSize) {
return; return;
} }
int& ammo = cWeapon["Ammo"]; Field<int> ammo = cWeapon["Ammo"];
if (ammo <= 0) { if (ammo <= 0) {
return; return;
} }
double reloadTime = cWeapon["ReloadTime"]; double reloadTime = cWeapon["ReloadTime"];
double& reloadTimer = cWeapon["ReloadTimer"]; Field<double> reloadTimer = cWeapon["ReloadTimer"];
// Start reload // Start reload
isReloading = true; isReloading = true;
@@ -165,11 +165,11 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"]; cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"];
// Stop reloading // Stop reloading
bool& isReloading = cWeapon["IsReloading"]; Field<bool> isReloading = cWeapon["IsReloading"];
isReloading = false; isReloading = false;
// Ammo // Ammo
int& magAmmo = cWeapon["MagazineAmmo"]; Field<int> magAmmo = cWeapon["MagazineAmmo"];
if (magAmmo <= 0) { if (magAmmo <= 0) {
return; return;
} else { } else {
@@ -194,16 +194,16 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
if (IsClient) { if (IsClient) {
EntityWrapper camera = wi.Player.FirstChildByName("Camera"); EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) { if (camera.Valid()) {
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
float viewPunch = cWeapon["ViewPunch"]; float viewPunch = cWeapon["ViewPunch"];
float maxTravelAngle = cWeapon["MaxTravelAngle"]; float maxTravelAngle = cWeapon["MaxTravelAngle"];
float& currentTravel = cWeapon["CurrentTravel"]; Field<float> currentTravel = cWeapon["CurrentTravel"];
if (currentTravel < maxTravelAngle) { if (currentTravel < maxTravelAngle) {
float change = viewPunch; float change = viewPunch;
if (currentTravel + change > maxTravelAngle) { if (currentTravel + change > maxTravelAngle) {
change = maxTravelAngle - currentTravel; change = maxTravelAngle - currentTravel;
} }
cameraOrientation.x += change; cameraOrientation.x(cameraOrientation.x() + change);
currentTravel += change; currentTravel += change;
} }
} }
@@ -222,10 +222,10 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1); glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1);
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction); float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);
EntityWrapper ray = SpawnerSystem::Spawn(spawner); EntityWrapper ray = SpawnerSystem::Spawn(spawner);
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f); ((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance / 100.f);
glm::vec3& orientation = ray["Transform"]["Orientation"]; Field<glm::vec3> orientation = ray["Transform"]["Orientation"];
orientation.x += angles.x; orientation.x(orientation.x() + angles.x);
orientation.y += angles.y; orientation.y(orientation.y() + angles.y);
glm::vec3 trajectory = direction * distance; glm::vec3 trajectory = direction * distance;
dealDamage(cWeapon, wi, direction, pelletDamage); dealDamage(cWeapon, wi, direction, pelletDamage);
} }
@@ -2,7 +2,7 @@
void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{ {
double& cooldown = cWeapon["FireCooldown"]; Field<double> cooldown = cWeapon["FireCooldown"];
if (cooldown > 0) { if (cooldown > 0) {
cooldown -= dt; cooldown -= dt;
if (cooldown < 0) { if (cooldown < 0) {
@@ -64,14 +64,14 @@ void SidearmWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
glm::vec3 direction = Transform::AbsoluteOrientation(tracerSpawner) * glm::vec3(0, 0, -1); glm::vec3 direction = Transform::AbsoluteOrientation(tracerSpawner) * glm::vec3(0, 0, -1);
float distance = traceRayDistance(origin, direction); float distance = traceRayDistance(origin, direction);
EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner); EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner);
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f); ((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance / 100.f);
} }
} }
bool SidearmWeaponBehaviour::canFire(ComponentWrapper cWeapon) bool SidearmWeaponBehaviour::canFire(ComponentWrapper cWeapon)
{ {
bool triggerHeld = cWeapon["TriggerHeld"]; bool triggerHeld = cWeapon["TriggerHeld"];
double& cooldown = cWeapon["FireCooldown"]; Field<double> cooldown = cWeapon["FireCooldown"];
// TODO: Ammo checks // TODO: Ammo checks
return triggerHeld && cooldown <= 0.0; return triggerHeld && cooldown <= 0.0;
} }
+9 -9
View File
@@ -30,14 +30,14 @@ BOOST_AUTO_TEST_CASE(WorldTestSingleAllocation, * boost::unit_test::tolerance(0.
BOOST_TEST(vec3.z == 3.f); BOOST_TEST(vec3.z == 3.f);
// Change values // Change values
((int&)c["TestInteger"]) += 1; ((Field<int>)c["TestInteger"]) += 1;
BOOST_TEST((int)c["TestInteger"] == 1338); BOOST_TEST((int)c["TestInteger"] == 1338);
((double&)c["TestDouble"]) += 1.11; ((Field<double>)c["TestDouble"]) += 1.11;
std::cout << (double)c["TestDouble"] << std::endl; std::cout << (double)c["TestDouble"] << std::endl;
BOOST_TEST((double)c["TestDouble"] == 14.48); BOOST_TEST((double)c["TestDouble"] == 14.48);
c["TestString"] = "Siesta"; c["TestString"] = "Siesta";
BOOST_TEST((std::string)c["TestString"] == "Siesta"); BOOST_TEST((std::string)c["TestString"] == "Siesta");
((glm::vec3&)c["TestVec3"]).y += 1.f; ((Field<glm::vec3>)c["TestVec3"]).y += 1.f;
BOOST_TEST(((glm::vec3)c["TestVec3"]).y == 3.f); BOOST_TEST(((glm::vec3)c["TestVec3"]).y == 3.f);
} }
@@ -100,16 +100,16 @@ BOOST_AUTO_TEST_CASE(WorldCopy, *utf::tolerance(0.00001))
// Check that built-in types are copied but don't reside in the same memory // Check that built-in types are copied but don't reside in the same memory
BOOST_CHECK((int)w1_c1["TestInteger"] == (int)w2_c1["TestInteger"]); BOOST_CHECK((int)w1_c1["TestInteger"] == (int)w2_c1["TestInteger"]);
BOOST_CHECK(&(int&)w1_c1["TestInteger"] != &(int&)w2_c1["TestInteger"]); BOOST_CHECK(&(Field<int>)w1_c1["TestInteger"] != &(Field<int>)w2_c1["TestInteger"]);
BOOST_CHECK((double)w1_c1["TestDouble"] == (double)w2_c1["TestDouble"]); BOOST_CHECK((double)w1_c1["TestDouble"] == (double)w2_c1["TestDouble"]);
BOOST_CHECK(&(int&)w1_c1["TestDouble"] != &(int&)w2_c1["TestDouble"]); BOOST_CHECK(&(Field<int>)w1_c1["TestDouble"] != &(Field<int>)w2_c1["TestDouble"]);
BOOST_CHECK((int)w1_c2["TestInteger"] == (int)w2_c2["TestInteger"]); BOOST_CHECK((int)w1_c2["TestInteger"] == (int)w2_c2["TestInteger"]);
BOOST_CHECK(&(int&)w1_c2["TestInteger"] != &(int&)w2_c2["TestInteger"]); BOOST_CHECK(&(Field<int>)w1_c2["TestInteger"] != &(Field<int>)w2_c2["TestInteger"]);
BOOST_CHECK((double)w1_c2["TestDouble"] == (double)w2_c2["TestDouble"]); BOOST_CHECK((double)w1_c2["TestDouble"] == (double)w2_c2["TestDouble"]);
BOOST_CHECK(&(int&)w1_c2["TestDouble"] != &(int&)w2_c2["TestDouble"]); BOOST_CHECK(&(Field<int>)w1_c2["TestDouble"] != &(Field<int>)w2_c2["TestDouble"]);
// Check that specially handled strings are fine // Check that specially handled strings are fine
BOOST_CHECK((std::string)w1_c1["TestString"] == (std::string)w2_c1["TestString"]); BOOST_CHECK((std::string)w1_c1["TestString"] == (std::string)w2_c1["TestString"]);
BOOST_CHECK(&(std::string&)w1_c1["TestString"] != &(std::string&)w2_c1["TestString"]); BOOST_CHECK(&(Field<std::string>)w1_c1["TestString"] != &(Field<std::string>)w2_c1["TestString"]);
BOOST_CHECK((std::string)w1_c2["TestString"] == (std::string)w2_c2["TestString"]); BOOST_CHECK((std::string)w1_c2["TestString"] == (std::string)w2_c2["TestString"]);
BOOST_CHECK(&(std::string&)w1_c2["TestString"] != &(std::string&)w2_c2["TestString"]); BOOST_CHECK(&(Field<std::string>)w1_c2["TestString"] != &(Field<std::string>)w2_c2["TestString"]);
} }