4 from sys
import platform
, argv
5 from logging
import info
6 from os
.path
import exists
7 from os
import makedirs
8 from panda3d
.core
import Filename
, load_prc_file_data
, AntialiasAttrib
9 from panda3d
.bullet
import BulletWorld
, BulletDebugNode
10 from direct
.showbase
.ShowBase
import ShowBase
11 from pmachines
.scene
import Scene
12 from pmachines
.music
import MusicMgr
13 from lib
.dictfile
import DctFile
14 from lib
.lib
.p3d
.p3d
import LibP3d
15 from lib
.engine
.lang
import LangMgr
22 self
.base
= ShowBase()
23 info('platform: %s' % platform
)
24 info('exists main.py: %s' % exists('main.py'))
25 args
= self
._parse
_args
()
26 self
._prepare
_window
(args
)
27 self
.updating
= args
.update
28 self
.version
= args
.version
31 MusicMgr(self
._options
['settings']['volume'])
32 self
.lang_mgr
= LangMgr('en',
36 self
._scene
= Scene(self
.world
)
39 load_prc_file_data('', 'window-title pmachines')
40 load_prc_file_data('', 'framebuffer-multisample 1')
41 load_prc_file_data('', 'multisamples 4')
42 load_prc_file_data('', 'framebuffer-srgb true')
44 def _parse_args(self
):
45 parser
= argparse
.ArgumentParser()
46 parser
.add_argument('--update', action
='store_true')
47 parser
.add_argument('--version', action
='store_true')
48 parser
.add_argument('--optfile')
49 cmd_line
= [arg
for arg
in iter(argv
[1:]) if not arg
.startswith('-psn_')]
50 args
= parser
.parse_args(cmd_line
)
53 def _prepare_window(self
, args
):
55 if (platform
.startswith('win') or platform
.startswith('linux')) and (
56 not exists('main.py') or __file__
.startswith('/app/bin/')):
57 # it is the deployed version for windows
58 data_path
= str(Filename
.get_user_appdata_directory()) + '/pmachines'
59 home
= '/home/flavio' # we must force this for wine
60 if data_path
.startswith('/c/users/') and exists(home
+ '/.wine/'):
61 data_path
= home
+ '/.wine/drive_' + data_path
[1:]
62 info('creating dirs: %s' % data_path
)
63 makedirs(data_path
, exist_ok
=True)
64 optfile
= args
.optfile
if args
.optfile
else 'options.ini'
65 info('data path: %s' % data_path
)
66 info('option file: %s' % optfile
)
67 info('fixed path: %s' % LibP3d
.fixpath(data_path
+ '/' + optfile
))
75 opt_path
= LibP3d
.fixpath(data_path
+ '/' + optfile
) if data_path
else optfile
76 opt_exists
= exists(opt_path
)
77 self
._options
= DctFile(
78 LibP3d
.fixpath(data_path
+ '/' + optfile
) if data_path
else optfile
,
82 gltf
.patch_loader(base
.loader
)
83 if self
._options
['development']['simplepbr']:
84 pipeline
= simplepbr
.init(
86 use_emission_maps
=False,
87 use_occlusion_maps
=True
89 render
.setAntialias(AntialiasAttrib
.MAuto
)
90 self
.base
.set_background_color(0, 0, 0, 1)
91 self
.base
.disable_mouse()
92 #self.base.accept('window-event', self._on_win_evt)
93 self
.base
.accept('aspectRatioChanged', self
._on
_aspect
_ratio
_changed
)
95 def _set_physics(self
):
96 if self
._options
['development']['physics_debug']:
97 debug_node
= BulletDebugNode('Debug')
98 debug_node
.show_wireframe(True)
99 debug_node
.show_constraints(True)
100 debug_node
.show_bounding_boxes(True)
101 debug_node
.show_normals(True)
102 debug_np
= render
.attach_new_node(debug_node
)
104 self
.world
= BulletWorld()
105 self
.world
.set_gravity((0, 0, -9.81))
106 if self
._options
['development']['physics_debug']:
107 self
.world
.set_debug_node(debug_np
.node())
109 dt
= globalClock
.get_dt()
110 self
.world
.do_physics(dt
)
112 taskMgr
.add(update
, 'update')
114 def _on_aspect_ratio_changed(self
):
115 self
._scene
.on_aspect_ratio_changed()