various cleanup
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "open_engine/input/keycodes.hpp"
|
||||
|
||||
#include "open_engine/renderer/render_command.hpp"
|
||||
#include "open_engine/renderer/subtexture2d.hpp"
|
||||
#include "open_engine/renderer/framebuffer.hpp"
|
||||
#include "open_engine/renderer/renderer2d.hpp"
|
||||
#include "open_engine/renderer/renderer.hpp"
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace OpenEngine {
|
||||
class Application
|
||||
{
|
||||
public:
|
||||
Application();
|
||||
Application(const std::string& name = "OpenEngine Project");
|
||||
~Application();
|
||||
|
||||
virtual void OnEvent(Event& event);
|
||||
@@ -26,7 +26,8 @@ namespace OpenEngine {
|
||||
inline static Application& Get() { return *instance; };
|
||||
|
||||
inline Window& GetWindow() { return *window; };
|
||||
inline void StopRunning() { running = false; };
|
||||
|
||||
void Close();
|
||||
|
||||
private:
|
||||
void Run();
|
||||
@@ -34,6 +35,7 @@ namespace OpenEngine {
|
||||
bool OnWindowResize(WindowResizeEvent& event);
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
std::unique_ptr<Window> window;
|
||||
|
||||
inline static Application* instance;
|
||||
|
||||
@@ -14,52 +14,25 @@ namespace OpenEngine {
|
||||
class Input
|
||||
{
|
||||
public:
|
||||
virtual ~Input() = default;
|
||||
Input(const Input&) = delete;
|
||||
Input& operator=(const Input&) = delete;
|
||||
static bool IsKeyPressed(KeyCode keycode);
|
||||
|
||||
inline static bool IsKeyPressed(KeyCode keycode) { return instance->IsKeyPressedImpl(keycode); };
|
||||
static bool IsMouseButtonPressed(MouseCode button);
|
||||
|
||||
inline static bool IsMouseButtonPressed(MouseCode button) { return instance->IsMouseButtonPressedImpl(button); };
|
||||
static std::pair<float, float> GetMousePosition();
|
||||
static float GetMouseX();
|
||||
static float GetMouseY();
|
||||
|
||||
inline static std::pair<float, float> GetMousePosition() { return instance->GetMousePositionImpl(); };
|
||||
inline static bool GetMouseX() { return instance->GetMouseXImpl(); };
|
||||
inline static bool GetMouseY() { return instance->GetMouseYImpl(); };
|
||||
static bool JoystickExists(unsigned int joystick);
|
||||
static std::map<unsigned int, std::string> GetJoystickList();
|
||||
|
||||
inline static bool JoystickExists(unsigned int joystick) { return instance->JoystickExistsImpl(joystick); };
|
||||
inline static std::map<unsigned int, std::string> GetJoystickList() { return instance->GetJoystickListImpl(); };
|
||||
static float GetJoystickAxis(unsigned int joystick, unsigned int axis);
|
||||
static const float* GetJoystickAxes(unsigned int joystick);
|
||||
static unsigned int GetJoystickAxesCount(unsigned int joystick);
|
||||
|
||||
inline static float GetJoystickAxis(unsigned int joystick, unsigned int axis) { return instance->GetJoystickAxisImpl(joystick, axis); };
|
||||
inline static const float* GetJoystickAxes(unsigned int joystick) { return instance->GetJoystickAxesImpl(joystick); };
|
||||
inline static unsigned int GetJoystickAxesCount(unsigned int joystick) { return instance->GetJoystickAxesCountImpl(joystick); };
|
||||
|
||||
inline static bool IsJoystickButtonPressed(unsigned int joystick, unsigned int button) { return instance->IsJoystickButtonPressedImpl(joystick, button); };
|
||||
|
||||
protected:
|
||||
Input() = default;
|
||||
|
||||
virtual bool IsKeyPressedImpl(KeyCode keycode) = 0;
|
||||
|
||||
virtual bool IsMouseButtonPressedImpl(MouseCode button) = 0;
|
||||
|
||||
virtual std::pair<float, float> GetMousePositionImpl() = 0;
|
||||
virtual float GetMouseXImpl() = 0;
|
||||
virtual float GetMouseYImpl() = 0;
|
||||
|
||||
virtual bool JoystickExistsImpl(unsigned int joystick) = 0;
|
||||
virtual std::map<unsigned int, std::string> GetJoystickListImpl() = 0;
|
||||
virtual const std::string GetJoystickNameImpl(unsigned int joystick) = 0;
|
||||
|
||||
virtual float GetJoystickAxisImpl(unsigned int joystick, unsigned int axis) = 0;
|
||||
virtual const float* GetJoystickAxesImpl(unsigned int joystick) = 0;
|
||||
virtual unsigned int GetJoystickAxesCountImpl(unsigned int joystick) = 0;
|
||||
|
||||
virtual bool IsJoystickButtonPressedImpl(unsigned int joystick, unsigned int button) = 0;
|
||||
static bool IsJoystickButtonPressed(unsigned int joystick, unsigned int button);
|
||||
|
||||
private:
|
||||
inline static const std::string GetJoystickName(unsigned int joystick) { return instance->GetJoystickNameImpl(joystick); };
|
||||
|
||||
static Scope<Input> instance;
|
||||
static const std::string GetJoystickName(unsigned int joystick);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef LINUX_INPUT_HPP
|
||||
#define LINUX_INPUT_HPP
|
||||
|
||||
#include "open_engine/input/input_system.hpp"
|
||||
#include "open_engine/input/keycodes.hpp"
|
||||
|
||||
namespace OpenEngine {
|
||||
class LinuxInput : public Input
|
||||
{
|
||||
protected:
|
||||
virtual bool IsKeyPressedImpl(KeyCode keycode) override;
|
||||
|
||||
virtual bool IsMouseButtonPressedImpl(MouseCode button) override;
|
||||
|
||||
virtual std::pair<float, float> GetMousePositionImpl() override;
|
||||
virtual float GetMouseXImpl() override;
|
||||
virtual float GetMouseYImpl() override;
|
||||
|
||||
virtual bool JoystickExistsImpl(unsigned int joystick) override;
|
||||
|
||||
virtual float GetJoystickAxisImpl(unsigned int joystick, unsigned int axis) override;
|
||||
virtual const std::string GetJoystickNameImpl(unsigned int joystick) override;
|
||||
|
||||
virtual std::map<unsigned int, std::string> GetJoystickListImpl() override;
|
||||
virtual const float* GetJoystickAxesImpl(unsigned int joystick) override;
|
||||
virtual unsigned int GetJoystickAxesCountImpl(unsigned int joystick) override;
|
||||
|
||||
virtual bool IsJoystickButtonPressedImpl(unsigned int joystick, unsigned int button) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LINUX_INPUT_HPP
|
||||
@@ -2,6 +2,7 @@
|
||||
#define RENDERER2D_HPP
|
||||
|
||||
#include "open_engine/orthographic_camera.hpp"
|
||||
#include "open_engine/renderer/subtexture2d.hpp"
|
||||
#include "open_engine/renderer/texture.hpp"
|
||||
#include "open_engine/ref_scope.hpp"
|
||||
|
||||
@@ -36,6 +37,7 @@ namespace OpenEngine {
|
||||
|
||||
static void DrawQuad(const Transform& transform_data, const glm::vec4& color);
|
||||
static void DrawQuad(const Transform& transform_data, const Ref<Texture2D>& texture, float tiling_factor = 1.0f);
|
||||
static void DrawQuad(const Transform& transform_data, const Ref<Subtexture2D>& subtexture, float tiling_factor = 1.0f);
|
||||
|
||||
static void ResetStats();
|
||||
static const Statistics& GetStats();
|
||||
|
||||
28
open_engine/include/open_engine/renderer/subtexture2d.hpp
Normal file
28
open_engine/include/open_engine/renderer/subtexture2d.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef SUBTEXTURE2D_HPP
|
||||
#define SUBTEXTURE2D_HPP
|
||||
|
||||
#include "open_engine/renderer/texture.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
class Subtexture2D
|
||||
{
|
||||
public:
|
||||
Subtexture2D(const Ref<Texture2D>& texture, glm::vec2& min, glm::vec2& max);
|
||||
|
||||
const Ref<Texture2D>& GetTexture() { return atlas; };
|
||||
const glm::vec2* GetCoords() { return coords; };
|
||||
|
||||
static Ref<Subtexture2D> CreateFromCoords(const Ref<Texture2D> texture,
|
||||
const glm::vec2& coordinates,
|
||||
const glm::vec2& cell_size,
|
||||
const glm::vec2& sprite_size = { 1.0f, 1.0f } );
|
||||
|
||||
private:
|
||||
Ref<Texture2D> atlas;
|
||||
glm::vec2 coords[4];
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SUBTEXTURE2D_HPP
|
||||
@@ -10,12 +10,12 @@ namespace OpenEngine {
|
||||
struct WindowProps
|
||||
{
|
||||
std::string title;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
WindowProps(const std::string& title = "OpenEngine",
|
||||
unsigned int width = 1280,
|
||||
unsigned int height = 729)
|
||||
uint32_t width = 1280,
|
||||
uint32_t height = 729)
|
||||
:title(title), width(width), height(height)
|
||||
{
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace OpenEngine {
|
||||
struct WindowData
|
||||
{
|
||||
std::string title;
|
||||
unsigned int width, height;
|
||||
uint32_t width, height;
|
||||
bool vsync;
|
||||
|
||||
EventCallbackFunction event_callback;
|
||||
@@ -39,8 +39,8 @@ namespace OpenEngine {
|
||||
|
||||
virtual void OnUpdate() = 0;
|
||||
|
||||
virtual unsigned int GetWidth() const = 0;
|
||||
virtual unsigned int GetHeight() const = 0;
|
||||
virtual uint32_t GetWidth() const = 0;
|
||||
virtual uint32_t GetHeight() const = 0;
|
||||
|
||||
virtual void SetEventCallback(const EventCallbackFunction& callback) = 0;
|
||||
virtual void SetVSync(bool enabled) = 0;
|
||||
|
||||
Reference in New Issue
Block a user