change: Fixed some tests and alternate implementations
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
package storage
|
||||
|
||||
import "git.nicholasnovak.io/nnovak/spatial-db/world"
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
||||
)
|
||||
|
||||
type HashServer struct {
|
||||
blocks map[world.BlockPos]world.BlockID
|
||||
@@ -8,6 +16,37 @@ type HashServer struct {
|
||||
|
||||
func (hs *HashServer) SetStorageRoot(path string) {
|
||||
hs.blocks = make(map[world.BlockPos]world.BlockID)
|
||||
|
||||
chunkFiles, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for chunkIndex, chunkFile := range chunkFiles {
|
||||
var data world.ChunkData
|
||||
|
||||
log.Infof("Reading in chunk %d of %d", chunkIndex, len(chunkFiles))
|
||||
|
||||
f, err := os.Open(filepath.Join(path, chunkFile.Name()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Read each file from disk
|
||||
if err := json.NewDecoder(f).Decode(&data); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Load in each data point from disk
|
||||
for _, section := range data.Sections {
|
||||
for blockIndex, blockState := range section.BlockStates {
|
||||
pos := data.IndexToBlockPos(blockIndex)
|
||||
hs.blocks[pos] = blockState
|
||||
}
|
||||
}
|
||||
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (hs *HashServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) {
|
||||
|
||||
Reference in New Issue
Block a user