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
This commit is contained in:
Nathan Adams 2015-01-02 20:14:38 -06:00
parent b6e6744a88
commit 01748bc5f8
14 changed files with 157 additions and 17 deletions

View File

@ -136,6 +136,10 @@
* - Adding XOR Shift random class * - Adding XOR Shift random class
* - Adding extension for rectangleitem to get position in Farseer units ( getSimPosition ) * - 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 * - 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 #endregion

View File

@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Axios.Engine.Log; using Axios.Engine.Log;
using Axios.Engine.Data;
/* /*
* The empty AxiosCommandConsole is so that when you use the comamnd console * The empty AxiosCommandConsole is so that when you use the comamnd console
@ -23,8 +24,11 @@ namespace Axios.Engine
{ {
public class AxiosCommandConsole : CommandConsoleBase public class AxiosCommandConsole : CommandConsoleBase
{ {
protected AxiosGameScreen GameScreen; public AxiosGameScreen GameScreen;
protected List<string> RestrictedCommands = new List<string>(); protected List<string> RestrictedCommands = new List<string>();
public bool KeepRunning = false;
public AxiosCommandConsole(AxiosGameScreen gameScreen) public AxiosCommandConsole(AxiosGameScreen gameScreen)
: base(gameScreen.ScreenManager.Game) : 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("axioslog", "Displays the current Axios Log", input => { ShowAxiosLog(); }));
AddCommand(new CmdObject("tcc", "Toggles user camera control", input => { ToggleCamera(); })); 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(); base.InitializeCustomCommands();
} }

View File

@ -65,10 +65,12 @@ namespace Axios.Engine
public AxiosCommandConsole Console public AxiosCommandConsole Console
{ {
get { return _console; } get { return _console; }
private set { _console = value; } set { _console = value; }
} }
#endif #endif
protected bool screenHidden = false;
public AxiosGameScreen() public AxiosGameScreen()
: base() : base()
{ {
@ -328,6 +330,16 @@ namespace Axios.Engine
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) 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); base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
if (this._objectstoremove.Count > 0) if (this._objectstoremove.Count > 0)
@ -517,7 +529,7 @@ namespace Axios.Engine
//f.WriteData(AxiosLog.Instance.GetLog(), FileMode.Append); //f.WriteData(AxiosLog.Instance.GetLog(), FileMode.Append);
//CleanUp(); //CleanUp();
#if WINDOWS #if WINDOWS
if (_console != null) if (_console != null && !_console.KeepRunning)
{ {
//System.Diagnostics.Debugger.Break(); //System.Diagnostics.Debugger.Break();
ScreenManager.Game.Components.Remove(_console); ScreenManager.Game.Components.Remove(_console);

View File

@ -9,6 +9,7 @@ namespace Axios.Engine.Data
// A. This is not to cache textures loaded by content manager // A. This is not to cache textures loaded by content manager
// but other data/content that isn't. Use cases include: // but other data/content that isn't. Use cases include:
// - Any graphics generated during runtime (such as dialogs) // - Any graphics generated during runtime (such as dialogs)
// - Command console
// - Any data that is loaded in during run time (such as maps) // - Any data that is loaded in during run time (such as maps)
// Content manager performs it's own caching so anything loaded by it // Content manager performs it's own caching so anything loaded by it
// or the Gameservice - then attempted to load again will not be loaded // 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) public object get(string key)
{ {
return _cache[key]; object val;
_cache.TryGetValue(key, out val);
return val;
}
public T get<T>(string key)
{
object val;
_cache.TryGetValue(key, out val);
return (T)val;
} }
public void set(string key, object obj) public void set(string key, object obj)

View File

@ -17,5 +17,11 @@ namespace Axios.Engine.Extensions
pos.Y += ConvertUnits.ToSimUnits(prop.Height / 2); pos.Y += ConvertUnits.ToSimUnits(prop.Height / 2);
return pos; return pos;
} }
public static Vector2 getCenter(this RectangleItemProperties prop)
{
return prop.getSimPosition() / ConvertUnits.ToSimUnits(2);
}
} }
} }

View File

@ -19,5 +19,6 @@ namespace Axios.Engine.Extensions
{ {
return ConvertUnits.ToDisplayUnits(vec); return ConvertUnits.ToDisplayUnits(vec);
} }
} }
} }

View File

@ -9,6 +9,8 @@ namespace Axios.Engine.File
{ {
protected string _content; protected string _content;
protected bool disposed = false;
public String Content public String Content
{ {
get { return _content; } get { return _content; }

View File

@ -1,12 +1,13 @@
using System.IO; using System.IO;
using System.IO.IsolatedStorage; using System.IO.IsolatedStorage;
using Axios.Engine.Interfaces; using Axios.Engine.Interfaces;
using System;
namespace Axios.Engine.File namespace Axios.Engine.File
{ {
public class AxiosIsolatedFile : AxiosFile, IAxiosFile public class AxiosIsolatedFile : AxiosFile, IAxiosFile
{ {
protected IsolatedStorageFileStream _fs;
public AxiosIsolatedFile(string filename) public AxiosIsolatedFile(string filename)
{ {
this._filename = filename; this._filename = filename;
@ -58,9 +59,29 @@ namespace Axios.Engine.File
#else #else
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication(); IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
#endif #endif
IsolatedStorageFileStream fs = null; _fs = null;
fs = savegameStorage.OpenFile(_filename, mode); _fs = savegameStorage.OpenFile(_filename, mode);
return (Stream)fs; 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;
} }
} }

View File

@ -1,11 +1,13 @@
using System.IO; using System.IO;
using System;
using Axios.Engine.Interfaces; using Axios.Engine.Interfaces;
namespace Axios.Engine.File namespace Axios.Engine.File
{ {
public class AxiosRegularFile : AxiosFile, IAxiosFile public class AxiosRegularFile : AxiosFile, IAxiosFile, IDisposable
{ {
protected FileStream _fs;
public AxiosRegularFile(string file) public AxiosRegularFile(string file)
{ {
_filename = file; _filename = file;
@ -39,8 +41,29 @@ namespace Axios.Engine.File
public override Stream GetStream(FileMode mode) public override Stream GetStream(FileMode mode)
{ {
FileStream fs = new FileStream(_filename, mode); _fs = new FileStream(_filename, mode);
return (Stream)fs; 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;
} }
} }
} }

View File

@ -5,8 +5,9 @@ using Microsoft.Xna.Framework;
namespace Axios.Engine.File namespace Axios.Engine.File
{ {
public class AxiosTitleFile : AxiosFile, IAxiosFile public class AxiosTitleFile : AxiosFile, IAxiosFile, IDisposable
{ {
protected Stream _fs;
public AxiosTitleFile(string filename) public AxiosTitleFile(string filename)
{ {
//Title Files can only be opened for reading! //Title Files can only be opened for reading!
@ -30,7 +31,28 @@ namespace Axios.Engine.File
public override Stream GetStream(FileMode mode) 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;
} }
} }
} }

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Axios.Engine.Data;
using Axios.Engine.File;
namespace Axios.Engine.Log namespace Axios.Engine.Log
@ -13,24 +15,35 @@ namespace Axios.Engine.Log
WARN = 4, WARN = 4,
ERROR = 8, ERROR = 8,
FATAL = 16, FATAL = 16,
ALL = 32 ALL = ~0
} }
public class AxiosLog : Singleton<AxiosLog> public class AxiosLog : Singleton<AxiosLog>
{ {
private List<string> _log; private List<string> _log;
// Logs everything regardless of log level
// Used for debugging purposes
private List<string> _extendedlog;
public AxiosLog() public AxiosLog()
{ {
_log = new List<string>(); _log = new List<string>();
_extendedlog = new List<string>();
} }
public void AddLine(string line, LoggingFlag flag) 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); _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<string> GetLogList() public List<string> GetLogList()
{ {
return _log; return _log;
@ -45,5 +58,21 @@ namespace Axios.Engine.Log
{ {
return GetLog("\r\n"); 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);
}
}
} }
} }

View File

@ -247,6 +247,8 @@ namespace GameStateManagement
/// </summary> /// </summary>
public virtual void Unload() { } public virtual void Unload() { }
public virtual void ReActivate() { }
/// <summary> /// <summary>
/// Allows the screen to run logic, such as updating the transition position. /// Allows the screen to run logic, such as updating the transition position.

View File

@ -225,6 +225,8 @@ namespace GameStateManagement
// give it a chance to handle input. // give it a chance to handle input.
if (!otherScreenHasFocus) if (!otherScreenHasFocus)
{ {
// The default implementation of screens aren't aware that it's
// being woke up
input.ShowCursor = screen.HasCursor; input.ShowCursor = screen.HasCursor;
input.EnableVirtualStick = screen.HasVirtualStick; input.EnableVirtualStick = screen.HasVirtualStick;
screen.HandleInput(gameTime, input); screen.HandleInput(gameTime, input);

View File

@ -894,7 +894,7 @@ namespace XNACC.Console
{ {
m_linesBelow = true; m_linesBelow = true;
} }
for( int i = endLine; i > 0; i-- ) for( int i = endLine; i >= 0; i-- )
{ {
if( linePos.Y <= m_consoleRect.Top ) if( linePos.Y <= m_consoleRect.Top )
{ {