1
0
forked from MTSR/mapserver

param2 coloring cleanup

This commit is contained in:
NatureFreshMilk 2019-06-20 07:14:14 +02:00
parent 2b706f0fe7
commit 5a7c8d602d
7 changed files with 27 additions and 36 deletions

View File

@ -14,7 +14,6 @@ import (
"mapserver/settings" "mapserver/settings"
"mapserver/tiledb" "mapserver/tiledb"
"mapserver/tilerenderer" "mapserver/tilerenderer"
"mapserver/vfs"
"mapserver/worldconfig" "mapserver/worldconfig"
"time" "time"
@ -106,14 +105,8 @@ func Setup(p params.ParamsType, cfg *Config) *App {
} }
fullpalette, err := colormapping.NewPalette(vfs.FSMustByte(false, "/pics/unifieddyes_palette_extended.png"))
if err != nil {
panic(err)
}
//mapblock renderer //mapblock renderer
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping, fullpalette) a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping)
//mapserver database //mapserver database
if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" { if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" {

View File

@ -14,9 +14,16 @@ import (
type ColorMapping struct { type ColorMapping struct {
colors map[string]*color.RGBA colors map[string]*color.RGBA
extendedpalette *Palette
}
func (m *ColorMapping) GetColor(name string, param2 int) *color.RGBA {
//TODO: list of node->palette
if name == "unifiedbricks:brickblock" {
// param2 coloring
return m.extendedpalette.GetColor(param2)
} }
func (m *ColorMapping) GetColor(name string) *color.RGBA {
return m.colors[name] return m.colors[name]
} }
@ -95,5 +102,14 @@ func (m *ColorMapping) LoadVFSColors(useLocal bool, filename string) (int, error
} }
func NewColorMapping() *ColorMapping { func NewColorMapping() *ColorMapping {
return &ColorMapping{colors: make(map[string]*color.RGBA)} extendedpalette, err := NewPalette(vfs.FSMustByte(false, "/pics/unifieddyes_palette_extended.png"))
if err != nil {
panic(err)
}
return &ColorMapping{
colors: make(map[string]*color.RGBA),
extendedpalette: extendedpalette,
}
} }

View File

@ -11,12 +11,12 @@ func TestNewMapping(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
c := m.GetColor("scifi_nodes:blacktile2") c := m.GetColor("scifi_nodes:blacktile2", 0)
if c == nil { if c == nil {
panic("no color") panic("no color")
} }
c = m.GetColor("default:river_water_flowing") c = m.GetColor("default:river_water_flowing", 0)
if c == nil { if c == nil {
panic("no color") panic("no color")
} }

View File

@ -17,16 +17,14 @@ import (
type MapBlockRenderer struct { type MapBlockRenderer struct {
accessor *mapblockaccessor.MapBlockAccessor accessor *mapblockaccessor.MapBlockAccessor
colors *colormapping.ColorMapping colors *colormapping.ColorMapping
fullpalette *colormapping.Palette
enableShadow bool enableShadow bool
enableTransparency bool enableTransparency bool
} }
func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping, fullpalette *colormapping.Palette) *MapBlockRenderer { func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping) *MapBlockRenderer {
return &MapBlockRenderer{ return &MapBlockRenderer{
accessor: accessor, accessor: accessor,
colors: colors, colors: colors,
fullpalette: fullpalette,
enableShadow: true, enableShadow: true,
enableTransparency: false, enableTransparency: false,
} }
@ -132,18 +130,13 @@ func (r *MapBlockRenderer) Render(pos1, pos2 *coords.MapBlockCoords) (*image.NRG
} }
nodeName := mb.GetNodeName(x, y, z) nodeName := mb.GetNodeName(x, y, z)
param2 := mb.GetParam2(x, y, z)
if nodeName == "" { if nodeName == "" {
continue continue
} }
c := r.colors.GetColor(nodeName) c := r.colors.GetColor(nodeName, param2)
hasfullpalette := nodeName == "unifiedbricks:brickblock"
if hasfullpalette && r.fullpalette != nil {
param2 := mb.GetParam2(x, y, z)
c = r.fullpalette.GetColor(param2)
}
if c == nil { if c == nil {
continue continue

View File

@ -52,18 +52,7 @@ func TestSimpleRender(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
palettedata, err := ioutil.ReadFile("./testdata/unifieddyes_palette_extended.png") r := NewMapBlockRenderer(cache, c)
if err != nil {
t.Fatal(err)
}
palette, err := colormapping.NewPalette(palettedata)
if err != nil {
t.Fatal(err)
}
r := NewMapBlockRenderer(cache, c, palette)
os.Mkdir("../test-output", 0755) os.Mkdir("../test-output", 0755)
results := make(chan JobResult, 100) results := make(chan JobResult, 100)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 B

View File

@ -46,7 +46,7 @@ func TestTileRender(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
r := mapblockrenderer.NewMapBlockRenderer(cache, c, nil) r := mapblockrenderer.NewMapBlockRenderer(cache, c)
tiletmpdir, err := ioutil.TempDir("", "TestTileRenderTiles.*.sqlite") tiletmpdir, err := ioutil.TempDir("", "TestTileRenderTiles.*.sqlite")
defer os.RemoveAll(tiletmpdir) defer os.RemoveAll(tiletmpdir)