private void StoreToFileCache(AMeshKey key, Mesh mesh) { Stream stream = null; bool ok = false; // Make sure the target cache directory exists string dir = String.Empty; string filename = String.Empty; FileNames(key, out dir, out filename); lock (diskLock) { try { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } stream = File.Open(filename, FileMode.Create); ok = mesh.ToStream(stream); } catch (IOException e) { m_log.ErrorFormat( "[MESH CACHE]: Failed to write file {0}. Exception {1} {2}.", filename, e.Message, e.StackTrace); ok = false; } if (stream != null) stream.Close(); if (File.Exists(filename)) { if (ok) File.SetLastAccessTimeUtc(filename, DateTime.UtcNow); else File.Delete(filename); } } }
private Mesh GetFromFileCache(AMeshKey key) { Mesh mesh = null; string filename = FullFileName(key); bool ok = true; lock (diskLock) { if (File.Exists(filename)) { FileStream stream = null; try { stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryFormatter bformatter = new BinaryFormatter(); mesh = Mesh.FromStream(stream, key); } catch (Exception e) { ok = false; m_log.ErrorFormat( "[MESH CACHE]: Failed to get file {0}. Exception {1} {2}", filename, e.Message, e.StackTrace); } if (stream != null) stream.Close(); if (mesh == null || !ok) File.Delete(filename); else File.SetLastAccessTimeUtc(filename, DateTime.UtcNow); } } return mesh; }
public void FileNames(AMeshKey key, out string dir,out string fullFileName) { string id = key.ToString(); string init = id.Substring(0, 1); dir = System.IO.Path.Combine(cachePath, init); fullFileName = System.IO.Path.Combine(dir, id); }
public string FullFileName(AMeshKey key) { string id = key.ToString(); string init = id.Substring(0,1); id = System.IO.Path.Combine(init, id); id = System.IO.Path.Combine(cachePath, id); return id; }
public AMeshKey GetMeshUniqueKey(PrimitiveBaseShape primShape, Vector3 size, byte lod, bool convex) { AMeshKey key = new AMeshKey(); Byte[] someBytes; key.hashB = 5181; key.hashC = 5181; ulong hash = 5381; if (primShape.SculptEntry) { key.uuid = primShape.SculptTexture; key.hashC = mdjb2(key.hashC, primShape.SculptType); key.hashC = mdjb2(key.hashC, primShape.PCode); } else { hash = mdjb2(hash, primShape.PathCurve); hash = mdjb2(hash, (byte)primShape.HollowShape); hash = mdjb2(hash, (byte)primShape.ProfileShape); hash = mdjb2(hash, primShape.PathBegin); hash = mdjb2(hash, primShape.PathEnd); hash = mdjb2(hash, primShape.PathScaleX); hash = mdjb2(hash, primShape.PathScaleY); hash = mdjb2(hash, primShape.PathShearX); key.hashA = hash; hash = key.hashB; hash = mdjb2(hash, primShape.PathShearY); hash = mdjb2(hash, (byte)primShape.PathTwist); hash = mdjb2(hash, (byte)primShape.PathTwistBegin); hash = mdjb2(hash, (byte)primShape.PathRadiusOffset); hash = mdjb2(hash, (byte)primShape.PathTaperX); hash = mdjb2(hash, (byte)primShape.PathTaperY); hash = mdjb2(hash, primShape.PathRevolutions); hash = mdjb2(hash, (byte)primShape.PathSkew); hash = mdjb2(hash, primShape.ProfileBegin); hash = mdjb2(hash, primShape.ProfileEnd); hash = mdjb2(hash, primShape.ProfileHollow); hash = mdjb2(hash, primShape.PCode); key.hashB = hash; } hash = key.hashC; hash = mdjb2(hash, lod); if (size == m_MeshUnitSize) { hash = hash << 8; hash |= 8; } else { someBytes = size.GetBytes(); for (int i = 0; i < someBytes.Length; i++) hash = mdjb2(hash, someBytes[i]); hash = hash << 8; } if (convex) hash |= 4; if (primShape.SculptEntry) { hash |= 1; if (primShape.SculptType == (byte)SculptType.Mesh) hash |= 2; } key.hashC = hash; return key; }