refactor: Moved the servers to their separate directories
This commit is contained in:
parent
2f4303ddb8
commit
df2a128e1b
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
@ -1,4 +1,4 @@
|
|||||||
package storage
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -7,23 +7,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"git.nicholasnovak.io/nnovak/spatial-db/storage"
|
||||||
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
||||||
)
|
)
|
||||||
|
|
||||||
const fileCacheSize = 8
|
const fileCacheSize = 8
|
||||||
|
|
||||||
var (
|
|
||||||
ChunkNotFoundError = errors.New("chunk was not found in storage")
|
|
||||||
)
|
|
||||||
|
|
||||||
type SimpleServer struct {
|
type SimpleServer struct {
|
||||||
StorageDir string
|
StorageDir string
|
||||||
cache FileCache
|
cache storage.FileCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleServer) SetStorageRoot(path string) {
|
func (s *SimpleServer) SetStorageRoot(path string) {
|
||||||
s.StorageDir = path
|
s.StorageDir = path
|
||||||
s.cache = NewFileCache(256)
|
s.cache = storage.NewFileCache(256)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filesystem operations
|
// Filesystem operations
|
||||||
@ -56,7 +53,7 @@ func (s *SimpleServer) FetchOrCreateChunk(pos world.ChunkPos) (world.ChunkData,
|
|||||||
}
|
}
|
||||||
defer chunkFile.Close()
|
defer chunkFile.Close()
|
||||||
|
|
||||||
return ReadChunkFromFile(chunkFile)
|
return storage.ReadChunkFromFile(chunkFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// `FetchChunk' fetches the chunk's data, given the chunk's position
|
// `FetchChunk' fetches the chunk's data, given the chunk's position
|
||||||
@ -68,13 +65,13 @@ func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) {
|
|||||||
chunkFile, err := s.cache.FetchFile(chunkFileName)
|
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, ChunkNotFoundError
|
return chunkData, storage.ChunkNotFoundError
|
||||||
} else {
|
} else {
|
||||||
return chunkData, err
|
return chunkData, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReadChunkFromFile(chunkFile)
|
return storage.ReadChunkFromFile(chunkFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Voxel server implementation
|
// Voxel server implementation
|
@ -1,6 +1,10 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import "git.nicholasnovak.io/nnovak/spatial-db/world"
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
||||||
|
)
|
||||||
|
|
||||||
type StorageServer interface {
|
type StorageServer interface {
|
||||||
// Individual operations
|
// Individual operations
|
||||||
@ -16,3 +20,7 @@ type StorageServer interface {
|
|||||||
// Network-level operations
|
// Network-level operations
|
||||||
ReadChunkAt(pos world.ChunkPos) error
|
ReadChunkAt(pos world.ChunkPos) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ChunkNotFoundError = errors.New("chunk was not found in storage")
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user