mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add locking to some UI actions.
This is by no means complete. The bugs that this solves were already in 6.x, but we'd hidden the speed controls for the sim in that release, and have always said that anything done after pressing "go" the first time is undefined behavior. This is the first step on making those mid-sim actions behave correctly. UI actions such as creating a new package need to be executed between ticks of the sim. We can either do this synchronously by blocking the UI until the tick is done executing, acquiring a lock on the sim, executing the action, then releasing the lock; or asynchronously by queueing events and letting the sim execute them when it completes the current tick (or instantly if the sim is paused). Anything that comes from the new UI (currently just the map) must be asynchronous because it goes through the REST API, but for the old UI it's simpler (and because the lock will only be acquired as quickly as the user can act, shouldn't slow anything down) to do this synchronously, since it's difficult to use coroutines in Qt. https://github.com/dcs-liberation/dcs_liberation/issues/1680
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Callable, Optional, TYPE_CHECKING
|
||||
@@ -76,6 +78,11 @@ class SimController(QObject):
|
||||
self.started = True
|
||||
self.game_loop.set_simulation_speed(simulation_speed)
|
||||
|
||||
@contextmanager
|
||||
def paused_sim(self) -> Iterator[None]:
|
||||
with self.game_loop.paused_sim():
|
||||
yield
|
||||
|
||||
def run_to_first_contact(self) -> None:
|
||||
self.game_loop.run_to_first_contact()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user