本文整理汇总了Python中horizons.messaging.SpeedChanged.broadcast方法的典型用法代码示例。如果您正苦于以下问题:Python SpeedChanged.broadcast方法的具体用法?Python SpeedChanged.broadcast怎么用?Python SpeedChanged.broadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.messaging.SpeedChanged
的用法示例。
在下文中一共展示了SpeedChanged.broadcast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: speed_set
# 需要导入模块: from horizons.messaging import SpeedChanged [as 别名]
# 或者: from horizons.messaging.SpeedChanged import broadcast [as 别名]
def speed_set(self, ticks, suggestion=False):
"""Set game speed to ticks ticks per second"""
old = self.timer.ticks_per_second
self.timer.ticks_per_second = ticks
self.view.map.setTimeMultiplier(float(ticks) / float(GAME_SPEED.TICKS_PER_SECOND))
if old == 0 and self.timer.tick_next_time is None: # back from paused state
if self.paused_time_missing is None:
# happens if e.g. a dialog pauses the game during startup on hotkeypress
self.timer.tick_next_time = time.time()
else:
self.timer.tick_next_time = time.time() + (self.paused_time_missing / ticks)
elif ticks == 0 or self.timer.tick_next_time is None:
# go into paused state or very early speed change (before any tick)
if self.timer.tick_next_time is not None:
self.paused_time_missing = (self.timer.tick_next_time - time.time()) * old
else:
self.paused_time_missing = None
self.timer.tick_next_time = None
else:
"""
Under odd circumstances (anti-freeze protection just activated, game speed
decremented multiple times within this frame) this can delay the next tick
by minutes. Since the positive effects of the code aren't really observeable,
this code is commented out and possibly will be removed.
# correct the time until the next tick starts
time_to_next_tick = self.timer.tick_next_time - time.time()
if time_to_next_tick > 0: # only do this if we aren't late
self.timer.tick_next_time += (time_to_next_tick * old / ticks)
"""
SpeedChanged.broadcast(self, old, ticks)