Skip to content

Commit

Permalink
Initial source code support for SDL3. No build system support.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Feb 4, 2024
1 parent 5acc98c commit 62ac858
Show file tree
Hide file tree
Showing 23 changed files with 1,617 additions and 156 deletions.
10 changes: 8 additions & 2 deletions src/common/delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
#include "delay.h"

#include <SDL_timer.h>
#include <SDL_version.h>

namespace love
{

void sleep(unsigned int ms)
// TODO: use ns.
void sleep(double ms)
{
// We don't need to initialize the SDL timer subsystem for SDL_Delay to
// function - and doing so causes SDL to create a worker thread.
SDL_Delay(ms);
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_DelayNS(SDL_MS_TO_NS(ms));
#else
SDL_Delay((Uint32)ms);
#endif
}

} // love
2 changes: 1 addition & 1 deletion src/common/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace love
{

void sleep(unsigned int ms);
void sleep(double ms);

} // namespace love

Expand Down
19 changes: 15 additions & 4 deletions src/common/macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
#import <Cocoa/Cocoa.h>
#import <QuartzCore/CAMetalLayer.h>

#ifdef LOVE_MACOSX_SDL_DIRECT_INCLUDE
#include <SDL.h>
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#include <SDL_syswm.h>
#else
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#endif

namespace love
Expand Down Expand Up @@ -63,6 +60,13 @@
SDL_InitSubSystem(SDL_INIT_VIDEO);

SDL_PumpEvents();
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENT_DROP_FILE, SDL_EVENT_DROP_FILE) > 0)
{
if (event.type == SDL_EVENT_DROP_FILE)
dropstr = std::string(event.drop.data);
}
#else
if (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_DROPFILE, SDL_DROPFILE) > 0)
{
if (event.type == SDL_DROPFILE)
Expand All @@ -71,6 +75,7 @@
SDL_free(event.drop.file);
}
}
#endif

SDL_QuitSubSystem(SDL_INIT_VIDEO);

Expand Down Expand Up @@ -122,9 +127,15 @@ void setWindowSRGBColorSpace(SDL_Window *window)
// (at least, it was back when I tested in December 2016).
if (@available(macOS 11.0, *))
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_PropertiesID props = SDL_GetWindowProperties(window);
NSWindow *window = (__bridge NSWindow *) SDL_GetProperty(props, SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, nullptr);
window.colorSpace = [NSColorSpace sRGBColorSpace];
#else
SDL_SysWMinfo info = {};
if (SDL_GetWindowWMInfo(window, &info))
info.info.cocoa.window.colorSpace = [NSColorSpace sRGBColorSpace];
#endif
}
}
}
Expand Down
Loading

0 comments on commit 62ac858

Please sign in to comment.