开发者

Rails Game Loop in Application Controller?

Since i'm writing a game in RoR, i need to have a game loop that is responsible for checking different things every time a page refresh happens. My question is, wh开发者_运维技巧at is the best way to implement ?

I currently include the game_loop in my application controller. Is this the best practice ?


Executing the game look as a before_filter in your ApplicationController sounds reasonable, although you may not wish to put your logic in this class:

class ApplicationController < ActionController::Base
  before_filter :do_game_loop

  private

    def do_game_loop
      Game.do_game_loop # the implementation of Game is in another file, maybe in lib
    end
end

Do note that this will execute the game loop before every action in your application that involves a controller that extends from ApplicationController, including user login, logout, etc. It may be better to add the before_filter only in the controllers that definitely need to process the game loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜