Removing cache from Gleed2D as ContentManager automatically does this
Adding cache Adding XOR Shift random class
This commit is contained in:
parent
1a04355fde
commit
67ab74899f
@ -164,6 +164,7 @@
|
||||
<Compile Include="Engine\AxiosBreakableGameObject.cs" />
|
||||
<Compile Include="Engine\ComplexAxiosGameObject.cs" />
|
||||
<Compile Include="Engine\Data\AxiosCSV.cs" />
|
||||
<Compile Include="Engine\Data\Cache.cs" />
|
||||
<Compile Include="Engine\Data\DataEvents.cs" />
|
||||
<Compile Include="Engine\Data\AxiosDataTable.cs" />
|
||||
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
||||
@ -179,6 +180,7 @@
|
||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||
<Compile Include="Engine\GameServices.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||
|
@ -213,9 +213,11 @@
|
||||
<Compile Include="Dynamics\World.cs" />
|
||||
<Compile Include="Dynamics\WorldCallbacks.cs" />
|
||||
<Compile Include="Engine\AxiosGameObject.cs" />
|
||||
<Compile Include="Engine\AxiosRandom.cs" />
|
||||
<Compile Include="Engine\ComplexAxiosGameObject.cs" />
|
||||
<Compile Include="Engine\Data\AxiosCSV.cs" />
|
||||
<Compile Include="Engine\Data\AxiosDataTable.cs" />
|
||||
<Compile Include="Engine\Data\Cache.cs" />
|
||||
<Compile Include="Engine\Data\DataEvents.cs" />
|
||||
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
||||
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
||||
@ -230,6 +232,7 @@
|
||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||
<Compile Include="Engine\GameServices.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Item.cs" />
|
||||
<Compile Include="Engine\Gleed2D\PathItem.cs" />
|
||||
<Compile Include="Engine\Gleed2D\TextureItem.cs" />
|
||||
|
@ -158,6 +158,7 @@
|
||||
<Compile Include="Engine\ComplexAxiosGameObject.cs" />
|
||||
<Compile Include="Engine\Data\AxiosCSV.cs" />
|
||||
<Compile Include="Engine\Data\AxiosDataTable.cs" />
|
||||
<Compile Include="Engine\Data\Cache.cs" />
|
||||
<Compile Include="Engine\Data\DataEvents.cs" />
|
||||
<Compile Include="Engine\DrawableAxiosGameObject.cs" />
|
||||
<Compile Include="Engine\DrawableBreakableAxiosGameObject.cs" />
|
||||
@ -172,6 +173,7 @@
|
||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||
<Compile Include="Engine\GameServices.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||
|
@ -131,6 +131,9 @@
|
||||
*
|
||||
* 1.0.1.11 -
|
||||
* - Adding game services static class
|
||||
* - Removing cache from Gleed2D as ContentManager automatically does this
|
||||
* - Adding cache
|
||||
* - Adding XOR Shift random class
|
||||
*
|
||||
*/
|
||||
#endregion
|
||||
|
@ -78,8 +78,7 @@ namespace Axios.Engine
|
||||
this._uiobjects = new List<AxiosUIObject>();
|
||||
prevuiobj = null;
|
||||
prevuifocusobj = null;
|
||||
GameServices.AddService<GraphicsDevice>(this.ScreenManager.GraphicsDevice);
|
||||
GameServices.AddService<ContentManager>(this.ScreenManager.Game.Content);
|
||||
|
||||
}
|
||||
|
||||
public void LoadLevelFromStream(Stream s)
|
||||
@ -494,8 +493,10 @@ namespace Axios.Engine
|
||||
|
||||
public override void Unload()
|
||||
{
|
||||
//this.IsExiting = true;
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
base.Deactivate();
|
||||
ScreenState = GameStateManagement.ScreenState.TransitionOff;
|
||||
AxiosLog.Instance.AddLine("Memory usage before cleanup: " + GC.GetTotalMemory(true).ToString(), LoggingFlag.DEBUG);
|
||||
foreach (AxiosGameObject g in _gameObjects)
|
||||
g.UnloadContent(this);
|
||||
@ -523,6 +524,7 @@ namespace Axios.Engine
|
||||
_console = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -539,7 +541,7 @@ namespace Axios.Engine
|
||||
public virtual void LoadPathItem(PathItemProperties pathitem, Layer l)
|
||||
{
|
||||
PathItem p = new PathItem((PathItemProperties)pathitem);
|
||||
p.load(this, ref cache);
|
||||
p.load(this);
|
||||
PathItems[pathitem.Name] = p;
|
||||
}
|
||||
|
||||
@ -551,7 +553,7 @@ namespace Axios.Engine
|
||||
public virtual void LoadTextureItem(TextureItemProperties textureitem, Layer l)
|
||||
{
|
||||
TextureItem i = new TextureItem((TextureItemProperties)textureitem);
|
||||
i.load(this, ref cache);
|
||||
i.load(this);
|
||||
TextureItems[textureitem.Name] = i;
|
||||
}
|
||||
|
||||
|
53
axios/Engine/AxiosRandom.cs
Normal file
53
axios/Engine/AxiosRandom.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
// Implemenation of an XORShift
|
||||
// http://en.wikipedia.org/wiki/Xorshift
|
||||
// http://stackoverflow.com/questions/6275593/how-to-write-you-own-random-number-algorithm
|
||||
public class AxiosRandom
|
||||
{
|
||||
private static int x;
|
||||
private static int y;
|
||||
private static int z;
|
||||
private static int w;
|
||||
private static int t = 0;
|
||||
|
||||
public void init(int x, int y, int z, int w)
|
||||
{
|
||||
AxiosRandom.x = x;
|
||||
AxiosRandom.y = y;
|
||||
AxiosRandom.z = z;
|
||||
AxiosRandom.w = w;
|
||||
}
|
||||
|
||||
public static void init()
|
||||
{
|
||||
AxiosRandom.x = generateVector();
|
||||
AxiosRandom.y = generateVector();
|
||||
AxiosRandom.z = generateVector();
|
||||
AxiosRandom.w = generateVector();
|
||||
}
|
||||
|
||||
public static int next()
|
||||
{
|
||||
t = x ^ (x << 11);
|
||||
x = y; y = z; z = w;
|
||||
return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
|
||||
}
|
||||
|
||||
private static int generateVector()
|
||||
{
|
||||
int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int[] val = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
val[i] = x[GameServices.GetService<Random>().Next(x.Count() - 1)];
|
||||
return int.Parse(String.Join("", val));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
55
axios/Engine/Data/Cache.cs
Normal file
55
axios/Engine/Data/Cache.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Axios.Engine.Data
|
||||
{
|
||||
// Q. What is the point of this?
|
||||
// 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)
|
||||
// - 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
|
||||
// again but rather a reference to it will be returned
|
||||
// ************************************************
|
||||
// DANGER WILL ROBINSON DANGER
|
||||
// ************************************************
|
||||
// Only store stuff here that you want during the FULL lifecycle of your game
|
||||
// The cache is never cleared - so a reference will exist for the objects you leave
|
||||
// You MAY clear the cache by using the clear method or unset
|
||||
//
|
||||
// You probably don't want this
|
||||
// There is no cache...
|
||||
// This is not the cache you are looking for...
|
||||
//
|
||||
public class Cache : Singleton<Cache>
|
||||
{
|
||||
private Dictionary<string, object> _cache;
|
||||
public Cache()
|
||||
{
|
||||
_cache = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
public object get(string key)
|
||||
{
|
||||
return _cache[key];
|
||||
}
|
||||
|
||||
public void set(string key, object obj)
|
||||
{
|
||||
_cache[key] = obj;
|
||||
}
|
||||
|
||||
public void unset(string key)
|
||||
{
|
||||
_cache.Remove(key);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
_cache = new Dictionary<string, object>();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ namespace Axios.Engine
|
||||
public static class GameServices
|
||||
{
|
||||
private static GameServiceContainer container;
|
||||
private static object lockobj;
|
||||
private static object lockobj = new object();
|
||||
public static GameServiceContainer Instance
|
||||
{
|
||||
get
|
||||
|
@ -20,7 +20,7 @@ namespace Axios.Engine.Gleed2D
|
||||
/// Called by Level.FromFile(filename) on each Item after the deserialization process.
|
||||
/// Should be overriden and can be used to load anything needed by the Item (e.g. a texture).
|
||||
/// </summary>
|
||||
public virtual void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache)
|
||||
public virtual void load(AxiosGameScreen gameScreen)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ namespace Axios.Engine.Gleed2D
|
||||
this._item = i;
|
||||
}
|
||||
|
||||
public override void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache)
|
||||
public override void load(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.load(gameScreen, ref cache);
|
||||
base.load(gameScreen);
|
||||
|
||||
Vertices v = new Vertices(LayerItem.LocalPoints.Count);
|
||||
foreach (Vector2 vec in LayerItem.LocalPoints)
|
||||
|
@ -39,20 +39,20 @@ namespace Axios.Engine.Gleed2D
|
||||
/// You must provide your own implementation. However, you can rely on all public fields being
|
||||
/// filled by the level deserialization process.
|
||||
/// </summary>
|
||||
public override void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache)
|
||||
public override void load(AxiosGameScreen gameScreen)
|
||||
{
|
||||
base.load(gameScreen, ref cache);
|
||||
base.load(gameScreen);
|
||||
//throw new NotImplementedException();
|
||||
|
||||
//TODO: provide your own implementation of how a TextureItem loads its assets
|
||||
//for example:
|
||||
//this.texture = Texture2D.FromFile(<GraphicsDevice>, texture_filename);
|
||||
//or by using the Content Pipeline:
|
||||
if (!cache.ContainsKey(LayerItem.AssetName))
|
||||
/*if (!cache.ContainsKey(LayerItem.AssetName))
|
||||
{
|
||||
cache[LayerItem.AssetName] = gameScreen.ScreenManager.Game.Content.Load<Texture2D>(LayerItem.AssetName);
|
||||
}
|
||||
this.texture = cache[LayerItem.AssetName];
|
||||
}*/
|
||||
this.texture = gameScreen.ScreenManager.Game.Content.Load<Texture2D>(LayerItem.AssetName);
|
||||
//Visible = gameScreen.LoadTextureItem(this);
|
||||
|
||||
//this.texture = cm.Load<Texture2D>(asset_name);
|
||||
|
@ -98,7 +98,7 @@ namespace GameStateManagement
|
||||
|
||||
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||
{
|
||||
if (!coveredByOtherScreen && !otherScreenHasFocus)
|
||||
if (!coveredByOtherScreen && !otherScreenHasFocus && ScreenState != GameStateManagement.ScreenState.TransitionOff)
|
||||
{
|
||||
// variable time step but never less then 30 Hz
|
||||
if (UseSecondStep)
|
||||
|
@ -19,6 +19,7 @@ using System.IO;
|
||||
using System.IO.IsolatedStorage;
|
||||
using System.Xml.Linq;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using Axios.Engine;
|
||||
#endregion
|
||||
|
||||
namespace GameStateManagement
|
||||
@ -149,6 +150,18 @@ namespace GameStateManagement
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
font = content.Load<SpriteFont>("menufont");
|
||||
blankTexture = Game.Content.Load<Texture2D>("Materials/blank");
|
||||
GameServices.AddService<GraphicsDevice>(this.Game.GraphicsDevice);
|
||||
GameServices.AddService<ContentManager>(this.Game.Content);
|
||||
|
||||
// It is advised to use one instance of Random
|
||||
// because Random is seeded with the current time
|
||||
// initilizing random objects too quickly can cause
|
||||
// the impression of generating the same value
|
||||
// http://stackoverflow.com/questions/2727538/random-encounter-not-so-random
|
||||
GameServices.AddService<Random>(new Random());
|
||||
AxiosRandom.init();
|
||||
|
||||
|
||||
input.LoadContent();
|
||||
// Tell each of the screens to load their content.
|
||||
foreach (GameScreen screen in screens)
|
||||
|
Loading…
Reference in New Issue
Block a user