mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
More colors. Store indices of colors in decoded blocks instead of strings.
This commit is contained in:
parent
73b6fa4fb9
commit
baee56b27b
@ -10,6 +10,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -26,7 +27,7 @@ type DecodedBlock struct {
|
||||
MapContent []byte
|
||||
AirId int
|
||||
IgnoreId int
|
||||
NameMap map[int]string
|
||||
IndexMap map[int]int
|
||||
}
|
||||
|
||||
type PosBuf struct {
|
||||
@ -34,7 +35,7 @@ type PosBuf struct {
|
||||
Pos int
|
||||
}
|
||||
|
||||
func NewDecodedBlock(data []byte) (db *DecodedBlock, err error) {
|
||||
func NewDecodedBlock(data []byte, nameIndex map[string]int) (db *DecodedBlock, err error) {
|
||||
version := data[0]
|
||||
|
||||
contentWidth := int(data[2])
|
||||
@ -106,7 +107,7 @@ func NewDecodedBlock(data []byte) (db *DecodedBlock, err error) {
|
||||
offset += 4
|
||||
|
||||
airId, ignoreId := -1, -1
|
||||
nameMap := make(map[int]string)
|
||||
indexMap := make(map[int]int)
|
||||
if version >= 22 {
|
||||
offset++
|
||||
numMappings := int(binary.BigEndian.Uint16(data[offset:]))
|
||||
@ -124,7 +125,11 @@ func NewDecodedBlock(data []byte) (db *DecodedBlock, err error) {
|
||||
case "ignore":
|
||||
ignoreId = nodeId
|
||||
default:
|
||||
nameMap[nodeId] = name
|
||||
if index, found := nameIndex[name]; found {
|
||||
indexMap[nodeId] = index
|
||||
} else {
|
||||
log.Printf("Missing color entry for %s.", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -134,7 +139,7 @@ func NewDecodedBlock(data []byte) (db *DecodedBlock, err error) {
|
||||
MapContent: mapContent,
|
||||
AirId: airId,
|
||||
IgnoreId: ignoreId,
|
||||
NameMap: nameMap}
|
||||
IndexMap: indexMap}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -12,7 +12,12 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ParseColors(filename string) (colors map[string]color.RGBA, err error) {
|
||||
type Colors struct {
|
||||
Colors []color.RGBA
|
||||
NameIndex map[string]int
|
||||
}
|
||||
|
||||
func ParseColors(filename string) (colors *Colors, err error) {
|
||||
|
||||
var file *os.File
|
||||
if file, err = os.Open(filename); err != nil {
|
||||
@ -20,7 +25,8 @@ func ParseColors(filename string) (colors map[string]color.RGBA, err error) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
colors = make(map[string]color.RGBA)
|
||||
nameIndex := make(map[string]int)
|
||||
cols := make([]color.RGBA, 0, 2200)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
@ -32,9 +38,12 @@ func ParseColors(filename string) (colors map[string]color.RGBA, err error) {
|
||||
var name string
|
||||
if n, _ := fmt.Sscanf(
|
||||
line, "%s %d %d %d %d", &name, &c.R, &c.G, &c.B, &c.A); n > 0 {
|
||||
colors[name] = c
|
||||
idx := len(cols)
|
||||
cols = append(cols, c)
|
||||
nameIndex[name] = idx
|
||||
}
|
||||
}
|
||||
err = scanner.Err()
|
||||
colors = &Colors{Colors: cols, NameIndex: nameIndex}
|
||||
return
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"bitbucket.org/s_l_teichmann/mtredisalize/common"
|
||||
@ -38,7 +37,7 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
var colors map[string]color.RGBA
|
||||
var colors *Colors
|
||||
|
||||
if colors, err = ParseColors(colorsfile); err != nil {
|
||||
log.Fatalf("Cannot open color file: %s", err)
|
||||
@ -70,7 +69,7 @@ func main() {
|
||||
count := func(block *common.Block) {
|
||||
numBlocks++
|
||||
bytesTotal += int64(len(block.Data))
|
||||
if db, err := NewDecodedBlock(block.Data); err == nil {
|
||||
if db, err := NewDecodedBlock(block.Data, colors.NameIndex); err == nil {
|
||||
versions[db.Version]++
|
||||
} else {
|
||||
log.Printf("WARN: Decoding block failed: %s", err)
|
||||
|
Loading…
Reference in New Issue
Block a user