Skip to content

Commit 39bbdcd

Browse files
committed
Move position sending to Physics plugin
1 parent a192bb7 commit 39bbdcd

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

spockbot/plugins/helpers/movement.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ def final_target(self):
4040
class MovementPlugin(PluginBase):
4141
requires = ('ClientInfo', 'Event', 'Net', 'Pathfinding', 'Physics')
4242
events = {
43-
'client_tick': 'client_tick',
44-
'client_position_update': 'handle_position_update',
4543
'client_join_game': 'handle_join_game',
4644
}
4745

@@ -50,25 +48,12 @@ def __init__(self, ploader, settings):
5048

5149
self.flag_pos_reset = False
5250
self.movement = MovementCore(self)
53-
self.connected_to_server = False
54-
ploader.provides('Movement', self.movement)
5551
self.path_nodes = None
56-
57-
def client_tick(self, name, data):
58-
if not self.connected_to_server:
59-
return
60-
self.net.push_packet('PLAY>Player Position and Look',
61-
self.clientinfo.position.get_dict())
62-
if self.flag_pos_reset:
63-
self.event.emit('movement_position_reset')
64-
self.flag_pos_reset = False
52+
ploader.provides('Movement', self.movement)
6553

6654
def handle_join_game(self, name, data):
6755
self.connected_to_server = True
6856

69-
def handle_position_update(self, name, data):
70-
self.flag_pos_reset = True
71-
7257
def new_path(self, *xyz):
7358
target = Vector3(*xyz)
7459
self.pathfinding.pathfind(

spockbot/plugins/helpers/physics.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ def move_angle(self, angle, radians=False):
6666

6767
@pl_announce('Physics')
6868
class PhysicsPlugin(PluginBase):
69-
requires = ('Event', 'ClientInfo', 'World')
69+
requires = ('Event', 'ClientInfo', 'Net', 'World')
7070
events = {
71-
'physics_tick': 'tick',
72-
'client_position_update': 'stop_physics',
73-
'movement_position_reset': 'start_physics',
71+
'physics_tick': 'physics_tick',
72+
'client_tick': 'client_tick',
73+
'client_position_update': 'pause_physics',
7474
}
7575

7676
def __init__(self, ploader, settings):
@@ -80,21 +80,23 @@ def __init__(self, ploader, settings):
8080
self.world, BoundingBox(const.PLAYER_WIDTH, const.PLAYER_HEIGHT)
8181
)
8282
self.pos = self.clientinfo.position
83-
self.pause_physics = False
83+
self.skip_tick = False
8484
self.pc = PhysicsCore(self.pos, self.vec, self.clientinfo.abilities)
8585
ploader.provides('Physics', self.pc)
8686

87-
def stop_physics(self, _=None, __=None):
87+
def pause_physics(self, _=None, __=None):
8888
self.vec.zero()
89-
self.pause_physics = True
89+
self.skip_tick = True
9090

91-
def start_physics(self, _=None, __=None):
92-
self.pause_physics = False
93-
self.event.reg_event_handler('physics_tick', self.tick)
91+
def client_tick(self, name, data):
92+
self.net.push_packet('PLAY>Player Position and Look',
93+
self.clientinfo.position.get_dict())
94+
if self.skip_tick:
95+
self.skip_tick = False
9496

95-
def tick(self, _, __):
96-
if self.pause_physics:
97-
return self.pause_physics
97+
def physics_tick(self, _, __):
98+
if self.skip_tick:
99+
return
98100
self.apply_accel()
99101
mtv = self.get_mtv()
100102
self.apply_vector(mtv)

spockbot/plugins/tools/collision.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ def uncenter_position(pos, bbox):
1313

1414

1515
def gen_block_set(block_pos, xr=(-1, 2), yr=(0, 3), zr=(-1, 2)):
16-
offsets = (
17-
(x, y, z)
16+
pos = block_pos.floor()
17+
return (
18+
pos + Vector3(x, y, z)
1819
for x in range(*xr) for y in range(*yr) for z in range(*zr)
1920
)
20-
pos = block_pos.floor()
21-
return (pos + Vector3(*offset) for offset in offsets)
2221

2322

2423
# Axis must be a normalized/unit vector

0 commit comments

Comments
 (0)