diff --git a/server/hashserver.go b/server/hashserver.go index f520875..9a916c1 100644 --- a/server/hashserver.go +++ b/server/hashserver.go @@ -13,7 +13,13 @@ type HashServer struct { func (hs *HashServer) SetStorageRoot(path string) { hs.blocks = make(map[world.BlockPos]world.BlockID) - chunks, err := storage.ReadParallelFromDirectory(path) + u, err := storage.OpenUnityFile(path, path+".metadata") + if err != nil { + panic(err) + } + defer u.Close() + + chunks, err := u.ReadAllChunks() if err != nil { panic(err) } diff --git a/server/inmemory_server.go b/server/inmemory_server.go index 5cb40f8..58619cb 100644 --- a/server/inmemory_server.go +++ b/server/inmemory_server.go @@ -18,7 +18,13 @@ type InMemoryServer struct { func (s *InMemoryServer) SetStorageRoot(path string) { s.StorageDir = path - chunks, err := storage.ReadParallelFromDirectory(s.StorageDir) + u, err := storage.OpenUnityFile(s.StorageDir, s.StorageDir+".metadata") + if err != nil { + panic(err) + } + defer u.Close() + + chunks, err := u.ReadAllChunks() if err != nil { panic(err) } diff --git a/server/simple_server.go b/server/simple_server.go index 62a2c83..ff5bc9f 100644 --- a/server/simple_server.go +++ b/server/simple_server.go @@ -14,13 +14,18 @@ import ( const fileCacheSize = 8 type SimpleServer struct { - StorageDir string - cache storage.FileCache + StorageDir string + storageBackend storage.UnityFile } func (s *SimpleServer) SetStorageRoot(path string) { s.StorageDir = path - s.cache = storage.NewFileCache(256) + + var err error + s.storageBackend, err = storage.OpenUnityFile(path, path+".metadata") + if err != nil { + panic(err) + } } // Filesystem operations @@ -58,11 +63,7 @@ func (s *SimpleServer) FetchOrCreateChunk(pos world.ChunkPos) (world.ChunkData, // `FetchChunk' fetches the chunk's data, given the chunk's position func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) { - chunkFileName := filepath.Join(s.StorageDir, pos.ToFileName()) - - var chunkData world.ChunkData - - chunkFile, err := s.cache.FetchFile(chunkFileName) + chunkData, err := s.storageBackend.ReadChunk(pos) if err != nil { if errors.Is(err, fs.ErrNotExist) { return chunkData, storage.ChunkNotFoundError @@ -71,7 +72,7 @@ func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) { } } - return storage.ReadChunkFromFile(chunkFile) + return chunkData, nil } // Voxel server implementation