Skip to content

Instantly share code, notes, and snippets.

@guixxx
Last active June 7, 2020 02:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guixxx/fb30995ba299fc24d67a9cd06b5e9046 to your computer and use it in GitHub Desktop.
Save guixxx/fb30995ba299fc24d67a9cd06b5e9046 to your computer and use it in GitHub Desktop.
Patches latest FNA (tested on version 20.04), so it can build and run with the native Linux version of Terraria
diff --git a/Makefile b/Makefile
index 1dcecbc..e916e2e 100644
--- a/Makefile
+++ b/Makefile
@@ -121,8 +121,6 @@ SRC = \
src/FNAPlatform/FNAPlatform.cs \
src/FNAPlatform/FNAWindow.cs \
src/FNAPlatform/IGLDevice.cs \
- src/FNAPlatform/MetalDevice.cs \
- src/FNAPlatform/MetalDevice_MTL.cs \
src/FNAPlatform/ModernGLDevice.cs \
src/FNAPlatform/ModernGLDevice_GL.cs \
src/FNAPlatform/OpenGLDevice.cs \
@@ -282,14 +280,6 @@ SRC = \
src/Input/Mouse.cs \
src/Input/MouseState.cs \
src/Input/TextInputEXT.cs \
- src/Input/Touch/GestureDetector.cs \
- src/Input/Touch/GestureSample.cs \
- src/Input/Touch/GestureType.cs \
- src/Input/Touch/TouchCollection.cs \
- src/Input/Touch/TouchLocation.cs \
- src/Input/Touch/TouchLocationState.cs \
- src/Input/Touch/TouchPanel.cs \
- src/Input/Touch/TouchPanelCapabilities.cs \
src/IUpdateable.cs \
src/LaunchParameters.cs \
src/MathHelper.cs \
diff --git a/src/FNAPlatform/FNAPlatform.cs b/src/FNAPlatform/FNAPlatform.cs
index b8b7dd1..18f3439 100644
--- a/src/FNAPlatform/FNAPlatform.cs
+++ b/src/FNAPlatform/FNAPlatform.cs
@@ -14,7 +14,6 @@ using System.IO;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
-using Microsoft.Xna.Framework.Input.Touch;
#endregion
namespace Microsoft.Xna.Framework
@@ -115,9 +114,6 @@ namespace Microsoft.Xna.Framework
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;
// Don't overwrite application log hooks!
@@ -331,15 +327,6 @@ namespace Microsoft.Xna.Framework
public delegate void StopMicrophoneFunc(uint handle);
public static readonly StopMicrophoneFunc StopMicrophone;
- public delegate TouchPanelCapabilities GetTouchCapabilitiesFunc();
- public static readonly GetTouchCapabilitiesFunc GetTouchCapabilities;
-
- public delegate void UpdateTouchPanelStateFunc();
- public static readonly UpdateTouchPanelStateFunc UpdateTouchPanelState;
-
- public delegate int GetNumTouchFingersFunc();
- public static readonly GetNumTouchFingersFunc GetNumTouchFingers;
-
public delegate bool SupportsOrientationChangesFunc();
public static readonly SupportsOrientationChangesFunc SupportsOrientationChanges;
diff --git a/src/FNAPlatform/SDL2_FNAPlatform.cs b/src/FNAPlatform/SDL2_FNAPlatform.cs
index fedb850..e7040ff 100644
--- a/src/FNAPlatform/SDL2_FNAPlatform.cs
+++ b/src/FNAPlatform/SDL2_FNAPlatform.cs
@@ -19,7 +19,6 @@ using SDL2;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
-using Microsoft.Xna.Framework.Input.Touch;
#endregion
namespace Microsoft.Xna.Framework
@@ -276,23 +275,6 @@ namespace Microsoft.Xna.Framework
);
#endif
- if (OSVersion.Equals("Mac OS X"))
- {
- // Let's find out if the OS supports Metal...
- try
- {
- if (MetalDevice.MTLCreateSystemDefaultDevice() != IntPtr.Zero)
- {
- // We're good to go!
- return true;
- }
- }
- catch
- {
- // The OS is too old for Metal!
- return false;
- }
- }
else if (OSVersion.Equals("iOS") || OSVersion.Equals("tvOS"))
{
/* We only support iOS/tvOS 11.0+ so
@@ -534,10 +516,6 @@ namespace Microsoft.Xna.Framework
{
SDL.SDL_Vulkan_GetDrawableSize(window, out drawX, out drawY);
}
- else if (metal)
- {
- MetalDevice.GetDrawableSizeFromView(tempContext, out drawX, out drawY);
- }
else if (opengl)
{
SDL.SDL_GL_GetDrawableSize(window, out drawX, out drawY);
@@ -597,11 +575,6 @@ namespace Microsoft.Xna.Framework
Mouse.WindowHandle = IntPtr.Zero;
}
- if (TouchPanel.WindowHandle == window.Handle)
- {
- TouchPanel.WindowHandle = IntPtr.Zero;
- }
-
SDL.SDL_DestroyWindow(window.Handle);
}
@@ -970,9 +943,6 @@ namespace Microsoft.Xna.Framework
osxUseSpaces = false;
}
- // Perform initial check for a touch device
- TouchPanel.TouchDeviceExists = GetTouchCapabilities().IsConnected;
-
// Do we want to read keycodes or scancodes?
if (UseScancodes)
{
@@ -1067,44 +1037,6 @@ namespace Microsoft.Xna.Framework
Mouse.INTERNAL_MouseWheel += evt.wheel.y * 120;
}
- // Touch Input
- else if (evt.type == SDL.SDL_EventType.SDL_FINGERDOWN)
- {
- // Windows only notices a touch screen once it's touched
- TouchPanel.TouchDeviceExists = true;
-
- TouchPanel.INTERNAL_onTouchEvent(
- (int) evt.tfinger.fingerId,
- TouchLocationState.Pressed,
- evt.tfinger.x,
- evt.tfinger.y,
- 0,
- 0
- );
- }
- else if (evt.type == SDL.SDL_EventType.SDL_FINGERMOTION)
- {
- TouchPanel.INTERNAL_onTouchEvent(
- (int) evt.tfinger.fingerId,
- TouchLocationState.Moved,
- evt.tfinger.x,
- evt.tfinger.y,
- evt.tfinger.dx,
- evt.tfinger.dy
- );
- }
- else if (evt.type == SDL.SDL_EventType.SDL_FINGERUP)
- {
- TouchPanel.INTERNAL_onTouchEvent(
- (int) evt.tfinger.fingerId,
- TouchLocationState.Released,
- evt.tfinger.x,
- evt.tfinger.y,
- 0,
- 0
- );
- }
-
// Various Window Events...
else if (evt.type == SDL.SDL_EventType.SDL_WINDOWEVENT)
{
@@ -1329,8 +1261,6 @@ namespace Microsoft.Xna.Framework
switch (ActualGLDevice)
{
case VULKAN: break; // Maybe some day!
- case METAL:
- return new MetalDevice(presentationParameters);
case MODERNGL:
// FIXME: This is still experimental! -flibit
return new ModernGLDevice(presentationParameters);
@@ -2773,59 +2703,6 @@ namespace Microsoft.Xna.Framework
#endregion
- #region Touch Methods
-
- public static TouchPanelCapabilities GetTouchCapabilities()
- {
- /* Take these reported capabilities with a grain of salt.
- * On Windows, touch devices won't be detected until they
- * are interacted with. Also, MaximumTouchCount is completely
- * bogus. For any touch device, XNA always reports 4.
- *
- * -caleb
- */
- bool touchDeviceExists = SDL.SDL_GetNumTouchDevices() > 0;
- return new TouchPanelCapabilities(
- touchDeviceExists,
- touchDeviceExists ? 4 : 0
- );
- }
-
- public static unsafe void UpdateTouchPanelState()
- {
- // Poll the touch device for all active fingers
- long touchDevice = SDL.SDL_GetTouchDevice(0);
- for (int i = 0; i < TouchPanel.MAX_TOUCHES; i += 1)
- {
- SDL.SDL_Finger* finger = (SDL.SDL_Finger*) SDL.SDL_GetTouchFinger(touchDevice, i);
- if (finger == null)
- {
- // No finger found at this index
- TouchPanel.SetFinger(i, TouchPanel.NO_FINGER, Vector2.Zero);
- continue;
- }
-
- // Send the finger data to the TouchPanel
- TouchPanel.SetFinger(
- i,
- (int) finger->id,
- new Vector2(
- (float) Math.Round(finger->x * TouchPanel.DisplayWidth),
- (float) Math.Round(finger->y * TouchPanel.DisplayHeight)
- )
- );
- }
- }
-
- public static int GetNumTouchFingers()
- {
- return SDL.SDL_GetNumTouchFingers(
- SDL.SDL_GetTouchDevice(0)
- );
- }
-
- #endregion
-
#region SDL2<->XNA Key Conversion Methods
/* From: http://blogs.msdn.com/b/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx
diff --git a/src/FrameworkDispatcher.cs b/src/FrameworkDispatcher.cs
index f7f47f1..e77d2b5 100644
--- a/src/FrameworkDispatcher.cs
+++ b/src/FrameworkDispatcher.cs
@@ -11,7 +11,6 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework.Audio;
-using Microsoft.Xna.Framework.Input.Touch;
using MediaPlayer = Microsoft.Xna.Framework.Media.MediaPlayer;
#endregion
@@ -62,11 +61,6 @@ namespace Microsoft.Xna.Framework
MediaPlayer.OnMediaStateChanged();
MediaStateChanged = false;
}
-
- if (TouchPanel.TouchDeviceExists)
- {
- TouchPanel.Update();
- }
}
#endregion
diff --git a/src/Game.cs b/src/Game.cs
index 9973e92..51e4eca 100644
--- a/src/Game.cs
+++ b/src/Game.cs
@@ -16,7 +16,6 @@ using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
-using Microsoft.Xna.Framework.Input.Touch;
#endregion
namespace Microsoft.Xna.Framework
@@ -254,7 +253,6 @@ namespace Microsoft.Xna.Framework
Window = FNAPlatform.CreateWindow();
Mouse.WindowHandle = Window.Handle;
- TouchPanel.WindowHandle = Window.Handle;
FrameworkDispatcher.Update();
diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs
index 6f1d3ea..3e053e1 100644
--- a/src/Graphics/GraphicsDevice.cs
+++ b/src/Graphics/GraphicsDevice.cs
@@ -395,10 +395,6 @@ namespace Microsoft.Xna.Framework.Graphics
Input.Mouse.INTERNAL_BackBufferWidth = PresentationParameters.BackBufferWidth;
Input.Mouse.INTERNAL_BackBufferHeight = PresentationParameters.BackBufferHeight;
- // The Touch Panel needs this too, for the same reason.
- Input.Touch.TouchPanel.DisplayWidth = PresentationParameters.BackBufferWidth;
- Input.Touch.TouchPanel.DisplayHeight = PresentationParameters.BackBufferHeight;
-
// Force set the default render states.
BlendState = BlendState.Opaque;
DepthStencilState = DepthStencilState.Default;
@@ -664,10 +660,6 @@ namespace Microsoft.Xna.Framework.Graphics
Input.Mouse.INTERNAL_BackBufferWidth = PresentationParameters.BackBufferWidth;
Input.Mouse.INTERNAL_BackBufferHeight = PresentationParameters.BackBufferHeight;
- // The Touch Panel needs this too, for the same reason.
- Input.Touch.TouchPanel.DisplayWidth = PresentationParameters.BackBufferWidth;
- Input.Touch.TouchPanel.DisplayHeight = PresentationParameters.BackBufferHeight;
-
#if WIIU_GAMEPAD
wiiuPixelData = new byte[
PresentationParameters.BackBufferWidth *
@guixxx
Copy link
Author

guixxx commented May 1, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment