mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
refactor(window): migrate from GLFW to SDL3 for window and input
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include "Cubed/audio/audio_engine.hpp"
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include "Cubed/argument.hpp"
|
||||
#include "Cubed/audio/audio_engine.hpp"
|
||||
#include "Cubed/config.hpp"
|
||||
#include "Cubed/dev_panel.hpp"
|
||||
#include "Cubed/render/renderer.hpp"
|
||||
@@ -14,21 +13,15 @@ class App {
|
||||
public:
|
||||
App();
|
||||
~App();
|
||||
static void cursor_position_callback(GLFWwindow* window, double xpos,
|
||||
double ypos);
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode,
|
||||
int action, int mods);
|
||||
static void mouse_button_callback(GLFWwindow* window, int button,
|
||||
int action, int mods);
|
||||
static void window_focus_callback(GLFWwindow* window, int focused);
|
||||
static void window_reshape_callback(GLFWwindow* window, int new_width,
|
||||
int new_height);
|
||||
static void framebuffer_size_callback(GLFWwindow* window, int new_width,
|
||||
int new_height);
|
||||
static void mouse_scroll_callback(GLFWwindow* window, double xoffset,
|
||||
double yoffset);
|
||||
static void cursor_enter_callback(GLFWwindow* window, int entered);
|
||||
static void char_callback(GLFWwindow* window, unsigned int ch);
|
||||
void handle_cursor_position(float xpos, float ypos);
|
||||
void handle_sdl_key(SDL_Event& e);
|
||||
void handle_sdl_mouse_button(SDL_Event& e);
|
||||
void handle_window_focus(bool focused);
|
||||
void handle_window_resize(int new_width, int new_height);
|
||||
void handle_framebuffer_resize(int new_width, int new_height);
|
||||
void handle_mouse_scroll(float xoffset, float yoffset);
|
||||
void handle_text_input(const char* text);
|
||||
|
||||
static int start_cubed_application(int argc, char** argv);
|
||||
|
||||
static unsigned int seed();
|
||||
@@ -43,7 +36,10 @@ public:
|
||||
const Argument& argument() const;
|
||||
AudioEngine& audio();
|
||||
|
||||
const char* get_clipboard_text();
|
||||
std::string get_clipboard_text();
|
||||
|
||||
void start_text_input();
|
||||
void stop_text_input();
|
||||
|
||||
private:
|
||||
Config m_game_config;
|
||||
@@ -58,14 +54,14 @@ private:
|
||||
|
||||
SceneManager m_scene_manager;
|
||||
|
||||
inline static double last_time = glfwGetTime();
|
||||
inline static double current_time = glfwGetTime();
|
||||
inline static double dt = 0.0f;
|
||||
inline static double fps_time_count = 0.0f;
|
||||
inline static uint64_t last_tick = 0;
|
||||
inline static uint64_t current_tick = 0;
|
||||
inline static float dt = 0.0f;
|
||||
inline static float fps_time_count = 0.0f;
|
||||
inline static int frame_count = 0;
|
||||
inline static int fps = 0;
|
||||
Argument m_argument;
|
||||
|
||||
bool m_running = true;
|
||||
void init(int argc, char** argv);
|
||||
void handle_argument(int argc, char** argv);
|
||||
auto init_camera();
|
||||
@@ -76,6 +72,8 @@ private:
|
||||
void run();
|
||||
void update();
|
||||
|
||||
void handle_sdl_event(SDL_Event& e);
|
||||
|
||||
void dispatch_event(const Event& e);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/input/event.hpp"
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
@@ -9,7 +9,7 @@ enum class MouseKey {
|
||||
|
||||
BACK_BUTTON, // Side button back
|
||||
FORWARD_BUTTON, // Side button forward
|
||||
|
||||
/*
|
||||
WHEEL_UP,
|
||||
WHEEL_DOWN,
|
||||
WHEEL_LEFT,
|
||||
@@ -20,6 +20,7 @@ enum class MouseKey {
|
||||
EXTRA_BUTTON_3,
|
||||
EXTRA_BUTTON_4,
|
||||
EXTRA_BUTTON_5
|
||||
*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include "Cubed/config.hpp"
|
||||
#include "Cubed/input/event.hpp"
|
||||
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <SDL3/SDL.h>
|
||||
namespace Cubed {
|
||||
class Camera;
|
||||
class Renderer;
|
||||
@@ -14,8 +13,8 @@ public:
|
||||
~Window();
|
||||
|
||||
bool is_mouse_enable() const;
|
||||
const GLFWwindow* get_glfw_window() const;
|
||||
GLFWwindow* get_glfw_window();
|
||||
const SDL_Window* get_window() const;
|
||||
SDL_Window* get_window();
|
||||
void init();
|
||||
void imgui_init();
|
||||
|
||||
@@ -25,7 +24,7 @@ public:
|
||||
void reload_config();
|
||||
|
||||
void toggle_fullscreen();
|
||||
|
||||
void set_fullscreen(bool full);
|
||||
void enable_mouse();
|
||||
void disable_mouse();
|
||||
|
||||
@@ -40,11 +39,14 @@ public:
|
||||
|
||||
void set_imgui_enabled(bool enable);
|
||||
|
||||
void set_vsync(bool enable);
|
||||
|
||||
private:
|
||||
bool m_mouse_enable = true;
|
||||
bool m_imgui_init = false;
|
||||
bool m_game_running = false;
|
||||
GLFWwindow* m_window;
|
||||
SDL_Window* m_window;
|
||||
SDL_GLContext m_context;
|
||||
int m_window_width;
|
||||
int m_window_height;
|
||||
Config& m_config;
|
||||
|
||||
Reference in New Issue
Block a user