Browse Source

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
master
Nathan Adams 7 years ago
parent
commit
01748bc5f8
  1. 4
      axios/Axios_settings.cs
  2. 8
      axios/Engine/AxiosCommandConsole.cs
  3. 16
      axios/Engine/AxiosGameScreen.cs
  4. 12
      axios/Engine/Data/Cache.cs
  5. 6
      axios/Engine/Extensions/RectangleItemProperties.cs
  6. 1
      axios/Engine/Extensions/Vector2.cs
  7. 2
      axios/Engine/File/AxiosFile.cs
  8. 29
      axios/Engine/File/AxiosIsolatedFile.cs
  9. 29
      axios/Engine/File/AxiosRegularFile.cs
  10. 26
      axios/Engine/File/AxiosTitleFile.cs
  11. 35
      axios/Engine/Log/AxiosLog.cs
  12. 2
      axios/ScreenSystem/GameScreen.cs
  13. 2
      axios/ScreenSystem/ScreenManager.cs
  14. 2
      axios/XNACC/CommandConsoleBase.cs

4
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

8
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<string> RestrictedCommands = new List<string>();
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();
}

16
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);

12
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<T>(string key)
{
object val;
_cache.TryGetValue(key, out val);
return (T)val;
}
public void set(string key, object obj)

6
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);
}
}
}

1
axios/Engine/Extensions/Vector2.cs

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

2
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; }

29
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;
}
}

29
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;
}
}
}

26
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;
}
}
}

35
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<AxiosLog>
{
private List<string> _log;
// Logs everything regardless of log level
// Used for debugging purposes
private List<string> _extendedlog;
public AxiosLog()
{
_log = new List<string>();
_extendedlog = new List<string>();
}
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<string> 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);
}
}
}
}

2
axios/ScreenSystem/GameScreen.cs

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

2
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);

2
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 )
{

Loading…
Cancel
Save