merged xnacc integration

This commit is contained in:
Nathan Adams 2012-05-26 23:23:22 -05:00
commit b828694e69
12 changed files with 3329 additions and 9 deletions

16
README
View File

@ -42,6 +42,10 @@ Authors
General questions/comments/concerns can be directed at: General questions/comments/concerns can be directed at:
Nathan Adams - adamsna[at]datanethost.net Nathan Adams - adamsna[at]datanethost.net
Contributors:
Bret Deasy
Copyright and License Information Copyright and License Information
--------------------------------- ---------------------------------
@ -51,4 +55,14 @@ Axios - See Axios License.txt
Farseer - See Farseer License.txt Farseer - See Farseer License.txt
Glee2D - See Glee2D License.txt http://farseerphysics.codeplex.com/
Glee2D - See Glee2D.License.txt
http://gleed2d.codeplex.com/
XNACC - See XNACC.License.txt
http://xnacc.codeplex.com/
Portions of this product are (C) 2009-2011 JRTwine Software, LLC

32
XNACC.License.txt Normal file
View File

@ -0,0 +1,32 @@
Microsoft Public License (Ms-PL)
Microsoft Public License (Ms-PL)
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

View File

@ -155,6 +155,7 @@
<Compile Include="Dynamics\TimeStep.cs" /> <Compile Include="Dynamics\TimeStep.cs" />
<Compile Include="Dynamics\World.cs" /> <Compile Include="Dynamics\World.cs" />
<Compile Include="Dynamics\WorldCallbacks.cs" /> <Compile Include="Dynamics\WorldCallbacks.cs" />
<Compile Include="Engine\AxiosCommandConsole.cs" />
<Compile Include="Engine\AxiosEvents.cs" /> <Compile Include="Engine\AxiosEvents.cs" />
<Compile Include="Engine\AxiosGameObject.cs" /> <Compile Include="Engine\AxiosGameObject.cs" />
<Compile Include="Engine\AxiosGameScreen.cs" /> <Compile Include="Engine\AxiosGameScreen.cs" />
@ -232,6 +233,8 @@
<Compile Include="ScreenSystem\VirtualButton.cs" /> <Compile Include="ScreenSystem\VirtualButton.cs" />
<Compile Include="ScreenSystem\VirtualStick.cs" /> <Compile Include="ScreenSystem\VirtualStick.cs" />
<Compile Include="Settings.cs" /> <Compile Include="Settings.cs" />
<Compile Include="XNACC\CommandConsoleBase.cs" />
<Compile Include="XNACC\CommandConsoleBaseSharedTypes.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.Phone, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e, processorArchitecture=MSIL" /> <Reference Include="Microsoft.Phone, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e, processorArchitecture=MSIL" />

View File

@ -98,6 +98,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Engine\AxiosBreakableGameObject.cs" /> <Compile Include="Engine\AxiosBreakableGameObject.cs" />
<Compile Include="Engine\AxiosCommandConsole.cs" />
<Compile Include="Engine\AxiosEvents.cs" /> <Compile Include="Engine\AxiosEvents.cs" />
<Compile Include="Axios_settings.cs" /> <Compile Include="Axios_settings.cs" />
<Compile Include="Collision\Collision.cs" /> <Compile Include="Collision\Collision.cs" />
@ -276,6 +277,8 @@
<Compile Include="ScreenSystem\VirtualButton.cs" /> <Compile Include="ScreenSystem\VirtualButton.cs" />
<Compile Include="ScreenSystem\VirtualStick.cs" /> <Compile Include="ScreenSystem\VirtualStick.cs" />
<Compile Include="Settings.cs" /> <Compile Include="Settings.cs" />
<Compile Include="XNACC\CommandConsoleBase.cs" />
<Compile Include="XNACC\CommandConsoleBaseSharedTypes.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="AxiosEngine.cd" /> <None Include="AxiosEngine.cd" />

View File

@ -149,6 +149,7 @@
<Compile Include="Dynamics\World.cs" /> <Compile Include="Dynamics\World.cs" />
<Compile Include="Dynamics\WorldCallbacks.cs" /> <Compile Include="Dynamics\WorldCallbacks.cs" />
<Compile Include="Engine\AxiosBreakableGameObject.cs" /> <Compile Include="Engine\AxiosBreakableGameObject.cs" />
<Compile Include="Engine\AxiosCommandConsole.cs" />
<Compile Include="Engine\AxiosEvents.cs" /> <Compile Include="Engine\AxiosEvents.cs" />
<Compile Include="Engine\AxiosGameObject.cs" /> <Compile Include="Engine\AxiosGameObject.cs" />
<Compile Include="Engine\AxiosGameScreen.cs" /> <Compile Include="Engine\AxiosGameScreen.cs" />
@ -224,6 +225,8 @@
<Compile Include="ScreenSystem\VirtualButton.cs" /> <Compile Include="ScreenSystem\VirtualButton.cs" />
<Compile Include="ScreenSystem\VirtualStick.cs" /> <Compile Include="ScreenSystem\VirtualStick.cs" />
<Compile Include="Settings.cs" /> <Compile Include="Settings.cs" />
<Compile Include="XNACC\CommandConsoleBase.cs" />
<Compile Include="XNACC\CommandConsoleBaseSharedTypes.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.Xna.Framework" /> <Reference Include="Microsoft.Xna.Framework" />

View File

@ -91,6 +91,8 @@
* - Fixing bug where loadrecentangleitem wouldn't be called by Gleed2D library * - Fixing bug where loadrecentangleitem wouldn't be called by Gleed2D library
* - Changing AxiosTitleFile.GetStream() to return Stream instead of FileStream * - Changing AxiosTitleFile.GetStream() to return Stream instead of FileStream
* - Changing IAxiosFile.GetStream() to return Stream instead of FileStream * - Changing IAxiosFile.GetStream() to return Stream instead of FileStream
* - Adding support for XNACC
* - Fixed a bug where cleanup actions were being performed in Deactivate instead of Unload in AxiosGameScreen
* *
*/ */
#endregion #endregion

View File

@ -0,0 +1,83 @@
#if WINDOWS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNACC.Console;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
/*
* The empty AxiosCommandConsole is so that when you use the comamnd console
* in your game you don't need #if WINDOWS/#endif precompiler - when you attempt
* to use it on WP7/Xbox 360 it just won't do anything.
*
* Perhaps one day we should develop a customized console that doesn't require keyboard input
* to still allow debugging on WP7/Xbox 360
* -- Nathan Adams [adamsna@datanethost.net] - 5/26/2012
*/
namespace Axios.Engine
{
public class AxiosCommandConsole : CommandConsoleBase
{
//private AxiosGameScreen _gameScreen;
public AxiosCommandConsole(AxiosGameScreen gameScreen)
: base(gameScreen.ScreenManager.Game)
{
//_gameScreen = gameScreen;
Keyboard = gameScreen.ScreenManager.InputState;
}
public AxiosCommandConsole(AxiosGameScreen gameScreen, SpriteFont font)
: base(gameScreen.ScreenManager.Game, font)
{
//_gameScreen = gameScreen;
Keyboard = gameScreen.ScreenManager.InputState;
}
protected void LoadDefault()
{
FadeColor = Color.White * 0.5f;
Texture2D tmp = new Texture2D(GraphicsDevice, 1, 1);
tmp.SetData<Color>(new Color[] { Color.Black });
FadeImage = tmp;
}
public override void LoadContent(ContentManager content)
{
base.LoadContent(content);
}
protected override void LoadContent()
{
if (Font == null)
Font = Game.Content.Load<SpriteFont>("Console");
base.LoadContent();
}
}
}
#else
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
namespace Axios.Engine
{
public class AxiosCommandConsole
{
public bool Active = false;
public AxiosCommandConsole(AxiosGameScreen gameScreen)
{
}
public AxiosCommandConsole(AxiosGameScreen gameScreen, SpriteFont font)
{
}
}
}
#endif

View File

@ -41,6 +41,16 @@ namespace Axios.Engine
private Camera camera; private Camera camera;
AxiosCommandConsole _console = null;
protected bool AllowKeyboardWhileConsoleIsActive = false;
public AxiosCommandConsole Console
{
get { return _console; }
private set { _console = value; }
}
public AxiosGameScreen() public AxiosGameScreen()
: base() : base()
{ {
@ -94,7 +104,23 @@ namespace Axios.Engine
public void AddGameObject(object obj) public void AddGameObject(object obj)
{ {
if (obj is AxiosCommandConsole)
{
if (_console != null)
{
//remove the current one first
#if WINDOWS
ScreenManager.Game.Components.Remove(_console);
_console.Dispose();
#endif
_console = null;
}
_console = (AxiosCommandConsole)obj;
#if WINDOWS
ScreenManager.Game.Components.Add(_console);
_console.LoadContent(ScreenManager.Game.Content);
#endif
}
if (obj is AxiosGameObject || obj is AxiosUIObject || obj is AxiosTimer) if (obj is AxiosGameObject || obj is AxiosUIObject || obj is AxiosTimer)
{ {
AxiosGameObject tmp = obj as AxiosGameObject; AxiosGameObject tmp = obj as AxiosGameObject;
@ -213,7 +239,7 @@ namespace Axios.Engine
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
{ {
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
if (this._objectstoremove.Count > 0) if (this._objectstoremove.Count > 0)
{ {
List<AxiosGameObject> list = this._objectstoremove.ToList<AxiosGameObject>(); List<AxiosGameObject> list = this._objectstoremove.ToList<AxiosGameObject>();
@ -362,17 +388,21 @@ namespace Axios.Engine
public override void HandleInput(GameTime gameTime, InputState input) public override void HandleInput(GameTime gameTime, InputState input)
{ {
base.HandleInput(gameTime, input); if ((AllowKeyboardWhileConsoleIsActive && _console.Active) || !_console.Active)
{
base.HandleInput(gameTime, input);
foreach (AxiosGameObject g in _gameObjects.ToList()) foreach (AxiosGameObject g in _gameObjects.ToList())
g.HandleInput(this, input, gameTime); g.HandleInput(this, input, gameTime);
foreach (AxiosUIObject g in _uiobjects.ToList()) foreach (AxiosUIObject g in _uiobjects.ToList())
g.HandleInput(this, input, gameTime); g.HandleInput(this, input, gameTime);
}
} }
public override void Deactivate() public override void Unload()
{ {
//System.Diagnostics.Debugger.Break();
base.Deactivate(); base.Deactivate();
AxiosLog.Instance.AddLine("Memory usage before cleanup: " + GC.GetTotalMemory(true).ToString(), LoggingFlag.DEBUG); AxiosLog.Instance.AddLine("Memory usage before cleanup: " + GC.GetTotalMemory(true).ToString(), LoggingFlag.DEBUG);
foreach (AxiosGameObject g in _gameObjects) foreach (AxiosGameObject g in _gameObjects)
@ -392,6 +422,13 @@ namespace Axios.Engine
//AxiosIsolatedFile f = new AxiosIsolatedFile("log.log"); //AxiosIsolatedFile f = new AxiosIsolatedFile("log.log");
//f.WriteData(AxiosLog.Instance.GetLog(), FileMode.Append); //f.WriteData(AxiosLog.Instance.GetLog(), FileMode.Append);
//CleanUp(); //CleanUp();
#if WINDOWS
if (_console != null)
{
ScreenManager.Game.Components.Remove(_console);
_console.Dispose();
}
#endif
} }

View File

@ -15,6 +15,11 @@ using Microsoft.Xna.Framework.Input.Touch;
using FarseerPhysics.SamplesFramework; using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
#if WINDOWS
using XNACC.BaseTypes;
#endif
using System.Linq;
namespace GameStateManagement namespace GameStateManagement
{ {
@ -37,8 +42,46 @@ namespace GameStateManagement
/// query methods for high level input actions such as "move up through the menu" /// query methods for high level input actions such as "move up through the menu"
/// or "pause the game". /// or "pause the game".
/// </summary> /// </summary>
#if WINDOWS
public class InputState : IConsoleKeyboard
#else
public class InputState public class InputState
#endif
{ {
#if WINDOWS
#region XNACC
/*
* These are needed for XNACC
* -- Nathan Adams [adamsna@datanethost.net] - 5/26/2012
*/
private KeyboardState KeyState;
private List<Keys> newlyPressedKeys = new List<Keys>();
private List<Keys> heldKeys = new List<Keys>();
private Keys[] oldPressedKeys;
private Keys[] newPressedKeys;
public KeyboardState CurrentKeyboardState
{
get { return KeyState; }
}
public IList<Keys> NewlyPressedKeys
{
get { return newlyPressedKeys; }
}
public IList<Keys> HeldKeys
{
get { return heldKeys; }
}
/*
* End XNACC variables
*/
#endregion
#endif
public const int MaxInputs = 4; public const int MaxInputs = 4;
public readonly KeyboardState[] CurrentKeyboardStates; public readonly KeyboardState[] CurrentKeyboardStates;
@ -270,6 +313,27 @@ namespace GameStateManagement
/// </summary> /// </summary>
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
{ {
#if WINDOWS
#region XNACC
KeyState = Keyboard.GetState();
oldPressedKeys = newPressedKeys;
newPressedKeys = KeyState.GetPressedKeys();
newlyPressedKeys.Clear();
heldKeys.Clear();
foreach (Keys key in newPressedKeys)
{
if (oldPressedKeys.Contains(key))
heldKeys.Add(key);
else
newlyPressedKeys.Add(key);
}
#endregion
#endif
//PlayerIndex p; //PlayerIndex p;
_lastMouseState = _currentMouseState; _lastMouseState = _currentMouseState;
if (_handleVirtualStick) if (_handleVirtualStick)

View File

@ -57,6 +57,11 @@ namespace GameStateManagement
#region Properties #region Properties
public InputState InputState
{
get { return input; }
private set { input = value; }
}
public SpriteFonts Fonts public SpriteFonts Fonts
{ {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
#if WINDOWS
/// <summary>Namespace that contains shared types related to the XNACC (CommandConsole) component</summary>
namespace XNACC.BaseTypes
{
#region IConsoleKeyboard
/// <summary>Basic keyboard/input functionality required by the CommandConsole(Base) class</summary>
public interface IConsoleKeyboard
{
/// <summary>The current state of the keyboard as of the last Update</summary>
KeyboardState CurrentKeyboardState
{
get;
}
/// <summary>Collection of keys that are newly pressed (i.e. not held) as of the last Update</summary>
IList<Keys> NewlyPressedKeys
{
get;
}
/// <summary>Collection of keys that are being held fown (i.e. not newly pressed) as of the last Update</summary>
IList<Keys> HeldKeys
{
get;
}
}
#endregion
#region CVar Object
// JRT: OK - Why Is This In Its Own File? Because Of The Way The Type System Works In .NET. If You Create
// JRT: Two Completely Identical Types, But Put Them In Different Assemblies, They Are Considered To Be
// JRT: Two Completely DIFFERENT Types, Even Though They Are Compatible With One Another. By Putting
// JRT: The CVar Class Into A Separate Assembly, Both The CommandConsole And External Functions
// JRT: Reference The Same Type, Allowing Us To Pass CVars Back And Forth.
/// <summary>Object that wraps the functionality of a console variable -- defined separately because external functions will receive CVar instances</summary>
public class CVar
{
/// <summary>The storage for the Name property</summary>
protected string m_name = String.Empty;
/// <summary>The storage for the Value property</summary>
protected object m_value = null;
/// <summary>The string name for this console variable</summary>
public string Name
{
get
{
return (m_name);
}
protected set
{
if (String.IsNullOrWhiteSpace(value))
{
throw new ArgumentNullException("The name for a console variable cannot be null, empty, or whitespace");
}
m_name = value;
}
}
/// <summary>The actual value for this console variable, as an object, or null</summary>
public object Value
{
get
{
return( m_value );
}
set
{
// Set Value. Set Type To Type.Missing If Value Is null
m_value = value;
if (value == null)
{
ValueType = (Type)Type.Missing;
}
else
{
ValueType = value.GetType();
}
}
}
/// <summary>The actual type of the contained variable, or Type.Missing for null values</summary>
public Type ValueType
{
get;
protected set;
}
/// <summary>Construct a console variable with a default value of null</summary>
/// <param name="name">The name for ths console variable</param>
public CVar(string name )
: this( name, null )
{
return;
}
/// <summary>Construct a console variable with the specified name and value</summary>
/// <param name="name">The name for ths console variable</param>
/// <param name="value">The value for this console variable</param>
public CVar(string name, object value)
{
Name = name;
Value = value;
return;
}
/// <summary>Get a string representation of the object (not round-trippable!)</summary>
/// <returns>A string representation of this CVar</returns>
public override string ToString()
{
return( String.Format( "{0} ({1}) = {2}", Name,
ValueType.ToString(),
Value.ToString() ) );
}
/// <summary>Hash code function - needed for the dictionary</summary>
/// <returns>The hash value of the Name of the cvar</returns>
override public int GetHashCode()
{
return(Name.GetHashCode() );
}
}
#endregion
}
#endif