So loud added, changed how dependencies are organized.
This commit is contained in:
parent
02c1ceae14
commit
63a31c491d
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace SlatedGameToolkit.Framework.Exceptions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Any errors generated by an SDL feature that the engine requires are wrapped in the form of this type of exception.
|
|
||||||
/// </summary>
|
|
||||||
public class FrameworkSDLException : SDLException {
|
|
||||||
|
|
||||||
public FrameworkSDLException() : base() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public FrameworkSDLException(string message) : base(message) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public FrameworkSDLException(string message, Exception inner) : base(message, inner) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,17 +2,20 @@ using System;
|
|||||||
|
|
||||||
namespace SlatedGameToolkit.Framework.Exceptions
|
namespace SlatedGameToolkit.Framework.Exceptions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An exception that is thrown when an error occurrs on the game framework level that shouldn't have occurred and is definitely considered a bug.
|
||||||
|
/// </summary>
|
||||||
internal class InternalFrameworkException : FrameworkException {
|
internal class InternalFrameworkException : FrameworkException {
|
||||||
const string ADDITIONAL_MESSAGE = "\nThis exception is a framework bug!";
|
const string ADDITIONAL_MESSAGE = "**This exception is a framework bug!**";
|
||||||
public InternalFrameworkException() : base() {
|
public InternalFrameworkException() : base() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InternalFrameworkException(string message) : base(message + ADDITIONAL_MESSAGE) {
|
public InternalFrameworkException(string message) : base(message + ' ' + ADDITIONAL_MESSAGE) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InternalFrameworkException(string message, Exception inner) : base(message + ADDITIONAL_MESSAGE, inner) {
|
public InternalFrameworkException(string message, Exception inner) : base(message + ' ' + ADDITIONAL_MESSAGE, inner) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ namespace SlatedGameToolkit.Framework.Exceptions
|
|||||||
/// An SDLException is defined as an exception that is thrown whenever an error occurrs in any SDL functions.
|
/// An SDLException is defined as an exception that is thrown whenever an error occurrs in any SDL functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class SDLException : Exception {
|
public class SDLException : FrameworkException {
|
||||||
public string SDLMessage { get; }
|
public string SDLMessage { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SlatedGameToolkit.Framework.Exceptions
|
||||||
|
{
|
||||||
|
public class SoLoudException : FrameworkException
|
||||||
|
{
|
||||||
|
public int ErrorCode { get; private set; }
|
||||||
|
public SoLoudException(int errorCode) : base(GameEngine.SoLoudEngine.getErrorString(errorCode) + " SoLoud error has occurred.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoLoudException(int errorCode, string message) : base(GameEngine.SoLoudEngine.getErrorString(errorCode) + " SoLoud error has occurred: " + message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoLoudException(int errorCode, string message, Exception inner) : base(GameEngine.SoLoudEngine.getErrorString(errorCode) + " SoLoud error has occurred: " + message, inner)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,18 +3,19 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using SDL2;
|
using SDL2;
|
||||||
using SlatedGameToolkit.Framework.Exceptions;
|
using SlatedGameToolkit.Framework.Exceptions;
|
||||||
|
using SlatedGameToolkit.Framework.Graphics.OpenGL;
|
||||||
using SlatedGameToolkit.Framework.Graphics.Window;
|
using SlatedGameToolkit.Framework.Graphics.Window;
|
||||||
using SlatedGameToolkit.Framework.Input.Devices;
|
using SlatedGameToolkit.Framework.Input.Devices;
|
||||||
using SlatedGameToolkit.Framework.Logging;
|
using SlatedGameToolkit.Framework.Logging;
|
||||||
using SlatedGameToolkit.Framework.StateSystem;
|
using SlatedGameToolkit.Framework.StateSystem;
|
||||||
using SlatedGameToolkit.Framework.StateSystem.States;
|
using SlatedGameToolkit.Framework.StateSystem.States;
|
||||||
|
using SoLoud;
|
||||||
|
|
||||||
namespace SlatedGameToolkit.Framework {
|
namespace SlatedGameToolkit.Framework {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main engine that will host the game loop.
|
/// The main engine that will host the game loop.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class GameEngine {
|
public static class GameEngine {
|
||||||
private const int GL_MAJOR_VER = 3, GL_MINOR_VER = 3;
|
|
||||||
public static bool Debugging { get; set; }
|
public static bool Debugging { get; set; }
|
||||||
private static readonly object ignitionLock = new object();
|
private static readonly object ignitionLock = new object();
|
||||||
private static readonly object deltaUpdateLock = new object();
|
private static readonly object deltaUpdateLock = new object();
|
||||||
@ -73,7 +74,9 @@ namespace SlatedGameToolkit.Framework {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Loop(Object o) {
|
public static Soloud SoLoudEngine { get; private set; }
|
||||||
|
|
||||||
|
private static void Run(Object o) {
|
||||||
if (!(o is IState)) throw new InternalFrameworkException(String.Format("Expected initial state object for asynchronous loop. Got {0}", o));
|
if (!(o is IState)) throw new InternalFrameworkException(String.Format("Expected initial state object for asynchronous loop. Got {0}", o));
|
||||||
StateManager manager = new StateManager();
|
StateManager manager = new StateManager();
|
||||||
IState initialState = (IState) o;
|
IState initialState = (IState) o;
|
||||||
@ -180,6 +183,7 @@ namespace SlatedGameToolkit.Framework {
|
|||||||
stopped = true;
|
stopped = true;
|
||||||
manager.Dispose();
|
manager.Dispose();
|
||||||
SDL.SDL_Quit();
|
SDL.SDL_Quit();
|
||||||
|
SoLoudEngine.deinit();
|
||||||
WindowContextsManager.DisposeAllWindowContexts();
|
WindowContextsManager.DisposeAllWindowContexts();
|
||||||
Logger.Log("Game engine has gracefully stopped.");
|
Logger.Log("Game engine has gracefully stopped.");
|
||||||
Logger.FlushListeners();
|
Logger.FlushListeners();
|
||||||
@ -223,19 +227,37 @@ namespace SlatedGameToolkit.Framework {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit = false;
|
exit = false;
|
||||||
|
Logger.Log("Initializing SDL video subsystem.");
|
||||||
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0) {
|
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0) {
|
||||||
throw new FrameworkSDLException();
|
throw new SDLException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.Log("Initializing SDL audio subsystem.");
|
||||||
if (SDL.SDL_Init(SDL.SDL_INIT_AUDIO) != 0) {
|
if (SDL.SDL_Init(SDL.SDL_INIT_AUDIO) != 0) {
|
||||||
throw new FrameworkSDLException();
|
throw new SDLException();
|
||||||
|
}
|
||||||
|
Logger.Log("Initializing SoLoud Engine.");
|
||||||
|
SoLoudEngine = new Soloud();
|
||||||
|
int error = SoLoudEngine.init(aBackend: Soloud.SDL2);
|
||||||
|
if (error != 0) {
|
||||||
|
throw new SoLoudException(error);
|
||||||
|
}
|
||||||
|
uint soLoudVer = SoLoudEngine.getVersion();
|
||||||
|
if (soLoudVer != Soloud.SOLOUD_VER) {
|
||||||
|
if (soLoudVer < Soloud.SOLOUD_VER) {
|
||||||
|
throw new FrameworkUsageException(string.Format("SoLoud version is out-dated! Detected version {0}. Minimum version requirement is {1}", soLoudVer, Soloud.SOLOUD_VER));
|
||||||
|
} else {
|
||||||
|
Logger.Log(string.Format("SoLoud version detected is {0} which is newer than version used to build framework (ver. {1}).", soLoudVer, Soloud.SOLOUD_VER), LogLevel.WARNING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, GL_MAJOR_VER) < 0 ||
|
if (SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, GLContext.GL_MAJOR_VER) < 0 ||
|
||||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, GL_MINOR_VER) < 0 ||
|
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, GLContext.GL_MINOR_VER) < 0 ||
|
||||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE) < 0)
|
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE) < 0)
|
||||||
throw new FrameworkSDLException(string.Format("Unable to load correct OpenGL version {0}.{1}.0 Core.", GL_MINOR_VER, GL_MAJOR_VER));
|
throw new SDLException(string.Format("Unable to retrieve correct OpenGL version {0}.{1}.0 Core.", GLContext.GL_MINOR_VER, GLContext.GL_MAJOR_VER));
|
||||||
|
Logger.Log(string.Format("OpenGL version set to {0}.{1}.0 Core.", GLContext.GL_MAJOR_VER, GLContext.GL_MINOR_VER));
|
||||||
|
|
||||||
thread = new Thread(Loop);
|
thread = new Thread(Run);
|
||||||
thread.Name = "SGTK-Engine";
|
thread.Name = "SGTK-Engine";
|
||||||
thread.Priority = ThreadPriority.AboveNormal;
|
thread.Priority = ThreadPriority.AboveNormal;
|
||||||
thread.Start(initialState);
|
thread.Start(initialState);
|
||||||
|
@ -13,6 +13,7 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL
|
|||||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||||
public class GLContext : IDisposable
|
public class GLContext : IDisposable
|
||||||
{
|
{
|
||||||
|
public const int GL_MAJOR_VER = 3, GL_MINOR_VER = 3;
|
||||||
#region OpenGLFunctions
|
#region OpenGLFunctions
|
||||||
|
|
||||||
public IntPtr Handle { get; private set; }
|
public IntPtr Handle { get; private set; }
|
||||||
@ -3173,7 +3174,7 @@ namespace SlatedGameToolkit.Framework.Graphics.OpenGL
|
|||||||
GetProcAddressHandler loader = SDL.SDL_GL_GetProcAddress;
|
GetProcAddressHandler loader = SDL.SDL_GL_GetProcAddress;
|
||||||
Handle = SDL.SDL_GL_CreateContext(windowHandle);
|
Handle = SDL.SDL_GL_CreateContext(windowHandle);
|
||||||
if (Handle == null) {
|
if (Handle == null) {
|
||||||
throw new FrameworkSDLException();
|
throw new SDLException();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region OpenGLDelegateAssignment
|
#region OpenGLDelegateAssignment
|
||||||
|
@ -248,7 +248,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
|
|||||||
internal uint WindowID {
|
internal uint WindowID {
|
||||||
get {
|
get {
|
||||||
uint id = SDL.SDL_GetWindowID(windowHandle);
|
uint id = SDL.SDL_GetWindowID(windowHandle);
|
||||||
if (id == 0) throw new FrameworkSDLException();
|
if (id == 0) throw new SDLException();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,7 +260,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
|
|||||||
Logger.Log(String.Format("Starting openGL window with title \"{0}\"", title));
|
Logger.Log(String.Format("Starting openGL window with title \"{0}\"", title));
|
||||||
windowHandle = SDL.SDL_CreateWindow(title, x < 0 ? SDL.SDL_WINDOWPOS_CENTERED : x, y < 0 ? SDL.SDL_WINDOWPOS_CENTERED : y, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS | options);
|
windowHandle = SDL.SDL_CreateWindow(title, x < 0 ? SDL.SDL_WINDOWPOS_CENTERED : x, y < 0 ? SDL.SDL_WINDOWPOS_CENTERED : y, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS | options);
|
||||||
if (windowHandle == null) {
|
if (windowHandle == null) {
|
||||||
throw new FrameworkSDLException();
|
throw new SDLException();
|
||||||
}
|
}
|
||||||
this.Context = new GLContext(windowHandle);
|
this.Context = new GLContext(windowHandle);
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Window
|
|||||||
/// <returns>An integer representing the display this window resides within.</returns>
|
/// <returns>An integer representing the display this window resides within.</returns>
|
||||||
public int GetDisplayIndex() {
|
public int GetDisplayIndex() {
|
||||||
int index = SDL.SDL_GetWindowDisplayIndex(windowHandle);
|
int index = SDL.SDL_GetWindowDisplayIndex(windowHandle);
|
||||||
if (index < 0) throw new FrameworkSDLException();
|
if (index < 0) throw new SDLException();
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,5 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Resources/**"/>
|
<EmbeddedResource Include="Resources/**"/>
|
||||||
<Content Include="deps/**"/>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user