-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk.lua
41 lines (34 loc) · 977 Bytes
/
chunk.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
local base = require("base")
local chunk = setmetatable({}, {__index = base})
chunk.x = 0
chunk.chunkSize = 1000 -- Do not change after startup
chunk.spacing = 25 -- Do not change after startup
chunk.minimumVerticesPerChunk = chunk.chunkSize / chunk.spacing
chunk.halfDrawRange = 2
chunk.scale = 25
--[[ Callback ]]
function chunk:update(dt)
local chunk = self:getChunk(self.x)
local chunkIndex
for chunkIndex = chunk - self.halfDrawRange, chunk + self.halfDrawRange do
if chunkIndex > 0 then
if self[chunkIndex] ~= nil then
self:updateChunk(chunkIndex, dt)
else
self:generateChunk(chunkIndex, dt)
end
end
end
end
--[[ Utility ]]
function chunk:getX(chunk)
return (chunk - 1) * self.chunkSize
end
function chunk:getChunk(x)
return math.floor(x / (self.chunkSize)) + 1
end
function chunk:getChunkIndex(x, chunk)
return (x - self.chunkSize * (chunk - 1)) / self.spacing + 1
end
function chunk:updateChunk(dt) end
return chunk