How fgsfdsfgs/perfect_dark works
Overall Architecture & Project Type
• It as a game port (a cross-platform game engine) that reuses a decompilation of the original game.
• Its purpose is to run “Perfect Dark” on modern hardware, handling ROM input, asset loading for different regions (NTSC, PAL, JPN), and providing improvements (mouselook, dual analog, 60 FPS and even 240 FPS modes, etc.).
• It is structured around a traditional game engine with a core loop and specialized systems: rendering, audio, input, game logic, and asset management.
• Build & Configuration Layer:
• CMake scripts (CMakeLists.txt and the cmake/ directory).
• Build tools and scripts (tools/*, build pipelines for each platform).
• Platform Abstraction Layer:
• “port” directory: contains graphics API adapters (OpenGL, SDL2, glad) and platform-specific glue code.
• “include” and “lib” directories: contain both original and platform-abstraction modules (such as the libultra adaptations and audio/DMA routines).
• Game Core / Engine Layer:
• “src/game”: Contains all game logic including the main game loop, physics, AI, update routines (files like mainmenu.c, game_loop files, player.c, collision routines, etc.).
• “src/lib”: Contains utility libraries and common functions such as matrix math, audio mixer (via minimp3), RNG, and memory management.
• Rendering and Graphics System:
• Graphics related code appears in “src/game”, “port/fast3d”, and “src/lib/ultra” (which includes fast3d implementations and interfacing with low-level graphics via SDL2/OpenGL).
• Audio System:
• Modules in “src/lib/naudio” and “src/lib/mp3” indicate the use of a custom audio mixer and MP3 decoding.
• There is also integration in “src/lib/ultra/audio” to manage the original audio engine expectations.
• Input & Controls:
• Input processing code is distributed in source files (e.g., src/game/pad.c) along with configuration for different controller types (keyboard, Xbox, N64 pad).
• Asset Loading & Management:
• The “src/assets” directory structure is extensive with subdirectories for multiple versions (ntsc, jpn, pal, beta etc.). These hold animations, textures, language files, and level data.
• Tools in “tools/assetmgr” help to preprocess and package assets.
• ROM Handling and Emulator-like Features:
• The ROM loading and identification logic is part of the initialization routines in the engine.
• External Libraries and Dependencies:
• SDL2 (in both “port/fast3d” and build instructions in README) for windowing, input, and audio.
• OpenGL (via glad, whichever is used on each platform).
• ZLib for compression tasks (as seen by checksums and gzip utilities in “tools/mkrom”).
• The build and patch tools from the “tools” directory that support ROM manipulation and asset processing.
Relationships and Interactions
• The Build Layer generates executables for different platforms using CMake, which then integrate the entire Engine.
• The Platform Abstraction Layer communicates with the OS via SDL2 and low-level graphics/audio libraries.
• The Game Core repeatedly calls into systems for rendering, audio, input handling, and game logic updates in each cycle of the game loop.
• The Asset Manager loads and parses platform-specific asset files (located in src/assets) and passes them to the game core.
• Input events from controllers/keyboard/mouse lead into the input processing system that updates player state.
• Use connectors to indicate that the engine subsystems (graphics, audio, input, game logic) interoperate closely inside the core game loop.
Architectural Patterns and Design Principles
• Cross-Platform Abstraction: Separation between hardware-specific code (in “port” and “cmake” directories) and game core logic (in “src/game” and “src/lib”).
• Modularization: Clearly delineated modules (graphics, audio, etc.) that maintain boundaries by interfacing through defined APIs (as seen in “include” directories).
• Build-Time Configuration: Use of CMake and multiple build profiles (driven by ROMID and platform-specific flags) to produce different binaries for NTSC, PAL, and JPN.
Elements
▪ Data flow from user ROM file and configuration (via “data” folder) into the game initialization routines.
▪ Interactions from the game engine to rendering and audio subsystems.
• Then graphically connect these modules by showing how the engine core (game loop) calls the interfaces provided by the abstraction layer which in turn communicates with the OS via SDL2 and OpenGL for graphics and audio.
• External dependencies (ROMs, configuration files, external libraries) clearly.
This detailed, modular approach encapsulates the architecture of the Perfect Dark port project and will provide a clear visual reference for developers to understand and extend the system.