Push full unculled zone information in the event stream.

https://github.com/dcs-liberation/dcs_liberation/issues/2263
This commit is contained in:
Raffson 2022-06-25 23:09:07 +02:00 committed by GitHub
parent 3eafd0cb62
commit 289545e777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View File

@ -23,7 +23,9 @@ import {
ControlPoint, ControlPoint,
Flight, Flight,
FrontLine, FrontLine,
IadsConnection,
Tgo, Tgo,
UnculledZone,
} from "./liberationApi"; } from "./liberationApi";
import { navMeshUpdated } from "./navMeshSlice"; import { navMeshUpdated } from "./navMeshSlice";
import { updateTgo } from "./tgosSlice"; import { updateTgo } from "./tgosSlice";
@ -31,7 +33,6 @@ import { threatZonesUpdated } from "./threatZonesSlice";
import { unculledZonesUpdated } from "./unculledZonesSlice"; import { unculledZonesUpdated } from "./unculledZonesSlice";
import { LatLng } from "leaflet"; import { LatLng } from "leaflet";
import { updateIadsConnection } from "./iadsNetworkSlice"; import { updateIadsConnection } from "./iadsNetworkSlice";
import { IadsConnection } from "./_liberationApi";
interface GameUpdateEvents { interface GameUpdateEvents {
updated_flight_positions: { [id: string]: LatLng }; updated_flight_positions: { [id: string]: LatLng };
@ -39,7 +40,7 @@ interface GameUpdateEvents {
updated_combats: Combat[]; updated_combats: Combat[];
ended_combats: string[]; ended_combats: string[];
navmesh_updates: boolean[]; navmesh_updates: boolean[];
unculled_zones_updated: boolean; updated_unculled_zones: UnculledZone[];
threat_zones_updated: boolean; threat_zones_updated: boolean;
new_flights: Flight[]; new_flights: Flight[];
updated_flights: string[]; updated_flights: string[];
@ -88,14 +89,8 @@ export const handleStreamedEvents = (
}); });
} }
if (events.unculled_zones_updated) { if (events.updated_unculled_zones.length > 0) {
backend.get(`/map-zones/unculled`).then( dispatch(unculledZonesUpdated(events.updated_unculled_zones));
(result) => {
if (result.data) {
dispatch(unculledZonesUpdated(result.data));
}
}
);
} }
if (events.threat_zones_updated) { if (events.threat_zones_updated) {

View File

@ -514,7 +514,7 @@ class Game:
zones.append(package.target.position) zones.append(package.target.position)
self.__culling_zones = zones self.__culling_zones = zones
events.update_unculled_zones() events.update_unculled_zones(zones)
def add_destroyed_units(self, data: dict[str, Union[float, str]]) -> None: def add_destroyed_units(self, data: dict[str, Union[float, str]]) -> None:
pos = Point( pos = Point(

View File

@ -9,6 +9,7 @@ from game.server.combat.models import FrozenCombatJs
from game.server.flights.models import FlightJs from game.server.flights.models import FlightJs
from game.server.frontlines.models import FrontLineJs from game.server.frontlines.models import FrontLineJs
from game.server.leaflet import LeafletPoint from game.server.leaflet import LeafletPoint
from game.server.mapzones.models import UnculledZoneJs
if TYPE_CHECKING: if TYPE_CHECKING:
from game import Game from game import Game
@ -21,7 +22,7 @@ class GameUpdateEventsJs(BaseModel):
updated_combats: list[FrozenCombatJs] updated_combats: list[FrozenCombatJs]
ended_combats: list[UUID] ended_combats: list[UUID]
navmesh_updates: set[bool] navmesh_updates: set[bool]
unculled_zones_updated: bool updated_unculled_zones: list[UnculledZoneJs]
threat_zones_updated: bool threat_zones_updated: bool
new_flights: list[FlightJs] new_flights: list[FlightJs]
updated_flights: set[UUID] updated_flights: set[UUID]
@ -46,6 +47,7 @@ class GameUpdateEventsJs(BaseModel):
# because we need to send the unload event. # because we need to send the unload event.
new_combats = [] new_combats = []
updated_combats = [] updated_combats = []
updated_unculled_zones = []
if game is not None: if game is not None:
new_combats = [ new_combats = [
FrozenCombatJs.for_combat(c, game.theater) for c in events.new_combats FrozenCombatJs.for_combat(c, game.theater) for c in events.new_combats
@ -54,6 +56,7 @@ class GameUpdateEventsJs(BaseModel):
FrozenCombatJs.for_combat(c, game.theater) FrozenCombatJs.for_combat(c, game.theater)
for c in events.updated_combats for c in events.updated_combats
] ]
updated_unculled_zones = UnculledZoneJs.from_game(game)
return GameUpdateEventsJs( return GameUpdateEventsJs(
updated_flight_positions={ updated_flight_positions={
@ -63,7 +66,7 @@ class GameUpdateEventsJs(BaseModel):
updated_combats=updated_combats, updated_combats=updated_combats,
ended_combats=[c.id for c in events.ended_combats], ended_combats=[c.id for c in events.ended_combats],
navmesh_updates=events.navmesh_updates, navmesh_updates=events.navmesh_updates,
unculled_zones_updated=events.unculled_zones_updated, updated_unculled_zones=updated_unculled_zones,
threat_zones_updated=events.threat_zones_updated, threat_zones_updated=events.threat_zones_updated,
new_flights=[ new_flights=[
FlightJs.for_flight(f, with_waypoints=True) for f in events.new_flights FlightJs.for_flight(f, with_waypoints=True) for f in events.new_flights

View File

@ -22,7 +22,7 @@ class GameUpdateEvents:
ended_combats: list[FrozenCombat] = field(default_factory=list) ended_combats: list[FrozenCombat] = field(default_factory=list)
updated_flight_positions: list[tuple[Flight, Point]] = field(default_factory=list) updated_flight_positions: list[tuple[Flight, Point]] = field(default_factory=list)
navmesh_updates: set[bool] = field(default_factory=set) navmesh_updates: set[bool] = field(default_factory=set)
unculled_zones_updated: bool = False unculled_zones_updated: list[Point] = field(default_factory=list)
threat_zones_updated: bool = False threat_zones_updated: bool = False
new_flights: set[Flight] = field(default_factory=set) new_flights: set[Flight] = field(default_factory=set)
updated_flights: set[UUID] = field(default_factory=set) updated_flights: set[UUID] = field(default_factory=set)
@ -68,8 +68,8 @@ class GameUpdateEvents:
self.navmesh_updates.add(player) self.navmesh_updates.add(player)
return self return self
def update_unculled_zones(self) -> GameUpdateEvents: def update_unculled_zones(self, zones: list[Point]) -> GameUpdateEvents:
self.unculled_zones_updated = True self.unculled_zones_updated = zones
return self return self
def update_threat_zones(self) -> GameUpdateEvents: def update_threat_zones(self) -> GameUpdateEvents: