mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Stop preloading images that are rarely used.
The aircraft banners are only used for the unit info window, and that's not a normal part of gameplay. We spend a bit over 1.5 seconds preloading this data at startup (about 25% of the non-game load startup time). This data is only expensive to load in aggregate, and we never need all of it. The unit info window is not noticeably slowed by this, but startup is noticeably faster without it.
This commit is contained in:
parent
8a861d3da5
commit
e44b6b416b
@ -111,8 +111,6 @@ def run_ui(create_game_params: CreateGameParams | None, ui_flags: UiFlags) -> No
|
||||
uiconstants.load_event_icons()
|
||||
uiconstants.load_aircraft_icons()
|
||||
uiconstants.load_vehicle_icons()
|
||||
uiconstants.load_aircraft_banners()
|
||||
uiconstants.load_vehicle_banners()
|
||||
|
||||
# Show warning if no DCS Installation directory was set
|
||||
if liberation_install.get_dcs_install_directory() == "":
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
from PySide6.QtGui import QPixmap
|
||||
@ -9,15 +8,12 @@ from .liberation_theme import get_theme_icons
|
||||
LABELS_OPTIONS = ["Full", "Abbreviated", "Dot Only", "Neutral Dot", "Off"]
|
||||
SKILL_OPTIONS = ["Average", "Good", "High", "Excellent"]
|
||||
|
||||
AIRCRAFT_BANNERS: Dict[str, QPixmap] = {}
|
||||
AIRCRAFT_ICONS: Dict[str, QPixmap] = {}
|
||||
VEHICLE_BANNERS: Dict[str, QPixmap] = {}
|
||||
VEHICLES_ICONS: Dict[str, QPixmap] = {}
|
||||
ICONS: Dict[str, QPixmap] = {}
|
||||
|
||||
|
||||
def load_icons():
|
||||
|
||||
ICONS["New"] = QPixmap("./resources/ui/misc/" + get_theme_icons() + "/new.png")
|
||||
ICONS["Open"] = QPixmap("./resources/ui/misc/" + get_theme_icons() + "/open.png")
|
||||
ICONS["Save"] = QPixmap("./resources/ui/misc/" + get_theme_icons() + "/save.png")
|
||||
@ -214,19 +210,3 @@ def load_vehicle_icons():
|
||||
VEHICLES_ICONS[vehicle[:-7]] = QPixmap(
|
||||
os.path.join("./resources/ui/units/vehicles/icons/", vehicle)
|
||||
)
|
||||
|
||||
|
||||
def load_aircraft_banners() -> None:
|
||||
for path in Path().glob("resources/ui/units/aircrafts/banners/*.jpg"):
|
||||
AIRCRAFT_BANNERS[path.stem] = QPixmap(path)
|
||||
variants = ["Mirage-F1CT", "Mirage-F1EE", "Mirage-F1M-EE", "Mirage-F1EQ"]
|
||||
for f1 in variants:
|
||||
AIRCRAFT_BANNERS[f1] = AIRCRAFT_BANNERS["Mirage-F1C-200"]
|
||||
variants = ["Mirage-F1CE", "Mirage-F1M-CE"]
|
||||
for f1 in variants:
|
||||
AIRCRAFT_BANNERS[f1] = AIRCRAFT_BANNERS["Mirage-F1C"]
|
||||
|
||||
|
||||
def load_vehicle_banners() -> None:
|
||||
for path in Path().glob("resources/ui/units/vehicles/banners/*.jpg"):
|
||||
VEHICLE_BANNERS[path.stem] = QPixmap(path)
|
||||
|
||||
@ -1,14 +1,46 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtGui import QIcon, QPixmap
|
||||
from PySide6.QtWidgets import QDialog, QFrame, QGridLayout, QLabel, QTextBrowser
|
||||
|
||||
from game.dcs.aircrafttype import AircraftType
|
||||
from game.dcs.groundunittype import GroundUnitType
|
||||
from game.dcs.unittype import UnitType
|
||||
from game.game import Game
|
||||
from qt_ui.uiconstants import AIRCRAFT_BANNERS, VEHICLE_BANNERS
|
||||
|
||||
AIRCRAFT_BANNERS_BASE = Path("resources/ui/units/aircrafts/banners")
|
||||
VEHICLE_BANNERS_BASE = Path("resources/ui/units/vehicles/banners")
|
||||
MISSING_BANNER_PATH = AIRCRAFT_BANNERS_BASE / "Missing.jpg"
|
||||
|
||||
|
||||
def aircraft_banner_for(unit_type: AircraftType) -> Path:
|
||||
if unit_type.dcs_id in {
|
||||
"Mirage-F1CT",
|
||||
"Mirage-F1EE",
|
||||
"Mirage-F1M-EE",
|
||||
"Mirage-F1EQ",
|
||||
}:
|
||||
name = "Mirage-F1C-200"
|
||||
elif unit_type.dcs_id in {"Mirage-F1CE", "Mirage-F1M-CE"}:
|
||||
name = "Mirage-F1C"
|
||||
else:
|
||||
name = unit_type.dcs_id
|
||||
return AIRCRAFT_BANNERS_BASE / f"{name}.jpg"
|
||||
|
||||
|
||||
def vehicle_banner_for(unit_type: GroundUnitType) -> Path:
|
||||
return VEHICLE_BANNERS_BASE / f"{unit_type.dcs_id}.jpg"
|
||||
|
||||
|
||||
def banner_path_for(unit_type: UnitType) -> Path:
|
||||
if isinstance(unit_type, AircraftType):
|
||||
return aircraft_banner_for(unit_type)
|
||||
if isinstance(unit_type, GroundUnitType):
|
||||
return vehicle_banner_for(unit_type)
|
||||
raise NotImplementedError(f"Unhandled UnitType subclass: {unit_type.__class__}")
|
||||
|
||||
|
||||
class QUnitInfoWindow(QDialog):
|
||||
@ -29,14 +61,10 @@ class QUnitInfoWindow(QDialog):
|
||||
header = QLabel(self)
|
||||
header.setGeometry(0, 0, 720, 360)
|
||||
|
||||
pixmap = None
|
||||
|
||||
if isinstance(self.unit_type, AircraftType):
|
||||
pixmap = AIRCRAFT_BANNERS.get(self.unit_type.dcs_id)
|
||||
elif isinstance(self.unit_type, GroundUnitType):
|
||||
pixmap = VEHICLE_BANNERS.get(self.unit_type.dcs_id)
|
||||
if pixmap is None:
|
||||
pixmap = AIRCRAFT_BANNERS.get("Missing")
|
||||
banner_path = banner_path_for(unit_type)
|
||||
if not banner_path.exists():
|
||||
banner_path = MISSING_BANNER_PATH
|
||||
pixmap = QPixmap(banner_path)
|
||||
header.setPixmap(pixmap.scaled(header.width(), header.height()))
|
||||
self.layout.addWidget(header, 0, 0)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user