mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
from datetime import datetime, timedelta
|
|
from typing import TYPE_CHECKING
|
|
|
|
from .flightstate import FlightState
|
|
from .navigating import Navigating
|
|
from ..starttype import StartType
|
|
from ...utils import LBS_TO_KG
|
|
|
|
if TYPE_CHECKING:
|
|
from game.ato.flight import Flight
|
|
from game.settings import Settings
|
|
from game.sim.gameupdateevents import GameUpdateEvents
|
|
|
|
|
|
class Takeoff(FlightState):
|
|
def __init__(self, flight: Flight, settings: Settings, now: datetime) -> None:
|
|
super().__init__(flight, settings)
|
|
# TODO: Not accounted for in FlightPlan, can cause discrepancy without loiter.
|
|
self.completion_time = now + timedelta(seconds=30)
|
|
|
|
def on_game_tick(
|
|
self, events: GameUpdateEvents, time: datetime, duration: timedelta
|
|
) -> None:
|
|
if time < self.completion_time:
|
|
return
|
|
self.flight.set_state(Navigating(self.flight, self.settings, waypoint_index=0))
|
|
|
|
@property
|
|
def is_waiting_for_start(self) -> bool:
|
|
return False
|
|
|
|
@property
|
|
def spawn_type(self) -> StartType:
|
|
return StartType.RUNWAY
|
|
|
|
def estimate_fuel(self) -> float:
|
|
initial_fuel = super().estimate_fuel()
|
|
if self.flight.unit_type.fuel_consumption is None:
|
|
return initial_fuel
|
|
return initial_fuel - self.flight.unit_type.fuel_consumption.taxi * LBS_TO_KG
|
|
|
|
def should_halt_sim(self) -> bool:
|
|
if (
|
|
self.flight.client_count > 0
|
|
and self.settings.player_mission_interrupts_sim_at is StartType.RUNWAY
|
|
):
|
|
logging.info(
|
|
f"Interrupting simulation because {self.flight} has players and has "
|
|
"reached takeoff time"
|
|
)
|
|
return True
|
|
return False
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
return "Taking off"
|