Browse Source

Refactored the interop classes.

* Moved DotSDL.Sdl to DotSDL.Interop.Core to allow for external
      library (SDL_mixer, SDL_image, etc) support down the road and
      to make their purpose more clear.
    * Changed DllName constant to CoreLib to fit the namespace
      change.
improved_timing
Ian Burgmyer 6 years ago
parent
commit
037a6ccad0
  1. 2
      DotSDL/Audio/FormatConverter.cs
  2. 4
      DotSDL/Audio/Playback.cs
  3. 2
      DotSDL/Events/EventConversion.cs
  4. 2
      DotSDL/Events/EventHandler.cs
  5. 2
      DotSDL/Graphics/SdlWindow.cs
  6. 10
      DotSDL/Interop/Core/Audio.cs
  7. 10
      DotSDL/Interop/Core/Events.cs
  8. 12
      DotSDL/Interop/Core/Init.cs
  9. 2
      DotSDL/Interop/Core/Keyboard.cs
  10. 2
      DotSDL/Interop/Core/Pixels.cs
  11. 8
      DotSDL/Interop/Core/Power.cs
  12. 2
      DotSDL/Interop/Core/Rect.cs
  13. 18
      DotSDL/Interop/Core/Render.cs
  14. 6
      DotSDL/Interop/Core/Timer.cs
  15. 10
      DotSDL/Interop/Core/Video.cs
  16. 4
      DotSDL/Interop/Meta.cs
  17. 2
      DotSDL/Power/PowerState.cs
  18. 4
      DotSDL/SdlInit.cs

2
DotSDL/Audio/FormatConverter.cs

@ -1,5 +1,5 @@
using System;
using SdlAudio = DotSDL.Sdl.Audio;
using SdlAudio = DotSDL.Interop.Core.Audio;
namespace DotSDL.Audio {
/// <summary>

4
DotSDL/Audio/Playback.cs

@ -1,7 +1,7 @@
using DotSDL.Sdl;
using SdlAudio = DotSDL.Sdl.Audio;
using SdlAudio = DotSDL.Interop.Core.Audio;
using System;
using System.Runtime.InteropServices;
using DotSDL.Interop.Core;
namespace DotSDL.Audio {
/// <summary>

2
DotSDL/Events/EventConversion.cs

@ -1,4 +1,4 @@
using SdlEvents = DotSDL.Sdl.Events;
using SdlEvents = DotSDL.Interop.Core.Events;
namespace DotSDL.Events {
/// <summary>

2
DotSDL/Events/EventHandler.cs

@ -1,6 +1,6 @@
using System;
using System.Runtime.InteropServices;
using SdlEvents = DotSDL.Sdl.Events;
using SdlEvents = DotSDL.Interop.Core.Events;
namespace DotSDL.Events {
/// <summary>

2
DotSDL/Graphics/SdlWindow.cs

@ -1,7 +1,7 @@
using DotSDL.Events;
using DotSDL.Input;
using DotSDL.Sdl;
using System;
using DotSDL.Interop.Core;
namespace DotSDL.Graphics {
/// <summary>

10
DotSDL/Sdl/Audio.cs → DotSDL/Interop/Core/Audio.cs

@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_audio.h.
/// </summary>
@ -165,7 +165,7 @@ namespace DotSDL.Sdl {
/// Shuts down audio processing and closes the audio device.
/// </summary>
/// <param name="dev">An audio device previously opened by <see cref="OpenAudioDevice"/>.</param>
[DllImport(Meta.DllName, EntryPoint = "SDL_CloseAudioDevice", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_CloseAudioDevice", CallingConvention = CallingConvention.Cdecl)]
internal static extern void CloseAudioDevice(uint dev);
/// <summary>
@ -186,7 +186,7 @@ namespace DotSDL.Sdl {
/// <param name="allowedChanges"></param>
/// <returns>A non-zero value on success or zero on failure. This will never
/// return 1, since SDL reserves that ID for the SDL_OpenAudio() function.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_OpenAudioDevice", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_OpenAudioDevice", CallingConvention = CallingConvention.Cdecl)]
internal static extern uint OpenAudioDevice(IntPtr device, int isCapture, ref AudioSpec desired, out AudioSpec obtained, AllowedChanges allowedChanges);
/// <summary>
@ -207,7 +207,7 @@ namespace DotSDL.Sdl {
/// <param name="allowedChanges"></param>
/// <returns>A non-zero value on success or zero on failure. This will never
/// return 1, since SDL reserves that ID for the SDL_OpenAudio() function.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_OpenAudioDevice", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_OpenAudioDevice", CallingConvention = CallingConvention.Cdecl)]
internal static extern uint OpenAudioDevice(string device, int isCapture, ref AudioSpec desired, out AudioSpec obtained, AllowedChanges allowedChanges);
/// <summary>
@ -215,7 +215,7 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="dev">The audio device to change.</param>
/// <param name="pauseOn">The <see cref="AudioState"/> to switch to.</param>
[DllImport(Meta.DllName, EntryPoint = "SDL_PauseAudioDevice", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_PauseAudioDevice", CallingConvention = CallingConvention.Cdecl)]
internal static extern void PauseAudioDevice(uint dev, AudioState pauseOn);
}
}

10
DotSDL/Sdl/Events.cs → DotSDL/Interop/Core/Events.cs

@ -1,14 +1,14 @@
using ControllerButton = DotSDL.Input.Controller.Button;
using System;
using System.Runtime.InteropServices;
using DotSDL.Events;
using DotSDL.Input;
using DotSDL.Input.Controller;
using DotSDL.Input.Joystick;
using DotSDL.Input.Mouse;
using ControllerButton = DotSDL.Input.Controller.Button;
using MouseButton = DotSDL.Input.Mouse.Button;
using System;
using System.Runtime.InteropServices;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_events.h.
/// </summary>
@ -485,7 +485,7 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="sdlEvent">An object to store event data into. If this is not NULL, the event is removed from the queue and stored into the object.</param>
/// <returns>1 if there are any pending events, or 0 if there are none available.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_PollEvent", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_PollEvent", CallingConvention = CallingConvention.Cdecl)]
internal static extern int PollEvent(ref SdlEvent sdlEvent);
}
}

12
DotSDL/Sdl/Init.cs → DotSDL/Interop/Core/Init.cs

@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL.h.
/// </summary>
@ -44,7 +44,7 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="flags">Flags indicating which subsystem or subsystems to initialize.</param>
/// <returns>0 on success or a negative error code on failure.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_Init", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_Init", CallingConvention = CallingConvention.Cdecl)]
internal static extern int Initialize(SubsystemFlags flags);
/// <summary>
@ -58,7 +58,7 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="flags">Flags indicating which subsystem or subsystems to initialize.</param>
/// <returns>0 on success or a negative error code on failure.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_InitSubSystem", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_InitSubSystem", CallingConvention = CallingConvention.Cdecl)]
internal static extern int InitSubSystem(SubsystemFlags flags);
/// <summary>
@ -66,7 +66,7 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="flags">Flags indicating which subsystem or subsystems to quit.</param>
/// <returns>0 on success or a negative error code on failure.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_QuitSubSystem", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_QuitSubSystem", CallingConvention = CallingConvention.Cdecl)]
internal static extern int QuitSubSystem(SubsystemFlags flags);
/// <summary>
@ -77,14 +77,14 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="flags">Flags indicating which subsystem or subsystems to query.</param>
/// <returns>A set of all initialized subsystems.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_WasInit", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_WasInit", CallingConvention = CallingConvention.Cdecl)]
internal static extern SubsystemFlags WasInit(SubsystemFlags flags);
/// <summary>
/// This function cleans up all initialized subsystems. You should call it upon all
/// exit conditions.
/// </summary>
[DllImport(Meta.DllName, EntryPoint = "SDL_Quit", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_Quit", CallingConvention = CallingConvention.Cdecl)]
internal static extern void Quit();
}
}

2
DotSDL/Sdl/Keyboard.cs → DotSDL/Interop/Core/Keyboard.cs

@ -1,6 +1,6 @@
using DotSDL.Input.Keyboard;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_keyboard.h.
/// </summary>

2
DotSDL/Sdl/Pixels.cs → DotSDL/Interop/Core/Pixels.cs

@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_pixels.h.
/// </summary>

8
DotSDL/Sdl/Power.cs → DotSDL/Interop/Core/Power.cs

@ -1,7 +1,7 @@
using DotSDL.Power;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using DotSDL.Power;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_power.h.
/// </summary>
@ -16,7 +16,7 @@ namespace DotSDL.Sdl {
/// You can pass a NULL here if you don't care. Will return -1 if we
/// can't determine a value, or we're not running on a battery.</param>
/// <returns>The state of the battery (if any).</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_GetPowerInfo", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_GetPowerInfo", CallingConvention = CallingConvention.Cdecl)]
internal static extern BatteryStatus GetPowerInfo(out int secs, out int pct);
}
}

2
DotSDL/Sdl/Rect.cs → DotSDL/Interop/Core/Rect.cs

@ -1,6 +1,6 @@
using System.Runtime.InteropServices;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_rect.h.
/// </summary>

18
DotSDL/Sdl/Render.cs → DotSDL/Interop/Core/Render.cs

@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_render.h.
/// </summary>
@ -46,7 +46,7 @@ namespace DotSDL.Sdl {
/// to initialize the first one supporting the requested flags.</param>
/// <param name="flags">The requested flags for the renderer.</param>
/// <returns>A valid rendering context or NULL if there was an error.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_CreateRenderer", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_CreateRenderer", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr CreateRenderer(IntPtr window, int index, RendererFlags flags);
/// <summary>
@ -59,7 +59,7 @@ namespace DotSDL.Sdl {
/// <param name="h">The height of the texture in pixels.</param>
/// <returns>The created texture is returned, or NULL if no rendering context was
/// active, the foramt was unsupported, or the width or height were out of range.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_CreateTexture", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_CreateTexture", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr CreateTexture(IntPtr renderer, uint format, TextureAccess access, int w, int h);
/// <summary>
@ -69,7 +69,7 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="renderer">The renderer to clear.</param>
/// <returns>0 on success, -1 on error.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_RenderClear", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_RenderClear", CallingConvention = CallingConvention.Cdecl)]
internal static extern int RenderClear(IntPtr renderer);
/// <summary>
@ -80,16 +80,16 @@ namespace DotSDL.Sdl {
/// <param name="srcRect">The source rectangle, or NULL for the entire texture.</param>
/// <param name="dstRect">The destination rectangle, or NULL For the entire rendering target.</param>
/// <returns>0 on success, or -1 on error.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_RenderCopy", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_RenderCopy", CallingConvention = CallingConvention.Cdecl)]
internal static extern int RenderCopy(IntPtr renderer, IntPtr texture, Rect.SdlRect srcRect, Rect.SdlRect dstRect);
[DllImport(Meta.DllName, EntryPoint = "SDL_RenderCopy", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_RenderCopy", CallingConvention = CallingConvention.Cdecl)]
internal static extern int RenderCopy(IntPtr renderer, IntPtr texture, IntPtr srcRect, IntPtr dstRect);
/// <summary>
/// Update the screen with the rendering performed.
/// </summary>
/// <param name="renderer">The renderer to update.</param>
[DllImport(Meta.DllName, EntryPoint = "SDL_RenderPresent", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_RenderPresent", CallingConvention = CallingConvention.Cdecl)]
internal static extern void RenderPresent(IntPtr renderer);
/// <summary>
@ -100,7 +100,7 @@ namespace DotSDL.Sdl {
/// <param name="pixels">The raw pixel data.</param>
/// <param name="pitch">The number of bytes in a row of pixel data, including padding between lines.</param>
/// <returns>0 on success, or -1 if the texture is not valid.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_UpdateTexture", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_UpdateTexture", CallingConvention = CallingConvention.Cdecl)]
internal static extern int UpdateTexture(IntPtr texture, IntPtr rect, IntPtr pixels, int pitch);
/// <summary>
@ -111,7 +111,7 @@ namespace DotSDL.Sdl {
/// <param name="pixels">The raw pixel data.</param>
/// <param name="pitch">The number of bytes in a row of pixel data, including padding between lines.</param>
/// <returns>0 on success, or -1 if the texture is not valid.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_UpdateTexture", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_UpdateTexture", CallingConvention = CallingConvention.Cdecl)]
internal static extern int UpdateTexture(IntPtr texture, Rect.SdlRect rect, IntPtr pixels, int pitch);
}
}

6
DotSDL/Sdl/Timer.cs → DotSDL/Interop/Core/Timer.cs

@ -1,6 +1,6 @@
using System.Runtime.InteropServices;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_timer.h.
/// </summary>
@ -9,14 +9,14 @@ namespace DotSDL.Sdl {
/// Wait a specified number of milliseconds before returning.
/// </summary>
/// <param name="ms">The number of milliseconds to wait.</param>
[DllImport(Meta.DllName, EntryPoint = "SDL_Delay", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_Delay", CallingConvention = CallingConvention.Cdecl)]
internal static extern void Delay(uint ms);
/// <summary>
/// Retrieves the number of milliseconds since the SDL library was initialized.
/// </summary>
/// <returns>The number of milliseconds since the SDL library was initialized.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_GetTicks", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_GetTicks", CallingConvention = CallingConvention.Cdecl)]
internal static extern uint GetTicks();
}
}

10
DotSDL/Sdl/Video.cs → DotSDL/Interop/Core/Video.cs

@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;
namespace DotSDL.Sdl {
namespace DotSDL.Interop.Core {
/// <summary>
/// Contains the necessary constants and function imports from SDL_video.h.
/// </summary>
@ -85,14 +85,14 @@ namespace DotSDL.Sdl {
/// <param name="h">The height of the window, in screen coordinates.</param>
/// <param name="flags">One or more <see cref="WindowFlags"/> OR'd together.</param>
/// <returns>The window that was created, or NULL on failure.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_CreateWindow", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_CreateWindow", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr CreateWindow(string title, int x, int y, int w, int h, WindowFlags flags);
/// <summary>
/// Destroys an SDL window.
/// </summary>
/// <param name="window">The window to destroy.</param>
[DllImport(Meta.DllName, EntryPoint = "SDL_DestroyWindow", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_DestroyWindow", CallingConvention = CallingConvention.Cdecl)]
internal static extern void DestroyWindow(IntPtr window);
/// <summary>
@ -100,14 +100,14 @@ namespace DotSDL.Sdl {
/// </summary>
/// <param name="window">The window to query.</param>
/// <returns>The ID of the window.</returns>
[DllImport(Meta.DllName, EntryPoint = "SDL_GetWindowID", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_GetWindowID", CallingConvention = CallingConvention.Cdecl)]
internal static extern uint GetWindowId(IntPtr window);
/// <summary>
/// Shows an SDL window.
/// </summary>
/// <param name="window">The window to show.</param>
[DllImport(Meta.DllName, EntryPoint = "SDL_ShowWindow", CallingConvention = CallingConvention.Cdecl)]
[DllImport(Meta.CoreLib, EntryPoint = "SDL_ShowWindow", CallingConvention = CallingConvention.Cdecl)]
internal static extern void ShowWindow(IntPtr window);
}
}

4
DotSDL/Sdl/Meta.cs → DotSDL/Interop/Meta.cs

@ -1,4 +1,4 @@
namespace DotSDL.Sdl {
namespace DotSDL.Interop {
/// <summary>
/// Contains .NET constants to assist with making calls to the SDL library.
/// </summary>
@ -6,6 +6,6 @@
/// <summary>
/// Contains the name of the SDL library.
/// </summary>
internal const string DllName = "SDL2";
internal const string CoreLib = "SDL2";
}
}

2
DotSDL/Power/PowerState.cs

@ -13,7 +13,7 @@ namespace DotSDL.Power {
/// </summary>
public static PowerStatus CurrentPowerState {
get {
var state = Sdl.Power.GetPowerInfo(out var secs, out var pct);
var state = Interop.Core.Power.GetPowerInfo(out var secs, out var pct);
return new PowerStatus {
BatteryStatus = state,
BatteryPercent = pct,

4
DotSDL/SdlInit.cs

@ -1,6 +1,6 @@
using DotSDL.Sdl;
using System;
using System;
using System.Collections.Generic;
using DotSDL.Interop.Core;
namespace DotSDL {
/// <summary>

Loading…
Cancel
Save