From 9ba5488befb9026a114997fad890d0ca0f887ccc Mon Sep 17 00:00:00 2001 From: Flavio Calva Date: Sat, 8 Jan 2022 16:28:02 +0100 Subject: [PATCH] configuration --- .gitignore | 1 + pmachines/items/box.py | 19 +++++++++--------- pmachines/music.py | 6 +++--- pmachines/pmachines.py | 44 +++++++++++++++++++++++++++++++----------- prj.org | 7 +++++-- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 18da789..059e054 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ TAGS *.mo *.pyc *.blend1 +/options.ini /assets/gltf/ /build/ /dist/ diff --git a/pmachines/items/box.py b/pmachines/items/box.py index cb8c5ef..c0419bb 100644 --- a/pmachines/items/box.py +++ b/pmachines/items/box.py @@ -16,7 +16,7 @@ class Box: model.reparent_to(self._np) self._set_outline_model() self._start_drag_pos = None - self._start_rot_info = None + self._prev_rot_info = None taskMgr.add(self.on_frame, 'on_frame') def _set_outline_model(self): @@ -44,27 +44,28 @@ class Box: loader.load_sfx('assets/audio/sfx/grab.ogg').play() def on_click_r(self, pos): - self._start_rot_info = pos, self._np.get_pos(), self._np.get_r() + self._prev_rot_info = pos, self._np.get_pos(), self._np.get_r() loader.load_sfx('assets/audio/sfx/grab.ogg').play() def on_release(self): - if self._start_drag_pos or self._start_rot_info: + if self._start_drag_pos or self._prev_rot_info: loader.load_sfx('assets/audio/sfx/release.ogg').play() - self._start_drag_pos = self._start_rot_info = None + self._start_drag_pos = self._prev_rot_info = None def on_mouse_on(self): self._outline_model.show() def on_mouse_off(self): - if self._start_drag_pos or self._start_rot_info: return + if self._start_drag_pos or self._prev_rot_info: return self._outline_model.hide() def on_mouse_move(self, pos): if self._start_drag_pos: d_pos = pos - self._start_drag_pos[0] self._np.set_pos(self._start_drag_pos[1] + d_pos) - if self._start_rot_info: - start_vec = self._start_rot_info[0] - self._start_rot_info[1] - curr_vec = pos - self._start_rot_info[1] + if self._prev_rot_info: + start_vec = self._prev_rot_info[0] - self._prev_rot_info[1] + curr_vec = pos - self._prev_rot_info[1] d_angle = curr_vec.signed_angle_deg(start_vec, (0, -1, 0)) - self._np.set_r(self._start_rot_info[2] + d_angle) + self._np.set_r(self._prev_rot_info[2] + d_angle) + self._prev_rot_info = pos, self._np.get_pos(), self._np.get_r() diff --git a/pmachines/music.py b/pmachines/music.py index 71d2cf1..16e13dc 100644 --- a/pmachines/music.py +++ b/pmachines/music.py @@ -6,10 +6,10 @@ from panda3d.core import AudioSound class MusicMgr: - def __init__(self): + def __init__(self, volume): self._start_music(glob('assets/audio/music/*.ogg')) - base.musicManager.setVolume(.8) - base.sfxManagerList[0].setVolume(1) + base.musicManager.setVolume(.8 * volume) + base.sfxManagerList[0].setVolume(volume) taskMgr.add(self._on_frame, 'on frame music') def _start_music(self, files): diff --git a/pmachines/pmachines.py b/pmachines/pmachines.py index 2cfbd61..0936b42 100755 --- a/pmachines/pmachines.py +++ b/pmachines/pmachines.py @@ -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 lib.dictfile import DctFile +from lib.lib.p3d.p3d import LibP3d class Pmachines: @@ -19,13 +21,13 @@ class Pmachines: self.base = ShowBase() info('platform: %s' % platform) info('exists main.py: %s' % exists('main.py')) - self._prepare_window() args = self._parse_args() + self._prepare_window(args) self.updating = args.update self.version = args.version if args.update: return - MusicMgr() + MusicMgr(self._options['settings']['volume']) 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.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 - 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/')): @@ -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) + 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, @@ -65,16 +85,18 @@ class Pmachines: 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.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) diff --git a/prj.org b/prj.org index 3a72a5c..311ee94 100644 --- a/prj.org +++ b/prj.org @@ -1,10 +1,13 @@ * issues * todo -** rotation with vectors/quaternions (fixes some glitches) -** configuration (physics debug, music/sfx volume) +** instantiation of the objects +*** model in the left side with a counter +*** when you click a new object is created iff counter > 0 ** instructions ** main menu ** implement the operations of the buttons +** create one level per item, then levels with more items +*** e.g. item1, item2, item1+2, item3, item1+2+3, ... ** build pipeline ** magnet * waiting -- 2.30.2