From 987c86fae9848e0ad335eefcc61e19f3b61012ee Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 15 Jul 2020 15:17:19 -0400 Subject: [PATCH] mv World & Scene to SneakWorld & SneakScene. --- Shared/FSM.cs | 4 ++-- Shared/NPC.cs | 6 +++--- Shared/Player.cs | 6 +++--- Shared/Shared.projitems | 4 ++-- Shared/SneakGame.cs | 8 ++++---- Shared/{Scene.cs => SneakScene.cs} | 8 ++++---- Shared/{World.cs => SneakWorld.cs} | 6 +++--- Shared/TreeScene.cs | 4 ++++ Shared/TreeWorld.cs | 7 +++++++ 9 files changed, 32 insertions(+), 21 deletions(-) rename Shared/{Scene.cs => SneakScene.cs} (97%) rename Shared/{World.cs => SneakWorld.cs} (98%) diff --git a/Shared/FSM.cs b/Shared/FSM.cs index 8791b09..7bee5b7 100644 --- a/Shared/FSM.cs +++ b/Shared/FSM.cs @@ -7,7 +7,7 @@ namespace SemiColinGames { public void Enter(); // Returns the name of the new state, or null if we should stay in the same state. - public string Update(float modelTime, World world, T input); + public string Update(float modelTime, SneakWorld world, T input); } public class FSM { @@ -23,7 +23,7 @@ namespace SemiColinGames { public IState State { get; private set; } - public void Update(float modelTime, World world, T input) { + public void Update(float modelTime, SneakWorld world, T input) { string newState = State.Update(modelTime, world, input); if (newState != null) { Transition(newState); diff --git a/Shared/NPC.cs b/Shared/NPC.cs index 7e60de3..a9b9519 100644 --- a/Shared/NPC.cs +++ b/Shared/NPC.cs @@ -16,7 +16,7 @@ namespace SemiColinGames { timeInState = 0; } - public string Update(float modelTime, World world, Object _) { + public string Update(float modelTime, SneakWorld world, Object _) { timeInState += modelTime; if (timeInState > 1.0f) { npc.Facing *= -1; @@ -35,7 +35,7 @@ namespace SemiColinGames { public void Enter() {} - public string Update(float modelTime, World world, Object _) { + public string Update(float modelTime, SneakWorld world, Object _) { float moveSpeed = 120; float desiredX = npc.Position.X + moveSpeed * npc.Facing * modelTime; float testPoint = desiredX + npc.Box.HalfSize.X * npc.Facing; @@ -110,7 +110,7 @@ namespace SemiColinGames { } } - public void Update(float modelTime, World world) { + public void Update(float modelTime, SneakWorld world) { fsm.Update(modelTime, world, null); Box = new AABB(Position, halfSize); Debug.AddRect(Box, Color.White); diff --git a/Shared/Player.cs b/Shared/Player.cs index 0e3a758..ef88354 100644 --- a/Shared/Player.cs +++ b/Shared/Player.cs @@ -24,7 +24,7 @@ namespace SemiColinGames { public void Enter() { } - public string Update(float modelTime, World world, History input) { + public string Update(float modelTime, SneakWorld world, History input) { result = new Vector2() { X = input[0].Motion.X * moveSpeed * modelTime }; @@ -120,7 +120,7 @@ namespace SemiColinGames { public Vector2 Position { get { return position; } } - public void Update(float modelTime, World world, History input) { + public void Update(float modelTime, SneakWorld world, History input) { AABB BoxOffset(Vector2 position, int yOffset) { return new AABB(new Vector2(position.X, position.Y + yOffset), halfSize); } @@ -224,7 +224,7 @@ namespace SemiColinGames { } // Returns the desired (dx, dy) for the player to move this frame. - Vector2 HandleInput(float modelTime, World world, History input) { + Vector2 HandleInput(float modelTime, SneakWorld world, History input) { fsm.Update(modelTime, world, input); // TODO: remove ugly cast. return ((IPlayerState) fsm.State).Movement; diff --git a/Shared/Shared.projitems b/Shared/Shared.projitems index b3b7ea5..c9f32c2 100644 --- a/Shared/Shared.projitems +++ b/Shared/Shared.projitems @@ -16,6 +16,8 @@ + + @@ -31,11 +33,9 @@ - - \ No newline at end of file diff --git a/Shared/SneakGame.cs b/Shared/SneakGame.cs index f26c995..05d0946 100644 --- a/Shared/SneakGame.cs +++ b/Shared/SneakGame.cs @@ -64,11 +64,11 @@ namespace SemiColinGames { private void LoadLevel() { world?.Dispose(); - // world = new World(GraphicsDevice, Content.LoadString("levels/demo.json")); - world = new TreeWorld(); + world = new SneakWorld(GraphicsDevice, Content.LoadString("levels/demo.json")); + // world = new TreeWorld(); scene?.Dispose(); - // scene = new Scene(GraphicsDevice, ((World) world).Camera); - scene = new TreeScene(GraphicsDevice); + scene = new SneakScene(GraphicsDevice, ((SneakWorld) world).Camera); + // scene = new TreeScene(GraphicsDevice); GC.Collect(); GC.WaitForPendingFinalizers(); diff --git a/Shared/Scene.cs b/Shared/SneakScene.cs similarity index 97% rename from Shared/Scene.cs rename to Shared/SneakScene.cs index c6056a6..d42e720 100644 --- a/Shared/Scene.cs +++ b/Shared/SneakScene.cs @@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics; using System; namespace SemiColinGames { - public sealed class Scene : IScene { + public sealed class SneakScene : IScene { const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f; private readonly Color backgroundColor = Color.CornflowerBlue; @@ -22,7 +22,7 @@ namespace SemiColinGames { // frames can be really slow to draw. private int framesToSuppress = 2; - public Scene(GraphicsDevice graphics, Camera camera) { + public SneakScene(GraphicsDevice graphics, Camera camera) { this.graphics = graphics; this.camera = camera; @@ -43,7 +43,7 @@ namespace SemiColinGames { music.Volume = 0.1f; } - ~Scene() { + ~SneakScene() { Dispose(); } @@ -57,7 +57,7 @@ namespace SemiColinGames { } public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) { - World world = (World) iworld; + SneakWorld world = (SneakWorld) iworld; graphics.SetRenderTarget(null); graphics.Clear(backgroundColor); diff --git a/Shared/World.cs b/Shared/SneakWorld.cs similarity index 98% rename from Shared/World.cs rename to Shared/SneakWorld.cs index d6fded3..63d948c 100644 --- a/Shared/World.cs +++ b/Shared/SneakWorld.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace SemiColinGames { - public sealed class World : IWorld { + public sealed class SneakWorld : IWorld { // Size of World in terms of tile grid. private int gridWidth; @@ -27,7 +27,7 @@ namespace SemiColinGames { public readonly int Height; // TODO: it seems weird that World takes in a GraphicsDevice. Remove it? - public World(GraphicsDevice graphics, string json) { + public SneakWorld(GraphicsDevice graphics, string json) { Camera = new Camera(); LinesOfSight = new LinesOfSight(graphics); @@ -90,7 +90,7 @@ namespace SemiColinGames { new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue)); } - ~World() { + ~SneakWorld() { Dispose(); } diff --git a/Shared/TreeScene.cs b/Shared/TreeScene.cs index e7b5b9f..230f568 100644 --- a/Shared/TreeScene.cs +++ b/Shared/TreeScene.cs @@ -14,6 +14,10 @@ namespace SemiColinGames { this.graphics = graphics; } + ~TreeScene() { + Dispose(); + } + public void Dispose() { GC.SuppressFinalize(this); } diff --git a/Shared/TreeWorld.cs b/Shared/TreeWorld.cs index e04f7c5..fc70cd4 100644 --- a/Shared/TreeWorld.cs +++ b/Shared/TreeWorld.cs @@ -5,6 +5,13 @@ using System.Collections.Generic; namespace SemiColinGames { public sealed class TreeWorld : IWorld { + public TreeWorld() { + } + + ~TreeWorld() { + Dispose(); + } + public void Dispose() { GC.SuppressFinalize(this); }