summaryrefslogtreecommitdiff
path: root/common/map.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-06-18 22:28:37 +0100
committerubq323 <ubq323@ubq323.website>2023-06-18 22:28:37 +0100
commitf55c9f415a081a175e48b51db894f23e59ce47a2 (patch)
treeee63f98d5c4f1a2a11e9800ced9c2861eb3085a7 /common/map.lua
parent598bd4332deddd5f4c506689cbd136f495835ea7 (diff)
fix line lengths
Diffstat (limited to 'common/map.lua')
-rw-r--r--common/map.lua36
1 files changed, 23 insertions, 13 deletions
diff --git a/common/map.lua b/common/map.lua
index 67e2834..0437a12 100644
--- a/common/map.lua
+++ b/common/map.lua
@@ -1,15 +1,23 @@
-- a Map is a 2d array of chunks
-- it handles loading and unloading of chunks
--- each slot in the Map is either a Chunk object (if that chunk is loaded),
--- nil (if not loaded), or false (if 'loading'). on the client 'loading' means
--- the request for the chunk is currently in flight. on the server it might one day
--- mean that terrain generation for that chunk is currently in progress.
--- to test whether a chunk is loaded you can do if map:chunk(cp) then ... end
--- to test whether a chunk needs to be loaded you do if map:chunk(cp) == nil then ... end.
--- it will probably also do things relating to entities and multiblock things
-
--- note that the Map never creates any Chunks itself, which means it should be agnostic
--- to whatever actual Chunk class is being used (ChunkC or ChunkS or whatever)
+-- each slot in the Map is either a Chunk if that chunk is loaded,
+-- nil if not loaded, or false (if 'loading').
+-- on the client 'loading' means the request for the chunk is
+-- currently in flight.
+-- on the server it might one day mean that terrain generation
+-- for that chunk is currently in progress.
+--
+-- to test whether a chunk is loaded you can do
+-- if map:chunk(cp) then ... end
+-- to test whether a chunk needs to be loaded you do
+-- if map:chunk(cp) == nil then ... end
+--
+-- it will probably also do things relating to entities
+-- and multiblock things
+--
+-- note that the Map never creates any Chunks itself, which means
+-- it should be agnostic to whatever actual Chunk class is being used
+-- (ChunkC or ChunkS or whatever)
local class = require"common.class"
local coords = require"common.coords"
@@ -50,10 +58,12 @@ function Map.at(self,hpos)
-- returns tile at world coord hpos
-- if that tile's containing chunk isn't loaded, return nil
- -- not using the methods for doing this, in order to avoid lots of allocations
+ -- not using the methods for doing this, to avoid many allocations
-- inside the main drawing loop
- local cpu,cpv = math.floor(hpos.q/CHUNK_SIZE),math.floor(hpos.r/CHUNK_SIZE)
- local hoffq,hoffr = hpos.q-(cpu*CHUNK_SIZE), hpos.r-(cpv*CHUNK_SIZE)
+ local cpu = math.floor(hpos.q/CHUNK_SIZE)
+ local cpv = math.floor(hpos.r/CHUNK_SIZE)
+ local hoffq = hpos.q - (cpu*CHUNK_SIZE)
+ local hoffr = hpos.r - (cpv*CHUNK_SIZE)
local ch = self:_chunkuv(cpu,cpv)
if not ch then return nil end
return ch:_atqr(hoffq,hoffr)