summaryrefslogtreecommitdiff
path: root/common/chunk.lua
diff options
context:
space:
mode:
Diffstat (limited to 'common/chunk.lua')
-rw-r--r--common/chunk.lua15
1 files changed, 8 insertions, 7 deletions
diff --git a/common/chunk.lua b/common/chunk.lua
index 8e2ec40..1d3faa6 100644
--- a/common/chunk.lua
+++ b/common/chunk.lua
@@ -1,6 +1,7 @@
local json = require"common.dkjson"
+local class = require"common.class"
-local CHUNK_SIZE = 128
+local CHUNK_SIZE = 64
-- for now tiles shall be booleans
@@ -15,10 +16,9 @@ local function index(offq,offr)
return CHUNK_SIZE*offq + offr + 1
end
-local Chunk = {}
-Chunk.__index = Chunk
-function Chunk.make(tiles)
- return setmetatable({tiles=tiles},Chunk)
+local Chunk = class()
+function Chunk.make(cls,tiles)
+ return setmetatable({tiles=tiles},cls)
end
function Chunk.at(self,hoffs)
if not index_ok(hoffs.q,hoffs.r) then return nil end
@@ -35,11 +35,12 @@ end
function Chunk.from_packet_data(packet)
-- assuming packet has already been json.decoded
-- since otherwise how would we know it's a chunk packet
- return Chunk.make(packet.tiles)
+ return Chunk:make(packet.tiles)
end
return {
Chunk=Chunk,
SIZE=CHUNK_SIZE,
- index=index
+ index=index,
+ index_ok=index_ok,
}