mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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:
@@ -8,11 +8,10 @@ from typing import Callable, Optional, TYPE_CHECKING
|
||||
from PySide2.QtCore import QObject, Signal
|
||||
|
||||
from game.polldebriefingfilethread import PollDebriefingFileThread
|
||||
from game.sim.combat import FrozenCombat
|
||||
from game.sim.gameloop import GameLoop
|
||||
from game.sim.gameupdatecallbacks import GameUpdateCallbacks
|
||||
from game.sim.gameupdateevents import GameUpdateEvents
|
||||
from game.sim.simspeedsetting import SimSpeedSetting
|
||||
from qt_ui.simupdatethread import SimUpdateThread
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
@@ -20,19 +19,15 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class SimController(QObject):
|
||||
sim_update = Signal()
|
||||
sim_update = Signal(GameUpdateEvents)
|
||||
sim_speed_reset = Signal(SimSpeedSetting)
|
||||
simulation_complete = Signal()
|
||||
on_add_combat = Signal(FrozenCombat)
|
||||
on_combat_changed = Signal(FrozenCombat)
|
||||
|
||||
def __init__(self, game: Optional[Game]) -> None:
|
||||
super().__init__()
|
||||
self.game_loop: Optional[GameLoop] = None
|
||||
self.recreate_game_loop(game)
|
||||
self.started = False
|
||||
self._sim_update_thread = SimUpdateThread(self.sim_update.emit)
|
||||
self._sim_update_thread.start()
|
||||
|
||||
@property
|
||||
def completed(self) -> bool:
|
||||
@@ -54,12 +49,8 @@ class SimController(QObject):
|
||||
self.recreate_game_loop(game)
|
||||
self.sim_speed_reset.emit(SimSpeedSetting.PAUSED)
|
||||
|
||||
def shut_down(self) -> None:
|
||||
self._sim_update_thread.stop()
|
||||
|
||||
def recreate_game_loop(self, game: Optional[Game]) -> None:
|
||||
if self.game_loop is not None:
|
||||
self._sim_update_thread.on_sim_pause()
|
||||
self.game_loop.pause()
|
||||
self.game_loop = None
|
||||
if game is not None:
|
||||
@@ -67,8 +58,7 @@ class SimController(QObject):
|
||||
game,
|
||||
GameUpdateCallbacks(
|
||||
self.on_simulation_complete,
|
||||
self.on_add_combat.emit,
|
||||
self.on_combat_changed.emit,
|
||||
self.sim_update.emit,
|
||||
),
|
||||
)
|
||||
self.started = False
|
||||
@@ -81,17 +71,11 @@ class SimController(QObject):
|
||||
self.game_loop.start()
|
||||
self.started = True
|
||||
self.game_loop.set_simulation_speed(simulation_speed)
|
||||
if simulation_speed is SimSpeedSetting.PAUSED:
|
||||
self._sim_update_thread.on_sim_pause()
|
||||
else:
|
||||
self._sim_update_thread.on_sim_unpause()
|
||||
|
||||
def run_to_first_contact(self) -> None:
|
||||
self.game_loop.run_to_first_contact()
|
||||
self.sim_update.emit()
|
||||
|
||||
def generate_miz(self, output: Path) -> None:
|
||||
self._sim_update_thread.on_sim_pause()
|
||||
self.game_loop.pause_and_generate_miz(output)
|
||||
|
||||
def wait_for_debriefing(
|
||||
@@ -104,14 +88,11 @@ class SimController(QObject):
|
||||
def debrief_current_state(
|
||||
self, state_path: Path, force_end: bool = False
|
||||
) -> Debriefing:
|
||||
self._sim_update_thread.on_sim_pause()
|
||||
return self.game_loop.pause_and_debrief(state_path, force_end)
|
||||
|
||||
def process_results(self, debriefing: Debriefing) -> None:
|
||||
self._sim_update_thread.on_sim_pause()
|
||||
return self.game_loop.complete_with_results(debriefing)
|
||||
|
||||
def on_simulation_complete(self) -> None:
|
||||
logging.debug("Simulation complete")
|
||||
self._sim_update_thread.on_sim_pause()
|
||||
self.simulation_complete.emit()
|
||||
|
||||
Reference in New Issue
Block a user