Move unculled zones out of MapModel.

This commit is contained in:
Dan Albert
2022-02-22 19:37:43 -08:00
parent 95836a217c
commit 1c543666b5
8 changed files with 45 additions and 70 deletions

View File

@@ -18,6 +18,7 @@ class GameUpdateEventsJs(BaseModel):
new_combats: list[FrozenCombatJs] = []
updated_combats: list[FrozenCombatJs] = []
navmesh_updates: set[bool] = set()
unculled_zones_updated: bool = False
@classmethod
def from_events(cls, events: GameUpdateEvents, game: Game) -> GameUpdateEventsJs:
@@ -33,4 +34,5 @@ class GameUpdateEventsJs(BaseModel):
for c in events.updated_combats
],
navmesh_updates=events.navmesh_updates,
unculled_zones_updated=events.unculled_zones_updated,
)

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
from dcs.mapping import LatLng
from pydantic import BaseModel
from game.server.leaflet import LeafletPoly
@@ -9,3 +10,8 @@ class MapZonesJs(BaseModel):
inclusion: list[LeafletPoly]
exclusion: list[LeafletPoly]
sea: list[LeafletPoly]
class UnculledZoneJs(BaseModel):
position: LatLng
radius: float

View File

@@ -2,14 +2,14 @@ from fastapi import APIRouter, Depends, HTTPException, status
from game import Game
from game.server import GameContext
from .models import MapZonesJs
from .models import MapZonesJs, UnculledZoneJs
from ..leaflet import ShapelyUtil
router: APIRouter = APIRouter(prefix="/map-zones")
@router.get("/")
def get(game: Game = Depends(GameContext.get)) -> MapZonesJs:
@router.get("/terrain")
def get_terrain(game: Game = Depends(GameContext.get)) -> MapZonesJs:
zones = game.theater.landmap
if zones is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
@@ -19,3 +19,13 @@ def get(game: Game = Depends(GameContext.get)) -> MapZonesJs:
exclusion=ShapelyUtil.polys_to_leaflet(zones.exclusion_zones, game.theater),
sea=ShapelyUtil.polys_to_leaflet(zones.sea_zones, game.theater),
)
@router.get("/unculled")
def get_unculled_zones(game: Game = Depends(GameContext.get)) -> list[UnculledZoneJs]:
return [
UnculledZoneJs(
position=zone.latlng(), radius=game.settings.perf_culling_distance * 1000
)
for zone in game.get_culling_zones()
]