Exposed cache size argument to BetaWorld

This commit is contained in:
Justin Aquadro 2011-11-05 15:12:48 -04:00
parent c10ee4215f
commit 3ee1bf753a
3 changed files with 41 additions and 4 deletions

View file

@ -30,8 +30,8 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.7.3.0")]
[assembly: AssemblyFileVersion("0.7.3.0")]
[assembly: AssemblyVersion("0.8.0.0")]
[assembly: AssemblyFileVersion("0.8.0.0")]
// This library is compatible with all CLS-compliant .NET programming languages.
[assembly: CLSCompliant(true)]

View file

@ -27,6 +27,8 @@ namespace Substrate
private PlayerManager _playerMan;
private int _prefCacheSize = 256;
private BetaWorld ()
{
_regionMgrs = new Dictionary<int, RegionManager>();
@ -149,6 +151,20 @@ namespace Substrate
return new BetaWorld().OpenWorld(path) as BetaWorld;
}
/// <summary>
/// Opens an existing Beta-compatible Minecraft world and returns a new <see cref="BetaWorld"/> to represent it.
/// </summary>
/// <param name="path">The path to the directory containing the world's level.dat, or the path to level.dat itself.</param>
/// <param name="cacheSize">The preferred cache size in chunks for each opened dimension in this world.</param>
/// <returns>A new <see cref="BetaWorld"/> object representing an existing world on disk.</returns>
public static new BetaWorld Open (string path, int cacheSize)
{
BetaWorld world = new BetaWorld().OpenWorld(path);
world._prefCacheSize = cacheSize;
return world;
}
/// <summary>
/// Creates a new Beta-compatible Minecraft world and returns a new <see cref="BetaWorld"/> to represent it.
/// </summary>
@ -161,6 +177,22 @@ namespace Substrate
return new BetaWorld().CreateWorld(path) as BetaWorld;
}
/// <summary>
/// Creates a new Beta-compatible Minecraft world and returns a new <see cref="BetaWorld"/> to represent it.
/// </summary>
/// <param name="path">The path to the directory where the new world should be stored.</param>
/// <param name="cacheSize">The preferred cache size in chunks for each opened dimension in this world.</param>
/// <returns>A new <see cref="BetaWorld"/> object representing a new world.</returns>
/// <remarks>This method will attempt to create the specified directory immediately if it does not exist, but will not
/// write out any world data unless it is explicitly saved at a later time.</remarks>
public static BetaWorld Create (string path, int cacheSize)
{
BetaWorld world = new BetaWorld().CreateWorld(path);
world._prefCacheSize = cacheSize;
return world;
}
/// <exclude/>
protected override IBlockManager GetBlockManagerVirt (int dim)
{
@ -213,7 +245,7 @@ namespace Substrate
Directory.CreateDirectory(path);
}
ChunkCache cc = new ChunkCache();
ChunkCache cc = new ChunkCache(_prefCacheSize);
RegionManager rm = new RegionManager(path, cc);
BetaChunkManager cm = new BetaChunkManager(rm, cc);

View file

@ -9,8 +9,13 @@ namespace Substrate.Core
private Dictionary<ChunkKey, ChunkRef> _dirty;
public ChunkCache ()
: this(256)
{
_cache = new LRUCache<ChunkKey, ChunkRef>(256);
}
public ChunkCache (int cacheSize)
{
_cache = new LRUCache<ChunkKey, ChunkRef>(cacheSize);
_dirty = new Dictionary<ChunkKey, ChunkRef>();
_cache.RemoveCacheValue += EvictionHandler;