mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Added a flag to decoded block to check if it contains any transparent colors. Useful to establish a fast path in transparent rendering if it does not.
This commit is contained in:
parent
1acfd26e80
commit
eaa3949b10
@ -43,12 +43,13 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
DecodedBlock struct {
|
DecodedBlock struct {
|
||||||
Version byte
|
Version byte
|
||||||
MapContent []byte
|
MapContent []byte
|
||||||
AirId int32
|
AirId int32
|
||||||
IgnoreId int32
|
IgnoreId int32
|
||||||
AirOnly bool
|
AirOnly bool
|
||||||
IndexMap map[int32]int32
|
Transparent bool
|
||||||
|
IndexMap map[int32]int32
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -138,6 +139,7 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
|
|||||||
airId, ignoreId := int32(-1), int32(-1)
|
airId, ignoreId := int32(-1), int32(-1)
|
||||||
indexMap := make(map[int32]int32)
|
indexMap := make(map[int32]int32)
|
||||||
var airOnly bool
|
var airOnly bool
|
||||||
|
var transparent bool
|
||||||
if version >= 22 {
|
if version >= 22 {
|
||||||
offset++
|
offset++
|
||||||
numMappings := int(binary.BigEndian.Uint16(data[offset:]))
|
numMappings := int(binary.BigEndian.Uint16(data[offset:]))
|
||||||
@ -157,6 +159,9 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
|
|||||||
default:
|
default:
|
||||||
if index, found := colors.NameIndex[name]; found {
|
if index, found := colors.NameIndex[name]; found {
|
||||||
indexMap[nodeId] = index
|
indexMap[nodeId] = index
|
||||||
|
if colors.IsTransparent(index) {
|
||||||
|
transparent = true
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Missing color entry for %s.", name)
|
log.Printf("Missing color entry for %s.", name)
|
||||||
}
|
}
|
||||||
@ -166,12 +171,13 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
db = &DecodedBlock{
|
db = &DecodedBlock{
|
||||||
Version: version,
|
Version: version,
|
||||||
MapContent: mapContent,
|
MapContent: mapContent,
|
||||||
AirId: airId,
|
AirId: airId,
|
||||||
IgnoreId: ignoreId,
|
IgnoreId: ignoreId,
|
||||||
AirOnly: airOnly,
|
AirOnly: airOnly,
|
||||||
IndexMap: indexMap}
|
Transparent: transparent,
|
||||||
|
IndexMap: indexMap}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Colors struct {
|
type Colors struct {
|
||||||
Colors []color.RGBA
|
Colors []color.RGBA
|
||||||
NameIndex map[string]int32
|
NameIndex map[string]int32
|
||||||
Transparent int
|
NumTransparent int32
|
||||||
}
|
}
|
||||||
|
|
||||||
type namedColor struct {
|
type namedColor struct {
|
||||||
@ -24,6 +24,10 @@ type namedColor struct {
|
|||||||
color color.RGBA
|
color color.RGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (colors *Colors) IsTransparent(index int32) bool {
|
||||||
|
return index < colors.NumTransparent
|
||||||
|
}
|
||||||
|
|
||||||
type sortByAlpha []namedColor
|
type sortByAlpha []namedColor
|
||||||
|
|
||||||
func (colors sortByAlpha) Less(i, j int) bool {
|
func (colors sortByAlpha) Less(i, j int) bool {
|
||||||
@ -70,14 +74,17 @@ func ParseColors(filename string) (colors *Colors, err error) {
|
|||||||
cs := make([]color.RGBA, len(cols))
|
cs := make([]color.RGBA, len(cols))
|
||||||
nameIndex := make(map[string]int32, len(cols))
|
nameIndex := make(map[string]int32, len(cols))
|
||||||
|
|
||||||
transparent := 0
|
numTransparent := int32(0)
|
||||||
for i, nc := range cols {
|
for i, nc := range cols {
|
||||||
if nc.color.A < 0xff {
|
if nc.color.A < 0xff {
|
||||||
transparent++
|
numTransparent++
|
||||||
}
|
}
|
||||||
cs[i] = nc.color
|
cs[i] = nc.color
|
||||||
nameIndex[nc.name] = int32(i)
|
nameIndex[nc.name] = int32(i)
|
||||||
}
|
}
|
||||||
colors = &Colors{Colors: cs, NameIndex: nameIndex, Transparent: transparent}
|
colors = &Colors{
|
||||||
|
Colors: cs,
|
||||||
|
NameIndex: nameIndex,
|
||||||
|
NumTransparent: numTransparent}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user