internal mapblock format

This commit is contained in:
NatureFreshMilk 2019-01-28 11:45:23 +01:00
parent 60d715d25f
commit 83b02384cd
5 changed files with 39 additions and 8 deletions

View File

@ -9,12 +9,18 @@ type MapBlock struct {
Size int `json:"size"`
Version byte `json:"version"`
Underground bool `json:"underground"`
Mapdata []byte `json:"mapdata"`
Mapdata *MapData `json:"mapdata"`
Metadata *Metadata `json:"metadata"`
BlockMapping map[int]string `json:"blockmapping"`
Mtime int64 `json:"mtime"`
}
type MapData struct {
ContentId []int `json:"contentid"`
Param1 []int `json:"param1"`
Param2 []int `json:"param2"`
}
type Metadata struct {
Inventories map[int]map[string]*Inventory `json:"inventories"`
Pairs map[int]map[string]string `json:"pairs"`
@ -37,7 +43,7 @@ func getNodePos(x, y, z int) int {
func (mb *MapBlock) GetNodeName(x, y, z int) string {
pos := getNodePos(x, y, z)
id := readU16(mb.Mapdata, pos*2)
id := mb.Mapdata.ContentId[pos]
return mb.BlockMapping[id]
}

View File

@ -30,7 +30,20 @@ func parseMapdata(mapblock *MapBlock, data []byte) (int, error) {
return 0, errors.New("Mapdata length invalid: " + strconv.Itoa(buf.Len()))
}
mapblock.Mapdata = buf.Bytes()
rawdata := buf.Bytes()
mapd := MapData{
ContentId: make([]int, 4096),
Param1: make([]int, 4096),
Param2: make([]int, 4096),
}
mapblock.Mapdata = &mapd
for i := 0; i < 4096; i++ {
mapd.ContentId[i] = readU16(rawdata, i*2)
mapd.Param1[i] = readU8(rawdata, (i*2)+2)
mapd.Param2[i] = readU8(rawdata, (i*2)+3) //TODO: last item has wrong value
}
return cr.Count, nil
}

View File

@ -25,6 +25,10 @@ func readU16(data []byte, offset int) int {
return (int(data[offset]) << 8) | int(data[offset+1])
}
func readU8(data []byte, offset int) int {
return int(data[offset])
}
func readU32(data []byte, offset int) int {
return int(data[offset])<<24 |
int(data[offset+1])<<16 |

View File

@ -136,7 +136,9 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
if x > 0 {
//same mapblock
left = mb.GetNodeName(x-1, y, z)
leftAbove = mb.GetNodeName(x-1, y+1, z)
if y < 15 {
leftAbove = mb.GetNodeName(x-1, y+1, z)
}
} else {
//neighbouring mapblock
@ -145,14 +147,18 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
if neighbourMapblock != nil && err == nil {
left = neighbourMapblock.GetNodeName(15, y, z)
leftAbove = neighbourMapblock.GetNodeName(15, y+1, z)
if y < 15 {
leftAbove = neighbourMapblock.GetNodeName(15, y+1, z)
}
}
}
if z < 14 {
//same mapblock
top = mb.GetNodeName(x, y, z+1)
topAbove = mb.GetNodeName(x, y+1, z+1)
if y < 15 {
topAbove = mb.GetNodeName(x, y+1, z+1)
}
} else {
//neighbouring mapblock
@ -161,7 +167,9 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
if neighbourMapblock != nil && err == nil {
top = neighbourMapblock.GetNodeName(x, y, 0)
topAbove = neighbourMapblock.GetNodeName(x, y+1, z+0)
if y < 15 {
topAbove = neighbourMapblock.GetNodeName(x, y+1, z+0)
}
}
}

View File

@ -1,10 +1,10 @@
package web
import (
"encoding/json"
"mapserver/app"
"mapserver/coords"
"mapserver/mapobjectdb"
"encoding/json"
"net/http"
"strconv"
"strings"