Entity properties using boost::any. You'll need Boost now.
This commit is contained in:
@@ -4,15 +4,14 @@
|
||||
#include "Component.h"
|
||||
#include <glm/common.hpp>
|
||||
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Bounds : Component
|
||||
{
|
||||
//Axis Aligned Bounding Box
|
||||
glm::vec3 origin;
|
||||
glm::vec3 volumeVector; //The vector that defines the volume of the BB, it goes from one corner to the opposite one
|
||||
//Axis Aligned Bounding Box
|
||||
glm::vec3 Origin;
|
||||
glm::vec3 VolumeVector; //The vector that defines the volume of the BB, it goes from one corner to the opposite one
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
|
||||
<TargetName>$(ProjectName)-$(Configuration)</TargetName>
|
||||
<IncludePath>$(SolutionDir)\Libraries\SOIL\src;\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(BOOST_ROOT);$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>$(SolutionDir)\Libraries\SOIL\src;\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(BOOST_ROOT);$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LibraryPath>$(SolutionDir)\Libraries\SOIL\lib\Release;$(SolutionDir)\Libraries\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Release;$(LibraryPath)</LibraryPath>
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
#define World_h__
|
||||
|
||||
#include <stack>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <boost/any.hpp>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
#include "Factory.h"
|
||||
@@ -36,6 +39,17 @@ public:
|
||||
|
||||
EntityID GetEntityParent(EntityID entity);
|
||||
|
||||
template <class T>
|
||||
T GetProperty(EntityID entity, std::string property)
|
||||
{
|
||||
return boost::any_cast<T>(m_EntityProperties[entity][property]);
|
||||
}
|
||||
|
||||
void SetProperty(EntityID entity, std::string property, boost::any value)
|
||||
{
|
||||
m_EntityProperties[entity][property] = value;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
|
||||
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
||||
@@ -59,6 +73,8 @@ protected:
|
||||
// A bottom to top tree. A map of child entities to parent entities.
|
||||
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
||||
|
||||
std::unordered_map<EntityID, std::unordered_map<std::string, boost::any>> m_EntityProperties;
|
||||
|
||||
std::unordered_map<std::string, std::vector<std::shared_ptr<Component>>> m_ComponentsOfType;
|
||||
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user