diff options
author | Frederico Linhares <fred@linhares.blue> | 2025-07-14 21:27:52 -0300 |
---|---|---|
committer | Frederico Linhares <fred@linhares.blue> | 2025-07-14 21:27:52 -0300 |
commit | 4c52564f56545796ec5d9c03c93276347d732034 (patch) | |
tree | 6c581ffa4122e33fe5cfbc65049c627a5e485f2d /src | |
parent | 8ef58d472533a43155893889dfb1f97a4dec2dcf (diff) |
feat Update to SDL3
Diffstat (limited to 'src')
-rw-r--r-- | src/blu_cat/int/core.cpp | 24 | ||||
-rw-r--r-- | src/blu_cat/int/core.hpp | 4 | ||||
-rw-r--r-- | src/candy_gear/key.cpp | 54 | ||||
-rw-r--r-- | src/candy_gear/main.cpp | 18 |
4 files changed, 49 insertions, 51 deletions
diff --git a/src/blu_cat/int/core.cpp b/src/blu_cat/int/core.cpp index 5b9e53b..ffae1d2 100644 --- a/src/blu_cat/int/core.cpp +++ b/src/blu_cat/int/core.cpp @@ -56,14 +56,14 @@ vk_debug_callback( void load_sdl(void *obj) { - if(SDL_Init(SDL_INIT_EVERYTHING) < 0) + if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { std::string error{"SDL could not initialize! SDL Error → "}; error += SDL_GetError(); - throw error; + throw CommandError{error}; } - if(SDL_Vulkan_LoadLibrary(nullptr) != 0) + if(!SDL_Vulkan_LoadLibrary(nullptr)) { SDL_Quit(); std::string error{"SDL could not initialize Vulkan! SDL_Error → "}; @@ -82,13 +82,11 @@ unload_sdl(void *obj) void load_window(void *obj) { - BluCat::INT::core.window = nullptr; BluCat::INT::core.window = SDL_CreateWindow( BluCat::INT::core.game_name.c_str(), - SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, BluCat::INT::core.display_width, BluCat::INT::core.display_height, SDL_WINDOW_VULKAN); - if(BluCat::INT::core.window == nullptr) + if(BluCat::INT::core.window == NULL) { std::string error{"Window could not be created! SDL_Error → "}; error += SDL_GetError(); @@ -124,8 +122,10 @@ load_vk_instance(void *obj) uint32_t vk_sdl_extension_count; std::vector<const char*> vk_sdl_extensions; - if(!SDL_Vulkan_GetInstanceExtensions( - BluCat::INT::core.window, &vk_sdl_extension_count, nullptr)) + const char * const *instance_extensions = + SDL_Vulkan_GetInstanceExtensions(&vk_sdl_extension_count); + + if(instance_extensions == NULL) { std::string error{ "Vulkan extensions could not be loaded by SDL! SDL_Error: "}; @@ -133,10 +133,8 @@ load_vk_instance(void *obj) throw CommandError{error}; } - vk_sdl_extensions.resize(vk_sdl_extension_count); - SDL_Vulkan_GetInstanceExtensions( - BluCat::INT::core.window, &vk_sdl_extension_count, - vk_sdl_extensions.data()); + for(auto i{0}; i < vk_sdl_extension_count; i++) + vk_sdl_extensions.push_back(instance_extensions[i]); // Combine all extensions. vk_extensions_count = vk_sdl_extension_count + @@ -254,7 +252,7 @@ load_window_surface(void *obj) { if(!SDL_Vulkan_CreateSurface( BluCat::INT::core.window, BluCat::INT::core.vk_instance, - &BluCat::INT::core.window_surface)) + nullptr, &BluCat::INT::core.window_surface)) { std::string error{"Failed to create a window surface → "}; error += SDL_GetError(); diff --git a/src/blu_cat/int/core.hpp b/src/blu_cat/int/core.hpp index c369e7b..0e5f3a3 100644 --- a/src/blu_cat/int/core.hpp +++ b/src/blu_cat/int/core.hpp @@ -32,8 +32,8 @@ #include <Windows.h> #endif -#include <SDL2/SDL.h> -#include <SDL2/SDL_vulkan.h> +#include <SDL3/SDL.h> +#include <SDL3/SDL_vulkan.h> #include <ft2build.h> #include FT_FREETYPE_H diff --git a/src/candy_gear/key.cpp b/src/candy_gear/key.cpp index 615119c..74c2181 100644 --- a/src/candy_gear/key.cpp +++ b/src/candy_gear/key.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,32 +24,32 @@ cg_key_init(mrb_state *mrb) cg_m = mrb_module_get(mrb, "CandyGear"); cg_mKey = mrb_define_module_under(mrb, cg_m, "Key"); - mrb_define_const(mrb, cg_mKey, "A", mrb_int_value(mrb, SDLK_a)); - mrb_define_const(mrb, cg_mKey, "B", mrb_int_value(mrb, SDLK_b)); - mrb_define_const(mrb, cg_mKey, "C", mrb_int_value(mrb, SDLK_c)); - mrb_define_const(mrb, cg_mKey, "D", mrb_int_value(mrb, SDLK_d)); - mrb_define_const(mrb, cg_mKey, "E", mrb_int_value(mrb, SDLK_e)); - mrb_define_const(mrb, cg_mKey, "F", mrb_int_value(mrb, SDLK_f)); - mrb_define_const(mrb, cg_mKey, "G", mrb_int_value(mrb, SDLK_g)); - mrb_define_const(mrb, cg_mKey, "H", mrb_int_value(mrb, SDLK_h)); - mrb_define_const(mrb, cg_mKey, "I", mrb_int_value(mrb, SDLK_i)); - mrb_define_const(mrb, cg_mKey, "J", mrb_int_value(mrb, SDLK_j)); - mrb_define_const(mrb, cg_mKey, "K", mrb_int_value(mrb, SDLK_k)); - mrb_define_const(mrb, cg_mKey, "L", mrb_int_value(mrb, SDLK_l)); - mrb_define_const(mrb, cg_mKey, "M", mrb_int_value(mrb, SDLK_m)); - mrb_define_const(mrb, cg_mKey, "N", mrb_int_value(mrb, SDLK_n)); - mrb_define_const(mrb, cg_mKey, "O", mrb_int_value(mrb, SDLK_o)); - mrb_define_const(mrb, cg_mKey, "P", mrb_int_value(mrb, SDLK_p)); - mrb_define_const(mrb, cg_mKey, "Q", mrb_int_value(mrb, SDLK_q)); - mrb_define_const(mrb, cg_mKey, "R", mrb_int_value(mrb, SDLK_r)); - mrb_define_const(mrb, cg_mKey, "S", mrb_int_value(mrb, SDLK_s)); - mrb_define_const(mrb, cg_mKey, "T", mrb_int_value(mrb, SDLK_t)); - mrb_define_const(mrb, cg_mKey, "U", mrb_int_value(mrb, SDLK_u)); - mrb_define_const(mrb, cg_mKey, "V", mrb_int_value(mrb, SDLK_v)); - mrb_define_const(mrb, cg_mKey, "W", mrb_int_value(mrb, SDLK_w)); - mrb_define_const(mrb, cg_mKey, "X", mrb_int_value(mrb, SDLK_x)); - mrb_define_const(mrb, cg_mKey, "Y", mrb_int_value(mrb, SDLK_y)); - mrb_define_const(mrb, cg_mKey, "Z", mrb_int_value(mrb, SDLK_z)); + mrb_define_const(mrb, cg_mKey, "A", mrb_int_value(mrb, SDLK_A)); + mrb_define_const(mrb, cg_mKey, "B", mrb_int_value(mrb, SDLK_B)); + mrb_define_const(mrb, cg_mKey, "C", mrb_int_value(mrb, SDLK_C)); + mrb_define_const(mrb, cg_mKey, "D", mrb_int_value(mrb, SDLK_D)); + mrb_define_const(mrb, cg_mKey, "E", mrb_int_value(mrb, SDLK_E)); + mrb_define_const(mrb, cg_mKey, "F", mrb_int_value(mrb, SDLK_F)); + mrb_define_const(mrb, cg_mKey, "G", mrb_int_value(mrb, SDLK_G)); + mrb_define_const(mrb, cg_mKey, "H", mrb_int_value(mrb, SDLK_H)); + mrb_define_const(mrb, cg_mKey, "I", mrb_int_value(mrb, SDLK_I)); + mrb_define_const(mrb, cg_mKey, "J", mrb_int_value(mrb, SDLK_J)); + mrb_define_const(mrb, cg_mKey, "K", mrb_int_value(mrb, SDLK_K)); + mrb_define_const(mrb, cg_mKey, "L", mrb_int_value(mrb, SDLK_L)); + mrb_define_const(mrb, cg_mKey, "M", mrb_int_value(mrb, SDLK_M)); + mrb_define_const(mrb, cg_mKey, "N", mrb_int_value(mrb, SDLK_N)); + mrb_define_const(mrb, cg_mKey, "O", mrb_int_value(mrb, SDLK_O)); + mrb_define_const(mrb, cg_mKey, "P", mrb_int_value(mrb, SDLK_P)); + mrb_define_const(mrb, cg_mKey, "Q", mrb_int_value(mrb, SDLK_Q)); + mrb_define_const(mrb, cg_mKey, "R", mrb_int_value(mrb, SDLK_R)); + mrb_define_const(mrb, cg_mKey, "S", mrb_int_value(mrb, SDLK_S)); + mrb_define_const(mrb, cg_mKey, "T", mrb_int_value(mrb, SDLK_T)); + mrb_define_const(mrb, cg_mKey, "U", mrb_int_value(mrb, SDLK_U)); + mrb_define_const(mrb, cg_mKey, "V", mrb_int_value(mrb, SDLK_V)); + mrb_define_const(mrb, cg_mKey, "W", mrb_int_value(mrb, SDLK_W)); + mrb_define_const(mrb, cg_mKey, "X", mrb_int_value(mrb, SDLK_X)); + mrb_define_const(mrb, cg_mKey, "Y", mrb_int_value(mrb, SDLK_Y)); + mrb_define_const(mrb, cg_mKey, "Z", mrb_int_value(mrb, SDLK_Z)); mrb_define_const(mrb, cg_mKey, "UP", mrb_int_value(mrb, SDLK_UP)); mrb_define_const(mrb, cg_mKey, "DOWN", mrb_int_value(mrb, SDLK_DOWN)); diff --git a/src/candy_gear/main.cpp b/src/candy_gear/main.cpp index 353b6bf..bc38e9e 100644 --- a/src/candy_gear/main.cpp +++ b/src/candy_gear/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,23 +63,23 @@ int main(int argc, char *argv[]) { switch(event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: mrb_funcall_id( cg_core.mrb, main_obj, cg_core.sym_key_down, 1, - mrb_int_value(cg_core.mrb, event.key.keysym.sym)); + mrb_int_value(cg_core.mrb, event.key.key)); break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: mrb_funcall_id( cg_core.mrb, main_obj, cg_core.sym_key_up, 1, - mrb_int_value(cg_core.mrb, event.key.keysym.sym)); + mrb_int_value(cg_core.mrb, event.key.key)); break; - case SDL_MOUSEMOTION: + case SDL_EVENT_MOUSE_MOTION: break; - case SDL_MOUSEBUTTONDOWN: + case SDL_EVENT_MOUSE_BUTTON_DOWN: break; - case SDL_MOUSEBUTTONUP: + case SDL_EVENT_MOUSE_BUTTON_UP: break; - case SDL_QUIT: + case SDL_EVENT_QUIT: mrb_funcall_id(cg_core.mrb, main_obj, cg_core.sym_quit, 0); break; } |