From 01748bc5f8b78a55a8d8a0fdcbdff50d21b78322 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 2 Jan 2015 20:14:38 -0600 Subject: [PATCH] Fixing axios log flag detection Adding dispose methods to AxiosFile objects Adding extended log to AxiosLog Fixing issue in CommandConsole where the first line would not be displayed Adding commands to commandconsole --- axios/Axios_settings.cs | 4 +++ axios/Engine/AxiosCommandConsole.cs | 8 ++++- axios/Engine/AxiosGameScreen.cs | 16 +++++++-- axios/Engine/Data/Cache.cs | 12 ++++++- .../Extensions/RectangleItemProperties.cs | 6 ++++ axios/Engine/Extensions/Vector2.cs | 1 + axios/Engine/File/AxiosFile.cs | 2 ++ axios/Engine/File/AxiosIsolatedFile.cs | 29 ++++++++++++--- axios/Engine/File/AxiosRegularFile.cs | 29 +++++++++++++-- axios/Engine/File/AxiosTitleFile.cs | 26 ++++++++++++-- axios/Engine/Log/AxiosLog.cs | 35 +++++++++++++++++-- axios/ScreenSystem/GameScreen.cs | 2 ++ axios/ScreenSystem/ScreenManager.cs | 2 ++ axios/XNACC/CommandConsoleBase.cs | 2 +- 14 files changed, 157 insertions(+), 17 deletions(-) diff --git a/axios/Axios_settings.cs b/axios/Axios_settings.cs index d3acd33..cbc7ab9 100644 --- a/axios/Axios_settings.cs +++ b/axios/Axios_settings.cs @@ -136,6 +136,10 @@ * - Adding XOR Shift random class * - Adding extension for rectangleitem to get position in Farseer units ( getSimPosition ) * - Adding extension for vector2 to convert back and forth between sim and display units + * - Fixing axios log flag detection + * - Adding dispose methods to AxiosFile objects + * - Adding extended log to AxiosLog + * - Fixing issue in CommandConsole where the first line would not be displayed * */ #endregion diff --git a/axios/Engine/AxiosCommandConsole.cs b/axios/Engine/AxiosCommandConsole.cs index 1b3a689..7ee8602 100644 --- a/axios/Engine/AxiosCommandConsole.cs +++ b/axios/Engine/AxiosCommandConsole.cs @@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework; using Axios.Engine.Log; +using Axios.Engine.Data; /* * The empty AxiosCommandConsole is so that when you use the comamnd console @@ -23,8 +24,11 @@ namespace Axios.Engine { public class AxiosCommandConsole : CommandConsoleBase { - protected AxiosGameScreen GameScreen; + public AxiosGameScreen GameScreen; protected List RestrictedCommands = new List(); + + public bool KeepRunning = false; + public AxiosCommandConsole(AxiosGameScreen gameScreen) : base(gameScreen.ScreenManager.Game) { @@ -65,6 +69,8 @@ namespace Axios.Engine { AddCommand(new CmdObject("axioslog", "Displays the current Axios Log", input => { ShowAxiosLog(); })); AddCommand(new CmdObject("tcc", "Toggles user camera control", input => { ToggleCamera(); })); + AddCommand(new CmdObject("axiosloglevel", "Outputs axios log level", input => { AddOutputToLog(Settings.Loglevel.ToString()); })); + AddCommand(new CmdObject("saveaxiosextlog", "Saves Axios Engine extended log (any log events)", input => { AxiosLog.Instance.writeExtendedLog(); })); base.InitializeCustomCommands(); } diff --git a/axios/Engine/AxiosGameScreen.cs b/axios/Engine/AxiosGameScreen.cs index 84e274c..223919b 100644 --- a/axios/Engine/AxiosGameScreen.cs +++ b/axios/Engine/AxiosGameScreen.cs @@ -65,10 +65,12 @@ namespace Axios.Engine public AxiosCommandConsole Console { get { return _console; } - private set { _console = value; } + set { _console = value; } } #endif + protected bool screenHidden = false; + public AxiosGameScreen() : base() { @@ -328,6 +330,16 @@ namespace Axios.Engine public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { + if (otherScreenHasFocus) + { + screenHidden = true; + } + + if (screenHidden && !otherScreenHasFocus) + { + this.ReActivate(); + screenHidden = false; + } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (this._objectstoremove.Count > 0) @@ -517,7 +529,7 @@ namespace Axios.Engine //f.WriteData(AxiosLog.Instance.GetLog(), FileMode.Append); //CleanUp(); #if WINDOWS - if (_console != null) + if (_console != null && !_console.KeepRunning) { //System.Diagnostics.Debugger.Break(); ScreenManager.Game.Components.Remove(_console); diff --git a/axios/Engine/Data/Cache.cs b/axios/Engine/Data/Cache.cs index bc9fe0b..d770a85 100644 --- a/axios/Engine/Data/Cache.cs +++ b/axios/Engine/Data/Cache.cs @@ -9,6 +9,7 @@ namespace Axios.Engine.Data // A. This is not to cache textures loaded by content manager // but other data/content that isn't. Use cases include: // - Any graphics generated during runtime (such as dialogs) + // - Command console // - Any data that is loaded in during run time (such as maps) // Content manager performs it's own caching so anything loaded by it // or the Gameservice - then attempted to load again will not be loaded @@ -34,7 +35,16 @@ namespace Axios.Engine.Data public object get(string key) { - return _cache[key]; + object val; + _cache.TryGetValue(key, out val); + return val; + } + + public T get(string key) + { + object val; + _cache.TryGetValue(key, out val); + return (T)val; } public void set(string key, object obj) diff --git a/axios/Engine/Extensions/RectangleItemProperties.cs b/axios/Engine/Extensions/RectangleItemProperties.cs index 5541fcc..1b642e2 100644 --- a/axios/Engine/Extensions/RectangleItemProperties.cs +++ b/axios/Engine/Extensions/RectangleItemProperties.cs @@ -17,5 +17,11 @@ namespace Axios.Engine.Extensions pos.Y += ConvertUnits.ToSimUnits(prop.Height / 2); return pos; } + + public static Vector2 getCenter(this RectangleItemProperties prop) + { + return prop.getSimPosition() / ConvertUnits.ToSimUnits(2); + } + } } diff --git a/axios/Engine/Extensions/Vector2.cs b/axios/Engine/Extensions/Vector2.cs index 3fe494b..cabf767 100644 --- a/axios/Engine/Extensions/Vector2.cs +++ b/axios/Engine/Extensions/Vector2.cs @@ -19,5 +19,6 @@ namespace Axios.Engine.Extensions { return ConvertUnits.ToDisplayUnits(vec); } + } } diff --git a/axios/Engine/File/AxiosFile.cs b/axios/Engine/File/AxiosFile.cs index 4e4eecd..711e6f8 100644 --- a/axios/Engine/File/AxiosFile.cs +++ b/axios/Engine/File/AxiosFile.cs @@ -9,6 +9,8 @@ namespace Axios.Engine.File { protected string _content; + protected bool disposed = false; + public String Content { get { return _content; } diff --git a/axios/Engine/File/AxiosIsolatedFile.cs b/axios/Engine/File/AxiosIsolatedFile.cs index 42dd6d4..733f82f 100644 --- a/axios/Engine/File/AxiosIsolatedFile.cs +++ b/axios/Engine/File/AxiosIsolatedFile.cs @@ -1,12 +1,13 @@ using System.IO; using System.IO.IsolatedStorage; using Axios.Engine.Interfaces; +using System; namespace Axios.Engine.File { public class AxiosIsolatedFile : AxiosFile, IAxiosFile { - + protected IsolatedStorageFileStream _fs; public AxiosIsolatedFile(string filename) { this._filename = filename; @@ -58,9 +59,29 @@ namespace Axios.Engine.File #else IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication(); #endif - IsolatedStorageFileStream fs = null; - fs = savegameStorage.OpenFile(_filename, mode); - return (Stream)fs; + _fs = null; + _fs = savegameStorage.OpenFile(_filename, mode); + return (Stream)_fs; + } + + public void Dispose() + { + // http://msdn.microsoft.com/en-us/library/system.idisposable%28v=vs.110%29.aspx + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing && _fs != null) + { + _fs.Close(); + } + + disposed = true; } } diff --git a/axios/Engine/File/AxiosRegularFile.cs b/axios/Engine/File/AxiosRegularFile.cs index e241d18..ab3ec3c 100644 --- a/axios/Engine/File/AxiosRegularFile.cs +++ b/axios/Engine/File/AxiosRegularFile.cs @@ -1,11 +1,13 @@ using System.IO; +using System; using Axios.Engine.Interfaces; namespace Axios.Engine.File { - public class AxiosRegularFile : AxiosFile, IAxiosFile + public class AxiosRegularFile : AxiosFile, IAxiosFile, IDisposable { + protected FileStream _fs; public AxiosRegularFile(string file) { _filename = file; @@ -39,8 +41,29 @@ namespace Axios.Engine.File public override Stream GetStream(FileMode mode) { - FileStream fs = new FileStream(_filename, mode); - return (Stream)fs; + _fs = new FileStream(_filename, mode); + return (Stream)_fs; + } + + + public void Dispose() + { + // http://msdn.microsoft.com/en-us/library/system.idisposable%28v=vs.110%29.aspx + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing && _fs != null) + { + _fs.Close(); + } + + disposed = true; } } } diff --git a/axios/Engine/File/AxiosTitleFile.cs b/axios/Engine/File/AxiosTitleFile.cs index 21918d7..5de2004 100644 --- a/axios/Engine/File/AxiosTitleFile.cs +++ b/axios/Engine/File/AxiosTitleFile.cs @@ -5,8 +5,9 @@ using Microsoft.Xna.Framework; namespace Axios.Engine.File { - public class AxiosTitleFile : AxiosFile, IAxiosFile + public class AxiosTitleFile : AxiosFile, IAxiosFile, IDisposable { + protected Stream _fs; public AxiosTitleFile(string filename) { //Title Files can only be opened for reading! @@ -30,7 +31,28 @@ namespace Axios.Engine.File public override Stream GetStream(FileMode mode) { - return (Stream)TitleContainer.OpenStream(_filename);; + _fs = (Stream)TitleContainer.OpenStream(_filename); + return _fs; + } + + public void Dispose() + { + // http://msdn.microsoft.com/en-us/library/system.idisposable%28v=vs.110%29.aspx + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing && _fs != null) + { + _fs.Close(); + } + + disposed = true; } } } diff --git a/axios/Engine/Log/AxiosLog.cs b/axios/Engine/Log/AxiosLog.cs index e8d3bc2..3336697 100644 --- a/axios/Engine/Log/AxiosLog.cs +++ b/axios/Engine/Log/AxiosLog.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Axios.Engine.Data; +using Axios.Engine.File; namespace Axios.Engine.Log @@ -13,22 +15,33 @@ namespace Axios.Engine.Log WARN = 4, ERROR = 8, FATAL = 16, - ALL = 32 + ALL = ~0 } public class AxiosLog : Singleton { private List _log; + // Logs everything regardless of log level + // Used for debugging purposes + private List _extendedlog; public AxiosLog() { _log = new List(); + _extendedlog = new List(); } public void AddLine(string line, LoggingFlag flag) { - - if (flag <= Settings.Loglevel) + + if (Settings.Loglevel.HasFlag(flag)) + { + AxiosCommandConsole c = (AxiosCommandConsole)Cache.Instance.get("commandconsole"); + if (c != null) + c.AddToLog(line); _log.Add("[" + DateTime.Now.ToString("M/d/yyyy H:mm:ss") + " - " + flag.ToString() + "]" + line); + } + + _extendedlog.Add("[" + DateTime.Now.ToString("M/d/yyyy H:mm:ss") + " - " + flag.ToString() + "]" + line); } public List GetLogList() @@ -45,5 +58,21 @@ namespace Axios.Engine.Log { return GetLog("\r\n"); } + + public void writeLog() + { + using (AxiosRegularFile file = new AxiosRegularFile(System.IO.Directory.GetCurrentDirectory() + "/axioslog.log")) + { + file.WriteData(GetLog(), System.IO.FileMode.Create); + } + } + + public void writeExtendedLog() + { + using (AxiosRegularFile file = new AxiosRegularFile(System.IO.Directory.GetCurrentDirectory() + "/axioslog.log")) + { + file.WriteData(String.Join("\r\n", _extendedlog.ToArray()), System.IO.FileMode.Create); + } + } } } diff --git a/axios/ScreenSystem/GameScreen.cs b/axios/ScreenSystem/GameScreen.cs index 9d58f55..2fc153f 100644 --- a/axios/ScreenSystem/GameScreen.cs +++ b/axios/ScreenSystem/GameScreen.cs @@ -247,6 +247,8 @@ namespace GameStateManagement /// public virtual void Unload() { } + public virtual void ReActivate() { } + /// /// Allows the screen to run logic, such as updating the transition position. diff --git a/axios/ScreenSystem/ScreenManager.cs b/axios/ScreenSystem/ScreenManager.cs index c3622bc..cde220a 100644 --- a/axios/ScreenSystem/ScreenManager.cs +++ b/axios/ScreenSystem/ScreenManager.cs @@ -225,6 +225,8 @@ namespace GameStateManagement // give it a chance to handle input. if (!otherScreenHasFocus) { + // The default implementation of screens aren't aware that it's + // being woke up input.ShowCursor = screen.HasCursor; input.EnableVirtualStick = screen.HasVirtualStick; screen.HandleInput(gameTime, input); diff --git a/axios/XNACC/CommandConsoleBase.cs b/axios/XNACC/CommandConsoleBase.cs index 46bf54a..eec828a 100644 --- a/axios/XNACC/CommandConsoleBase.cs +++ b/axios/XNACC/CommandConsoleBase.cs @@ -894,7 +894,7 @@ namespace XNACC.Console { m_linesBelow = true; } - for( int i = endLine; i > 0; i-- ) + for( int i = endLine; i >= 0; i-- ) { if( linePos.Y <= m_consoleRect.Top ) {