diff --git a/source/backends/SDL3/base.cpp b/source/backends/SDL3/base.cpp new file mode 100644 index 0000000..baa5b2d --- /dev/null +++ b/source/backends/SDL3/base.cpp @@ -0,0 +1,88 @@ +#if BACKEND == SDL3 + +#include "backends/backend.h" +#include "state.h" +#include "mini/win/win.h" +#include "mini/surf/surf.h" + +namespace backend +{ + state_t current_state = running; + + void init() { + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD); + //video::init(); + } + + void quit() { + SDL_Quit(); + } + + void poll_events() { + //[TODO] + //if (update_mode==UPDATE_WAIT) + // SDL_WaitEvent(NULL); + //else if (update_mode==UPDATE_TIMEOUT) + // SDL_WaitEventTimeout(NULL, timeout); + + SDL_Event e; + while(SDL_PollEvent(&e)) { + if (e.type == SDL_EVENT_QUIT) { + current_state=quitting; + break; + } + else if (e.type == SDL_EVENT_TEXT_INPUT) { + SDL_strlcpy(input::key::text_input_buffer, e.text.text, sizeof(input::key::text_input_buffer)); + input::key::has_text_input = true; + } + else if (e.type == SDL_EVENT_KEY_DOWN) { + #ifdef DEBUG + if (e.key.scancode == SDL_SCANCODE_F12) { + mini::surf::reloadsurfs(); + //} else if (e.key.scancode == SDL_SCANCODE_F11) { + // mini::lua::debug::toggle(); + } else if (e.key.scancode == SDL_SCANCODE_F5) { + current_state=exiting; + } else { + input::key::just_pressed = e.key.scancode; + } + #else + input::key::just_pressed = e.key.scancode; + #endif + } + else if (e.type == SDL_EVENT_MOUSE_BUTTON_UP) { + if (input::mouse::discard_buttons) + input::mouse::discard_buttons = false; + else + if (e.button.clicks==2 && e.button.button==SDL_BUTTON_LEFT) { + input::mouse::double_click = true; + } else { + input::mouse::just_pressed = e.button.button; + } + } + else if (e.type == SDL_EVENT_MOUSE_WHEEL) { + input::mouse::w = e.wheel.y; + } + else if (e.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN) { + input::pad::just_pressed = e.gbutton.button; + } + } + + input::key::keys = SDL_GetKeyboardState(NULL); + + // Update mouse + float real_mouse_x, real_mouse_y; + input::mouse::buttons = SDL_GetMouseState(&real_mouse_x, &real_mouse_y); + float mx, my; + SDL_RenderCoordinatesFromWindow(video::renderer, real_mouse_x, real_mouse_y, &mx, &my); + input::mouse::x = int(mx/mini::win::state.zoom); + input::mouse::y = int(my/mini::win::state.zoom); + } + + const state_t& state() { + return current_state; + } + +} + +#endif \ No newline at end of file diff --git a/source/backends/SDL3/input.cpp b/source/backends/SDL3/input.cpp new file mode 100644 index 0000000..fa65321 --- /dev/null +++ b/source/backends/SDL3/input.cpp @@ -0,0 +1,153 @@ +#if BACKEND == SDL3 + +#include "backends/backend.h" +#include "state.h" +#include "mini/view/view.h" + +namespace backend +{ + namespace input + { + void reset() { + key::just_pressed = 0; + key::has_text_input = false; + key::text_input_buffer[0] = '\0'; + mouse::just_pressed = 0; + mouse::double_click = false; + mouse::w = 0; + pad::just_pressed = SDL_GAMEPAD_BUTTON_INVALID; + } + + namespace key + { + const bool *keys; + uint8_t just_pressed = 0; + char text_input_buffer[10]; + bool has_text_input = false; + + bool down(uint8_t i) { + return keys[i]; + } + + bool press(uint8_t i) { + if (just_pressed == i) { + just_pressed=0; + return true; + } else { + return false; + } + } + + int press() { + return just_pressed; + } + + bool any() { + const bool something_pressed = (just_pressed != 0) || (pad::just_pressed != -1); + just_pressed=0; + pad::just_pressed=-1; + return something_pressed; + } + + void text(const bool enable) { + if (enable) + SDL_StartTextInput(backend::video::window); + else + SDL_StopTextInput(backend::video::window); + } + + const char *utf8char() { + return has_text_input ? text_input_buffer : nullptr; + } + } + + namespace mouse + { + int x, y, w; + uint32_t buttons; + uint8_t just_pressed = 0; + bool double_click = false; + bool discard_buttons = false; + + int posx() { + return x - mini::view::state.origin[0]; + } + + int posy() { + return y - mini::view::state.origin[1]; + } + + int wheel() { + return w; + } + + bool down(uint8_t i) { + if (discard_buttons) return false; + return buttons & SDL_BUTTON_MASK(i); + } + + bool press(uint8_t i) { + return just_pressed == i; + } + + bool dblclick() { + return double_click; + } + + void discard() { + discard_buttons = true; + } + + bool inside(int x, int y, int w, int h) { + const int mx = x - mini::view::state.origin[0]; + const int my = y - mini::view::state.origin[1]; + return (mx>=x) && (my>=y) && (mx + +namespace backend +{ + namespace video + { + extern SDL_Window *window; + extern SDL_Renderer *renderer; + extern SDL_Texture *tex_back; + extern SDL_Texture *tex_shader; + } + + namespace input + { + namespace key + { + extern const bool *keys; + extern uint8_t just_pressed; + extern char text_input_buffer[10]; + extern bool has_text_input; + } + + namespace mouse + { + extern int x, y, w; + extern uint32_t buttons; + extern uint8_t just_pressed; + extern bool double_click; + extern bool discard_buttons; + } + + namespace pad + { + extern SDL_Gamepad *gamepad; + extern int8_t just_pressed; + } + } +} + +#endif diff --git a/source/backends/SDL3/video.cpp b/source/backends/SDL3/video.cpp new file mode 100644 index 0000000..84e66c9 --- /dev/null +++ b/source/backends/SDL3/video.cpp @@ -0,0 +1,88 @@ +#if BACKEND == SDL3 + +#include "backends/backend.h" +#include "state.h" +#include "mini/win/win.h" +#include "mini/surf/surf.h" +#include "mini/pal/pal.h" +#include "mini/shader/shader.h" + +namespace backend +{ + namespace video + { + SDL_Window *window { nullptr }; + SDL_Renderer *renderer { nullptr }; + SDL_Texture *tex_back { nullptr }; + SDL_Texture *tex_shader { nullptr }; + + void init() { + const auto &title = mini::win::state.title; + const auto &width = mini::win::state.width; + const auto &height = mini::win::state.height; + auto &zoom = mini::win::state.zoom; + + // Ajustar el zoom a un valor vàlid + if (zoom <= 0) zoom = 1; + const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay()); + while ( width * zoom > dm->w || height * zoom > dm->h) zoom--; + + // Crear SDL_Window i SDL_Renderer + window = SDL_CreateWindow(title, width*zoom, height*zoom, SDL_WINDOW_OPENGL|(mini::win::state.fullscreen?SDL_WINDOW_FULLSCREEN:0)); + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); + renderer = SDL_CreateRenderer(window, NULL); + + // Mostrar o ocultar el cursor + if (mini::win::state.cursor) SDL_ShowCursor(); else SDL_HideCursor(); + + // Crear textura backbuffer + tex_back = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); + SDL_SetTextureScaleMode(tex_back, SDL_SCALEMODE_NEAREST); + + // Crear textura shaders i inicialitzar shaders + tex_shader = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width*zoom, height*zoom); + SDL_SetTextureScaleMode(tex_shader, SDL_SCALEMODE_NEAREST); + + mini::shader::init(window, tex_shader, nullptr); + + // [TODO] + //log_msg(LOG_OK, "Graphics subsystem initialized\n"); + } + + void quit() { + SDL_DestroyTexture(tex_shader); + SDL_DestroyTexture(tex_back); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + } + + void render() { + // Render frame + SDL_SetRenderTarget(renderer, tex_shader); + //SDL_SetRenderDrawColor(win::state.renderer, 0, 0, 0, 255); + //SDL_RenderClear(win::state.renderer); + + uint32_t *pixels; + int pitch; + SDL_LockTexture(tex_back, NULL, (void**)&pixels, &pitch); + for (uint32_t i=0;isize;++i) pixels[i] = mini::pal::palette[mini::surf::state.screen_surface->p[i]]; + SDL_UnlockTexture(tex_back); + SDL_RenderTexture(renderer, tex_back, NULL, NULL); //NEW + + mini::shader::render(); + + //SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL); + //SDL_RenderPresent(mini_ren); + } + + void raise_window() { + SDL_RaiseWindow(window); + } + + void cursor(const bool value) { + if (value) SDL_ShowCursor(); else SDL_HideCursor(); + } + } +} + +#endif diff --git a/source/backends/backend.cpp b/source/backends/backend.cpp new file mode 100644 index 0000000..11f755d --- /dev/null +++ b/source/backends/backend.cpp @@ -0,0 +1,16 @@ +#include "backend.h" +#include + +namespace backend +{ + uint64_t get_time_ms() { + using namespace std::chrono; + return duration_cast( + steady_clock::now().time_since_epoch() + ).count(); + } + + void exit() { + current_state = quitting; + } +} \ No newline at end of file diff --git a/source/backends/backend.h b/source/backends/backend.h new file mode 100644 index 0000000..db5104e --- /dev/null +++ b/source/backends/backend.h @@ -0,0 +1,75 @@ +#pragma once + +#define SDL3 1 +#define SFML 2 +#define EMSCRIPTEN 3 + +#ifndef BACKEND + #define BACKEND SDL3 +#endif + +#include + +namespace backend +{ + enum state_t { running=0, exiting=1, quitting=2 }; + extern state_t current_state; + + void init(); + void quit(); + void poll_events(); + const state_t& state(); + void exit(); + uint64_t get_time_ms(); + + namespace video + { + void init(); + void quit(); + void render(); + void raise_window(); + void cursor(const bool value); + } + + namespace audio + { + void init(); + void quit(); + void render(); + } + + namespace input + { + void reset(); + + namespace key + { + bool down(uint8_t i); + bool press(uint8_t i); + int press(); + bool any(); + void text(const bool enable); + const char *utf8char(); + } + + namespace mouse + { + int posx(); + int posy(); + int wheel(); + bool down(uint8_t i); + bool press(uint8_t i); + bool dblclick(); + void discard(); + bool inside(int x, int y, int w, int h); + } + + namespace pad + { + void init(); + bool down(int8_t i); + bool press(int8_t i); + int press(); + } + } +} diff --git a/source/mini/key/key.cpp b/source/mini/key/key.cpp index c3216e6..45660ec 100644 --- a/source/mini/key/key.cpp +++ b/source/mini/key/key.cpp @@ -2,47 +2,34 @@ #include "mini/pad/pad.h" #include "mini/win/win.h" -#include +#include "backends/backend.h" namespace mini { namespace key { - state_t state; - bool down(uint8_t i) { - return state.keys[i]; + return backend::input::key::down(i); } bool press(uint8_t i) { - if (state.just_pressed == i) { - state.just_pressed=0; - return true; - } else { - return false; - } + return backend::input::key::press(i); } int press() { - return state.just_pressed; + return backend::input::key::press(); } bool any() { - const bool something_pressed = (state.just_pressed != 0) || (pad::state.just_pressed != -1); - state.just_pressed=0; - pad::state.just_pressed=-1; - return something_pressed; + return backend::input::key::any(); } void text(const bool enable) { - if (enable) - SDL_StartTextInput(win::state.window); - else - SDL_StopTextInput(win::state.window); + backend::input::key::text(enable); } const char* utf8char() { - return state.has_text_input ? state.text_input_buffer : nullptr; + return backend::input::key::utf8char(); } } diff --git a/source/mini/key/key.h b/source/mini/key/key.h index 0af72e9..3e21305 100644 --- a/source/mini/key/key.h +++ b/source/mini/key/key.h @@ -5,14 +5,6 @@ namespace mini { namespace key { - struct state_t { - const bool *keys; - uint8_t just_pressed = 0; - char text_input_buffer[10]; - bool has_text_input = false; - }; - extern state_t state; - bool down(uint8_t i); bool press(uint8_t i); int press(); diff --git a/source/mini/mini.cpp b/source/mini/mini.cpp index 38da8de..675304e 100644 --- a/source/mini/mini.cpp +++ b/source/mini/mini.cpp @@ -18,7 +18,8 @@ #include "lua/lua.h" #include "aux/log.h" -#include +//#include +#include "backends/backend.h" #include @@ -43,9 +44,6 @@ int fps=0; uint32_t last_update = 0; float delta_time = 0.0f; -bool should_exit = false; -bool should_quit = false; - int16_t beats, num_beats = 0; void createNewProject(); @@ -96,7 +94,7 @@ namespace mini } float time() { - return float(SDL_GetTicks())/1000.0f; + return float(backend::get_time_ms())/1000.0f; } bool beat(int16_t i) { @@ -123,8 +121,7 @@ namespace mini } void exit() { - should_exit = true; - should_quit = true; + backend::exit(); } } @@ -137,10 +134,10 @@ using namespace mini; int main(int argc,char*argv[]){ - #ifdef DEBUG - SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); - log_msg(LOG_UNSALTED, "MINI v%s\n",MINI_VERSION); - #endif + //#ifdef DEBUG + // SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); + // log_msg(LOG_UNSALTED, "MINI v%s\n",MINI_VERSION); + //#endif // Gestió de arguments // =============================================================== @@ -176,8 +173,7 @@ int main(int argc,char*argv[]){ file::setresourcefilename(res_file); #endif - while (!should_quit) { - should_exit=false; + while (backend::state()!=backend::quitting) { // READ INI if (!override_ini) @@ -196,7 +192,7 @@ int main(int argc,char*argv[]){ if (sound_enabled) audio::sound::enable::set(strcmp(sound_enabled, "true")==0?true:false); } - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD); + backend::init(); log_msg(LOG_INFO, "STARTING A SYSTEM REINITIALIZATION\n"); win::init(); @@ -211,85 +207,24 @@ int main(int argc,char*argv[]){ lua::init(main_lua_file); lua::callbacks::init(); - Uint32 dt=SDL_GetTicks(); + uint32_t dt = backend::get_time_ms(); - key::state.just_pressed = 0; - key::state.has_text_input = false; - pad::state.just_pressed = SDL_GAMEPAD_BUTTON_INVALID; - mouse::state.just_pressed = 0; - mouse::state.wheel = 0; - mouse::state.double_click = false; + backend::input::reset(); int fps_counter=0; uint32_t fps_timer=0; - while(!should_exit) { - if (update_mode==UPDATE_WAIT) - SDL_WaitEvent(NULL); - else if (update_mode==UPDATE_TIMEOUT) - SDL_WaitEventTimeout(NULL, timeout); + while(backend::state()==backend::running) { - SDL_Event e; - while(SDL_PollEvent(&e)) { - if (e.type == SDL_EVENT_QUIT) { - should_exit=true; - should_quit=true; - break; - } - else if (e.type == SDL_EVENT_TEXT_INPUT) { - SDL_strlcpy(key::state.text_input_buffer, e.text.text, sizeof(key::state.text_input_buffer)); - key::state.has_text_input = true; - } - else if (e.type == SDL_EVENT_KEY_DOWN) { - #ifdef DEBUG - if (e.key.scancode == SDL_SCANCODE_F12) { - mini::surf::reloadsurfs(); - //} else if (e.key.scancode == SDL_SCANCODE_F11) { - // mini::lua::debug::toggle(); - } else if (e.key.scancode == SDL_SCANCODE_F5) { - should_exit=true; - } else { - key::state.just_pressed = e.key.scancode; - } - #else - key::state.just_pressed = e.key.scancode; - #endif - } - else if (e.type == SDL_EVENT_MOUSE_BUTTON_UP) { - if (mouse::state.discard) - mouse::state.discard = false; - else - if (e.button.clicks==2 && e.button.button==SDL_BUTTON_LEFT) { - mouse::state.double_click = true; - } else { - mouse::state.just_pressed = e.button.button; - } - } - else if (e.type == SDL_EVENT_MOUSE_WHEEL) { - mouse::state.wheel = e.wheel.y; - } - else if (e.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN) { - pad::state.just_pressed = e.gbutton.button; - } - } + backend::poll_events(); - key::state.keys = SDL_GetKeyboardState(NULL); - - // Update mouse - float real_mouse_x, real_mouse_y; - mouse::state.buttons = SDL_GetMouseState(&real_mouse_x, &real_mouse_y); - float mx, my; - SDL_RenderCoordinatesFromWindow(win::state.renderer, real_mouse_x, real_mouse_y, &mx, &my); - mouse::state.x = int(mx/win::state.zoom); - mouse::state.y = int(my/win::state.zoom); - // Do update - if (SDL_GetTicks()-dt>13) { - dt = SDL_GetTicks(); + if (backend::get_time_ms()-dt>13) { + dt = backend::get_time_ms(); if (lua::running()) { - delta_time = float(SDL_GetTicks() - last_update)/1000.0f; - last_update = SDL_GetTicks(); + delta_time = float(backend::get_time_ms() - last_update)/1000.0f; + last_update = backend::get_time_ms(); lua::callbacks::update(); } else { @@ -299,50 +234,25 @@ int main(int argc,char*argv[]){ if (beats == 0) beats = num_beats; if (beats > 0) beats--; - // Reset keyboard, mouse and pad - key::state.just_pressed = 0; - key::state.has_text_input = false; - key::state.text_input_buffer[0] = '\0'; - mouse::state.just_pressed = 0; - mouse::state.double_click = false; - mouse::state.wheel = 0; - pad::state.just_pressed = SDL_GAMEPAD_BUTTON_INVALID; + backend::input::reset(); } - // Render frame - SDL_SetRenderTarget(win::state.renderer, win::state.tex_shader); - //SDL_SetRenderDrawColor(win::state.renderer, 0, 0, 0, 255); - //SDL_RenderClear(win::state.renderer); - - uint32_t *pixels; - int pitch; - SDL_LockTexture(win::state.tex_back, NULL, (void**)&pixels, &pitch); - for (uint32_t i=0;isize;++i) pixels[i] = pal::palette[surf::state.screen_surface->p[i]]; - SDL_UnlockTexture(win::state.tex_back); - SDL_RenderTexture(win::state.renderer, win::state.tex_back, NULL, NULL); //NEW - - shader::render(); - //SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL); - //SDL_RenderPresent(mini_ren); + backend::video::render(); fps_counter++; - if (SDL_GetTicks()>=(fps_timer+1000)) { + if (backend::get_time_ms()>=(fps_timer+1000)) { fps = fps_counter; fps_counter=0; - fps_timer = SDL_GetTicks(); + fps_timer = backend::get_time_ms(); } } lua::quit(); audio::quit(); - - //Mix_Quit(); - surf::quit(); - map::quit(); win::quit(); - SDL_Quit(); + backend::quit(); } lua::cleanup(); diff --git a/source/mini/mouse/mouse.cpp b/source/mini/mouse/mouse.cpp index af79e6a..e9d3cc5 100644 --- a/source/mini/mouse/mouse.cpp +++ b/source/mini/mouse/mouse.cpp @@ -1,47 +1,42 @@ #include "mouse.h" #include "mini/view/view.h" -#include +#include "backends/backend.h" namespace mini { namespace mouse { - state_t state; - int posx() { - return state.x-view::state.origin[0]; + return backend::input::mouse::posx(); } int posy() { - return state.y-view::state.origin[1]; + return backend::input::mouse::posy(); } int wheel() { - return state.wheel; + return backend::input::mouse::wheel(); } bool down(uint8_t i) { - if (state.discard) return false; - return state.buttons & SDL_BUTTON_MASK(i); + return backend::input::mouse::down(i); } bool press(uint8_t i) { - return state.just_pressed == i; + return backend::input::mouse::press(i); } bool dblclick() { - return state.double_click; + return backend::input::mouse::dblclick(); } void discard() { - state.discard = true; + backend::input::mouse::discard(); } bool inside(int x, int y, int w, int h) { - const int mx = state.x - view::state.origin[0]; - const int my = state.y - view::state.origin[1]; - return (mx>=x) && (my>=y) && (mx +#include "backends/backend.h" namespace mini { namespace pad { - state_t state; - void init() { - int num_joysticks; - SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); - if (joysticks) { - for (int i=0; i -struct SDL_Gamepad; - namespace mini { namespace pad { - struct state_t { - SDL_Gamepad *gamepad = nullptr; - int8_t just_pressed = -1; - }; - extern state_t state; - void init(); bool down(int8_t i); bool press(int8_t i); diff --git a/source/mini/shader/shader.cpp b/source/mini/shader/shader.cpp index 0aa348b..22c119a 100644 --- a/source/mini/shader/shader.cpp +++ b/source/mini/shader/shader.cpp @@ -92,7 +92,8 @@ namespace mini char *fshaderfile = nullptr; if (fshader) { fshaderfile = file::getfilebuffer(fshader, filesize, true); } - init(win::state.window, win::state.tex_shader, vshaderfile, fshaderfile); + // [TODO] + //init(win::state.window, win::state.tex_shader, vshaderfile, fshaderfile); } diff --git a/source/mini/win/win.cpp b/source/mini/win/win.cpp index 647fa99..0d799ea 100644 --- a/source/mini/win/win.cpp +++ b/source/mini/win/win.cpp @@ -2,8 +2,9 @@ #include "aux/log.h" #include "mini/file/file.h" #include "mini/shader/shader.h" +#include -#include +#include namespace mini { @@ -12,48 +13,16 @@ namespace mini state_t state; void init() { - // Ajustar el zoom a un valor vàlid - if (state.zoom <= 0) state.zoom = 1; - const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay()); - while (state.width*state.zoom > dm->w || state.height*state.zoom > dm->h) state.zoom--; - - // Crear SDL_Window i SDL_Renderer - state.window = SDL_CreateWindow(state.title, state.width*state.zoom, state.height*state.zoom, SDL_WINDOW_OPENGL|(state.fullscreen?SDL_WINDOW_FULLSCREEN:0)); - //windowID = SDL_GetWindowID(mini_win); - SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); - state.renderer = SDL_CreateRenderer(state.window, NULL); - - // Mostrar o ocultar el cursor - if (state.cursor) SDL_ShowCursor(); else SDL_HideCursor(); - - // Crear textura backbuffer - state.tex_back = SDL_CreateTexture(state.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, state.width, state.height); - SDL_SetTextureScaleMode(state.tex_back, SDL_SCALEMODE_NEAREST); - - //SDL_PropertiesID props = SDL_GetTextureProperties(state.tex_back); - //int real_pixelformat = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, -1); - //if (real_pixelformat != SDL_PIXELFORMAT_ARGB8888) { - // log_msg(LOG_FAIL, "Pixelformat incorrecte: %i\n", real_pixelformat); - // exit(1); - //} - - // Crear textura shaders i inicialitzar shaders - state.tex_shader = SDL_CreateTexture(state.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, state.width*state.zoom, state.height*state.zoom); - SDL_SetTextureScaleMode(state.tex_shader, SDL_SCALEMODE_NEAREST); - shader::init(state.window, state.tex_shader, nullptr); - + backend::video::init(); log_msg(LOG_OK, "Graphics subsystem initialized\n"); } void quit() { - SDL_DestroyTexture(state.tex_shader); - SDL_DestroyTexture(state.tex_back); - SDL_DestroyRenderer(state.renderer); - SDL_DestroyWindow(state.window); + backend::video::quit(); } void raise() { - SDL_RaiseWindow(state.window); + backend::video::raise_window(); } namespace zoom { @@ -64,8 +33,7 @@ namespace mini state.zoom = value; quit(); init(); - char strzoom[3]; - file::setconfigvalue("zoom", SDL_itoa(state.zoom, strzoom, 10)); + file::setconfigvalue("zoom", std::to_string(state.zoom).c_str()); } } @@ -87,7 +55,7 @@ namespace mini } void set(const bool value) { state.cursor=value; - if (state.cursor) SDL_ShowCursor(); else SDL_HideCursor(); + backend::video::cursor(value); } } diff --git a/source/mini/win/win.h b/source/mini/win/win.h index 34a44f5..eb02c7d 100644 --- a/source/mini/win/win.h +++ b/source/mini/win/win.h @@ -1,10 +1,6 @@ #pragma once #include -struct SDL_Window; -struct SDL_Renderer; -struct SDL_Texture; - namespace mini { namespace win @@ -16,12 +12,6 @@ namespace mini uint8_t zoom { 4 }; bool fullscreen { false }; bool cursor { true }; - - SDL_Window *window { nullptr }; - SDL_Renderer*renderer { nullptr }; - SDL_Texture *tex_back { nullptr }; - SDL_Texture *tex_shader { nullptr }; - //Uint32 windowID; }; extern state_t state;