summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-15 23:55:58 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-15 23:55:58 +0200
commit82a18a1cc4d5c8b1a4c3d030e5d617000a858246 (patch)
tree5f1017bf21a6890217c9b33eb62f2cf5fe06da76
parent85fc1f809f616b0038b986114b468af6b3b3534b (diff)
downloadbiomed-82a18a1cc4d5c8b1a4c3d030e5d617000a858246.tar.gz
biomed-82a18a1cc4d5c8b1a4c3d030e5d617000a858246.tar.bz2
biomed-82a18a1cc4d5c8b1a4c3d030e5d617000a858246.zip
Preparing for tool usage
-rw-r--r--main.go6
-rw-r--r--mapwidget.go111
2 files changed, 90 insertions, 27 deletions
diff --git a/main.go b/main.go
index ba84bdc..04c2850 100644
--- a/main.go
+++ b/main.go
@@ -17,8 +17,6 @@ type GUI struct {
statusContext uint
mapw *MapWidget
-
- tool Tool
}
func (g *GUI) openWorldDlg() {
@@ -214,6 +212,8 @@ func (g *GUI) Init() {
g.window.SetDefaultSize(800, 600)
g.window.Connect("destroy", g.exitApp)
+
+ g.setTool(NewFillTool())
}
func (g *GUI) reportError(msg string) {
@@ -245,7 +245,7 @@ func (g *GUI) mkUpdateBiomeFx(rb *gtk.RadioButton, bio mcmap.Biome) func() {
}
func (g *GUI) setTool(t Tool) {
- g.tool = t
+ g.mapw.SetTool(t)
}
func (g *GUI) setBiome(bio mcmap.Biome) {
diff --git a/mapwidget.go b/mapwidget.go
index b3d8055..cb6d3e1 100644
--- a/mapwidget.go
+++ b/mapwidget.go
@@ -90,6 +90,8 @@ type MapWidget struct {
redraw chan bool
tileCmds chan tileCmd
+
+ tool Tool
}
var (
@@ -106,6 +108,10 @@ func (mw *MapWidget) SetShowBiomes(b bool) {
mw.redraw <- true
}
+func (mw *MapWidget) SetTool(t Tool) {
+ mw.tool = t
+}
+
func (mw *MapWidget) DArea() *gtk.DrawingArea { return mw.dArea }
func (mw *MapWidget) doTileCmds() {
@@ -157,31 +163,33 @@ func (mw *MapWidget) doTileCmds() {
}
}
- for z := startZ; z < endZ; z++ {
- scanX:
- for x := startX; x < endX; x++ {
- pos := XZPos{x, z}
-
- if _, ok := mw.biotiles[pos]; ok {
- continue scanX
+ if mw.region != nil {
+ for z := startZ; z < endZ; z++ {
+ scanX:
+ for x := startX; x < endX; x++ {
+ pos := XZPos{x, z}
+
+ if _, ok := mw.biotiles[pos]; ok {
+ continue scanX
+ }
+
+ chunk, err := mw.region.Chunk(x, z)
+ switch err {
+ case nil:
+ case mcmap.NotAvailable:
+ continue scanX
+ default:
+ mw.reportFail(fmt.Sprintf("Could not get chunk %d, %d: %s", x, z, err))
+ return
+ }
+
+ mw.maptiles[pos], mw.biotiles[pos], mw.bioCache[pos] = renderTile(chunk)
+ chunk.MarkUnused()
+
+ gdk.ThreadsLeave()
+ mw.redraw <- true
+ gdk.ThreadsEnter()
}
-
- chunk, err := mw.region.Chunk(x, z)
- switch err {
- case nil:
- case mcmap.NotAvailable:
- continue scanX
- default:
- mw.reportFail(fmt.Sprintf("Could not get chunk %d, %d: %s", x, z, err))
- return
- }
-
- mw.maptiles[pos], mw.biotiles[pos], mw.bioCache[pos] = renderTile(chunk)
- chunk.MarkUnused()
-
- gdk.ThreadsLeave()
- mw.redraw <- true
- gdk.ThreadsEnter()
}
}
@@ -340,6 +348,61 @@ func (mw *MapWidget) setRegion(region *mcmap.Region) {
mw.tileCmds <- cmdUpdateTiles
}
+func (mw *MapWidget) GetBiome(x, z int) (mcmap.Biome, bool) {
+ cx, cz, bx, bz := mcmap.BlockToChunk(x, z)
+ pos := XZPos{cx, cz}
+
+ if bc, ok := mw.bioCache[pos]; ok {
+ return bc[bz*mcmap.ChunkSizeXZ+bx], true
+ }
+
+ chunk, err := mw.region.Chunk(x, z)
+ switch err {
+ case nil:
+ case mcmap.NotAvailable:
+ return mcmap.BioUncalculated, false
+ default:
+ mw.reportFail(fmt.Sprintf("Error while getting chunk %d, %d: %s", cx, cz, err))
+ return mcmap.BioUncalculated, false
+ }
+ defer chunk.MarkUnused()
+
+ bc := make([]mcmap.Biome, mcmap.ChunkRectXZ)
+ i := 0
+ for z := 0; z < mcmap.ChunkSizeXZ; z++ {
+ for x := 0; x < mcmap.ChunkSizeXZ; x++ {
+ bc[i] = chunk.Biome(x, z)
+ i++
+ }
+ }
+ mw.bioCache[pos] = bc
+
+ return chunk.Biome(bx, bz), true
+}
+
+func (mw *MapWidget) SetBiome(x, z int, bio mcmap.Biome) {
+ cx, cz, bx, bz := mcmap.BlockToChunk(x, z)
+ pos := XZPos{cx, cz}
+
+ // Update cache
+ if bc, ok := mw.bioCache[pos]; ok {
+ bc[bz*mcmap.ChunkSizeXZ+bx] = bio
+ }
+
+ chunk, err := mw.region.Chunk(x, z)
+ switch err {
+ case nil:
+ case mcmap.NotAvailable:
+ return
+ default:
+ mw.reportFail(fmt.Sprintf("Error while getting chunk %d, %d: %s", cx, cz, err))
+ return
+ }
+ defer chunk.MarkUnused()
+
+ chunk.SetBiome(bx, bz, bio)
+}
+
func NewMapWidget(reportFail func(msg string), updateInfo func(x, z int, bio mcmap.Biome)) *MapWidget {
mw := &MapWidget{reportFail: reportFail, updateInfo: updateInfo}
mw.init()