local lg = assert( love.graphics ) local scene = assert( require 'client.scene' ) local shared = assert( require 'shared' ) local server = assert( require 'client.udp' ) local crepuscular = assert( require 'client.crepuscular' ) local game = {} local t = 0 local tick = 0 local serverTick = "0" function game.draw() lg.print( tick, 0, 0 ) lg.print( serverTick, 0, 25 ) end function game.onPacket( data ) if not data then return end serverTick = data return game.onPacket( server.receive() ) --Recurse to get all waiting packets. end function game.update( dt ) t = dt + t game.onPacket( server.receive() ) if t > 0.1 then t = 0 tick = tick + 1 assert( server.send( tostring(tick) ) ) end end function game.newGame( ) game.curWorld = shared.NewWorld() --Last world state received from server. game.preWorld = shared.NewWorld() --Current world state predicted by this client. end function game.disconnect( ) return scene.mainmenu( server.disconnect() ) end function game.onLoad( params ) end function game.keypressed( key, code, isRepeat ) if code == "escape" then return game.disconnect() end end scene.game = game return game