Beispiel #1
0
                public void Execute()
                {
                    var _path = StringToBytes.FromBytes(path.ToArray());

                    if (string.IsNullOrEmpty(_path))
                    {
                        return;
                    }

                    StreamReader reader = null;

                    try
                    {
                        rLOD0.CopyFrom(ReadGeomDataFromFile(FilePathForBuffer(_path, 0)));
                        rLOD1.CopyFrom(ReadGeomDataFromFile(FilePathForBuffer(_path, 1)));
                        rLOD2.CopyFrom(ReadGeomDataFromFile(FilePathForBuffer(_path, 2)));
                    } catch (Exception)

                    {
                    } finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
Beispiel #2
0
        public static void ReadAsync(IntVector3 chunkPos, Action <SerializedChunk> callback)
        {
            /*
             * if (!File.Exists(GetFileFullPath(chunkPos)))
             * {
             *  Debug.Log("No file at" + chunkPos);
             *  callback(null);
             *  return;
             * }
             */
            if (!Chunk.MetaData.SavedChunkExists(chunkPos))
            {
                callback(null);
                return;
            }

            GameObject jcbGO = new GameObject();

            SerializedDisplayBuffers.DeserJob dsbuffJob = default(SerializedDisplayBuffers.DeserJob);
            MapDisplay.LODBuffers             dbuffers  = null;
            try
            {
                Chunk.MetaData metaData = new Chunk.MetaData()
                {
                    Dirty = true
                };
                metaData = XMLOp.Deserialize <Chunk.MetaData>(GetMetaDataFullPath(chunkPos));

                if (metaData.isInvalid)
                {
                    Debug.Log("invalid meta data at: " + chunkPos);
                    callback(null);
                    return;
                }

                dsbuffJob = new SerializedDisplayBuffers.DeserJob();

                var all = Allocator.TempJob;
                dsbuffJob.path  = new NativeArray <byte>(StringToBytes.ToBytes(GetDBufferFullPath(chunkPos)), all);
                dsbuffJob.rLOD0 = new NativeArray <VoxelGeomDataMirror>(metaData.LODBufferLengths[0], all);
                dsbuffJob.rLOD1 = new NativeArray <VoxelGeomDataMirror>(metaData.LODBufferLengths[1], all);
                dsbuffJob.rLOD2 = new NativeArray <VoxelGeomDataMirror>(metaData.LODBufferLengths[2], all);

                var jcb = jcbGO.AddComponent <JobCall>();
                jcb.Schedule(dsbuffJob, () =>
                {
                    dbuffers    = new MapDisplay.LODBuffers();
                    dbuffers[0] = CVoxelMapFormat.BufferCountArgs.CreateBuffer(dsbuffJob.rLOD0);
                    dbuffers[1] = CVoxelMapFormat.BufferCountArgs.CreateBuffer(dsbuffJob.rLOD1);
                    dbuffers[2] = CVoxelMapFormat.BufferCountArgs.CreateBuffer(dsbuffJob.rLOD2);

                    dsbuffJob.DisposeNArrays();


                    uint[] voxelsFakeEmpty = new uint[1];
                    callback(new SerializedChunk(chunkPos, dbuffers, voxelsFakeEmpty, metaData));

                    /*
                     * FileStream chunkFile = File.Open(GetFileFullPath(chunkPos), FileMode.Open);
                     * //
                     * // Maybe read the full voxel array later, as needed
                     * //
                     * using (BinaryReader br = new BinaryReader(chunkFile))
                     * {
                     *  int pos = 0;
                     *  int length = (int)br.BaseStream.Length;
                     *  uint[] voxels = new uint[length / VoxelStorageSize];
                     *  while (pos * VoxelStorageSize < length)
                     *  {
                     *      voxels[pos++] = br.ReadUInt32();
                     *  }
                     *  callback(new SerializedChunk(chunkPos, dbuffers, voxels, metaData));
                     * }
                     */
                    GameObject.Destroy(jcbGO);
                });
            }
            catch (Exception e)
            {
                Debug.LogWarning("Excptn while reading: " + e.ToString());
                dsbuffJob.DisposeNArrays();
                if (dbuffers != null)
                {
                    dbuffers.release();
                }
                GameObject.Destroy(jcbGO);
                callback(null);
            }
        }