Skip to content

Commit

Permalink
Refactor: type Blocks []uint16 -> type Blocks struct { []uint16 }
Browse files Browse the repository at this point in the history
  • Loading branch information
quag committed Oct 2, 2011
1 parent 6b1ae11 commit 796f463
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/quag.geek.nz/mcobj/mcobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 361,19 @@ func walkEnclosedChunks(pool mcworld.ChunkPool, opener mcworld.ChunkOpener, chun
return started
}

type Blocks []uint16
type Blocks struct {
data []uint16
}

type BlockColumn []uint16

func (b *Blocks) Get(x, y, z int) uint16 {
return (*b)[y (z*128 (x*128*16))]
return b.data[y (z*128 (x*128*16))]
}

func (b *Blocks) Column(x, z int) BlockColumn {
var i = 128 * (z x*16)
return BlockColumn((*b)[i : i 128])
return BlockColumn(b.data[i : i 128])
}

func zigzag(n int) int {
Expand Down
4 changes: 2 additions & 2 deletions src/quag.geek.nz/mcobj/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 498,7 @@ func (fs *Faces) processBlocks(enclosedChunk *EnclosedChunk) {
}
}

for i := 0; i < len(enclosedChunk.blocks); i = 128 {
for i := 0; i < len(enclosedChunk.blocks.data); i = 128 {
var x, z = (i / 128) / 16, (i / 128) % 16

var (
Expand All @@ -508,7 508,7 @@ func (fs *Faces) processBlocks(enclosedChunk *EnclosedChunk) {
r4 = new(blockRun)
)

var column = BlockColumn(enclosedChunk.blocks[i : i 128])
var column = BlockColumn(enclosedChunk.blocks.data[i : i 128])
for y, blockId := range column {
if y < yMin {
continue
Expand Down
4 changes: 2 additions & 2 deletions src/quag.geek.nz/mcobj/prt.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 59,10 @@ func (o *PrtGenerator) chunkProcessor() {

var e = job.enclosed

for i := 0; i < len(e.blocks); i = 128 {
for i := 0; i < len(e.blocks.data); i = 128 {
var x, z = (i / 128) / 16, (i / 128) % 16

var column = BlockColumn(e.blocks[i : i 128])
var column = BlockColumn(e.blocks.data[i : i 128])
for y, blockId := range column {
if y < yMin {
continue
Expand Down
8 changes: 6 additions & 2 deletions src/quag.geek.nz/mcobj/sideCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,11 @@ func (s *SideCache) AddChunk(chunk *nbt.Chunk) {
s.chunks = make(map[uint64]*ChunkSides)
}

s.chunks[s.key(chunk.XPos, chunk.ZPos)] = calculateSides(chunk.Blocks)
s.chunks[s.key(chunk.XPos, chunk.ZPos)] = calculateSides(wrapBlockData(chunk.Blocks))
}

func wrapBlockData(data []uint16) Blocks {
return Blocks{data}
}

func (s *SideCache) HasSide(x, z int) bool {
Expand All @@ -36,7 40,7 @@ func (s *SideCache) EncloseChunk(chunk *nbt.Chunk) *EnclosedChunk {
return &EnclosedChunk{
chunk.XPos,
chunk.ZPos,
chunk.Blocks,
wrapBlockData(chunk.Blocks),
EnclosingSides{
s.getSide(chunk.XPos-1, chunk.ZPos, 1),
s.getSide(chunk.XPos 1, chunk.ZPos, 0),
Expand Down

0 comments on commit 796f463

Please sign in to comment.