New scene items system
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include "RenderHost.hpp"
|
||||
#include "assert/assertgl.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "game/Game.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -13,15 +14,15 @@ RenderHost::RenderHost() {
|
||||
|
||||
}
|
||||
|
||||
void RenderHost::init() {
|
||||
void RenderHost::init(std::shared_ptr<Game> game) {
|
||||
// Init GLFW
|
||||
if(!glfwInit()) {
|
||||
throw std::runtime_error("Failed to initialize GLFW!");
|
||||
assertUnreachable("Failed to initialize GLFW!");
|
||||
}
|
||||
|
||||
// Set the error callback for error handling.
|
||||
glfwSetErrorCallback([](int error, const char *description) {
|
||||
throw std::runtime_error(description);
|
||||
assertUnreachable(description);
|
||||
});
|
||||
|
||||
// Setup window hints
|
||||
@ -41,9 +42,10 @@ void RenderHost::init() {
|
||||
);
|
||||
|
||||
// Validate window exists
|
||||
if(!window) {
|
||||
throw std::runtime_error("Failed to create GLFW window!");
|
||||
}
|
||||
if(!window) assertUnreachable("Failed to create GLFW window!");
|
||||
|
||||
// Setup the user pointer
|
||||
glfwSetWindowUserPointer(window, game.get());
|
||||
|
||||
// Load GLAD
|
||||
glfwMakeContextCurrent(window);
|
||||
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "display/IRenderHost.hpp"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
@ -12,7 +12,9 @@
|
||||
#define DAWN_GLFW_WINDOW_HEIGHT_DEFAULT 720
|
||||
|
||||
namespace Dawn {
|
||||
class RenderHost {
|
||||
class Game;
|
||||
|
||||
class RenderHost : public IRenderHost {
|
||||
public:
|
||||
GLFWwindow *window = nullptr;
|
||||
|
||||
@ -21,26 +23,12 @@ namespace Dawn {
|
||||
*/
|
||||
RenderHost();
|
||||
|
||||
/**
|
||||
* Initializes GLFW and creates the window.
|
||||
*/
|
||||
void init();
|
||||
void init(std::shared_ptr<Game> game) override;
|
||||
|
||||
/**
|
||||
* Performs an update and renders the frame.
|
||||
*/
|
||||
void update();
|
||||
void update() override;
|
||||
|
||||
/**
|
||||
* Returns whether or not GLFW has been requested to close.
|
||||
*
|
||||
* @return True if GLFW has been requested to close.
|
||||
*/
|
||||
bool_t isCloseRequested();
|
||||
bool_t isCloseRequested() override;
|
||||
|
||||
/**
|
||||
* Cleans up GLFW.
|
||||
*/
|
||||
virtual ~RenderHost();
|
||||
~RenderHost();
|
||||
};
|
||||
}
|
@ -9,11 +9,47 @@
|
||||
using namespace Dawn;
|
||||
|
||||
void InputManager::init(const std::shared_ptr<Game> game) {
|
||||
auto window = game->renderHost.window;
|
||||
|
||||
glfwSetCursorPosCallback(window, [](
|
||||
GLFWwindow* window,
|
||||
double_t x,
|
||||
double_t y
|
||||
) {
|
||||
auto game = (Game*)glfwGetWindowUserPointer(window);
|
||||
game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_X] = (float_t) x;
|
||||
game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_Y] = (float_t) y;
|
||||
});
|
||||
|
||||
glfwSetMouseButtonCallback(window, [](
|
||||
GLFWwindow* window,
|
||||
int32_t button,
|
||||
int32_t action,
|
||||
int32_t mods
|
||||
) {
|
||||
auto game = (Game*)glfwGetWindowUserPointer(window);
|
||||
game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_0 + button] = (
|
||||
action == GLFW_PRESS ? 1.0f : 0.0f
|
||||
);
|
||||
});
|
||||
|
||||
glfwSetMouseButtonCallback(window, [](
|
||||
GLFWwindow* window,
|
||||
int32_t button,
|
||||
int32_t action,
|
||||
int32_t mods
|
||||
) {
|
||||
auto game = (Game*)glfwGetWindowUserPointer(window);
|
||||
game->inputManager.rawInputValues[button] = (
|
||||
action == GLFW_PRESS ? 1.0f : 0.0f
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
float_t InputManager::getInputValue(int32_t axis) {
|
||||
return 0.0f;
|
||||
auto exist = rawInputValues.find(axis);
|
||||
if(exist == rawInputValues.end()) return 0.0f;
|
||||
return exist->second;
|
||||
}
|
||||
|
||||
InputManager::~InputManager() {
|
||||
|
@ -6,16 +6,20 @@
|
||||
#pragma once
|
||||
#include "input/IInputManager.hpp"
|
||||
|
||||
#define INPUT_MANAGER_AXIS_MOUSE_X -580000
|
||||
#define INPUT_MANAGER_AXIS_MOUSE_Y -580001
|
||||
#define INPUT_MANAGER_AXIS_MOUSE_0 -590000
|
||||
|
||||
namespace Dawn {
|
||||
class Game;
|
||||
|
||||
class InputManager : public IInputManager<int32_t> {
|
||||
protected:
|
||||
std::unordered_map<int32_t, float_t> rawInputValues;
|
||||
|
||||
float_t getInputValue(int32_t axis) override;
|
||||
|
||||
public:
|
||||
std::unordered_map<int32_t, float_t> rawInputValues;
|
||||
|
||||
/**
|
||||
* Initializes the input manager system.
|
||||
*
|
||||
|
Reference in New Issue
Block a user