From 9b3058cad29b6b7a7ef0b6e1a0479bda7217e009 Mon Sep 17 00:00:00 2001 From: ZakatTeamI2P Date: Mon, 30 Mar 2026 20:28:12 +0400 Subject: [PATCH] SDL3 changesssssssssssssssssssss UwU naxui --- src/oneshot.cpp | 5 +++-- src/oneshot.h | 6 +++--- src/screen.cpp | 19 ++++++++++--------- src/sdl-util.h | 50 ++++++++++++++++++++++++------------------------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/oneshot.cpp b/src/oneshot.cpp index 2f7740c..94026e1 100644 --- a/src/oneshot.cpp +++ b/src/oneshot.cpp @@ -357,11 +357,12 @@ void Oneshot::update() screenRect.w = 640; screenRect.h = 480; + //костыль ебучий int num_displays; SDL_DisplayID *displays = SDL_GetDisplays(&num_displays) - + SDL_free(displays); //Update obscured map and texture for window portion offscreen - for (int i = 0, max = SDL_GetNumVideoDisplays(); i < max; ++i) + for (int i = 0, max = num_displays; i < max; ++i) { SDL_Rect bounds; SDL_GetDisplayBounds(i, &bounds); diff --git a/src/oneshot.h b/src/oneshot.h index bb02091..e07d074 100644 --- a/src/oneshot.h +++ b/src/oneshot.h @@ -1,9 +1,9 @@ #ifndef ONESHOT_H #define ONESHOT_H -#include -#include -#include +#include +#include +#include #include "etc-internal.h" #include diff --git a/src/screen.cpp b/src/screen.cpp index 2ce783e..b4179d5 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #define FPS 60 #define DEFAULT_WIDTH 320 @@ -13,7 +13,7 @@ static void showInitError(const std::string &msg) { Debug() << msg; - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OneShot", msg.c_str(), 0); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OneShot: sunshine", msg.c_str(), 0); } static bool readMessage(Pipe &ipc, char *buf, size_t size) @@ -61,9 +61,10 @@ int screenMain(Config &conf) SDL_WindowShapeMode shapeMode; shapeMode.mode = ShapeModeColorKey; shapeMode.parameters.colorKey = colorKey; - - SDL_Surface *shape = SDL_CreateRGBSurface(0, DEFAULT_WIDTH, DEFAULT_HEIGHT, 8, 0, 0, 0, 0); - SDL_SetPaletteColors(shape->format->palette, &black, 0, 1); + //SDL_Surface *surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_INDEX8); + SDL_Surface *shape = SDL_CreateRGBSurface(DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, 0, 0, 0); + // SDL_Palette *palette = SDL_CreateSurfacePalette(surface); + SDL_SetPaletteColors(shape, &black, 0, 1); char messageBuf[256]; @@ -83,7 +84,7 @@ int screenMain(Config &conf) if (strcmp(messageBuf, "END") == 0) break; std::string imgname = conf.gameFolder + "/Journal/" + messageBuf + ".png"; - SDL_FreeSurface(shape); + SDL_DestroySurface(shape); if ((shape = IMG_Load(imgname.c_str())) == NULL) break; SDL_SetWindowSize(win, shape->w, shape->h); @@ -101,6 +102,6 @@ int screenMain(Config &conf) ticks = SDL_GetTicks(); } - SDL_FreeSurface(shape); + SDL_DestroySurface(shape); return 0; } diff --git a/src/sdl-util.h b/src/sdl-util.h index b22ccff..b6c6ea1 100644 --- a/src/sdl-util.h +++ b/src/sdl-util.h @@ -1,9 +1,9 @@ #ifndef SDLUTIL_H #define SDLUTIL_H -#include -#include -#include +#include +#include +#include #include #include @@ -56,32 +56,30 @@ SDL_Thread *createSDLThread(C *obj, const std::string &name = std::string()) * the apk asset folder even when a file with same name exists * on the physical filesystem. This wrapper attempts to open a * real file first before falling back to the assets folder */ -static inline -SDL_RWops *RWFromFile(const char *filename, - const char *mode) -{ - FILE *f = fopen(filename, mode); +//static inline +//SDL_RWops *RWFromFile(const char *filename, +// const char *mode) +//{ +// FILE *f = fopen(filename, mode); +// +// if (!f) +// return SDL_RWFromFile(filename, mode); +// +// return SDL_RWFromFP(f, SDL_TRUE); +//} - if (!f) - return SDL_RWFromFile(filename, mode); - - return SDL_RWFromFP(f, SDL_TRUE); -} - -inline bool readFileSDL(const char *path, - std::string &out) -{ - SDL_RWops *f = RWFromFile(path, "rb"); +inline bool readFileSDL(const char *path, std::string &out){ + SDL_IOStream *f = SDL_IOFromFile(path, "rb"); if (!f) return false; - long size = SDL_RWsize(f); + long size = SDL_GetIOSize(f); size_t back = out.size(); out.resize(back+size); - size_t read = SDL_RWread(f, &out[back], 1, size); - SDL_RWclose(f); + size_t read = SDL_ReadIO(f, &out[back], size); + SDL_CloseIO(f); if (read != (size_t) size) out.resize(back+read); @@ -118,7 +116,7 @@ private: start += pbSize; } - size_t n = SDL_RWread(ops, start, 1, bufSize - (start - base)); + size_t n = SDL_ReadIO(ops, start, 1, bufSize - (start - base)); if (n == 0) return traits_type::eof(); @@ -127,7 +125,7 @@ private: return underflow(); } - SDL_RWops *ops; + SDL_IOStream *ops; char buf[bufSize+pbSize]; }; @@ -136,7 +134,7 @@ class SDLRWStream public: SDLRWStream(const char *filename, const char *mode) - : ops(RWFromFile(filename, mode)), + : ops(SDL_IOFromFile(filename, mode)), buf(ops), s(&buf) {} @@ -144,7 +142,7 @@ public: ~SDLRWStream() { if (ops) - SDL_RWclose(ops); + SDL_CloseIO(ops); } operator bool() const @@ -158,7 +156,7 @@ public: } private: - SDL_RWops *ops; + SDL_CloseIO *ops; SDLRWBuf<> buf; std::istream s; };