Dan Albert 656a98675e 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
2021-12-23 17:46:24 -08:00

66 lines
1.6 KiB
Python

from __future__ import annotations
from abc import ABC, abstractmethod
from datetime import datetime, timedelta
from typing import Optional, TYPE_CHECKING
from game.ato.starttype import StartType
if TYPE_CHECKING:
from game.ato.flight import Flight
from game.settings import Settings
from game.sim.gameupdateevents import GameUpdateEvents
from game.threatzones import ThreatPoly
class FlightState(ABC):
def __init__(self, flight: Flight, settings: Settings) -> None:
self.flight = flight
self.settings = settings
@abstractmethod
def on_game_tick(
self, events: GameUpdateEvents, time: datetime, duration: timedelta
) -> None:
...
@property
def vulnerable_to_intercept(self) -> bool:
return False
@property
def vulnerable_to_sam(self) -> bool:
return False
@property
def will_join_air_combat(self) -> bool:
return False
def should_halt_sim(self) -> bool:
return False
@property
@abstractmethod
def is_waiting_for_start(self) -> bool:
...
@property
@abstractmethod
def spawn_type(self) -> StartType:
...
def a2a_commit_region(self) -> Optional[ThreatPoly]:
return None
def estimate_fuel(self) -> float:
"""Returns the estimated remaining fuel **in kilograms**."""
if (max_takeoff_fuel := self.flight.max_takeoff_fuel()) is not None:
return max_takeoff_fuel
return self.flight.unit_type.dcs_unit_type.fuel_max
@property
@abstractmethod
def description(self) -> str:
"""Describes the current flight state."""
...