From b7b6acb54ca511184fe896fa940fffea417c358f Mon Sep 17 00:00:00 2001 From: Kovak Date: Sat, 8 Feb 2014 06:53:09 -0700 Subject: [PATCH] fixed physics on screen queries taking up waaay too much time --- kivent_cython/kivent_cython/physics.pyx | 2 ++ kivent_cython/kivent_cython/renderers.pyx | 7 ++++--- sample_application/main.py | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kivent_cython/kivent_cython/physics.pyx b/kivent_cython/kivent_cython/physics.pyx index 10e7bfa2..6b938d1c 100644 --- a/kivent_cython/kivent_cython/physics.pyx +++ b/kivent_cython/kivent_cython/physics.pyx @@ -19,6 +19,7 @@ class CymunkPhysics(GameSystem): super(CymunkPhysics, self).__init__(**kwargs) self.bb_query_result = list() self.segment_query_result = list() + self.on_screen_result = list() self.init_physics() def add_collision_handler(self, int type_a, int type_b, begin_func=None, @@ -193,4 +194,5 @@ class CymunkPhysics(GameSystem): system_data['position'] = body.position system_data['angle'] = body.angle - M_PI_2 system_data['unit_vector'] = body.rotation_vector + self.on_screen_result = self.query_on_screen() diff --git a/kivent_cython/kivent_cython/renderers.pyx b/kivent_cython/kivent_cython/renderers.pyx index 407d325b..643b45d0 100644 --- a/kivent_cython/kivent_cython/renderers.pyx +++ b/kivent_cython/kivent_cython/renderers.pyx @@ -333,7 +333,7 @@ class DynamicRenderer(Renderer): cdef list on_screen if self.physics_system in systems: physics_system = systems[self.physics_system] - on_screen = physics_system.query_on_screen() + on_screen = [x for x in physics_system.on_screen_result] else: on_screen = [] cdef dict entity @@ -346,9 +346,10 @@ class DynamicRenderer(Renderer): if system_id not in entity: continue system_data = entity[system_id] - if not system_data['on_screen'] and entity_id in on_screen: + on_screen_status = system_data['on_screen'] + if not on_screen_status and entity_id in on_screen: system_data['on_screen'] = True - if system_data['on_screen'] and not entity_id in on_screen: + if on_screen_status and not entity_id in on_screen: system_data['on_screen'] = False if entity_id in on_screen: tr_a(entity_id) diff --git a/sample_application/main.py b/sample_application/main.py index 3b4fae8a..2b48851f 100644 --- a/sample_application/main.py +++ b/sample_application/main.py @@ -76,9 +76,10 @@ def setup_states(self): self.gameworld.add_state(state_name='main_menu', systems_added=[ 'static_renderer', 'default_map'], systems_removed=['physics_renderer', 'particle_manager', - 'lighting_renderer', 'probe_system', 'background_renderer'], + 'lighting_renderer', 'static_renderer', + 'probe_system', 'background_renderer'], systems_paused=['cymunk-physics', 'default_gameview', - 'physics_renderer', 'background_renderer', + 'physics_renderer', 'background_renderer', 'static_renderer', 'particle_manager', 'asteroid_system', 'ship_system', 'lighting_renderer', 'probe_system', 'ship_ai_system'], systems_unpaused=[], @@ -86,7 +87,8 @@ def setup_states(self): self.gameworld.add_state(state_name='choose_character', systems_added=[ 'static_renderer', 'default_map'], systems_removed=['physics_renderer', 'particle_manager', - 'lighting_renderer','probe_system', 'background_renderer'], + 'lighting_renderer','probe_system', 'background_renderer', + 'static_renderer'], systems_paused=['cymunk-physics', 'default_gameview', 'physics_renderer', 'static_renderer', 'background_renderer', 'particle_manager', 'asteroid_system',