Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest SDL3-CS friendly overload and null-terminated UTF8 conversion #6245

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions osu.Framework.iOS/IOSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ protected override unsafe void RunMainLoop()
// iOS may be a good forward direction if this ever comes up, as a user may see a potentially higher
// frame rate with multi-threaded mode turned on, but it is going to give them worse input latency
// and higher power usage.
SDL3.SDL_iPhoneSetEventPump(SDL_bool.SDL_FALSE);
SDL3.SDL_iPhoneSetAnimationCallback(SDLWindowHandle, 1, &runFrame, ObjectHandle.Handle);
SDL3.SDL_iOSSetEventPump(SDL_bool.SDL_FALSE);
SDL3.SDL_iOSSetAnimationCallback(SDLWindowHandle, 1, &runFrame, ObjectHandle.Handle);
}

[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Platform/SDL/SDL3Clipboard.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Text;
using SDL;
using SixLabors.ImageSharp;

Expand All @@ -14,7 +13,7 @@ public class SDL3Clipboard : Clipboard
// assume that empty text means no text.
public override string? GetText() => SDL3.SDL_HasClipboardText() == SDL_bool.SDL_TRUE ? SDL3.SDL_GetClipboardText() : null;

public override void SetText(string text) => SDL3.SDL_SetClipboardText(Encoding.UTF8.GetBytes(text));
public override void SetText(string text) => SDL3.SDL_SetClipboardText(text);

public override Image<TPixel>? GetImage<TPixel>()
{
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Platform/SDL/SDL3GraphicsSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using osuTK.Graphics;
using osuTK.Graphics.ES30;
using SDL;
Expand Down Expand Up @@ -141,7 +140,7 @@ private IntPtr getProcAddress(string symbol)
// Prevent logging calls to SDL_GL_GetProcAddress() that fail on systems which don't have the requested symbol (typically macOS).
SDL3.SDL_LogSetPriority(error_category, SDL_LogPriority.SDL_LOG_PRIORITY_INFO);

IntPtr ret = SDL3.SDL_GL_GetProcAddress(Encoding.UTF8.GetBytes(symbol));
IntPtr ret = SDL3.SDL_GL_GetProcAddress(symbol);

// Reset the logging behaviour.
SDL3.SDL_LogSetPriority(error_category, oldPriority);
Expand Down
18 changes: 8 additions & 10 deletions osu.Framework/Platform/SDL3Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Configuration;
Expand Down Expand Up @@ -70,7 +69,7 @@ public string Title
set
{
title = value;
ScheduleCommand(() => SDL3.SDL_SetWindowTitle(SDLWindowHandle, Encoding.UTF8.GetBytes(title)));
ScheduleCommand(() => SDL3.SDL_SetWindowTitle(SDLWindowHandle, title));
}
}

Expand Down Expand Up @@ -202,7 +201,7 @@ public virtual void Create()
// so we deactivate it on startup.
SDL3.SDL_StopTextInput();

SDLWindowHandle = SDL3.SDL_CreateWindow(Encoding.UTF8.GetBytes(title), Size.Width, Size.Height, flags);
SDLWindowHandle = SDL3.SDL_CreateWindow(title, Size.Width, Size.Height, flags);

if (SDLWindowHandle == null)
throw new InvalidOperationException($"Failed to create SDL window. SDL Error: {SDL3.SDL_GetError()}");
Expand Down Expand Up @@ -275,7 +274,7 @@ protected void RunFrame()
/// </remarks>
protected virtual void HandleEventFromFilter(SDL_Event evt)
{
switch (evt.type)
switch (evt.Type)
{
case SDL_EventType.SDL_EVENT_TERMINATING:
handleQuitEvent(evt.quit);
Expand All @@ -297,7 +296,7 @@ protected virtual void HandleEventFromFilter(SDL_Event evt)

protected void HandleEventFromWatch(SDL_Event evt)
{
switch (evt.type)
switch (evt.Type)
{
case SDL_EventType.SDL_EVENT_WINDOW_RESIZED:
// polling via SDL_PollEvent blocks on resizes (https://stackoverflow.com/a/50858339)
Expand Down Expand Up @@ -450,8 +449,7 @@ private void pollSDLEvents()

do
{
fixed (SDL_Event* buf = events)
eventsRead = SDL3.SDL_PeepEvents(buf, events_per_peep, SDL_eventaction.SDL_GETEVENT, SDL_EventType.SDL_EVENT_FIRST, SDL_EventType.SDL_EVENT_LAST);
eventsRead = SDL3.SDL_PeepEvents(events, SDL_eventaction.SDL_GETEVENT, SDL_EventType.SDL_EVENT_FIRST, SDL_EventType.SDL_EVENT_LAST);
for (int i = 0; i < eventsRead; i++)
HandleEvent(events[i]);
} while (eventsRead == events_per_peep);
Expand All @@ -462,19 +460,19 @@ private void pollSDLEvents()
/// </summary>
protected virtual void HandleEvent(SDL_Event e)
{
if (e.type >= SDL_EventType.SDL_EVENT_DISPLAY_FIRST && e.type <= SDL_EventType.SDL_EVENT_DISPLAY_LAST)
if (e.Type >= SDL_EventType.SDL_EVENT_DISPLAY_FIRST && e.Type <= SDL_EventType.SDL_EVENT_DISPLAY_LAST)
{
handleDisplayEvent(e.display);
return;
}

if (e.type >= SDL_EventType.SDL_EVENT_WINDOW_FIRST && e.type <= SDL_EventType.SDL_EVENT_WINDOW_LAST)
if (e.Type >= SDL_EventType.SDL_EVENT_WINDOW_FIRST && e.Type <= SDL_EventType.SDL_EVENT_WINDOW_LAST)
{
handleWindowEvent(e.window);
return;
}

switch (e.type)
switch (e.Type)
{
case SDL_EventType.SDL_EVENT_QUIT:
handleQuitEvent(e.quit);
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Platform/Windows/WindowsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private SDL_bool handleEventFromHook(MSG msg)

protected override void HandleEventFromFilter(SDL_Event evt)
{
switch (evt.type)
switch (evt.Type)
{
case SDL_EventType.SDL_EVENT_WINDOW_FOCUS_LOST:
warpCursorFromFocusLoss();
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/osu.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="ppy.osuTK.NS20" Version="1.0.211" />
<PackageReference Include="StbiSharp" Version="1.1.0" />
<PackageReference Include="ppy.SDL3-CS" Version="2024.413.0" />
<PackageReference Include="ppy.SDL3-CS" Version="2024.418.1" />
<PackageReference Include="ppy.osu.Framework.SourceGeneration" Version="2023.720.0" />

<!-- DO NOT use ProjectReference for native packaging project.
Expand Down
Loading