internal void readCacheFile() { string filename = Settings.Instance.game.shaderCacheFile; FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); ShaderCacheObject cacheObject; using (fileStream) { // Read the source file into a byte array. byte[] bytes = new byte[fileStream.Length]; int numBytesToRead = (int)fileStream.Length; int numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to numBytesToRead. int n = fileStream.Read(bytes, numBytesRead, numBytesToRead); // Break when the end of the file is reached. if (n == 0) { break; } numBytesRead += n; numBytesToRead -= n; } cacheObject = (ShaderCacheObject)GenericMethods.ByteArrayToObject(bytes); fileStream.Close(); } foreach (var shader in cacheObject.shaders) { Shader curShader = shader; string name = shader.name; if (!shaderNames.ContainsKey(shader.name)) { int identifier = shaders.Count; curShader.type = Shader.Type.fromCache; curShader.identifier = identifier; shaders.Add(curShader); shaderNames.Add(name, identifier); } } foreach (var newSnippet in cacheObject.snippets) { loadSnippetFromCache(newSnippet); } gameWindow.log("loaded " + cacheObject.shaders.Count + " shaders from cache"); gameWindow.log("loaded " + cacheObject.snippets.Count + " shader-snippets from cache"); }
internal void readCacheFile() { string filename = Settings.Instance.game.templateCacheFile; FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); List <Template> tmpTemplates; using (fileStream) { // Read the source file into a byte array. byte[] bytes = new byte[fileStream.Length]; int numBytesToRead = (int)fileStream.Length; int numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to numBytesToRead. int n = fileStream.Read(bytes, numBytesRead, numBytesToRead); // Break when the end of the file is reached. if (n == 0) { break; } numBytesRead += n; numBytesToRead -= n; } tmpTemplates = (List <Template>)GenericMethods.ByteArrayToObject(bytes); fileStream.Close(); } int templateCount = tmpTemplates.Count; for (int i = 0; i < templateCount; i++) { Template curTmp = tmpTemplates[i]; string name = curTmp.name; if (!templateNames.ContainsKey(name)) { curTmp.type = Template.Type.fromCache; int identifier = templates.Count; curTmp.identifier = identifier; curTmp.loaded = true; templateNames.Add(name, identifier); templates.Add(curTmp); } } gameWindow.log("loaded " + templateCount + " templates from cache"); }
public void readCacheFile() { string filename = Settings.Instance.game.materialCacheFile; FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); List <Material> tmpMaterials; using (fileStream) { // Read the source file into a byte array. byte[] bytes = new byte[fileStream.Length]; int numBytesToRead = (int)fileStream.Length; int numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to numBytesToRead. int n = fileStream.Read(bytes, numBytesRead, numBytesToRead); // Break when the end of the file is reached. if (n == 0) { break; } numBytesRead += n; numBytesToRead -= n; } tmpMaterials = (List <Material>)GenericMethods.ByteArrayToObject(bytes); fileStream.Close(); } int materialCount = tmpMaterials.Count; for (int i = 0; i < materialCount; i++) { Material curMat = tmpMaterials[i]; string name = curMat.name; if (!materialNames.ContainsKey(name)) { curMat.type = Material.Type.fromCache; int identifier = materials.Count; curMat.identifier = identifier; materialNames.Add(name, identifier); materials.Add(curMat); } } gameWindow.log("loaded " + materialCount + " materials from cache"); }
internal void readCacheFile() { string filename = Settings.Instance.game.textureCacheFile; FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); List <Texture> tmpTextures; using (fileStream) { // Read the source file into a byte array. byte[] bytes = new byte[fileStream.Length]; int numBytesToRead = (int)fileStream.Length; int numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to numBytesToRead. int n = fileStream.Read(bytes, numBytesRead, numBytesToRead); // Break when the end of the file is reached. if (n == 0) { break; } numBytesRead += n; numBytesToRead -= n; } tmpTextures = (List <Texture>)GenericMethods.ByteArrayToObject(bytes); fileStream.Close(); } foreach (var Texture in tmpTextures) { Texture curTex = Texture; string name = Texture.name; if (!textureNames.ContainsKey(name)) { int identifier = textures.Count; curTex.type = Texture.Type.fromDds; curTex.identifier = identifier; curTex.bitmap = curTex.CacheBitmap; textures.Add(curTex); textureNames.Add(name, identifier); } } }
public void readCacheFile() { string filename = Settings.Instance.game.modelCacheFile; FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); List <Mesh> tmpMeshes; using (fileStream) { // Read the source file into a byte array. byte[] bytes = new byte[fileStream.Length]; int numBytesToRead = (int)fileStream.Length; int numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to numBytesToRead. int n = fileStream.Read(bytes, numBytesRead, numBytesToRead); // Break when the end of the file is reached. if (n == 0) { break; } numBytesRead += n; numBytesToRead -= n; } tmpMeshes = (List <Mesh>)GenericMethods.ByteArrayToObject(bytes); fileStream.Close(); } int meshCount = tmpMeshes.Count; for (int i = 0; i < meshCount; i++) { Mesh curMesh = tmpMeshes[i]; string name = curMesh.name; if (!meshesNames.ContainsKey(name)) { if (curMesh.indicesVboData != null) { curMesh.type = Mesh.Type.fromCache; } else { curMesh.type = Mesh.Type.empty; curMesh.loaded = true; } int identifier = meshes.Count; curMesh.identifier = identifier; if (curMesh.animationData != null) { curMesh.curAnimationData = curMesh.animationData[0]; } meshesNames.Add(name, identifier); meshes.Add(curMesh); } } gameWindow.log("loaded " + meshCount + " meshes from cache"); }