feat: Moved over all of the servers to use unity files
This commit is contained in:
parent
07b676c571
commit
5ad8bd2407
@ -13,7 +13,13 @@ type HashServer struct {
|
|||||||
func (hs *HashServer) SetStorageRoot(path string) {
|
func (hs *HashServer) SetStorageRoot(path string) {
|
||||||
hs.blocks = make(map[world.BlockPos]world.BlockID)
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,13 @@ type InMemoryServer struct {
|
|||||||
func (s *InMemoryServer) SetStorageRoot(path string) {
|
func (s *InMemoryServer) SetStorageRoot(path string) {
|
||||||
s.StorageDir = path
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,18 @@ import (
|
|||||||
const fileCacheSize = 8
|
const fileCacheSize = 8
|
||||||
|
|
||||||
type SimpleServer struct {
|
type SimpleServer struct {
|
||||||
StorageDir string
|
StorageDir string
|
||||||
cache storage.FileCache
|
storageBackend storage.UnityFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleServer) SetStorageRoot(path string) {
|
func (s *SimpleServer) SetStorageRoot(path string) {
|
||||||
s.StorageDir = path
|
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
|
// 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
|
// `FetchChunk' fetches the chunk's data, given the chunk's position
|
||||||
func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) {
|
func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) {
|
||||||
chunkFileName := filepath.Join(s.StorageDir, pos.ToFileName())
|
chunkData, err := s.storageBackend.ReadChunk(pos)
|
||||||
|
|
||||||
var chunkData world.ChunkData
|
|
||||||
|
|
||||||
chunkFile, err := s.cache.FetchFile(chunkFileName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
return chunkData, storage.ChunkNotFoundError
|
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
|
// Voxel server implementation
|
||||||
|
Loading…
Reference in New Issue
Block a user