Advertisement
Kitomas

ksdl2 work for 2024-08-02 (2/5)

Aug 2nd, 2024 (edited)
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.58 KB | None | 0 0
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. //"ksdl2\src\kit_sdl2\kit_fileio_File.cpp":
  4. #include "_kit_common.hpp"
  5.  
  6.  
  7. #define KIT_IS_INVALID_FILE (!_valid && !_constructing)
  8. #define KIT_FILE_CHECK(_funcName) \
  9.   if(KIT_IS_INVALID_FILE){ throw PUSH_ERROR(_funcName ": invalid File");           } \
  10.   if(_file == nullptr   ){ throw PUSH_ERROR(_funcName ": _file = nullptr");        } \
  11.   if(_closed            ){ throw PUSH_ERROR(_funcName ": file is already closed"); }
  12.  
  13. #define FILE_PTR ((SDL_RWops*)_file)
  14. #define SIZE()                               size(FILE_PTR)
  15. #define READ(_elems, _elemSize, _elems_len)  read(FILE_PTR, _elems, _elemSize, _elems_len)
  16. #define WRITE(_elems, _elemSize, _elems_len) write(FILE_PTR, _elems, _elemSize, _elems_len)
  17. #define SEEK(_off, _whence)                  seek(FILE_PTR, _off, _whence)
  18. #define TELL()                               seek(FILE_PTR, 0, RW_SEEK_CUR)
  19. #define CLOSE()                              close(FILE_PTR)
  20.  
  21.  
  22. namespace kit {
  23.  
  24.  
  25.  
  26.  
  27.  
  28. File::File(const char* filePath, const char* mode){
  29.   _type = KIT_CLASSTYPE_FILE;
  30.  
  31.   _file = (GenOpqPtr)SDL_RWFromFile(filePath, mode);
  32.   if(_file == nullptr) throw PUSH_ERRORF("File::File(): \"%s\"", SDL_GetError());
  33.  
  34.   _valid = true;
  35.   _constructing = false;
  36.  
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. File::~File(){
  44.   if(!_valid) return;
  45.   _valid = false;
  46.  
  47.   if(_file != nullptr){
  48.     _zombie = FILE_PTR->CLOSE()<0;
  49.     _file = nullptr;
  50.   }
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58. size_t File::read(void* elements, size_t elementSize, size_t elements_len){
  59.   KIT_FILE_CHECK("File::read()");
  60.  
  61.   size_t result = FILE_PTR->READ(elements, elementSize, elements_len);
  62.   if(!result && !strnCmp("Error", SDL_GetError()))
  63.     throw PUSH_ERRORF("File::read(): \"%s\"", SDL_GetError());
  64.  
  65.   return result;
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. void File::write(const void* elements, size_t elementSize, size_t elements_len){
  74.   KIT_FILE_CHECK("File::write()");
  75.  
  76.   size_t result = FILE_PTR->WRITE(elements, elementSize, elements_len);
  77.   if(result < elements_len)
  78.     throw PUSH_ERRORF("File::write(): \"%s\"", SDL_GetError());
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86. size_t File::seek(s64 offset, u32 whence){
  87.   KIT_FILE_CHECK("File::seek()");
  88.  
  89.   if(whence > 2) throw PUSH_ERROR("File::seek(): whence is invalid");
  90.  
  91.   s64 result = FILE_PTR->SEEK(offset, whence);
  92.   if(result < 0) throw PUSH_ERRORF("File::seek(): \"%s\"", SDL_GetError());
  93.  
  94.   return (size_t)result;
  95.  
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102. void File::close(){
  103.   KIT_FILE_CHECK("File::close()");
  104.  
  105.   if(FILE_PTR->CLOSE()<0)
  106.     throw PUSH_ERROR("File::close(): write error occurred while flushing data");
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114. size_t File::size(){
  115.   KIT_FILE_CHECK("File::size()");
  116.  
  117.   s64 result = FILE_PTR->SIZE();
  118.   if(result < 0)
  119.     throw PUSH_ERROR("File::size(): failed to get file's size");
  120.  
  121.   return (size_t)result;
  122.  
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129. }; /* namespace kit */
  130. /******************************************************************************/
  131. /******************************************************************************/
  132. //"ksdl2\src\kit_sdl2\kit_func.cpp":
  133. #include "_kit_common.hpp"
  134.  
  135.  
  136. namespace kit {
  137.  
  138.  
  139.  
  140.  
  141.  
  142. //(len_max does not include null-terminator!)
  143. //(if !len_max, call is analogous to str(not n)len)
  144. size_t strnLen(const char* str, size_t len_max){
  145.   //if(str == nullptr) throw PUSH_ERROR("strnLen(): str = nullptr");
  146.  
  147.   size_t len = 0;
  148.  
  149.   if(!len_max){
  150.     for(; str[len]; ++len);
  151.  
  152.   } else {
  153.     for(; str[len] && len<len_max; ++len);
  154.  
  155.   }
  156.  
  157.   return len;
  158.  
  159. }
  160.  
  161.  
  162.  
  163.  
  164. //(len_max does not include null-terminator!)
  165. //(if !len_max, call is analogous to str(not n)cmp)
  166. s32 strnCmp(const char* str_a, const char* str_b, size_t len_max){
  167.   //might uncomment these, maybe not though
  168.   //if(str_a == nullptr) throw PUSH_ERROR("strnCmp(): str_a = nullptr");
  169.   //if(str_b == nullptr) throw PUSH_ERROR("strnCmp(): str_b = nullptr");
  170.  
  171.   if(!len_max){
  172.     while(*str_a && (*str_a == *str_b))
  173.       ++str_a, ++str_b;
  174.  
  175.   } else {
  176.     --len_max;
  177.     while(*str_a && (*str_a == *str_b) && len_max)
  178.       ++str_a, ++str_b, --len_max;
  179.  
  180.   }
  181.  
  182.   return (*(const u8*)str_a) - (*(const u8*)str_b);
  183.  
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190. const char* getLastSysError(){
  191.   return SDL_GetError();
  192.  
  193. }
  194.  
  195.  
  196.  
  197. void clearSysError(){
  198.   SDL_ClearError();
  199.  
  200. }
  201.  
  202.  
  203.  
  204. void freeThreadError(){
  205.   _freeError(); //frees error of *current* thread
  206.  
  207. }
  208.  
  209.  
  210.  
  211.  
  212.  
  213. u32 getNumLogicalCPUCores(){
  214.   return SDL_GetCPUCount();
  215.  
  216. }
  217.  
  218.  
  219.  
  220. u32 getCPUCacheLineSize(){
  221.   return SDL_GetCPUCacheLineSize();
  222.  
  223. }
  224.  
  225.  
  226.  
  227.  
  228.  
  229. #define MSGBOX_EWI_FLAGS (MSGBOX_ERROR|MSGBOX_WARNING|MSGBOX_INFO)
  230.  
  231. void showMsgBox(const char* text, const char* title, u32 flags, Window* win){
  232.   flags &= MSGBOX_EWI_FLAGS;
  233.  
  234.   SDL_Window* win_sdl = nullptr;
  235.   if(win != nullptr){
  236.     if(KIT_GET_CLASS_TYPE(win) != KIT_CLASSTYPE_WINDOW)
  237.       throw PUSH_ERROR("showMsgBoxSimple(): win does not point to a Window object");
  238.     win_sdl = (SDL_Window*)KIT_GET_CLASS_OPAQUE(win);
  239.   }
  240.  
  241.   if(SDL_ShowSimpleMessageBox(flags, title, text, win_sdl)<0)
  242.     throw PUSH_ERRORF("showMsgBoxSimple(): \"%s\"", SDL_GetError());
  243.  
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250. bool clipboardHasText(){
  251.   return SDL_HasClipboardText();
  252.  
  253. }
  254.  
  255.  
  256.  
  257. char* clipboardGetText(){
  258.   char* txt = SDL_GetClipboardText();
  259.  
  260.   //txt will be an empty string on error
  261.   if(!txt[0]){
  262.     //according to the SDL2 wiki, you need to
  263.      //free the returned pointer, even on error
  264.     SDL_free(txt);
  265.  
  266.     throw PUSH_ERRORF("clipboardGetText(): \"%s\"", SDL_GetError());
  267.  
  268.   }
  269.  
  270.   ++numAllocations; //a subsequent call to memory::free should undo this
  271.  
  272.   return txt;
  273.  
  274. }
  275.  
  276.  
  277.  
  278. void clipboardSetText(const char* txt){
  279.   if(SDL_SetClipboardText(txt)<0)
  280.     throw PUSH_ERRORF("clipboardSetText(): \"%s\"", SDL_GetError());
  281.  
  282. }
  283.  
  284.  
  285.  
  286.  
  287.  
  288. bool showCursor(s32 toggle){
  289.   s32 result = SDL_ShowCursor((toggle < 0) ? -1 : toggle&1);
  290.  
  291.   if(result < 0)
  292.     throw PUSH_ERRORF("showCursor(): \"%s\"", SDL_GetError());
  293.  
  294.   return (bool)result;
  295.  
  296. }
  297.  
  298.  
  299.  
  300.  
  301.  
  302. void warpMouseGlobal(s32 x, s32 y){
  303.   if(SDL_WarpMouseGlobal(x, y) < 0)
  304.     throw PUSH_ERRORF("warpMouseGlobal(): \"%s\"", SDL_GetError());
  305.  
  306. }
  307.  
  308.  
  309.  
  310.  
  311.  
  312. }; /* namespace kit */
  313. /******************************************************************************/
  314. /******************************************************************************/
  315. //"ksdl2\src\kit_sdl2\kit_func_init-quit.cpp":
  316. #include "_kit_common.hpp"
  317.  
  318.  
  319. namespace kit {
  320.  
  321.  
  322. _globalStates _gl;
  323. const char _fstr_failure[] = "(FSTR FAILED)";
  324.  
  325.  
  326.  
  327.  
  328.  
  329. #define FLAG_SET(_flag) (flags&(_flag))
  330.  
  331.  
  332.  
  333.  
  334.  
  335. #define SHOULD_INIT(_flag, _member) (FLAG_SET(_flag) && !_gl.init._member)
  336.  
  337. #define INIT_CHECK(_sdl_flag) { \
  338.   if(SDL_InitSubSystem(_sdl_flag)<0){ throw PUSH_ERRORF("initSubsystems(): \"%s\"", SDL_GetError()); } }
  339.  
  340. #define KINIT_JOYSTICK_IMPLICIT (0x40)
  341. #define KINIT_EVENTS_IMPLICIT   (0x80)
  342.  
  343. void initSubsystems(u32 flags){
  344.   SDL_version ver;
  345.   SDL_GetVersion(&ver);
  346.  
  347.   if(ver.major != SDL_MAJOR_VERSION){
  348.     throw PUSH_ERRORF("kit_sdl%u requires SDL%u, not SDL%u",
  349.                       SDL_MAJOR_VERSION, SDL_MAJOR_VERSION, ver.major);
  350.   }
  351.  
  352.   if(ver.minor < SDL_MINOR_VERSION) {
  353.     throw PUSH_ERRORF("SDL%u version must be >= %u.%u.x, not %u.%u.x",
  354.                       SDL_MAJOR_VERSION,
  355.                       SDL_MAJOR_VERSION, SDL_MINOR_VERSION,
  356.                       ver.major, ver.minor);
  357.   }
  358.  
  359.   //just warn instead of error if patch level is less than what it should be
  360.   if(ver.patch < SDL_PATCHLEVEL  &&  ver.minor == SDL_MINOR_VERSION  &&
  361.      !_gl.patch_warning_disabled)
  362.   {
  363.     _log("\b\b\b\b\b\bWARN: SDL%u patch version should be >= x.x.%u, not x.x.%u",
  364.          SDL_MAJOR_VERSION, SDL_PATCHLEVEL, ver.patch);
  365.   }
  366.  
  367.  
  368.   //disable these flags just in case the user set them for whatever reason
  369.   flags &= ~(KINIT_JOYSTICK_IMPLICIT|KINIT_EVENTS_IMPLICIT);
  370.  
  371.  
  372.   if(SHOULD_INIT(KINIT_TIMER, timer)){
  373.     INIT_CHECK(SDL_INIT_TIMER);
  374.     _gl.init.timer = true;
  375.   }
  376.  
  377.  
  378.   if(SHOULD_INIT(KINIT_AUDIO, audio)){
  379.     INIT_CHECK(SDL_INIT_AUDIO);
  380.     _gl.init.audio = true;
  381.   }
  382.  
  383.  
  384.   if(SHOULD_INIT(KINIT_VIDEO, video)){
  385.     INIT_CHECK(SDL_INIT_VIDEO);
  386.     _gl.init.video = true;
  387.     flags |= KINIT_EVENTS_IMPLICIT; //indicate that events should auto-init
  388.   }
  389.  
  390.  
  391.   if(SHOULD_INIT(KINIT_GAMECONTROLLER, gamecontroller)){
  392.     INIT_CHECK(SDL_INIT_GAMECONTROLLER);
  393.     _gl.init.gamecontroller = true;
  394.     flags |= KINIT_JOYSTICK_IMPLICIT; //indicate that joystick should auto-init
  395.   }
  396.  
  397.  
  398.   if(SHOULD_INIT(KINIT_JOYSTICK|KINIT_JOYSTICK_IMPLICIT, joystick)){
  399.     if(FLAG_SET(KINIT_JOYSTICK)){
  400.       INIT_CHECK(SDL_INIT_JOYSTICK);
  401.       _gl.init.joystick_sdl = true;
  402.     }
  403.     _gl.init.joystick = true;
  404.     flags |= KINIT_EVENTS_IMPLICIT; //indicate that events should auto-init
  405.   }
  406.  
  407.  
  408.   if(SHOULD_INIT(KINIT_EVENTS|KINIT_EVENTS_IMPLICIT, events)){
  409.     if(FLAG_SET(KINIT_EVENTS)){
  410.       INIT_CHECK(SDL_INIT_EVENTS);
  411.       _gl.init.events_sdl = true;
  412.     }
  413.     _gl.init.events = true;
  414.   }
  415.  
  416.  
  417.   bool errors_just_created = false;
  418.   if(flags && _gl.errors == nullptr){
  419.     _gl.errors_len = 1;
  420.     _gl.errors     = (Error*)memory::alloc( sizeof(Error) * _gl.errors_len );
  421.  
  422.     if(_gl.errors == nullptr){
  423.       _gl.errors_len = 0;
  424.       throw PUSH_ERROR("initSubsystems(): failed to allocate internal memory");
  425.  
  426.     }
  427.  
  428.     errors_just_created = true;
  429.  
  430.     memory::set(_gl.errors, 0, sizeof(Error) * _gl.errors_len );
  431.  
  432.   }
  433.  
  434.  
  435.   if(_gl.init_value && _gl.lock == nullptr){
  436.     _gl.lock = SDL_CreateMutex();
  437.     if(_gl.lock == nullptr){
  438.       if(errors_just_created) _freeErrors();
  439.       throw PUSH_ERROR("initSubsystems(): failed to create internal mutex");
  440.     }
  441.   }
  442.  
  443. }
  444.  
  445.  
  446.  
  447.  
  448.  
  449. #define SHOULD_QUIT(_flag, _member) (FLAG_SET(_flag) && _gl.init._member)
  450. #define QUIT_SUB(_flag) SDL_QuitSubSystem(_flag)
  451.  
  452. void quitSubsystems(u32 flags){
  453.   flags &= ~(KINIT_JOYSTICK_IMPLICIT|KINIT_EVENTS_IMPLICIT);
  454.  
  455.  
  456.   if(SHOULD_QUIT(KINIT_TIMER, timer)){
  457.     QUIT_SUB(SDL_INIT_TIMER);
  458.     _gl.init.timer = false;
  459.   }
  460.  
  461.  
  462.   if(SHOULD_QUIT(KINIT_AUDIO, audio)){
  463.     QUIT_SUB(SDL_INIT_AUDIO);
  464.     _gl.init.audio = false;
  465.   }
  466.  
  467.  
  468.   if(SHOULD_QUIT(KINIT_VIDEO, video)){
  469.     QUIT_SUB(SDL_INIT_VIDEO);
  470.     _gl.init.video = false;
  471.   }
  472.  
  473.  
  474.   if(SHOULD_QUIT(KINIT_GAMECONTROLLER, gamecontroller)){
  475.     QUIT_SUB(SDL_INIT_GAMECONTROLLER);
  476.     _gl.init.gamecontroller = false;
  477.   }
  478.  
  479.  
  480.   if(SHOULD_QUIT(KINIT_JOYSTICK, joystick)){
  481.     if(_gl.init.joystick_sdl){
  482.       QUIT_SUB(SDL_INIT_JOYSTICK);
  483.       _gl.init.joystick_sdl = false;
  484.     }
  485.     _gl.init.joystick = false;
  486.   }
  487.  
  488.  
  489.   if(SHOULD_QUIT(KINIT_EVENTS, events)){
  490.     if(_gl.init.events_sdl){
  491.       QUIT_SUB(SDL_INIT_EVENTS);
  492.       _gl.init.events_sdl = false;
  493.     }
  494.     _gl.init.events = false;
  495.   }
  496.  
  497.  
  498.  
  499.   if(!_gl.init_value){
  500.     _freeErrors();
  501.  
  502.     if(_gl.lock != nullptr){
  503.       LOCK_GLOBALS();   //to lessen the chance that the mutex is destroyed
  504.       UNLOCK_GLOBALS();  //before all the other threads unlock it
  505.  
  506.       SDL_DestroyMutex(_gl.lock);
  507.       _gl.lock = nullptr;
  508.  
  509.     }
  510.  
  511.     //apparently you still need to call SDL_Quit,
  512.      //(even if you've already closed any open subsystems)
  513.     SDL_Quit();
  514.  
  515.   }
  516.  
  517. }
  518.  
  519.  
  520.  
  521.  
  522.  
  523. }; /* namespace kit */
  524. /******************************************************************************/
  525. /******************************************************************************/
  526. //"ksdl2\src\kit_sdl2\kit_func_pollEvent.cpp":
  527. #include "_kit_common.hpp"
  528.  
  529.  
  530. namespace kit {
  531.  
  532.  
  533.  
  534.  
  535.  
  536. #define ETYPE(_event_type) e_kit.common.type = _event_type
  537.  
  538. bool pollEvent(Event* event_p){
  539.   if(!_gl.init.events)
  540.     throw PUSH_ERROR("pollEvent(): events subsystem is uninitialized");
  541.  
  542.   SDL_Event e_sdl;
  543.   Event     e_kit;
  544.   bool queueWasNotEmpty;
  545.  
  546.   _get_another_event:
  547.  
  548.   queueWasNotEmpty = SDL_PollEvent((event_p != nullptr) ? &e_sdl : nullptr);
  549.  
  550.   if(event_p == nullptr) return queueWasNotEmpty;
  551.   e_kit.common.timestamp = e_sdl.common.timestamp;
  552.  
  553.  
  554.  
  555.   if(queueWasNotEmpty)
  556.   switch(e_sdl.type){
  557.     case SDL_QUIT:  ETYPE(KEVENT_QUIT);  break;
  558.  
  559.  
  560.  
  561.     case SDL_DISPLAYEVENT:
  562.     {
  563.       switch(e_sdl.display.event){
  564.         case SDL_DISPLAYEVENT_ORIENTATION :  ETYPE(KEVENT_DISPLAY_ORIENTATION );  break;
  565.         case SDL_DISPLAYEVENT_CONNECTED   :  ETYPE(KEVENT_DISPLAY_CONNECTED   );  break;
  566.         case SDL_DISPLAYEVENT_DISCONNECTED:  ETYPE(KEVENT_DISPLAY_DISCONNECTED);  break;
  567.         case SDL_DISPLAYEVENT_MOVED       :  ETYPE(KEVENT_DISPLAY_MOVED       );  break;
  568.         default                           :  goto _get_another_event; //this shouldn't happen
  569.       }
  570.       e_kit.display.id   = e_sdl.display.display;
  571.       e_kit.display.data = e_sdl.display.data1;
  572.     } break;
  573.  
  574.  
  575.  
  576.     case SDL_WINDOWEVENT:
  577.     {
  578.       switch(e_sdl.window.event){
  579.         case SDL_WINDOWEVENT_SHOWN          :  ETYPE(KEVENT_WIN_SHOWN          );  break;
  580.         case SDL_WINDOWEVENT_HIDDEN         :  ETYPE(KEVENT_WIN_HIDDEN         );  break;
  581.         case SDL_WINDOWEVENT_EXPOSED        :  ETYPE(KEVENT_WIN_EXPOSED        );  break;
  582.         case SDL_WINDOWEVENT_MOVED          :  ETYPE(KEVENT_WIN_MOVED          );  break;
  583.         case SDL_WINDOWEVENT_RESIZED        :  ETYPE(KEVENT_WIN_RESIZED        );  break;
  584.         case SDL_WINDOWEVENT_SIZE_CHANGED   :  ETYPE(KEVENT_WIN_SIZE_CHANGED   );  break;
  585.         case SDL_WINDOWEVENT_MINIMIZED      :  ETYPE(KEVENT_WIN_MINIMIZED      );  break;
  586.         case SDL_WINDOWEVENT_MAXIMIZED      :  ETYPE(KEVENT_WIN_MAXIMIZED      );  break;
  587.         case SDL_WINDOWEVENT_RESTORED       :  ETYPE(KEVENT_WIN_RESTORED       );  break;
  588.         case SDL_WINDOWEVENT_ENTER          :  ETYPE(KEVENT_WIN_MFOCUS_GAINED  );  break;
  589.         case SDL_WINDOWEVENT_LEAVE          :  ETYPE(KEVENT_WIN_MFOCUS_LOST    );  break;
  590.         case SDL_WINDOWEVENT_FOCUS_GAINED   :  ETYPE(KEVENT_WIN_KFOCUS_GAINED  );  break;
  591.         case SDL_WINDOWEVENT_FOCUS_LOST     :  ETYPE(KEVENT_WIN_KFOCUS_LOST    );  break;
  592.         case SDL_WINDOWEVENT_CLOSE          :  ETYPE(KEVENT_WIN_CLOSE          );  break;
  593.         case SDL_WINDOWEVENT_TAKE_FOCUS     :  ETYPE(KEVENT_WIN_TAKE_FOCUS     );  break;
  594.         case SDL_WINDOWEVENT_HIT_TEST       :  ETYPE(KEVENT_WIN_HIT_TEST       );  break;
  595.         case SDL_WINDOWEVENT_ICCPROF_CHANGED:  ETYPE(KEVENT_WIN_ICCPROF_CHANGED);  break;
  596.         case SDL_WINDOWEVENT_DISPLAY_CHANGED:  ETYPE(KEVENT_WIN_DISPLAY_CHANGED);  break;
  597.         default                             :  goto _get_another_event; //this shouldn't happen
  598.       }
  599.       e_kit.win.id    = e_sdl.window.windowID;
  600.       e_kit.win.data1 = e_sdl.window.data1;
  601.       e_kit.win.data2 = e_sdl.window.data2;
  602.     } break;
  603.  
  604.  
  605.  
  606.     case SDL_KEYDOWN:  ETYPE(KEVENT_KEY_DOWN);  goto _event_key;
  607.     case SDL_KEYUP  :  ETYPE(KEVENT_KEY_UP  );       _event_key:
  608.     {
  609.       e_kit.key.window  = e_sdl.key.windowID;
  610.       e_kit.key.pressed = e_sdl.key.state == SDL_PRESSED;
  611.       e_kit.key.repeat  = e_sdl.key.repeat != 0;
  612.       e_kit.key.vkey    = e_sdl.key.keysym.sym;
  613.       e_kit.key.pkey    = e_sdl.key.keysym.scancode;
  614.       e_kit.key.kmods   = e_sdl.key.keysym.mod;
  615.     } break;
  616.  
  617.  
  618.  
  619.     //not to be confused with key events, as they are separate
  620.     case SDL_KEYMAPCHANGED:  ETYPE(KEVENT_KEYMAPCHANGED);  break;
  621.  
  622.  
  623.  
  624.     case SDL_MOUSEMOTION    :  ETYPE(KEVENT_MOUSE_MOVED);
  625.     {
  626.       e_kit.mouse.button  = e_sdl.motion.state;
  627.       e_kit.mouse.pressed = e_kit.mouse.button != 0;
  628.       e_kit.mouse.x       = e_sdl.motion.x;
  629.       e_kit.mouse.y       = e_sdl.motion.y;
  630.       e_kit.mouse.dx      = e_sdl.motion.xrel;
  631.       e_kit.mouse.dy      = e_sdl.motion.yrel;
  632.     } goto _set_mouse_common;
  633.  
  634.     case SDL_MOUSEBUTTONDOWN:  ETYPE(KEVENT_MOUSE_DOWN);  goto _event_mouse_bt;
  635.     case SDL_MOUSEBUTTONUP  :  ETYPE(KEVENT_MOUSE_UP  );       _event_mouse_bt:
  636.     {
  637.       //(turn button index into button flag using SDL_BUTTON)
  638.       e_kit.mouse.button   = SDL_BUTTON(e_sdl.button.button);
  639.       e_kit.mouse.pressed  = e_sdl.button.state == SDL_PRESSED;
  640.       e_kit.mouse.dblClick = ((MAX(1,e_sdl.button.clicks)-1)&1) > 0;
  641.       e_kit.mouse.x        = e_sdl.button.x;
  642.       e_kit.mouse.y        = e_sdl.button.y;
  643.     } goto _set_mouse_common;
  644.  
  645.     case SDL_MOUSEWHEEL     :  ETYPE(KEVENT_MOUSE_WHEEL);
  646.     {
  647.       e_kit.mouse.flipped = e_sdl.wheel.direction == SDL_MOUSEWHEEL_FLIPPED;
  648.       e_kit.mouse.x       = e_sdl.wheel.mouseX;
  649.       e_kit.mouse.y       = e_sdl.wheel.mouseY;
  650.       e_kit.mouse.dx      = e_sdl.wheel.x;
  651.       e_kit.mouse.dy      = e_sdl.wheel.y;
  652.       e_kit.mouse.pdx     = e_sdl.wheel.preciseX;
  653.       e_kit.mouse.pdy     = e_sdl.wheel.preciseY;
  654.     } //goto _set_mouse_common; //(redundant)
  655.  
  656.     _set_mouse_common: //(common to all Mouse events)
  657.     {
  658.       e_kit.mouse.window = e_sdl.motion.windowID;
  659.     } break;
  660.  
  661.  
  662.  
  663.     case SDL_JOYAXISMOTION    :  ETYPE(KEVENT_JOY_AXIS          );
  664.     {
  665.       e_kit.joy.axis.which = e_sdl.jaxis.axis;
  666.       e_kit.joy.axis.value = e_sdl.jaxis.value;
  667.     } goto _set_joy_common;
  668.  
  669.     case SDL_JOYBALLMOTION    :  ETYPE(KEVENT_JOY_TRACKBALL     );
  670.     {
  671.       e_kit.joy.trackball.which = e_sdl.jball.ball;
  672.       e_kit.joy.trackball.dx    = e_sdl.jball.xrel;
  673.       e_kit.joy.trackball.dy    = e_sdl.jball.yrel;
  674.     } goto _set_joy_common;
  675.  
  676.     case SDL_JOYHATMOTION     :  ETYPE(KEVENT_JOY_HAT           );
  677.     {
  678.       e_kit.joy.hat.which = e_sdl.jhat.hat;
  679.       e_kit.joy.hat.value = e_sdl.jhat.value;
  680.     } goto _set_joy_common;
  681.  
  682.     case SDL_JOYBUTTONDOWN    :  ETYPE(KEVENT_JOY_BUTTON_DOWN   );  goto _event_joy_bt;
  683.     case SDL_JOYBUTTONUP      :  ETYPE(KEVENT_JOY_BUTTON_UP     );       _event_joy_bt:
  684.     {
  685.       e_kit.joy.button.which   = e_sdl.jbutton.button;
  686.       e_kit.joy.button.pressed = e_sdl.jbutton.state == SDL_PRESSED;
  687.     } goto _set_joy_common;
  688.  
  689.     case SDL_JOYDEVICEADDED   :  ETYPE(KEVENT_JOY_DEVICE_ADDED  );  goto _event_joy_dv;
  690.     case SDL_JOYDEVICEREMOVED :  ETYPE(KEVENT_JOY_DEVICE_REMOVED);       _event_joy_dv:
  691.     {
  692.       e_kit.joy.device.added = e_sdl.jdevice.type == SDL_JOYDEVICEADDED;
  693.     } goto _set_joy_common;
  694.  
  695.     case SDL_JOYBATTERYUPDATED:  ETYPE(KEVENT_JOY_BATTERY       );
  696.     {
  697.       e_kit.joy.battery.level = e_sdl.jbattery.level;
  698.     } //goto _set_joy_common; //redundant
  699.  
  700.     _set_joy_common: //(common to all Joystick events)
  701.     {
  702.       e_kit.joy.id = e_sdl.jdevice.which;
  703.     } break;
  704.  
  705.  
  706.  
  707.     case SDL_CONTROLLERAXISMOTION    :  ETYPE(KEVENT_CTLR_AXIS           );
  708.     {
  709.       e_kit.ctlr.axis.which = e_sdl.caxis.axis;
  710.       e_kit.ctlr.axis.value = e_sdl.caxis.value;
  711.     } goto _set_ctlr_common;
  712.  
  713.     case SDL_CONTROLLERBUTTONDOWN    :  ETYPE(KEVENT_CTLR_BUTTON_DOWN    );  goto _event_ctlr_bt;
  714.     case SDL_CONTROLLERBUTTONUP      :  ETYPE(KEVENT_CTLR_BUTTON_UP      );       _event_ctlr_bt:
  715.     {
  716.       e_kit.ctlr.button.which   = e_sdl.cbutton.button;
  717.       e_kit.ctlr.button.pressed = e_sdl.cbutton.state == SDL_PRESSED;
  718.     } goto _set_ctlr_common;
  719.  
  720.     case SDL_CONTROLLERDEVICEADDED   :  ETYPE(KEVENT_CTLR_DEVICE_ADDED   );  goto _event_ctlr_dv;
  721.     case SDL_CONTROLLERDEVICEREMOVED :  ETYPE(KEVENT_CTLR_DEVICE_REMOVED );  goto _event_ctlr_dv;
  722.     case SDL_CONTROLLERDEVICEREMAPPED:  ETYPE(KEVENT_CTLR_DEVICE_REMAPPED);       _event_ctlr_dv:
  723.     {
  724.       e_kit.ctlr.device.subtype = KIT_SUBEVENT_ID(e_kit.type);
  725.     } goto _set_ctlr_common;
  726.  
  727.     case SDL_CONTROLLERTOUCHPADDOWN  :  ETYPE(KEVENT_CTLR_TOUCHPAD_DOWN  );  goto _event_ctlr_tp;
  728.     case SDL_CONTROLLERTOUCHPADMOTION:  ETYPE(KEVENT_CTLR_TOUCHPAD_MOVED );  goto _event_ctlr_tp;
  729.     case SDL_CONTROLLERTOUCHPADUP    :  ETYPE(KEVENT_CTLR_TOUCHPAD_UP    );       _event_ctlr_tp:
  730.     {
  731.       e_kit.ctlr.touchpad.which    = e_sdl.ctouchpad.touchpad;
  732.       e_kit.ctlr.touchpad.finger   = e_sdl.ctouchpad.finger;
  733.       e_kit.ctlr.touchpad.x        = e_sdl.ctouchpad.x;
  734.       e_kit.ctlr.touchpad.y        = e_sdl.ctouchpad.y;
  735.       e_kit.ctlr.touchpad.pressure = e_sdl.ctouchpad.pressure;
  736.     } goto _set_ctlr_common;
  737.  
  738.     case SDL_CONTROLLERSENSORUPDATE  :  ETYPE(KEVENT_CTLR_SENSOR         );
  739.     {
  740.       e_kit.ctlr.sensor.which        = e_sdl.csensor.sensor;
  741.       e_kit.ctlr.sensor.data[0]      = e_sdl.csensor.data[0];
  742.       e_kit.ctlr.sensor.data[1]      = e_sdl.csensor.data[1];
  743.       e_kit.ctlr.sensor.data[2]      = e_sdl.csensor.data[2];
  744.       e_kit.ctlr.sensor.timestamp_us = e_sdl.csensor.timestamp_us;
  745.     } //goto _set_ctlr_common; //(redundant)
  746.  
  747.     _set_ctlr_common: //(common to all GameController events)
  748.     {
  749.       e_kit.ctlr.id = e_sdl.cdevice.which;
  750.     } break;
  751.  
  752.  
  753.  
  754.     case SDL_CLIPBOARDUPDATE:  ETYPE(KEVENT_CLIPBOARDUPDATE);  break;
  755.  
  756.  
  757.  
  758.     case SDL_DROPFILE    :  ETYPE(KEVENT_DROP_FILE    );  goto _event_drop;
  759.     case SDL_DROPTEXT    :  ETYPE(KEVENT_DROP_TEXT    );  goto _event_drop;
  760.     case SDL_DROPBEGIN   :  ETYPE(KEVENT_DROP_BEGIN   );  goto _event_drop;
  761.     case SDL_DROPCOMPLETE:  ETYPE(KEVENT_DROP_COMPLETE);       _event_drop:
  762.     {
  763.       e_kit.drop.filePath = e_sdl.drop.file;
  764.       e_kit.drop.window   = e_sdl.drop.windowID;
  765.     } break;
  766.  
  767.  
  768.  
  769.     case SDL_AUDIODEVICEADDED  :  ETYPE(KEVENT_ADEV_ADDED  );  goto _event_adev;
  770.     case SDL_AUDIODEVICEREMOVED:  ETYPE(KEVENT_ADEV_REMOVED);       _event_adev:
  771.     {
  772.       e_kit.adev.id      = e_sdl.adevice.which;
  773.       e_kit.adev.isInput = e_sdl.adevice.iscapture;
  774.     } break;
  775.  
  776.  
  777.  
  778.     case SDL_RENDER_TARGETS_RESET:  ETYPE(KEVENT_RENDER_TARGETS_RESET);  break;
  779.     case SDL_RENDER_DEVICE_RESET :  ETYPE(KEVENT_RENDER_DEVICE_RESET );  break;
  780.  
  781.  
  782.  
  783.     case SDL_USEREVENT:  ETYPE(KEVENT_USER);
  784.     {
  785.       e_kit.user.window = e_sdl.user.windowID;
  786.       e_kit.user.id     = e_sdl.user.code;
  787.       e_kit.user.data1  = e_sdl.user.data1;
  788.       e_kit.user.data2  = e_sdl.user.data2;
  789.     } break;
  790.  
  791.  
  792.  
  793.     //event is not recognized, so call SDL_PollEvent until either
  794.      //a supported event type is found, or event queue empties
  795.     default: goto _get_another_event;
  796.  
  797.   }
  798.  
  799.  
  800.  
  801.   *event_p = e_kit; //should be impossible for event_p to be null here
  802.  
  803.   return queueWasNotEmpty;
  804.  
  805. }
  806.  
  807.  
  808.  
  809.  
  810.  
  811. const char* getEventText(u32 type){
  812.   const char* eventName;
  813.  
  814.  
  815. #ifdef _DEBUG
  816.   switch(type){
  817.     case KEVENT_NULL                : eventName = "KEVENT_NULL";                 break;
  818.  
  819.     case KEVENT_COMMON              : eventName = "KEVENT_COMMON";               break;
  820.  
  821.     case KEVENT_DISPLAY             : eventName = "KEVENT_DISPLAY";              break;
  822.     case KEVENT_DISPLAY_ORIENTATION : eventName = "KEVENT_DISPLAY_ORIENTATION";  break;
  823.     case KEVENT_DISPLAY_DISCONNECTED: eventName = "KEVENT_DISPLAY_DISCONNECTED"; break;
  824.     case KEVENT_DISPLAY_CONNECTED   : eventName = "KEVENT_DISPLAY_CONNECTED";    break;
  825.     case KEVENT_DISPLAY_MOVED       : eventName = "KEVENT_DISPLAY_MOVED";        break;
  826.  
  827.     case KEVENT_WIN                 : eventName = "KEVENT_WIN";                  break;
  828.     case KEVENT_WIN_EXPOSED         : eventName = "KEVENT_WIN_EXPOSED";          break;
  829.     case KEVENT_WIN_HIDDEN          : eventName = "KEVENT_WIN_HIDDEN";           break;
  830.     case KEVENT_WIN_SHOWN           : eventName = "KEVENT_WIN_SHOWN";            break;
  831.     case KEVENT_WIN_MOVED           : eventName = "KEVENT_WIN_MOVED";            break;
  832.     case KEVENT_WIN_RESIZED         : eventName = "KEVENT_WIN_RESIZED";          break;
  833.     case KEVENT_WIN_SIZE_CHANGED    : eventName = "KEVENT_WIN_SIZE_CHANGED";     break;
  834.     case KEVENT_WIN_RESTORED        : eventName = "KEVENT_WIN_RESTORED";         break;
  835.     case KEVENT_WIN_MINIMIZED       : eventName = "KEVENT_WIN_MINIMIZED";        break;
  836.     case KEVENT_WIN_MAXIMIZED       : eventName = "KEVENT_WIN_MAXIMIZED";        break;
  837.     case KEVENT_WIN_MFOCUS_LOST     : eventName = "KEVENT_WIN_MFOCUS_LOST";      break;
  838.     case KEVENT_WIN_MFOCUS_GAINED   : eventName = "KEVENT_WIN_MFOCUS_GAINED";    break;
  839.     case KEVENT_WIN_KFOCUS_LOST     : eventName = "KEVENT_WIN_KFOCUS_LOST";      break;
  840.     case KEVENT_WIN_KFOCUS_GAINED   : eventName = "KEVENT_WIN_KFOCUS_GAINED";    break;
  841.     case KEVENT_WIN_CLOSE           : eventName = "KEVENT_WIN_CLOSE";            break;
  842.     case KEVENT_WIN_TAKE_FOCUS      : eventName = "KEVENT_WIN_TAKE_FOCUS";       break;
  843.     case KEVENT_WIN_HIT_TEST        : eventName = "KEVENT_WIN_HIT_TEST";         break;
  844.     case KEVENT_WIN_ICCPROF_CHANGED : eventName = "KEVENT_WIN_ICCPROF_CHANGED";  break;
  845.     case KEVENT_WIN_DISPLAY_CHANGED : eventName = "KEVENT_WIN_DISPLAY_CHANGED";  break;
  846.  
  847.     case KEVENT_KEY                 : eventName = "KEVENT_KEY";                  break;
  848.     case KEVENT_KEY_DOWN            : eventName = "KEVENT_KEY_DOWN";             break;
  849.     case KEVENT_KEY_UP              : eventName = "KEVENT_KEY_UP";               break;
  850.  
  851.     case KEVENT_KEYMAPCHANGED       : eventName = "KEVENT_KEYMAPCHANGED";        break;
  852.  
  853.     case KEVENT_MOUSE               : eventName = "KEVENT_MOUSE";                break;
  854.     case KEVENT_MOUSE_MOVED         : eventName = "KEVENT_MOUSE_MOVED";          break;
  855.     case KEVENT_MOUSE_UP            : eventName = "KEVENT_MOUSE_UP";             break;
  856.     case KEVENT_MOUSE_DOWN          : eventName = "KEVENT_MOUSE_DOWN";           break;
  857.     case KEVENT_MOUSE_WHEEL         : eventName = "KEVENT_MOUSE_WHEEL";          break;
  858.  
  859.     case KEVENT_JOY                 : eventName = "KEVENT_JOY";                  break;
  860.     case KEVENT_JOY_AXIS            : eventName = "KEVENT_JOY_AXIS";             break;
  861.     case KEVENT_JOY_TRACKBALL       : eventName = "KEVENT_JOY_TRACKBALL";        break;
  862.     case KEVENT_JOY_HAT             : eventName = "KEVENT_JOY_HAT";              break;
  863.     case KEVENT_JOY_BUTTON_UP       : eventName = "KEVENT_JOY_BUTTON_UP";        break;
  864.     case KEVENT_JOY_BUTTON_DOWN     : eventName = "KEVENT_JOY_BUTTON_DOWN";      break;
  865.     case KEVENT_JOY_DEVICE_REMOVED  : eventName = "KEVENT_JOY_DEVICE_REMOVED";   break;
  866.     case KEVENT_JOY_DEVICE_ADDED    : eventName = "KEVENT_JOY_DEVICE_ADDED";     break;
  867.     case KEVENT_JOY_BATTERY         : eventName = "KEVENT_JOY_BATTERY";          break;
  868.  
  869.     case KEVENT_CTLR                : eventName = "KEVENT_CTLR";                 break;
  870.     case KEVENT_CTLR_AXIS           : eventName = "KEVENT_CTLR_AXIS";            break;
  871.     case KEVENT_CTLR_BUTTON_UP      : eventName = "KEVENT_CTLR_BUTTON_UP";       break;
  872.     case KEVENT_CTLR_BUTTON_DOWN    : eventName = "KEVENT_CTLR_BUTTON_DOWN";     break;
  873.     case KEVENT_CTLR_DEVICE_REMOVED : eventName = "KEVENT_CTLR_DEVICE_REMOVED";  break;
  874.     case KEVENT_CTLR_DEVICE_ADDED   : eventName = "KEVENT_CTLR_DEVICE_ADDED";    break;
  875.     case KEVENT_CTLR_DEVICE_REMAPPED: eventName = "KEVENT_CTLR_DEVICE_REMAPPED"; break;
  876.     case KEVENT_CTLR_TOUCHPAD_UP    : eventName = "KEVENT_CTLR_TOUCHPAD_UP";     break;
  877.     case KEVENT_CTLR_TOUCHPAD_DOWN  : eventName = "KEVENT_CTLR_TOUCHPAD_DOWN";   break;
  878.     case KEVENT_CTLR_TOUCHPAD_MOVED : eventName = "KEVENT_CTLR_TOUCHPAD_MOVED";  break;
  879.     case KEVENT_CTLR_SENSOR         : eventName = "KEVENT_CTLR_SENSOR";          break;
  880.  
  881.     case KEVENT_ADEV                : eventName = "KEVENT_ADEV";                 break;
  882.     case KEVENT_ADEV_ADDED          : eventName = "KEVENT_ADEV_ADDED";           break;
  883.     case KEVENT_ADEV_REMOVED        : eventName = "KEVENT_ADEV_REMOVED";         break;
  884.  
  885.     case KEVENT_DROP                : eventName = "KEVENT_DROP";                 break;
  886.     case KEVENT_DROP_FILE           : eventName = "KEVENT_DROP_FILE";            break;
  887.     case KEVENT_DROP_TEXT           : eventName = "KEVENT_DROP_TEXT";            break;
  888.     case KEVENT_DROP_BEGIN          : eventName = "KEVENT_DROP_BEGIN";           break;
  889.     case KEVENT_DROP_COMPLETE       : eventName = "KEVENT_DROP_COMPLETE";        break;
  890.  
  891.     case KEVENT_QUIT                : eventName = "KEVENT_QUIT";                 break;
  892.  
  893.     case KEVENT_USER                : eventName = "KEVENT_USER";                 break;
  894.  
  895.     case KEVENT_RENDER              : eventName = "KEVENT_RENDER";               break;
  896.     case KEVENT_RENDER_TARGETS_RESET: eventName = "KEVENT_RENDER_TARGETS_RESET"; break;
  897.     case KEVENT_RENDER_DEVICE_RESET : eventName = "KEVENT_RENDER_DEVICE_RESET "; break;
  898.  
  899.     case KEVENT_CLIPBOARDUPDATE     : eventName = "KEVENT_CLIPBOARDUPDATE";      break;
  900.  
  901.     default                         : eventName = "KEVENT_UNKNOWN";
  902.   }
  903.  
  904.  
  905. #else
  906.   type = type; //makes the unused variable warning go away without using #pragma
  907.   eventName = "(getEventText() is not available in release build)";
  908.  
  909.  
  910. #endif /* _DEBUG */
  911.  
  912.  
  913.   return eventName;
  914.  
  915. }
  916.  
  917.  
  918.  
  919.  
  920.  
  921. }; /* namespace kit */
  922. /******************************************************************************/
  923. /******************************************************************************/
  924. //"ksdl2\src\kit_sdl2\kit_lodepng_custom.cpp":
  925. #include "_kit_common.hpp"
  926.  
  927.  
  928. using namespace kit;
  929.  
  930.  
  931.  
  932.  
  933.  
  934. void* lodepng_malloc(size_t size){
  935. #ifdef LODEPNG_MAX_ALLOC
  936.   if(size > LODEPNG_MAX_ALLOC) return 0;
  937. #endif
  938.   return memory::alloc(size);
  939.  
  940. }
  941.  
  942.  
  943.  
  944.  
  945.  
  946. // NOTE: when realloc returns NULL, it leaves the original memory untouched
  947. void* lodepng_realloc(void* ptr, size_t new_size){
  948. #ifdef LODEPNG_MAX_ALLOC
  949.   if(new_size > LODEPNG_MAX_ALLOC) return 0;
  950. #endif
  951.   return memory::realloc(&ptr, new_size);
  952.  
  953. }
  954.  
  955.  
  956.  
  957.  
  958.  
  959. void lodepng_free(void* ptr){
  960.   memory::free(&ptr);
  961.  
  962. }
  963.  
  964.  
  965.  
  966.  
  967.  
  968. //i rewrote lodepng's file io functions to only use SDL functions
  969.  
  970. #ifndef LODEPNG_NO_COMPILE_DISK
  971.  
  972.  
  973. #undef LONG_MAX
  974. #define LONG_MAX (2147483647)
  975.  
  976.  
  977. unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) {
  978.   *out = (unsigned char*)SDL_LoadFile(filename, outsize);
  979.  
  980.   if(*out == nullptr){
  981.     return 78;
  982.  
  983.   } else {
  984.     ++numAllocations; //a subsequent call to memory::free should undo this
  985.  
  986.     return 0;
  987.   }
  988.  
  989. }
  990.  
  991.  
  992. // write given buffer to the file, overwriting the file, it doesn't append to it.
  993. unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) {
  994.   SDL_RWops* file = SDL_RWFromFile(filename, "wb");
  995.   if(file == nullptr) return 79;
  996.  
  997.   size_t bytesWritten = SDL_RWwrite(file, buffer, 1, buffersize);
  998.  
  999.   SDL_RWclose(file);
  1000.  
  1001.   if(bytesWritten < buffersize) return 79;
  1002.   else                          return  0;
  1003.  
  1004. }
  1005.  
  1006.  
  1007.  
  1008. /*
  1009. #undef LONG_MAX
  1010. #define LONG_MAX (2147483647)
  1011. #include <stdio.h>
  1012.  
  1013. // returns negative value on error. This should be pure C compatible, so no fstat.
  1014. static long lodepng_filesize(const char* filename) {
  1015.   FILE* file;
  1016.   long size;
  1017.   file = fopen(filename, "rb");
  1018.   if(!file) return -1;
  1019.  
  1020.   if(fseek(file, 0, SEEK_END) != 0) {
  1021.     fclose(file);
  1022.     return -1;
  1023.   }
  1024.  
  1025.   size = ftell(file);
  1026.   // It may give LONG_MAX as directory size, this is invalid for us.
  1027.   if(size == LONG_MAX) size = -1;
  1028.  
  1029.   fclose(file);
  1030.   return size;
  1031. }
  1032.  
  1033. // load file into buffer that already has the correct allocated size. Returns error code.
  1034. static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) {
  1035.   FILE* file;
  1036.   size_t readsize;
  1037.   file = fopen(filename, "rb");
  1038.   if(!file) return 78;
  1039.  
  1040.   readsize = fread(out, 1, size, file);
  1041.   fclose(file);
  1042.  
  1043.   if(readsize != size) return 78;
  1044.   return 0;
  1045. }
  1046.  
  1047. unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) {
  1048.   long size = lodepng_filesize(filename);
  1049.   if(size < 0) return 78;
  1050.   *outsize = (size_t)size;
  1051.  
  1052.   *out = (unsigned char*)lodepng_malloc((size_t)size);
  1053.   if(!(*out) && size > 0) return 83; // the above malloc failed
  1054.  
  1055.   return lodepng_buffer_file(*out, (size_t)size, filename);
  1056. }
  1057.  
  1058. // write given buffer to the file, overwriting the file, it doesn't append to it.
  1059. unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) {
  1060.   FILE* file;
  1061.   file = fopen(filename, "wb" );
  1062.   if(!file) return 79;
  1063.   fwrite(buffer, 1, buffersize, file);
  1064.   fclose(file);
  1065.   return 0;
  1066. }
  1067. */
  1068.  
  1069. #endif /* LODEPNG_NO_COMPILE_DISK */
  1070.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement