Split components into separate files
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#include "inferno/render/renderer.h"
|
||||
#include "inferno/render/shader.h"
|
||||
#include "inferno/render/texture.h"
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/scene/scene.h"
|
||||
#include "inferno/settings.h"
|
||||
#include "inferno/time.h"
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef CAMERA_COMPONENT_H
|
||||
#define CAMERA_COMPONENT_H
|
||||
|
||||
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
enum CameraType {
|
||||
Orthographic,
|
||||
Perspective,
|
||||
};
|
||||
|
||||
struct CameraComponent {
|
||||
CameraType type = CameraType::Perspective;
|
||||
|
||||
// Orthographic
|
||||
float zoomLevel = 1.0f;
|
||||
glm::vec3 rotateAxis { 0.0f, 0.0f, 1.0f };
|
||||
|
||||
// Perspective
|
||||
float fov = 90.0f;
|
||||
float pitch = 0.0f;
|
||||
float yaw = -90.0f;
|
||||
glm::vec3 up { 0.0f, 1.0f, 0.0f };
|
||||
|
||||
glm::mat4 projection { 1.0f }; // Identity matrix
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CAMERA_COMPONENT_H
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef LUA_SCRIPT_COMPONENT_H
|
||||
#define LUA_SCRIPT_COMPONENT_H
|
||||
|
||||
#include <string> // std::string
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class LuaScript;
|
||||
|
||||
struct LuaScriptComponent {
|
||||
LuaScript* instance = nullptr;
|
||||
std::string path;
|
||||
|
||||
// Dont allow manually setting instance during construction
|
||||
LuaScriptComponent() {}
|
||||
LuaScriptComponent(const std::string& path)
|
||||
: path(path) {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LUA_SCRIPT_COMPONENT_H
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef NATIVE_SCRIPT_COMPONENT_H
|
||||
#define NATIVE_SCRIPT_COMPONENT_H
|
||||
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/script/nativescript.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct NativeScriptComponent {
|
||||
NativeScript* instance = nullptr;
|
||||
|
||||
NativeScript* (*initialize)();
|
||||
|
||||
// Dont allow manually setting instance during construction
|
||||
NativeScriptComponent() {}
|
||||
|
||||
template<typename T>
|
||||
void bind()
|
||||
{
|
||||
ASSERT(instance == nullptr, "NativeScript already bound");
|
||||
initialize = []() { return static_cast<NativeScript*>(new T()); };
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
ASSERT(instance, "Attempting to destroy an uninitialized NativeScript");
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NATIVE_SCRIPT_COMPONENT_H
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef SPRITE_COMPONENT_H
|
||||
#define SPRITE_COMPONENT_H
|
||||
|
||||
#include <memory> // std::shared_ptr
|
||||
|
||||
#include "glm/ext/vector_float4.hpp" // glm::vec4
|
||||
|
||||
#include "inferno/render/texture.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct SpriteComponent {
|
||||
glm::vec4 color { 1.0f };
|
||||
std::shared_ptr<Texture> texture;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SPRITE_COMPONENT_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef TAG_COMPONENT_H
|
||||
#define TAG_COMPONENT_H
|
||||
|
||||
#include <string> // std::string
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TagComponent {
|
||||
std::string tag;
|
||||
|
||||
TagComponent() = default;
|
||||
TagComponent(const std::string& tag)
|
||||
: tag(tag) {}
|
||||
|
||||
operator const std::string&() const { return tag; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TAG_COMPONENT_H
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef TRANSFORM_COMPONENT_H
|
||||
#define TRANSFORM_COMPONENT_H
|
||||
|
||||
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||
|
||||
#include "inferno/io/log.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TransformComponent {
|
||||
glm::vec3 translate { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 rotate { 0.0f, 0.0f, 0.0f } ;
|
||||
glm::vec3 scale { 1.0f, 1.0f, 1.0f };
|
||||
glm::mat4 transform { 1.0f }; // Identity matrix
|
||||
};
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec3& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec4& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::mat4& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const TransformComponent& value);
|
||||
}
|
||||
|
||||
#endif // TRANSFORM_COMPONENT_H
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||
#include "glm/ext/vector_float4.hpp" // glm::vec4
|
||||
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
#ifndef COMPONENTS_H
|
||||
#define COMPONENTS_H
|
||||
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <string> // std::string
|
||||
#include <functional> // std::function
|
||||
|
||||
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/render/texture.h"
|
||||
#include "inferno/script/nativescript.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class LuaScript;
|
||||
|
||||
struct TagComponent {
|
||||
std::string tag;
|
||||
|
||||
TagComponent() = default;
|
||||
TagComponent(const std::string& tag)
|
||||
: tag(tag) {}
|
||||
|
||||
operator const std::string&() const { return tag; }
|
||||
};
|
||||
|
||||
struct TransformComponent {
|
||||
glm::vec3 translate { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 rotate { 0.0f, 0.0f, 0.0f } ;
|
||||
glm::vec3 scale { 1.0f, 1.0f, 1.0f };
|
||||
glm::mat4 transform { 1.0f }; // Identity matrix
|
||||
};
|
||||
|
||||
enum CameraType {
|
||||
Orthographic,
|
||||
Perspective,
|
||||
};
|
||||
|
||||
struct CameraComponent {
|
||||
CameraType type = CameraType::Perspective;
|
||||
|
||||
// Orthographic
|
||||
float zoomLevel = 1.0f;
|
||||
glm::vec3 rotateAxis { 0.0f, 0.0f, 1.0f };
|
||||
|
||||
// Perspective
|
||||
float fov = 90.0f;
|
||||
float pitch = 0.0f;
|
||||
float yaw = -90.0f;
|
||||
glm::vec3 up { 0.0f, 1.0f, 0.0f };
|
||||
|
||||
glm::mat4 projection { 1.0f }; // Identity matrix
|
||||
};
|
||||
|
||||
struct SpriteComponent {
|
||||
glm::vec4 color { 1.0f };
|
||||
std::shared_ptr<Texture> texture;
|
||||
};
|
||||
|
||||
struct NativeScriptComponent {
|
||||
NativeScript* instance = nullptr;
|
||||
|
||||
NativeScript* (*initialize)();
|
||||
|
||||
// Dont allow manually setting instance during construction
|
||||
NativeScriptComponent() {}
|
||||
|
||||
template<typename T>
|
||||
void bind()
|
||||
{
|
||||
ASSERT(instance == nullptr, "NativeScript already bound");
|
||||
initialize = []() { return static_cast<NativeScript*>(new T()); };
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
ASSERT(instance, "Attempting to destroy an uninitialized NativeScript");
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct LuaScriptComponent {
|
||||
LuaScript* instance = nullptr;
|
||||
std::string path;
|
||||
|
||||
// Dont allow manually setting instance during construction
|
||||
LuaScriptComponent() {}
|
||||
LuaScriptComponent(const std::string& path)
|
||||
: path(path) {}
|
||||
};
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const TransformComponent& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec3& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec4& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::mat4& value);
|
||||
|
||||
}
|
||||
|
||||
#endif // COMPONENTS_H
|
||||
@@ -1,4 +1,9 @@
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/components/cameracomponent.h"
|
||||
#include "inferno/components/luascriptcomponent.h"
|
||||
#include "inferno/components/nativescriptcomponent.h"
|
||||
#include "inferno/components/spritecomponent.h"
|
||||
#include "inferno/components/tagcomponent.h"
|
||||
#include "inferno/scene/scene.h"
|
||||
#include "inferno/script/cameracontroller.h"
|
||||
#include "inferno/script/nativescript.h"
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
namespace Inferno {
|
||||
|
||||
class Camera;
|
||||
class Entity;
|
||||
class Texture;
|
||||
|
||||
class Scene {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "glm/ext/matrix_transform.hpp" // glm::radians
|
||||
|
||||
#include "inferno/keycodes.h"
|
||||
#include "inferno/components/cameracomponent.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
#include "inferno/io/input.h"
|
||||
#include "inferno/keycodes.h"
|
||||
#include "inferno/script/cameracontroller.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
#define NEAR_PLANE 0.1f
|
||||
#define FAR_PLANE 100.0f
|
||||
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/script/nativescript.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct CameraComponent;
|
||||
|
||||
class CameraController final : public NativeScript {
|
||||
public:
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#include "sol/unsafe_function_result.hpp"
|
||||
|
||||
#include "inferno/components/cameracomponent.h"
|
||||
#include "inferno/components/spritecomponent.h"
|
||||
#include "inferno/components/tagcomponent.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
#include "inferno/io/file.h"
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/scene/scene.h"
|
||||
#include "inferno/script/luascript.h"
|
||||
#include "inferno/script/registration.h"
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
#include "glm/ext/vector_float4.hpp" // glm::vec4
|
||||
#include "glm/ext/matrix_transform.hpp" // glm::radians
|
||||
|
||||
#include "inferno/keycodes.h"
|
||||
#include "inferno/components/cameracomponent.h"
|
||||
#include "inferno/components/spritecomponent.h"
|
||||
#include "inferno/components/tagcomponent.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
#include "inferno/io/input.h"
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/keycodes.h"
|
||||
#include "inferno/script/registration.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -12,12 +12,11 @@
|
||||
|
||||
#include "entt/entity/registry.hpp" // entt::entity, entt::registry
|
||||
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/components/cameracomponent.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Entity;
|
||||
|
||||
class CameraSystem {
|
||||
public:
|
||||
void initialize();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "glm/ext/matrix_transform.hpp" // glm::translate, glm::rotate, glm::scale, glm::radians
|
||||
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/components/spritecomponent.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/render/renderer.h"
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/systems/render.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "entt/entity/registry.hpp" // entt::entity, entt::registry
|
||||
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/components/luascriptcomponent.h"
|
||||
#include "inferno/components/nativescriptcomponent.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/scene/scene.h"
|
||||
#include "inferno/script/luascript.h"
|
||||
#include "inferno/script/nativescript.h"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "glm/ext/matrix_transform.hpp" // glm::translate, glm::rotate, glm::scale, glm::radians
|
||||
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/components/transformcomponent.h"
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/scene/components.h"
|
||||
#include "inferno/systems/transform.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
Reference in New Issue
Block a user