using System;
using System.Collections.Generic;
using System.Text;
namespace ACE.Server.Entity
{
///
/// Maintains a single copy of each static mesh
///
public class StaticMeshCache
{
///
/// The static mesh cache
///
public static Dictionary Meshes;
///
/// Static constructor
///
static StaticMeshCache()
{
Meshes = new Dictionary();
}
///
/// Returns true if mesh is already cached
///
/// The model id
public static bool Contains(uint id)
{
return Meshes.ContainsKey(id);
}
///
/// Adds a static mesh to the cache
///
public static void Add(uint id, StaticMesh mesh)
{
Meshes.Add(id, mesh);
}
///
/// Performs a cache lookup,
/// adds a new static mesh if not found
///
/// The model id to fetch the static mesh for
public static StaticMesh GetMesh(uint id)
{
StaticMesh mesh = null;
Meshes.TryGetValue(id, out mesh);
if (mesh == null)
{
mesh = new StaticMesh(id);
Add(id, mesh);
}
return mesh;
}
// TODO: different caching strategies
// besides global cache
}
}