mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
A possible explanation for the infrequent CTDs we've been seeing since adding fast forward is that QWebChannel doesn't keep a reference to the python objects that it passes to js, so if the object is GC'd before the front end is done with it, it crashes. We don't really like QWebChannel anyway, so this begins replacing that with FastAPI.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from PySide2.QtCore import Property, QObject, Signal
|
|
|
|
from game import Game
|
|
from game.navmesh import NavMesh
|
|
from game.server.leaflet import LeafletPoly
|
|
from game.theater import ConflictTheater
|
|
from .navmeshpolyjs import NavMeshPolyJs
|
|
|
|
|
|
class NavMeshJs(QObject):
|
|
blueChanged = Signal()
|
|
redChanged = Signal()
|
|
|
|
def __init__(self, blue: list[NavMeshPolyJs], red: list[NavMeshPolyJs]) -> None:
|
|
super().__init__()
|
|
self._blue = blue
|
|
self._red = red
|
|
# TODO: Boundary markers.
|
|
# TODO: Numbering.
|
|
# TODO: Localization debugging.
|
|
|
|
@Property(list, notify=blueChanged)
|
|
def blue(self) -> list[LeafletPoly]:
|
|
return self._blue
|
|
|
|
@Property(list, notify=redChanged)
|
|
def red(self) -> list[LeafletPoly]:
|
|
return self._red
|
|
|
|
@staticmethod
|
|
def to_polys(navmesh: NavMesh, theater: ConflictTheater) -> list[NavMeshPolyJs]:
|
|
polys = []
|
|
for poly in navmesh.polys:
|
|
polys.append(NavMeshPolyJs.from_navmesh(poly, theater))
|
|
return polys
|
|
|
|
@classmethod
|
|
def from_game(cls, game: Game) -> NavMeshJs:
|
|
return NavMeshJs(
|
|
cls.to_polys(game.blue.nav_mesh, game.theater),
|
|
cls.to_polys(game.red.nav_mesh, game.theater),
|
|
)
|