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:
Dan Albert 2023-06-06 21:48:42 -07:00 committed by Raffson
parent 88db6eb5f0
commit b45139bf02
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 47 additions and 51 deletions

View File

@ -123,8 +123,6 @@ def run_ui(game: Optional[Game], ui_flags: UiFlags) -> None:
uiconstants.load_event_icons() uiconstants.load_event_icons()
uiconstants.load_aircraft_icons() uiconstants.load_aircraft_icons()
uiconstants.load_vehicle_icons() uiconstants.load_vehicle_icons()
uiconstants.load_aircraft_banners()
uiconstants.load_vehicle_banners()
# Show warning if no DCS Installation directory was set # Show warning if no DCS Installation directory was set
if liberation_install.get_dcs_install_directory() == "": if liberation_install.get_dcs_install_directory() == "":

View File

@ -1,5 +1,4 @@
import os import os
from pathlib import Path
from typing import Dict from typing import Dict
from PySide2.QtGui import QPixmap from PySide2.QtGui import QPixmap
@ -17,9 +16,7 @@ URLS: Dict[str, str] = {
LABELS_OPTIONS = ["Full", "Abbreviated", "Dot Only", "Neutral Dot", "Off"] LABELS_OPTIONS = ["Full", "Abbreviated", "Dot Only", "Neutral Dot", "Off"]
SKILL_OPTIONS = ["Average", "Good", "High", "Excellent"] SKILL_OPTIONS = ["Average", "Good", "High", "Excellent"]
AIRCRAFT_BANNERS: Dict[str, QPixmap] = {}
AIRCRAFT_ICONS: Dict[str, QPixmap] = {} AIRCRAFT_ICONS: Dict[str, QPixmap] = {}
VEHICLE_BANNERS: Dict[str, QPixmap] = {}
VEHICLES_ICONS: Dict[str, QPixmap] = {} VEHICLES_ICONS: Dict[str, QPixmap] = {}
ICONS: Dict[str, QPixmap] = {} ICONS: Dict[str, QPixmap] = {}
@ -221,39 +218,3 @@ def load_vehicle_icons():
os.path.join("./resources/ui/units/vehicles/icons/", vehicle) os.path.join("./resources/ui/units/vehicles/icons/", vehicle)
) )
VEHICLES_ICONS["(IDF Mods Project) BM-21 Grad 122mm"] = VEHICLES_ICONS["Grad-URAL"] VEHICLES_ICONS["(IDF Mods Project) BM-21 Grad 122mm"] = VEHICLES_ICONS["Grad-URAL"]
def load_aircraft_banners():
for path in Path().glob("resources/ui/units/aircrafts/banners/*.jpg"):
AIRCRAFT_BANNERS[path.stem] = QPixmap(path)
_load_mirage_banners()
_load_su30mod_banners()
def _load_mirage_banners():
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_su30mod_banners():
variants = ["Su-30MKA", "Su-30MKI", "Su-30MKM"]
for su30 in variants:
AIRCRAFT_BANNERS[su30] = AIRCRAFT_BANNERS["Su-30SM"]
def load_vehicle_banners():
for path in Path().glob("resources/ui/units/vehicles/banners/*.jpg"):
VEHICLE_BANNERS[path.stem] = QPixmap(path)
VEHICLE_BANNERS["(IDF Mods Project) BM-21 Grad 122mm"] = VEHICLE_BANNERS[
"Grad-URAL"
]
VEHICLE_BANNERS["(IDF Mods Project) Urgan BM-27 220mm"] = VEHICLE_BANNERS[
"Uragan_BM-27"
]
VEHICLE_BANNERS["(IDF Mods Project) 9A52 Smerch CM 300mm"] = VEHICLE_BANNERS[
"Smerch_HE"
]

View File

@ -1,7 +1,9 @@
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from PySide2.QtCore import Qt from PySide2.QtCore import Qt
from PySide2.QtGui import QIcon from PySide2.QtGui import QIcon, QPixmap
from PySide2.QtWidgets import ( from PySide2.QtWidgets import (
QDialog, QDialog,
QGridLayout, QGridLayout,
@ -14,7 +16,46 @@ from game.dcs.aircrafttype import AircraftType
from game.dcs.groundunittype import GroundUnitType from game.dcs.groundunittype import GroundUnitType
from game.dcs.unittype import UnitType from game.dcs.unittype import UnitType
from game.game import Game 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"
elif unit_type.dcs_id in {"Su-30MKA", "Su-30MKI", "Su-30MKM"}:
name = "Su-30SM"
else:
name = unit_type.dcs_id
return AIRCRAFT_BANNERS_BASE / f"{name}.jpg"
def vehicle_banner_for(unit_type: GroundUnitType) -> Path:
if unit_type.dcs_id == "(IDF Mods Project) BM-21 Grad 122mm":
return VEHICLE_BANNERS_BASE / "Grad-URAL.jpg"
elif unit_type.dcs_id == "(IDF Mods Project) Urgan BM-27 220mm":
return VEHICLE_BANNERS_BASE / "Uragan_BM-27.jpg"
elif unit_type.dcs_id == "(IDF Mods Project) 9A52 Smerch CM 300mm":
return VEHICLE_BANNERS_BASE / "Smerch_HE.jpg"
else:
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): class QUnitInfoWindow(QDialog):
@ -35,14 +76,10 @@ class QUnitInfoWindow(QDialog):
header = QLabel(self) header = QLabel(self)
header.setGeometry(0, 0, 720, 360) header.setGeometry(0, 0, 720, 360)
pixmap = None banner_path = banner_path_for(unit_type)
if not banner_path.exists():
if isinstance(self.unit_type, AircraftType): banner_path = MISSING_BANNER_PATH
pixmap = AIRCRAFT_BANNERS.get(self.unit_type.dcs_id) pixmap = QPixmap(banner_path.as_posix())
elif isinstance(self.unit_type, GroundUnitType):
pixmap = VEHICLE_BANNERS.get(self.unit_type.dcs_id)
if pixmap is None:
pixmap = AIRCRAFT_BANNERS.get("Missing")
header.setPixmap(pixmap.scaled(header.width(), header.height())) header.setPixmap(pixmap.scaled(header.width(), header.height()))
self.layout.addWidget(header, 0, 0) self.layout.addWidget(header, 0, 0)