aboutsummaryrefslogtreecommitdiff
path: root/static/src
diff options
context:
space:
mode:
Diffstat (limited to 'static/src')
-rw-r--r--static/src/main.ts6
-rw-r--r--static/src/mouse_controller.ts15
-rw-r--r--static/src/network.ts6
3 files changed, 12 insertions, 15 deletions
diff --git a/static/src/main.ts b/static/src/main.ts
index 16de636..c3588de 100644
--- a/static/src/main.ts
+++ b/static/src/main.ts
@@ -65,9 +65,11 @@ class KennelClient {
break;
}
}
-
- console.log(events, dt);
+ if (events.length > 0) {
+ console.log(events, dt);
+ }
this.event_queue.clear();
+ this.event_publisher.publish();
}
private process_set_controllable_event(event: SetControllableEvent) {
diff --git a/static/src/mouse_controller.ts b/static/src/mouse_controller.ts
index c7ae304..bd8d51a 100644
--- a/static/src/mouse_controller.ts
+++ b/static/src/mouse_controller.ts
@@ -7,7 +7,6 @@ export class MouseController {
constructor(
private readonly publisher: (new_movement: Vec2) => void | Promise<void>,
private readonly debounce_ms = 200,
- private readonly l2_norm_threshold = 40,
) {}
public start() {
@@ -29,20 +28,14 @@ export class MouseController {
}
public move(x: number, y: number) {
- const new_movement = new Vec2(x, y);
- if (
- typeof this.last_movement !== "undefined" &&
- new_movement.distance_to(this.last_movement) >= this.l2_norm_threshold
- ) {
- this.publish_movement();
- }
- this.last_movement = new_movement;
+ this.last_movement = new Vec2(x, y);
+ this.publish_movement();
}
private publish_movement() {
if (
- typeof this.last_movement === "undefined" ||
- Date.now() - this.last_event_time < this.debounce_ms
+ Date.now() - this.last_event_time < this.debounce_ms ||
+ typeof this.last_movement === "undefined"
) {
return;
}
diff --git a/static/src/network.ts b/static/src/network.ts
index f707148..fac96df 100644
--- a/static/src/network.ts
+++ b/static/src/network.ts
@@ -66,8 +66,7 @@ export class WebSocketEventQueue implements EventQueue {
private listen_to(websocket: WebSocket) {
websocket.onmessage = ({ data }) => {
- const [event_type, event_data] = JSON.parse(data);
- this.queue.push({ event_type, data: event_data } as Event);
+ this.queue = this.queue.concat(JSON.parse(data));
};
}
}
@@ -84,6 +83,9 @@ export class WebsocketEventPublisher implements EventPublisher {
}
public publish() {
+ if (this.queue.length === 0) {
+ return;
+ }
this.websocket.send(JSON.stringify(this.queue));
this.queue = [];
}