Rework sim status update to not need a thread.

Rather than polling at 60Hz (which may be faster than the tick rate,
wasting cycles; and also makes synchronization annoying), collect events
during the tick and emit them after (rate limited, pooling events until
it is time for another event to send).

This can be improved by paying attention to the aircraft update list,
which would allow us to avoid updating aircraft that don't have a status
change. To do that we need to be able to quickly lookup a FlightJs
matching a Flight through, and Flight isn't hashable.

We should also be removing dead events and de-duplicating. Currently
each flight has an update for every tick, but only the latest one
matters. Combat update events also don't matter if the same combat is
new in the update.

https://github.com/dcs-liberation/dcs_liberation/issues/1680
This commit is contained in:
Dan Albert
2021-12-23 17:46:24 -08:00
parent 43d5dc0528
commit 656a98675e
23 changed files with 146 additions and 114 deletions

View File

@@ -2,10 +2,8 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from game.sim.combat import FrozenCombat
from game.sim.gameupdateevents import GameUpdateEvents
# Ought to be frozen but mypy can't handle that:
@@ -13,5 +11,4 @@ if TYPE_CHECKING:
@dataclass
class GameUpdateCallbacks:
on_simulation_complete: Callable[[], None]
on_add_combat: Callable[[FrozenCombat], None]
on_combat_changed: Callable[[FrozenCombat], None]
on_update: Callable[[GameUpdateEvents], None]