Merge branch 'main' of https://github.com/TwilitRealm/dusk into randomizer

This commit is contained in:
gymnast86
2026-07-13 15:52:24 -07:00
175 changed files with 17712 additions and 680 deletions
+21
View File
@@ -53,6 +53,7 @@
#include "dusk/dusk.h"
#include "dusk/endian.h"
#include "dusk/frame_interpolation.h"
#include "dusk/gfx.hpp"
#include "dusk/gx_helper.h"
#include "dusk/imgui/ImGuiConsole.hpp"
#include "dusk/logging.h"
@@ -2356,6 +2357,10 @@ int mDoGph_Painter() {
GXSetClipMode(GX_CLIP_ENABLE);
#if TARGET_PC
dusk::mods::gfx_run_stage(GFX_STAGE_SCENE_BEGIN, &camera_p->view, view_port);
#endif
#if DEBUG
// "drawing up to Background (Translucent) (Rendering)"
fapGm_HIO_c::stopCpuTimer("背景(半透明)描画まで(レンダリング)");
@@ -2384,6 +2389,10 @@ int mDoGph_Painter() {
GX_DEBUG_GROUP(dComIfGd_drawShadow, camera_p->view.viewMtx);
#if TARGET_PC
dusk::mods::gfx_run_stage(GFX_STAGE_SCENE_AFTER_TERRAIN, &camera_p->view, view_port);
#endif
#if DEBUG
// "shadow drawing (Rendering)"
fapGm_HIO_c::stopCpuTimer("影描画(レンダリング)");
@@ -2413,6 +2422,10 @@ int mDoGph_Painter() {
GX_DEBUG_GROUP(dComIfGd_drawOpaListPacket);
#if TARGET_PC
dusk::mods::gfx_run_stage(GFX_STAGE_SCENE_AFTER_OPAQUE, &camera_p->view, view_port);
#endif
#if DEBUG
// "drawing up to special-use drawing (Opaque) except J3D (Rendering)"
fapGm_HIO_c::stopCpuTimer("J3D以外などの特殊用(不透明)描画まで(レンダリング)");
@@ -2778,6 +2791,10 @@ int mDoGph_Painter() {
captureScreenSetPort();
#endif
#if TARGET_PC
dusk::mods::gfx_run_stage(GFX_STAGE_FRAME_BEFORE_HUD);
#endif
if (fapGmHIO_get2Ddraw()) {
Mtx m4;
cMtx_copy(j3dSys.getViewMtx(), m4);
@@ -2835,6 +2852,10 @@ int mDoGph_Painter() {
dComIfGd_draw2DXlu();
}
#if TARGET_PC
dusk::mods::gfx_run_stage(GFX_STAGE_FRAME_AFTER_HUD);
#endif
#if DEBUG
if (dJcame_c::get()) {
dJcame_c::get()->show2D();
+142 -28
View File
@@ -42,6 +42,7 @@
#include "m_Do/m_Do_ext2.h"
#include "SSystem/SComponent/c_counter.h"
#include <cstring>
#include <sstream>
#include <filesystem>
#include <system_error>
@@ -61,6 +62,7 @@
#include "dusk/imgui/ImGuiConsole.hpp"
#include "dusk/imgui/ImGuiEngine.hpp"
#include "dusk/iso_validate.hpp"
#include "dusk/mod_loader.hpp"
#include "dusk/logging.h"
#include "dusk/main.h"
#include "dusk/ui/menu_bar.hpp"
@@ -131,6 +133,8 @@ bool dusk::IsRunning = true;
bool dusk::IsShuttingDown = false;
bool dusk::IsGameLaunched = false;
bool dusk::RestartRequested = false;
uint8_t dusk::SaveRequested = 0;
dusk::StageRequest dusk::StageRequested = {"",false};
std::filesystem::path dusk::ConfigPath;
std::filesystem::path dusk::CachePath;
#endif
@@ -272,7 +276,7 @@ void main01(void) {
if (dusk::getSettings().video.rememberWindowSize && !dusk::getSettings().video.enableFullscreen) {
dusk::getSettings().video.lastWindowWidth.setValue(event->windowSize.width);
dusk::getSettings().video.lastWindowHeight.setValue(event->windowSize.height);
dusk::config::Save();
dusk::config::save();
}
break;
case AURORA_DISPLAY_SCALE_CHANGED:
@@ -370,6 +374,7 @@ void main01(void) {
} while (dusk::IsRunning);
exit:;
dusk::mods::ModLoader::instance().shutdown();
dusk::ui::shutdown();
}
@@ -437,16 +442,7 @@ static void ApplyCVarOverrides(const cxxopts::OptionValue& option) {
const auto name = std::string_view(cvarArg).substr(0, sep);
const auto value = std::string_view(cvarArg).substr(sep + 1);
const auto cVar = dusk::config::GetConfigVar(name);
if (!cVar) {
DuskLog.fatal("Unknown --cvar name: '{}'", name);
}
try {
cVar->getImpl()->loadFromArg(*cVar, value);
} catch (const std::exception& e) {
DuskLog.fatal("Unable to parse: '{}': {}", value, e.what());
}
dusk::config::load_arg_override(name, value);
}
}
@@ -527,9 +523,6 @@ int game_main(int argc, char* argv[]) {
}
mainCalled = true;
dusk::registerSettings();
dusk::config::FinishRegistration();
cxxopts::ParseResult parsed_arg_options;
try {
@@ -540,8 +533,12 @@ int game_main(int argc, char* argv[]) {
("h,help", "Print usage")
("console", "Show the Windows console window for logs", cxxopts::value<bool>()->default_value("false")->implicit_value("true"))
("dvd", "Path to DVD image file", cxxopts::value<std::string>())
("mods", "Path to mods directory", cxxopts::value<std::string>())
("backend", "Graphics API backend to use (auto, d3d12, d3d11, metal, vulkan, null)", cxxopts::value<std::string>())
("cvar", "Override configuration variables without modifying config", cxxopts::value<std::vector<std::string>>());
("cvar", "Override configuration variables without modifying config", cxxopts::value<std::vector<std::string>>())
("develop", "Enable the game's developer mode and OSReport for debugging", cxxopts::value<bool>()->default_value("false")->implicit_value("true"))
("load-save", "Skip the opening and load a save from slot 1-3", cxxopts::value<uint8_t>()->default_value("0"))
("stage", "Upon launching, load a stage, room, spawn point, and layer. When using --load-save, it uses the specified save on the loaded stage. Format (STAGE,ROOM,POINT,LAYER). Example: (STAGE) or (STAGE,0,0,-1)", cxxopts::value<std::string>());
arg_options.parse_positional({"dvd"});
arg_options.positional_help("<dvd-image>");
@@ -554,11 +551,52 @@ int game_main(int argc, char* argv[]) {
printf("%s", (arg_options.help() + "\n").c_str());
exit(0);
}
if (parsed_arg_options.count("stage")) {
std::stringstream ss(parsed_arg_options["stage"].as<std::string>());
std::string token;
std::getline(ss,token,',');
std::string stageName = token;
s8 room = 0;
s16 point = 0;
s8 layer = -1;
if (std::getline(ss,token,',')) {
room = std::stoi(token);
if (std::getline(ss,token,',')) {
point = std::stoi(token);
if (std::getline(ss,token,',')) {
layer = std::stoi(token);
}
}
}
dusk::StageRequested = {stageName,true, room,point,layer};
}
}
catch (const cxxopts::exceptions::exception& e) {
fprintf(stderr, "Argument Error: %s\n", e.what());
exit(1);
}
catch (const std::invalid_argument& e) {
// Handle parsing std::stoi when loading a stage
fprintf(stderr, "Fatal: Invalid Argument When Parsing Stage\n");
exit(1);
}
catch (const std::out_of_range& e) {
// Handle parsing std::stoi when loading a stage
fprintf(stderr, "Fatal: Argument Out of Range In Parsing Stage\n");
exit(1);
}
if (parsed_arg_options.contains("load-save")){
uint8_t slot = parsed_arg_options["load-save"].as<uint8_t>();
if (slot >= 1 && slot <= 3) {
dusk::SaveRequested = slot;
}
}
dusk::registerSettings();
const auto startupLogLevel =
static_cast<AuroraLogLevel>(parsed_arg_options["log-level"].as<uint8_t>());
@@ -567,12 +605,15 @@ int game_main(int argc, char* argv[]) {
dusk::CachePath = dataPaths.cachePath;
dusk::InitializeFileLogging(dusk::CachePath, startupLogLevel);
// Development Mode
if (parsed_arg_options.count("develop")) {
mDoMain::developmentMode = parsed_arg_options["develop"].as<bool>(); // Enable Dev Mode for Debugging
dusk::OSReportReallyForceEnable = parsed_arg_options["develop"].as<bool>(); // Print OSReport to console
}
log_build_info();
dusk::config::LoadFromUserPreferences();
if (dusk::getSettings().game.speedrunMode) {
dusk::resetForSpeedrunMode();
}
dusk::config::load_from_user_preferences();
ApplyCVarOverrides(parsed_arg_options["cvar"]);
dusk::android::update_surface_frame_rate();
dusk::crash_reporting::initialize();
@@ -636,6 +677,12 @@ int game_main(int argc, char* argv[]) {
auroraInfo = aurora_initialize(argc, argv, &config);
}
// Apply after aurora_initialize: speedrun mode mutates cvars whose change callbacks push
// values into aurora.
if (dusk::getSettings().game.speedrunMode) {
dusk::resetForSpeedrunMode();
}
#ifdef DUSK_DISCORD
if (dusk::getSettings().game.enableDiscordPresence) {
dusk::discord::initialize();
@@ -706,7 +753,7 @@ int game_main(int argc, char* argv[]) {
saveConfigBeforePrelaunch = true;
}
std::string dvd_path;
std::string dvd_path = dusk::getSettings().backend.isoPath;
bool dvd_opened = false;
if (parsed_arg_options.count("dvd")) {
dvd_path = parsed_arg_options["dvd"].as<std::string>();
@@ -720,7 +767,7 @@ int game_main(int argc, char* argv[]) {
dusk::getSettings().backend.isoPath.setValue(dvd_path);
dusk::getSettings().backend.isoVerification.setValue(
dusk::DiscVerificationState::Unknown);
dusk::config::Save();
dusk::config::save();
dusk::IsGameLaunched = true;
}
} else {
@@ -729,6 +776,22 @@ int game_main(int argc, char* argv[]) {
}
}
bool skipPreLaunchUI = dusk::getSettings().backend.skipPreLaunchUI.getValue();
// If we can't load right into the game, stop requesting to load a stage or save
if (forcePreLaunchUI || dvd_path.empty()) {
if (dusk::StageRequested.set) {
DuskLog.warn("Cannot load stage {} because no iso path is set, opening prelaunch UI",dusk::StageRequested.stage);
dusk::StageRequested = {};
}
if (dusk::SaveRequested) {
DuskLog.warn("Cannot load save {} because no iso path is set, opening prelaunch UI",dusk::SaveRequested);
dusk::SaveRequested = 0;
}
}else if (dusk::StageRequested.set || dusk::SaveRequested) {
skipPreLaunchUI = true;
}
dusk::iso::log_verification_state(
dusk::getSettings().backend.isoPath.getValue(),
dusk::getSettings().backend.isoVerification.getValue());
@@ -737,16 +800,16 @@ int game_main(int argc, char* argv[]) {
if (dusk::getSettings().backend.isoPath.getValue().empty()) {
forcePreLaunchUI = true;
}
if (forcePreLaunchUI && dusk::getSettings().backend.skipPreLaunchUI.getValue()) {
if (forcePreLaunchUI && skipPreLaunchUI) {
DuskLog.warn("Prelaunch UI was disabled with no usable DVD image, enabling prelaunch UI");
dusk::getSettings().backend.skipPreLaunchUI.setValue(false);
saveConfigBeforePrelaunch = true;
}
if (saveConfigBeforePrelaunch) {
dusk::config::Save();
dusk::config::save();
}
if (!dusk::getSettings().backend.skipPreLaunchUI) {
if (!skipPreLaunchUI) {
dusk::ui::push_document(std::make_unique<dusk::ui::Prelaunch>(), true);
// pre game launch ui main loop
@@ -765,7 +828,6 @@ int game_main(int argc, char* argv[]) {
}
dvd_path = dusk::getSettings().backend.isoPath;
if (dvd_path.empty()) {
DuskLog.fatal("No DVD image specified, unable to boot!");
}
@@ -808,12 +870,63 @@ int game_main(int argc, char* argv[]) {
// Global Context Init
dComIfG_ct();
// Development Mode
// mDoMain::developmentMode = 1; // Force Dev Mode for Debugging
mDoDvdThd::SyncWidthSound = false;
OSReport("Starting main01 (Game Loop)...\n");
// Mod search directories, highest priority first: user dir (--mods replaces it), then
// mods/ next to the app, then install-bundled mods inside the app bundle.
{
std::vector<dusk::mods::ModSearchDir> modDirs;
if (parsed_arg_options.contains("mods") &&
!parsed_arg_options["mods"].as<std::string>().empty())
{
modDirs.push_back({.path = parsed_arg_options["mods"].as<std::string>()});
} else {
modDirs.push_back({.path = dusk::ConfigPath / "mods"});
}
#if TARGET_ANDROID
// APK-bundled mods are extracted to internal storage
// by DuskActivity before SDL_main runs.
modDirs.push_back({
.path = dusk::CachePath / "bundled_mods",
});
#elif defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)
modDirs.push_back({
.path = dusk::data::base_path_relative("mods"),
.inPlaceNative = true,
.nativeLibDir = dusk::data::base_path_relative("Frameworks"),
});
#else
#if defined(__APPLE__)
// Base path is Contents/Resources; search up for dev mods
// TODO: scope to non-CI builds
modDirs.push_back({
.path = dusk::data::base_path_relative("../../../mods").lexically_normal(),
.inPlaceNative = true,
});
// Contents/Resources/mods
modDirs.push_back({
.path = dusk::data::base_path_relative("mods"),
.inPlaceNative = true,
});
#else
modDirs.push_back({
.path = dusk::data::base_path_relative("mods"),
.inPlaceNative = true,
});
#endif
#endif
dusk::mods::ModLoader::instance().set_search_dirs(std::move(modDirs));
}
#if TARGET_ANDROID
// A user-relocated data dir can live on external storage, which is mounted noexec.
// Native mod libraries must be extracted to internal storage.
dusk::mods::ModLoader::instance().set_cache_dir(dusk::CachePath / "mod_cache");
#endif
DuskLog.info("Initializing mods...");
dusk::mods::ModLoader::instance().init();
OSReport("Starting main01 (Game Loop)...\n");
main01();
@@ -834,6 +947,7 @@ int game_main(int argc, char* argv[]) {
#endif
dusk::ui::shutdown();
dusk::texture_replacements::shutdown();
dusk::config::shutdown();
aurora_shutdown();
return 0;