Working on major restructuring
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
require "async"
|
||||
require "async/websocket"
|
||||
|
||||
module GameServer
|
||||
module Server
|
||||
class WebSocketServer
|
||||
def initialize(world)
|
||||
@world = world
|
||||
end
|
||||
|
||||
def start
|
||||
Async do |task|
|
||||
task.async { simulation_loop }
|
||||
|
||||
Async::WebSocket::Server.open("0.0.0.0", Settings::PORT) do |ws|
|
||||
task.async { Connection.new(ws, @world).run }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def simulation_loop
|
||||
last = Time.now
|
||||
loop do
|
||||
now = Time.now
|
||||
delta = (now - last) * Settings::GAME_SPEED
|
||||
@world.advance(delta)
|
||||
last = now
|
||||
sleep Settings::SIMULATION_STEP
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user