mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Update the UI to show sim state.
https://github.com/dcs-liberation/dcs_liberation/issues/1704
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Callable, Optional, TYPE_CHECKING
|
||||
|
||||
from PySide2.QtCore import QObject, Signal
|
||||
|
||||
from game.polldebriefingfilethread import PollDebriefingFileThread
|
||||
from game.sim.gameloop import GameLoop
|
||||
from game.sim.simspeedsetting import SimSpeedSetting
|
||||
from game.polldebriefingfilethread import PollDebriefingFileThread
|
||||
from qt_ui.simupdatethread import SimUpdateThread
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
@@ -16,6 +18,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class SimController(QObject):
|
||||
sim_update = Signal()
|
||||
sim_speed_reset = Signal(SimSpeedSetting)
|
||||
simulation_complete = Signal()
|
||||
|
||||
@@ -24,18 +27,28 @@ class SimController(QObject):
|
||||
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:
|
||||
return self.game_loop.completed
|
||||
|
||||
@property
|
||||
def current_time_in_sim(self) -> Optional[datetime]:
|
||||
if self.game_loop is None:
|
||||
return None
|
||||
return self.game_loop.current_time_in_sim
|
||||
|
||||
def set_game(self, game: Optional[Game]) -> None:
|
||||
self.recreate_game_loop(game)
|
||||
self.sim_speed_reset.emit(SimSpeedSetting.PAUSED)
|
||||
|
||||
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:
|
||||
self.game_loop = GameLoop(game, self.on_simulation_complete)
|
||||
self.started = False
|
||||
@@ -48,11 +61,17 @@ 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(
|
||||
@@ -65,11 +84,14 @@ 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