switch test GameApp to use BasicGameApp and game states/processes instead
This commit is contained in:
parent
5b45f2c71e
commit
03a71a52ab
41
Game.Core/DebugInfoProcess.cs
Normal file
41
Game.Core/DebugInfoProcess.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using Blarg.GameFramework;
|
||||
using Blarg.GameFramework.Events;
|
||||
using Blarg.GameFramework.Graphics;
|
||||
using Blarg.GameFramework.Processes;
|
||||
using Blarg.GameFramework.Support;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class DebugInfoProcess : GameProcess
|
||||
{
|
||||
StringBuilder _sb = new StringBuilder(1024);
|
||||
SpriteBatch _spriteBatch;
|
||||
|
||||
public DebugInfoProcess(ProcessManager processManager, EventManager eventManager)
|
||||
: base(processManager, eventManager)
|
||||
{
|
||||
_spriteBatch = Framework.Services.Get<SpriteBatch>();
|
||||
}
|
||||
|
||||
public override void OnRender(float delta)
|
||||
{
|
||||
base.OnRender(delta);
|
||||
|
||||
long gcmem = GC.GetTotalMemory(false);
|
||||
_sb.Clear();
|
||||
_sb.Append("GC Mem Usage: ").AppendNumber((int)gcmem).Append('\n');
|
||||
_sb.Append("FPS: ").AppendNumber(Framework.Application.FPS);
|
||||
_sb.Append(", ").AppendNumber(Framework.Application.FrameTime).Append(" ms");
|
||||
_sb.Append(", RT: ").AppendNumber(Framework.Application.RenderTime).Append(" (").AppendNumber(Framework.Application.RendersPerSecond).Append(")");
|
||||
_sb.Append(", UT: ").AppendNumber(Framework.Application.UpdateTime).Append(" (").AppendNumber(Framework.Application.UpdatesPerSecond).Append(")");
|
||||
_sb.Append(", RD: ").AppendNumber(delta);
|
||||
|
||||
_spriteBatch.Begin();
|
||||
_spriteBatch.Render(Framework.GraphicsDevice.SansSerifFont, 10, 10, Color.White, _sb);
|
||||
_spriteBatch.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,8 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GameApp.cs" />
|
||||
<Compile Include="TestGameState.cs" />
|
||||
<Compile Include="DebugInfoProcess.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -8,103 +8,12 @@ using Blarg.GameFramework.Support;
|
|||
|
||||
namespace Game
|
||||
{
|
||||
public class GameApp : IGameApp
|
||||
public class GameApp : BasicGameApp
|
||||
{
|
||||
FlatWireframeGrid _grid;
|
||||
FreeMovementCamera _camera;
|
||||
SpriteBatch _spriteBatch;
|
||||
StringBuilder _sb = new StringBuilder(1024);
|
||||
|
||||
public GameApp()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnInit()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnShutdown()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAppGainFocus()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAppLostFocus()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAppPause()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAppResume()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnLoad()
|
||||
{
|
||||
_camera = new FreeMovementCamera(Framework.GraphicsDevice.ViewContext);
|
||||
_camera.Position = new Vector3(0.0f, 5.0f, 0.0f);
|
||||
Framework.GraphicsDevice.ViewContext.Camera = _camera;
|
||||
|
||||
_grid = new FlatWireframeGrid(Framework.GraphicsDevice, 32, 32);
|
||||
|
||||
_spriteBatch = new SpriteBatch(Framework.GraphicsDevice);
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
Framework.GraphicsDevice.ViewContext.Camera = null;
|
||||
}
|
||||
|
||||
public void OnLostContext()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnNewContext()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnRender(float delta)
|
||||
{
|
||||
Framework.GraphicsDevice.Clear(0.25f, 0.5f, 1.0f, 1.0f);
|
||||
|
||||
var shader = Framework.GraphicsDevice.SimpleColorShader;
|
||||
Framework.GraphicsDevice.BindShader(shader);
|
||||
shader.SetModelViewMatrix(Framework.GraphicsDevice.ViewContext.ModelViewMatrix);
|
||||
shader.SetProjectionMatrix(Framework.GraphicsDevice.ViewContext.ProjectionMatrix);
|
||||
_grid.Render();
|
||||
Framework.GraphicsDevice.UnbindShader();
|
||||
|
||||
long gcmem = GC.GetTotalMemory(false);
|
||||
_sb.Clear();
|
||||
_sb.Append("GC Mem Usage: ").AppendNumber((int)gcmem).Append('\n')
|
||||
.Append("FPS: ").AppendNumber(Framework.Application.FPS)
|
||||
.Append(", ").AppendNumber(Framework.Application.FrameTime).Append(" ms")
|
||||
.Append(", RT: ").AppendNumber(Framework.Application.RenderTime).Append(" (").AppendNumber(Framework.Application.RendersPerSecond).Append(")")
|
||||
.Append(", UT: ").AppendNumber(Framework.Application.UpdateTime).Append(" (").AppendNumber(Framework.Application.UpdatesPerSecond).Append(")")
|
||||
.Append(", RD: ").AppendNumber(delta);
|
||||
|
||||
_spriteBatch.Begin();
|
||||
_spriteBatch.Render(Framework.GraphicsDevice.SansSerifFont, 10, 10, Color.White, _sb);
|
||||
_spriteBatch.End();
|
||||
}
|
||||
|
||||
public void OnResize(ScreenOrientation orientation, Rect size)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnUpdate(float delta)
|
||||
{
|
||||
if (Framework.Keyboard.IsPressed(Blarg.GameFramework.Input.Key.Escape))
|
||||
Framework.Application.Quit();
|
||||
_camera.OnUpdate(delta);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public override void OnLoad()
|
||||
{
|
||||
base.OnLoad();
|
||||
StateManager.Push<TestGameState>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
61
Game.Core/TestGameState.cs
Normal file
61
Game.Core/TestGameState.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using Blarg.GameFramework;
|
||||
using Blarg.GameFramework.Events;
|
||||
using Blarg.GameFramework.Graphics;
|
||||
using Blarg.GameFramework.Graphics.Helpers;
|
||||
using Blarg.GameFramework.Graphics.ScreenEffects;
|
||||
using Blarg.GameFramework.States;
|
||||
using Blarg.GameFramework.Support;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class TestGameState : GameState
|
||||
{
|
||||
FlatWireframeGrid _grid;
|
||||
FreeMovementCamera _camera;
|
||||
|
||||
public TestGameState(StateManager stateManager, EventManager eventManager)
|
||||
: base(stateManager, eventManager)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnPush()
|
||||
{
|
||||
_camera = new FreeMovementCamera(Framework.GraphicsDevice.ViewContext);
|
||||
_camera.Position = new Vector3(0.0f, 5.0f, 0.0f);
|
||||
Framework.GraphicsDevice.ViewContext.Camera = _camera;
|
||||
|
||||
_grid = new FlatWireframeGrid(Framework.GraphicsDevice, 32, 32);
|
||||
|
||||
ProcessManager.Add<DebugInfoProcess>();
|
||||
}
|
||||
|
||||
public override void OnPop()
|
||||
{
|
||||
Framework.GraphicsDevice.ViewContext.Camera = null;
|
||||
}
|
||||
|
||||
public override void OnRender(float delta)
|
||||
{
|
||||
Framework.GraphicsDevice.Clear(0.25f, 0.5f, 1.0f, 1.0f);
|
||||
|
||||
var shader = Framework.GraphicsDevice.SimpleColorShader;
|
||||
Framework.GraphicsDevice.BindShader(shader);
|
||||
shader.SetModelViewMatrix(Framework.GraphicsDevice.ViewContext.ModelViewMatrix);
|
||||
shader.SetProjectionMatrix(Framework.GraphicsDevice.ViewContext.ProjectionMatrix);
|
||||
_grid.Render();
|
||||
Framework.GraphicsDevice.UnbindShader();
|
||||
|
||||
base.OnRender(delta);
|
||||
}
|
||||
|
||||
public override void OnUpdate(float delta)
|
||||
{
|
||||
base.OnUpdate(delta);
|
||||
if (Framework.Keyboard.IsPressed(Blarg.GameFramework.Input.Key.Escape))
|
||||
Framework.Application.Quit();
|
||||
_camera.OnUpdate(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in a new issue