Skip to content

Commit

Permalink
Hook up SDL3_FNAPlatform to FNAPlatform
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Sep 26, 2024
1 parent 373b340 commit 9f24e06
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 58 deletions.
2 changes: 2 additions & 0 deletions FNA.NetFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<Compile Include="src\FNAPlatform\FNAPlatform.cs" />
<Compile Include="src\FNAPlatform\FNAWindow.cs" />
<Compile Include="src\FNAPlatform\SDL2_FNAPlatform.cs" />
<Compile Include="src\FNAPlatform\SDL3_FNAPlatform.cs" />
<Compile Include="src\FrameworkDispatcher.cs" />
<Compile Include="src\Game.cs" />
<Compile Include="src\GameComponent.cs" />
Expand Down Expand Up @@ -338,6 +339,7 @@
<Compile Include="src\Vector3.cs" />
<Compile Include="src\Vector4.cs" />
<Compile Include="lib\SDL2-CS\src\SDL2.cs" />
<Compile Include="lib\SDL3-CS\SDL3\SDL3.cs" />
<Compile Include="lib\FAudio\csharp\FAudio.cs" />
<Compile Include="lib\Theorafile\csharp\Theorafile.cs" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions FNA.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<Compile Include="src\FNAPlatform\FNAPlatform.cs" />
<Compile Include="src\FNAPlatform\FNAWindow.cs" />
<Compile Include="src\FNAPlatform\SDL2_FNAPlatform.cs" />
<Compile Include="src\FNAPlatform\SDL3_FNAPlatform.cs" />
<Compile Include="src\FrameworkDispatcher.cs" />
<Compile Include="src\Game.cs" />
<Compile Include="src\GameComponent.cs" />
Expand Down Expand Up @@ -337,6 +338,7 @@
<Compile Include="src\Vector3.cs" />
<Compile Include="src\Vector4.cs" />
<Compile Include="lib\SDL2-CS\src\SDL2.cs" />
<Compile Include="lib\SDL3-CS\SDL3\SDL3.cs" />
<Compile Include="lib\FAudio\csharp\FAudio.cs" />
<Compile Include="lib\Theorafile\csharp\Theorafile.cs" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ SRC = \
src/FNAPlatform/FNAPlatform.cs \
src/FNAPlatform/FNAWindow.cs \
src/FNAPlatform/SDL2_FNAPlatform.cs \
src/FNAPlatform/SDL3_FNAPlatform.cs \
src/FrameworkDispatcher.cs \
src/Game.cs \
src/GameComponent.cs \
Expand Down Expand Up @@ -321,6 +322,7 @@ SRC = \
src/Vector3.cs \
src/Vector4.cs \
lib/SDL2-CS/src/SDL2.cs \
lib/SDL3-CS/SDL3/SDL3.cs \
lib/FAudio/csharp/FAudio.cs \
lib/Theorafile/csharp/Theorafile.cs

Expand Down
185 changes: 129 additions & 56 deletions src/FNAPlatform/FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ static FNAPlatform()
* -flibit
*/

// Environment.GetEnvironmentVariable("FNA_PLATFORM_BACKEND");
bool useSDL3 = Environment.GetEnvironmentVariable("FNA_PLATFORM_BACKEND") == "SDL3";

SetEnv = SDL2_FNAPlatform.SetEnv;
if (useSDL3)
{
SetEnv = SDL3_FNAPlatform.SetEnv;
}
else
{
SetEnv = SDL2_FNAPlatform.SetEnv;
}

// Built-in command line arguments
LaunchParameters args = new LaunchParameters();
Expand Down Expand Up @@ -93,63 +100,129 @@ static FNAPlatform()
);
}

Malloc = SDL2_FNAPlatform.Malloc;
Free = SDL2.SDL.SDL_free;
CreateWindow = SDL2_FNAPlatform.CreateWindow;
DisposeWindow = SDL2_FNAPlatform.DisposeWindow;
ApplyWindowChanges = SDL2_FNAPlatform.ApplyWindowChanges;
ScaleForWindow = SDL2_FNAPlatform.ScaleForWindow;
GetWindowBounds = SDL2_FNAPlatform.GetWindowBounds;
GetWindowResizable = SDL2_FNAPlatform.GetWindowResizable;
SetWindowResizable = SDL2_FNAPlatform.SetWindowResizable;
GetWindowBorderless = SDL2_FNAPlatform.GetWindowBorderless;
SetWindowBorderless = SDL2_FNAPlatform.SetWindowBorderless;
SetWindowTitle = SDL2_FNAPlatform.SetWindowTitle;
IsScreenKeyboardShown = SDL2_FNAPlatform.IsScreenKeyboardShown;
RegisterGame = SDL2_FNAPlatform.RegisterGame;
UnregisterGame = SDL2_FNAPlatform.UnregisterGame;
PollEvents = SDL2_FNAPlatform.PollEvents;
GetGraphicsAdapters = SDL2_FNAPlatform.GetGraphicsAdapters;
GetCurrentDisplayMode = SDL2_FNAPlatform.GetCurrentDisplayMode;
GetKeyFromScancode = SDL2_FNAPlatform.GetKeyFromScancode;
IsTextInputActive = SDL2_FNAPlatform.IsTextInputActive;
StartTextInput = SDL2.SDL.SDL_StartTextInput;
StopTextInput = SDL2.SDL.SDL_StopTextInput;
SetTextInputRectangle = SDL2_FNAPlatform.SetTextInputRectangle;
GetMouseState = SDL2_FNAPlatform.GetMouseState;
SetMousePosition = SDL2.SDL.SDL_WarpMouseInWindow;
OnIsMouseVisibleChanged = SDL2_FNAPlatform.OnIsMouseVisibleChanged;
GetRelativeMouseMode = SDL2_FNAPlatform.GetRelativeMouseMode;
SetRelativeMouseMode = SDL2_FNAPlatform.SetRelativeMouseMode;
GetGamePadCapabilities = SDL2_FNAPlatform.GetGamePadCapabilities;
GetGamePadState = SDL2_FNAPlatform.GetGamePadState;
SetGamePadVibration = SDL2_FNAPlatform.SetGamePadVibration;
SetGamePadTriggerVibration = SDL2_FNAPlatform.SetGamePadTriggerVibration;
GetGamePadGUID = SDL2_FNAPlatform.GetGamePadGUID;
SetGamePadLightBar = SDL2_FNAPlatform.SetGamePadLightBar;
GetGamePadGyro = SDL2_FNAPlatform.GetGamePadGyro;
GetGamePadAccelerometer = SDL2_FNAPlatform.GetGamePadAccelerometer;
GetStorageRoot = SDL2_FNAPlatform.GetStorageRoot;
GetDriveInfo = SDL2_FNAPlatform.GetDriveInfo;
ReadFileToPointer = SDL2_FNAPlatform.ReadToPointer;
FreeFilePointer = SDL2_FNAPlatform.FreeFilePointer;
ShowRuntimeError = SDL2_FNAPlatform.ShowRuntimeError;
GetMicrophones = SDL2_FNAPlatform.GetMicrophones;
GetMicrophoneSamples = SDL2_FNAPlatform.GetMicrophoneSamples;
GetMicrophoneQueuedBytes = SDL2_FNAPlatform.GetMicrophoneQueuedBytes;
StartMicrophone = SDL2_FNAPlatform.StartMicrophone;
StopMicrophone = SDL2_FNAPlatform.StopMicrophone;
GetTouchCapabilities = SDL2_FNAPlatform.GetTouchCapabilities;
UpdateTouchPanelState = SDL2_FNAPlatform.UpdateTouchPanelState;
GetNumTouchFingers = SDL2_FNAPlatform.GetNumTouchFingers;
SupportsOrientationChanges = SDL2_FNAPlatform.SupportsOrientationChanges;
NeedsPlatformMainLoop = SDL2_FNAPlatform.NeedsPlatformMainLoop;
RunPlatformMainLoop = SDL2_FNAPlatform.RunPlatformMainLoop;
if (useSDL3)
{
Malloc = SDL3_FNAPlatform.Malloc;
Free = SDL3.SDL.SDL_free;
CreateWindow = SDL3_FNAPlatform.CreateWindow;
DisposeWindow = SDL3_FNAPlatform.DisposeWindow;
ApplyWindowChanges = SDL3_FNAPlatform.ApplyWindowChanges;
ScaleForWindow = SDL3_FNAPlatform.ScaleForWindow;
GetWindowBounds = SDL3_FNAPlatform.GetWindowBounds;
GetWindowResizable = SDL3_FNAPlatform.GetWindowResizable;
SetWindowResizable = SDL3_FNAPlatform.SetWindowResizable;
GetWindowBorderless = SDL3_FNAPlatform.GetWindowBorderless;
SetWindowBorderless = SDL3_FNAPlatform.SetWindowBorderless;
SetWindowTitle = SDL3_FNAPlatform.SetWindowTitle;
IsScreenKeyboardShown = SDL3_FNAPlatform.IsScreenKeyboardShown;
RegisterGame = SDL3_FNAPlatform.RegisterGame;
UnregisterGame = SDL3_FNAPlatform.UnregisterGame;
PollEvents = SDL3_FNAPlatform.PollEvents;
GetGraphicsAdapters = SDL3_FNAPlatform.GetGraphicsAdapters;
GetCurrentDisplayMode = SDL3_FNAPlatform.GetCurrentDisplayMode;
GetKeyFromScancode = SDL3_FNAPlatform.GetKeyFromScancode;
IsTextInputActive = SDL3_FNAPlatform.IsTextInputActive;
StartTextInput = SDL3_FNAPlatform.StartTextInput;
StopTextInput = SDL3_FNAPlatform.StopTextInput;
SetTextInputRectangle = SDL3_FNAPlatform.SetTextInputRectangle;
GetMouseState = SDL3_FNAPlatform.GetMouseState;
SetMousePosition = SDL3_FNAPlatform.WarpMouseInWindow;
OnIsMouseVisibleChanged = SDL3_FNAPlatform.OnIsMouseVisibleChanged;
GetRelativeMouseMode = SDL3_FNAPlatform.GetRelativeMouseMode;
SetRelativeMouseMode = SDL3_FNAPlatform.SetRelativeMouseMode;
GetGamePadCapabilities = SDL3_FNAPlatform.GetGamePadCapabilities;
GetGamePadState = SDL3_FNAPlatform.GetGamePadState;
SetGamePadVibration = SDL3_FNAPlatform.SetGamePadVibration;
SetGamePadTriggerVibration = SDL3_FNAPlatform.SetGamePadTriggerVibration;
GetGamePadGUID = SDL3_FNAPlatform.GetGamePadGUID;
SetGamePadLightBar = SDL3_FNAPlatform.SetGamePadLightBar;
GetGamePadGyro = SDL3_FNAPlatform.GetGamePadGyro;
GetGamePadAccelerometer = SDL3_FNAPlatform.GetGamePadAccelerometer;
GetStorageRoot = SDL3_FNAPlatform.GetStorageRoot;
GetDriveInfo = SDL3_FNAPlatform.GetDriveInfo;
ReadFileToPointer = SDL3_FNAPlatform.ReadToPointer;
FreeFilePointer = SDL3_FNAPlatform.FreeFilePointer;
ShowRuntimeError = SDL3_FNAPlatform.ShowRuntimeError;
GetMicrophones = SDL3_FNAPlatform.GetMicrophones;
GetMicrophoneSamples = SDL3_FNAPlatform.GetMicrophoneSamples;
GetMicrophoneQueuedBytes = SDL3_FNAPlatform.GetMicrophoneQueuedBytes;
StartMicrophone = SDL3_FNAPlatform.StartMicrophone;
StopMicrophone = SDL3_FNAPlatform.StopMicrophone;
GetTouchCapabilities = SDL3_FNAPlatform.GetTouchCapabilities;
UpdateTouchPanelState = SDL3_FNAPlatform.UpdateTouchPanelState;
GetNumTouchFingers = SDL3_FNAPlatform.GetNumTouchFingers;
SupportsOrientationChanges = SDL3_FNAPlatform.SupportsOrientationChanges;
NeedsPlatformMainLoop = SDL3_FNAPlatform.NeedsPlatformMainLoop;
RunPlatformMainLoop = SDL3_FNAPlatform.RunPlatformMainLoop;
}
else
{
Malloc = SDL2_FNAPlatform.Malloc;
Free = SDL2.SDL.SDL_free;
CreateWindow = SDL2_FNAPlatform.CreateWindow;
DisposeWindow = SDL2_FNAPlatform.DisposeWindow;
ApplyWindowChanges = SDL2_FNAPlatform.ApplyWindowChanges;
ScaleForWindow = SDL2_FNAPlatform.ScaleForWindow;
GetWindowBounds = SDL2_FNAPlatform.GetWindowBounds;
GetWindowResizable = SDL2_FNAPlatform.GetWindowResizable;
SetWindowResizable = SDL2_FNAPlatform.SetWindowResizable;
GetWindowBorderless = SDL2_FNAPlatform.GetWindowBorderless;
SetWindowBorderless = SDL2_FNAPlatform.SetWindowBorderless;
SetWindowTitle = SDL2_FNAPlatform.SetWindowTitle;
IsScreenKeyboardShown = SDL2_FNAPlatform.IsScreenKeyboardShown;
RegisterGame = SDL2_FNAPlatform.RegisterGame;
UnregisterGame = SDL2_FNAPlatform.UnregisterGame;
PollEvents = SDL2_FNAPlatform.PollEvents;
GetGraphicsAdapters = SDL2_FNAPlatform.GetGraphicsAdapters;
GetCurrentDisplayMode = SDL2_FNAPlatform.GetCurrentDisplayMode;
GetKeyFromScancode = SDL2_FNAPlatform.GetKeyFromScancode;
IsTextInputActive = SDL2_FNAPlatform.IsTextInputActive;
StartTextInput = SDL2.SDL.SDL_StartTextInput;
StopTextInput = SDL2.SDL.SDL_StopTextInput;
SetTextInputRectangle = SDL2_FNAPlatform.SetTextInputRectangle;
GetMouseState = SDL2_FNAPlatform.GetMouseState;
SetMousePosition = SDL2.SDL.SDL_WarpMouseInWindow;
OnIsMouseVisibleChanged = SDL2_FNAPlatform.OnIsMouseVisibleChanged;
GetRelativeMouseMode = SDL2_FNAPlatform.GetRelativeMouseMode;
SetRelativeMouseMode = SDL2_FNAPlatform.SetRelativeMouseMode;
GetGamePadCapabilities = SDL2_FNAPlatform.GetGamePadCapabilities;
GetGamePadState = SDL2_FNAPlatform.GetGamePadState;
SetGamePadVibration = SDL2_FNAPlatform.SetGamePadVibration;
SetGamePadTriggerVibration = SDL2_FNAPlatform.SetGamePadTriggerVibration;
GetGamePadGUID = SDL2_FNAPlatform.GetGamePadGUID;
SetGamePadLightBar = SDL2_FNAPlatform.SetGamePadLightBar;
GetGamePadGyro = SDL2_FNAPlatform.GetGamePadGyro;
GetGamePadAccelerometer = SDL2_FNAPlatform.GetGamePadAccelerometer;
GetStorageRoot = SDL2_FNAPlatform.GetStorageRoot;
GetDriveInfo = SDL2_FNAPlatform.GetDriveInfo;
ReadFileToPointer = SDL2_FNAPlatform.ReadToPointer;
FreeFilePointer = SDL2_FNAPlatform.FreeFilePointer;
ShowRuntimeError = SDL2_FNAPlatform.ShowRuntimeError;
GetMicrophones = SDL2_FNAPlatform.GetMicrophones;
GetMicrophoneSamples = SDL2_FNAPlatform.GetMicrophoneSamples;
GetMicrophoneQueuedBytes = SDL2_FNAPlatform.GetMicrophoneQueuedBytes;
StartMicrophone = SDL2_FNAPlatform.StartMicrophone;
StopMicrophone = SDL2_FNAPlatform.StopMicrophone;
GetTouchCapabilities = SDL2_FNAPlatform.GetTouchCapabilities;
UpdateTouchPanelState = SDL2_FNAPlatform.UpdateTouchPanelState;
GetNumTouchFingers = SDL2_FNAPlatform.GetNumTouchFingers;
SupportsOrientationChanges = SDL2_FNAPlatform.SupportsOrientationChanges;
NeedsPlatformMainLoop = SDL2_FNAPlatform.NeedsPlatformMainLoop;
RunPlatformMainLoop = SDL2_FNAPlatform.RunPlatformMainLoop;
}

FNALoggerEXT.Initialize();

AppDomain.CurrentDomain.ProcessExit += SDL2_FNAPlatform.ProgramExit;
TitleLocation = SDL2_FNAPlatform.ProgramInit(args);
if (useSDL3)
{
AppDomain.CurrentDomain.ProcessExit += SDL3_FNAPlatform.ProgramExit;
TitleLocation = SDL3_FNAPlatform.ProgramInit(args);
}
else
{
AppDomain.CurrentDomain.ProcessExit += SDL2_FNAPlatform.ProgramExit;
TitleLocation = SDL2_FNAPlatform.ProgramInit(args);
}

/* Do this AFTER ProgramInit so the platform library
* has a chance to load first!
Expand Down
4 changes: 2 additions & 2 deletions src/FNAPlatform/README
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ platforms as well as multiple backends for each platform all simultaneously.

That said, if you are adding a new platform, it is extremely likely that you
will NOT be touching anything in FNA itself! The expectation is that 100% of
your work will end up in SDL2 and FNA3D. You _might_ add some OSVersion checks
to SDL2_FNAPlatform.cs, but that should be the only change in the managed code.
your work will end up in SDL3 and FNA3D. You _might_ add some OSVersion checks
to SDL3_FNAPlatform.cs, but that should be the only change in the managed code.

If for some reason you REALLY need a new FNAPlatform, the new platforms will add
code exclusively to this folder. Some interfaces may need to change for new
Expand Down
18 changes: 18 additions & 0 deletions src/FNAPlatform/SDL3_FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,12 @@ out ButtonState x2
x2 = (ButtonState) ((uint) (flags & SDL.SDL_MouseButtonFlags.SDL_BUTTON_X2MASK) >> 4);
}

public static void WarpMouseInWindow(IntPtr window, int x, int y)
{
// Implicit conversion to float
SDL.SDL_WarpMouseInWindow(window, x, y);
}

public static void OnIsMouseVisibleChanged(bool visible)
{
if (visible)
Expand Down Expand Up @@ -2245,6 +2251,18 @@ public static bool IsTextInputActive()
return SDL.SDL_TextInputActive(IntPtr.Zero);
}

public static void StartTextInput()
{
// FIXME SDL3: Need a window...
SDL.SDL_StartTextInput(IntPtr.Zero);
}

public static void StopTextInput()
{
// FIXME SDL3: Need a window...
SDL.SDL_StopTextInput(IntPtr.Zero);
}

#endregion

#region SDL2<->XNA Key Conversion Methods
Expand Down

0 comments on commit 9f24e06

Please sign in to comment.