Fix up the concept of "None" tiles and objects

Replace with "Unknown" which is effectively an invalid value
This commit is contained in:
Marc Di Luzio 2020-07-19 12:33:11 +01:00
parent 305f64ec38
commit 7bdfa44fb6
10 changed files with 72 additions and 87 deletions

View file

@ -10,8 +10,6 @@ import (
// TileGlyph returns the glyph for this tile type
func TileGlyph(t roveapi.Tile) Glyph {
switch t {
case roveapi.Tile_TileNone:
return GlyphNone
case roveapi.Tile_Rock:
return GlyphGroundRock
case roveapi.Tile_Gravel:
@ -21,7 +19,7 @@ func TileGlyph(t roveapi.Tile) Glyph {
}
log.Fatalf("Unknown tile type: %c", t)
return GlyphNone
return 0
}
// Atlas represents a 2D world atlas of tiles and objects

View file

@ -260,12 +260,10 @@ func TestAtlas_WorldGen(t *testing.T) {
for j := num - 1; j >= 0; j-- {
for i := 0; i < num; i++ {
t, o := a.QueryPosition(maths.Vector{X: i, Y: j})
if o.Type != roveapi.Object_ObjectNone {
if o.Type != roveapi.Object_ObjectUnknown {
fmt.Printf("%c", ObjectGlyph(o.Type))
} else if t != roveapi.Tile_TileNone {
fmt.Printf("%c", TileGlyph(t))
} else {
fmt.Printf(" ")
fmt.Printf("%c", TileGlyph(t))
}
}

View file

@ -121,14 +121,14 @@ func (a *chunkBasedAtlas) populate(chunk int) {
// Get the object noise value for this location
o := a.objectNoise.Eval2(float64(origin.X+i)/objectNoiseScale, float64(origin.Y+j)/objectNoiseScale)
var obj = roveapi.Object_ObjectNone
var obj = roveapi.Object_ObjectUnknown
switch {
case o > 0.6:
obj = roveapi.Object_RockLarge
case o > 0.5:
obj = roveapi.Object_RockSmall
}
if obj != roveapi.Object_ObjectNone {
if obj != roveapi.Object_ObjectUnknown {
c.Objects[j*a.ChunkSize+i] = Object{Type: roveapi.Object(obj)}
}
}
@ -160,7 +160,7 @@ func (a *chunkBasedAtlas) setObject(chunk int, local maths.Vector, object Object
c := a.Chunks[chunk]
i := a.chunkTileIndex(local)
if object.Type != roveapi.Object_ObjectNone {
if object.Type != roveapi.Object_ObjectUnknown {
c.Objects[i] = object
} else {
delete(c.Objects, i)

View file

@ -4,9 +4,6 @@ package atlas
type Glyph byte
const (
// GlyphNone is a keyword for nothing
GlyphNone = Glyph(0)
// GlyphGroundRock is solid rock ground
GlyphGroundRock = Glyph('-')

View file

@ -9,8 +9,6 @@ import (
// ObjectGlyph returns the glyph for this object type
func ObjectGlyph(o roveapi.Object) Glyph {
switch o {
case roveapi.Object_ObjectNone:
return GlyphNone
case roveapi.Object_RoverLive:
return GlyphRoverLive
case roveapi.Object_RockSmall:
@ -20,7 +18,7 @@ func ObjectGlyph(o roveapi.Object) Glyph {
}
log.Fatalf("Unknown object type: %c", o)
return GlyphNone
return 0
}
// Object represents an object in the world