ya2 · news · projects · code · about

configuration
[pmachines.git] / pmachines / pmachines.py
index 2cfbd61108bb3f225200f82696feee6b7a9fbe50..0936b42bb0203aad58c4a1b3d88bbf28f40ff95e 100755 (executable)
@@ -10,6 +10,8 @@ from panda3d.bullet import BulletWorld, BulletDebugNode
 from direct.showbase.ShowBase import ShowBase
 from pmachines.scene import Scene
 from pmachines.music import MusicMgr
 from direct.showbase.ShowBase import ShowBase
 from pmachines.scene import Scene
 from pmachines.music import MusicMgr
+from lib.dictfile import DctFile
+from lib.lib.p3d.p3d import LibP3d
 
 
 class Pmachines:
 
 
 class Pmachines:
@@ -19,13 +21,13 @@ class Pmachines:
         self.base = ShowBase()
         info('platform: %s' % platform)
         info('exists main.py: %s' % exists('main.py'))
         self.base = ShowBase()
         info('platform: %s' % platform)
         info('exists main.py: %s' % exists('main.py'))
-        self._prepare_window()
         args = self._parse_args()
         args = self._parse_args()
+        self._prepare_window(args)
         self.updating = args.update
         self.version = args.version
         if args.update:
             return
         self.updating = args.update
         self.version = args.version
         if args.update:
             return
-        MusicMgr()
+        MusicMgr(self._options['settings']['volume'])
         self._set_physics()
         Scene(self.world)
 
         self._set_physics()
         Scene(self.world)
 
@@ -39,11 +41,12 @@ class Pmachines:
         parser = argparse.ArgumentParser()
         parser.add_argument('--update', action='store_true')
         parser.add_argument('--version', action='store_true')
         parser = argparse.ArgumentParser()
         parser.add_argument('--update', action='store_true')
         parser.add_argument('--version', action='store_true')
+        parser.add_argument('--optfile')
         cmd_line = [arg for arg in iter(argv[1:]) if not arg.startswith('-psn_')]
         args = parser.parse_args(cmd_line)
         return args
 
         cmd_line = [arg for arg in iter(argv[1:]) if not arg.startswith('-psn_')]
         args = parser.parse_args(cmd_line)
         return args
 
-    def _prepare_window(self):
+    def _prepare_window(self, args):
         data_path = ''
         if (platform.startswith('win') or platform.startswith('linux')) and (
                 not exists('main.py') or __file__.startswith('/app/bin/')):
         data_path = ''
         if (platform.startswith('win') or platform.startswith('linux')) and (
                 not exists('main.py') or __file__.startswith('/app/bin/')):
@@ -54,6 +57,23 @@ class Pmachines:
                 data_path = home + '/.wine/drive_' + data_path[1:]
             info('creating dirs: %s' % data_path)
             makedirs(data_path, exist_ok=True)
                 data_path = home + '/.wine/drive_' + data_path[1:]
             info('creating dirs: %s' % data_path)
             makedirs(data_path, exist_ok=True)
+        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))
+        default_opt = {
+            'settings': {
+                'volume': 1},
+            'development': {
+                'verbose_log': 0,
+                'physics_debug': 0}}
+        opt_path = LibP3d.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,
+            default_opt)
+        if not opt_exists:
+            self._options.store()
         gltf.patch_loader(base.loader)
         pipeline = simplepbr.init(
             use_normal_maps=True,
         gltf.patch_loader(base.loader)
         pipeline = simplepbr.init(
             use_normal_maps=True,
@@ -65,16 +85,18 @@ class Pmachines:
         self.base.disable_mouse()
 
     def _set_physics(self):
         self.base.disable_mouse()
 
     def _set_physics(self):
-        debug_node = BulletDebugNode('Debug')
-        debug_node.show_wireframe(True)
-        debug_node.show_constraints(True)
-        debug_node.show_bounding_boxes(True)
-        debug_node.show_normals(True)
-        debug_np = render.attach_new_node(debug_node)
-        debug_np.show()
+        if self._options['development']['physics_debug']:
+            debug_node = BulletDebugNode('Debug')
+            debug_node.show_wireframe(True)
+            debug_node.show_constraints(True)
+            debug_node.show_bounding_boxes(True)
+            debug_node.show_normals(True)
+            debug_np = render.attach_new_node(debug_node)
+            debug_np.show()
         self.world = BulletWorld()
         self.world.set_gravity((0, 0, -9.81))
         self.world = BulletWorld()
         self.world.set_gravity((0, 0, -9.81))
-        self.world.set_debug_node(debug_np.node())
+        if self._options['development']['physics_debug']:
+            self.world.set_debug_node(debug_np.node())
         def update(task):
             dt = globalClock.get_dt()
             self.world.do_physics(dt)
         def update(task):
             dt = globalClock.get_dt()
             self.world.do_physics(dt)