2013-08-17 15:15:24 -04:00
|
|
|
using System;
|
2013-08-18 18:03:28 -04:00
|
|
|
using System.Text;
|
2013-08-17 15:15:24 -04:00
|
|
|
using PortableGL;
|
|
|
|
using Blarg.GameFramework;
|
|
|
|
using Blarg.GameFramework.Graphics;
|
2013-08-18 14:20:42 -04:00
|
|
|
using Blarg.GameFramework.Graphics.Helpers;
|
|
|
|
using Blarg.GameFramework.Support;
|
2013-08-17 15:15:24 -04:00
|
|
|
|
|
|
|
namespace Game
|
|
|
|
{
|
|
|
|
public class GameApp : IGameApp
|
|
|
|
{
|
2013-08-18 14:20:42 -04:00
|
|
|
FlatWireframeGrid _grid;
|
|
|
|
FreeMovementCamera _camera;
|
2013-08-18 18:03:28 -04:00
|
|
|
SpriteBatch _spriteBatch;
|
|
|
|
StringBuilder _sb = new StringBuilder(1024);
|
2013-08-18 14:20:42 -04:00
|
|
|
|
2013-08-17 15:15:24 -04:00
|
|
|
public GameApp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-22 23:02:17 -04:00
|
|
|
public void OnInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnShutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-17 15:15:24 -04:00
|
|
|
public void OnAppGainFocus()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnAppLostFocus()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnAppPause()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnAppResume()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnLoad()
|
|
|
|
{
|
2013-08-23 18:02:02 -04:00
|
|
|
_camera = new FreeMovementCamera(Framework.GraphicsDevice.ViewContext);
|
2013-08-18 14:20:42 -04:00
|
|
|
_camera.Position = new Vector3(0.0f, 5.0f, 0.0f);
|
2013-08-23 18:02:02 -04:00
|
|
|
Framework.GraphicsDevice.ViewContext.Camera = _camera;
|
2013-08-18 14:20:42 -04:00
|
|
|
|
2013-08-23 18:02:02 -04:00
|
|
|
_grid = new FlatWireframeGrid(Framework.GraphicsDevice, 32, 32);
|
2013-08-18 18:03:28 -04:00
|
|
|
|
2013-08-23 18:02:02 -04:00
|
|
|
_spriteBatch = new SpriteBatch(Framework.GraphicsDevice);
|
2013-08-17 15:15:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnUnload()
|
|
|
|
{
|
2013-08-23 18:02:02 -04:00
|
|
|
Framework.GraphicsDevice.ViewContext.Camera = null;
|
2013-08-17 15:15:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnLostContext()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnNewContext()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnRender(float delta)
|
|
|
|
{
|
2013-08-23 18:02:02 -04:00
|
|
|
Framework.GraphicsDevice.Clear(0.25f, 0.5f, 1.0f, 1.0f);
|
2013-08-18 14:20:42 -04:00
|
|
|
|
2013-08-23 18:02:02 -04:00
|
|
|
var shader = Framework.GraphicsDevice.SimpleColorShader;
|
|
|
|
Framework.GraphicsDevice.BindShader(shader);
|
|
|
|
shader.SetModelViewMatrix(Framework.GraphicsDevice.ViewContext.ModelViewMatrix);
|
|
|
|
shader.SetProjectionMatrix(Framework.GraphicsDevice.ViewContext.ProjectionMatrix);
|
2013-08-18 14:20:42 -04:00
|
|
|
_grid.Render();
|
2013-08-23 18:02:02 -04:00
|
|
|
Framework.GraphicsDevice.UnbindShader();
|
2013-08-18 18:03:28 -04:00
|
|
|
|
|
|
|
long gcmem = GC.GetTotalMemory(false);
|
|
|
|
_sb.Clear();
|
|
|
|
_sb.Append("GC Mem Usage: ").AppendNumber((int)gcmem).Append('\n')
|
2013-08-23 18:02:02 -04:00
|
|
|
.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(")")
|
2013-08-18 20:14:14 -04:00
|
|
|
.Append(", RD: ").AppendNumber(delta);
|
2013-08-18 18:03:28 -04:00
|
|
|
|
|
|
|
_spriteBatch.Begin();
|
2013-08-23 18:02:02 -04:00
|
|
|
_spriteBatch.Render(Framework.GraphicsDevice.SansSerifFont, 10, 10, Color.White, _sb);
|
2013-08-18 18:03:28 -04:00
|
|
|
_spriteBatch.End();
|
2013-08-17 15:15:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnResize(ScreenOrientation orientation, Rect size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnUpdate(float delta)
|
|
|
|
{
|
2013-08-23 18:02:02 -04:00
|
|
|
if (Framework.Keyboard.IsPressed(Blarg.GameFramework.Input.Key.Escape))
|
|
|
|
Framework.Application.Quit();
|
2013-08-18 14:20:42 -04:00
|
|
|
_camera.OnUpdate(delta);
|
2013-08-17 15:15:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|