mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add websocket event stream for sim updates.
As a proof of concept this only covers the flight positions.
This commit is contained in:
@@ -72,6 +72,11 @@ class GameLoop:
|
||||
self.completed = True
|
||||
|
||||
def send_update(self, rate_limit: bool) -> None:
|
||||
# We don't skip empty events because we still want the tick in the Qt part of
|
||||
# the UI, which will update things like the current simulation time. The time
|
||||
# probably be an "event" of its own. For now the websocket endpoint will filter
|
||||
# out empty events to avoid the map handling unnecessary events, but we still
|
||||
# pass the events through to Qt.
|
||||
now = datetime.now()
|
||||
time_since_update = now - self.last_update_time
|
||||
if not rate_limit or time_since_update >= timedelta(seconds=1 / 60):
|
||||
|
||||
@@ -2,6 +2,8 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from dcs import Point
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game.ato import Flight
|
||||
from game.sim.combat import FrozenCombat
|
||||
@@ -12,7 +14,18 @@ class GameUpdateEvents:
|
||||
self.simulation_complete = False
|
||||
self.new_combats: list[FrozenCombat] = []
|
||||
self.updated_combats: list[FrozenCombat] = []
|
||||
self.updated_flights: list[Flight] = []
|
||||
self.updated_flights: list[tuple[Flight, Point]] = []
|
||||
|
||||
@property
|
||||
def empty(self) -> bool:
|
||||
return not any(
|
||||
[
|
||||
self.simulation_complete,
|
||||
self.new_combats,
|
||||
self.updated_combats,
|
||||
self.updated_flights,
|
||||
]
|
||||
)
|
||||
|
||||
def complete_simulation(self) -> None:
|
||||
self.simulation_complete = True
|
||||
@@ -23,5 +36,5 @@ class GameUpdateEvents:
|
||||
def update_combat(self, combat: FrozenCombat) -> None:
|
||||
self.updated_combats.append(combat)
|
||||
|
||||
def update_flight(self, flight: Flight) -> None:
|
||||
self.updated_flights.append(flight)
|
||||
def update_flight(self, flight: Flight, new_position: Point) -> None:
|
||||
self.updated_flights.append((flight, new_position))
|
||||
|
||||
Reference in New Issue
Block a user