diff --git a/Src/Game.NET/Core/Engine.cs b/Src/Game.NET/Core/Engine.cs index db935d2..e72eba0 100644 --- a/Src/Game.NET/Core/Engine.cs +++ b/Src/Game.NET/Core/Engine.cs @@ -1,4 +1,9 @@ -using Game.NET.Logic; +using System.Collections.Generic; +using Game.NET.Gfx; +using Game.NET.Logic; +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; namespace Game.NET.Core { @@ -10,6 +15,25 @@ public class Engine public bool IsDone { get; private set; } + public IResourceManager ResourceManager + { + get + { + if (_resourceManager == null) + _resourceManager = new ResourceManager(); + return _resourceManager; + } + } + + private List states = new List(); + + private GameWindow window; + private Renderer renderer = new Renderer(); + private IResourceManager _resourceManager; + + private float fpsTime; + private int frames; + public Engine() { IsDone = true; @@ -18,9 +42,12 @@ public Engine() public bool Init(string[] argv = null, string config = "Config.cfg") { IsDone = false; + + renderer.CreateBatch("default"); + return true; } - + public void SwitchState(State state) { if (CurrentState != null) CurrentState.End(); @@ -30,9 +57,48 @@ public void SwitchState(State state) if (CurrentState != null) CurrentState.Start(); } + public void ProcessInput() + { + if(CurrentState != null) CurrentState.ProcessInput(); + } + + public void Update(GameTime time) + { + time.RealTime += time.DeltaTime; + time.Time += time.Speed * time.DeltaTime; + + if (fpsTime >= 1.0f) + { + time.Fps = frames / fpsTime; + frames = 0; + fpsTime = 0.0f; + } + + if (CurrentState != null) CurrentState.Update(time); + } + + public void Draw(GameTime time) + { + frames++; + fpsTime += time.DeltaTime; + + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + + if (CurrentState != null) CurrentState.Draw(renderer, time); + + renderer.Draw(); + } + + public void Exit() + { + IsDone = true; + } + public void CleanUp() { IsDone = true; + // free data + ResourceManager.CleanAll(); } } } diff --git a/Src/Game.NET/Core/ResourceManager/ResourceManager.cs b/Src/Game.NET/Core/ResourceManager/ResourceManager.cs index 9a05135..123de65 100644 --- a/Src/Game.NET/Core/ResourceManager/ResourceManager.cs +++ b/Src/Game.NET/Core/ResourceManager/ResourceManager.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Game.NET { @@ -52,6 +53,7 @@ public void Remove(T resource) where T : Resource { if (Contains(resource.Name)) { + Delete(resource); _resources.Remove(resource.Name); } } @@ -60,13 +62,28 @@ public void Remove(string name) where T : Resource { if (Contains(name)) { + Delete(_resources[name]); _resources.Remove(name); } } public void CleanAll() { + foreach (var resource in _resources) + { + Delete(resource.Value); + } + _resources.Clear(); } + + private void Delete(Resource resource) + { + IDisposable disposable = resource as IDisposable; + if (disposable != null) + { + disposable.Dispose(); + } + } } } diff --git a/Src/Game.NET/Game.NET.csproj b/Src/Game.NET/Game.NET.csproj index 8ac3461..0bc40f8 100644 --- a/Src/Game.NET/Game.NET.csproj +++ b/Src/Game.NET/Game.NET.csproj @@ -23,6 +23,7 @@ prompt 4 false + true AnyCPU @@ -58,12 +59,24 @@ + + + + + + + + + + + + @@ -78,7 +91,7 @@ - + @@ -94,6 +107,7 @@ +