From 3c66e7a4d91e2c891cd3b93346ee1f211eb4b6a5 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 25 Feb 2023 15:24:33 +0000 Subject: don't draw chunks definitely not on screen; add targeting reticle; save chunks before exiting on sigint; add /tp 'command' --- client/drawing2.lua | 11 +++++++++++ client/main.lua | 32 +++++++++++++++++++++++++++++++- server/server.lua | 30 +++++++++++++++++++++++------- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/client/drawing2.lua b/client/drawing2.lua index e09d7dc..c894e4c 100644 --- a/client/drawing2.lua +++ b/client/drawing2.lua @@ -123,16 +123,27 @@ local function draw_map(camera,map) shader:send("zoom",camera.zoom) love.graphics.setShader(shader) + local cam_tl,cam_br = camera:extents() + local count = CHUNK_SIZE*CHUNK_SIZE for _,ch in map:iter_chunks() do if ch then -- todo: skip chunks that aren't on screen, maybe local htl,hbr = ch.cp:extents() local tl = htl:to_pos() + local br = hbr:to_pos() + + if br.x < cam_tl.x or cam_br.x < tl.x or br.y < cam_tl.y or cam_br.y < tl.y then + -- definitely not visible on screen + -- this does not catch every single nonvisible chunk + goto next + end + set_imesh(ch.imesh) love.graphics.drawInstanced(shape_mesh, count, tl.x, tl.y) end + ::next:: end love.graphics.setShader() diff --git a/client/main.lua b/client/main.lua index 74a8be9..c2d5a76 100644 --- a/client/main.lua +++ b/client/main.lua @@ -75,7 +75,17 @@ function love.keypressed(key,scancode,isrepeat) elseif ui_mode == "chat" then if key == "return" then ui_mode = "normal" - peer:send(json.encode{t="chat",msg=this_chatmsg}) + if this_chatmsg:sub(1,3) == "/tp" then + local x,y = this_chatmsg:match("/tp (%S+) (%S+)") + if x then + x,y = tonumber(x),tonumber(y) + local_player.pos.x=x + local_player.pos.y=y + local_player.pos_dirty=true + end + else + peer:send(json.encode{t="chat",msg=this_chatmsg}) + end -- msgbox.add("[me] "..this_chatmsg) elseif key == "escape" then ui_mode = "normal" @@ -264,6 +274,26 @@ function love.draw() local wm = camera:screen_to_world(sm) local hm = wm:to_hex() + -- draw reticle + local hmr = hm:round() + local mouse_tile = map:at(hmr) + if mouse_tile then + local col = {0.5,0.5,0.5} + if mouse_tile == 0 then col = {0,0,0} end + local c = hmr:to_pos() + local verts = {} + for i=0,5 do + local angle = math.pi*2*(i+0.5)/6 + table.insert(verts, c.x+math.cos(angle)) + table.insert(verts, c.y+math.sin(angle)) + end + love.graphics.setColor(col) + love.graphics.setLineWidth(0.05) + love.graphics.polygon("line",verts) + end + + + love.graphics.origin() util.print_good(tostring(selected_tile), "center",10) if _G.debugmode and local_player then diff --git a/server/server.lua b/server/server.lua index 097bc99..24b49ae 100644 --- a/server/server.lua +++ b/server/server.lua @@ -7,6 +7,8 @@ local Pos = coords.Pos local worldgen = require"worldgen" local MapS = require"map".MapS local posix_time = require"posix.time" +local posix_signal = require"posix.signal" + math.randomseed(os.time()) local host = enet.host_create("*:8473",nil,2) @@ -181,20 +183,34 @@ local function player_near_chunk(cp) return false end +local function save_things() + for cp,ch in map:iter_chunks() do + map:save_chunk(cp) + if not player_near_chunk(cp) then + -- print("unloading chunk",cp) + map:remove_chunk(cp) + end + end +end + local function tick(ntick) if ntick % 30 == 0 then -- print("saving things") - for cp,ch in map:iter_chunks() do - map:save_chunk(cp) - if not player_near_chunk(cp) then - -- print("unloading chunk",cp) - map:remove_chunk(cp) - end - end + save_things() end end +local stopping=false + +posix_signal.signal(posix_signal.SIGINT, function() stopping=true end) + while true do + if stopping then + print("stopping...") + save_things() + break + end + local now = timenow() local dt = now - last_tick_time local time_till_next_tick = (last_tick_time+tick_interval)-now -- cgit v1.2.3