Compare commits

..

1 Commits

Author SHA1 Message Date
Jace 36477abc63 WTF? 2016-03-08 18:26:03 +01:00
39 changed files with 251 additions and 412 deletions
+2 -1
View File
@@ -13,7 +13,7 @@ class ComponentPoolForwardIterator
: public std::iterator<std::forward_iterator_tag, ComponentWrapper>
{
public:
ComponentPoolForwardIterator(ComponentPool* pool, const MemoryPool<char>::iterator begin, const MemoryPool<char>::iterator end);
ComponentPoolForwardIterator(ComponentPool* pool);
ComponentPoolForwardIterator(const ComponentPoolForwardIterator& other) = default;
ComponentPoolForwardIterator(ComponentPoolForwardIterator&& other) = default;
@@ -42,6 +42,7 @@ public:
typedef ComponentWrapper value_type;
typedef ComponentWrapper* pointer;
typedef ComponentWrapper& reference;
typedef std::unordered_map<EntityID, std::set<decltype(ComponentInfo::Field_t::Index)>> DirtySet_t;
ComponentPool(const ::ComponentInfo& ci)
: m_ComponentInfo(ci)
+12 -144
View File
@@ -4,13 +4,11 @@
#include <boost/shared_array.hpp>
#include <boost/any.hpp>
#include "../Common.h"
#include "../GLM.h"
#include "Entity.h"
#include "ComponentInfo.h"
#include "DirtySet.h"
#include "Util/Any.h"
struct ComponentWrapper
{
ComponentWrapper(const ComponentInfo& componentInfo, char* data, ::DirtyBitField* dirtyBitField)
@@ -54,14 +52,6 @@ struct ComponentWrapper
}
}
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>
T& Field(const std::string& name)
{
@@ -75,15 +65,13 @@ struct ComponentWrapper
}
template <typename T>
void SetField(const std::string& name, const T& value)
{
Field<T>(name) = value;
SetAllDirty(name);
}
void SetField(const std::string& name, const T value) { Field<T>(name) = value; }
//template <typename T>
//void SetField(std::string name, T& value) { Field<T>(name) = value; }
// Specialization for string literals
template <std::size_t N>
void SetField(const std::string& name, const char(&value)[N]) { SetField(name, std::string(value)); }
void SetField(const std::string& name, const char(&value)[N]) { Field<std::string>(name) = std::string(value); }
void Copy(ComponentWrapper& destination)
{
@@ -117,8 +105,7 @@ struct ComponentWrapper
struct SubscriptProxy
{
friend struct ComponentWrapper;
public:
private:
SubscriptProxy(ComponentWrapper* component, std::string fieldName)
: m_Component(component)
, m_FieldName(fieldName)
@@ -132,28 +119,15 @@ struct ComponentWrapper
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); }
operator const double&() { return m_Component->Field<double>(m_FieldName); }
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>
void operator=(const T& val) { m_Component->SetField<T>(m_FieldName, val); }
operator T&() { return m_Component->Field<T>(m_FieldName); }
template <typename T>
void operator=(const T val) { m_Component->SetField<T>(m_FieldName, val); }
// TODO: Pass by reference and rvalue (universal reference?)
//template <typename T>
//void operator=(T& val) { m_Component->SetField<T>(m_PropertyName, val); }
// Specialization for string literals
template <std::size_t N>
@@ -162,112 +136,6 @@ struct ComponentWrapper
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
struct SharedComponentWrapper : ComponentWrapper
{
@@ -28,7 +28,7 @@ public:
virtual bool OnCommand(const Events::InputCommand& e) override;
virtual void Reset();
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, Field<double> assaultDashCoolDownTimer, EntityID playerID);
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID);
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
bool SpecialAbilityKeyDown() const { return m_SpecialAbilityKeyDown; }
@@ -286,7 +286,7 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
}
template <typename EventContext>
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, Field<double> assaultDashCoolDownTimer, EntityID playerID) {
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID) {
m_AssaultDashDoubleTapDeltaTime += dt;
m_DashEffectResetTimer += 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)
: ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage, isShielded)
{
ExplosionOrigin = (Field<glm::vec3>)explosionEffectComponent["ExplosionOrigin"];
TimeSinceDeath = (Field<double>)explosionEffectComponent["TimeSinceDeath"];
ExplosionDuration = (Field<double>)explosionEffectComponent["ExplosionDuration"];
EndColor = (Field<glm::vec4>)explosionEffectComponent["EndColor"];
Randomness = (Field<bool>)explosionEffectComponent["Randomness"];
RandomnessScalar = (Field<double>)explosionEffectComponent["RandomnessScalar"];
Velocity = (Field<glm::vec2>)explosionEffectComponent["Velocity"];
ColorByDistance = (Field<bool>)explosionEffectComponent["ColorByDistance"];
ExponentialAccelaration = (Field<bool>)explosionEffectComponent["ExponentialAccelaration"];
ExplosionOrigin = (glm::vec3)explosionEffectComponent["ExplosionOrigin"];
TimeSinceDeath = (double)explosionEffectComponent["TimeSinceDeath"];
ExplosionDuration = (double)explosionEffectComponent["ExplosionDuration"];
EndColor = (glm::vec4)explosionEffectComponent["EndColor"];
Randomness = (bool)explosionEffectComponent["Randomness"];
RandomnessScalar = (double)explosionEffectComponent["RandomnessScalar"];
Velocity = (glm::vec2)explosionEffectComponent["Velocity"];
ColorByDistance = (bool)explosionEffectComponent["ColorByDistance"];
ExponentialAccelaration = (bool)explosionEffectComponent["ExponentialAccelaration"];
};
glm::vec3 ExplosionOrigin;
+2 -2
View File
@@ -17,8 +17,8 @@ struct TextJob : RenderJob
: RenderJob()
{
Matrix = matrix;
Color = (const glm::vec4&)textComponent["Color"];
Content = (const std::string&)textComponent["Content"];
Color = (glm::vec4)textComponent["Color"];
Content = (std::string)textComponent["Content"];
Resource = font;
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
{
ComponentWrapper& transform = m_World->GetComponent(component.EntityID, "Transform");
(Field<double>)component["Time"] += dt;
(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"];
(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"];
}
};
+3 -24
View File
@@ -1,25 +1,6 @@
#include "Common.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
{
public:
@@ -28,11 +9,9 @@ public:
, PureSystem("RaptorCopter")
{ }
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRaptorCopter, double dt) override
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override
{
ComponentWrapper& cTransform = entity["Transform"];
//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"];
ComponentWrapper& transform = m_World->GetComponent(component.EntityID, "Transform");
(glm::vec3&)transform["Orientation"] += (float)(double)component["Speed"] * (float)dt * (glm::vec3)component["Axis"];
}
};
@@ -269,8 +269,7 @@ private:
EntityWrapper thirdPersonAttachment;
for (auto& attachment : weaponAttachments) {
ComponentWrapper cWeaponAttachment = attachment["WeaponAttachment"];
Field<std::string> weaponType = cWeaponAttachment["Weapon"];
if (*weaponType == m_ComponentType) {
if ((std::string&)cWeaponAttachment["Weapon"] == m_ComponentType) {
ComponentWrapper::SubscriptProxy person = cWeaponAttachment["Person"];
if ((ComponentInfo::EnumType)person == person.Enum("FirstPerson")) {
firstPersonAttachment = attachment;
+3 -3
View File
@@ -619,9 +619,9 @@ boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeM
AABB modelSpaceBox;
if (entity.HasComponent("AABB") && !takeModelBox) {
ComponentWrapper& cAABB = entity["AABB"];
modelSpaceBox = EntityAABB::FromOriginSize((const glm::vec3&)cAABB["Origin"], (const glm::vec3&)cAABB["Size"]);
modelSpaceBox = EntityAABB::FromOriginSize((glm::vec3)cAABB["Origin"], (glm::vec3)cAABB["Size"]);
} else if (entity.HasComponent("Model")) {
const std::string& res = entity["Model"]["Resource"];
std::string res = entity["Model"]["Resource"];
if (res.empty()) {
return boost::none;
}
@@ -667,7 +667,7 @@ boost::optional<EntityAABB> AbsoluteAABBExplosionEffect(EntityWrapper& entity)
if (!modelBox) {
return boost::none;
}
Field<bool> isRandom = entity["ExplosionEffect"]["Randomness"];
bool isRandom = (bool)entity["ExplosionEffect"]["Randomness"];
float random = isRandom ? (float)(double)entity["ExplosionEffect"]["RandomnessScalar"] : 0;
glm::vec3 origin = (glm::vec3)entity["ExplosionEffect"]["ExplosionOrigin"];
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.
glm::vec3 newOriginPos = ray.Origin() + (dist - 0.707107f*diameter) * ray.Direction();
glm::vec3 resolve = newOriginPos - boxA.Origin();
(Field<glm::vec3>)cTransform["Position"] += resolve;
(glm::vec3&)cTransform["Position"] += resolve;
boxA = *Collision::EntityAbsoluteAABB(entity);
if (resolve.y > 0) {
everHitTheGround = true;
cPhysics["IsOnGround"] = true;
((Field<glm::vec3>)cPhysics["Velocity"]).y(0.f);
(bool)cPhysics["IsOnGround"] = true;
((glm::vec3&)cPhysics["Velocity"]).y = 0.f;
}
break;
}
@@ -93,7 +93,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
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.
(Field<glm::vec3>)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity);
cPhysics["Velocity"] = inOutVelocity;
if (isOnGround) {
@@ -103,12 +103,12 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
}
} else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) {
//Enter here if boxB has no Model.
(Field<glm::vec3>)cTransform["Position"] += resolutionVector;
(glm::vec3&)cTransform["Position"] += resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity);
if (resolutionVector.y > 0) {
everHitTheGround = true;
(bool)cPhysics["IsOnGround"] = true;
((Field<glm::vec3>)cPhysics["Velocity"]).y(0.f);
((glm::vec3&)cPhysics["Velocity"]).y = 0.f;
}
}
}
+6 -6
View File
@@ -1,10 +1,10 @@
#include "Core/ComponentPool.h"
ComponentPoolForwardIterator::ComponentPoolForwardIterator(ComponentPool* pool, const MemoryPool<char>::iterator begin, const MemoryPool<char>::iterator end)
ComponentPoolForwardIterator::ComponentPoolForwardIterator(ComponentPool* pool)
: m_ComponentPool(pool)
, m_ComponentInfo(pool->m_ComponentInfo)
, m_MemoryPoolIterator(begin)
, m_MemoryPoolEnd(end)
, m_MemoryPoolIterator(pool->m_Pool.begin())
, m_MemoryPoolEnd(pool->m_Pool.end())
{ }
ComponentWrapper ComponentPoolForwardIterator::operator*() const
@@ -52,7 +52,7 @@ ComponentPool::ComponentPool(const ComponentPool& other)
// Duplicate strings
for (auto& name : m_ComponentInfo.StringFields) {
for (auto& c : *this) {
Field<std::string> val = c[name];
std::string& val = c[name];
ComponentWrapper::SolidifyStrings(c);
}
}
@@ -110,12 +110,12 @@ void ComponentPool::Delete(ComponentWrapper& wrapper)
ComponentPool::iterator ComponentPool::begin()
{
return iterator(this, m_Pool.begin(), m_Pool.end());
return iterator(this);
}
ComponentPool::iterator ComponentPool::end()
{
return iterator(this, m_Pool.end(), m_Pool.end());
return iterator(this);
}
size_t ComponentPool::size() const
+3 -3
View File
@@ -5,7 +5,7 @@ glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
glm::mat4 t = glm::mat4(1.f);
while (entity.Valid()) {
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;
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;
entity = entity.Parent();
}
@@ -24,7 +24,7 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
while (entity != EntityID_Invalid) {
ComponentWrapper transform = world->GetComponent(entity, "Transform");
EntityID parent = world->GetParent(entity);
position += Transform::AbsoluteOrientation(world, parent) * (const glm::vec3&)transform["Position"];
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
entity = parent;
}
@@ -37,7 +37,7 @@ glm::vec3 Transform::AbsoluteOrientationEuler(EntityWrapper entity)
while (entity.Valid()) {
ComponentWrapper transform = entity["Transform"];
orientation += (Field<glm::vec3>)transform["Orientation"];
orientation += (glm::vec3)transform["Orientation"];
entity = entity.Parent();
}
+2 -2
View File
@@ -13,8 +13,8 @@ void UniformScaleSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
return;
}
float distance = glm::length((glm::vec3)entity["Transform"]["Position"] - (const glm::vec3&)m_Camera["Transform"]["Position"]);
entity["Transform"]["Scale"] = (const glm::vec3&)cUniformScale["Scale"] * distance;
float distance = glm::length((glm::vec3)entity["Transform"]["Position"] - (glm::vec3&)m_Camera["Transform"]["Position"]);
entity["Transform"]["Scale"] = (glm::vec3&)cUniformScale["Scale"] * distance;
}
bool UniformScaleSystem::OnSetCamera(const Events::SetCamera& e)
+10 -10
View File
@@ -71,21 +71,21 @@ void EditorSystem::Update(double dt)
m_EditorStats->Draw(actualDelta);
if (m_CurrentSelection.Valid() && m_Widget.Valid()) {
m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection);
(glm::vec3&)m_Widget["Transform"]["Position"] = Transform::AbsolutePosition(m_CurrentSelection);
if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
m_Widget["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(m_CurrentSelection);
(glm::vec3&)m_Widget["Transform"]["Orientation"] = Transform::AbsoluteOrientationEuler(m_CurrentSelection);
} else {
m_Widget["Transform"]["Orientation"] = glm::vec3(0, 0, 0);
(glm::vec3&)m_Widget["Transform"]["Orientation"] = glm::vec3(0, 0, 0);
}
}
m_EditorWorldSystemPipeline->Update(actualDelta);
ComponentWrapper& cameraTransform = m_EditorCamera["Transform"];
Field<glm::vec3> ori = cameraTransform["Orientation"];
ori.x(m_EditorCameraInputController->Rotation().x);
ori.y(m_EditorCameraInputController->Rotation().y);
Field<glm::vec3> pos = cameraTransform["Position"];
glm::vec3& ori = cameraTransform["Orientation"];
ori.x = m_EditorCameraInputController->Rotation().x;
ori.y = m_EditorCameraInputController->Rotation().y;
glm::vec3& pos = cameraTransform["Position"];
pos += m_EditorCameraInputController->Movement() * glm::inverse(glm::quat(ori)) * (float)actualDelta;
}
}
@@ -101,7 +101,7 @@ void EditorSystem::Enable()
eSetCamera.CameraEntity = m_EditorCamera;
m_EventBroker->Publish(eSetCamera);
if (m_ActualCamera.Valid()) {
(Field<glm::vec3>)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera);
(glm::vec3&)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera);
}
// Pause the world we're editing
@@ -208,11 +208,11 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
if (parent.Valid()) {
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
}
(Field<glm::vec3>)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
glm::vec3 localTranslation = selectionOri * e.Translation;
(Field<glm::vec3>)m_CurrentSelection["Transform"]["Position"] += localTranslation;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation;
}
m_EditorGUI->SetDirty(m_CurrentSelection);
}
+2 -2
View File
@@ -596,8 +596,8 @@ void Client::sendLocalPlayerTransform()
Packet packet(MessageType::PlayerTransform, m_SendPacketID);
ComponentWrapper cTransform = m_LocalPlayer["Transform"];
const glm::vec3& position = cTransform["Position"];
const glm::vec3& orientation = cTransform["Orientation"];
glm::vec3& position = cTransform["Position"];
glm::vec3& orientation = cTransform["Orientation"];
packet.WritePrimitive(position.x);
packet.WritePrimitive(position.y);
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) {
ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField);
if (fieldInfo.Type == "string") {
const std::string& value = componentWrapper[componentField];
std::string& value = componentWrapper[componentField];
packet.WriteString(value);
} else {
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) {
ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField);
if (fieldInfo.Type == "string") {
const std::string& value = componentWrapper[componentField];
std::string& value = componentWrapper[componentField];
packet.WriteString(value);
} else {
packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride);
+12 -13
View File
@@ -71,8 +71,7 @@ void AnimationSystem::UpdateAnimations(double dt)
Model* model;
try {
Field<std::string> res = modelEntity["Model"]["Resource"];
model = ResourceManager::Load<::Model, true>(res);
model = ResourceManager::Load<::Model, true>(modelEntity["Model"]["Resource"]);
} catch (const std::exception&) {
return;
}
@@ -88,23 +87,23 @@ void AnimationSystem::UpdateAnimations(double dt)
continue;;
}
double animationSpeed = (const double&)animationC["Speed"];
double animationSpeed = (double)animationC["Speed"];
if((const bool&)animationC["Reverse"]) {
if((bool)animationC["Reverse"]) {
animationSpeed *= -1;
}
if ((const bool&)animationC["Play"]) {
if ((bool)animationC["Play"]) {
double nextTime = (Field<double>)animationC["Time"] + animationSpeed * dt;
if (!(Field<bool>)animationC["Loop"]) {
double nextTime = (double)animationC["Time"] + animationSpeed * dt;
if (!(bool)animationC["Loop"]) {
if (nextTime > animation->Duration) {
nextTime = animation->Duration;
(Field<bool>)animationC["Play"] = false;
(bool&)animationC["Play"] = false;
} else if (nextTime < 0) {
nextTime = 0;
(Field<bool>)animationC["Play"] = false;
(bool&)animationC["Play"] = false;
}
} else {
if (nextTime > animation->Duration) {
@@ -118,7 +117,7 @@ void AnimationSystem::UpdateAnimations(double dt)
}
}
}
(Field<double>)animationC["Time"] = nextTime;
(double&)animationC["Time"] = nextTime;
}
}
}
@@ -203,15 +202,15 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
if (nodeEntity.Valid()) {
if (nodeEntity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]);
(Field<bool>)nodeEntity["Animation"]["Reverse"] = e.Reverse;
(bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse;
if (e.Restart) {
if (animation != nullptr) {
if (e.Restart) {
if (e.Reverse) {
(Field<double>)nodeEntity["Animation"]["Time"] = animation->Duration;
(double&)nodeEntity["Animation"]["Time"] = animation->Duration;
} else {
(Field<double>)nodeEntity["Animation"]["Time"] = 0.0;
(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->Entity = ModelEntity;
m_Root->Name = ModelEntity.Name();
m_Root->Pose = m_Skeleton->GetFrameBones(animation, (const double&)ModelEntity["Animation"]["Time"], (const bool&)ModelEntity["Animation"]["Additive"]);
m_Root->Pose = m_Skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]);
m_Root->Parent = nullptr;
m_Root->Type = NodeType::Animation;
@@ -26,9 +26,9 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
m_Root->Name = ModelEntity.Name();
m_Root->Parent = nullptr;
m_Root->Type = NodeType::Blend;
m_Root->Weight = (const double&)ModelEntity["Blend"]["Weight"];
m_Root->SubTreeRoot = (const bool&)ModelEntity["Blend"]["SubTreeRoot"];
ModelEntity["Blend"]["Weight"] = glm::clamp((const double&)ModelEntity["Blend"]["Weight"], 0.0, 1.0);
m_Root->Weight = (double)ModelEntity["Blend"]["Weight"];
m_Root->SubTreeRoot = (bool)ModelEntity["Blend"]["SubTreeRoot"];
(double&)ModelEntity["Blend"]["Weight"] = glm::clamp((double)ModelEntity["Blend"]["Weight"], 0.0, 1.0);
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);
@@ -120,7 +120,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
Node* node = new Node();
node->Entity = childEntity;
node->Name = childEntity.Name();
node->Pose = m_Skeleton->GetFrameBones(animation, (const double&)childEntity["Animation"]["Time"], (const bool&)childEntity["Animation"]["Additive"]);
node->Pose = m_Skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]);
node->Parent = parentNode;
node->Type = NodeType::Animation;
return node;
@@ -131,9 +131,9 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
node->Name = childEntity.Name();
node->Parent = parentNode;
node->Type = NodeType::Blend;
childEntity["Blend"]["Weight"] = glm::clamp((const double&)childEntity["Blend"]["Weight"], 0.0, 1.0);
node->Weight = (const double&)childEntity["Blend"]["Weight"];
node->SubTreeRoot = (const bool&)childEntity["Blend"]["SubTreeRoot"];
(double&)childEntity["Blend"]["Weight"] = glm::clamp((double)childEntity["Blend"]["Weight"], 0.0, 1.0);
node->Weight = (double)childEntity["Blend"]["Weight"];
node->SubTreeRoot = (bool)childEntity["Blend"]["SubTreeRoot"];
//if (node->Weight < 1.f && node->Weight > 0.f) {
node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], 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.HasComponent("Blend")) {
entity["Blend"]["Weight"] = blendInfo.Weight;
(double&)entity["Blend"]["Weight"] = blendInfo.Weight;
}
}
}
@@ -229,7 +229,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
if (entity.Valid()) {
if (entity.HasComponent("Animation")) {
entity["Animation"]["Play"] = true;
(bool&)entity["Animation"]["Play"] = true;
}
}
}
@@ -263,7 +263,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
}
double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight;
currentNode->Entity["Blend"]["Weight"] = weight;
(double&)currentNode->Entity["Blend"]["Weight"] = weight;
currentNode->Weight = weight;
lastNode = currentNode;
@@ -326,7 +326,7 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
}
double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight;
currentNode->Entity["Blend"]["Weight"] = weight;
(double&)currentNode->Entity["Blend"]["Weight"] = weight;
currentNode->Weight = weight;
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));
if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
}
if ((bool)entity["BoneAttachment"]["InheritOrientation"]) {
entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"];
(glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"];
}
if ((bool)entity["BoneAttachment"]["InheritScale"]) {
entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
(glm::vec3&)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);
// Path changed
if (it->second->SoundResource->Path() != (const std::string&)emitter["FilePath"]) {
it->second->SoundResource = ResourceManager::Load<Sound>((const std::string&)emitter["FilePath"]);
if (it->second->SoundResource->Path() != (std::string)emitter["FilePath"]) {
it->second->SoundResource = ResourceManager::Load<Sound>((std::string)emitter["FilePath"]);
if (it->second->SoundResource->Buffer() != 0) {
playSound(it->second);
}
@@ -205,14 +205,14 @@ bool SoundManager::OnPlaySoundOnPosition(const Events::PlaySoundOnPosition & e)
Source* source = createSource(e.FilePath);
auto emitterID = m_World->CreateEntity();
auto transform = m_World->AttachComponent(emitterID, "Transform");
transform["Position"] = e.Position;
(glm::vec3&)transform["Position"] = e.Position;
auto emitter = m_World->AttachComponent(emitterID, "SoundEmitter");
emitter["Gain"] = e.Gain;
emitter["Pitch"] = e.Pitch;
emitter["Loop"] = e.Loop;
emitter["MaxDistance"] = e.MaxDistance;
emitter["RollOffFactor"] = e.RollOffFactor;
emitter["ReferenceDistance"] = e.ReferenceDistance;
(float&)(double)emitter["Gain"] = e.Gain;
(float&)(double)emitter["Pitch"] = e.Pitch;
(bool&)emitter["Loop"] = e.Loop;
(float&)(double)emitter["MaxDistance"] = e.MaxDistance;
(float&)(double)emitter["RollOffFactor"] = e.RollOffFactor;
(float&)(double)emitter["ReferenceDistance"] = e.ReferenceDistance;
source->Type = SoundType::SFX;
m_Sources[emitterID] = source;
playSound(source);
@@ -246,8 +246,8 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
}
auto emitterChild = m_World->CreateEntity((*it).EntityID);
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
emitter["Loop"] = true;
emitter["FilePath"] = e.FilePath;
(bool&)emitter["Loop"] = true;
(std::string&)emitter["FilePath"] = e.FilePath;
m_World->AttachComponent(emitterChild, "Transform");
Source* source = createSource(e.FilePath);
source->Type = SoundType::BGM;
@@ -28,21 +28,21 @@ void AbilityCooldownHUDSystem::Update(double dt)
//If we have a shield ability, we set the right icon
abilityName = "ShieldAbility";
if (entity.HasComponent("Sprite")) {
entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\SheildDots-01.png";
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\SheildDots-01.png";
}
}
} else {
//If we do have a sprint ability, we change the icon
abilityName = "SprintAbility";
if (entity.HasComponent("Sprite")) {
entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Dash-01.png";
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Dash-01.png";
}
}
} else {
//If we have a dash ability, we set the icon to the correct one.
abilityName = "DashAbility";
if (entity.HasComponent("Sprite")) {
entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Superman-01.png";
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Superman-01.png";
}
}
@@ -57,7 +57,7 @@ void AbilityCooldownHUDSystem::Update(double dt)
if (cooldownTextEntity.Valid()) {
if (cooldownTextEntity.HasComponent("Text")) {
cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3);
std::string t = (std::string&)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")) {
EntityWrapper parentWithAssaultBoost = assaultEntity.FirstParentWithComponent("BoostAssault");
if (parentWithAssaultBoost.Valid()) {
assaultEntity["Fill"]["Percentage"] = 1.0;
(double&)assaultEntity["Fill"]["Percentage"] = 1.0;
} else {
assaultEntity["Fill"]["Percentage"] = 0.0;
(double&)assaultEntity["Fill"]["Percentage"] = 0.0;
}
}
}
@@ -21,9 +21,9 @@ void BoostIconsHUDSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
if (defenderEntity.HasComponent("Fill")) {
EntityWrapper parentWithAssaultBoost = defenderEntity.FirstParentWithComponent("BoostDefender");
if (parentWithAssaultBoost.Valid()) {
defenderEntity["Fill"]["Percentage"] = 1.0;
(double&)defenderEntity["Fill"]["Percentage"] = 1.0;
} else {
defenderEntity["Fill"]["Percentage"] = 0.0;
(double&)defenderEntity["Fill"]["Percentage"] = 0.0;
}
}
}
@@ -32,9 +32,9 @@ void BoostIconsHUDSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
if (sniperEntity.HasComponent("Fill")) {
EntityWrapper parentWithAssaultBoost = sniperEntity.FirstParentWithComponent("BoostSniper");
if (parentWithAssaultBoost.Valid()) {
sniperEntity["Fill"]["Percentage"] = 1.0;
(double&)sniperEntity["Fill"]["Percentage"] = 1.0;
} else {
sniperEntity["Fill"]["Percentage"] = 0.0;
(double&)sniperEntity["Fill"]["Percentage"] = 0.0;
}
}
}
@@ -155,13 +155,13 @@ void CapturePointArrowHUDSystem::Update(double dt)
pos = m_BlueTeamCurrentTarget;
}
Field<glm::vec3> arrowOri = arrowEntity["Transform"]["Orientation"];
glm::vec3& arrowOri = arrowEntity["Transform"]["Orientation"];
glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(arrowEntity) - pos); //Maybe should be player instead
float pitch = std::asin(-lookVector.y);
float yaw = std::atan2(lookVector.x, lookVector.z);
arrowOri.x(pitch);
arrowOri.y(yaw);
arrowOri.z(0.f);
arrowOri.x = pitch;
arrowOri.y = yaw;
arrowOri.z = 0.f;
EntityWrapper parent = arrowEntity.Parent();
if (parent.Valid()) {
arrowOri -= Transform::AbsoluteOrientationEuler(parent);
+1 -2
View File
@@ -49,8 +49,7 @@ void CapturePointHUDSystem::Update(double dt)
double currentCaptureTime = (double)entityCP["CapturePoint"]["CaptureTimer"];
double progress = glm::abs(currentCaptureTime)/15.0;
int currentCapturingTeam = currentCaptureTime > 0 ? redTeam : currentCaptureTime < 0 ? blueTeam : spectatorTeam;
Field<glm::vec3> orientation = entityHUD["Transform"]["Orientation"];
orientation.z(currentCapturingTeam == redTeam ? glm::half_pi<float>()+glm::pi<float>() : glm::half_pi<float>());
((glm::vec3&)entityHUD["Transform"]["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);
entityHUD["Fill"]["Color"] = fillColor;
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++) {
auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"];
if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) {
m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false;
m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false;
m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false;
}
}
//save the next cap points and publish the captured event
+3 -4
View File
@@ -2,11 +2,10 @@
void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
{
Field<double> timeSinceDeath = component["TimeSinceDeath"];
if (timeSinceDeath > (double)component["ExplosionDuration"]) {
timeSinceDeath = 0.f;
if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) {
(double)component["TimeSinceDeath"] = 0.f;
}
timeSinceDeath += dt;
(double&)component["TimeSinceDeath"] += dt;
//if ((bool)Component["Gravity"] == true) {
// (bool)Component["ExponentialAccelaration"] = false;
+7 -11
View File
@@ -22,23 +22,19 @@ void HealthHUDSystem::Update(double dt)
if (entityIDParent.HasComponent("Health")) {
if (entity.HasComponent("Text")) {
Field<double> health = entityIDParent["Health"]["Health"];
Field<double> maxHealth = entityIDParent["Health"]["Health"];
std::string s = "";
s = s + std::to_string((int)health);
s = s + std::to_string((int)(double)entityIDParent["Health"]["Health"]);
s = s + "/";
s = s + std::to_string((int)maxHealth);
float healthPercentage = health/maxHealth;
//(Field<glm::vec4>)entity["Text"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Text"]["Color"]).a);
s = s + std::to_string((int)(double)entityIDParent["Health"]["MaxHealth"]);
float healthPercentage = (double)entityIDParent["Health"]["Health"]/(double)entityIDParent["Health"]["MaxHealth"];
//(glm::vec4&)entity["Text"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Text"]["Color"]).a);
entity["Text"]["Content"] = s;
}
if(entity.HasComponent("Fill")) {
Field<double> health = entityIDParent["Health"]["Health"];
Field<double> maxHealth = entityIDParent["Health"]["Health"];
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;
float healthPercentage = (double)entityIDParent["Health"]["Health"]/(double)entityIDParent["Health"]["MaxHealth"];
(glm::vec4&)entity["Fill"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Fill"]["Color"]).a);
(double&)entity["Fill"]["Percentage"] = healthPercentage;
}
}
+3 -3
View File
@@ -21,7 +21,7 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
}
ComponentWrapper cHealth = e.Victim["Health"];
Field<double> health = cHealth["Health"];
double& health = cHealth["Health"];
//if player has the boost from a defender, subtract the damage taken by StrengthOfEffect amount
auto playerBoostDefenderEntity = e.Victim.FirstChildByName("BoostDefender");
if (playerBoostDefenderEntity.Valid()) {
@@ -56,9 +56,9 @@ bool HealthSystem::OnInputCommand(Events::InputCommand& e)
bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e)
{
ComponentWrapper cHealth = e.Player["Health"];
Field<double> health = cHealth["Health"];
double& health = cHealth["Health"];
health += e.HealthAmount;
health = std::min((double)health, (double)cHealth["MaxHealth"]);
health = std::min(health, (double)cHealth["MaxHealth"]);
return true;
}
+5 -5
View File
@@ -17,7 +17,7 @@ void InterpolationSystem::Update(double dt)
continue;
}
auto& iPosition = kv.second;
Field<glm::tvec3<float, glm::highp>> position = iPosition.Component[iPosition.Field];
glm::vec3& position = iPosition.Component[iPosition.Field];
iPosition.Alpha += dt;
float alpha = glm::min(iPosition.Alpha / m_SnapshotInterval, 1.0);
@@ -31,7 +31,7 @@ void InterpolationSystem::Update(double dt)
continue;
}
auto& iOrientation = kv.second;
Field<glm::vec3> orientation = iOrientation.Component[iOrientation.Field];
glm::vec3& orientation = iOrientation.Component[iOrientation.Field];
iOrientation.Alpha += dt / m_SnapshotInterval;
iOrientation.Alpha = glm::min(iOrientation.Alpha, 1.0);
@@ -45,7 +45,7 @@ void InterpolationSystem::Update(double dt)
continue;
}
auto& iVelocity = kv.second;
Field<glm::vec3> position = iVelocity.Component[iVelocity.Field];
glm::vec3& position = iVelocity.Component[iVelocity.Field];
iVelocity.Alpha += dt;
float alpha = glm::min(iVelocity.Alpha / m_SnapshotInterval, 1.0);
@@ -72,8 +72,8 @@ bool InterpolationSystem::OnInterpolate(Events::Interpolate& e)
Interpolation<glm::quat> iOrientation(
cTransform,
"Orientation",
glm::quat((Field<glm::vec3>)cTransform["Orientation"]),
glm::quat((Field<glm::vec3>)e.Component["Orientation"])
glm::quat((glm::vec3&)cTransform["Orientation"]),
glm::quat((glm::vec3&)e.Component["Orientation"])
);
m_InterpolateOrientation.erase(e.Entity);
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++) {
EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(i));
if (child.HasComponent("Text")) {
(Field<std::string>)child["Text"]["Content"] = "";
(std::string&)child["Text"]["Content"] = "";
}
}
@@ -27,14 +27,14 @@ void KillFeedSystem::Update(double dt)
EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(feedIndex));
if (child.HasComponent("Text")) {
(Field<std::string>)child["Text"]["Content"] = (*it).Content;
(Field<glm::vec4>)child["Text"]["Color"] = (*it).Color;
(std::string&)child["Text"]["Content"] = (*it).Content;
(glm::vec4&)child["Text"]["Color"] = (*it).Color;
(*it).TimeToLive -= dt;
if ((*it).TimeToLive <= 0.f) {
(Field<std::string>)child["Text"]["Content"] = "";
(Field<glm::vec4>)child["Text"]["Color"] = (*it).Color;
(std::string&)child["Text"]["Content"] = "";
(glm::vec4&)child["Text"]["Color"] = (*it).Color;
remove = true;
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ void LifetimeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cL
return;
}
Field<double> lifetime = cLifetime["Lifetime"];
double& lifetime = cLifetime["Lifetime"];
lifetime -= dt;
if (lifetime <= 0.0) {
+29 -30
View File
@@ -54,7 +54,7 @@ void PlayerMovementSystem::Update(double dt)
playerEntityModel.Copy(sprintEffect["Model"]);
playerEntityAnimation.Copy(sprintEffect["Animation"]);
sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
((Field<glm::vec4>)sprintEffect["ExplosionEffect"]["EndColor"]).w(0.f);
((glm::vec4&)sprintEffect["ExplosionEffect"]["EndColor"]).w = 0.f;
sprintEffect["Animation"]["Speed1"] = 0.0;
sprintEffect["Animation"]["Speed2"] = 0.0;
sprintEffect["Animation"]["Speed3"] = 0.0;
@@ -77,10 +77,10 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
// Aim pitch
EntityWrapper cameraEntity = player.FirstChildByName("Camera");
if (cameraEntity.Valid()) {
Field<glm::vec3> cameraOrientation = cameraEntity["Transform"]["Orientation"];
cameraOrientation.x(cameraOrientation.x() + controller->Rotation().x);
glm::vec3& cameraOrientation = cameraEntity["Transform"]["Orientation"];
cameraOrientation.x += controller->Rotation().x;
// 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
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
@@ -89,29 +89,29 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("AimPrimary");
if(aimPrimaryEntity.Valid()){
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>();
(Field<double>)aimPrimaryEntity["Animation"]["Time"] = time;
(double&)aimPrimaryEntity["Animation"]["Time"] = time;
}
}
EntityWrapper aimSecondaryEntity = playerModel.FirstChildByName("AimSecondary");
if (aimSecondaryEntity.Valid()) {
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>();
(Field<double>)aimSecondaryEntity["Animation"]["Time"] = time;
(double&)aimSecondaryEntity["Animation"]["Time"] = time;
}
}
}
}
ComponentWrapper& cTransform = player["Transform"];
Field<glm::vec3> ori = cTransform["Orientation"];
ori.y(ori.y() + controller->Rotation().y);
glm::vec3& ori = cTransform["Orientation"];
ori.y += controller->Rotation().y;
float playerMovementSpeed = player["Player"]["MovementSpeed"];
float playerCrouchSpeed = player["Player"]["CrouchSpeed"];
Field<glm::vec3> wishDirection = player["Player"]["CurrentWishDirection"];
glm::vec3& wishDirection = player["Player"]["CurrentWishDirection"];
auto playerBoostAssaultEntity = player.FirstChildByName("BoostAssault");
if (playerBoostAssaultEntity.Valid()) {
playerMovementSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"];
@@ -131,8 +131,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
ComponentWrapper cPhysics = player["Physics"];
//Assault Dash Check
if (player.HasComponent("DashAbility")) {
Field<double> coolDownTimer = player["DashAbility"]["CoolDownTimer"];
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], coolDownTimer, player.ID);
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player.ID);
}
wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
//this makes sure you can only dash in the 4 directions: forw,backw,left,right
@@ -146,21 +145,21 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
wishSpeed = playerMovementSpeed;
}
if (player.ID == m_LocalPlayer.ID) {
if (glm::length((glm::vec3)wishDirection) == 0) {
if (glm::length(wishDirection) == 0) {
// If no key is pressed, reset the distance moved since last step.
m_DistanceMoved = 0;
}
}
Field<glm::vec3> velocity = cPhysics["Velocity"];
glm::vec3& velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"];
//ImGui::Text(isOnGround ? "On ground" : "In air");
//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);
groundVelocity.x = velocity.x();
groundVelocity.z = velocity.z();
groundVelocity.x = velocity.x;
groundVelocity.z = velocity.z;
//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));
float currentSpeedProj = glm::dot(groundVelocity, (glm::vec3)wishDirection);
float currentSpeedProj = glm::dot(groundVelocity, wishDirection);
float addSpeed = wishSpeed - currentSpeedProj;
//ImGui::Text("currentSpeedProj: %f", currentSpeedProj);
//ImGui::Text("wishSpeed: %f", wishSpeed);
@@ -185,8 +184,8 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (sniperSprinting) {
accelerationSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"];
}
velocity += accelerationSpeed * (glm::vec3)wishDirection;
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x(), velocity.y(), velocity.z(), glm::length((glm::vec3)velocity));
velocity += accelerationSpeed * wishDirection;
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
}
if (isOnGround) {
@@ -196,7 +195,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (controller->Jumping() && !controller->Crouching()) {
if (isOnGround) {
(bool)cPhysics["IsOnGround"] = false;
velocity.y(player["Player"]["JumpSpeed"]);
velocity.y = player["Player"]["JumpSpeed"];
if (player.Valid()) {
@@ -228,7 +227,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
} else if (player.HasComponent("DoubleJump") && !controller->DoubleJumping()) {
//Enter here if player can double jump and is doing so.
(bool)cPhysics["IsOnGround"] = false;
velocity.y(player["DoubleJump"]["DoubleJumpSpeed"]);
velocity.y = player["DoubleJump"]["DoubleJumpSpeed"];
if (player.Valid()) {
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
@@ -269,7 +268,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
}
if (player.HasComponent("AABB")) {
Field<glm::vec3> size = player["AABB"]["Size"];
glm::vec3& size = player["AABB"]["Size"];
if (controller->Crouching()) {
size = glm::vec3(1.f, 1.f, 1.f);
} else {
@@ -291,11 +290,11 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
// Only apply velocity to local player
ComponentWrapper& cTransform = player["Transform"];
ComponentWrapper& cPhysics = player["Physics"];
Field<glm::vec3> velocity = cPhysics["Velocity"];
glm::vec3& velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"];
// Ground friction
float speed = glm::length((glm::vec3)velocity);
float speed = glm::length(velocity);
static float groundFriction = 7.f;
ImGui::InputFloat("groundFriction", &groundFriction);
static float airFriction = 2.f;
@@ -305,16 +304,16 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
if (speed > 0) {
float drop = speed * friction * (float)dt;
float multiplier = glm::max(speed - drop, 0.f) / speed;
velocity.x(velocity.x() * multiplier);
velocity.z(velocity.z() * multiplier);
velocity.x *= multiplier;
velocity.z *= multiplier;
}
// Gravity
if (cPhysics["Gravity"]) {
velocity.y(velocity.y() - (9.82f * (float)dt));
velocity.y -= 9.82f * (float)dt;
}
Field<glm::vec3> position = cTransform["Position"];
glm::vec3& position = cTransform["Position"];
position += velocity * (float)dt;
}
@@ -496,7 +495,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
playerEntityModel.Copy(dashEffect["Model"]);
playerEntityAnimation.Copy(dashEffect["Animation"]);
dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
((Field<glm::vec4>)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f;
((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.
ComponentWrapper& modeComponent = *pool->begin();
// Increase timer.
Field<double> timer = modeComponent["RespawnTime"];
double& timer = (double&)modeComponent["RespawnTime"];
timer += dt;
if (m_DbgConfigForceRespawn) {
(Field<double>)modeComponent["MaxRespawnTime"] = m_ForcedRespawnTime;
(double&)modeComponent["MaxRespawnTime"] = m_ForcedRespawnTime;
}
double maxRespawnTime = (double)modeComponent["MaxRespawnTime"];
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->second.Team != currentTeam) {
m_World->DeleteEntity(child.ID);
(Field<int>)entity["ScoreScreen"]["TotalIdentities"] -= 1;
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1;
break;
}
for (auto it2 = m_DisconnectedIdentities.begin(); it2 != m_DisconnectedIdentities.end(); ++it2) {
if (ID == *it2) {
m_World->DeleteEntity(child.ID);
(Field<int>)entity["ScoreScreen"]["TotalIdentities"] -= 1;
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1;
it2 = m_DisconnectedIdentities.erase(it2);
it = m_PlayerIdentities.erase(it);
@@ -59,17 +59,17 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
break;
}
//Update Deaths for child
(Field<int>)child["ScoreIdentity"]["Kills"] = it->second.Kills;
(int&)child["ScoreIdentity"]["Kills"] = it->second.Kills;
//Update Kills for child
(Field<int>)child["ScoreIdentity"]["Deaths"] = it->second.Deaths;
(int&)child["ScoreIdentity"]["Deaths"] = it->second.Deaths;
//KD is not updated at the moment.
if (it->second.Deaths != 0) {
(Field<double>)child["ScoreIdentity"]["KD"] = it->second.Kills/it->second.Deaths;
(double&)child["ScoreIdentity"]["KD"] = it->second.Kills/it->second.Deaths;
}
//Update position for child
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
(Field<glm::vec3>) child["Transform"]["Position"] = offset * position;
(glm::vec3&) child["Transform"]["Position"] = offset * position;
position += 1.f;
break;
@@ -90,16 +90,16 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
EntityWrapper scoreIdentity = entityFile->MergeInto(m_World);
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
int newPosition = (int)entity["ScoreScreen"]["TotalIdentities"];
(Field<glm::vec3>) scoreIdentity["Transform"]["Position"] = offset * (float)newPosition;
(glm::vec3&) scoreIdentity["Transform"]["Position"] = offset * (float)newPosition;
auto cScoreIdentity = scoreIdentity["ScoreIdentity"];
auto data = it->second;
(Field<std::string>)cScoreIdentity["Name"] = data.Name;
(Field<int>)cScoreIdentity["ID"] = data.ID;
(std::string&)cScoreIdentity["Name"] = data.Name;
(int&)cScoreIdentity["ID"] = data.ID;
m_World->SetParent(scoreIdentity.ID, entity.ID);
(Field<int>)entity["ScoreScreen"]["TotalIdentities"] += 1;
(int&)entity["ScoreScreen"]["TotalIdentities"] += 1;
}
}
+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);
Field<std::string> text = entity["Text"]["Content"];
std::string& text = entity["Text"]["Content"];
if (field.Type == "int") {
text = boost::lexical_cast<std::string>((const int&)component[fieldName]);
@@ -2,7 +2,7 @@
void AssaultWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{
Field<double> fireCooldown = cWeapon["FireCooldown"];
double& fireCooldown = cWeapon["FireCooldown"];
fireCooldown = glm::max(0.0, fireCooldown - 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)
{
// Start reloading automatically if at 0 mag ammo
Field<int> magAmmo = cWeapon["MagazineAmmo"];
int& magAmmo = cWeapon["MagazineAmmo"];
if (m_ConfigAutoReload && magAmmo <= 0) {
OnReload(cWeapon, wi);
}
// Only start reloading once we're done firing
Field<bool> reloadQueued = cWeapon["ReloadQueued"];
Field<double> fireCooldown = cWeapon["FireCooldown"];
Field<bool> isReloading = cWeapon["IsReloading"];
bool& reloadQueued = cWeapon["ReloadQueued"];
double& fireCooldown = cWeapon["FireCooldown"];
bool& isReloading = cWeapon["IsReloading"];
if (reloadQueued && fireCooldown <= 0) {
reloadQueued = fireCooldown;
isReloading = true;
}
// Decrement reload timer
Field<double> reloadTimer = cWeapon["ReloadTimer"];
double& reloadTimer = cWeapon["ReloadTimer"];
if (isReloading) {
reloadTimer = glm::max(0.0, reloadTimer - dt);
}
// Handle reloading
if (isReloading && reloadTimer <= 0.0) {
Field<int> magSize = cWeapon["MagazineSize"];
Field<int> ammo = cWeapon["Ammo"];
int& magSize = cWeapon["MagazineSize"];
int& ammo = cWeapon["Ammo"];
ammo = glm::max(0, ammo - (magSize - magAmmo));
magAmmo = glm::min(*magSize, *ammo);
magAmmo = glm::min(magSize, ammo);
isReloading = false;
if (wi.FirstPersonEntity.Valid()) {
wi.FirstPersonEntity["Model"]["Visible"] = true;
@@ -49,15 +49,15 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
// Restore view angle
if (IsClient) {
Field<float> currentTravel = cWeapon["CurrentTravel"];
Field<float> returnSpeed = cWeapon["ViewReturnSpeed"];
float& currentTravel = cWeapon["CurrentTravel"];
float& returnSpeed = cWeapon["ViewReturnSpeed"];
if (currentTravel > 0) {
float change = returnSpeed * dt;
currentTravel = glm::max(0.f, currentTravel - change);
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) {
Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
cameraOrientation.x(cameraOrientation.x() - change);
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
cameraOrientation.x -= change;
}
}
}
@@ -72,7 +72,7 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
if (rootNode.Valid()) {
EntityWrapper blend = rootNode.FirstChildByName("MovementBlend");
if (blend.Valid()) {
(Field<double>)blend["Blend"]["Weight"] = animationWeight;
(double&)blend["Blend"]["Weight"] = animationWeight;
}
}
@@ -97,24 +97,24 @@ void AssaultWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, Weapon
void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
{
Field<bool> reloadQueued = cWeapon["ReloadQueued"];
Field<bool> isReloading = cWeapon["IsReloading"];
bool& reloadQueued = cWeapon["ReloadQueued"];
bool& isReloading = cWeapon["IsReloading"];
if (reloadQueued || isReloading) {
return;
}
Field<int> magAmmo = cWeapon["MagazineAmmo"];
Field<int> magSize = cWeapon["MagazineSize"];
int& magAmmo = cWeapon["MagazineAmmo"];
int& magSize = cWeapon["MagazineSize"];
if (magAmmo >= magSize) {
return;
}
Field<int> ammo = cWeapon["Ammo"];
int& ammo = cWeapon["Ammo"];
if (ammo <= 0) {
return;
}
Field<double> reloadTime = cWeapon["ReloadTime"];
Field<double> reloadTimer = cWeapon["ReloadTimer"];
double reloadTime = cWeapon["ReloadTime"];
double& reloadTimer = cWeapon["ReloadTimer"];
// Start reload
reloadQueued = true;
@@ -163,7 +163,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"];
// Ammo
Field<int> magAmmo = cWeapon["MagazineAmmo"];
int& magAmmo = cWeapon["MagazineAmmo"];
if (magAmmo <= 0) {
return;
} else {
@@ -174,16 +174,16 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
if (IsClient) {
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) {
Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
float viewPunch = cWeapon["ViewPunch"];
float maxTravelAngle = cWeapon["MaxTravelAngle"];
Field<float> currentTravel = cWeapon["CurrentTravel"];
float& currentTravel = cWeapon["CurrentTravel"];
if (currentTravel < maxTravelAngle) {
float change = viewPunch;
if (currentTravel + change > maxTravelAngle) {
change = maxTravelAngle - currentTravel;
}
cameraOrientation.x(cameraOrientation.x() + change);
cameraOrientation.x += change;
currentTravel += change;
}
}
@@ -203,7 +203,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
float distance = traceRayDistance(origin, direction);
EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner);
if (ray.Valid()) {
((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance);
((glm::vec3&)ray["Transform"]["Scale"]).z = distance;
}
}
@@ -2,7 +2,7 @@
void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{
Field<double> fireCooldown = cWeapon["FireCooldown"];
double& fireCooldown = cWeapon["FireCooldown"];
fireCooldown = glm::max(0.0, fireCooldown - 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)
{
// Decrement reload timer
Field<double> reloadTimer = cWeapon["ReloadTimer"];
double& reloadTimer = cWeapon["ReloadTimer"];
reloadTimer = glm::max(0.0, reloadTimer - dt);
// Start reloading automatically if at 0 mag ammo
Field<int> magAmmo = cWeapon["MagazineAmmo"];
int& magAmmo = cWeapon["MagazineAmmo"];
if (m_ConfigAutoReload && magAmmo <= 0) {
OnReload(cWeapon, wi);
}
// Handle reloading
Field<bool> isReloading = cWeapon["IsReloading"];
bool& isReloading = cWeapon["IsReloading"];
if (isReloading && reloadTimer <= 0.0) {
double reloadTime = cWeapon["ReloadTime"];
Field<int> magSize = cWeapon["MagazineSize"];
Field<int> ammo = cWeapon["Ammo"];
int& magSize = cWeapon["MagazineSize"];
int& ammo = cWeapon["Ammo"];
if (magAmmo < magSize && ammo > 0) {
ammo -= 1;
magAmmo += 1;
@@ -42,15 +42,15 @@ void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
// Restore view angle
if (IsClient) {
Field<float> currentTravel = cWeapon["CurrentTravel"];
Field<float> returnSpeed = cWeapon["ViewReturnSpeed"];
float& currentTravel = cWeapon["CurrentTravel"];
float& returnSpeed = cWeapon["ViewReturnSpeed"];
if (currentTravel > 0) {
float change = returnSpeed * dt;
currentTravel = glm::max(0.f, currentTravel - change);
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) {
Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
cameraOrientation.x(cameraOrientation.x() - change);
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
cameraOrientation.x -= change;
}
}
}
@@ -76,23 +76,23 @@ void DefenderWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, Weapo
void DefenderWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
{
Field<bool> isReloading = cWeapon["IsReloading"];
bool& isReloading = cWeapon["IsReloading"];
if (isReloading) {
return;
}
Field<int> magAmmo = cWeapon["MagazineAmmo"];
Field<int> magSize = cWeapon["MagazineSize"];
int& magAmmo = cWeapon["MagazineAmmo"];
int& magSize = cWeapon["MagazineSize"];
if (magAmmo >= magSize) {
return;
}
Field<int> ammo = cWeapon["Ammo"];
int& ammo = cWeapon["Ammo"];
if (ammo <= 0) {
return;
}
double reloadTime = cWeapon["ReloadTime"];
Field<double> reloadTimer = cWeapon["ReloadTimer"];
double& reloadTimer = cWeapon["ReloadTimer"];
// Start reload
isReloading = true;
@@ -165,11 +165,11 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"];
// Stop reloading
Field<bool> isReloading = cWeapon["IsReloading"];
bool& isReloading = cWeapon["IsReloading"];
isReloading = false;
// Ammo
Field<int> magAmmo = cWeapon["MagazineAmmo"];
int& magAmmo = cWeapon["MagazineAmmo"];
if (magAmmo <= 0) {
return;
} else {
@@ -194,16 +194,16 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
if (IsClient) {
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) {
Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"];
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
float viewPunch = cWeapon["ViewPunch"];
float maxTravelAngle = cWeapon["MaxTravelAngle"];
Field<float> currentTravel = cWeapon["CurrentTravel"];
float& currentTravel = cWeapon["CurrentTravel"];
if (currentTravel < maxTravelAngle) {
float change = viewPunch;
if (currentTravel + change > maxTravelAngle) {
change = maxTravelAngle - currentTravel;
}
cameraOrientation.x(cameraOrientation.x() + change);
cameraOrientation.x += 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);
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);
EntityWrapper ray = SpawnerSystem::Spawn(spawner);
((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance / 100.f);
Field<glm::vec3> orientation = ray["Transform"]["Orientation"];
orientation.x(orientation.x() + angles.x);
orientation.y(orientation.y() + angles.y);
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f);
glm::vec3& orientation = ray["Transform"]["Orientation"];
orientation.x += angles.x;
orientation.y += angles.y;
glm::vec3 trajectory = direction * distance;
dealDamage(cWeapon, wi, direction, pelletDamage);
}
@@ -2,7 +2,7 @@
void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{
Field<double> cooldown = cWeapon["FireCooldown"];
double& cooldown = cWeapon["FireCooldown"];
if (cooldown > 0) {
cooldown -= dt;
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);
float distance = traceRayDistance(origin, direction);
EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner);
((Field<glm::vec3>)ray["Transform"]["Scale"]).z(distance / 100.f);
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f);
}
}
bool SidearmWeaponBehaviour::canFire(ComponentWrapper cWeapon)
{
bool triggerHeld = cWeapon["TriggerHeld"];
Field<double> cooldown = cWeapon["FireCooldown"];
double& cooldown = cWeapon["FireCooldown"];
// TODO: Ammo checks
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);
// Change values
((Field<int>)c["TestInteger"]) += 1;
((int&)c["TestInteger"]) += 1;
BOOST_TEST((int)c["TestInteger"] == 1338);
((Field<double>)c["TestDouble"]) += 1.11;
((double&)c["TestDouble"]) += 1.11;
std::cout << (double)c["TestDouble"] << std::endl;
BOOST_TEST((double)c["TestDouble"] == 14.48);
c["TestString"] = "Siesta";
BOOST_TEST((std::string)c["TestString"] == "Siesta");
((Field<glm::vec3>)c["TestVec3"]).y += 1.f;
((glm::vec3&)c["TestVec3"]).y += 1.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
BOOST_CHECK((int)w1_c1["TestInteger"] == (int)w2_c1["TestInteger"]);
BOOST_CHECK(&(Field<int>)w1_c1["TestInteger"] != &(Field<int>)w2_c1["TestInteger"]);
BOOST_CHECK(&(int&)w1_c1["TestInteger"] != &(int&)w2_c1["TestInteger"]);
BOOST_CHECK((double)w1_c1["TestDouble"] == (double)w2_c1["TestDouble"]);
BOOST_CHECK(&(Field<int>)w1_c1["TestDouble"] != &(Field<int>)w2_c1["TestDouble"]);
BOOST_CHECK(&(int&)w1_c1["TestDouble"] != &(int&)w2_c1["TestDouble"]);
BOOST_CHECK((int)w1_c2["TestInteger"] == (int)w2_c2["TestInteger"]);
BOOST_CHECK(&(Field<int>)w1_c2["TestInteger"] != &(Field<int>)w2_c2["TestInteger"]);
BOOST_CHECK(&(int&)w1_c2["TestInteger"] != &(int&)w2_c2["TestInteger"]);
BOOST_CHECK((double)w1_c2["TestDouble"] == (double)w2_c2["TestDouble"]);
BOOST_CHECK(&(Field<int>)w1_c2["TestDouble"] != &(Field<int>)w2_c2["TestDouble"]);
BOOST_CHECK(&(int&)w1_c2["TestDouble"] != &(int&)w2_c2["TestDouble"]);
// Check that specially handled strings are fine
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_c1["TestString"] != &(std::string&)w2_c1["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"]);
BOOST_CHECK(&(std::string&)w1_c2["TestString"] != &(std::string&)w2_c2["TestString"]);
}