Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
def main(args: argparse.Namespace, maxnbplayers: int) -> int:
original_rom = args.rom

# squashfs roms if squashed
if original_rom.suffix == ".squashfs":
# squashfs roms if squashed, the windows systems name theirs .wsquashfs
if original_rom.suffix in ('.squashfs', '.wsquashfs'):
with mount_squashfs(original_rom) as squash_rom:
return start_rom(args, maxnbplayers, squash_rom, original_rom)
else:
Expand Down Expand Up @@ -103,8 +103,8 @@ def start_rom(args: argparse.Namespace, maxnbplayers: int, rom: Path, original_r
generator = get_generator(system.config.emulator, system.config.core)

with (
mount_overlayfs(rom, SAVES / system.name / original_rom.stem)
if original_rom.suffix == ".squashfs" and generator.writesToRom(system.config)
mount_overlayfs(rom, generator.writableRomDir(system, original_rom))
if original_rom.suffix in ('.squashfs', '.wsquashfs') and generator.writesToRom(system.config)
else contextlib.nullcontext(rom)
) as rom:
# the resolution must be changed before configuration while the configuration may depend on it (ie bezels)
Expand Down Expand Up @@ -184,10 +184,7 @@ def start_rom(args: argparse.Namespace, maxnbplayers: int, rom: Path, original_r

# run the emulator
_evmapy_instance = evmapy(systemName, system.config.emulator, effectiveCore, original_rom, player_controllers, guns)
with (
_evmapy_instance,
set_hotkeygen_context(generator, system)
):
with _evmapy_instance:
# change directory if wanted
executionDirectory = generator.executionDirectory(system.config, rom)
if executionDirectory is not None:
Expand Down Expand Up @@ -278,7 +275,14 @@ def start_rom(args: argparse.Namespace, maxnbplayers: int, rom: Path, original_r
_logger.error("Failed to draw_gun_borders for gun_borders")
_logger.error(e)

with profiler.pause():
# the hotkeys are set once the generator has run: an emulator that
# exits through a command rather than a key only knows which one
# after it has decided how to run the game
with (
set_hotkeygen_context(generator, system),
profiler.pause(),
generator.running(system.config, rom),
):
monitor_thread.start()
exitCode = runCommand(cmd)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

from abc import ABCMeta, abstractmethod
from contextlib import nullcontext
from typing import TYPE_CHECKING

from ..batoceraPaths import SAVES

if TYPE_CHECKING:
from collections.abc import Mapping
from contextlib import AbstractContextManager
from pathlib import Path

from ..Command import Command
Expand Down Expand Up @@ -38,10 +42,24 @@ def getMouseMode(self, config: SystemConfig, rom: Path) -> bool:
def executionDirectory(self, config: SystemConfig, rom: Path) -> Path | None:
return None

# Wraps the run of the command returned by generate(). Emulators that leave processes
# of their own behind (wine hands the game over to its wineserver and exits) override
# this to clean them up: the rom is only released for good once this exits, which
# matters for a rom mounted from a squashfs.
def running(self, config: SystemConfig, rom: Path) -> AbstractContextManager[None]:
return nullcontext()

# Some systems expect to write into the ROM area, for example: DOS, Amiga, and Wine
def writesToRom(self, config: SystemConfig) -> bool:
return False

# Where the writes of a squashed rom are kept, when writesToRom() asks for an
# overlay. They go with the saves of the system, unless the emulator already has a
# place of its own for the state of a game: wine keeps a prefix per runner, and a
# squashed rom is a prefix.
def writableRomDir(self, system: Emulator, rom: Path) -> Path:
return SAVES / system.name / rom.stem

# mame or libretro have internal bezels, don't display the one of mangohud
def supportsInternalBezels(self) -> bool:
return False
Expand Down
Loading