Skip to content

Commit

Permalink
Physics only sends pitch/yaw if they changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gjum committed Jan 9, 2016
1 parent 6125aa9 commit 447d296
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions spockbot/plugins/helpers/physics.py
Expand Up @@ -82,6 +82,7 @@ def __init__(self, ploader, settings):
self.world, BoundingBox(const.PLAYER_WIDTH, const.PLAYER_HEIGHT)
)
self.pos = self.clientinfo.position
self.prev_dict = None
self.skip_tick = False
self.pc = PhysicsCore(self.pos, self.vec, self.clientinfo.abilities)
ploader.provides('Physics', self.pc)
Expand All @@ -98,8 +99,13 @@ def resume_physics(self, _=None, __=None):
self.event.reg_event_handler('physics_tick', self.physics_tick)

def client_tick(self, name, data):
self.net.push_packet('PLAY>Player Position and Look',
self.clientinfo.position.get_dict())
current_dict = self.clientinfo.position.get_dict()
if self.prev_dict and self.prev_dict['yaw'] == current_dict['yaw'] \
and self.prev_dict['pitch'] == current_dict['pitch']:
self.net.push_packet('PLAY>Player Position', current_dict)
else:
self.net.push_packet('PLAY>Player Position and Look', current_dict)
self.prev_dict = current_dict

def physics_tick(self, _, __):
if self.skip_tick:
Expand Down

1 comment on commit 447d296

@nickelpro
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pointless comparison, server doesn't complain when we send Position and Look and we'll spend a longer time calculating this than we gain in the marginal improvement to serverbound traffic (which is already minimal)

Please sign in to comment.