ya2 · news · projects · code · about

housekeeping: ya2 module
[pmachines.git] / pmachines / app.py
index 095c151d1c40a8512c0762681791ac821716dbfc..5baea798453bda2ef97be04445b9d88202b169b3 100755 (executable)
@@ -9,7 +9,7 @@ from os.path import exists
 from os import makedirs
 from multiprocessing import cpu_count
 from panda3d.core import Filename, load_prc_file_data, AntialiasAttrib, \
-    WindowProperties, LVector2i, TextNode
+    WindowProperties, LVector2i, TextNode, GraphicsBuffer
 from panda3d.bullet import BulletWorld, BulletDebugNode
 from direct.showbase.ShowBase import ShowBase
 from direct.gui.OnscreenText import OnscreenText
@@ -21,11 +21,11 @@ from pmachines.scene import Scene
 from pmachines.posmgr import PositionMgr
 from pmachines.persistent import Persistent
 from ya2.utils.dictfile import DctFile
-from ya2.p3d.p3d import LibP3d
+from ya2.utils.logics import LogicsTools
 from ya2.utils.lang import LangMgr
 from ya2.utils.log import LogMgr
 from ya2.utils.functional import FunctionalTest
-from ya2.p3d.asserts import Assert
+from ya2.utils.asserts import Assert
 
 
 class MainFsm(FSM):
@@ -54,7 +54,7 @@ class MainFsm(FSM):
 
     def __do_asserts(self):
         args = self._pmachines._args
-        if not LibP3d.runtime() or args.functional_test or args.functional_ref:
+        if not LogicsTools.runtime() or args.functional_test or args.functional_ref:
             Assert.assert_threads()
             Assert.assert_tasks()
             Assert.assert_render3d()
@@ -63,6 +63,9 @@ class MainFsm(FSM):
             Assert.assert_events()
             Assert.assert_buffers()
 
+    def enterOff(self):
+        self.ignore('new_scene')
+
 
 class Pmachines:
 
@@ -84,6 +87,8 @@ class Pmachines:
         self.log_mgr = LogMgr.init_cls()()
         self._pos_mgr = PositionMgr()
         self._prepare_window(args)
+        self._fsm = MainFsm(self)
+        self._fsm.demand('Start')  # otherwise it is Off and cleanup in tests won't work
         if args.update:
             return
         if args.functional_test:
@@ -92,10 +97,9 @@ class Pmachines:
         self.lang_mgr = LangMgr(self._options['settings']['language'],
                                 'pmachines',
                                 'assets/locale/')
-        self._fsm = MainFsm(self)
         if args.functional_test or args.functional_ref:
             FunctionalTest(args.functional_ref, self._pos_mgr)
-        if not LibP3d.runtime() or args.functional_test or args.functional_ref:
+        if not LogicsTools.runtime() or args.functional_test or args.functional_ref:
             self.__fps_lst = []
             taskMgr.do_method_later(1.0, self.__assert_fps, 'assert_fps')
 
@@ -194,7 +198,7 @@ class Pmachines:
         optfile = args.optfile if args.optfile else 'options.ini'
         info('data path: %s' % data_path)
         info('option file: %s' % optfile)
-        info('fixed path: %s' % LibP3d.fixpath(data_path + '/' + optfile))
+        info('fixed path: %s' % LogicsTools.fixpath(data_path + '/' + optfile))
         default_opt = {
             'settings': {
                 'volume': 1,
@@ -218,10 +222,10 @@ class Pmachines:
                 'fps': 0,
                 'editor': 0,
                 'auto_start_editor': 0}}
-        opt_path = LibP3d.fixpath(data_path + '/' + optfile) if data_path else optfile
+        opt_path = LogicsTools.fixpath(data_path + '/' + optfile) if data_path else optfile
         opt_exists = exists(opt_path)
         self._options = DctFile(
-            LibP3d.fixpath(data_path + '/' + optfile) if data_path else optfile,
+            LogicsTools.fixpath(data_path + '/' + optfile) if data_path else optfile,
             default_opt)
         if not opt_exists:
             self._options.store()
@@ -248,7 +252,7 @@ class Pmachines:
             props.set_size(res)
         props.set_fullscreen(fullscreen)
         props.set_icon_filename('assets/images/icon/pmachines.ico')
-        if not args.screenshot and not self.is_version_run and base.win:
+        if not args.screenshot and not self.is_version_run and base.win and not isinstance(base.win, GraphicsBuffer):
             base.win.request_properties(props)
         #gltf.patch_loader(base.loader)
         if self._options['development']['simplepbr'] and not self.is_version_run and base.win:
@@ -318,6 +322,10 @@ class Pmachines:
             assert not all(fps < fps_threshold for fps in self.__fps_lst), 'low fps %s' % self.__fps_lst
         return task.again
 
+    def destroy(self):
+        self._fsm.cleanup()
+        self.base.destroy()
+
     def run(self):
         self.start()
         self.base.run()