From: Flavio Calva Date: Tue, 5 Jul 2022 17:54:41 +0000 (+0100) Subject: removed GameObject X-Git-Url: http://git.ya2.it/?p=pmachines.git;a=commitdiff_plain;h=aed9737a016073ef8ffc694bd338488ba7c87ca3 removed GameObject --- diff --git a/pmachines/app.py b/pmachines/app.py index 8cbcd63..bbb82c7 100755 --- a/pmachines/app.py +++ b/pmachines/app.py @@ -72,7 +72,7 @@ class PmachinesApp: self._pipeline = None self.updating = args.update self.version = args.version - self.log_mgr = LogMgr.init_cls()(self) + self.log_mgr = LogMgr.init_cls()() self._pos_mgr = PositionMgr() self._prepare_window(args) if args.update: diff --git a/prj.org b/prj.org index e42e35f..6518203 100644 --- a/prj.org +++ b/prj.org @@ -3,7 +3,6 @@ #+CATEGORY: pmachines #+TAGS: bug(b) calendar(c) waiting(w) -* CODE remove GameObject * READY drag and drop positions in the scene files as empty nodes * READY functional tests for performance (frame rate) * READY functional tests for "cleaning" i.e. at the end of the states verify: @@ -14,6 +13,7 @@ - [ ] current nodepaths (render3d) - [ ] current accepting events - [ ] current buffers +* READY refactoring * BACKLOG intro animation (from target item to start position) * BACKLOG buttons of the scenes enabled sequentially - [ ] each scene has a version diff --git a/tests/functional_test.py b/tests/functional_test.py index 9aa1d8a..ddaaaf0 100644 --- a/tests/functional_test.py +++ b/tests/functional_test.py @@ -20,11 +20,10 @@ from sys import exit, argv from panda3d.core import Filename from direct.showbase.ShowBase import ShowBase from direct.gui.OnscreenText import OnscreenText -from ya2.patterns.gameobject import GameObject from ya2.build.build import _branch -class FunctionalTest(GameObject): +class FunctionalTest: screenshot_time = 1.2 evt_time = 1.0 diff --git a/tests/ya2/utils/test_gameobject.py b/tests/ya2/utils/test_gameobject.py deleted file mode 100644 index 58cae86..0000000 --- a/tests/ya2/utils/test_gameobject.py +++ /dev/null @@ -1,228 +0,0 @@ -from pathlib import Path -import sys -if '' in sys.path: sys.path.remove('') -sys.path.append(str(Path(__file__).parent.parent.parent)) -from unittest.mock import patch -from unittest import TestCase -from panda3d.core import loadPrcFileData -#from ya2.engine.engine import Engine -from ya2.patterns.gameobject import AiColleague, AudioColleague, EventColleague, \ - FsmColleague, GameObject, GfxColleague, GuiColleague, LogicColleague, \ - PhysColleague, Colleague - - -class AiTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - #self.engine = Engine() - game_obj = GameObject() - ai = AiColleague(game_obj) - self.assertIsInstance(ai, AiColleague) - - -class AudioTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - #self.engine = Engine() - game_obj = GameObject() - audio = AudioColleague(game_obj) - self.assertIsInstance(audio, AudioColleague) - - -class ColleagueTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - #self.engine = Engine() - game_obj = GameObject() - colleague = Colleague(game_obj) - self.assertIsInstance(colleague, Colleague) - - -class EventTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - #self.engine = Engine() - game_obj = GameObject() - event = EventColleague(game_obj) - self.assertIsInstance(event, EventColleague) - - -class FsmTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - #self.engine = Engine() - game_obj = GameObject() - fsm = FsmColleague(game_obj) - self.assertIsInstance(fsm, FsmColleague) - - -class GfxTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - #self.engine = Engine() - game_obj = GameObject() - gfx = GfxColleague(game_obj) - self.assertIsInstance(gfx, GfxColleague) - - -class GuiTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - pass - #self.engine = Engine() - game_obj = GameObject() - gui = GuiColleague(game_obj) - self.assertIsInstance(gui, GuiColleague) - - -class LogicTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - pass - #self.engine = Engine() - game_obj = GameObject() - logic = LogicColleague(game_obj) - self.assertIsInstance(logic, LogicColleague) - - -class PhysicsTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - def test_init(self): - pass - #self.engine = Engine() - game_obj = GameObject() - phys = PhysColleague(game_obj) - self.assertIsInstance(phys, PhysColleague) - - -class GameObjectInstance(GameObject): - - def __init__(self): - GameObject.__init__(self) - self.fsm = FsmColleague(self) - self.event = EventColleague(self) - self.ai = AiColleague(self) - self.phys = PhysColleague(self) - self.audio = AudioColleague(self) - self.logic = LogicColleague(self) - self.gui = GuiColleague(self) - self.gfx = GfxColleague(self) - - def destroy(self): - self.fsm.destroy() - self.event.destroy() - self.ai.destroy() - self.phys.destroy() - self.audio.destroy() - self.logic.destroy() - self.gui.destroy() - self.gfx.destroy() - - -class GameObjectTests(TestCase): - - def setUp(self): - loadPrcFileData('', 'window-type none') - loadPrcFileData('', 'audio-library-name null') - - def tearDown(self): - pass - #self.engine.destroy() - - @patch.object(GfxColleague, 'destroy') - @patch.object(GuiColleague, 'destroy') - @patch.object(LogicColleague, 'destroy') - @patch.object(AudioColleague, 'destroy') - @patch.object(PhysColleague, 'destroy') - @patch.object(AiColleague, 'destroy') - @patch.object(EventColleague, 'destroy') - @patch.object(FsmColleague, 'destroy') - def test_init( - self, mock_fsm_destroy, mock_event_destroy, mock_ai_destroy, - mock_phys_destroy, mock_audio_destroy, mock_logic_destroy, - mock_gui_destroy, mock_gfx_destroy): - #self.engine = Engine() - mock_event_destroy.__name__ = 'destroy' - game_obj = GameObjectInstance() - self.assertIsInstance(game_obj, GameObject) - game_obj.destroy() - assert mock_fsm_destroy.called - assert mock_event_destroy.called - assert mock_ai_destroy.called - assert mock_phys_destroy.called - assert mock_audio_destroy.called - assert mock_logic_destroy.called - assert mock_gui_destroy.called - assert mock_gfx_destroy.called diff --git a/ya2/patterns/gameobject.py b/ya2/patterns/gameobject.py deleted file mode 100644 index 50dc5a1..0000000 --- a/ya2/patterns/gameobject.py +++ /dev/null @@ -1,100 +0,0 @@ -from direct.fsm.FSM import FSM -from direct.showbase.DirectObject import DirectObject -from ya2.patterns.observer import Subject - - -class Colleague(Subject): - - eng = None - - def __init__(self, mediator): - Subject.__init__(self) - self.mediator = mediator # refactor: remove it - - def destroy(self): - self.mediator = None - Subject.destroy(self) - - -class FsmColleague(FSM, Colleague): - - def __init__(self, mediator): - FSM.__init__(self, self.__class__.__name__) - Colleague.__init__(self, mediator) - - def destroy(self): - if self.state: - self.cleanup() - Colleague.destroy(self) - - -class EventColleague(Colleague, DirectObject): - - def destroy(self): - self.ignoreAll() - Colleague.destroy(self) - - -class AudioColleague(Colleague): - pass - - -class AiColleague(Colleague): - pass - - -class GfxColleague(Colleague): - pass - - -class GuiColleague(Colleague): - pass - - -class LogicColleague(Colleague): - - def on_start(self): pass - - -class PhysColleague(Colleague): - pass - - -class GODirector: - - def __init__(self, tgt_obj, init_lst, end_cb): - self.__obj = tgt_obj - tgt_obj.attach(self.on_comp_blt) - self.end_cb = end_cb - self.completed = [False for _ in init_lst] - self.pending = {} - self.__init_lst = init_lst - for idx, _ in enumerate(init_lst): - self.__process_lst(tgt_obj, idx) - - def __process_lst(self, obj, idx): - if not self.__init_lst[idx]: - self.end_lst(idx) - return - comp_info = self.__init_lst[idx].pop(0) - attr_name, cls, arguments = comp_info - self.pending[cls.__name__] = idx - setattr(obj, attr_name, cls(*arguments)) - - def on_comp_blt(self, obj): - self.__process_lst(obj.mediator, self.pending[obj.__class__.__name__]) - - def end_lst(self, idx): - self.completed[idx] = True - if all(self.completed): - if self.end_cb: - self.end_cb() - self.destroy() - - def destroy(self): - self.__obj.detach(self.on_comp_blt) - self.__obj = self.end_cb = self.__init_lst = None - - -class GameObject(Subject): - pass diff --git a/ya2/utils/cursor.py b/ya2/utils/cursor.py index 0968759..5756a71 100644 --- a/ya2/utils/cursor.py +++ b/ya2/utils/cursor.py @@ -1,6 +1,5 @@ from panda3d.core import GraphicsWindow, WindowProperties from ya2.p3d.gui import P3dImg as Img -from ya2.patterns.gameobject import GameObject class MouseCursorFacade: @@ -13,10 +12,9 @@ class MouseCursorFacade: return self.cursor_img.hide() -class MouseCursor(GameObject, MouseCursorFacade): +class MouseCursor(MouseCursorFacade): def __init__(self, filepath, scale, color, hotspot): - GameObject.__init__(self) MouseCursorFacade.__init__(self) if not filepath: return diff --git a/ya2/utils/dictfile.py b/ya2/utils/dictfile.py index 15f885e..f6c4e55 100644 --- a/ya2/utils/dictfile.py +++ b/ya2/utils/dictfile.py @@ -4,14 +4,12 @@ from os import makedirs from os.path import dirname from collections.abc import Mapping from configparser import ConfigParser -from ya2.patterns.gameobject import GameObject from ya2.p3d.p3d import LibP3d -class DctFile(GameObject): +class DctFile: def __init__(self, fpath, default_dct=None, persistent=True): - GameObject.__init__(self) default_dct = default_dct or {} if sys.platform == 'darwin' and LibP3d.runtime(): fpath = dirname(__file__) + '/' + fpath diff --git a/ya2/utils/functional.py b/ya2/utils/functional.py index f9ff93f..06f67e4 100644 --- a/ya2/utils/functional.py +++ b/ya2/utils/functional.py @@ -7,7 +7,6 @@ from xmlrpc.server import SimpleXMLRPCServer from threading import Thread from panda3d.core import Filename from direct.gui.OnscreenText import OnscreenText -from ya2.patterns.gameobject import GameObject from ya2.build.build import _branch @@ -58,7 +57,7 @@ class RPCServerThread(Thread): self.server.serve_forever() -class FunctionalTest(GameObject): +class FunctionalTest: def __init__(self, ref, pos_mgr): super().__init__() diff --git a/ya2/utils/lang.py b/ya2/utils/lang.py index 20d332a..90bbe71 100644 --- a/ya2/utils/lang.py +++ b/ya2/utils/lang.py @@ -2,7 +2,6 @@ from logging import info from os.path import join, exists, dirname from gettext import translation from pathlib import Path -from ya2.patterns.gameobject import GameObject import sys @@ -34,10 +33,9 @@ def curr_path(): return curr_path + '/' -class LangMgr(GameObject): +class LangMgr: def __init__(self, lang, domain, dpath): - GameObject.__init__(self) self.lang = lang self.domain = domain self.dpath = join(curr_path(), dpath) diff --git a/ya2/utils/log.py b/ya2/utils/log.py index f6b70c5..726ddb5 100755 --- a/ya2/utils/log.py +++ b/ya2/utils/log.py @@ -15,7 +15,6 @@ from sys import version_info # from multiprocessing import cpu_count from panda3d.core import Filename, GraphicsWindow, PandaSystem from panda3d.bullet import get_bullet_version -from ya2.patterns.gameobject import Colleague from ya2.p3d.p3d import LibP3d @@ -41,14 +40,13 @@ basicConfig(level=lev, format='%(asctime)s %(message)s', datefmt='%H:%M:%S') getLogger().setLevel(lev) # it doesn't work otherwise -class LogMgrBase(Colleague): # headless log manager +class LogMgrBase: # headless log manager @staticmethod def init_cls(): return LogMgr if base.win else LogMgrBase - def __init__(self, mediator): - Colleague.__init__(self, mediator) + def __init__(self): self.log_cfg() def log(self, msg, verbose=False):