From 526330f3c8b1d760e7de1ca4118d19f8ca3f2525 Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Mon, 17 Aug 2026 23:08:27 +0400 Subject: [PATCH] Starting replacing WIN32 specific code with crossplatform SDL! --- binding-mri/binding-mri.cpp | 3 +- journal/SDL/CMakeLists.txt | 10 ++--- journal/SDL/assets/default.png | Bin 0 -> 430 bytes journal/SDL/main.c | 75 +++++++++++++++++++++++++++++++++ src/main.cpp | 69 +++++++++++------------------- 5 files changed, 107 insertions(+), 50 deletions(-) create mode 100644 journal/SDL/assets/default.png diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 727e417..2494989 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include extern const char binding_mri_module_rpg1_rb[]; extern const int binding_mri_module_rpg1_rb_len; @@ -421,7 +422,7 @@ static void runRMXPScripts(BacktraceData &btData){ rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str())); } - /* Execute preloaded scripts */ + //Execute preloaded scripts for (std::set::iterator i = preloadScripts.begin(); i != preloadScripts.end(); ++i) runCustomScript(*i); diff --git a/journal/SDL/CMakeLists.txt b/journal/SDL/CMakeLists.txt index 66533fe..54594c3 100644 --- a/journal/SDL/CMakeLists.txt +++ b/journal/SDL/CMakeLists.txt @@ -3,13 +3,12 @@ project(_______) include(FindPackageHandleStandardArgs) option(DEBUG "Debug mode" ON) option(SANITIZERS "Enable sanitizers" OFF) -option(NATIVE "Use native instructions(for local use only)" OFF) set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE) -set(VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION "5.1.2600.0") set(CMAKE_INCLUDE_CURRENT_DIR ON) set(EMBEDDED_INPUT assets/icon.png + assets/default.png ) ## Process Embeddeds ## @@ -43,7 +42,8 @@ endforeach() source_group("Embedded Source" FILES ${EMBEDDED_INPUT} ${EMBEDDED_SOURCE}) add_executable(${PROJECT_NAME} ${EMBEDDED_SOURCE} main.c) -find_package(SDL3 CONFIG) -find_package(SDL3_image CONFIG) +find_package(SDL3 CONFIG REQUIRED) +find_package(SDL3_image CONFIG REQUIRED) +find_package(SDL3_net CONFIG REQUIRED) target_compile_definitions(${PROJECT_NAME} PRIVATE ${DEFINES}) -target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image) +target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image SDL3_net::SDL3_net) diff --git a/journal/SDL/assets/default.png b/journal/SDL/assets/default.png new file mode 100644 index 0000000000000000000000000000000000000000..969a0bacc7bfc948b7f2f30981976e0903c249b0 GIT binary patch literal 430 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2WS_3NUQq-G3KIv7|ftIx;Y9?C1WI$O_~u zBzpw;GB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpafHrx4R1iVG?wXe=^Ydl_mE!;nTTabXF*>g9nbNsJ2?+eVpWHkYyp!!rwnIv1*^zmQ zn~q&v^j*_XCFs$$--6wLBz8tkJMnv}+9uu~J +#include +#include "icon.png.xxd" +#include "default.png.xxd" + +char image[256] = "default" + +int LoadImage(SDL_Renderer* ren){ + if(image == "default"){ + SDL_Surface* img = IMG_Load_IO(SDL_IOFromConstMem(assets_the_modded_machine_png, assets_the_modded_machine_png_len), true); + }else{ + + } +} + +int main(int argc, char* argv[]) { + SDL_Init(SDL_INIT_VIDEO); + + SDL_Window* win = SDL_CreateWindow("SDL3 Image",640, 480, 0); + if (win == NULL) { + SDL_Log("SDL_CreateWindow Error: %s", SDL_GetError()); + SDL_Quit(); + return 1; + } + + SDL_Renderer* ren = SDL_CreateRenderer(win, NULL); + if (ren == NULL) { + SDL_Log("SDL_CreateRenderer Error: %s", SDL_GetError()); + SDL_DestroyWindow(win); + SDL_Quit(); + return 1; + } + + SDL_Surface* bmp = SDL_LoadBMP("lettuce.bmp"); + if (bmp == NULL) { + SDL_Log("Image loading Error: %s", SDL_GetError()); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + SDL_Quit(); + return 1; + } + + SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, bmp); + SDL_DestroySurface(bmp); + + if (tex == NULL) { + std::cerr << "SDL_CreateTextureFromSurface Error: " << SDL_GetError() << std::endl; + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + SDL_Quit(); + return 1; + } + + SDL_Event e; + bool quit = false; + + while (!quit) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_EVENT_QUIT) { + quit = true; + } + } + + SDL_RenderClear(ren); + SDL_RenderTexture(ren, tex, NULL, NULL); + SDL_RenderPresent(ren); + } + + SDL_DestroyTexture(tex); + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + SDL_Quit(); + + return 0; +} diff --git a/src/main.cpp b/src/main.cpp index 49d7bd7..ab343dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,9 @@ #include #include #include +#include #include +#include #ifdef _MSC_VER #include @@ -31,7 +33,6 @@ #else #include #endif -#include #include #include #include @@ -166,41 +167,6 @@ static void setupWindowIcon(const Config &conf, SDL_Window *win){ } } -// mainly doing this so journal app knows where to load images from -static void setGamePathInRegistry() { -#if defined WIN32 - // this logic is currently windows specific - const char* dataDir = SDL_GetBasePath(); - if (dataDir){ - HKEY key; - long keyOpenError = RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), &key); - - if (keyOpenError != ERROR_SUCCESS) { - // try creating the key first - long keyCreateError = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL); - - if (keyCreateError != ERROR_SUCCESS){ - WarnMsg("Unable to create key in registry"); - } - else { - keyOpenError = ERROR_SUCCESS; - } - } - - if (keyOpenError != ERROR_SUCCESS){ - WarnMsg("Unable to open registry."); - } - else { - DWORD dataSize = (SDL_strlen(dataDir) + 1) * sizeof(char); - if (RegSetValueEx(key, TEXT("GameDirectory"), 0, REG_SZ, (LPBYTE)dataDir, dataSize) != ERROR_SUCCESS){ - WarnMsg("Unable to set GameDirectory registry value"); - } - RegCloseKey(key); - } - } -#endif - //TODO handle this for Linux/Mac -} int main(int argc, char *argv[]){ startTime = boost::chrono::high_resolution_clock::now(); loadLanguageMetadata(); //there will be a segfault on fclose if I don't move it here @@ -247,9 +213,6 @@ int main(int argc, char *argv[]){ (void)result; } #endif - - setGamePathInRegistry(); - /* Initialize physfs here so that config can call PHYSFS_getPrefDir */ PHYSFS_init(argv[0]); @@ -266,13 +229,33 @@ int main(int argc, char *argv[]){ freopen("CONOUT$", "w", stderr); } #endif - + if (!conf.gameFolder.empty()){ if (chdir(conf.gameFolder.c_str()) != 0){ WarnMsg("Unable to switch into gameFolder %s", conf.gameFolder.c_str()); return 0; } } + + std::string path; + + if (!conf.gameFolder.empty()) { + if (conf.gameFolder == ".") { + path = std::filesystem::current_path().string(); + } else { + path = std::filesystem::absolute(conf.gameFolder).string(); + } + } else { + path = std::filesystem::current_path().string(); + } + + std::ofstream out(std::filesystem::temp_directory_path() / "sunshine"); + if (!out) { + WarnMsg("Failed to write game directory path to temp file, problems with journal app expected!"); + } else { + out << path; + } + extern int screenMain(Config &conf); if (conf.screenMode) return screenMain(conf); @@ -283,13 +266,13 @@ int main(int argc, char *argv[]){ if (TTF_Init() == false){ WarnMsg("Error initializing SDL_ttf: %s", SDL_GetError()); SDL_Quit(); + return 0; } if (MIX_Init() == false){ WarnMsg("Error initializing SDL_mixer: %s", SDL_GetError()); TTF_Quit(); SDL_Quit(); - return 0; } @@ -305,7 +288,6 @@ int main(int argc, char *argv[]){ MIX_Quit(); TTF_Quit(); SDL_Quit(); - return 0; } @@ -329,8 +311,7 @@ int main(int argc, char *argv[]){ WarnMsg("Error creating Mixer Device, check your system audio configuration"); MIX_Quit(); TTF_Quit(); - SDL_Quit(); - + SDL_Quit(); return 0; }