class Gameworks::Servlet::MatchMaker
Constants
- SEATS
Attributes
server[RW]
Public Class Methods
request_game(&blk)
click to toggle source
on the class because I want it persistent
# File lib/gameworks/servlet/match_maker.rb, line 26 def request_game(&blk) promise = Promise.new promise.demand(&blk) queue.push(promise) end
Protected Class Methods
find_match()
click to toggle source
# File lib/gameworks/servlet/match_maker.rb, line 41 def find_match match = [] SEATS.times do queue.pop do |request| match << request if match.size == SEATS run_match(match) find_match end end end end
queue()
click to toggle source
# File lib/gameworks/servlet/match_maker.rb, line 33 def queue unless @queue @queue = EventMachine::Queue.new find_match end @queue end
run_match(match)
click to toggle source
# File lib/gameworks/servlet/match_maker.rb, line 54 def run_match(match) game = server.game_class.random('seats' => SEATS) server.game_registry.add(game) match.each{ |request| request.fulfill(game) } end
Public Instance Methods
GET(request)
click to toggle source
# File lib/gameworks/servlet/match_maker.rb, line 61 def GET(request) MatchMaker.server ||= @server MatchMaker.request_game do |game| request[:async_cb].call [201, {'Location' => "/#{game.id}"}, []] end [-1, {}, []] end