add GraphicsDevice object to the application object. minor adjustments to make it easier to clean up platform-independant "system" objects
This commit is contained in:
parent
044bf67f46
commit
82236acfa7
|
@ -22,8 +22,8 @@ namespace Blarg.GameFramework
|
|||
SDLKeyboard _keyboard;
|
||||
SDLMouse _mouse;
|
||||
SDLFileSystem _filesystem;
|
||||
SDLGL20 _gl;
|
||||
SDLWindow _windowInfo;
|
||||
SDLGL20 _gl;
|
||||
PlatformOS _os;
|
||||
|
||||
bool _isWindowActive;
|
||||
|
@ -146,6 +146,7 @@ namespace Blarg.GameFramework
|
|||
|
||||
Platform.Set(this);
|
||||
|
||||
OnInit();
|
||||
OnNewContext();
|
||||
OnResize(ScreenOrientation.Rotation0, _windowInfo.ClientRectangle);
|
||||
OnLoad();
|
||||
|
@ -161,7 +162,7 @@ namespace Blarg.GameFramework
|
|||
GameApp.Dispose();
|
||||
GameApp = null;
|
||||
|
||||
ReleaseSDL();
|
||||
Release();
|
||||
}
|
||||
|
||||
public override void Quit()
|
||||
|
@ -611,13 +612,15 @@ namespace Blarg.GameFramework
|
|||
|
||||
#region IDisposable
|
||||
|
||||
private void ReleaseSDL()
|
||||
protected override void Release()
|
||||
{
|
||||
if (!_isSDLinited)
|
||||
return;
|
||||
|
||||
Logger.Info(LOG_TAG, "Releasing SDL.");
|
||||
Logger.Info(LOG_TAG, "Releasing SDL application object.");
|
||||
base.Release();
|
||||
|
||||
Logger.Info(LOG_TAG, "Releasing SDL.");
|
||||
DestroyOpenGLContext();
|
||||
DestroyWindow();
|
||||
SDL.SDL_Quit();
|
||||
|
@ -628,14 +631,14 @@ namespace Blarg.GameFramework
|
|||
|
||||
~SDLApplication()
|
||||
{
|
||||
ReleaseSDL();
|
||||
Release();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
Logger.Info(LOG_TAG, "Disposing.");
|
||||
ReleaseSDL();
|
||||
Release();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ namespace Blarg.GameFramework
|
|||
{
|
||||
const string LOG_TAG = "BASE_APP";
|
||||
|
||||
private bool _isReleased = false;
|
||||
|
||||
protected IGameApp GameApp { get; set; }
|
||||
|
||||
public abstract PlatformOS OperatingSystem { get; }
|
||||
|
@ -22,6 +24,7 @@ namespace Blarg.GameFramework
|
|||
public abstract ITouchScreen TouchScreen { get; }
|
||||
public abstract IPlatformWindow Window { get; }
|
||||
public abstract GL20 GL { get; }
|
||||
public GraphicsDevice GraphicsDevice { get; private set; }
|
||||
|
||||
public int FPS { get; protected set; }
|
||||
public float FrameTime { get; protected set; }
|
||||
|
@ -34,6 +37,12 @@ namespace Blarg.GameFramework
|
|||
public abstract void Run(IGameApp gameApp, IPlatformConfiguration config);
|
||||
public abstract void Quit();
|
||||
|
||||
protected void OnInit()
|
||||
{
|
||||
Logger.Info(LOG_TAG, "Initializing application objects.");
|
||||
GraphicsDevice = new GraphicsDevice();
|
||||
}
|
||||
|
||||
protected void OnAppGainFocus()
|
||||
{
|
||||
Logger.Info(LOG_TAG, "OnAppGainFocus");
|
||||
|
@ -98,10 +107,22 @@ namespace Blarg.GameFramework
|
|||
GameApp.OnUpdate(delta);
|
||||
}
|
||||
|
||||
#region Disposable
|
||||
|
||||
protected virtual void Release()
|
||||
{
|
||||
if (_isReleased)
|
||||
return;
|
||||
|
||||
Logger.Info(LOG_TAG, "Releasing resources.");
|
||||
GraphicsDevice.Dispose();
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
Logger.Info(LOG_TAG, "Disposing.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using PortableGL;
|
||||
using Blarg.GameFramework.Graphics;
|
||||
using Blarg.GameFramework.Input;
|
||||
using Blarg.GameFramework.IO;
|
||||
|
||||
|
@ -16,6 +17,7 @@ namespace Blarg.GameFramework
|
|||
IMouse Mouse { get; }
|
||||
ITouchScreen TouchScreen { get; }
|
||||
IPlatformWindow Window { get; }
|
||||
GraphicsDevice GraphicsDevice { get; }
|
||||
GL20 GL { get; }
|
||||
|
||||
int FPS { get; }
|
||||
|
|
|
@ -23,16 +23,52 @@ namespace Blarg.GameFramework
|
|||
|
||||
public static class Platform
|
||||
{
|
||||
public static PlatformOS OperatingSystem { get; private set; }
|
||||
public static PlatformType Type { get; private set; }
|
||||
|
||||
public static IApplication Application { get; private set; }
|
||||
public static ILogger Logger { get; private set; }
|
||||
public static IFileSystem FileSystem { get; private set; }
|
||||
public static IKeyboard Keyboard { get; private set; }
|
||||
public static IMouse Mouse { get; private set; }
|
||||
public static ITouchScreen TouchScreen { get; private set; }
|
||||
public static GL20 GL { get; private set; }
|
||||
|
||||
public static PlatformOS OperatingSystem
|
||||
{
|
||||
get { return Application.OperatingSystem; }
|
||||
}
|
||||
|
||||
public static PlatformType Type
|
||||
{
|
||||
get { return Application.Type; }
|
||||
}
|
||||
|
||||
public static ILogger Logger
|
||||
{
|
||||
get { return Application.Logger; }
|
||||
}
|
||||
|
||||
public static IFileSystem FileSystem
|
||||
{
|
||||
get { return Application.FileSystem; }
|
||||
}
|
||||
|
||||
public static IKeyboard Keyboard
|
||||
{
|
||||
get { return Application.Keyboard; }
|
||||
}
|
||||
|
||||
public static IMouse Mouse
|
||||
{
|
||||
get { return Application.Mouse; }
|
||||
}
|
||||
|
||||
public static ITouchScreen TouchScreen
|
||||
{
|
||||
get { return Application.TouchScreen; }
|
||||
}
|
||||
|
||||
public static GraphicsDevice GraphicsDevice
|
||||
{
|
||||
get { return Application.GraphicsDevice; }
|
||||
}
|
||||
|
||||
public static GL20 GL
|
||||
{
|
||||
get { return Application.GL; }
|
||||
}
|
||||
|
||||
public static void Set(IApplication application)
|
||||
{
|
||||
|
@ -40,14 +76,6 @@ namespace Blarg.GameFramework
|
|||
throw new InvalidOperationException();
|
||||
|
||||
Application = application;
|
||||
OperatingSystem = Application.OperatingSystem;
|
||||
Type = Application.Type;
|
||||
Logger = Application.Logger;
|
||||
FileSystem = Application.FileSystem;
|
||||
Keyboard = Application.Keyboard;
|
||||
Mouse = Application.Mouse;
|
||||
TouchScreen = Application.TouchScreen;
|
||||
GL = Application.GL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue