Created framework for a hardcoded world for TESTING PURPOSES
This commit is contained in:
+3
-3
@@ -3,12 +3,11 @@
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Rendering/DummyRenderer.h"
|
||||
#include "Core/InputManager.h"
|
||||
|
||||
#include "GUI/Frame.h"
|
||||
#include "Core/World.h"
|
||||
|
||||
class Game
|
||||
{
|
||||
@@ -26,6 +25,7 @@ private:
|
||||
IRenderer* m_Renderer;
|
||||
InputManager* m_InputManager;
|
||||
GUI::Frame* m_FrameStack;
|
||||
World* m_World;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
#include <boost/any.hpp>
|
||||
#include "GLM.h"
|
||||
#include "Core/World.h"
|
||||
|
||||
struct any
|
||||
{
|
||||
any() { }
|
||||
|
||||
template <typename T>
|
||||
any(const T& value)
|
||||
{
|
||||
Buffer = std::shared_ptr<char>(new char[sizeof(T)]);
|
||||
memcpy(Buffer.get(), &value, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
any(T&& value)
|
||||
{
|
||||
Buffer = std::shared_ptr<char>(new char[sizeof(T)]);
|
||||
memcpy(Buffer.get(), &value, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
any& operator=(const T& value)
|
||||
{
|
||||
return any(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
any& operator=(T&& value)
|
||||
{
|
||||
return any(value);
|
||||
}
|
||||
|
||||
std::shared_ptr<char> Buffer = nullptr;
|
||||
};
|
||||
|
||||
class HardcodedTestWorld : public World
|
||||
{
|
||||
public:
|
||||
HardcodedTestWorld()
|
||||
: World()
|
||||
{
|
||||
registerTestComponents();
|
||||
createTestEntities();
|
||||
}
|
||||
|
||||
private:
|
||||
void registerTestComponents()
|
||||
{
|
||||
std::unordered_map<std::string, std::list<std::tuple<std::size_t, std::string, any>>> components
|
||||
{
|
||||
{
|
||||
"Test",
|
||||
{
|
||||
std::make_tuple(sizeof(int), "TestInteger", 1337),
|
||||
std::make_tuple(sizeof(float), "TestFloat", 13.37f)
|
||||
}
|
||||
},
|
||||
{
|
||||
"Debug",
|
||||
{
|
||||
std::make_tuple(sizeof(std::string), "Name", std::string("Unnamed")),
|
||||
std::make_tuple(sizeof(glm::vec3), "PickingColor", glm::vec3(0.f))
|
||||
}
|
||||
},
|
||||
{
|
||||
"Transform",
|
||||
{
|
||||
std::make_tuple(sizeof(glm::vec3), "Position", glm::vec3(0.f, 0.f, 0.f)),
|
||||
std::make_tuple(sizeof(glm::quat), "Orientation", glm::quat()),
|
||||
std::make_tuple(sizeof(glm::vec3), "Scale", glm::vec3(1.f, 1.f, 1.f))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (auto& c : components) {
|
||||
ComponentInfo ci;
|
||||
ci.Name = c.first;
|
||||
|
||||
// Fields
|
||||
unsigned int stride = 0;
|
||||
for (auto& f : c.second) {
|
||||
stride += std::get<0>(f);
|
||||
}
|
||||
ci.Meta.Stride = stride;
|
||||
ci.Defaults = std::shared_ptr<char>(new char[stride]);
|
||||
unsigned int offset = 0;
|
||||
for (auto& f : c.second) {
|
||||
std::size_t size;
|
||||
std::string fieldName;
|
||||
any defaultValue;
|
||||
std::tie(size, fieldName, defaultValue) = f;
|
||||
|
||||
ci.FieldOffsets[fieldName] = offset;
|
||||
ci.FieldTypes[fieldName] = "undefined";
|
||||
memcpy(ci.Defaults.get() + offset, defaultValue.Buffer.get(), size);
|
||||
offset += size;
|
||||
}
|
||||
|
||||
RegisterComponent(ci);
|
||||
}
|
||||
}
|
||||
|
||||
void createTestEntities()
|
||||
{
|
||||
EntityID e = CreateEntity();
|
||||
AttachComponent(e, "Test");
|
||||
AttachComponent(e, "Debug");
|
||||
AttachComponent(e, "Transform");
|
||||
ComponentWrapper testComponent = GetComponent(e, "Test");
|
||||
int testValue = testComponent["TestInteger"];
|
||||
float testFloat = testComponent["TestFloat"];
|
||||
ComponentWrapper debugComponent = GetComponent(e, "Debug");
|
||||
std::string name = debugComponent["Name"];
|
||||
glm::vec3 pickingColor = debugComponent["PickingColor"];
|
||||
ComponentWrapper testTransform = GetComponent(e, "Transform");
|
||||
glm::vec3 pos = testTransform["Position"];
|
||||
glm::quat ori = testTransform["Orientation"];
|
||||
glm::vec3 scale = testTransform["Scale"];
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Game.h"
|
||||
#include "HardcodedTestWorld.h"
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
{
|
||||
@@ -30,6 +31,9 @@ Game::Game(int argc, char* argv[])
|
||||
m_FrameStack->Width = m_Renderer->Resolution().Width;
|
||||
m_FrameStack->Height = m_Renderer->Resolution().Height;
|
||||
|
||||
// Create a TEST WORLD
|
||||
m_World = new HardcodedTestWorld();
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user