summaryrefslogtreecommitdiff
path: root/common/map.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-06 12:19:58 +0000
committerubq323 <ubq323@ubq323.website>2023-02-06 12:19:58 +0000
commit0d86a5cf4b84e03af518d4b8dceb2385672032a8 (patch)
tree30778e8a2b380c6bd943303889d1c5243546a81e /common/map.lua
parent3ad4d4da500a770e4f9cc7aa1bfe42588126a67c (diff)
clientside chunk unloading when not near. also refactor coordinate things slightly
Diffstat (limited to 'common/map.lua')
-rw-r--r--common/map.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/map.lua b/common/map.lua
index 8161f11..64d353c 100644
--- a/common/map.lua
+++ b/common/map.lua
@@ -10,6 +10,7 @@
local class = require"common.class"
local chunk = require"common.chunk"
+local coords = require"common.coords"
local CHUNK_SIZE = require"common.constants".CHUNK_SIZE
local Map = class()
@@ -66,5 +67,20 @@ function Map.set_at(self,hpos,tile)
if not ch then return nil end
ch:set_at(hoffs,tile)
end
+function Map.iter_chunks(self)
+ -- iterates through all cp,chunk pairs
+ -- chunk might be false
+ -- not guaranteed to be in any particular order
+
+ return coroutine.wrap(function()
+ for u,t in pairs(self.chunks) do
+ for v,ch in pairs(t) do
+ -- if ch is false, won't have a .cp
+ local cp = coords.ChunkPos:make(u,v)
+ coroutine.yield(cp,ch)
+ end
+ end
+ end)
+end
return {Map=Map}