Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Include header in BYTES_PER_REGION

  • Loading branch information...
commit 9030961a7eee871dde1f09b8df083f385677314f 1 parent 7df7b48
Blixt authored
Showing with 11 additions and 7 deletions.
  1. +6 −6 lib/regionrenderer.js
  2. +5 −1 lib/worldrenderer.js
View
12 lib/regionrenderer.js
@@ -8,7 +8,7 @@ var TILES_PER_REGION = TILES_X * TILES_Y;
var HEADER_BYTES = 3;
var BYTES_PER_TILE = 23;
var BYTES_PER_ROW = BYTES_PER_TILE * TILES_X;
-var BYTES_PER_REGION = BYTES_PER_TILE * TILES_PER_REGION;
+var BYTES_PER_REGION = HEADER_BYTES + BYTES_PER_TILE * TILES_PER_REGION;
var TILE_WIDTH = 8;
var TILE_HEIGHT = 8;
@@ -153,9 +153,9 @@ RegionRenderer.prototype._renderTiles = function (renderer, context) {
this, HEADER_BYTES + BYTES_PER_ROW,
this, HEADER_BYTES + BYTES_PER_ROW + BYTES_PER_TILE,
null, null,
- this.neighbors[4], HEADER_BYTES + BYTES_PER_REGION - BYTES_PER_ROW + BYTES_PER_TILE,
- this.neighbors[4], HEADER_BYTES + BYTES_PER_REGION - BYTES_PER_ROW,
- this.neighbors[5], HEADER_BYTES + BYTES_PER_REGION - BYTES_PER_TILE,
+ this.neighbors[4], BYTES_PER_REGION - BYTES_PER_ROW + BYTES_PER_TILE,
+ this.neighbors[4], BYTES_PER_REGION - BYTES_PER_ROW,
+ this.neighbors[5], BYTES_PER_REGION - BYTES_PER_TILE,
null, null,
this.neighbors[6], HEADER_BYTES + BYTES_PER_ROW + BYTES_PER_ROW - BYTES_PER_TILE
];
@@ -192,7 +192,7 @@ RegionRenderer.prototype._renderTiles = function (renderer, context) {
} else if (x == 1) {
if (y == 0) {
neighbors[10] = this.neighbors[4];
- neighbors[11] = HEADER_BYTES + BYTES_PER_REGION - BYTES_PER_ROW;
+ neighbors[11] = BYTES_PER_REGION - BYTES_PER_ROW;
} else {
neighbors[10] = this;
neighbors[11] = offset - BYTES_PER_ROW - BYTES_PER_TILE;
@@ -222,7 +222,7 @@ RegionRenderer.prototype._renderTiles = function (renderer, context) {
if (y == 0) {
neighbors[6] = this.neighbors[3];
- neighbors[7] = HEADER_BYTES + BYTES_PER_REGION - BYTES_PER_ROW;
+ neighbors[7] = BYTES_PER_REGION - BYTES_PER_ROW;
} else {
neighbors[6] = this.neighbors[2];
neighbors[7] = offset - BYTES_PER_TILE;
View
6 lib/worldrenderer.js
@@ -10,7 +10,7 @@ var TILES_PER_REGION = TILES_X * TILES_Y;
var HEADER_BYTES = 3;
var BYTES_PER_TILE = 23;
var BYTES_PER_ROW = BYTES_PER_TILE * TILES_X;
-var BYTES_PER_REGION = BYTES_PER_TILE * TILES_PER_REGION;
+var BYTES_PER_REGION = HEADER_BYTES + BYTES_PER_TILE * TILES_PER_REGION;
var TILE_WIDTH = 8;
var TILE_HEIGHT = 8;
@@ -125,6 +125,10 @@ WorldRenderer.prototype.getRegion = function (regionX, regionY, opt_skipNeighbor
console.error(err.stack);
}
return;
+ } else if (regionData.buffer.byteLength != BYTES_PER_REGION) {
+ region.state = RegionRenderer.STATE_ERROR;
+ console.error('Corrupted region ' + regionX + ', ' + regionY);
+ return;
}
region.entities = regionData.entities;
Please sign in to comment.
Something went wrong with that request. Please try again.