Engine: Run clang-format
This commit is contained in:
+24
-24
@@ -25,8 +25,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
Application::Application(s)
|
||||
{
|
||||
Application::Application(s)
|
||||
{
|
||||
// Initialize
|
||||
|
||||
Settings::initialize();
|
||||
@@ -57,10 +57,10 @@ namespace Inferno {
|
||||
// Gltf model = Gltf("assets/gltf/reciprocatingsaw.glb");
|
||||
|
||||
// Gltf model = Gltf("assets/gltf/triangle-without-indices.gltf");
|
||||
}
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
Application::~Application()
|
||||
{
|
||||
m_scene->destroy();
|
||||
|
||||
FontManager::destroy();
|
||||
@@ -72,10 +72,10 @@ namespace Inferno {
|
||||
// Input::destroy();
|
||||
|
||||
Settings::destroy();
|
||||
}
|
||||
}
|
||||
|
||||
int Application::run()
|
||||
{
|
||||
int Application::run()
|
||||
{
|
||||
dbg() << "Application startup";
|
||||
|
||||
std::array<CharacterVertex, Renderer::vertexPerQuad> character;
|
||||
@@ -159,19 +159,19 @@ namespace Inferno {
|
||||
dbg() << "Application shutdown";
|
||||
|
||||
return m_status;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onEvent(Event& e)
|
||||
{
|
||||
void Application::onEvent(Event& e)
|
||||
{
|
||||
EventDispatcher dispatcher(e);
|
||||
dispatcher.dispatch<WindowCloseEvent>(NF_BIND_EVENT(Application::onWindowClose));
|
||||
dispatcher.dispatch<WindowResizeEvent>(NF_BIND_EVENT(Application::onWindowResize));
|
||||
dispatcher.dispatch<KeyPressEvent>(NF_BIND_EVENT(Application::onKeyPress));
|
||||
dispatcher.dispatch<MousePositionEvent>(NF_BIND_EVENT(Application::onMousePosition));
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::onWindowClose(WindowCloseEvent& e)
|
||||
{
|
||||
bool Application::onWindowClose(WindowCloseEvent& e)
|
||||
{
|
||||
// Suppress unused warning
|
||||
(void)e;
|
||||
|
||||
@@ -181,10 +181,10 @@ namespace Inferno {
|
||||
m_window->setShouldClose(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::onWindowResize(WindowResizeEvent& e)
|
||||
{
|
||||
bool Application::onWindowResize(WindowResizeEvent& e)
|
||||
{
|
||||
// Suppress unused warning
|
||||
(void)e;
|
||||
|
||||
@@ -193,10 +193,10 @@ namespace Inferno {
|
||||
RenderCommand::setViewport(0, 0, e.getWidth(), e.getHeight());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::onKeyPress(KeyPressEvent& e)
|
||||
{
|
||||
bool Application::onKeyPress(KeyPressEvent& e)
|
||||
{
|
||||
// Suppress unused warning
|
||||
(void)e;
|
||||
|
||||
@@ -210,11 +210,11 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::onMousePosition(MousePositionEvent& e)
|
||||
{
|
||||
bool Application::onMousePosition(MousePositionEvent& e)
|
||||
{
|
||||
return Input::onMousePosition(e);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+14
-14
@@ -6,17 +6,17 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Event;
|
||||
class Font;
|
||||
class KeyPressEvent;
|
||||
class MousePositionEvent;
|
||||
class Scene;
|
||||
class Window;
|
||||
class WindowCloseEvent;
|
||||
class WindowResizeEvent;
|
||||
class Event;
|
||||
class Font;
|
||||
class KeyPressEvent;
|
||||
class MousePositionEvent;
|
||||
class Scene;
|
||||
class Window;
|
||||
class WindowCloseEvent;
|
||||
class WindowResizeEvent;
|
||||
|
||||
class Application : public ruc::Singleton<Application> {
|
||||
public:
|
||||
class Application : public ruc::Singleton<Application> {
|
||||
public:
|
||||
Application(s);
|
||||
virtual ~Application();
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Inferno {
|
||||
|
||||
inline Window& getWindow() const { return *m_window; }
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_status { 0 };
|
||||
float m_lastFrameTime { 0.0f };
|
||||
|
||||
@@ -42,10 +42,10 @@ namespace Inferno {
|
||||
//
|
||||
std::shared_ptr<Font> m_font;
|
||||
//
|
||||
};
|
||||
};
|
||||
|
||||
// To be defined in the game
|
||||
extern Application& createApplication();
|
||||
// To be defined in the game
|
||||
extern Application& createApplication();
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ inline void __crash()
|
||||
asm volatile("int $0x03");
|
||||
}
|
||||
|
||||
// FIXME: Doesnt print to stderr
|
||||
#ifdef NF_ENABLE_ASSERTS
|
||||
template<typename... P>
|
||||
inline void __assert_fail(const char* assertion, const char* file, uint32_t line, const char* function, P&&... parameters)
|
||||
{
|
||||
// FIXME: Doesnt print to stderr
|
||||
#ifdef NF_ENABLE_ASSERTS
|
||||
template<typename... P>
|
||||
inline void __assert_fail(const char* assertion, const char* file, uint32_t line, const char* function, P&&... parameters)
|
||||
{
|
||||
(void)function;
|
||||
|
||||
// Get the line that caused the error
|
||||
@@ -105,9 +105,9 @@ inline void __crash()
|
||||
|
||||
fflush(stdout); // FIXME: stdout is buffered, strerr is not so wouldnt need this
|
||||
CRASH();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
// https://github.com/scottt/debugbreak
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
enum CameraType {
|
||||
enum CameraType {
|
||||
Orthographic,
|
||||
Perspective,
|
||||
};
|
||||
};
|
||||
|
||||
struct CameraComponent {
|
||||
struct CameraComponent {
|
||||
CameraType type = CameraType::Perspective;
|
||||
|
||||
// Orthographic
|
||||
@@ -24,6 +24,6 @@ namespace Inferno {
|
||||
glm::vec3 up { 0.0f, 1.0f, 0.0f };
|
||||
|
||||
glm::mat4 projection { 1.0f }; // Identity matrix
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -5,15 +5,17 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class LuaScript;
|
||||
class LuaScript;
|
||||
|
||||
struct LuaScriptComponent {
|
||||
struct LuaScriptComponent {
|
||||
LuaScript* instance { nullptr };
|
||||
std::string path;
|
||||
|
||||
// Dont allow manually setting instance during construction
|
||||
LuaScriptComponent() {}
|
||||
LuaScriptComponent(const std::string& path)
|
||||
: path(std::move(path)) {}
|
||||
};
|
||||
: path(std::move(path))
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct NativeScriptComponent {
|
||||
struct NativeScriptComponent {
|
||||
NativeScript* instance { nullptr };
|
||||
|
||||
NativeScript* (*initialize)();
|
||||
@@ -21,11 +21,12 @@ namespace Inferno {
|
||||
initialize = []() { return static_cast<NativeScript*>(new T()); };
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
void destroy()
|
||||
{
|
||||
VERIFY(instance, "Attempting to destroy an uninitialized NativeScript");
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct SpriteComponent {
|
||||
struct SpriteComponent {
|
||||
glm::vec4 color { 1.0f };
|
||||
std::shared_ptr<Texture> texture;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TagComponent {
|
||||
struct TagComponent {
|
||||
std::string tag;
|
||||
|
||||
TagComponent() = default;
|
||||
TagComponent(const std::string& tag)
|
||||
: tag(std::move(tag)) {}
|
||||
: tag(std::move(tag))
|
||||
{
|
||||
}
|
||||
|
||||
operator const std::string&() const { return tag; }
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TextAreaComponent {
|
||||
struct TextAreaComponent {
|
||||
std::string content { "" };
|
||||
std::string font { "" };
|
||||
uint32_t fontSize { 0 };
|
||||
@@ -18,12 +18,18 @@ namespace Inferno {
|
||||
TextAreaComponent() {}
|
||||
TextAreaComponent(const std::string& content, const std::string& font,
|
||||
uint32_t fontSize, uint32_t width, uint32_t lines)
|
||||
: content(std::move(content)), font(std::move(font)), fontSize(fontSize), width(width), lines(lines) {}
|
||||
: content(std::move(content))
|
||||
, font(std::move(font))
|
||||
, fontSize(fontSize)
|
||||
, width(width)
|
||||
, lines(lines)
|
||||
{
|
||||
}
|
||||
|
||||
// booleans?
|
||||
// glm::vec4 outlineColor { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
// glow?
|
||||
// float dropShadow { 0.0f };
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -2,46 +2,46 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec2& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec2& value)
|
||||
{
|
||||
return stream << "{ "
|
||||
<< (value.x >= 0.0f ? " " : "") << value.x << ", "
|
||||
<< (value.y >= 0.0f ? " " : "") << value.y
|
||||
<< " }";
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec3& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec3& value)
|
||||
{
|
||||
return stream << "{ "
|
||||
<< (value.x >= 0.0f ? " " : "") << value.x << ", "
|
||||
<< (value.y >= 0.0f ? " " : "") << value.y << ", "
|
||||
<< (value.z >= 0.0f ? " " : "") << value.z
|
||||
<< " }";
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec4& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec4& value)
|
||||
{
|
||||
return stream << "{ "
|
||||
<< (value.x >= 0.0f ? " " : "") << value.x << ", "
|
||||
<< (value.y >= 0.0f ? " " : "") << value.y << ", "
|
||||
<< (value.z >= 0.0f ? " " : "") << value.z << ", "
|
||||
<< (value.w >= 0.0f ? " " : "") << value.w
|
||||
<< " }";
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::mat4& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::mat4& value)
|
||||
{
|
||||
return stream << "mat4 "
|
||||
<< value[0] << "\n " << value[1] << "\n "
|
||||
<< value[2] << "\n " << value[3];
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const TransformComponent& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const TransformComponent& value)
|
||||
{
|
||||
return stream << "transform "
|
||||
<< value.translate << " t\n "
|
||||
<< value.rotate << " r\n "
|
||||
<< value.scale << " s";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TransformComponent {
|
||||
struct TransformComponent {
|
||||
glm::vec3 translate { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 rotate { 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::vec2& 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);
|
||||
const LogStream& operator<<(const LogStream& stream, const TransformComponent& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::vec2& 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);
|
||||
const LogStream& operator<<(const LogStream& stream, const TransformComponent& value);
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -6,16 +6,19 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class WindowCloseEvent : public Event {
|
||||
public:
|
||||
class WindowCloseEvent : public Event {
|
||||
public:
|
||||
EVENT_CLASS_TYPE(WindowClose)
|
||||
EVENT_CLASS_CATEGORY(ApplicationEventCategory)
|
||||
};
|
||||
};
|
||||
|
||||
class WindowResizeEvent : public Event {
|
||||
public:
|
||||
WindowResizeEvent(int width, int height) :
|
||||
m_width(width), m_height(height) {}
|
||||
class WindowResizeEvent : public Event {
|
||||
public:
|
||||
WindowResizeEvent(int width, int height)
|
||||
: m_width(width)
|
||||
, m_height(height)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -24,7 +27,7 @@ namespace Inferno {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// -----------------------------------------
|
||||
|
||||
inline int getWidth() const { return m_width; }
|
||||
inline int getHeight() const { return m_height; }
|
||||
@@ -32,8 +35,8 @@ namespace Inferno {
|
||||
EVENT_CLASS_TYPE(WindowResize)
|
||||
EVENT_CLASS_CATEGORY(ApplicationEventCategory)
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_width;
|
||||
int m_height;
|
||||
};
|
||||
};
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -6,24 +6,28 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class JoystickEvent : public Event {
|
||||
public:
|
||||
class JoystickEvent : public Event {
|
||||
public:
|
||||
inline int getID() const { return m_id; }
|
||||
|
||||
EVENT_CLASS_CATEGORY(InputEventCategory | JoystickEventCatergory)
|
||||
|
||||
protected:
|
||||
JoystickEvent(int id) :
|
||||
m_id(id) {}
|
||||
protected:
|
||||
JoystickEvent(int id)
|
||||
: m_id(id)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_id;
|
||||
};
|
||||
};
|
||||
|
||||
class JoystickConnectedEvent : public JoystickEvent {
|
||||
public:
|
||||
JoystickConnectedEvent(int id) :
|
||||
JoystickEvent(id) {}
|
||||
class JoystickConnectedEvent : public JoystickEvent {
|
||||
public:
|
||||
JoystickConnectedEvent(int id)
|
||||
: JoystickEvent(id)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -33,12 +37,14 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(JoystickConnected)
|
||||
};
|
||||
};
|
||||
|
||||
class JoystickDisconnectedEvent : public JoystickEvent {
|
||||
public:
|
||||
JoystickDisconnectedEvent(int id) :
|
||||
JoystickEvent(id) {}
|
||||
class JoystickDisconnectedEvent : public JoystickEvent {
|
||||
public:
|
||||
JoystickDisconnectedEvent(int id)
|
||||
: JoystickEvent(id)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -48,6 +54,6 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(JoystickDisconnected)
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -6,24 +6,28 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class KeyEvent : public Event {
|
||||
public:
|
||||
class KeyEvent : public Event {
|
||||
public:
|
||||
inline int getKey() const { return m_key; }
|
||||
|
||||
EVENT_CLASS_CATEGORY(InputEventCategory | KeyEventCategory)
|
||||
|
||||
protected:
|
||||
KeyEvent(int key) :
|
||||
m_key(key) {}
|
||||
protected:
|
||||
KeyEvent(int key)
|
||||
: m_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_key;
|
||||
};
|
||||
};
|
||||
|
||||
class KeyPressEvent : public KeyEvent {
|
||||
public:
|
||||
KeyPressEvent(int key) :
|
||||
KeyEvent(key) {}
|
||||
class KeyPressEvent : public KeyEvent {
|
||||
public:
|
||||
KeyPressEvent(int key)
|
||||
: KeyEvent(key)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -33,12 +37,14 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(KeyPress)
|
||||
};
|
||||
};
|
||||
|
||||
class KeyReleaseEvent : public KeyEvent {
|
||||
public:
|
||||
KeyReleaseEvent(int key) :
|
||||
KeyEvent(key) {}
|
||||
class KeyReleaseEvent : public KeyEvent {
|
||||
public:
|
||||
KeyReleaseEvent(int key)
|
||||
: KeyEvent(key)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -48,12 +54,14 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(KeyPress)
|
||||
};
|
||||
};
|
||||
|
||||
class KeyRepeatEvent : public KeyEvent {
|
||||
public:
|
||||
KeyRepeatEvent(int key) :
|
||||
KeyEvent(key) {}
|
||||
class KeyRepeatEvent : public KeyEvent {
|
||||
public:
|
||||
KeyRepeatEvent(int key)
|
||||
: KeyEvent(key)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -63,6 +71,6 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(KeyPress)
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -6,24 +6,28 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class MouseButtonEvent : public Event {
|
||||
public:
|
||||
class MouseButtonEvent : public Event {
|
||||
public:
|
||||
inline int getButton() const { return m_button; }
|
||||
|
||||
EVENT_CLASS_CATEGORY(InputEventCategory | MouseEventCategory | MouseButtonEventCategory)
|
||||
|
||||
protected:
|
||||
MouseButtonEvent(int button) :
|
||||
m_button(button) {}
|
||||
protected:
|
||||
MouseButtonEvent(int button)
|
||||
: m_button(button)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_button;
|
||||
};
|
||||
};
|
||||
|
||||
class MouseButtonPressEvent : public MouseButtonEvent {
|
||||
public:
|
||||
MouseButtonPressEvent(int button) :
|
||||
MouseButtonEvent(button) {}
|
||||
class MouseButtonPressEvent : public MouseButtonEvent {
|
||||
public:
|
||||
MouseButtonPressEvent(int button)
|
||||
: MouseButtonEvent(button)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -33,12 +37,14 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(MouseButtonPress)
|
||||
};
|
||||
};
|
||||
|
||||
class MouseButtonReleaseEvent : public MouseButtonEvent {
|
||||
public:
|
||||
MouseButtonReleaseEvent(int button) :
|
||||
MouseButtonEvent(button) {}
|
||||
class MouseButtonReleaseEvent : public MouseButtonEvent {
|
||||
public:
|
||||
MouseButtonReleaseEvent(int button)
|
||||
: MouseButtonEvent(button)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -48,12 +54,15 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
EVENT_CLASS_TYPE(MouseButtonRelease)
|
||||
};
|
||||
};
|
||||
|
||||
class MousePositionEvent : public Event {
|
||||
public:
|
||||
MousePositionEvent(float xPos, float yPos) :
|
||||
m_xPos(xPos), m_yPos(yPos) {}
|
||||
class MousePositionEvent : public Event {
|
||||
public:
|
||||
MousePositionEvent(float xPos, float yPos)
|
||||
: m_xPos(xPos)
|
||||
, m_yPos(yPos)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -62,7 +71,7 @@ namespace Inferno {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// -----------------------------------------
|
||||
|
||||
inline float getXPos() const { return m_xPos; }
|
||||
inline float getYPos() const { return m_yPos; }
|
||||
@@ -70,15 +79,18 @@ namespace Inferno {
|
||||
EVENT_CLASS_TYPE(MousePosition)
|
||||
EVENT_CLASS_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||
|
||||
private:
|
||||
private:
|
||||
float m_xPos;
|
||||
float m_yPos;
|
||||
};
|
||||
};
|
||||
|
||||
class MouseScrollEvent : public Event {
|
||||
public:
|
||||
MouseScrollEvent(float xOffset, float yOffset) :
|
||||
m_xOffset(xOffset), m_yOffset(yOffset) {}
|
||||
class MouseScrollEvent : public Event {
|
||||
public:
|
||||
MouseScrollEvent(float xOffset, float yOffset)
|
||||
: m_xOffset(xOffset)
|
||||
, m_yOffset(yOffset)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
@@ -87,7 +99,7 @@ namespace Inferno {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
// -----------------------------------------
|
||||
|
||||
inline float getXOffset() const { return m_xOffset; }
|
||||
inline float getYOffset() const { return m_yOffset; }
|
||||
@@ -95,9 +107,9 @@ namespace Inferno {
|
||||
EVENT_CLASS_TYPE(MouseScroll)
|
||||
EVENT_CLASS_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||
|
||||
private:
|
||||
private:
|
||||
float m_xOffset;
|
||||
float m_yOffset;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
std::shared_ptr<char[]> File::raw(const std::string& path)
|
||||
{
|
||||
std::shared_ptr<char[]> File::raw(const std::string& path)
|
||||
{
|
||||
// Create input stream object and open file
|
||||
std::ifstream file(path);
|
||||
VERIFY(file.is_open(), "File could not open '{}'", path);
|
||||
@@ -27,22 +27,22 @@ namespace Inferno {
|
||||
buffer[length] = '\0';
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
std::string File::read(const std::string &path)
|
||||
{
|
||||
std::string File::read(const std::string& path)
|
||||
{
|
||||
// Create string from the buffer and return
|
||||
return std::string(raw(path).get());
|
||||
}
|
||||
}
|
||||
|
||||
int32_t File::length(const std::string& path, std::ifstream& file)
|
||||
{
|
||||
int32_t File::length(const std::string& path, std::ifstream& file)
|
||||
{
|
||||
file.seekg(0, std::ios::end);
|
||||
int32_t length = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
VERIFY(length != -1, "File could not determine length '{}'", path);
|
||||
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class File {
|
||||
public:
|
||||
class File {
|
||||
public:
|
||||
static std::shared_ptr<char[]> raw(const std::string& path);
|
||||
static std::string read(const std::string& path);
|
||||
static int32_t length(const std::string& path, std::ifstream& file);
|
||||
@@ -40,7 +40,7 @@ namespace Inferno {
|
||||
template<typename T>
|
||||
static bool ioWrite(T* t, const std::string& path)
|
||||
{
|
||||
std::ofstream file (path);
|
||||
std::ofstream file(path);
|
||||
VERIFY(file.is_open(), "File could not open! {}", path);
|
||||
|
||||
if (!file.is_open()) {
|
||||
@@ -49,7 +49,7 @@ namespace Inferno {
|
||||
|
||||
try {
|
||||
// Write file with single tabs, nicely formatted
|
||||
file << std::setfill ('\t') << std::setw(1) << *t << std::endl;
|
||||
file << std::setfill('\t') << std::setw(1) << *t << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
return false;
|
||||
@@ -57,6 +57,6 @@ namespace Inferno {
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> GltfFile::read(const std::string& path)
|
||||
{
|
||||
std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> GltfFile::read(const std::string& path)
|
||||
{
|
||||
std::string extension = path.substr(path.find_first_of("."));
|
||||
|
||||
if (extension.compare(".glb") == 0) {
|
||||
@@ -25,10 +25,10 @@ namespace Inferno {
|
||||
|
||||
VERIFY(false, "GltfFile unknown file extension!");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> GltfFile::glb(const std::string& path)
|
||||
{
|
||||
std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> GltfFile::glb(const std::string& path)
|
||||
{
|
||||
// Create input stream object and open file
|
||||
std::ifstream glb(path, std::ios::in | std::ios::binary);
|
||||
VERIFY(glb.is_open(), "GltfFile could not open '{}'", path);
|
||||
@@ -74,10 +74,10 @@ namespace Inferno {
|
||||
glb.close();
|
||||
|
||||
return { jsonChunk.first, binaryChunk.first };
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<std::shared_ptr<char[]>, uint32_t> GltfFile::readChunk(std::ifstream& ifstream, uint32_t offset, uint32_t type)
|
||||
{
|
||||
std::pair<std::shared_ptr<char[]>, uint32_t> GltfFile::readChunk(std::ifstream& ifstream, uint32_t offset, uint32_t type)
|
||||
{
|
||||
constexpr uint32_t size = 4;
|
||||
|
||||
char chunkLength[size];
|
||||
@@ -99,6 +99,6 @@ namespace Inferno {
|
||||
chunkData.get()[chunkLengthInt] = '\0';
|
||||
|
||||
return { chunkData, chunkLengthInt };
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class GltfFile {
|
||||
public:
|
||||
class GltfFile {
|
||||
public:
|
||||
static std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> read(const std::string& path);
|
||||
|
||||
private:
|
||||
private:
|
||||
static std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> glb(const std::string& path);
|
||||
static std::pair<std::shared_ptr<char[]>, uint32_t> readChunk(std::ifstream& ifstream, uint32_t offset, uint32_t type);
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+45
-45
@@ -8,32 +8,32 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
bool Input::m_firstMousePos = true;
|
||||
float Input::m_xPosLast = 0.0f;
|
||||
float Input::m_yPosLast = 0.0f;
|
||||
float Input::m_xOffset = 0.0f;
|
||||
float Input::m_yOffset = 0.0f;
|
||||
bool Input::m_firstMousePos = true;
|
||||
float Input::m_xPosLast = 0.0f;
|
||||
float Input::m_yPosLast = 0.0f;
|
||||
float Input::m_xOffset = 0.0f;
|
||||
float Input::m_yOffset = 0.0f;
|
||||
|
||||
void Input::initialize()
|
||||
{
|
||||
void Input::initialize()
|
||||
{
|
||||
// Set cursor in the middle of the screen
|
||||
m_xPosLast = Application::the().getWindow().getWidth() / 2.0f;
|
||||
m_yPosLast = Application::the().getWindow().getHeight() / 2.0f;
|
||||
|
||||
info() << "Input initialized";
|
||||
}
|
||||
}
|
||||
|
||||
void Input::update()
|
||||
{
|
||||
void Input::update()
|
||||
{
|
||||
// Stop infinite mouse movement
|
||||
m_xOffset = 0.0f;
|
||||
m_yOffset = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
bool Input::onMousePosition(MousePositionEvent& e)
|
||||
{
|
||||
bool Input::onMousePosition(MousePositionEvent& e)
|
||||
{
|
||||
// Prevent weird jump on first cursor window enter
|
||||
if(m_firstMousePos) {
|
||||
if (m_firstMousePos) {
|
||||
m_firstMousePos = false;
|
||||
m_xPosLast = e.getXPos();
|
||||
m_yPosLast = e.getYPos();
|
||||
@@ -46,47 +46,47 @@ namespace Inferno {
|
||||
m_yPosLast = e.getYPos();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Input::isKeyPressed(int key)
|
||||
{
|
||||
bool Input::isKeyPressed(int key)
|
||||
{
|
||||
GLFWwindow* w = Application::the().getWindow().getWindow();
|
||||
return glfwGetKey(w, key) == GLFW_PRESS;
|
||||
}
|
||||
}
|
||||
|
||||
bool Input::isMouseButtonPressed(int button)
|
||||
{
|
||||
bool Input::isMouseButtonPressed(int button)
|
||||
{
|
||||
GLFWwindow* w = Application::the().getWindow().getWindow();
|
||||
return glfwGetMouseButton(w, button) == GLFW_PRESS;
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<float, float> Input::getMousePosition()
|
||||
{
|
||||
std::pair<float, float> Input::getMousePosition()
|
||||
{
|
||||
GLFWwindow* w = Application::the().getWindow().getWindow();
|
||||
double xPos;
|
||||
double yPos;
|
||||
glfwGetCursorPos(w, &xPos, &yPos);
|
||||
return { (float)xPos, (float)yPos };
|
||||
}
|
||||
|
||||
float Input::getMouseX()
|
||||
{
|
||||
return getMousePosition().first;
|
||||
}
|
||||
|
||||
float Input::getMouseY()
|
||||
{
|
||||
return getMousePosition().second;
|
||||
}
|
||||
|
||||
const char* Input::getKeyName(int key)
|
||||
{
|
||||
return glfwGetKeyName(key, getKeyScancode(key));
|
||||
}
|
||||
|
||||
int Input::getKeyScancode(int key)
|
||||
{
|
||||
return glfwGetKeyScancode(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float Input::getMouseX()
|
||||
{
|
||||
return getMousePosition().first;
|
||||
}
|
||||
|
||||
float Input::getMouseY()
|
||||
{
|
||||
return getMousePosition().second;
|
||||
}
|
||||
|
||||
const char* Input::getKeyName(int key)
|
||||
{
|
||||
return glfwGetKeyName(key, getKeyScancode(key));
|
||||
}
|
||||
|
||||
int Input::getKeyScancode(int key)
|
||||
{
|
||||
return glfwGetKeyScancode(key);
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class MousePositionEvent;
|
||||
class MousePositionEvent;
|
||||
|
||||
class Input {
|
||||
public:
|
||||
class Input {
|
||||
public:
|
||||
static void initialize();
|
||||
static void update();
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace Inferno {
|
||||
static inline float getXOffset() { return m_xOffset; }
|
||||
static inline float getYOffset() { return m_yOffset; }
|
||||
|
||||
private:
|
||||
private:
|
||||
static bool m_firstMousePos;
|
||||
static float m_xPosLast;
|
||||
static float m_yPosLast;
|
||||
static float m_xOffset;
|
||||
static float m_yOffset;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+112
-112
@@ -11,16 +11,16 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
BufferedLogStream::~BufferedLogStream()
|
||||
{
|
||||
BufferedLogStream::~BufferedLogStream()
|
||||
{
|
||||
// Free buffer memory
|
||||
if (m_capacity > sizeof(m_buffer.stack)) {
|
||||
free(m_buffer.heap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BufferedLogStream::grow(size_t bytes) const
|
||||
{
|
||||
void BufferedLogStream::grow(size_t bytes) const
|
||||
{
|
||||
// Bitwise & ~ example, we use 127 as binary starts at 0
|
||||
// 0b001111111 127 ~
|
||||
// 0b100000100 260 &
|
||||
@@ -47,12 +47,12 @@ namespace Inferno {
|
||||
|
||||
m_buffer.heap = newBuffer;
|
||||
m_capacity = newCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
DebugLogStream::~DebugLogStream()
|
||||
{
|
||||
DebugLogStream::~DebugLogStream()
|
||||
{
|
||||
if (m_type != Log::None) {
|
||||
const char* clear = "\033[0m";
|
||||
write(clear, strlen(clear));
|
||||
@@ -64,10 +64,10 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
fwrite(buffer(), 1, count(), stdout);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugLogStream::color() const
|
||||
{
|
||||
void DebugLogStream::color() const
|
||||
{
|
||||
const char* color = "";
|
||||
|
||||
if (m_type == Log::Info) {
|
||||
@@ -87,21 +87,21 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
write(color, strlen(color));
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
StringLogStream::~StringLogStream()
|
||||
{
|
||||
StringLogStream::~StringLogStream()
|
||||
{
|
||||
char terminator = '\0';
|
||||
write(&terminator, 1);
|
||||
*m_fill = std::string(reinterpret_cast<char*>(buffer()));
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const char* value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const char* value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
stream.write("(null)", 6);
|
||||
return stream;
|
||||
@@ -109,10 +109,10 @@ namespace Inferno {
|
||||
|
||||
stream.write(value, strlen(value));
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const unsigned char* value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const unsigned char* value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
stream.write("(null)", 6);
|
||||
return stream;
|
||||
@@ -120,104 +120,104 @@ namespace Inferno {
|
||||
|
||||
stream.write(value, strlen((const char*)value));
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string& value)
|
||||
{
|
||||
stream.write(value.c_str(), value.length());
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string_view& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string_view& value)
|
||||
{
|
||||
stream.write(value.data(), value.length());
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, char value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, char value)
|
||||
{
|
||||
stream.write(&value, 1);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned char value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned char value)
|
||||
{
|
||||
stream.write(&value, 1);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, int value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, int value)
|
||||
{
|
||||
// return stream << std::to_string(value);
|
||||
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%d", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, long int value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, long int value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%ld", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, long long int value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, long long int value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%lld", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned int value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned int value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%u", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, long unsigned int value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, long unsigned int value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%lu", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, long long unsigned int value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, long long unsigned int value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%llu", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, double value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, double value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%.4f", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, float value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, float value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%.4f", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const void* value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const void* value)
|
||||
{
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%p", value);
|
||||
return stream << buffer;
|
||||
}
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, bool value)
|
||||
{
|
||||
return stream << (value ? "true": "false");
|
||||
}
|
||||
const LogStream& operator<<(const LogStream& stream, bool value)
|
||||
{
|
||||
return stream << (value ? "true" : "false");
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, Log value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, Log value)
|
||||
{
|
||||
switch (value) {
|
||||
case Log::None:
|
||||
return stream << "Log";
|
||||
@@ -235,87 +235,87 @@ namespace Inferno {
|
||||
VERIFY_NOT_REACHED();
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
DebugLogStream dbg()
|
||||
{
|
||||
DebugLogStream dbg()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream dbg(bool newline)
|
||||
{
|
||||
DebugLogStream dbg(bool newline)
|
||||
{
|
||||
return DebugLogStream(newline);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream info()
|
||||
{
|
||||
DebugLogStream info()
|
||||
{
|
||||
return DebugLogStream(Log::Info);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream warn()
|
||||
{
|
||||
DebugLogStream warn()
|
||||
{
|
||||
return DebugLogStream(Log::Warn);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream danger()
|
||||
{
|
||||
DebugLogStream danger()
|
||||
{
|
||||
return DebugLogStream(Log::Danger);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream success()
|
||||
{
|
||||
DebugLogStream success()
|
||||
{
|
||||
return DebugLogStream(Log::Success);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream comment()
|
||||
{
|
||||
DebugLogStream comment()
|
||||
{
|
||||
return DebugLogStream(Log::Comment);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream info(bool newline)
|
||||
{
|
||||
DebugLogStream info(bool newline)
|
||||
{
|
||||
return DebugLogStream(Log::Info, newline);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream warn(bool newline)
|
||||
{
|
||||
DebugLogStream warn(bool newline)
|
||||
{
|
||||
return DebugLogStream(Log::Warn, newline);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream danger(bool newline)
|
||||
{
|
||||
DebugLogStream danger(bool newline)
|
||||
{
|
||||
return DebugLogStream(Log::Danger, newline);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream success(bool newline)
|
||||
{
|
||||
DebugLogStream success(bool newline)
|
||||
{
|
||||
return DebugLogStream(Log::Success, newline);
|
||||
}
|
||||
}
|
||||
|
||||
DebugLogStream comment(bool newline)
|
||||
{
|
||||
DebugLogStream comment(bool newline)
|
||||
{
|
||||
return DebugLogStream(Log::Comment, newline);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void dbgln(Log type, bool newline)
|
||||
{
|
||||
void dbgln(Log type, bool newline)
|
||||
{
|
||||
(void)type, DebugLogStream(newline);
|
||||
}
|
||||
}
|
||||
|
||||
void dbgln(Log type, bool newline, const char* format)
|
||||
{
|
||||
void dbgln(Log type, bool newline, const char* format)
|
||||
{
|
||||
DebugLogStream(type, newline) << format;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
StringLogStream str(std::string* fill)
|
||||
{
|
||||
StringLogStream str(std::string* fill)
|
||||
{
|
||||
return StringLogStream(fill);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+80
-64
@@ -10,30 +10,30 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
enum class Log {
|
||||
enum class Log {
|
||||
None,
|
||||
Info,
|
||||
Warn,
|
||||
Danger,
|
||||
Success,
|
||||
Comment,
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
class LogStream {
|
||||
public:
|
||||
class LogStream {
|
||||
public:
|
||||
LogStream() {}
|
||||
virtual ~LogStream() {}
|
||||
|
||||
virtual void write(const char* characters, int length) const = 0;
|
||||
virtual void write(const unsigned char* characters, int length) const = 0;
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
class BufferedLogStream : public LogStream {
|
||||
public:
|
||||
class BufferedLogStream : public LogStream {
|
||||
public:
|
||||
BufferedLogStream() {}
|
||||
virtual ~BufferedLogStream();
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Inferno {
|
||||
m_count = newSize;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
inline unsigned char* buffer() const
|
||||
{
|
||||
if (m_capacity <= sizeof(m_buffer.stack)) {
|
||||
@@ -69,7 +69,7 @@ namespace Inferno {
|
||||
inline bool empty() const { return m_count == 0; }
|
||||
inline size_t count() const { return m_count; }
|
||||
|
||||
private:
|
||||
private:
|
||||
void grow(size_t bytes) const;
|
||||
|
||||
mutable size_t m_count { 0 };
|
||||
@@ -78,80 +78,96 @@ namespace Inferno {
|
||||
mutable unsigned char* heap { nullptr };
|
||||
mutable unsigned char stack[BUFFER_SIZE];
|
||||
} m_buffer;
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
class DebugLogStream final : public BufferedLogStream {
|
||||
public:
|
||||
class DebugLogStream final : public BufferedLogStream {
|
||||
public:
|
||||
DebugLogStream()
|
||||
: m_newline(true), m_type(Log::None) {}
|
||||
: m_newline(true)
|
||||
, m_type(Log::None)
|
||||
{
|
||||
}
|
||||
DebugLogStream(bool newline)
|
||||
: m_newline(newline), m_type(Log::None) {}
|
||||
: m_newline(newline)
|
||||
, m_type(Log::None)
|
||||
{
|
||||
}
|
||||
DebugLogStream(Log type)
|
||||
: m_newline(true), m_type(type) { color(); }
|
||||
: m_newline(true)
|
||||
, m_type(type)
|
||||
{
|
||||
color();
|
||||
}
|
||||
DebugLogStream(Log type, bool newline)
|
||||
: m_newline(newline), m_type(type) { color(); }
|
||||
: m_newline(newline)
|
||||
, m_type(type)
|
||||
{
|
||||
color();
|
||||
}
|
||||
virtual ~DebugLogStream() override;
|
||||
|
||||
void color() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
bool m_newline;
|
||||
Log m_type;
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
class StringLogStream final : public BufferedLogStream {
|
||||
public:
|
||||
class StringLogStream final : public BufferedLogStream {
|
||||
public:
|
||||
StringLogStream(std::string* fill)
|
||||
: m_fill(fill) {}
|
||||
: m_fill(fill)
|
||||
{
|
||||
}
|
||||
virtual ~StringLogStream() override;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string* m_fill { nullptr };
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const char* value);
|
||||
const LogStream& operator<<(const LogStream& stream, const unsigned char* value);
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string_view& value);
|
||||
const LogStream& operator<<(const LogStream& stream, char value);
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned char value);
|
||||
const LogStream& operator<<(const LogStream& stream, int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long long int value);
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long unsigned int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long long unsigned int value);
|
||||
const LogStream& operator<<(const LogStream& stream, double value);
|
||||
const LogStream& operator<<(const LogStream& stream, float value);
|
||||
const LogStream& operator<<(const LogStream& stream, const void* value);
|
||||
const LogStream& operator<<(const LogStream& stream, bool value);
|
||||
const LogStream& operator<<(const LogStream& stream, Log value);
|
||||
const LogStream& operator<<(const LogStream& stream, const char* value);
|
||||
const LogStream& operator<<(const LogStream& stream, const unsigned char* value);
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const std::string_view& value);
|
||||
const LogStream& operator<<(const LogStream& stream, char value);
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned char value);
|
||||
const LogStream& operator<<(const LogStream& stream, int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long long int value);
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long unsigned int value);
|
||||
const LogStream& operator<<(const LogStream& stream, long long unsigned int value);
|
||||
const LogStream& operator<<(const LogStream& stream, double value);
|
||||
const LogStream& operator<<(const LogStream& stream, float value);
|
||||
const LogStream& operator<<(const LogStream& stream, const void* value);
|
||||
const LogStream& operator<<(const LogStream& stream, bool value);
|
||||
const LogStream& operator<<(const LogStream& stream, Log value);
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
DebugLogStream dbg();
|
||||
DebugLogStream info();
|
||||
DebugLogStream warn();
|
||||
DebugLogStream danger();
|
||||
DebugLogStream success();
|
||||
DebugLogStream comment();
|
||||
DebugLogStream dbg();
|
||||
DebugLogStream info();
|
||||
DebugLogStream warn();
|
||||
DebugLogStream danger();
|
||||
DebugLogStream success();
|
||||
DebugLogStream comment();
|
||||
|
||||
DebugLogStream dbg(bool newline);
|
||||
DebugLogStream info(bool newline);
|
||||
DebugLogStream warn(bool newline);
|
||||
DebugLogStream danger(bool newline);
|
||||
DebugLogStream success(bool newline);
|
||||
DebugLogStream comment(bool newline);
|
||||
DebugLogStream dbg(bool newline);
|
||||
DebugLogStream info(bool newline);
|
||||
DebugLogStream warn(bool newline);
|
||||
DebugLogStream danger(bool newline);
|
||||
DebugLogStream success(bool newline);
|
||||
DebugLogStream comment(bool newline);
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
template<typename... P> void dbgln(const char* format, P&&... parameters) { dbgln(Log::None, true, format, std::forward<P>(parameters)...); }
|
||||
template<typename... P> void infoln(const char* format, P&&... parameters) { dbgln(Log::Info, true, format, std::forward<P>(parameters)...); }
|
||||
template<typename... P> void warnln(const char* format, P&&... parameters) { dbgln(Log::Warn, true, format, std::forward<P>(parameters)...); }
|
||||
@@ -193,20 +209,20 @@ namespace Inferno {
|
||||
template<typename... P> void dangerln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Danger, newline, format.data(), std::forward<P>(parameters)...); }
|
||||
template<typename... P> void successln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Success, newline, format.data(), std::forward<P>(parameters)...); }
|
||||
template<typename... P> void commentln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Comment, newline, format.data(), std::forward<P>(parameters)...); }
|
||||
// clang-format on
|
||||
// clang-format on
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void dbgln(Log type, bool newline);
|
||||
void dbgln(Log type, bool newline, const char* format);
|
||||
void dbgln(Log type, bool newline);
|
||||
void dbgln(Log type, bool newline, const char* format);
|
||||
|
||||
// https://en.cppreference.com/w/cpp/language/parameter_pack#Example
|
||||
template<typename T, typename... P>
|
||||
void dbgln(Log type, bool newline, const char* format, T value, P&&... parameters)
|
||||
{
|
||||
// https://en.cppreference.com/w/cpp/language/parameter_pack#Example
|
||||
template<typename T, typename... P>
|
||||
void dbgln(Log type, bool newline, const char* format, T value, P&&... parameters)
|
||||
{
|
||||
std::string_view view { format };
|
||||
|
||||
for(uint32_t i = 0; format[i] != '\0'; i++) {
|
||||
for (uint32_t i = 0; format[i] != '\0'; i++) {
|
||||
|
||||
if (format[i] == '{' && format[i + 1] == '}') {
|
||||
DebugLogStream(type, false) << view.substr(0, i) << value;
|
||||
@@ -214,11 +230,11 @@ namespace Inferno {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// possible c++17 improvent https://riptutorial.com/cplusplus/example/3208/iterating-over-a-parameter-pack
|
||||
}
|
||||
// possible c++17 improvent https://riptutorial.com/cplusplus/example/3208/iterating-over-a-parameter-pack
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
StringLogStream str(std::string* fill);
|
||||
StringLogStream str(std::string* fill);
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
static std::unordered_map<std::string, int> keys ({
|
||||
static std::unordered_map<std::string, int> keys({
|
||||
{ MAP_KEY(GLFW_KEY_UNKNOWN) },
|
||||
{ MAP_KEY(GLFW_KEY_SPACE) },
|
||||
{ MAP_KEY(GLFW_KEY_APOSTROPHE) },
|
||||
@@ -130,14 +130,14 @@ namespace Inferno {
|
||||
{ MAP_KEY(GLFW_KEY_RIGHT_ALT) },
|
||||
{ MAP_KEY(GLFW_KEY_RIGHT_SUPER) },
|
||||
{ MAP_KEY(GLFW_KEY_MENU) },
|
||||
});
|
||||
});
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
int keyCode(const char* name)
|
||||
{
|
||||
int keyCode(const char* name)
|
||||
{
|
||||
VERIFY(keys.find(name) != keys.end(), "keyCode could not find '{}'", name);
|
||||
return keys.at(name);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
int keyCode(const char* name);
|
||||
int keyCode(const char* name);
|
||||
|
||||
}
|
||||
|
||||
+243
-162
@@ -1,166 +1,247 @@
|
||||
#include "glad/glad.h"
|
||||
|
||||
#include "ruc/meta/assert.h"
|
||||
#include "inferno/core.h"
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/render/buffer.h"
|
||||
#include "ruc/meta/assert.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
BufferElement::BufferElement(BufferElementType type, std::string name, bool normalized) :
|
||||
m_type(type),
|
||||
m_name(name),
|
||||
m_size(BufferElement::getTypeSize(type)),
|
||||
m_normalized(normalized)
|
||||
{
|
||||
}
|
||||
BufferElement::BufferElement(BufferElementType type, std::string name, bool normalized)
|
||||
: m_type(type)
|
||||
, m_name(name)
|
||||
, m_size(BufferElement::getTypeSize(type))
|
||||
, m_normalized(normalized)
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t BufferElement::getTypeSize() const
|
||||
{
|
||||
uint32_t BufferElement::getTypeSize() const
|
||||
{
|
||||
return BufferElement::getTypeSize(m_type);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t BufferElement::getTypeCount() const
|
||||
{
|
||||
uint32_t BufferElement::getTypeCount() const
|
||||
{
|
||||
return BufferElement::getTypeCount(m_type);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t BufferElement::getTypeGL() const
|
||||
{
|
||||
uint32_t BufferElement::getTypeGL() const
|
||||
{
|
||||
return BufferElement::getTypeGL(m_type);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t BufferElement::getTypeSize(const BufferElementType type)
|
||||
{
|
||||
uint32_t BufferElement::getTypeSize(const BufferElementType type)
|
||||
{
|
||||
switch (type) {
|
||||
case BufferElementType::None: return 0;
|
||||
case BufferElementType::Bool: return sizeof(bool);
|
||||
case BufferElementType::Bool2: return sizeof(bool) * 2;
|
||||
case BufferElementType::Bool3: return sizeof(bool) * 3;
|
||||
case BufferElementType::Bool4: return sizeof(bool) * 4;
|
||||
case BufferElementType::Int: return sizeof(int32_t);
|
||||
case BufferElementType::Int2: return sizeof(int32_t) * 2;
|
||||
case BufferElementType::Int3: return sizeof(int32_t) * 3;
|
||||
case BufferElementType::Int4: return sizeof(int32_t) * 4;
|
||||
case BufferElementType::Uint: return sizeof(uint32_t);
|
||||
case BufferElementType::Uint2: return sizeof(uint32_t) * 2;
|
||||
case BufferElementType::Uint3: return sizeof(uint32_t) * 3;
|
||||
case BufferElementType::Uint4: return sizeof(uint32_t) * 4;
|
||||
case BufferElementType::Float: return sizeof(float);
|
||||
case BufferElementType::Vec2: return sizeof(float) * 2;
|
||||
case BufferElementType::Vec3: return sizeof(float) * 3;
|
||||
case BufferElementType::Vec4: return sizeof(float) * 4;
|
||||
case BufferElementType::Double: return sizeof(double);
|
||||
case BufferElementType::Double2: return sizeof(double);
|
||||
case BufferElementType::Double3: return sizeof(double);
|
||||
case BufferElementType::Double4: return sizeof(double);
|
||||
case BufferElementType::Mat2: return sizeof(float) * 2 * 2;
|
||||
case BufferElementType::Mat3: return sizeof(float) * 3 * 3;
|
||||
case BufferElementType::Mat4: return sizeof(float) * 4 * 4;
|
||||
case BufferElementType::DoubleMat2: return sizeof(double) * 2 * 2;
|
||||
case BufferElementType::DoubleMat3: return sizeof(double) * 3 * 3;
|
||||
case BufferElementType::DoubleMat4: return sizeof(double) * 4 * 4;
|
||||
case BufferElementType::None:
|
||||
return 0;
|
||||
case BufferElementType::Bool:
|
||||
return sizeof(bool);
|
||||
case BufferElementType::Bool2:
|
||||
return sizeof(bool) * 2;
|
||||
case BufferElementType::Bool3:
|
||||
return sizeof(bool) * 3;
|
||||
case BufferElementType::Bool4:
|
||||
return sizeof(bool) * 4;
|
||||
case BufferElementType::Int:
|
||||
return sizeof(int32_t);
|
||||
case BufferElementType::Int2:
|
||||
return sizeof(int32_t) * 2;
|
||||
case BufferElementType::Int3:
|
||||
return sizeof(int32_t) * 3;
|
||||
case BufferElementType::Int4:
|
||||
return sizeof(int32_t) * 4;
|
||||
case BufferElementType::Uint:
|
||||
return sizeof(uint32_t);
|
||||
case BufferElementType::Uint2:
|
||||
return sizeof(uint32_t) * 2;
|
||||
case BufferElementType::Uint3:
|
||||
return sizeof(uint32_t) * 3;
|
||||
case BufferElementType::Uint4:
|
||||
return sizeof(uint32_t) * 4;
|
||||
case BufferElementType::Float:
|
||||
return sizeof(float);
|
||||
case BufferElementType::Vec2:
|
||||
return sizeof(float) * 2;
|
||||
case BufferElementType::Vec3:
|
||||
return sizeof(float) * 3;
|
||||
case BufferElementType::Vec4:
|
||||
return sizeof(float) * 4;
|
||||
case BufferElementType::Double:
|
||||
return sizeof(double);
|
||||
case BufferElementType::Double2:
|
||||
return sizeof(double);
|
||||
case BufferElementType::Double3:
|
||||
return sizeof(double);
|
||||
case BufferElementType::Double4:
|
||||
return sizeof(double);
|
||||
case BufferElementType::Mat2:
|
||||
return sizeof(float) * 2 * 2;
|
||||
case BufferElementType::Mat3:
|
||||
return sizeof(float) * 3 * 3;
|
||||
case BufferElementType::Mat4:
|
||||
return sizeof(float) * 4 * 4;
|
||||
case BufferElementType::DoubleMat2:
|
||||
return sizeof(double) * 2 * 2;
|
||||
case BufferElementType::DoubleMat3:
|
||||
return sizeof(double) * 3 * 3;
|
||||
case BufferElementType::DoubleMat4:
|
||||
return sizeof(double) * 4 * 4;
|
||||
};
|
||||
|
||||
VERIFY(false, "BufferElement unknown BufferElementType size!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t BufferElement::getTypeCount(const BufferElementType type)
|
||||
{
|
||||
uint32_t BufferElement::getTypeCount(const BufferElementType type)
|
||||
{
|
||||
switch (type) {
|
||||
case BufferElementType::None: return 0;
|
||||
case BufferElementType::Bool: return 1;
|
||||
case BufferElementType::Bool2: return 2;
|
||||
case BufferElementType::Bool3: return 3;
|
||||
case BufferElementType::Bool4: return 4;
|
||||
case BufferElementType::Int: return 1;
|
||||
case BufferElementType::Int2: return 2;
|
||||
case BufferElementType::Int3: return 3;
|
||||
case BufferElementType::Int4: return 4;
|
||||
case BufferElementType::Uint: return 1;
|
||||
case BufferElementType::Uint2: return 2;
|
||||
case BufferElementType::Uint3: return 3;
|
||||
case BufferElementType::Uint4: return 4;
|
||||
case BufferElementType::Float: return 1;
|
||||
case BufferElementType::Vec2: return 2;
|
||||
case BufferElementType::Vec3: return 3;
|
||||
case BufferElementType::Vec4: return 4;
|
||||
case BufferElementType::Double: return 1;
|
||||
case BufferElementType::Double2: return 2;
|
||||
case BufferElementType::Double3: return 3;
|
||||
case BufferElementType::Double4: return 4;
|
||||
case BufferElementType::Mat2: return 2 * 2;
|
||||
case BufferElementType::Mat3: return 3 * 3;
|
||||
case BufferElementType::Mat4: return 4 * 4;
|
||||
case BufferElementType::DoubleMat2: return 2 * 2;
|
||||
case BufferElementType::DoubleMat3: return 3 * 3;
|
||||
case BufferElementType::DoubleMat4: return 4 * 4;
|
||||
case BufferElementType::None:
|
||||
return 0;
|
||||
case BufferElementType::Bool:
|
||||
return 1;
|
||||
case BufferElementType::Bool2:
|
||||
return 2;
|
||||
case BufferElementType::Bool3:
|
||||
return 3;
|
||||
case BufferElementType::Bool4:
|
||||
return 4;
|
||||
case BufferElementType::Int:
|
||||
return 1;
|
||||
case BufferElementType::Int2:
|
||||
return 2;
|
||||
case BufferElementType::Int3:
|
||||
return 3;
|
||||
case BufferElementType::Int4:
|
||||
return 4;
|
||||
case BufferElementType::Uint:
|
||||
return 1;
|
||||
case BufferElementType::Uint2:
|
||||
return 2;
|
||||
case BufferElementType::Uint3:
|
||||
return 3;
|
||||
case BufferElementType::Uint4:
|
||||
return 4;
|
||||
case BufferElementType::Float:
|
||||
return 1;
|
||||
case BufferElementType::Vec2:
|
||||
return 2;
|
||||
case BufferElementType::Vec3:
|
||||
return 3;
|
||||
case BufferElementType::Vec4:
|
||||
return 4;
|
||||
case BufferElementType::Double:
|
||||
return 1;
|
||||
case BufferElementType::Double2:
|
||||
return 2;
|
||||
case BufferElementType::Double3:
|
||||
return 3;
|
||||
case BufferElementType::Double4:
|
||||
return 4;
|
||||
case BufferElementType::Mat2:
|
||||
return 2 * 2;
|
||||
case BufferElementType::Mat3:
|
||||
return 3 * 3;
|
||||
case BufferElementType::Mat4:
|
||||
return 4 * 4;
|
||||
case BufferElementType::DoubleMat2:
|
||||
return 2 * 2;
|
||||
case BufferElementType::DoubleMat3:
|
||||
return 3 * 3;
|
||||
case BufferElementType::DoubleMat4:
|
||||
return 4 * 4;
|
||||
};
|
||||
|
||||
VERIFY(false, "BufferElement unknown BufferElementType count!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t BufferElement::getTypeGL(const BufferElementType type)
|
||||
{
|
||||
uint32_t BufferElement::getTypeGL(const BufferElementType type)
|
||||
{
|
||||
switch (type) {
|
||||
case BufferElementType::None: return GL_NONE;
|
||||
case BufferElementType::Bool: return GL_BOOL;
|
||||
case BufferElementType::Bool2: return GL_BOOL;
|
||||
case BufferElementType::Bool3: return GL_BOOL;
|
||||
case BufferElementType::Bool4: return GL_BOOL;
|
||||
case BufferElementType::Int: return GL_INT;
|
||||
case BufferElementType::Int2: return GL_INT;
|
||||
case BufferElementType::Int3: return GL_INT;
|
||||
case BufferElementType::Int4: return GL_INT;
|
||||
case BufferElementType::Uint: return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Uint2: return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Uint3: return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Uint4: return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Float: return GL_FLOAT;
|
||||
case BufferElementType::Vec2: return GL_FLOAT;
|
||||
case BufferElementType::Vec3: return GL_FLOAT;
|
||||
case BufferElementType::Vec4: return GL_FLOAT;
|
||||
case BufferElementType::Double: return GL_DOUBLE;
|
||||
case BufferElementType::Double2: return GL_DOUBLE;
|
||||
case BufferElementType::Double3: return GL_DOUBLE;
|
||||
case BufferElementType::Double4: return GL_DOUBLE;
|
||||
case BufferElementType::Mat2: return GL_FLOAT;
|
||||
case BufferElementType::Mat3: return GL_FLOAT;
|
||||
case BufferElementType::Mat4: return GL_FLOAT;
|
||||
case BufferElementType::DoubleMat2: return GL_DOUBLE;
|
||||
case BufferElementType::DoubleMat3: return GL_DOUBLE;
|
||||
case BufferElementType::DoubleMat4: return GL_DOUBLE;
|
||||
case BufferElementType::None:
|
||||
return GL_NONE;
|
||||
case BufferElementType::Bool:
|
||||
return GL_BOOL;
|
||||
case BufferElementType::Bool2:
|
||||
return GL_BOOL;
|
||||
case BufferElementType::Bool3:
|
||||
return GL_BOOL;
|
||||
case BufferElementType::Bool4:
|
||||
return GL_BOOL;
|
||||
case BufferElementType::Int:
|
||||
return GL_INT;
|
||||
case BufferElementType::Int2:
|
||||
return GL_INT;
|
||||
case BufferElementType::Int3:
|
||||
return GL_INT;
|
||||
case BufferElementType::Int4:
|
||||
return GL_INT;
|
||||
case BufferElementType::Uint:
|
||||
return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Uint2:
|
||||
return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Uint3:
|
||||
return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Uint4:
|
||||
return GL_UNSIGNED_INT;
|
||||
case BufferElementType::Float:
|
||||
return GL_FLOAT;
|
||||
case BufferElementType::Vec2:
|
||||
return GL_FLOAT;
|
||||
case BufferElementType::Vec3:
|
||||
return GL_FLOAT;
|
||||
case BufferElementType::Vec4:
|
||||
return GL_FLOAT;
|
||||
case BufferElementType::Double:
|
||||
return GL_DOUBLE;
|
||||
case BufferElementType::Double2:
|
||||
return GL_DOUBLE;
|
||||
case BufferElementType::Double3:
|
||||
return GL_DOUBLE;
|
||||
case BufferElementType::Double4:
|
||||
return GL_DOUBLE;
|
||||
case BufferElementType::Mat2:
|
||||
return GL_FLOAT;
|
||||
case BufferElementType::Mat3:
|
||||
return GL_FLOAT;
|
||||
case BufferElementType::Mat4:
|
||||
return GL_FLOAT;
|
||||
case BufferElementType::DoubleMat2:
|
||||
return GL_DOUBLE;
|
||||
case BufferElementType::DoubleMat3:
|
||||
return GL_DOUBLE;
|
||||
case BufferElementType::DoubleMat4:
|
||||
return GL_DOUBLE;
|
||||
};
|
||||
|
||||
VERIFY(false, "BufferElement unknown BufferElementType GL!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
BufferLayout::BufferLayout(const std::initializer_list<BufferElement>& elements)
|
||||
BufferLayout::BufferLayout(const std::initializer_list<BufferElement>& elements)
|
||||
: m_elements(elements)
|
||||
{
|
||||
{
|
||||
calculateOffsetsAndStride();
|
||||
}
|
||||
}
|
||||
|
||||
void BufferLayout::calculateOffsetsAndStride()
|
||||
{
|
||||
void BufferLayout::calculateOffsetsAndStride()
|
||||
{
|
||||
m_stride = 0;
|
||||
for (auto& element : m_elements) {
|
||||
element.setOffset(m_stride);
|
||||
m_stride += element.getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
VertexBuffer::VertexBuffer(size_t size)
|
||||
{
|
||||
VertexBuffer::VertexBuffer(size_t size)
|
||||
{
|
||||
glGenBuffers(1, &m_id);
|
||||
bind();
|
||||
|
||||
@@ -168,10 +249,10 @@ namespace Inferno {
|
||||
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer(float* vertices, size_t size)
|
||||
{
|
||||
VertexBuffer::VertexBuffer(float* vertices, size_t size)
|
||||
{
|
||||
glGenBuffers(1, &m_id);
|
||||
bind();
|
||||
|
||||
@@ -179,38 +260,38 @@ namespace Inferno {
|
||||
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
||||
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexBuffer::bind() const
|
||||
{
|
||||
void VertexBuffer::bind() const
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexBuffer::unbind() const
|
||||
{
|
||||
void VertexBuffer::unbind() const
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexBuffer::uploadData(const void* data, uint32_t size)
|
||||
{
|
||||
void VertexBuffer::uploadData(const void* data, uint32_t size)
|
||||
{
|
||||
bind();
|
||||
|
||||
// Upload data to the GPU
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, size, data);
|
||||
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
IndexBuffer::IndexBuffer(uint32_t* indices, size_t size) :
|
||||
m_count(size / sizeof(uint32_t))
|
||||
{
|
||||
IndexBuffer::IndexBuffer(uint32_t* indices, size_t size)
|
||||
: m_count(size / sizeof(uint32_t))
|
||||
{
|
||||
glCreateBuffers(1, &m_id);
|
||||
bind();
|
||||
|
||||
@@ -218,47 +299,47 @@ namespace Inferno {
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW);
|
||||
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
IndexBuffer::~IndexBuffer()
|
||||
{
|
||||
IndexBuffer::~IndexBuffer()
|
||||
{
|
||||
glDeleteBuffers(1, &m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void IndexBuffer::bind() const
|
||||
{
|
||||
void IndexBuffer::bind() const
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void IndexBuffer::unbind() const
|
||||
{
|
||||
void IndexBuffer::unbind() const
|
||||
{
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
VertexArray::VertexArray()
|
||||
{
|
||||
VertexArray::VertexArray()
|
||||
{
|
||||
glCreateVertexArrays(1, &m_id);
|
||||
}
|
||||
}
|
||||
|
||||
VertexArray::~VertexArray()
|
||||
{
|
||||
VertexArray::~VertexArray()
|
||||
{
|
||||
glDeleteVertexArrays(1, &m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArray::bind() const
|
||||
{
|
||||
void VertexArray::bind() const
|
||||
{
|
||||
glBindVertexArray(m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArray::unbind() const
|
||||
{
|
||||
void VertexArray::unbind() const
|
||||
{
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArray::addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer)
|
||||
{
|
||||
void VertexArray::addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer)
|
||||
{
|
||||
const auto& layout = vertexBuffer->getLayout();
|
||||
VERIFY(layout.getElements().size(), "VertexBuffer has no layout");
|
||||
|
||||
@@ -282,10 +363,10 @@ namespace Inferno {
|
||||
|
||||
unbind();
|
||||
vertexBuffer->unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArray::setIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer)
|
||||
{
|
||||
void VertexArray::setIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer)
|
||||
{
|
||||
bind();
|
||||
indexBuffer->bind();
|
||||
|
||||
@@ -293,6 +374,6 @@ namespace Inferno {
|
||||
|
||||
unbind();
|
||||
indexBuffer->unbind();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+32
-30
@@ -8,8 +8,9 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
// https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)
|
||||
enum class BufferElementType {
|
||||
// clang-format off
|
||||
// https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)
|
||||
enum class BufferElementType {
|
||||
None = 0,
|
||||
Bool, Bool2, Bool3, Bool4, // bvec
|
||||
Int, Int2, Int3, Int4, // ivec
|
||||
@@ -18,13 +19,14 @@ namespace Inferno {
|
||||
Double, Double2, Double3, Double4, // dvec
|
||||
Mat2, Mat3, Mat4, // mat
|
||||
DoubleMat2, DoubleMat3, DoubleMat4, // dmat
|
||||
};
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// Describes one element of the BufferLayout
|
||||
class BufferElement {
|
||||
public:
|
||||
// Describes one element of the BufferLayout
|
||||
class BufferElement {
|
||||
public:
|
||||
BufferElement(BufferElementType type, std::string name, bool normalized = false);
|
||||
|
||||
uint32_t getTypeSize() const;
|
||||
@@ -34,7 +36,7 @@ namespace Inferno {
|
||||
static uint32_t getTypeCount(const BufferElementType type);
|
||||
static uint32_t getTypeGL(const BufferElementType type);
|
||||
|
||||
inline BufferElementType getType() const{ return m_type; }
|
||||
inline BufferElementType getType() const { return m_type; }
|
||||
inline std::string getName() const { return m_name; }
|
||||
inline uint32_t getSize() const { return m_size; }
|
||||
inline uint32_t getOffset() const { return m_offset; }
|
||||
@@ -46,19 +48,19 @@ namespace Inferno {
|
||||
inline void setOffset(const uint32_t& offset) { m_offset = offset; }
|
||||
inline void setNormalized(const bool& normalized) { m_normalized = normalized; }
|
||||
|
||||
private:
|
||||
private:
|
||||
BufferElementType m_type;
|
||||
std::string m_name;
|
||||
uint32_t m_size { 0 };
|
||||
uint32_t m_offset { 0 };
|
||||
bool m_normalized { false };
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// Layout that describes raw vertex data
|
||||
class BufferLayout {
|
||||
public:
|
||||
// Layout that describes raw vertex data
|
||||
class BufferLayout {
|
||||
public:
|
||||
BufferLayout() {}
|
||||
BufferLayout(const std::initializer_list<BufferElement>& elements);
|
||||
|
||||
@@ -71,19 +73,19 @@ namespace Inferno {
|
||||
inline std::vector<BufferElement>::const_iterator begin() const { return m_elements.begin(); }
|
||||
inline std::vector<BufferElement>::const_iterator end() const { return m_elements.end(); }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void calculateOffsetsAndStride();
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<BufferElement> m_elements;
|
||||
uint32_t m_stride { 0 };
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// GPU memory which holds raw vertex data
|
||||
class VertexBuffer {
|
||||
public:
|
||||
// GPU memory which holds raw vertex data
|
||||
class VertexBuffer {
|
||||
public:
|
||||
VertexBuffer(size_t size);
|
||||
VertexBuffer(float* vertices, size_t size);
|
||||
~VertexBuffer();
|
||||
@@ -97,16 +99,16 @@ namespace Inferno {
|
||||
|
||||
inline void setLayout(const BufferLayout& layout) { m_layout = layout; }
|
||||
|
||||
private:
|
||||
private:
|
||||
uint32_t m_id { 0 };
|
||||
BufferLayout m_layout;
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// Vertices order of rendering
|
||||
class IndexBuffer {
|
||||
public:
|
||||
// Vertices order of rendering
|
||||
class IndexBuffer {
|
||||
public:
|
||||
IndexBuffer(uint32_t* indices, size_t size);
|
||||
~IndexBuffer();
|
||||
|
||||
@@ -115,16 +117,16 @@ namespace Inferno {
|
||||
|
||||
inline uint32_t getCount() const { return m_count; }
|
||||
|
||||
private:
|
||||
private:
|
||||
uint32_t m_id { 0 };
|
||||
uint32_t m_count { 0 };
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// Array that holds the vertex attributes configuration
|
||||
class VertexArray {
|
||||
public:
|
||||
// Array that holds the vertex attributes configuration
|
||||
class VertexArray {
|
||||
public:
|
||||
VertexArray();
|
||||
~VertexArray();
|
||||
|
||||
@@ -137,9 +139,9 @@ namespace Inferno {
|
||||
inline const std::vector<std::shared_ptr<VertexBuffer>>& getVertexBuffers() const { return m_vertexBuffers; }
|
||||
inline std::shared_ptr<IndexBuffer> getIndexBuffer() const { return m_indexBuffer; }
|
||||
|
||||
private:
|
||||
private:
|
||||
uint32_t m_id { 0 };
|
||||
std::vector<std::shared_ptr<VertexBuffer>> m_vertexBuffers;
|
||||
std::shared_ptr<IndexBuffer> m_indexBuffer;
|
||||
};
|
||||
};
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "glad/glad.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "glad/glad.h"
|
||||
#include "ruc/meta/assert.h"
|
||||
|
||||
#include "inferno/core.h"
|
||||
@@ -9,14 +9,14 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
Context::Context(GLFWwindow* window) :
|
||||
m_window(window)
|
||||
{
|
||||
Context::Context(GLFWwindow* window)
|
||||
: m_window(window)
|
||||
{
|
||||
VERIFY(window, "Context window is nullptr!");
|
||||
}
|
||||
}
|
||||
|
||||
void Context::initialize()
|
||||
{
|
||||
void Context::initialize()
|
||||
{
|
||||
Context::setCurrent();
|
||||
|
||||
// Initialize glad
|
||||
@@ -32,21 +32,21 @@ namespace Inferno {
|
||||
// Check OpenGL version
|
||||
VERIFY(GLVersion.major > 4 || (GLVersion.major == 4 && GLVersion.minor >= 5),
|
||||
"Inferno requires at least OpenGL version 4.5!");
|
||||
}
|
||||
}
|
||||
|
||||
void Context::destroy()
|
||||
{
|
||||
}
|
||||
void Context::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
void Context::render()
|
||||
{
|
||||
void Context::render()
|
||||
{
|
||||
glfwSwapBuffers(m_window);
|
||||
}
|
||||
}
|
||||
|
||||
void Context::setCurrent()
|
||||
{
|
||||
void Context::setCurrent()
|
||||
{
|
||||
// Set current OpenGL context to this window
|
||||
glfwMakeContextCurrent(m_window);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -4,8 +4,8 @@ struct GLFWwindow;
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Context {
|
||||
public:
|
||||
class Context {
|
||||
public:
|
||||
Context(GLFWwindow* window);
|
||||
|
||||
void initialize();
|
||||
@@ -14,8 +14,8 @@ namespace Inferno {
|
||||
|
||||
void setCurrent();
|
||||
|
||||
private:
|
||||
private:
|
||||
GLFWwindow* m_window { nullptr };
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+43
-44
@@ -11,9 +11,9 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
Font::Font(const std::string& name)
|
||||
Font::Font(const std::string& name)
|
||||
: m_name(std::move(name))
|
||||
{
|
||||
{
|
||||
std::string path = name + ".fnt";
|
||||
std::string image = name + ".png";
|
||||
|
||||
@@ -21,15 +21,14 @@ namespace Inferno {
|
||||
parseFont(font);
|
||||
|
||||
m_texture = std::make_shared<Texture>(image);
|
||||
}
|
||||
}
|
||||
|
||||
void Font::parseFont(const std::string& font)
|
||||
{
|
||||
void Font::parseFont(const std::string& font)
|
||||
{
|
||||
std::istringstream iss(font);
|
||||
for (std::string line; std::getline(iss, line);) {
|
||||
|
||||
if (findAction(line).compare("info") != 0 &&
|
||||
findAction(line).compare("char") != 0) {
|
||||
if (findAction(line).compare("info") != 0 && findAction(line).compare("char") != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -53,15 +52,15 @@ namespace Inferno {
|
||||
};
|
||||
m_characterList.emplace(id, std::make_shared<Character>(character));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::string Font::findAction(const std::string& line)
|
||||
{
|
||||
const std::string Font::findAction(const std::string& line)
|
||||
{
|
||||
return line.substr(0, line.find(" "));
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> Font::findColumns(const std::string& line)
|
||||
{
|
||||
const std::vector<std::string> Font::findColumns(const std::string& line)
|
||||
{
|
||||
std::vector<std::string> elements;
|
||||
|
||||
size_t index = 0;
|
||||
@@ -85,10 +84,10 @@ namespace Inferno {
|
||||
|
||||
VERIFY(!elements.empty(), "Font file did not find any columns");
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string Font::findValue(const std::string& key, const std::vector<std::string>& columns)
|
||||
{
|
||||
const std::string Font::findValue(const std::string& key, const std::vector<std::string>& columns)
|
||||
{
|
||||
size_t find = 0;
|
||||
// Loop over columns
|
||||
for (auto& column : columns) {
|
||||
@@ -100,27 +99,27 @@ namespace Inferno {
|
||||
|
||||
VERIFY(false, "Font file did not contain key '{}'", key);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
FontManager::FontManager(s)
|
||||
{
|
||||
FontManager::FontManager(s)
|
||||
{
|
||||
info() << "FontManager initialized";
|
||||
}
|
||||
}
|
||||
|
||||
FontManager::~FontManager()
|
||||
{
|
||||
}
|
||||
FontManager::~FontManager()
|
||||
{
|
||||
}
|
||||
|
||||
void FontManager::add(const std::string& name, std::shared_ptr<Font> font)
|
||||
{
|
||||
void FontManager::add(const std::string& name, std::shared_ptr<Font> font)
|
||||
{
|
||||
// Construct (key, value) pair and insert it into the unordered_map
|
||||
m_fontList.emplace(std::move(name), std::move(font));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> FontManager::load(const std::string& name)
|
||||
{
|
||||
std::shared_ptr<Font> FontManager::load(const std::string& name)
|
||||
{
|
||||
if (exists(name)) {
|
||||
return get(name);
|
||||
}
|
||||
@@ -128,37 +127,37 @@ namespace Inferno {
|
||||
std::shared_ptr<Font> font = std::make_shared<Font>(name);
|
||||
add(name, font);
|
||||
return get(name);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> FontManager::get(const std::string& name)
|
||||
{
|
||||
std::shared_ptr<Font> FontManager::get(const std::string& name)
|
||||
{
|
||||
return exists(name) ? m_fontList.at(name) : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool FontManager::exists(const std::string& name)
|
||||
{
|
||||
bool FontManager::exists(const std::string& name)
|
||||
{
|
||||
return m_fontList.find(name) != m_fontList.end();
|
||||
}
|
||||
}
|
||||
|
||||
void FontManager::remove(const std::string& name)
|
||||
{
|
||||
void FontManager::remove(const std::string& name)
|
||||
{
|
||||
if (exists(name)) {
|
||||
m_fontList.erase(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FontManager::remove(std::shared_ptr<Font> font)
|
||||
{
|
||||
void FontManager::remove(std::shared_ptr<Font> font)
|
||||
{
|
||||
if (exists(font->name())) {
|
||||
m_fontList.erase(font->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::ivec2& value)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::ivec2& value)
|
||||
{
|
||||
return stream << "{ " << value.x << ", " << value.y << " }";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+15
-15
@@ -14,19 +14,19 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Texture;
|
||||
class Texture;
|
||||
|
||||
struct Character {
|
||||
struct Character {
|
||||
glm::uvec2 position; // Position
|
||||
glm::uvec2 size; // Width/height
|
||||
glm::ivec2 offset; // Offset from baseline to left / top of glyph
|
||||
uint32_t advance; // Amount to advance to next glyph
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class Font {
|
||||
public:
|
||||
class Font {
|
||||
public:
|
||||
Font(const std::string& name);
|
||||
virtual ~Font() {}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Inferno {
|
||||
inline std::shared_ptr<Character> get(unsigned char c) const { return m_characterList.at(c); }
|
||||
inline std::shared_ptr<Character> operator[](unsigned char c) const { return m_characterList.at(c); }
|
||||
|
||||
private:
|
||||
private:
|
||||
void parseFont(const std::string& font);
|
||||
const std::string findAction(const std::string& line);
|
||||
const std::vector<std::string> findColumns(const std::string& line);
|
||||
@@ -47,12 +47,12 @@ namespace Inferno {
|
||||
uint32_t m_size;
|
||||
std::shared_ptr<Texture> m_texture;
|
||||
std::unordered_map<unsigned char, std::shared_ptr<Character>> m_characterList;
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class FontManager final : public ruc::Singleton<FontManager> {
|
||||
public:
|
||||
class FontManager final : public ruc::Singleton<FontManager> {
|
||||
public:
|
||||
FontManager(s);
|
||||
virtual ~FontManager();
|
||||
|
||||
@@ -64,13 +64,13 @@ namespace Inferno {
|
||||
void remove(const std::string& name);
|
||||
void remove(std::shared_ptr<Font> font);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Font>> m_fontList;
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::ivec2& value);
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::ivec2& value);
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Framebuffer {
|
||||
public:
|
||||
class Framebuffer {
|
||||
public:
|
||||
Framebuffer();
|
||||
virtual ~Framebuffer();
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#if 0
|
||||
#include <algorithm> // std::copy
|
||||
#include <utility> // std::move
|
||||
#include <algorithm> // std::copy
|
||||
#include <utility> // std::move
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "ruc/meta/assert.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "ruc/meta/assert.h"
|
||||
|
||||
#include "inferno/io/file.h"
|
||||
#include "inferno/io/gltffile.h"
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/render/gltf.h"
|
||||
#include "inferno/util/integer.h"
|
||||
#include "inferno/io/file.h"
|
||||
#include "inferno/io/gltffile.h"
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/render/gltf.h"
|
||||
#include "inferno/util/integer.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
|
||||
+23
-23
@@ -1,34 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#if 0
|
||||
#include <cstdint> // uint32_t
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <string> // std::string
|
||||
#include <unordered_map> // std::unordered_map
|
||||
#include <vector> // std::vector
|
||||
#include <cstdint> // uint32_t
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <string> // std::string
|
||||
#include <unordered_map> // std::unordered_map
|
||||
#include <vector> // std::vector
|
||||
|
||||
#include "ruc/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
#include "inferno/util/json.h"
|
||||
#include "inferno/util/json.h"
|
||||
|
||||
#define GLTF_TYPE_SCALAR 1
|
||||
#define GLTF_TYPE_VEC2 2
|
||||
#define GLTF_TYPE_VEC3 3
|
||||
#define GLTF_TYPE_VEC4 4
|
||||
#define GLTF_TYPE_MAT2 8
|
||||
#define GLTF_TYPE_MAT3 12
|
||||
#define GLTF_TYPE_MAT4 16
|
||||
#define GLTF_TYPE_SCALAR 1
|
||||
#define GLTF_TYPE_VEC2 2
|
||||
#define GLTF_TYPE_VEC3 3
|
||||
#define GLTF_TYPE_VEC4 4
|
||||
#define GLTF_TYPE_MAT2 8
|
||||
#define GLTF_TYPE_MAT3 12
|
||||
#define GLTF_TYPE_MAT4 16
|
||||
|
||||
#define GLTF_COMPONENT_TYPE_BYTE 5120
|
||||
#define GLTF_COMPONENT_TYPE_UNSIGNED_BYTE 5121
|
||||
#define GLTF_COMPONENT_TYPE_SHORT 5122
|
||||
#define GLTF_COMPONENT_TYPE_UNSIGNED_SHORT 5123
|
||||
#define GLTF_COMPONENT_TYPE_INT 5124
|
||||
#define GLTF_COMPONENT_TYPE_UNSIGNED_INT 5125
|
||||
#define GLTF_COMPONENT_TYPE_FLOAT 5126
|
||||
#define GLTF_COMPONENT_TYPE_BYTE 5120
|
||||
#define GLTF_COMPONENT_TYPE_UNSIGNED_BYTE 5121
|
||||
#define GLTF_COMPONENT_TYPE_SHORT 5122
|
||||
#define GLTF_COMPONENT_TYPE_UNSIGNED_SHORT 5123
|
||||
#define GLTF_COMPONENT_TYPE_INT 5124
|
||||
#define GLTF_COMPONENT_TYPE_UNSIGNED_INT 5125
|
||||
#define GLTF_COMPONENT_TYPE_FLOAT 5126
|
||||
|
||||
#define GLTF_TARGET_ARRAY_BUFFER 34962
|
||||
#define GLTF_TARGET_ELEMENT_ARRAY_BUFFER 34963
|
||||
#define GLTF_TARGET_ARRAY_BUFFER 34962
|
||||
#define GLTF_TARGET_ELEMENT_ARRAY_BUFFER 34963
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
|
||||
+111
-108
@@ -10,8 +10,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
void RenderCommand::initialize()
|
||||
{
|
||||
void RenderCommand::initialize()
|
||||
{
|
||||
setDepthTest(true);
|
||||
|
||||
// Enable transparency
|
||||
@@ -19,59 +19,59 @@ namespace Inferno {
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
info() << "RenderCommand initialized";
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCommand::destroy()
|
||||
{
|
||||
}
|
||||
void RenderCommand::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
void RenderCommand::clear()
|
||||
{
|
||||
void RenderCommand::clear()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCommand::clearColor(const glm::vec4& color)
|
||||
{
|
||||
void RenderCommand::clearColor(const glm::vec4& color)
|
||||
{
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCommand::drawIndexed(const VertexArray& vertexArray, uint32_t indexCount)
|
||||
{
|
||||
void RenderCommand::drawIndexed(const VertexArray& vertexArray, uint32_t indexCount)
|
||||
{
|
||||
uint32_t count = indexCount ? indexCount : vertexArray.getIndexBuffer()->getCount();
|
||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCommand::setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height)
|
||||
{
|
||||
void RenderCommand::setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height)
|
||||
{
|
||||
glViewport(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCommand::setDepthTest(bool enabled)
|
||||
{
|
||||
void RenderCommand::setDepthTest(bool enabled)
|
||||
{
|
||||
// Set z-buffer / depth buffer
|
||||
enabled ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderCommand::depthTest()
|
||||
{
|
||||
bool RenderCommand::depthTest()
|
||||
{
|
||||
unsigned char depthTest = GL_FALSE;
|
||||
glGetBooleanv(GL_DEPTH_TEST, &depthTest);
|
||||
return depthTest == GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t RenderCommand::textureUnitAmount()
|
||||
{
|
||||
int32_t RenderCommand::textureUnitAmount()
|
||||
{
|
||||
int32_t amount = 0;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &amount);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
uint32_t Renderer::m_supportedTextureUnitPerBatch = 0;
|
||||
uint32_t Renderer::m_supportedTextureUnitPerBatch = 0;
|
||||
|
||||
void Renderer::initialize()
|
||||
{
|
||||
void Renderer::initialize()
|
||||
{
|
||||
// Get amount of texture units supported by the GPU
|
||||
uint32_t constTextureUnitCount = textureUnitPerBatch;
|
||||
uint32_t gpuTextureUnitCount = RenderCommand::textureUnitAmount();
|
||||
@@ -94,14 +94,14 @@ namespace Inferno {
|
||||
|
||||
// Create vertex array
|
||||
m_vertexArray = std::make_shared<VertexArray>();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::destroy()
|
||||
{
|
||||
}
|
||||
void Renderer::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t Renderer::addTextureUnit(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
uint32_t Renderer::addTextureUnit(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
if (texture == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
@@ -124,10 +124,10 @@ namespace Inferno {
|
||||
m_textureUnitIndex++;
|
||||
|
||||
return textureUnitIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::bind()
|
||||
{
|
||||
void Renderer::bind()
|
||||
{
|
||||
m_shader->bind();
|
||||
|
||||
for (uint32_t i = 1; i < m_textureUnitIndex; i++) {
|
||||
@@ -135,10 +135,10 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
m_vertexArray->bind();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::unbind()
|
||||
{
|
||||
void Renderer::unbind()
|
||||
{
|
||||
m_vertexArray->unbind();
|
||||
|
||||
for (uint32_t i = 1; i < m_textureUnitIndex; i++) {
|
||||
@@ -146,12 +146,12 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
m_shader->unbind();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
Renderer2D::Renderer2D(s)
|
||||
{
|
||||
Renderer2D::Renderer2D(s)
|
||||
{
|
||||
Renderer::initialize();
|
||||
|
||||
// CPU
|
||||
@@ -202,49 +202,52 @@ namespace Inferno {
|
||||
delete[] indices;
|
||||
|
||||
info() << "Renderer2D initialized";
|
||||
}
|
||||
}
|
||||
|
||||
Renderer2D::~Renderer2D()
|
||||
{
|
||||
Renderer2D::~Renderer2D()
|
||||
{
|
||||
Renderer::destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::beginScene(glm::mat4 cameraProjectionView)
|
||||
{
|
||||
void Renderer2D::beginScene(glm::mat4 cameraProjectionView)
|
||||
{
|
||||
m_shader->bind();
|
||||
m_shader->setFloat("u_projectionView", cameraProjectionView);
|
||||
m_shader->unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::endScene()
|
||||
{
|
||||
void Renderer2D::endScene()
|
||||
{
|
||||
nextBatch();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::vec4 color)
|
||||
{
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::vec4 color)
|
||||
{
|
||||
drawQuad(transform, color, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color)
|
||||
{
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color)
|
||||
{
|
||||
drawQuad(transform, color, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
drawQuad(transform, glm::mat4(color, color, color, color), texture);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
// Create a new batch if the quad limit has been reached
|
||||
if (m_quadIndex >= quadCount) {
|
||||
nextBatch();
|
||||
}
|
||||
|
||||
constexpr glm::vec2 textureCoordinates[] = {
|
||||
{ 0.0f, 0.0f }, { 1.0f, 0.0f }, { 1.0f, 1.0f }, { 0.0f, 1.0f }
|
||||
{ 0.0f, 0.0f },
|
||||
{ 1.0f, 0.0f },
|
||||
{ 1.0f, 1.0f },
|
||||
{ 0.0f, 1.0f }
|
||||
};
|
||||
|
||||
uint32_t textureUnitIndex = addTextureUnit(texture);
|
||||
@@ -259,15 +262,15 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
m_quadIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::loadShader()
|
||||
{
|
||||
void Renderer2D::loadShader()
|
||||
{
|
||||
m_shader = ShaderManager::the().load("assets/glsl/batch-quad");
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::flush()
|
||||
{
|
||||
void Renderer2D::flush()
|
||||
{
|
||||
if (m_quadIndex == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -283,26 +286,26 @@ namespace Inferno {
|
||||
RenderCommand::drawIndexed(*m_vertexArray, m_quadIndex * indexPerQuad);
|
||||
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::startBatch()
|
||||
{
|
||||
void Renderer2D::startBatch()
|
||||
{
|
||||
m_quadIndex = 0;
|
||||
m_vertexBufferPtr = m_vertexBufferBase.get();
|
||||
|
||||
m_textureUnitIndex = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer2D::nextBatch()
|
||||
{
|
||||
void Renderer2D::nextBatch()
|
||||
{
|
||||
flush();
|
||||
startBatch();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
RendererCharacter::RendererCharacter(s)
|
||||
{
|
||||
RendererCharacter::RendererCharacter(s)
|
||||
{
|
||||
Renderer::initialize();
|
||||
|
||||
// CPU
|
||||
@@ -353,24 +356,24 @@ namespace Inferno {
|
||||
delete[] indices;
|
||||
|
||||
info() << "RendererCharacter initialized";
|
||||
}
|
||||
}
|
||||
|
||||
RendererCharacter::~RendererCharacter()
|
||||
{
|
||||
RendererCharacter::~RendererCharacter()
|
||||
{
|
||||
Renderer::destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCharacter::beginScene()
|
||||
{
|
||||
}
|
||||
void RendererCharacter::beginScene()
|
||||
{
|
||||
}
|
||||
|
||||
void RendererCharacter::endScene()
|
||||
{
|
||||
void RendererCharacter::endScene()
|
||||
{
|
||||
nextBatch();
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCharacter::drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
void RendererCharacter::drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
// Create a new batch if the quad limit has been reached
|
||||
if (m_quadIndex >= quadCount) {
|
||||
nextBatch();
|
||||
@@ -396,15 +399,15 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
m_quadIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCharacter::loadShader()
|
||||
{
|
||||
void RendererCharacter::loadShader()
|
||||
{
|
||||
m_shader = ShaderManager::the().load("assets/glsl/batch-font");
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCharacter::flush()
|
||||
{
|
||||
void RendererCharacter::flush()
|
||||
{
|
||||
if (m_quadIndex == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -423,20 +426,20 @@ namespace Inferno {
|
||||
RenderCommand::setDepthTest(depthTest);
|
||||
|
||||
unbind();
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCharacter::startBatch()
|
||||
{
|
||||
void RendererCharacter::startBatch()
|
||||
{
|
||||
m_quadIndex = 0;
|
||||
m_vertexBufferPtr = m_vertexBufferBase.get();
|
||||
|
||||
m_textureUnitIndex = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCharacter::nextBatch()
|
||||
{
|
||||
void RendererCharacter::nextBatch()
|
||||
{
|
||||
flush();
|
||||
startBatch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -13,18 +13,18 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Shader;
|
||||
class Texture;
|
||||
class VertexArray;
|
||||
class Shader;
|
||||
class Texture;
|
||||
class VertexArray;
|
||||
|
||||
struct QuadVertex {
|
||||
struct QuadVertex {
|
||||
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec4 color { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
glm::vec2 textureCoordinates { 0.0f, 0.0f };
|
||||
float textureIndex = 0; // @Todo get int to pass to fragment correctly
|
||||
};
|
||||
};
|
||||
|
||||
struct CharacterVertex {
|
||||
struct CharacterVertex {
|
||||
QuadVertex quad;
|
||||
|
||||
// Font
|
||||
@@ -36,12 +36,12 @@ namespace Inferno {
|
||||
glm::vec4 borderColor { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
// Dropshadow
|
||||
float offset = 0.0f;
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class RenderCommand {
|
||||
public:
|
||||
class RenderCommand {
|
||||
public:
|
||||
static void initialize();
|
||||
static void destroy();
|
||||
|
||||
@@ -54,17 +54,17 @@ namespace Inferno {
|
||||
|
||||
static bool depthTest();
|
||||
static int32_t textureUnitAmount();
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
class Renderer {
|
||||
public:
|
||||
static const uint32_t vertexPerQuad = 4;
|
||||
static const uint32_t indexPerQuad = 6;
|
||||
static const uint32_t textureUnitPerBatch = 32;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
Renderer() {}
|
||||
|
||||
void initialize();
|
||||
@@ -89,14 +89,14 @@ namespace Inferno {
|
||||
// GPU objects
|
||||
std::shared_ptr<Shader> m_shader;
|
||||
std::shared_ptr<VertexArray> m_vertexArray;
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class Renderer2D final
|
||||
class Renderer2D final
|
||||
: public Renderer
|
||||
, public ruc::Singleton<Renderer2D> {
|
||||
public:
|
||||
public:
|
||||
Renderer2D(s);
|
||||
virtual ~Renderer2D();
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace Inferno {
|
||||
void drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture);
|
||||
void drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture);
|
||||
|
||||
private:
|
||||
private:
|
||||
void loadShader() override;
|
||||
void flush() override;
|
||||
void startBatch() override;
|
||||
@@ -126,14 +126,14 @@ namespace Inferno {
|
||||
|
||||
// Default quad vertex positions
|
||||
glm::vec4 m_vertexPositions[vertexPerQuad];
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class RendererCharacter final
|
||||
class RendererCharacter final
|
||||
: public Renderer
|
||||
, public ruc::Singleton<RendererCharacter> {
|
||||
public:
|
||||
public:
|
||||
RendererCharacter(s);
|
||||
virtual ~RendererCharacter();
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Inferno {
|
||||
|
||||
void drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture);
|
||||
|
||||
private:
|
||||
private:
|
||||
void loadShader() override;
|
||||
void flush() override;
|
||||
void startBatch() override;
|
||||
@@ -157,6 +157,6 @@ namespace Inferno {
|
||||
// CPU quad vertices
|
||||
std::unique_ptr<CharacterVertex[]> m_vertexBufferBase;
|
||||
CharacterVertex* m_vertexBufferPtr { nullptr };
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
Shader::Shader(const std::string& name)
|
||||
: m_name(std::move(name)),
|
||||
m_id(0)
|
||||
{
|
||||
Shader::Shader(const std::string& name)
|
||||
: m_name(std::move(name))
|
||||
, m_id(0)
|
||||
{
|
||||
// Get file contents
|
||||
std::string vertexSrc = File::read(name + ".vert");
|
||||
std::string fragmentSrc = File::read(name + ".frag");
|
||||
@@ -29,91 +29,93 @@ namespace Inferno {
|
||||
m_id = linkShader(vertexID, fragmentID);
|
||||
}
|
||||
// Clear resources
|
||||
else if (vertexID > 0) glDeleteShader(vertexID);
|
||||
else if (fragmentID > 0) glDeleteShader(fragmentID);
|
||||
}
|
||||
else if (vertexID > 0)
|
||||
glDeleteShader(vertexID);
|
||||
else if (fragmentID > 0)
|
||||
glDeleteShader(fragmentID);
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
Shader::~Shader()
|
||||
{
|
||||
if (m_id > 0) {
|
||||
glDeleteProgram(m_id);
|
||||
m_id = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Shader::findUniform(const std::string& name) const
|
||||
{
|
||||
int32_t Shader::findUniform(const std::string& name) const
|
||||
{
|
||||
int32_t location = glGetUniformLocation(m_id, name.c_str());
|
||||
VERIFY(location != -1, "Shader could not find uniform '{}'", name);
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setInt(const std::string& name, int value)
|
||||
{
|
||||
void Shader::setInt(const std::string& name, int value)
|
||||
{
|
||||
// Set uniform int
|
||||
glUniform1i(findUniform(name), value);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setInt(const std::string& name, int* values, uint32_t count)
|
||||
{
|
||||
void Shader::setInt(const std::string& name, int* values, uint32_t count)
|
||||
{
|
||||
// Set uniform int array
|
||||
glUniform1iv(findUniform(name), count, values);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string& name, float value) const
|
||||
{
|
||||
void Shader::setFloat(const std::string& name, float value) const
|
||||
{
|
||||
// Set uniform float
|
||||
glUniform1f(findUniform(name), value);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string& name, float v1, float v2, float v3, float v4) const
|
||||
{
|
||||
void Shader::setFloat(const std::string& name, float v1, float v2, float v3, float v4) const
|
||||
{
|
||||
// Set uniform vec4 data
|
||||
glUniform4f(findUniform(name), v1, v2, v3, v4);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string& name, glm::vec2 value) const
|
||||
{
|
||||
void Shader::setFloat(const std::string& name, glm::vec2 value) const
|
||||
{
|
||||
// Set uniform vec2 data
|
||||
glUniform2f(findUniform(name), value.x, value.y);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string& name, glm::vec3 value) const
|
||||
{
|
||||
void Shader::setFloat(const std::string& name, glm::vec3 value) const
|
||||
{
|
||||
// Set uniform vec3 data
|
||||
glUniform3f(findUniform(name), value.x, value.y, value.z);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string& name, glm::vec4 value) const
|
||||
{
|
||||
void Shader::setFloat(const std::string& name, glm::vec4 value) const
|
||||
{
|
||||
// Set uniform vec4 data
|
||||
glUniform4f(findUniform(name), value.x, value.y, value.z, value.w);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string& name, glm::mat3 matrix) const
|
||||
{
|
||||
void Shader::setFloat(const std::string& name, glm::mat3 matrix) const
|
||||
{
|
||||
// Set uniform mat3 data
|
||||
glUniformMatrix3fv(findUniform(name), 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string& name, glm::mat4 matrix) const
|
||||
{
|
||||
void Shader::setFloat(const std::string& name, glm::mat4 matrix) const
|
||||
{
|
||||
// Set uniform mat4 data
|
||||
glUniformMatrix4fv(findUniform(name), 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::bind() const
|
||||
{
|
||||
void Shader::bind() const
|
||||
{
|
||||
glUseProgram(m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::unbind() const
|
||||
{
|
||||
void Shader::unbind() const
|
||||
{
|
||||
glUseProgram(0);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Shader::compileShader(int32_t type, const char* source) const
|
||||
{
|
||||
uint32_t Shader::compileShader(int32_t type, const char* source) const
|
||||
{
|
||||
// Create new shader
|
||||
uint32_t shader = 0;
|
||||
shader = glCreateShader(type);
|
||||
@@ -130,10 +132,10 @@ namespace Inferno {
|
||||
// On fail
|
||||
glDeleteShader(shader);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Shader::linkShader(uint32_t vertex, uint32_t fragment) const
|
||||
{
|
||||
uint32_t Shader::linkShader(uint32_t vertex, uint32_t fragment) const
|
||||
{
|
||||
// Create new shader program
|
||||
uint32_t shaderProgram = 0;
|
||||
shaderProgram = glCreateProgram();
|
||||
@@ -156,10 +158,10 @@ namespace Inferno {
|
||||
// On fail
|
||||
glDeleteProgram(shaderProgram);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Shader::checkStatus(uint32_t check, bool isProgram) const
|
||||
{
|
||||
int32_t Shader::checkStatus(uint32_t check, bool isProgram) const
|
||||
{
|
||||
int32_t success;
|
||||
int32_t maxLength = 0;
|
||||
std::vector<char> infoLog;
|
||||
@@ -189,27 +191,27 @@ namespace Inferno {
|
||||
VERIFY(success == GL_TRUE, "Shader program creation failed!");
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
ShaderManager::ShaderManager(s)
|
||||
{
|
||||
ShaderManager::ShaderManager(s)
|
||||
{
|
||||
info() << "ShaderManager initialized";
|
||||
}
|
||||
}
|
||||
|
||||
ShaderManager::~ShaderManager()
|
||||
{
|
||||
}
|
||||
ShaderManager::~ShaderManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderManager::add(const std::string& name, std::shared_ptr<Shader> shader)
|
||||
{
|
||||
void ShaderManager::add(const std::string& name, std::shared_ptr<Shader> shader)
|
||||
{
|
||||
// Construct (key, value) pair and insert it into the unordered_map
|
||||
m_shaderList.emplace(std::move(name), std::move(shader));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Shader> ShaderManager::load(const std::string& name)
|
||||
{
|
||||
std::shared_ptr<Shader> ShaderManager::load(const std::string& name)
|
||||
{
|
||||
if (exists(name)) {
|
||||
return get(name);
|
||||
}
|
||||
@@ -217,42 +219,42 @@ namespace Inferno {
|
||||
std::shared_ptr<Shader> shader = std::make_shared<Shader>(name);
|
||||
add(name, shader);
|
||||
return get(name);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Shader> ShaderManager::load(const std::string& vertexSource,
|
||||
std::shared_ptr<Shader> ShaderManager::load(const std::string& vertexSource,
|
||||
const std::string& fragmentSource)
|
||||
{
|
||||
{
|
||||
std::string name = computeName(vertexSource, fragmentSource);
|
||||
return load(name);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Shader> ShaderManager::get(const std::string& name)
|
||||
{
|
||||
std::shared_ptr<Shader> ShaderManager::get(const std::string& name)
|
||||
{
|
||||
return exists(name) ? m_shaderList.at(name) : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool ShaderManager::exists(const std::string& name)
|
||||
{
|
||||
bool ShaderManager::exists(const std::string& name)
|
||||
{
|
||||
return m_shaderList.find(name) != m_shaderList.end();
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderManager::remove(const std::string& name)
|
||||
{
|
||||
void ShaderManager::remove(const std::string& name)
|
||||
{
|
||||
if (exists(name)) {
|
||||
m_shaderList.erase(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderManager::remove(std::shared_ptr<Shader> shader)
|
||||
{
|
||||
void ShaderManager::remove(std::shared_ptr<Shader> shader)
|
||||
{
|
||||
if (exists(shader->name())) {
|
||||
m_shaderList.erase(shader->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ShaderManager::computeName(const std::string& vertexSource,
|
||||
std::string ShaderManager::computeName(const std::string& vertexSource,
|
||||
const std::string& fragmentSource)
|
||||
{
|
||||
{
|
||||
auto vertexPos = vertexSource.find_last_of('.');
|
||||
auto fragmentPos = fragmentSource.find_last_of('.');
|
||||
|
||||
@@ -265,6 +267,6 @@ namespace Inferno {
|
||||
VERIFY(vertexName == fragmentName, "Shader names did not match: {} {}", vertexSource, fragmentSource);
|
||||
|
||||
return vertexName;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+11
-11
@@ -10,8 +10,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
class Shader {
|
||||
public:
|
||||
Shader(const std::string& name);
|
||||
virtual ~Shader();
|
||||
|
||||
@@ -33,20 +33,20 @@ namespace Inferno {
|
||||
inline std::string name() const { return m_name; }
|
||||
inline uint32_t id() const { return m_id; }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
uint32_t compileShader(int32_t type, const char* shaderSource) const;
|
||||
uint32_t linkShader(uint32_t vertex, uint32_t fragment) const;
|
||||
int32_t checkStatus(uint32_t check, bool isProgram = false) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string m_name;
|
||||
uint32_t m_id;
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class ShaderManager final : public ruc::Singleton<ShaderManager> {
|
||||
public:
|
||||
class ShaderManager final : public ruc::Singleton<ShaderManager> {
|
||||
public:
|
||||
ShaderManager(s);
|
||||
virtual ~ShaderManager();
|
||||
|
||||
@@ -60,12 +60,12 @@ namespace Inferno {
|
||||
void remove(const std::string& name);
|
||||
void remove(std::shared_ptr<Shader> shader);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::string computeName(const std::string& vertexSource,
|
||||
const std::string& fragmentSource);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Shader>> m_shaderList;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
Texture::Texture(const std::string& path)
|
||||
Texture::Texture(const std::string& path)
|
||||
: m_path(std::move(path))
|
||||
{
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int channels;
|
||||
@@ -41,15 +41,15 @@ namespace Inferno {
|
||||
|
||||
// Clean resources
|
||||
stbi_image_free(data);
|
||||
}
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
Texture::~Texture()
|
||||
{
|
||||
glDeleteTextures(1, &m_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::bind(uint32_t unit) const
|
||||
{
|
||||
void Texture::bind(uint32_t unit) const
|
||||
{
|
||||
// Set active unit
|
||||
glActiveTexture(GL_TEXTURE0 + unit);
|
||||
|
||||
@@ -57,15 +57,15 @@ namespace Inferno {
|
||||
|
||||
// Reset unit
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::unbind() const
|
||||
{
|
||||
void Texture::unbind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::create(unsigned char* data)
|
||||
{
|
||||
void Texture::create(unsigned char* data)
|
||||
{
|
||||
m_id = UINT_MAX;
|
||||
|
||||
// Create texture object
|
||||
@@ -100,27 +100,27 @@ namespace Inferno {
|
||||
|
||||
// Unbind texture object
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
TextureManager::TextureManager(s)
|
||||
{
|
||||
TextureManager::TextureManager(s)
|
||||
{
|
||||
info() << "TextureManager initialized";
|
||||
}
|
||||
}
|
||||
|
||||
TextureManager::~TextureManager()
|
||||
{
|
||||
}
|
||||
TextureManager::~TextureManager()
|
||||
{
|
||||
}
|
||||
|
||||
void TextureManager::add(const std::string& path, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
void TextureManager::add(const std::string& path, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
// Construct (key, value) pair and insert it into the unordered_map
|
||||
m_textureList.emplace(std::move(path), std::move(texture));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> TextureManager::load(const std::string& path)
|
||||
{
|
||||
std::shared_ptr<Texture> TextureManager::load(const std::string& path)
|
||||
{
|
||||
if (exists(path)) {
|
||||
return get(path);
|
||||
}
|
||||
@@ -128,30 +128,30 @@ namespace Inferno {
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>(path);
|
||||
add(path, texture);
|
||||
return get(path);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> TextureManager::get(const std::string& path)
|
||||
{
|
||||
std::shared_ptr<Texture> TextureManager::get(const std::string& path)
|
||||
{
|
||||
return exists(path) ? m_textureList.at(path) : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextureManager::exists(const std::string& path)
|
||||
{
|
||||
bool TextureManager::exists(const std::string& path)
|
||||
{
|
||||
return m_textureList.find(path) != m_textureList.end();
|
||||
}
|
||||
}
|
||||
|
||||
void TextureManager::remove(const std::string& path)
|
||||
{
|
||||
void TextureManager::remove(const std::string& path)
|
||||
{
|
||||
if (exists(path)) {
|
||||
m_textureList.erase(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextureManager::remove(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
void TextureManager::remove(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
if (exists(texture->path())) {
|
||||
m_textureList.erase(texture->path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Texture {
|
||||
public:
|
||||
class Texture {
|
||||
public:
|
||||
Texture(const std::string& path);
|
||||
virtual ~Texture();
|
||||
|
||||
@@ -24,22 +24,22 @@ namespace Inferno {
|
||||
inline uint32_t internalFormat() const { return m_internalFormat; }
|
||||
inline uint32_t dataFormat() const { return m_dataFormat; }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void create(unsigned char* data);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string m_path;
|
||||
uint32_t m_width;
|
||||
uint32_t m_height;
|
||||
uint32_t m_id;
|
||||
uint32_t m_internalFormat;
|
||||
uint32_t m_dataFormat;
|
||||
};
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class TextureManager final : public ruc::Singleton<TextureManager> {
|
||||
public:
|
||||
class TextureManager final : public ruc::Singleton<TextureManager> {
|
||||
public:
|
||||
TextureManager(s);
|
||||
virtual ~TextureManager();
|
||||
|
||||
@@ -51,8 +51,8 @@ namespace Inferno {
|
||||
void remove(const std::string& path);
|
||||
void remove(std::shared_ptr<Texture> texture);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Texture>> m_textureList;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+28
-28
@@ -17,8 +17,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
void Scene::initialize()
|
||||
{
|
||||
void Scene::initialize()
|
||||
{
|
||||
// Initialize
|
||||
// ---------------------------------
|
||||
|
||||
@@ -68,60 +68,60 @@ namespace Inferno {
|
||||
// addComponent<TextAreaComponent>(text, "@#$%^&*()qygij!", "assets/fnt/dejavu-sans-test", 0, 150, 3);
|
||||
|
||||
info() << "Scene initialized";
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::update(float deltaTime)
|
||||
{
|
||||
void Scene::update(float deltaTime)
|
||||
{
|
||||
ScriptSystem::the().update(deltaTime);
|
||||
|
||||
TransformSystem::the().update();
|
||||
CameraSystem::the().update();
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::render()
|
||||
{
|
||||
void Scene::render()
|
||||
{
|
||||
RenderSystem::the().render();
|
||||
TextAreaSystem::the().render();
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::destroy()
|
||||
{
|
||||
void Scene::destroy()
|
||||
{
|
||||
ScriptSystem::destroy();
|
||||
RenderSystem::destroy();
|
||||
CameraSystem::destroy();
|
||||
TransformSystem::destroy();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Scene::createEntity(const std::string& name)
|
||||
{
|
||||
uint32_t Scene::createEntity(const std::string& name)
|
||||
{
|
||||
uint32_t entity = static_cast<uint32_t>(m_registry->create());
|
||||
addComponent<TagComponent>(entity, name.empty() ? "Unnamed Entity" : name);
|
||||
addComponent<TransformComponent>(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::destroyEntity(uint32_t entity)
|
||||
{
|
||||
void Scene::destroyEntity(uint32_t entity)
|
||||
{
|
||||
ScriptSystem::the().cleanup(entity);
|
||||
m_registry->destroy(entt::entity { entity });
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 Scene::cameraProjectionView()
|
||||
{
|
||||
glm::mat4 Scene::cameraProjectionView()
|
||||
{
|
||||
return CameraSystem::the().projectionView();
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::validEntity(uint32_t entity) const
|
||||
{
|
||||
void Scene::validEntity(uint32_t entity) const
|
||||
{
|
||||
VERIFY(m_registry->valid(entt::entity { entity }), "Entity is not valid");
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, entt::entity entity)
|
||||
{
|
||||
const LogStream& operator<<(const LogStream& stream, entt::entity entity)
|
||||
{
|
||||
return stream << static_cast<uint32_t>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Camera;
|
||||
class Texture;
|
||||
class Camera;
|
||||
class Texture;
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
class Scene {
|
||||
public:
|
||||
void initialize();
|
||||
void update(float deltaTime);
|
||||
void render();
|
||||
@@ -67,16 +67,16 @@ namespace Inferno {
|
||||
// const entt::registry& registry() const { return m_registry; }
|
||||
std::shared_ptr<entt::registry> registry() const { return m_registry; }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<Texture> m_texture;
|
||||
std::shared_ptr<Texture> m_texture2;
|
||||
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, entt::entity handle);
|
||||
const LogStream& operator<<(const LogStream& stream, entt::entity handle);
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
void CameraController::updateOrthographic(float deltaTime)
|
||||
{
|
||||
void CameraController::updateOrthographic(float deltaTime)
|
||||
{
|
||||
// Update camera rotation
|
||||
|
||||
float cameraRotateSpeed = ROTATE_SPEED * deltaTime;
|
||||
@@ -62,10 +62,10 @@ namespace Inferno {
|
||||
}
|
||||
m_camera->zoomLevel = std::max(m_camera->zoomLevel, 0.25f);
|
||||
m_camera->zoomLevel = std::min(m_camera->zoomLevel, 10.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void CameraController::updatePerspective(float deltaTime)
|
||||
{
|
||||
void CameraController::updatePerspective(float deltaTime)
|
||||
{
|
||||
// Get mouse movement offset compared to last frame
|
||||
float xOffset = Input::getXOffset() * MOUSE_SENSITIVITY;
|
||||
float yOffset = Input::getYOffset() * MOUSE_SENSITIVITY;
|
||||
@@ -73,8 +73,10 @@ namespace Inferno {
|
||||
m_camera->pitch += yOffset;
|
||||
|
||||
// Prevent gimbal lock
|
||||
if (m_camera->pitch > 89.0f) m_camera->pitch = 89.0f;
|
||||
if (m_camera->pitch < -89.0f) m_camera->pitch = -89.0f;
|
||||
if (m_camera->pitch > 89.0f)
|
||||
m_camera->pitch = 89.0f;
|
||||
if (m_camera->pitch < -89.0f)
|
||||
m_camera->pitch = -89.0f;
|
||||
|
||||
// Update camera rotation, by calculating direction vector via yaw and pitch
|
||||
|
||||
@@ -118,5 +120,5 @@ namespace Inferno {
|
||||
if (Input::isKeyPressed(keyCode("GLFW_KEY_LEFT_SHIFT"))) {
|
||||
transform->translate.y -= cameraSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct CameraComponent;
|
||||
struct CameraComponent;
|
||||
|
||||
class CameraController final : public NativeScript {
|
||||
public:
|
||||
class CameraController final : public NativeScript {
|
||||
public:
|
||||
virtual void update(float deltaTime) override
|
||||
{
|
||||
m_camera = &getComponent<CameraComponent>();
|
||||
@@ -29,8 +29,8 @@ namespace Inferno {
|
||||
void updateOrthographic(float deltaTime);
|
||||
void updatePerspective(float deltaTime);
|
||||
|
||||
private:
|
||||
private:
|
||||
CameraComponent* m_camera { nullptr };
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
void LuaScript::initialize()
|
||||
{
|
||||
void LuaScript::initialize()
|
||||
{
|
||||
// Type registration
|
||||
// ---------------------------------
|
||||
|
||||
@@ -48,32 +48,32 @@ namespace Inferno {
|
||||
loadScript();
|
||||
|
||||
callFunction("LuaScript", "initialize");
|
||||
}
|
||||
}
|
||||
|
||||
void LuaScript::destroy()
|
||||
{
|
||||
void LuaScript::destroy()
|
||||
{
|
||||
callFunction("LuaScript", "destroy");
|
||||
}
|
||||
}
|
||||
|
||||
void LuaScript::update(float deltaTime)
|
||||
{
|
||||
void LuaScript::update(float deltaTime)
|
||||
{
|
||||
m_state["LuaScript"]["transform"] = &m_scene->getComponent<TransformComponent>(m_entity);
|
||||
callFunction("LuaScript", "update", deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void LuaScript::loadScript()
|
||||
{
|
||||
void LuaScript::loadScript()
|
||||
{
|
||||
std::string script = File::read(m_path);
|
||||
auto result = m_state.script(script.c_str(),
|
||||
[](lua_State*, sol::protected_function_result pfr) { return pfr; });
|
||||
VERIFY(result.valid(), "LuaScript {}", ((sol::error)result).what());
|
||||
}
|
||||
}
|
||||
|
||||
sol::table LuaScript::getTable(const char* name)
|
||||
{
|
||||
sol::table LuaScript::getTable(const char* name)
|
||||
{
|
||||
sol::table table = m_state[name];
|
||||
VERIFY(table.valid(), "LuaScript table does not exist");
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -12,19 +12,19 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TransformComponent;
|
||||
struct TransformComponent;
|
||||
|
||||
class Scene;
|
||||
class Scene;
|
||||
|
||||
class LuaScript {
|
||||
public:
|
||||
class LuaScript {
|
||||
public:
|
||||
void initialize();
|
||||
void destroy();
|
||||
void update(float deltaTime);
|
||||
|
||||
void loadScript();
|
||||
|
||||
private:
|
||||
private:
|
||||
sol::table getTable(const char* name);
|
||||
|
||||
template<typename... P>
|
||||
@@ -48,6 +48,6 @@ namespace Inferno {
|
||||
TransformComponent* transform { nullptr };
|
||||
|
||||
friend class ScriptSystem;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TransformComponent;
|
||||
struct TransformComponent;
|
||||
|
||||
class NativeScript {
|
||||
public:
|
||||
class NativeScript {
|
||||
public:
|
||||
virtual ~NativeScript() {}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void initialize() {}
|
||||
virtual void destroy() {}
|
||||
virtual void update(float deltaTime) { (void)deltaTime; }
|
||||
@@ -23,11 +23,11 @@ namespace Inferno {
|
||||
|
||||
TransformComponent* transform { nullptr };
|
||||
|
||||
private:
|
||||
private:
|
||||
Scene* m_scene { nullptr };
|
||||
uint32_t m_entity { 0 };
|
||||
|
||||
friend class ScriptSystem;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "glm/ext/matrix_transform.hpp" // glm::radians
|
||||
#include "glm/ext/vector_float2.hpp" // glm::vec2
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||
#include "glm/ext/vector_float4.hpp" // glm::vec4
|
||||
#include "glm/ext/matrix_transform.hpp" // glm::radians
|
||||
|
||||
#include "inferno/component/cameracomponent.h"
|
||||
#include "inferno/component/spritecomponent.h"
|
||||
@@ -13,15 +13,15 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
void Registration::fill(sol::state_view &state)
|
||||
{
|
||||
void Registration::fill(sol::state_view& state)
|
||||
{
|
||||
glm(state);
|
||||
component(state);
|
||||
input(state);
|
||||
}
|
||||
}
|
||||
|
||||
void Registration::glm(sol::state_view& state)
|
||||
{
|
||||
void Registration::glm(sol::state_view& state)
|
||||
{
|
||||
auto glm = state["glm"].get_or_create<sol::table>();
|
||||
|
||||
auto vec2 = glm.new_usertype<glm::vec2>(
|
||||
@@ -34,8 +34,7 @@ namespace Inferno {
|
||||
"__sub", subtraction<glm::vec2, float>(),
|
||||
"__mul", multiplication<glm::vec2, float>(),
|
||||
"__div", division<glm::vec2, float>(),
|
||||
"__tostring", string<glm::vec2>
|
||||
);
|
||||
"__tostring", string<glm::vec2>);
|
||||
|
||||
auto vec3 = glm.new_usertype<glm::vec3>(
|
||||
"vec3",
|
||||
@@ -47,8 +46,7 @@ namespace Inferno {
|
||||
"__sub", subtraction<glm::vec3, float>(),
|
||||
"__mul", multiplication<glm::vec3, float>(),
|
||||
"__div", division<glm::vec3, float>(),
|
||||
"__tostring", string<glm::vec3>
|
||||
);
|
||||
"__tostring", string<glm::vec3>);
|
||||
|
||||
auto vec4 = glm.new_usertype<glm::vec4>(
|
||||
"vec4",
|
||||
@@ -60,27 +58,24 @@ namespace Inferno {
|
||||
"__sub", subtraction<glm::vec4, float>(),
|
||||
"__mul", multiplication<glm::vec4, float>(),
|
||||
"__div", division<glm::vec4, float>(),
|
||||
"__tostring", string<glm::vec4>
|
||||
);
|
||||
"__tostring", string<glm::vec4>);
|
||||
|
||||
glm.set_function("radians", sol::overload(
|
||||
[](float v) { return glm::radians(v); },
|
||||
[](const glm::vec2& v) { return glm::radians(v); },
|
||||
[](const glm::vec3& v) { return glm::radians(v); },
|
||||
[](const glm::vec4& v) { return glm::radians(v); }
|
||||
));
|
||||
[](const glm::vec4& v) { return glm::radians(v); }));
|
||||
|
||||
glm.set_function("normalize", sol::overload(
|
||||
[](const glm::vec2& v) { return glm::normalize(v); },
|
||||
[](const glm::vec3& v) { return glm::normalize(v); },
|
||||
[](const glm::vec4& v) { return glm::normalize(v); }
|
||||
));
|
||||
[](const glm::vec4& v) { return glm::normalize(v); }));
|
||||
|
||||
glm.set_function("cross", [](const glm::vec3& x, const glm::vec3& y) { return glm::cross(x, y); });
|
||||
}
|
||||
}
|
||||
|
||||
void Registration::component(sol::state_view& state)
|
||||
{
|
||||
void Registration::component(sol::state_view& state)
|
||||
{
|
||||
auto tagComponent = state.new_usertype<TagComponent>("TagComponent", sol::no_constructor);
|
||||
tagComponent["tag"] = &TagComponent::tag;
|
||||
|
||||
@@ -108,15 +103,15 @@ namespace Inferno {
|
||||
auto spriteComponent = state.new_usertype<SpriteComponent>("SpriteComponent", sol::no_constructor);
|
||||
spriteComponent["color"] = &SpriteComponent::color;
|
||||
spriteComponent["texture"] = &SpriteComponent::texture;
|
||||
}
|
||||
}
|
||||
|
||||
void Registration::input(sol::state_view& state)
|
||||
{
|
||||
void Registration::input(sol::state_view& state)
|
||||
{
|
||||
state.set_function("keyCode", &keyCode);
|
||||
|
||||
auto input = state.new_usertype<Input>("Input", sol::no_constructor);
|
||||
input["isKeyPressed"] = &Input::isKeyPressed;
|
||||
input["getXOffset"] = &Input::getXOffset;
|
||||
input["getYOffset"] = &Input::getYOffset;
|
||||
}
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Registration final {
|
||||
public:
|
||||
class Registration final {
|
||||
public:
|
||||
static void fill(sol::state_view& state);
|
||||
|
||||
private:
|
||||
private:
|
||||
static void glm(sol::state_view& state);
|
||||
static void component(sol::state_view& state);
|
||||
static void input(sol::state_view& state);
|
||||
@@ -22,8 +22,7 @@ namespace Inferno {
|
||||
return sol::overload(
|
||||
[](const T& lhs, const T& rhs) { return lhs + rhs; },
|
||||
[](const T& lhs, const V& rhs) { return lhs + rhs; },
|
||||
[](const V& lhs, const T& rhs) { return lhs + rhs; }
|
||||
);
|
||||
[](const V& lhs, const T& rhs) { return lhs + rhs; });
|
||||
}
|
||||
|
||||
template<typename T, typename V>
|
||||
@@ -32,8 +31,7 @@ namespace Inferno {
|
||||
return sol::overload(
|
||||
[](const T& lhs, const T& rhs) { return lhs - rhs; },
|
||||
[](const T& lhs, const V& rhs) { return lhs - rhs; },
|
||||
[](const V& lhs, const T& rhs) { return lhs - rhs; }
|
||||
);
|
||||
[](const V& lhs, const T& rhs) { return lhs - rhs; });
|
||||
}
|
||||
|
||||
template<typename T, typename V>
|
||||
@@ -42,8 +40,7 @@ namespace Inferno {
|
||||
return sol::overload(
|
||||
[](const T& lhs, const T& rhs) { return lhs * rhs; },
|
||||
[](const T& lhs, const V& rhs) { return lhs * rhs; },
|
||||
[](const V& lhs, const T& rhs) { return lhs * rhs; }
|
||||
);
|
||||
[](const V& lhs, const T& rhs) { return lhs * rhs; });
|
||||
}
|
||||
|
||||
template<typename T, typename V>
|
||||
@@ -52,8 +49,7 @@ namespace Inferno {
|
||||
return sol::overload(
|
||||
[](const T& lhs, const T& rhs) { return lhs / rhs; },
|
||||
[](const T& lhs, const V& rhs) { return lhs / rhs; },
|
||||
[](const V& lhs, const T& rhs) { return lhs / rhs; }
|
||||
);
|
||||
[](const V& lhs, const T& rhs) { return lhs / rhs; });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -63,6 +59,6 @@ namespace Inferno {
|
||||
str(&result) << t;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+27
-27
@@ -10,24 +10,24 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
const char* Settings::m_path { "assets/settings.json" };
|
||||
SettingsProperties Settings::m_properties {};
|
||||
const char* Settings::m_path { "assets/settings.json" };
|
||||
SettingsProperties Settings::m_properties {};
|
||||
|
||||
void Settings::initialize()
|
||||
{
|
||||
void Settings::initialize()
|
||||
{
|
||||
Settings::load();
|
||||
|
||||
info() << "Settings initialized";
|
||||
|
||||
Settings::save();
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::destroy()
|
||||
{
|
||||
}
|
||||
void Settings::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
bool Settings::load()
|
||||
{
|
||||
bool Settings::load()
|
||||
{
|
||||
ruc::Json object;
|
||||
|
||||
if (!File::ioRead(&object, m_path)) {
|
||||
@@ -38,10 +38,10 @@ namespace Inferno {
|
||||
m_properties = object.get<SettingsProperties>();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Settings::save()
|
||||
{
|
||||
bool Settings::save()
|
||||
{
|
||||
ruc::Json object = m_properties;
|
||||
|
||||
if (!File::ioWrite(&object, m_path)) {
|
||||
@@ -51,27 +51,27 @@ namespace Inferno {
|
||||
|
||||
info() << "Settings saved";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
void toJson(ruc::Json& object, const SettingsProperties& settings)
|
||||
{
|
||||
void toJson(ruc::Json& object, const SettingsProperties& settings)
|
||||
{
|
||||
object = ruc::Json {
|
||||
{ "window", settings.window }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void fromJson(const ruc::Json& object, SettingsProperties& settings)
|
||||
{
|
||||
void fromJson(const ruc::Json& object, SettingsProperties& settings)
|
||||
{
|
||||
VERIFY(object.type() == ruc::Json::Type::Object);
|
||||
|
||||
if (object.exists("window"))
|
||||
object.at("window").getTo(settings.window);
|
||||
}
|
||||
}
|
||||
|
||||
void toJson(ruc::Json& object, const WindowProperties& window)
|
||||
{
|
||||
void toJson(ruc::Json& object, const WindowProperties& window)
|
||||
{
|
||||
object = ruc::Json {
|
||||
{ "title", window.title },
|
||||
{ "width", window.width },
|
||||
@@ -79,10 +79,10 @@ namespace Inferno {
|
||||
{ "fullscreen", window.fullscreen },
|
||||
{ "vsync", window.vsync },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void fromJson(const ruc::Json& object, WindowProperties& window)
|
||||
{
|
||||
void fromJson(const ruc::Json& object, WindowProperties& window)
|
||||
{
|
||||
VERIFY(object.type() == ruc::Json::Type::Object);
|
||||
|
||||
if (object.exists("title"))
|
||||
@@ -95,6 +95,6 @@ namespace Inferno {
|
||||
object.at("fullscreen").getTo(window.fullscreen);
|
||||
if (object.exists("vsync"))
|
||||
object.at("vsync").getTo(window.vsync);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+11
-11
@@ -6,12 +6,12 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct SettingsProperties {
|
||||
struct SettingsProperties {
|
||||
WindowProperties window;
|
||||
};
|
||||
};
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
class Settings {
|
||||
public:
|
||||
static void initialize();
|
||||
static void destroy();
|
||||
|
||||
@@ -20,19 +20,19 @@ namespace Inferno {
|
||||
|
||||
static inline SettingsProperties& get() { return m_properties; }
|
||||
|
||||
private:
|
||||
private:
|
||||
static const char* m_path;
|
||||
static SettingsProperties m_properties;
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// Json arbitrary type conversion functions
|
||||
// Json arbitrary type conversion functions
|
||||
|
||||
void toJson(ruc::Json& object, const SettingsProperties& settings);
|
||||
void fromJson(const ruc::Json& object, SettingsProperties& settings);
|
||||
void toJson(ruc::Json& object, const SettingsProperties& settings);
|
||||
void fromJson(const ruc::Json& object, SettingsProperties& settings);
|
||||
|
||||
void toJson(ruc::Json& object, const WindowProperties& window);
|
||||
void fromJson(const ruc::Json& object, WindowProperties& window);
|
||||
void toJson(ruc::Json& object, const WindowProperties& window);
|
||||
void fromJson(const ruc::Json& object, WindowProperties& window);
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
template<typename T>
|
||||
class Singleton {
|
||||
template<typename T>
|
||||
class Singleton {
|
||||
// Application is allowed to access its Singleton instance for early setting
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
public:
|
||||
static inline void initialize()
|
||||
{
|
||||
VERIFY(!s_instance, "singleton already exists");
|
||||
@@ -35,17 +35,17 @@ namespace Inferno {
|
||||
Singleton(Singleton&&) = delete;
|
||||
Singleton& operator=(Singleton&&) = delete;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
Singleton() {}
|
||||
|
||||
// Constructor token
|
||||
struct s {};
|
||||
|
||||
private:
|
||||
private:
|
||||
static T* s_instance;
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T* Singleton<T>::s_instance = nullptr;
|
||||
template<typename T>
|
||||
T* Singleton<T>::s_instance = nullptr;
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
CameraSystem::CameraSystem(s)
|
||||
{
|
||||
CameraSystem::CameraSystem(s)
|
||||
{
|
||||
info() << "CameraSystem initialized";
|
||||
}
|
||||
}
|
||||
|
||||
CameraSystem::~CameraSystem()
|
||||
{
|
||||
}
|
||||
CameraSystem::~CameraSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void CameraSystem::update()
|
||||
{
|
||||
void CameraSystem::update()
|
||||
{
|
||||
auto view = m_registry->view<TransformComponent, CameraComponent>();
|
||||
|
||||
for (auto [entity, transform, camera] : view.each()) {
|
||||
@@ -34,10 +34,10 @@ namespace Inferno {
|
||||
updatePerspective(transform, camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 CameraSystem::projectionView()
|
||||
{
|
||||
glm::mat4 CameraSystem::projectionView()
|
||||
{
|
||||
auto view = m_registry->view<TransformComponent, CameraComponent>();
|
||||
|
||||
for (auto [entity, transform, camera] : view.each()) {
|
||||
@@ -47,10 +47,10 @@ namespace Inferno {
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
return glm::mat4 { 1.0f };
|
||||
}
|
||||
}
|
||||
|
||||
void CameraSystem::updateOrthographic(TransformComponent& transform, CameraComponent& camera)
|
||||
{
|
||||
void CameraSystem::updateOrthographic(TransformComponent& transform, CameraComponent& camera)
|
||||
{
|
||||
// Update camera matrix
|
||||
|
||||
// Local space -> World space: model matrix
|
||||
@@ -58,8 +58,7 @@ namespace Inferno {
|
||||
|
||||
// World space -> View space: view matrix
|
||||
transform.transform = {
|
||||
glm::translate(glm::mat4(1.0f), transform.translate) *
|
||||
glm::rotate(glm::mat4(1.0f), glm::radians(transform.rotate.z), camera.rotateAxis)
|
||||
glm::translate(glm::mat4(1.0f), transform.translate) * glm::rotate(glm::mat4(1.0f), glm::radians(transform.rotate.z), camera.rotateAxis)
|
||||
};
|
||||
transform.transform = { glm::inverse(transform.transform) };
|
||||
|
||||
@@ -72,10 +71,10 @@ namespace Inferno {
|
||||
|
||||
// Clip space -> Screen space: viewport transform
|
||||
// Is done in the fragment shader using the settings of glViewport
|
||||
}
|
||||
}
|
||||
|
||||
void CameraSystem::updatePerspective(TransformComponent& transform, CameraComponent& camera)
|
||||
{
|
||||
void CameraSystem::updatePerspective(TransformComponent& transform, CameraComponent& camera)
|
||||
{
|
||||
// Update camera matrix
|
||||
|
||||
// Local space -> World space: model matrix
|
||||
@@ -92,6 +91,6 @@ namespace Inferno {
|
||||
// Is done in the fragment shader using the settings of glViewport
|
||||
|
||||
// Souce: https://learnopengl.com/img/getting-started/coordinate_systems.png
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct TransformComponent;
|
||||
struct CameraComponent;
|
||||
struct TransformComponent;
|
||||
struct CameraComponent;
|
||||
|
||||
class CameraSystem final : public ruc::Singleton<CameraSystem> {
|
||||
public:
|
||||
class CameraSystem final : public ruc::Singleton<CameraSystem> {
|
||||
public:
|
||||
CameraSystem(s);
|
||||
virtual ~CameraSystem();
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace Inferno {
|
||||
|
||||
void setRegistry(std::shared_ptr<entt::registry> registry) { m_registry = registry; };
|
||||
|
||||
private:
|
||||
private:
|
||||
void updateOrthographic(TransformComponent& transform, CameraComponent& camera);
|
||||
void updatePerspective(TransformComponent& transform, CameraComponent& camera);
|
||||
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -8,22 +8,22 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
RenderSystem::RenderSystem(s)
|
||||
{
|
||||
RenderSystem::RenderSystem(s)
|
||||
{
|
||||
info() << "RenderSystem initialized";
|
||||
}
|
||||
}
|
||||
|
||||
RenderSystem::~RenderSystem()
|
||||
{
|
||||
}
|
||||
RenderSystem::~RenderSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void RenderSystem::render()
|
||||
{
|
||||
void RenderSystem::render()
|
||||
{
|
||||
auto group = m_registry->group<TransformComponent, SpriteComponent>();
|
||||
|
||||
for (auto [entity, transform, sprite] : group.each()) {
|
||||
Renderer2D::the().drawQuad(transform, sprite.color, sprite.texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class RenderSystem final : public ruc::Singleton<RenderSystem> {
|
||||
public:
|
||||
class RenderSystem final : public ruc::Singleton<RenderSystem> {
|
||||
public:
|
||||
RenderSystem(s);
|
||||
virtual ~RenderSystem();
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace Inferno {
|
||||
|
||||
void setRegistry(std::shared_ptr<entt::registry> registry) { m_registry = registry; };
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
ScriptSystem::ScriptSystem(s)
|
||||
{
|
||||
ScriptSystem::ScriptSystem(s)
|
||||
{
|
||||
info() << "ScriptSystem initialized";
|
||||
}
|
||||
}
|
||||
|
||||
ScriptSystem::~ScriptSystem()
|
||||
{
|
||||
ScriptSystem::~ScriptSystem()
|
||||
{
|
||||
auto nativeScriptView = m_scene->registry()->view<NativeScriptComponent>();
|
||||
|
||||
for (auto entity : nativeScriptView) {
|
||||
@@ -29,10 +29,10 @@ namespace Inferno {
|
||||
for (auto entity : luaScriptView) {
|
||||
cleanup(luaScriptView.get<LuaScriptComponent>(entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptSystem::update(float deltaTime)
|
||||
{
|
||||
void ScriptSystem::update(float deltaTime)
|
||||
{
|
||||
// @Todo figure out why group doesn't work here
|
||||
auto nativeScriptView = m_scene->registry()->view<TransformComponent, NativeScriptComponent>();
|
||||
|
||||
@@ -67,10 +67,10 @@ namespace Inferno {
|
||||
|
||||
luaScript.instance->update(deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptSystem::cleanup(uint32_t entity)
|
||||
{
|
||||
void ScriptSystem::cleanup(uint32_t entity)
|
||||
{
|
||||
if (m_scene->hasComponent<NativeScriptComponent>(entity)) {
|
||||
auto& nativeScript = m_scene->getComponent<NativeScriptComponent>(entity);
|
||||
cleanup(nativeScript);
|
||||
@@ -80,22 +80,22 @@ namespace Inferno {
|
||||
auto& luaScript = m_scene->getComponent<LuaScriptComponent>(entity);
|
||||
cleanup(luaScript);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptSystem::cleanup(NativeScriptComponent& nativeScript)
|
||||
{
|
||||
void ScriptSystem::cleanup(NativeScriptComponent& nativeScript)
|
||||
{
|
||||
if (nativeScript.instance) {
|
||||
nativeScript.instance->destroy();
|
||||
nativeScript.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptSystem::cleanup(LuaScriptComponent& luaScript)
|
||||
{
|
||||
void ScriptSystem::cleanup(LuaScriptComponent& luaScript)
|
||||
{
|
||||
if (luaScript.instance) {
|
||||
luaScript.instance->destroy();
|
||||
delete luaScript.instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
struct NativeScriptComponent;
|
||||
struct LuaScriptComponent;
|
||||
struct NativeScriptComponent;
|
||||
struct LuaScriptComponent;
|
||||
|
||||
class Scene;
|
||||
class Scene;
|
||||
|
||||
class ScriptSystem final : public ruc::Singleton<ScriptSystem> {
|
||||
public:
|
||||
class ScriptSystem final : public ruc::Singleton<ScriptSystem> {
|
||||
public:
|
||||
ScriptSystem(s);
|
||||
virtual ~ScriptSystem();
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace Inferno {
|
||||
|
||||
void setScene(Scene* scene) { m_scene = scene; }
|
||||
|
||||
private:
|
||||
private:
|
||||
Scene* m_scene { nullptr };
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
TextAreaSystem::TextAreaSystem(s)
|
||||
{
|
||||
TextAreaSystem::TextAreaSystem(s)
|
||||
{
|
||||
info() << "TextAreaSystem initialized";
|
||||
}
|
||||
}
|
||||
|
||||
TextAreaSystem::~TextAreaSystem()
|
||||
{
|
||||
}
|
||||
TextAreaSystem::~TextAreaSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void TextAreaSystem::render()
|
||||
{
|
||||
void TextAreaSystem::render()
|
||||
{
|
||||
auto view = m_scene->registry()->view<TransformComponent, TextAreaComponent>();
|
||||
|
||||
glm::ivec2 viewport = {
|
||||
@@ -48,10 +48,10 @@ namespace Inferno {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<CharacterQuad> TextAreaSystem::calculateCharacterQuad(unsigned char character, std::shared_ptr<Font> font, float& advance)
|
||||
{
|
||||
std::optional<CharacterQuad> TextAreaSystem::calculateCharacterQuad(unsigned char character, std::shared_ptr<Font> font, float& advance)
|
||||
{
|
||||
CharacterQuad characterQuad;
|
||||
|
||||
auto c = font->get(character);
|
||||
@@ -113,6 +113,6 @@ namespace Inferno {
|
||||
characterQuad.at(3).quad.textureCoordinates = { x.x, y.y };
|
||||
|
||||
return characterQuad;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
using CharacterQuad = std::array<CharacterVertex, Renderer::vertexPerQuad>;
|
||||
using CharacterQuad = std::array<CharacterVertex, Renderer::vertexPerQuad>;
|
||||
|
||||
class Font;
|
||||
class Scene;
|
||||
class Font;
|
||||
class Scene;
|
||||
|
||||
class TextAreaSystem final : public ruc::Singleton<TextAreaSystem> {
|
||||
public:
|
||||
class TextAreaSystem final : public ruc::Singleton<TextAreaSystem> {
|
||||
public:
|
||||
TextAreaSystem(s);
|
||||
virtual ~TextAreaSystem();
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace Inferno {
|
||||
|
||||
void setScene(Scene* scene) { m_scene = scene; }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::optional<CharacterQuad> calculateCharacterQuad(unsigned char character, std::shared_ptr<Font> font, float& advance);
|
||||
|
||||
Scene* m_scene { nullptr };
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
TransformSystem::TransformSystem(s)
|
||||
{
|
||||
TransformSystem::TransformSystem(s)
|
||||
{
|
||||
info() << "TransformSystem initialized";
|
||||
}
|
||||
}
|
||||
|
||||
TransformSystem::~TransformSystem()
|
||||
{
|
||||
}
|
||||
TransformSystem::~TransformSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void TransformSystem::update()
|
||||
{
|
||||
void TransformSystem::update()
|
||||
{
|
||||
auto view = m_registry->view<TransformComponent>();
|
||||
|
||||
for (auto entity : view) {
|
||||
@@ -30,13 +30,13 @@ namespace Inferno {
|
||||
component.transform = glm::translate(component.transform, component.translate);
|
||||
|
||||
// Rotate
|
||||
component.transform = glm::rotate(component.transform, glm::radians(component.rotate.x), {1.0, 0.0, 0.0});
|
||||
component.transform = glm::rotate(component.transform, glm::radians(component.rotate.y), {0.0, 1.0, 0.0});
|
||||
component.transform = glm::rotate(component.transform, glm::radians(component.rotate.z), {0.0, 0.0, 1.0});
|
||||
component.transform = glm::rotate(component.transform, glm::radians(component.rotate.x), { 1.0, 0.0, 0.0 });
|
||||
component.transform = glm::rotate(component.transform, glm::radians(component.rotate.y), { 0.0, 1.0, 0.0 });
|
||||
component.transform = glm::rotate(component.transform, glm::radians(component.rotate.z), { 0.0, 0.0, 1.0 });
|
||||
|
||||
// Scale
|
||||
component.transform = glm::scale(component.transform, component.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class TransformSystem final : public ruc::Singleton<TransformSystem> {
|
||||
public:
|
||||
class TransformSystem final : public ruc::Singleton<TransformSystem> {
|
||||
public:
|
||||
TransformSystem(s);
|
||||
virtual ~TransformSystem();
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace Inferno {
|
||||
|
||||
void setRegistry(std::shared_ptr<entt::registry> registry) { m_registry = registry; };
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
float Time::time()
|
||||
{
|
||||
float Time::time()
|
||||
{
|
||||
return static_cast<float>(glfwGetTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Time {
|
||||
public:
|
||||
class Time {
|
||||
public:
|
||||
static float time();
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
|
||||
namespace std {
|
||||
|
||||
// Can't believe this is not in the standard library
|
||||
// Can't believe this is not in the standard library
|
||||
|
||||
inline uint32_t stou(const std::string& string)
|
||||
{
|
||||
inline uint32_t stou(const std::string& string)
|
||||
{
|
||||
unsigned long size = std::stoul(string);
|
||||
VERIFY(size <= std::numeric_limits<uint32_t>::max(), "String util not in uint32_t range '{}'", string);
|
||||
return static_cast<uint32_t>(size);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint32_t stou(const char* string)
|
||||
{
|
||||
inline uint32_t stou(const char* string)
|
||||
{
|
||||
return stou(std::string(string));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#if 0
|
||||
#include <cstdint> // int32_t, uint32_t
|
||||
#include <optional> // std::optional
|
||||
#include <vector> // std::vector
|
||||
#include <cstdint> // int32_t, uint32_t
|
||||
#include <optional> // std::optional
|
||||
#include <vector> // std::vector
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "ruc/meta/assert.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "ruc/meta/assert.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
template<typename T>
|
||||
std::string intToHex(T i)
|
||||
{
|
||||
template<typename T>
|
||||
std::string intToHex(T i)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << "0x"
|
||||
<< std::setfill('0') << std::setw(sizeof(T) * 2)
|
||||
<< std::hex << i;
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+39
-38
@@ -18,10 +18,10 @@
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
unsigned char Window::s_windowCount = 0;
|
||||
unsigned char Window::s_windowCount = 0;
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
Window::Window()
|
||||
{
|
||||
m_properties = {
|
||||
Settings::get().window.title,
|
||||
Settings::get().window.width,
|
||||
@@ -31,17 +31,17 @@ namespace Inferno {
|
||||
};
|
||||
|
||||
this->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
Window::~Window()
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void Window::initialize()
|
||||
{
|
||||
void Window::initialize()
|
||||
{
|
||||
std::string title = m_properties.title;
|
||||
uint32_t width = m_properties.width;
|
||||
uint32_t height = m_properties.height;
|
||||
@@ -168,10 +168,10 @@ namespace Inferno {
|
||||
MouseScrollEvent event(xOffset, yOffset);
|
||||
w.m_eventCallback(event);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Window::destroy()
|
||||
{
|
||||
void Window::destroy()
|
||||
{
|
||||
m_context->destroy();
|
||||
|
||||
glfwDestroyWindow(m_window);
|
||||
@@ -180,10 +180,10 @@ namespace Inferno {
|
||||
if (s_windowCount == 0) {
|
||||
glfwTerminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::update()
|
||||
{
|
||||
void Window::update()
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
// Capture cursor in window and hide it
|
||||
@@ -193,27 +193,27 @@ namespace Inferno {
|
||||
else {
|
||||
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::render()
|
||||
{
|
||||
void Window::render()
|
||||
{
|
||||
m_context->render();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void Window::signalCallback(int signal)
|
||||
{
|
||||
void Window::signalCallback(int signal)
|
||||
{
|
||||
Application::the().setStatus(signal);
|
||||
|
||||
if (signal == SIGINT || signal == SIGTERM) {
|
||||
WindowCloseEvent e;
|
||||
Application::the().getWindow().m_eventCallback(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setWindowMonitor() const
|
||||
{
|
||||
void Window::setWindowMonitor() const
|
||||
{
|
||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||
int xPos = 0;
|
||||
int yPos = 0;
|
||||
@@ -241,21 +241,22 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
glfwSetWindowMonitor(m_window, monitor, xPos, yPos, width, height, refresh);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setVSync(bool enabled)
|
||||
{
|
||||
void Window::setVSync(bool enabled)
|
||||
{
|
||||
enabled ? glfwSwapInterval(GL_TRUE) : glfwSwapInterval(GL_FALSE);
|
||||
m_properties.vsync = enabled;
|
||||
}
|
||||
|
||||
void Window::setShouldClose(bool close) const
|
||||
{
|
||||
glfwSetWindowShouldClose(m_window, close ? GL_TRUE : GL_FALSE);
|
||||
}
|
||||
|
||||
bool Window::shouldClose() const {
|
||||
return glfwWindowShouldClose(m_window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Window::setShouldClose(bool close) const
|
||||
{
|
||||
glfwSetWindowShouldClose(m_window, close ? GL_TRUE : GL_FALSE);
|
||||
}
|
||||
|
||||
bool Window::shouldClose() const
|
||||
{
|
||||
return glfwWindowShouldClose(m_window);
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
+10
-10
@@ -9,30 +9,30 @@ struct GLFWwindow;
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Context;
|
||||
class Event;
|
||||
class Context;
|
||||
class Event;
|
||||
|
||||
struct WindowProperties {
|
||||
struct WindowProperties {
|
||||
std::string title { "Inferno" };
|
||||
uint32_t width = 1280;
|
||||
uint32_t height = 720;
|
||||
std::string fullscreen { "windowed" }; // windowed/fullscreen/borderless
|
||||
bool vsync = true;
|
||||
};
|
||||
};
|
||||
|
||||
class Window {
|
||||
public:
|
||||
class Window {
|
||||
public:
|
||||
Window();
|
||||
virtual ~Window();
|
||||
|
||||
// -----------------------------------------
|
||||
// -----------------------------------------
|
||||
|
||||
void initialize();
|
||||
void destroy();
|
||||
void update();
|
||||
void render();
|
||||
|
||||
// -----------------------------------------
|
||||
// -----------------------------------------
|
||||
|
||||
static void signalCallback(int signal);
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Inferno {
|
||||
|
||||
inline void setEventCallback(const std::function<void(Event&)>& callback) { m_eventCallback = callback; }
|
||||
|
||||
private:
|
||||
private:
|
||||
WindowProperties m_properties;
|
||||
GLFWwindow* m_window;
|
||||
std::shared_ptr<Context> m_context;
|
||||
@@ -58,6 +58,6 @@ namespace Inferno {
|
||||
std::function<void(Event&)> m_eventCallback;
|
||||
|
||||
static unsigned char s_windowCount;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
Reference in New Issue
Block a user