应用程序控制器中的 Rails 游戏循环?
由于我正在 RoR 中编写游戏,因此我需要一个游戏循环,负责在每次页面刷新时检查不同的内容。我的问题是,最好的实施方式是什么?
我目前将 game_loop 包含在我的应用程序控制器中。这是最佳实践吗?
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, what is the best way to implement ?
I currently include the game_loop in my application controller. Is this the best practice ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行游戏看起来像
before_filter
在您的ApplicationController
中听起来很合理,尽管您可能不希望将逻辑放入此类中:请注意,这将在应用程序中的每个操作之前执行游戏循环涉及到从
ApplicationController
扩展而来的控制器,包括用户登录、注销等。最好只在肯定需要处理游戏循环的控制器中添加before_filter
。Executing the game look as a
before_filter
in yourApplicationController
sounds reasonable, although you may not wish to put your logic in this class: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 thebefore_filter
only in the controllers that definitely need to process the game loop.