def loadScene(filepath, name): """ Loads a new scene from another blend. Blends loaded with this method must have only 1 scene. They also need to have a Python controller conected with an always on module mode with the following string: ``main.libload``. This logic bricks are recomended to be used in an object that clearly is the main object of the scene or a camera if any. The name of the library is the filepath. :param string filepath: Relative path from the *data* folder where the blend file is placed. :param string name: Name of the new scene, used with *behavior.Scene*. """ global _change_scene_name global _change_scene_path if module.change_scene_dynamic == False: module._started = False module.change_scene_dynamic = True utils.setScene("Dynamic") _change_scene_name = name _change_scene_path = filepath module.change_scene_dynamic_state = 1 return #Once scene is loaded else: if name or filepath: return name = _change_scene_name scene = utils.getSceneByName("Dynamic") if not scene: return state = module.change_scene_dynamic_state if state == 1: module.change_scene_dynamic_state += 1 module.scene_game = scene if name in module.scene_behavior_dict: module.scene_behavior = (module.scene_behavior_dict[name])() b = module.scene_behavior b.scene = scene loadIntoScene(_change_scene_path, "Scene", scene.active_camera) return if state == 2: return if state == 3: #+1 on main.libload module.change_scene_dynamic_state = 0 module.change_scene_frame = False module.change_scene_dynamic = False if name in module.scene_behavior_dict: b = module.scene_behavior for ob in scene.objects: b.objects[ob.name] = ob for ob in scene.objectsInactive: b.objectsInactive[ob.name] = ob b.init() b.baseInit() for bh in b.behaviors: bh.init()
def secondary_loop(): global _last_traceback, _fatal_error #It takes 0.6ms when with the editor. (Without tile replacing) try: if _fatal_error: return #Set scene if module.change_scene_frame == True: if module.change_scene_dynamic == True: dynamic.loadScene(None, None) else: utils.setScene(None) return else: if module.scene_behavior.paused == False: module.scene_behavior.update() module.scene_behavior.baseUpdate() if not module.scene_behavior: return #When removing the scene for b in module.scene_behavior.behaviors: if b.paused == False: b.update() if not module.scene_behavior: return #When removing the scene except: if not module.scene_behavior: return module.scene_behavior.paused = True s = traceback.format_exc() if s != _last_traceback: utils.debug("Error during runtime. Scene behavior suspended!") print(s) _fatal_error = True _last_traceback = s #It takes about 0.3ms (As much as the main loop) listen_list = [ x for x in module.listen_input_list if x._immuse_keyboard == True and x.scene == module.scene_game ] for x in module.listen_input_list: x._immuse_keyboard = x.use_keyboard event._key_event_loop(listen_list) module.window.secondary_update()
def secondary_loop(): global _last_traceback, _fatal_error #It takes 0.6ms when with the editor. (Without tile replacing) try: if _fatal_error: return #Set scene if module.change_scene_frame == True: if module.change_scene_dynamic == True: dynamic.loadScene(None, None) else: utils.setScene(None) return else: if module.scene_behavior.paused == False: module.scene_behavior.update() module.scene_behavior.baseUpdate() if not module.scene_behavior: return #When removing the scene for b in module.scene_behavior.behaviors: if b.paused == False: b.update() if not module.scene_behavior: return #When removing the scene except: if not module.scene_behavior: return module.scene_behavior.paused = True s = traceback.format_exc() if s != _last_traceback: utils.debug("Error during runtime. Scene behavior suspended!") print(s) _fatal_error = True _last_traceback = s #It takes about 0.3ms (As much as the main loop) listen_list = [x for x in module.listen_input_list if x._immuse_keyboard == True and x.scene == module.scene_game] for x in module.listen_input_list: x._immuse_keyboard = x.use_keyboard event._key_event_loop(listen_list) module.window.secondary_update()