Skip to content

Commit

Permalink
fixed physics on screen queries taking up waaay too much time
Browse files Browse the repository at this point in the history
  • Loading branch information
Kovak committed Feb 8, 2014
1 parent 138f4dd commit b7b6acb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions kivent_cython/kivent_cython/physics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

7 changes: 4 additions & 3 deletions kivent_cython/kivent_cython/renderers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions sample_application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ 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=[],
screenmanager_screen='main_menu')
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',
Expand Down

0 comments on commit b7b6acb

Please sign in to comment.