summaryrefslogtreecommitdiff
path: root/common/coords.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/coords.lua
parent3ad4d4da500a770e4f9cc7aa1bfe42588126a67c (diff)
clientside chunk unloading when not near. also refactor coordinate things slightly
Diffstat (limited to 'common/coords.lua')
-rw-r--r--common/coords.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/common/coords.lua b/common/coords.lua
index 111429a..49c2bf2 100644
--- a/common/coords.lua
+++ b/common/coords.lua
@@ -136,6 +136,21 @@ function ChunkPos.extents(self)
local brq,brr = (self.u+1)*CHUNK_SIZE -1, (self.v+1)*CHUNK_SIZE -1
return Hex:make(tlq,tlr), Hex:make(brq,brr)
end
+function ChunkPos.neighborhood(self)
+ -- return all chunkposes within the 3x3 square centered on self, including self
+ local out = {}
+ for du=-1,1 do
+ for dv = -1,1 do
+ table.insert(out,ChunkPos:make(du,dv) + self)
+ end
+ end
+ return out
+end
+function ChunkPos.orth_dist(self,other)
+ local du = math.abs(self.u-other.u)
+ local dv = math.abs(self.v-other.v)
+ return math.max(du,dv)
+end
function ChunkPos.filename(self)
-- filename of chunk with that cp
return "world/c_"..self.u.."_"..self.v..".dat"