diff options
author | ubq323 <ubq323@ubq323.website> | 2023-01-29 02:59:50 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-01-29 02:59:50 +0000 |
commit | ebe12a65c07bccfbc704667c88d8125be33067cf (patch) | |
tree | 9c1ef457ce0da96b4d5dbe77cd56625f53b4ba89 /client/drawing.lua | |
parent | 9b659149c7273a57a82c9be988a8a78c62bb23f4 (diff) |
camera stuff + vastly optimise hex drawing
Diffstat (limited to 'client/drawing.lua')
-rw-r--r-- | client/drawing.lua | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/client/drawing.lua b/client/drawing.lua index 29069e7..21513cb 100644 --- a/client/drawing.lua +++ b/client/drawing.lua @@ -13,29 +13,57 @@ for i=0,5 do table.insert(corners,y) end -local function draw_hex(cpos,color,thick) - love.graphics.push() - love.graphics.setLineWidth(thick or 0.1) - love.graphics.translate(cpos.x,cpos.y) - if color then love.graphics.setColor(color) else - love.graphics.setColor(love.math.colorFromBytes(0xe7,0x9e,0)) +-- local function draw_hex(cpos,color) +-- love.graphics.push() +-- love.graphics.setLineWidth(0.1) +-- love.graphics.translate(cpos.x,cpos.y) +-- if color then love.graphics.setColor(color) else +-- love.graphics.setColor(love.math.colorFromBytes(0xe7,0x9e,0)) +-- end +-- love.graphics.polygon("fill",corners) +-- love.graphics.setColor(0,0,0) +-- love.graphics.polygon("line",corners) +-- love.graphics.pop() +-- end + +local _corners = {} +local function draw_hex(cpos,color) + local cx,cy = cpos.x,cpos.y + for i=0,5 do + local angle = tau*(i+0.5)/6 + local x = cx + math.cos(angle) + local y = cy + math.sin(angle) + _corners[2*i+1] = x + _corners[2*i+2] = y end - love.graphics.polygon("fill",corners) + love.graphics.setLineWidth(0.1) + -- love.graphics.setColor(love.math.colorFromBytes(0xe7,0x9e,0)) + love.graphics.setColor(color or {0.91,0.62,0}) + love.graphics.polygon("fill",_corners) love.graphics.setColor(0,0,0) - love.graphics.polygon("line",corners) - love.graphics.pop() + love.graphics.polygon("line",_corners) end -local function draw_chunk(the_chunk) - for q = 0,31 do - for r = 0,31 do - local t = the_chunk.tiles[chunk.index(q,r)] +local function draw_chunk(camera,the_chunk) + local tl,br = camera:extents() + local tlh,brh = tl:to_hex():round(), br:to_hex():round() + local trh = coords.Pos.make(br.x,tl.y):to_hex():round() + + for r = tlh.r-1,brh.r+1 do + local rowidx = r-tlh.r + local minq = tlh.q - math.floor((rowidx+1)/2) + local maxq = minq+(trh.q-tlh.q)+1 + print(string.format("r=%d; q = %d to %d",r,minq,maxq)) + for q = minq,maxq do + local h = coords.Hex.make(q,r) + local t = the_chunk:tile_at_offset(h) if t then - local p = coords.Hex.make(q,r):to_pos() - draw_hex(p) + draw_hex(h:to_pos()) end end end + + end return {draw_hex=draw_hex,draw_chunk=draw_chunk} |