Skip to content

Commit

Permalink
Refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
quag committed Oct 2, 2011
1 parent 7f81309 commit 6ea7cb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/quag.geek.nz/mcobj/enclosedChunk.go
Original file line number Diff line number Diff line change
@@ -1,13 1,13 @@
package main

type EnclosingSides [4]IChunkSide
type EnclosingSides [4]ChunkSide
type EnclosedChunk struct {
xPos, zPos int
blocks Blocks
enclosing EnclosingSides
}

func (s *EnclosingSides) side(i int) IChunkSide {
func (s *EnclosingSides) side(i int) ChunkSide {
return (*s)[i]
}

Expand Down
10 changes: 5 additions & 5 deletions src/quag.geek.nz/mcobj/sideCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@ import (
)

type SideCache struct {
chunks map[uint64]*ChunkSides
chunks map[uint64]*ChunkSidesData
}

func (s *SideCache) Clear() {
Expand All @@ -18,7 18,7 @@ func (s *SideCache) AddChunk(chunk *nbt.Chunk) {
}

if s.chunks == nil {
s.chunks = make(map[uint64]*ChunkSides)
s.chunks = make(map[uint64]*ChunkSidesData)
}

s.chunks[s.key(chunk.XPos, chunk.ZPos)] = calculateSides(wrapBlockData(chunk.Blocks))
Expand Down Expand Up @@ -50,8 50,8 @@ func (s *SideCache) EncloseChunk(chunk *nbt.Chunk) *EnclosedChunk {
}
}

func calculateSides(blocks Blocks) *ChunkSides {
var sides = &ChunkSides{NewChunkSide(blocks.height), NewChunkSide(blocks.height), NewChunkSide(blocks.height), NewChunkSide(blocks.height)}
func calculateSides(blocks Blocks) *ChunkSidesData {
var sides = &ChunkSidesData{NewChunkSide(blocks.height), NewChunkSide(blocks.height), NewChunkSide(blocks.height), NewChunkSide(blocks.height)}
for i := 0; i < 16; i {
copy(sides[0].Column(i), blocks.Column(0, i))
copy(sides[1].Column(i), blocks.Column(15, i))
Expand All @@ -62,7 62,7 @@ func calculateSides(blocks Blocks) *ChunkSides {
return sides
}

func (s *SideCache) getSide(x, z int, side int) IChunkSide {
func (s *SideCache) getSide(x, z int, side int) ChunkSide {
if s.chunks == nil {
return defaultSide
}
Expand Down
18 changes: 9 additions & 9 deletions src/quag.geek.nz/mcobj/sides.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@ var (
defaultSide = solidSide
)

type IChunkSide interface {
type ChunkSide interface {
BlockId(x, y int) uint16
}

Expand All @@ -18,29 18,29 @@ func (s *FixedChunkSide) BlockId(x, y int) uint16 {
return s.blockId
}

func NewChunkSide(height int) *ChunkSide {
return &ChunkSide{make([]uint16, height*16)}
func NewChunkSide(height int) *ChunkSideData {
return &ChunkSideData{make([]uint16, height*16)}
}

type ChunkSide struct {
type ChunkSideData struct {
data []uint16
}

type ChunkSides [4]*ChunkSide
type ChunkSidesData [4]*ChunkSideData

func (s *ChunkSide) index(x, y int) int {
func (s *ChunkSideData) index(x, y int) int {
return y (x * s.height())
}

func (s *ChunkSide) BlockId(x, y int) uint16 {
func (s *ChunkSideData) BlockId(x, y int) uint16 {
return s.data[s.index(x, y)]
}

func (s *ChunkSide) Column(x int) BlockColumn {
func (s *ChunkSideData) Column(x int) BlockColumn {
var i = s.height() * x
return BlockColumn(s.data[i : i s.height()])
}

func (s *ChunkSide) height() int {
func (s *ChunkSideData) height() int {
return len(s.data) / 16
}

0 comments on commit 6ea7cb5

Please sign in to comment.