Browse Source

Split components into separate files

master
Riyyi 3 years ago
parent
commit
b402506a11
  1. 1
      inferno/src/inferno/application.cpp
  2. 32
      inferno/src/inferno/components/cameracomponent.h
  3. 21
      inferno/src/inferno/components/luascriptcomponent.h
  4. 33
      inferno/src/inferno/components/nativescriptcomponent.h
  5. 19
      inferno/src/inferno/components/spritecomponent.h
  6. 20
      inferno/src/inferno/components/tagcomponent.h
  7. 2
      inferno/src/inferno/components/transformcomponent.cpp
  8. 26
      inferno/src/inferno/components/transformcomponent.h
  9. 2
      inferno/src/inferno/render/renderer.h
  10. 104
      inferno/src/inferno/scene/components.h
  11. 7
      inferno/src/inferno/scene/scene.cpp
  12. 1
      inferno/src/inferno/scene/scene.h
  13. 4
      inferno/src/inferno/script/cameracontroller.cpp
  14. 3
      inferno/src/inferno/script/cameracontroller.h
  15. 5
      inferno/src/inferno/script/luascript.cpp
  16. 7
      inferno/src/inferno/script/registration.cpp
  17. 5
      inferno/src/inferno/systems/camera.h
  18. 3
      inferno/src/inferno/systems/render.cpp
  19. 4
      inferno/src/inferno/systems/script.cpp
  20. 2
      inferno/src/inferno/systems/transform.cpp

1
inferno/src/inferno/application.cpp

@ -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"

32
inferno/src/inferno/components/cameracomponent.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

21
inferno/src/inferno/components/luascriptcomponent.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

33
inferno/src/inferno/components/nativescriptcomponent.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

19
inferno/src/inferno/components/spritecomponent.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

20
inferno/src/inferno/components/tagcomponent.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

2
inferno/src/inferno/scene/components.cpp → inferno/src/inferno/components/transformcomponent.cpp

@ -1,4 +1,4 @@
#include "inferno/scene/components.h"
#include "inferno/components/transformcomponent.h"
namespace Inferno {

26
inferno/src/inferno/components/transformcomponent.h

@ -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

2
inferno/src/inferno/render/renderer.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 {

104
inferno/src/inferno/scene/components.h

@ -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

7
inferno/src/inferno/scene/scene.cpp

@ -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"

1
inferno/src/inferno/scene/scene.h

@ -12,7 +12,6 @@
namespace Inferno {
class Camera;
class Entity;
class Texture;
class Scene {

4
inferno/src/inferno/script/cameracontroller.cpp

@ -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 {

3
inferno/src/inferno/script/cameracontroller.h

@ -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:

5
inferno/src/inferno/script/luascript.cpp

@ -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"

7
inferno/src/inferno/script/registration.cpp

@ -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 {

5
inferno/src/inferno/systems/camera.h

@ -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();

3
inferno/src/inferno/systems/render.cpp

@ -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 {

4
inferno/src/inferno/systems/script.cpp

@ -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"

2
inferno/src/inferno/systems/transform.cpp

@ -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 {

Loading…
Cancel
Save