Skip to content

Commit

Permalink
Fix improper chunks generation
Browse files Browse the repository at this point in the history
fixes #149

The issue was connected with internal chunks generation.
For maps with axis sizes less than a chunk size they were generated improperly.
  • Loading branch information
SpaiR committed May 26, 2022
1 parent dff7f1b commit 87b87fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v2.5.4.alpha

Fixed crashes when modifying maps with specific sizes. The issue was connected with internal chunks generation.<br>
For maps with axis sizes less than a chunk size they were generated improperly.

# v2.5.3.alpha

### Fixes
Expand All @@ -6,13 +11,11 @@

# v2.5.2.alpha

### Fixes
* Fixed "option" preference wrong options. @KIBORG04
Fixed "option" preference wrong options. @KIBORG04

# v2.5.1.alpha

### Fixes
* Keypad "enter" key didn't work. @igorsaux
Fixed keypad "enter" key didn't work. @igorsaux

# v2.5.0.alpha

Expand Down
13 changes: 9 additions & 4 deletions src/app/render/bucket/level/chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func generateChunks(maxX, maxY, iconSize int) map[util.Point]*chunk.Chunk {
// Variables below help to find start points for those areas.
var nextX, nextY int

createChunk := func(x1, y1, x2, y2 float32) *chunk.Chunk {
c := chunk.New(x1, y1, x2, y2, float32(iconSize))
nextX = int(c.MapBounds.X2) + 1
nextY = int(c.MapBounds.Y2) + 1
return c
}

generateAxis := func(x, xRange int) {
nextY = 0 // Reset for every new Y axis.
for y := 1; y <= maxY; y++ {
Expand All @@ -31,16 +38,14 @@ func generateChunks(maxX, maxY, iconSize int) map[util.Point]*chunk.Chunk {
if y%(chunk.Size+1) == 0 {
chunkCreated = true
x1, y1, x2, y2 := chunkBounds(x, y, xRange, chunk.Size)
c := chunk.New(x1, y1, x2, y2, float32(iconSize))
nextX = int(c.MapBounds.X2) + 1
nextY = int(c.MapBounds.Y2) + 1
c := createChunk(x1, y1, x2, y2)
chunks[util.Point{X: int(c.MapBounds.X1), Y: int(c.MapBounds.Y1)}] = c
}
}
if !chunkCreated {
chunkCreated = true
x1, y1, x2, y2 := chunkBounds(x, maxY, xRange, maxY-nextY)
c := chunk.New(x1, y1, x2, y2, float32(iconSize))
c := createChunk(x1, y1, x2, y2)
chunks[util.Point{X: int(c.MapBounds.X1), Y: int(c.MapBounds.Y1)}] = c
}
}
Expand Down

0 comments on commit 87b87fe

Please sign in to comment.