本文整理汇总了Python中horizons.scheduler.Scheduler类的典型用法代码示例。如果您正苦于以下问题:Python Scheduler类的具体用法?Python Scheduler怎么用?Python Scheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, db, rng_seed=None):
"""
Unfortunately, right now there is no other way to setup Dummy versions of the GUI,
View etc., unless we want to patch the references in the session module.
"""
super(LivingObject, self).__init__()
self.gui = Dummy()
self.db = db
self.savecounter = 0 # this is a new game.
self.is_alive = True
WorldObject.reset()
NamedObject.reset()
AIPlayer.clear_caches()
# Game
self.current_tick = 0
self.random = self.create_rng(rng_seed)
self.timer = self.create_timer()
Scheduler.create_instance(self.timer)
ExtScheduler.create_instance(Dummy)
self.manager = self.create_manager()
self.view = Dummy()
self.view.renderer = Dummy()
Entities.load(self.db)
self.scenario_eventhandler = Dummy()
self.campaign = {}
self.selected_instances = []
# GUI
self.gui.session = self
self.ingame_gui = Dummy()
GAME_SPEED.TICKS_PER_SECOND = 16
示例2: save
def save(self, db):
super(Trader, self).save(db)
# mark self as a trader
db("UPDATE player SET is_trader = 1 WHERE rowid = ?", self.worldid)
for ship in self.ships:
# prepare values
ship_state = self.ships[ship]
remaining_ticks = None
# get current callback in scheduler, according to ship state, to retrieve
# the number of ticks, when the call will actually be done
current_callback = None
if ship_state == self.shipStates.reached_warehouse:
current_callback = Callback(self.ship_idle, ship)
if current_callback is not None:
# current state has a callback
calls = Scheduler().get_classinst_calls(self, current_callback)
assert len(calls) == 1, "got %s calls for saving %s: %s" %(len(calls), current_callback, calls)
remaining_ticks = max(calls.values()[0], 1)
targeted_warehouse = None if ship.worldid not in self.office else self.office[ship.worldid].worldid
# put them in the database
db("INSERT INTO trader_ships(rowid, state, remaining_ticks, targeted_warehouse) \
VALUES(?, ?, ?, ?)", ship.worldid, ship_state.index, remaining_ticks, targeted_warehouse)
示例3: end
def end(self):
self.log.debug("Ending session")
self.is_alive = False
self.gui.session = None
Scheduler().rem_all_classinst_calls(self)
ExtScheduler().rem_all_classinst_calls(self)
if horizons.main.fife.get_fife_setting("PlaySounds"):
for emitter in horizons.main.fife.emitter['ambient'][:]:
emitter.stop()
horizons.main.fife.emitter['ambient'].remove(emitter)
horizons.main.fife.emitter['effects'].stop()
horizons.main.fife.emitter['speech'].stop()
self.cursor = None
self.world = None
self.keylistener = None
self.ingame_gui = None
self.view = None
self.manager = None
self.timer = None
self.scenario_eventhandler = None
Scheduler.destroy_instance()
self.selected_instances = None
self.selection_groups = None
示例4: setUp
def setUp(self):
self.inventory = GenericStorage()
self.owner_inventory = GenericStorage()
class Instance:
def __init__(self, comp):
self.comp = comp
self.owner = None # type: Optional[Instance]
def get_component(self, x):
class Comp:
inventory = self.comp
return Comp()
self.tradepost = TradePostComponent()
self.tradepost.instance = Instance(self.inventory)
self.tradepost.instance.owner = Instance(self.owner_inventory)
self.tradepost.initialize()
class Timer:
def add_call(self, x):
pass
def get_ticks(self, x):
return 100
Scheduler.create_instance(timer=Timer())
示例5: save
def save(self, db):
super(Pirate, self).save(db)
db("UPDATE player SET is_pirate = 1 WHERE rowid = ?", self.worldid)
db("INSERT INTO pirate_home_point(x, y) VALUES(?, ?)", self.home_point.x, self.home_point.y)
current_callback = Callback(self.tick)
calls = Scheduler().get_classinst_calls(self, current_callback)
assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback, calls)
remaining_ticks = max(calls.values()[0], 1)
current_callback_long = Callback(self.tick_long)
calls = Scheduler().get_classinst_calls(self, current_callback_long)
assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback_long, calls)
remaining_ticks_long = max(calls.values()[0], 1)
db("INSERT INTO ai_pirate(rowid, remaining_ticks, remaining_ticks_long) VALUES(?, ?, ?)", self.worldid,
remaining_ticks, remaining_ticks_long)
for ship in self.ships:
ship_state = self.ships[ship]
db("INSERT INTO pirate_ships(rowid, state) VALUES(?, ?)",
ship.worldid, ship_state.index)
# save unit manager
self.unit_manager.save(db)
# save combat manager
self.combat_manager.save(db)
# save strategy manager
self.strategy_manager.save(db)
# save behavior manager
self.behavior_manager.save(db)
示例6: __init__
def __init__(self, gui, db):
super(Session, self).__init__()
self.log.debug("Initing session")
self.gui = gui # main gui, not ingame gui
self.db = db # main db for game data (game.sqlite)
# this saves how often the current game has been saved
self.savecounter = 0
self.is_alive = True
WorldObject.reset()
NamedObject.reset()
#game
self.random = self.create_rng()
self.timer = Timer()
Scheduler.create_instance(self.timer)
self.manager = self.create_manager()
self.view = View(self, (15, 15))
Entities.load(self.db)
self.scenario_eventhandler = ScenarioEventHandler(self) # dummy handler with no events
self.campaign = {}
#GUI
self.gui.session = self
self.ingame_gui = IngameGui(self, self.gui)
self.keylistener = IngameKeyListener(self)
self.display_speed()
self.selected_instances = set()
self.selection_groups = [set()] * 10 # List of sets that holds the player assigned unit groups.
示例7: end
def end(self):
self.log.debug("Ending session")
self.is_alive = False
# Has to be done here, cause the manager uses Scheduler!
Scheduler().rem_all_classinst_calls(self)
ExtScheduler().rem_all_classinst_calls(self)
horizons.globals.fife.sound.end()
# these will call end() if the attribute still exists by the LivingObject magic
self.ingame_gui = None # keep this before world
self.world.end() # must be called before the world ref is gone
self.world = None
self.view = None
self.manager = None
self.timer = None
self.scenario_eventhandler = None
Scheduler().end()
Scheduler.destroy_instance()
self.selected_instances = None
self.selection_groups = None
horizons.main._modules.session = None
self._clear_caches()
# subscriptions shouldn't survive listeners (except the main Gui)
self.gui.unsubscribe()
SettingChanged.unsubscribe(self._on_setting_changed)
MessageBus().reset()
self.gui.subscribe()
示例8: end
def end(self):
self.log.debug("Ending session")
self.is_alive = False
# Has to be done here, cause the manager uses Scheduler!
Scheduler().rem_all_classinst_calls(self)
ExtScheduler().rem_all_classinst_calls(self)
horizons.globals.fife.sound.end()
# these will call end() if the attribute still exists by the LivingObject magic
self.ingame_gui = None # keep this before world
if hasattr(self, 'world'):
# must be called before the world ref is gone, but may not exist yet while loading
self.world.end()
self.world = None
self.view = None
self.manager = None
self.timer = None
self.scenario_eventhandler = None
Scheduler().end()
Scheduler.destroy_instance()
self.selected_instances = None
self.selection_groups = None
self._clear_caches()
# discard() in case loading failed and we did not yet subscribe
SettingChanged.discard(self._on_setting_changed)
MessageBus().reset()
示例9: cleanup
def cleanup(cls):
"""
If a test uses manual session management, we cannot be sure that session.end was
called before a crash, leaving the game in an unclean state. This method should
return the game to a valid state.
"""
Scheduler.destroy_instance()
示例10: save
def save(self, db):
super(Collector, self).save(db)
# save state and remaining ticks for next callback
# retrieve remaining ticks according current callback according to state
current_callback = None
remaining_ticks = None
if self.state == self.states.idle:
current_callback = self.search_job
elif self.state == self.states.working:
current_callback = self.finish_working
if current_callback is not None:
calls = Scheduler().get_classinst_calls(self, current_callback)
assert len(calls) == 1, 'Collector should have callback %s scheduled, but has %s' % \
(current_callback, [ str(i) for i in Scheduler().get_classinst_calls(self).keys() ])
remaining_ticks = max(calls.values()[0], 1) # save a number > 0
db("INSERT INTO collector(rowid, state, remaining_ticks, start_hidden) VALUES(?, ?, ?, ?)",
self.worldid, self.state.index, remaining_ticks, self.start_hidden)
# save the job
if self.job is not None:
obj_id = -1 if self.job.object is None else self.job.object.worldid
# this is not in 3rd normal form since the object is saved multiple times but
# it preserves compatiblity with old savegames this way.
for entry in self.job.reslist:
db("INSERT INTO collector_job(collector, object, resource, amount) VALUES(?, ?, ?, ?)",
self.worldid, obj_id, entry.res, entry.amount)
示例11: __init__
def __init__(self, db, rng_seed=None, ingame_gui_class=IngameGui):
super(Session, self).__init__()
assert isinstance(db, horizons.util.uhdbaccessor.UhDbAccessor)
self.log.debug("Initing session")
self.db = db # main db for game data (game.sql)
# this saves how often the current game has been saved
self.savecounter = 0
self.is_alive = True
self._clear_caches()
#game
self.random = self.create_rng(rng_seed)
assert isinstance(self.random, Random)
self.timer = self.create_timer()
Scheduler.create_instance(self.timer)
self.manager = self.create_manager()
self.view = View()
Entities.load(self.db)
self.scenario_eventhandler = ScenarioEventHandler(self) # dummy handler with no events
#GUI
self._ingame_gui_class = ingame_gui_class
self.selected_instances = set()
# List of sets that holds the player assigned unit groups.
self.selection_groups = [set()] * 10
self._old_autosave_interval = None
示例12: save
def save(self, db):
super(AIPlayer, self).save(db)
# save the player
db("UPDATE player SET client_id = 'AIPlayer' WHERE rowid = ?", self.worldid)
current_callback = Callback(self.tick)
calls = Scheduler().get_classinst_calls(self, current_callback)
assert len(calls) == 1, "got %s calls for saving %s: %s" % (len(calls), current_callback, calls)
remaining_ticks = max(calls.values()[0], 1)
db("INSERT INTO ai_player(rowid, need_more_ships, need_feeder_island, remaining_ticks) VALUES(?, ?, ?, ?)", \
self.worldid, self.need_more_ships, self.need_feeder_island, remaining_ticks)
# save the ships
for ship, state in self.ships.iteritems():
db("INSERT INTO ai_ship(rowid, owner, state) VALUES(?, ?, ?)", ship.worldid, self.worldid, state.index)
# save the land managers
for land_manager in self.islands.itervalues():
land_manager.save(db)
# save the settlement managers
for settlement_manager in self.settlement_managers:
settlement_manager.save(db)
# save the missions
for mission in self.missions:
mission.save(db)
# save the personality manager
self.personality_manager.save(db)
示例13: end
def end(self):
self.log.debug("Ending session")
self.is_alive = False
LastActivePlayerSettlementManager().remove()
LastActivePlayerSettlementManager.destroy_instance()
self.gui.session = None
Scheduler().rem_all_classinst_calls(self)
ExtScheduler().rem_all_classinst_calls(self)
if horizons.main.fife.get_fife_setting("PlaySounds"):
for emitter in horizons.main.fife.sound.emitter['ambient'][:]:
emitter.stop()
horizons.main.fife.sound.emitter['ambient'].remove(emitter)
horizons.main.fife.sound.emitter['effects'].stop()
horizons.main.fife.sound.emitter['speech'].stop()
if hasattr(self, "cursor"): # the line below would crash uglily on ^C
self.cursor.remove()
self.cursor = None
self.world = None
self.keylistener = None
self.ingame_gui = None
self.view = None
self.manager = None
self.timer = None
self.scenario_eventhandler = None
Scheduler.destroy_instance()
self.selected_instances = None
self.selection_groups = None
示例14: end
def end(self):
self.log.debug("Ending session")
self.is_alive = False
self.gui.session = None
# Has to be done here, cause the manager uses Scheduler!
self.end_production_finished_icon_manager()
Scheduler().rem_all_classinst_calls(self)
ExtScheduler().rem_all_classinst_calls(self)
if horizons.globals.fife.get_fife_setting("PlaySounds"):
for emitter in horizons.globals.fife.sound.emitter['ambient'][:]:
emitter.stop()
horizons.globals.fife.sound.emitter['ambient'].remove(emitter)
horizons.globals.fife.sound.emitter['effects'].stop()
horizons.globals.fife.sound.emitter['speech'].stop()
if hasattr(self, "cursor"): # the line below would crash uglily on ^C
self.cursor.remove()
if hasattr(self, 'cursor') and self.cursor is not None:
self.cursor.end()
# these will call end() if the attribute still exists by the LivingObject magic
self.ingame_gui = None # keep this before world
LastActivePlayerSettlementManager().remove() # keep after ingame_gui
LastActivePlayerSettlementManager.destroy_instance()
self.cursor = None
self.world.end() # must be called before the world ref is gone
self.world = None
self.keylistener = None
self.view = None
self.manager = None
self.timer = None
self.scenario_eventhandler = None
Scheduler().end()
Scheduler.destroy_instance()
self.selected_instances = None
self.selection_groups = None
self.status_icon_manager.end()
self.status_icon_manager = None
horizons.main._modules.session = None
self._clear_caches()
# subscriptions shouldn't survive listeners (except the main Gui)
self.gui.unsubscribe()
AutosaveIntervalChanged.unsubscribe(self._on_autosave_interval_changed)
MessageBus().reset()
self.gui.subscribe()
示例15: end
def end(self):
self.log.debug("Ending session")
self.is_alive = False
self.gui.session = None
Scheduler().rem_all_classinst_calls(self)
ExtScheduler().rem_all_classinst_calls(self)
if horizons.main.fife.get_fife_setting("PlaySounds"):
for emitter in horizons.main.fife.sound.emitter['ambient'][:]:
emitter.stop()
horizons.main.fife.sound.emitter['ambient'].remove(emitter)
horizons.main.fife.sound.emitter['effects'].stop()
horizons.main.fife.sound.emitter['speech'].stop()
if hasattr(self, "cursor"): # the line below would crash uglily on ^C
self.cursor.remove()
if hasattr(self, 'cursor') and self.cursor is not None:
self.cursor.end()
# these will call end() if the attribute still exists by the LivingObject magic
self.ingame_gui = None # keep this before world
LastActivePlayerSettlementManager().remove() # keep after ingame_gui
LastActivePlayerSettlementManager.destroy_instance()
self.cursor = None
try:
# This is likely to throw when the game state is invalid.
# Try to continue cleanup afterwards even if this fails.
# NOTE: This is not a proper solution, separating sessions by design (e.g. single processes) would be.
self.world.end() # must be called before the world ref is gone
except Exception:
import traceback
traceback.print_exc()
print 'Exception on world end(), trying to continue to cleanup'
self.world = None
self.keylistener = None
self.view = None
self.manager = None
self.timer = None
self.scenario_eventhandler = None
Scheduler().end()
Scheduler.destroy_instance()
self.selected_instances = None
self.selection_groups = None
self.status_icon_manager = None
self.message_bus = None
horizons.main._modules.session = None
self._clear_caches()