Merge branch 'develop' into develop

This commit is contained in:
IShallRiseAgain 2022-04-21 22:03:31 -04:00 committed by GitHub
commit 7f0023c909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 3544 additions and 843 deletions

402
.gitignore vendored Normal file
View File

@ -0,0 +1,402 @@
# Cache files
__pycache__/
.pyc
.DS_Store
# Text editor remnants
.vscode/
.vs/
.idea/
CMakeLists.txt
cmake-build-debug
venv/
# Project-specific ignores
build/
expected/
notes/
baserom/
docs/doxygen/
*.elf
*.sra
*.z64
*.n64
*.v64
*.map
*.dump
out.txt
# Tool artifacts
tools/mipspro7.2_compiler/
tools/overlayhelpers/batchdisasm/output/*
tools/overlayhelpers/batchdisasm/output2/*
tools/overlayhelpers/batchdisasm/mipsdisasm/*
tools/disasm/output/*
tools/asmsplitter/asm/*
tools/asmsplitter/c/*
ctx.c
tools/*dSYM/
graphs/
# Assets
*.png
*.jpg
*.mdli
*.anmi
*.obj
*.mtl
*.fbx
!*_custom*
.extracted-assets.json
# Docs
!docs/tutorial/
# Per-user configuration
.python-version
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
*.out
*.o
*.d
lib/libgfxd/libgfxd.a
ExporterTest/ExporterTest.a
ZAPDUtils/ZAPDUtils.a
.vscode/
build/
ZAPDUtils/build/
ZAPD/BuildInfo.h
DebugObj/*
ReleaseObj/*

View File

@ -667,7 +667,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
{
int sss = (data & 0x00FFF00000000000) >> 44;
int ttt = (data & 0x00000FFF00000000) >> 32;
int i = (data & 0x000000000F000000) >> 16;
int i = (data & 0x000000000F000000) >> 24;
int uuu = (data & 0x0000000000FFF000) >> 12;
int vvv= (data & 0x0000000000000FFF);

View File

@ -1,14 +1,51 @@
#!/usr/bin/env python3
import argparse, json, os, signal, time, sys, shutil
# How to use:
# Place a rom in this directory then run the script.
# If you are using multiple roms, the script will let you choose one.
# To choose with a commandline argument:
# Python3 extract_assets.py <number>
# Invalid input results in the first rom being selected
import json, os, signal, time, sys, shutil, glob
from multiprocessing import Pool, cpu_count, Event, Manager, ProcessError
from enum import Enum
import shutil
def BuildOTR(xmlPath):
romVer = "..\\soh\\baserom_non_mq.z64"
roms = [];
checksums = ["", "", ""];
class Checksums(Enum):
OOT_NTSC_10 = "EC7011B7"
OOT_NTSC_11 = "D43DA81F"
OOT_NTSC_12 = "693BA2AE"
OOT_PAL_10 = "B044B569"
OOT_PAL_11 = "B2055FBD"
OOT_NTSC_JP_GC_CE = "F7F52DB8"
OOT_NTSC_JP_GC = "F611F4BA"
OOT_NTSC_US_GC = "F3DD35BA"
OOT_PAL_GC = "09465AC3"
OOT_NTSC_JP_MQ = "F43B45BA"
OOT_NTSC_US_MQ = "F034001A"
OOT_PAL_MQ = "1D4136F3"
OOT_PAL_GC_DBG1 = "871E1C92"
OOT_PAL_GC_DBG2 = "87121EFE"
OOT_PAL_GC_MQ_DBG = "917D18F6"
OOT_IQUE_TW = "3D81FB3E"
OOT_IQUE_CN = "B1E1E07B"
OOT_UNKNOWN = "FFFFFFFF"
CompatibleChecksums = [
Checksums.OOT_PAL_GC,
Checksums.OOT_PAL_GC_DBG1
]
def BuildOTR(xmlPath, rom):
shutil.copytree("assets", "Extract/assets")
execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out"
execStr += " ed -i %s -b baserom.z64 -fl CFG\\filelists -o placeholder -osf placeholder -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath)
execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out"
execStr += " ed -i %s -b %s -fl CFG\\filelists -o placeholder -osf placeholder -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath, rom)
print(execStr)
exitValue = os.system(execStr)
@ -18,23 +55,95 @@ def BuildOTR(xmlPath):
print("Aborting...", file=os.sys.stderr)
print("\n")
def main():
parser = argparse.ArgumentParser(description="baserom asset extractor")
parser.add_argument("-v", "--version", help="Sets game version.")
args = parser.parse_args()
def checkChecksum(rom):
r = open(rom, "rb")
r.seek(16)
bytes = r.read(4).hex().upper()
r.close()
# TODO: Read from makerom file to automatically determine game version
xmlVer = "GC_NMQ_D"
for checksum in Checksums:
if (checksum.value == bytes):
for compat in CompatibleChecksums:
if (checksum.name == compat.name):
print("Compatible rom found!")
return checksum
print("Valid oot rom found. However, not compatible with SoH.")
print("Compatible roms:")
for compat in CompatibleChecksums:
print(compat.name+" | 0x"+compat.value)
sys.exit(1)
print("Wrong rom! No valid checksum found")
sys.exit(1)
if (args.version == "gc_pal_nmpq"):
xmlVer = "GC_NMQ_PAL_F"
elif (args.version == "dbg_mq"):
xmlVer = "GC_MQ_D"
def main():
romToUse = "";
for file in glob.glob("*.z64"):
roms.append(file)
if not (roms):
print("Error: No roms located, place one in the OTRExporter directory", file=os.sys.stderr)
sys.exit(1)
if (len(roms) > 1):
# If commandline args exist
if (len(sys.argv) > 1):
try:
if ((int(sys.argv[1]) - 1) < 1):
romToUse = roms[0]
elif ((int(sys.argv[1]) - 1) > len(roms)):
romToUse = roms[len(roms) - 1]
else:
romToUse = roms[int(sys.argv[1]) - 1]
except:
romToUse = roms[0]
# No commandline args, select rom using user input
else:
print(str(len(roms))+" roms found, please select one by pressing 1-"+str(len(roms)))
count = 1
for list in range(len(roms)):
print(str(count)+". "+roms[list])
count += 1
while(1):
try:
selection = int(input())
except:
print("Bad input. Try again with the number keys.")
continue
if (selection < 1 or selection > len(roms)):
print("Bad input. Try again.")
continue
else: break
romToUse = roms[selection - 1]
else:
romToUse = roms[0]
match checkChecksum(romToUse).name:
case Checksums.OOT_PAL_GC:
xmlVer = "GC_NMQ_PAL_F"
case Checksums.OOT_PAL_GC_DBG1:
xmlVer = "GC_MQ_D"
case _: # default case
xmlVer = "GC_NMQ_D"
if (os.path.exists("Extract")):
shutil.rmtree("Extract")
BuildOTR("..\\soh\\assets\\xml\\" + xmlVer + "\\")
BuildOTR("..\\soh\\assets\\xml\\" + xmlVer + "\\", romToUse)
if __name__ == "__main__":
main()
main()

View File

@ -55,20 +55,22 @@ Official Discord: https://discord.com/invite/BtBmd55HVH
2. Install [Visual Studio 2022 Community Edition](https://visualstudio.microsoft.com/vs/community/)
2b. In the Visual Studio Installer, install `MSVC v142 - VS 2019 C++`.
4. Clone the Ship of Harkinian repository.
5. Place `oot debug` rom (not Master Quest) in the `soh` folder named `baserom_original_non_mq`.
6. Launch `soh/fixbaserom.py`.
7. Launch `soh/extract_baserom.py`.
8. Copy the `baserom` folder from the `soh` folder into the `OTRExporter` folder.
9. Run `OTRExporter/OTRExporter.sln`.
10. Switch the solution to `Release x64`.
11. Build the solution.
12. Launching `OTRExporter/extract_assets.py` will generate an `oot.otr` archive file in `OTRExporter/oot.otr`.
13. Run `soh/soh.sln`
14. Switch the solution to `Release x86`.
15. Build the solution.
16. Copy the `OTRExporter/oot.otr` archive file to `soh/Release`.
17. Launch `soh.exe`.
5. Place one or more [compatible](#compatible-roms) roms in the `OTRExporter` directory with namings of your choice.
6. Run `OTRExporter/OTRExporter.sln`.
7. Switch the solution to `Release x64`.
8. Build the solution.
9. Launching `OTRExporter/extract_assets.py` will generate an `oot.otr` archive file in `OTRExporter/oot.otr`.
10. Run `soh/soh.sln`
11. Switch the solution to `Release x86`.
12. Build the solution.
13. Copy the `OTRExporter/oot.otr` archive file to `soh/Release`.
14. Launch `soh.exe`.
## Compatible Roms
```
OOT_PAL_GC checksum 0x09465AC3
OOT_PAL_GC_DBG1 checksum 0x871E1C92 (debug non-master quest)
```
## Troubleshooting The Exporter
- Affirm that you have an `/assets` folder filled with XMLs in the same directory as OTRGui.exe
- Affirm that `zapd.exe` exists in the `/assets/extractor` folder

View File

@ -51,8 +51,11 @@ namespace Game {
Settings.debug.n64mode = stob(Conf[ConfSection]["n64_mode"]);
// Enhancements
Settings.enhancements.fast_text = stob(Conf[EnhancementSection]["fast_text"]);
CVar_SetS32("gFastText", Settings.enhancements.fast_text);
Settings.enhancements.skip_text = stob(Conf[EnhancementSection]["skip_text"]);
CVar_SetS32("gSkipText", Settings.enhancements.skip_text);
Settings.enhancements.text_speed = Ship::stoi(Conf[EnhancementSection]["text_speed"]);
CVar_SetS32("gTextSpeed", Settings.enhancements.text_speed);
Settings.enhancements.disable_lod = stob(Conf[EnhancementSection]["disable_lod"]);
CVar_SetS32("gDisableLOD", Settings.enhancements.disable_lod);
@ -60,8 +63,17 @@ namespace Game {
Settings.enhancements.animated_pause_menu = stob(Conf[EnhancementSection]["animated_pause_menu"]);
CVar_SetS32("gPauseLiveLink", Settings.enhancements.animated_pause_menu);
Settings.enhancements.dynamic_wallet_icon = stob(Conf[EnhancementSection]["dynamic_wallet_icon"]);
CVar_SetS32(const_cast<char*>("gDynamicWalletIcon"), Settings.enhancements.dynamic_wallet_icon);
Settings.enhancements.minimal_ui = stob(Conf[EnhancementSection]["minimal_ui"]);
CVar_SetS32(const_cast<char*>("gMinimalUI"), Settings.enhancements.minimal_ui);
CVar_SetS32("gMinimalUI", Settings.enhancements.minimal_ui);
Settings.enhancements.visualagony = stob(Conf[EnhancementSection]["visualagony"]);
CVar_SetS32("gVisualAgony", Settings.enhancements.visualagony);
Settings.enhancements.mm_bunny_hood = stob(Conf[EnhancementSection]["mm_bunny_hood"]);
CVar_SetS32("gMMBunnyHood", Settings.enhancements.mm_bunny_hood);
// Audio
Settings.audio.master = Ship::stof(Conf[AudioSection]["master"]);
@ -169,6 +181,15 @@ namespace Game {
CVar_SetS32("gInputEnabled", Settings.controller.input_enabled);
Settings.controller.dpad_pause_name = stob(Conf[ControllerSection]["dpad_pause_name"]);
CVar_SetS32("gDpadPauseName", Settings.controller.dpad_pause_name);
Settings.controller.dpad_ocarina_text = stob(Conf[ControllerSection]["dpad_ocarina_text"]);
CVar_SetS32("gDpadOcarinaText", Settings.controller.dpad_ocarina_text);
Settings.controller.dpad_shop = stob(Conf[ControllerSection]["dpad_shop"]);
CVar_SetS32("gDpadShop", Settings.controller.dpad_shop);
// Cheats
Settings.cheats.debug_mode = stob(Conf[CheatSection]["debug_mode"]);
@ -186,6 +207,9 @@ namespace Game {
Settings.cheats.infinite_magic = stob(Conf[CheatSection]["infinite_magic"]);
CVar_SetS32("gInfiniteMagic", Settings.cheats.infinite_magic);
Settings.cheats.infinite_nayru = stob(Conf[CheatSection]["infinite_nayru"]);
CVar_SetS32("gInfiniteNayru", Settings.cheats.infinite_nayru);
Settings.cheats.no_clip = stob(Conf[CheatSection]["no_clip"]);
CVar_SetS32("gNoClip", Settings.cheats.no_clip);
@ -198,6 +222,15 @@ namespace Game {
Settings.cheats.super_tunic = stob(Conf[CheatSection]["super_tunic"]);
CVar_SetS32("gSuperTunic", Settings.cheats.super_tunic);
Settings.cheats.ez_isg = stob(Conf[CheatSection]["ez_isg"]);
CVar_SetS32("gEzISG", Settings.cheats.ez_isg);
Settings.cheats.no_restrict_item = stob(Conf[CheatSection]["no_restrict_item"]);
CVar_SetS32("gNoRestrictItems", Settings.cheats.no_restrict_item);
Settings.cheats.freeze_time = stob(Conf[CheatSection]["freeze_time"]);
CVar_SetS32("gFreezeTime", Settings.cheats.freeze_time);
UpdateAudio();
}
@ -219,16 +252,24 @@ namespace Game {
Conf[AudioSection]["fanfare"] = std::to_string(Settings.audio.fanfare);
// Enhancements
Conf[EnhancementSection]["fast_text"] = std::to_string(Settings.enhancements.fast_text);
Conf[EnhancementSection]["skip_text"] = std::to_string(Settings.enhancements.skip_text);
Conf[EnhancementSection]["text_speed"] = std::to_string(Settings.enhancements.text_speed);
Conf[EnhancementSection]["disable_lod"] = std::to_string(Settings.enhancements.disable_lod);
Conf[EnhancementSection]["animated_pause_menu"] = std::to_string(Settings.enhancements.animated_pause_menu);
Conf[EnhancementSection]["dynamic_wallet_icon"] = std::to_string(Settings.enhancements.dynamic_wallet_icon);
Conf[EnhancementSection]["minimal_ui"] = std::to_string(Settings.enhancements.minimal_ui);
Conf[EnhancementSection]["visualagony"] = std::to_string(Settings.enhancements.visualagony);
Conf[EnhancementSection]["mm_bunny_hood"] = std::to_string(Settings.enhancements.mm_bunny_hood);
// Controllers
Conf[ControllerSection]["gyro_sensitivity"] = std::to_string(Settings.controller.gyro_sensitivity);
Conf[ControllerSection]["rumble_strength"] = std::to_string(Settings.controller.rumble_strength);
Conf[ControllerSection]["input_scale"] = std::to_string(Settings.controller.input_scale);
Conf[ControllerSection]["input_enabled"] = std::to_string(Settings.controller.input_enabled);
Conf[ControllerSection]["dpad_pause_name"] = std::to_string(Settings.controller.dpad_pause_name);
Conf[ControllerSection]["dpad_ocarina_text"] = std::to_string(Settings.controller.dpad_ocarina_text);
Conf[ControllerSection]["dpad_shop"] = std::to_string(Settings.controller.dpad_shop);
// Cosmetics

View File

@ -20,10 +20,15 @@ struct SoHConfigType {
// Enhancements
struct {
bool fast_text = false;
int text_speed = 1;
bool skip_text = false;
bool disable_lod = false;
bool animated_pause_menu = false;
bool dynamic_wallet_icon = false;
bool minimal_ui = false;
bool visualagony = false;
bool mm_bunny_hood = false;
} enhancements;
// Controller
@ -34,6 +39,9 @@ struct SoHConfigType {
float gyroDriftX = 0.0f;
float gyroDriftY = 0.0f;
bool input_enabled = false;
bool dpad_pause_name = false;
bool dpad_ocarina_text = false;
bool dpad_shop = false;
} controller;
struct {
@ -84,11 +92,20 @@ struct SoHConfigType {
bool infinite_health = false;
bool infinite_ammo = false;
bool infinite_magic = false;
bool infinite_nayru = false;
bool no_clip = false;
bool climb_everything = false;
bool moon_jump_on_l = false;
bool super_tunic = false;
bool ez_isg = false;
bool no_restrict_item = false;
bool freeze_time = false;
} cheats;
// Graphics
struct {
bool show = false;
} graphics;
};
enum SeqPlayers {

View File

@ -37,9 +37,8 @@ namespace {
struct PerFrameCB {
uint32_t noise_frame;
float noise_scale_x;
float noise_scale_y;
uint32_t padding;
float noise_scale;
uint32_t padding[2]; // constant buffers must be multiples of 16 bytes in size
};
struct PerDrawCB {
@ -51,12 +50,12 @@ struct PerDrawCB {
} textures[2];
};
struct CoordCB {
float x, y;
float padding[2]; // structure size must be multiple of 16
struct Coord {
int x, y;
};
struct TextureData {
ComPtr<ID3D11Texture2D> texture;
ComPtr<ID3D11ShaderResourceView> resource_view;
ComPtr<ID3D11SamplerState> sampler_state;
uint32_t width;
@ -64,10 +63,13 @@ struct TextureData {
bool linear_filtering;
};
struct FramebufferData {
struct Framebuffer {
ComPtr<ID3D11RenderTargetView> render_target_view;
ComPtr<ID3D11DepthStencilView> depth_stencil_view;
ComPtr<ID3D11ShaderResourceView> depth_stencil_srv;
uint32_t texture_id;
bool has_depth_buffer;
uint32_t msaa_level;
};
struct ShaderProgramD3D11 {
@ -91,34 +93,30 @@ static struct {
pD3DCompile D3DCompile;
D3D_FEATURE_LEVEL feature_level;
uint32_t msaa_num_quality_levels[D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT];
ComPtr<ID3D11Device> device;
ComPtr<IDXGISwapChain1> swap_chain;
ComPtr<ID3D11DeviceContext> context;
ComPtr<ID3D11RenderTargetView> backbuffer_view;
ComPtr<ID3D11DepthStencilView> depth_stencil_view;
ComPtr<ID3D11ShaderResourceView> depth_stencil_srv;
ComPtr<ID3D11RasterizerState> rasterizer_state;
ComPtr<ID3D11DepthStencilState> depth_stencil_state;
ComPtr<ID3D11Buffer> vertex_buffer;
ComPtr<ID3D11Buffer> per_frame_cb;
ComPtr<ID3D11Buffer> per_draw_cb;
ComPtr<ID3D11Texture2D> depth_stencil_texture;
ComPtr<ID3D11Texture2D> depth_stencil_copy_texture;
ComPtr<ID3D11Buffer> coord_buffer;
ComPtr<ID3D11ShaderResourceView> coord_buffer_srv;
ComPtr<ID3D11Buffer> depth_value_output_buffer;
ComPtr<ID3D11Buffer> depth_value_output_buffer_copy;
ComPtr<ID3D11UnorderedAccessView> depth_value_output_uav;
ComPtr<ID3D11SamplerState> depth_value_sampler;
ComPtr<ID3D11ComputeShader> compute_shader;
bool copied_depth_buffer;
ComPtr<ID3D11ComputeShader> compute_shader_msaa;
ComPtr<ID3DBlob> compute_shader_msaa_blob;
size_t coord_buffer_size;
#if DEBUG_D3D
ComPtr<ID3D11Debug> debug;
#endif
DXGI_SAMPLE_DESC sample_description;
PerFrameCB per_frame_cb_data;
PerDrawCB per_draw_cb_data;
@ -128,14 +126,15 @@ static struct {
int current_tile;
uint32_t current_texture_ids[2];
std::vector<FramebufferData> framebuffers;
std::vector<Framebuffer> framebuffers;
// Current state
struct ShaderProgramD3D11 *shader_program;
uint32_t current_width, current_height;
//uint32_t current_width, current_height;
uint32_t render_target_height;
int current_framebuffer;
int8_t depth_test;
int8_t depth_mask;
@ -156,7 +155,9 @@ static struct {
static LARGE_INTEGER last_time, accumulated_time, frequency;
void create_depth_stencil_objects(uint32_t width, uint32_t height, ID3D11Texture2D **texture, ID3D11DepthStencilView **view, ID3D11ShaderResourceView **srv) {
int gfx_d3d11_create_framebuffer(void);
void create_depth_stencil_objects(uint32_t width, uint32_t height, uint32_t msaa_count, ID3D11DepthStencilView **view, ID3D11ShaderResourceView **srv) {
D3D11_TEXTURE2D_DESC texture_desc;
texture_desc.Width = width;
texture_desc.Height = height;
@ -164,93 +165,42 @@ void create_depth_stencil_objects(uint32_t width, uint32_t height, ID3D11Texture
texture_desc.ArraySize = 1;
texture_desc.Format = d3d.feature_level >= D3D_FEATURE_LEVEL_10_0 ?
DXGI_FORMAT_R32_TYPELESS : DXGI_FORMAT_R24G8_TYPELESS;
texture_desc.SampleDesc.Count = 1;
texture_desc.SampleDesc.Count = msaa_count;
texture_desc.SampleDesc.Quality = 0;
texture_desc.Usage = D3D11_USAGE_DEFAULT;
texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | (srv != nullptr ? D3D11_BIND_SHADER_RESOURCE : 0);
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = 0;
ThrowIfFailed(d3d.device->CreateTexture2D(&texture_desc, nullptr, texture));
ComPtr<ID3D11Texture2D> texture;
ThrowIfFailed(d3d.device->CreateTexture2D(&texture_desc, nullptr, texture.GetAddressOf()));
D3D11_DEPTH_STENCIL_VIEW_DESC view_desc;
view_desc.Format = d3d.feature_level >= D3D_FEATURE_LEVEL_10_0 ?
DXGI_FORMAT_D32_FLOAT : DXGI_FORMAT_D24_UNORM_S8_UINT;
view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
view_desc.Flags = 0;
view_desc.Texture2D.MipSlice = 0;
if (msaa_count > 1) {
view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
view_desc.Texture2DMS.UnusedField_NothingToDefine = 0;
} else {
view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
view_desc.Texture2D.MipSlice = 0;
}
ThrowIfFailed(d3d.device->CreateDepthStencilView(*texture, &view_desc, view));
ThrowIfFailed(d3d.device->CreateDepthStencilView(texture.Get(), &view_desc, view));
if (srv != nullptr) {
D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
srv_desc.Format = d3d.feature_level >= D3D_FEATURE_LEVEL_10_0 ?
DXGI_FORMAT_R32_FLOAT : DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srv_desc.ViewDimension = msaa_count > 1 ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D;
srv_desc.Texture2D.MostDetailedMip = 0;
srv_desc.Texture2D.MipLevels = -1;
ThrowIfFailed(d3d.device->CreateShaderResourceView(*texture, &srv_desc, srv));
ThrowIfFailed(d3d.device->CreateShaderResourceView(texture.Get(), &srv_desc, srv));
}
}
static void create_render_target_views(bool is_resize) {
DXGI_SWAP_CHAIN_DESC1 desc1;
if (is_resize) {
// Release previous stuff (if any)
d3d.backbuffer_view.Reset();
d3d.depth_stencil_texture.Reset();
d3d.depth_stencil_view.Reset();
d3d.depth_stencil_srv.Reset();
d3d.depth_stencil_copy_texture.Reset();
// Resize swap chain buffers
ThrowIfFailed(d3d.swap_chain->GetDesc1(&desc1));
ThrowIfFailed(d3d.swap_chain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, desc1.Flags),
gfx_dxgi_get_h_wnd(), "Failed to resize IDXGISwapChain buffers.");
}
// Get new size
ThrowIfFailed(d3d.swap_chain->GetDesc1(&desc1));
// Create back buffer
ComPtr<ID3D11Texture2D> backbuffer_texture;
ThrowIfFailed(d3d.swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID *) backbuffer_texture.GetAddressOf()),
gfx_dxgi_get_h_wnd(), "Failed to get backbuffer from IDXGISwapChain.");
ThrowIfFailed(d3d.device->CreateRenderTargetView(backbuffer_texture.Get(), nullptr, d3d.backbuffer_view.GetAddressOf()),
gfx_dxgi_get_h_wnd(), "Failed to create render target view.");
// Create depth buffer
create_depth_stencil_objects(desc1.Width, desc1.Height, d3d.depth_stencil_texture.GetAddressOf(), d3d.depth_stencil_view.GetAddressOf(), d3d.depth_stencil_srv.GetAddressOf());
// Create texture that can be used to retrieve depth value
D3D11_TEXTURE2D_DESC depth_texture = {};
depth_texture.Width = desc1.Width;
depth_texture.Height = desc1.Height;
depth_texture.MipLevels = 1;
depth_texture.ArraySize = 1;
depth_texture.Format = DXGI_FORMAT_D32_FLOAT;
depth_texture.SampleDesc.Count = 1;
depth_texture.SampleDesc.Quality = 0;
depth_texture.Usage = D3D11_USAGE_STAGING;
depth_texture.BindFlags = 0;
depth_texture.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
depth_texture.MiscFlags = 0;
ThrowIfFailed(d3d.device->CreateTexture2D(&depth_texture, nullptr, d3d.depth_stencil_copy_texture.GetAddressOf()));
// Save resolution
d3d.current_width = desc1.Width;
d3d.current_height = desc1.Height;
}
static void gfx_d3d11_init(void) {
// Load d3d11.dll
d3d.d3d11_module = LoadLibraryW(L"d3d11.dll");
@ -300,11 +250,6 @@ static void gfx_d3d11_init(void) {
}
});
// Sample description to be used in back buffer and depth buffer
d3d.sample_description.Count = 1;
d3d.sample_description.Quality = 0;
// Create the swap chain
d3d.swap_chain = gfx_dxgi_create_swap_chain(d3d.device.Get());
@ -315,9 +260,19 @@ static void gfx_d3d11_init(void) {
gfx_dxgi_get_h_wnd(), "Failed to get ID3D11Debug device.");
#endif
// Create views
// Create the default framebuffer which represents the window
Framebuffer& fb = d3d.framebuffers[gfx_d3d11_create_framebuffer()];
create_render_target_views(false);
// Check the size of the window
DXGI_SWAP_CHAIN_DESC1 swap_chain_desc;
ThrowIfFailed(d3d.swap_chain->GetDesc1(&swap_chain_desc));
d3d.textures[fb.texture_id].width = swap_chain_desc.Width;
d3d.textures[fb.texture_id].height = swap_chain_desc.Height;
fb.msaa_level = 1;
for (uint32_t sample_count = 1; sample_count <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; sample_count++) {
ThrowIfFailed(d3d.device->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, sample_count, &d3d.msaa_num_quality_levels[sample_count - 1]));
}
// Create main vertex buffer
@ -364,61 +319,30 @@ static void gfx_d3d11_init(void) {
// Create compute shader that can be used to retrieve depth buffer values
D3D11_BUFFER_DESC coord_cb_desc;
coord_cb_desc.Usage = D3D11_USAGE_DYNAMIC;
coord_cb_desc.ByteWidth = sizeof(CoordCB);
coord_cb_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
coord_cb_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
coord_cb_desc.MiscFlags = 0;
coord_cb_desc.StructureByteStride = 0;
ThrowIfFailed(d3d.device->CreateBuffer(&coord_cb_desc, nullptr, d3d.coord_buffer.GetAddressOf()));
D3D11_SAMPLER_DESC sampler_desc = {};
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.MinLOD = 0;
sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
ThrowIfFailed(d3d.device->CreateSamplerState(&sampler_desc, d3d.depth_value_sampler.GetAddressOf()));
D3D11_BUFFER_DESC output_buffer_desc;
output_buffer_desc.Usage = D3D11_USAGE_DEFAULT;
output_buffer_desc.ByteWidth = sizeof(float);
output_buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
output_buffer_desc.CPUAccessFlags = 0;
output_buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
output_buffer_desc.StructureByteStride = sizeof(float);
ThrowIfFailed(d3d.device->CreateBuffer(&output_buffer_desc, nullptr, d3d.depth_value_output_buffer.GetAddressOf()));
D3D11_UNORDERED_ACCESS_VIEW_DESC output_buffer_uav_desc;
output_buffer_uav_desc.Format = DXGI_FORMAT_UNKNOWN;
output_buffer_uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
output_buffer_uav_desc.Buffer.FirstElement = 0;
output_buffer_uav_desc.Buffer.NumElements = 1;
output_buffer_uav_desc.Buffer.Flags = 0;
ThrowIfFailed(d3d.device->CreateUnorderedAccessView(d3d.depth_value_output_buffer.Get(), &output_buffer_uav_desc, d3d.depth_value_output_uav.GetAddressOf()));
output_buffer_desc.Usage = D3D11_USAGE_STAGING;
output_buffer_desc.BindFlags = 0;
output_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
ThrowIfFailed(d3d.device->CreateBuffer(&output_buffer_desc, nullptr, d3d.depth_value_output_buffer_copy.GetAddressOf()));
const char* shader_source = R"(
sampler my_sampler : register(s0);
Texture2D<float> tex : register(t0);
cbuffer coordCB : register(b0) {
float2 coord;
}
StructuredBuffer<int2> coord : register(t1);
RWStructuredBuffer<float> output : register(u0);
[numthreads(1, 1, 1)]
void CSMain(uint3 DTid : SV_DispatchThreadID) {
output[0] = tex.SampleLevel(my_sampler, coord, 0);
output[DTid.x] = tex.Load(int3(coord[DTid.x], 0));
}
)";
const char* shader_source_msaa = R"(
sampler my_sampler : register(s0);
Texture2DMS<float, 2> tex : register(t0);
StructuredBuffer<int2> coord : register(t1);
RWStructuredBuffer<float> output : register(u0);
[numthreads(1, 1, 1)]
void CSMain(uint3 DTid : SV_DispatchThreadID) {
output[DTid.x] = tex.Load(coord[DTid.x], 0);
}
)";
#if DEBUG_D3D
UINT compile_flags = D3DCOMPILE_DEBUG;
#else
@ -426,7 +350,9 @@ void CSMain(uint3 DTid : SV_DispatchThreadID) {
#endif
ComPtr<ID3DBlob> cs, error_blob;
HRESULT hr = d3d.D3DCompile(shader_source, strlen(shader_source), nullptr, nullptr, nullptr, "CSMain", "cs_4_0", compile_flags, 0, cs.GetAddressOf(), error_blob.GetAddressOf());
HRESULT hr;
hr = d3d.D3DCompile(shader_source, strlen(shader_source), nullptr, nullptr, nullptr, "CSMain", "cs_4_0", compile_flags, 0, cs.GetAddressOf(), error_blob.GetAddressOf());
if (FAILED(hr)) {
char* err = (char*)error_blob->GetBufferPointer();
@ -436,6 +362,14 @@ void CSMain(uint3 DTid : SV_DispatchThreadID) {
ThrowIfFailed(d3d.device->CreateComputeShader(cs->GetBufferPointer(), cs->GetBufferSize(), nullptr, d3d.compute_shader.GetAddressOf()));
hr = d3d.D3DCompile(shader_source_msaa, strlen(shader_source_msaa), nullptr, nullptr, nullptr, "CSMain", "cs_4_1", compile_flags, 0, d3d.compute_shader_msaa_blob.GetAddressOf(), error_blob.ReleaseAndGetAddressOf());
if (FAILED(hr)) {
char* err = (char*)error_blob->GetBufferPointer();
MessageBoxA(gfx_dxgi_get_h_wnd(), err, "Error", MB_OK | MB_ICONERROR);
throw hr;
}
// Create ImGui
SohImGui::WindowImpl window_impl;
@ -445,8 +379,8 @@ void CSMain(uint3 DTid : SV_DispatchThreadID) {
}
static bool gfx_d3d11_z_is_from_0_to_1(void) {
return true;
static struct GfxClipParameters gfx_d3d11_get_clip_parameters(void) {
return { true, false };
}
static void gfx_d3d11_unload_shader(struct ShaderProgram *old_prg) {
@ -531,8 +465,8 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(uint64_t shade
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; // We initially clear alpha to 1.0f and want to keep it at 1.0f
blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
} else {
@ -592,6 +526,10 @@ static D3D11_TEXTURE_ADDRESS_MODE gfx_cm_to_d3d11(uint32_t val) {
static void gfx_d3d11_upload_texture(const uint8_t *rgba32_buf, uint32_t width, uint32_t height) {
// Create texture
TextureData *texture_data = &d3d.textures[d3d.current_texture_ids[d3d.current_tile]];
texture_data->width = width;
texture_data->height = height;
D3D11_TEXTURE2D_DESC texture_desc;
ZeroMemory(&texture_desc, sizeof(D3D11_TEXTURE2D_DESC));
@ -612,21 +550,11 @@ static void gfx_d3d11_upload_texture(const uint8_t *rgba32_buf, uint32_t width,
resource_data.SysMemPitch = width * 4;
resource_data.SysMemSlicePitch = resource_data.SysMemPitch * height;
ComPtr<ID3D11Texture2D> texture;
ThrowIfFailed(d3d.device->CreateTexture2D(&texture_desc, &resource_data, texture.GetAddressOf()));
TextureData *texture_data = &d3d.textures[d3d.current_texture_ids[d3d.current_tile]];
texture_data->width = width;
texture_data->height = height;
ThrowIfFailed(d3d.device->CreateTexture2D(&texture_desc, &resource_data, texture_data->texture.ReleaseAndGetAddressOf()));
// Create shader resource view from texture
if (texture_data->resource_view.Get() != nullptr) {
// Free the previous texture in this slot
texture_data->resource_view.Reset();
}
ThrowIfFailed(d3d.device->CreateShaderResourceView(texture.Get(), nullptr, texture_data->resource_view.GetAddressOf()));
ThrowIfFailed(d3d.device->CreateShaderResourceView(texture_data->texture.Get(), nullptr, texture_data->resource_view.ReleaseAndGetAddressOf()));
}
static void gfx_d3d11_set_sampler_parameters(int tile, bool linear_filter, uint32_t cms, uint32_t cmt) {
@ -803,20 +731,10 @@ static void gfx_d3d11_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_t
}
static void gfx_d3d11_on_resize(void) {
create_render_target_views(true);
//create_render_target_views(true);
}
static void gfx_d3d11_start_frame(void) {
// Set render targets
d3d.context->OMSetRenderTargets(1, d3d.backbuffer_view.GetAddressOf(), d3d.depth_stencil_view.Get());
// Clear render targets
const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
d3d.context->ClearRenderTargetView(d3d.backbuffer_view.Get(), clearColor);
d3d.context->ClearDepthStencilView(d3d.depth_stencil_view.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0);
// Set per-frame constant buffer
d3d.per_frame_cb_data.noise_frame++;
@ -824,22 +742,9 @@ static void gfx_d3d11_start_frame(void) {
// No high values, as noise starts to look ugly
d3d.per_frame_cb_data.noise_frame = 0;
}
float aspect_ratio = (float) d3d.current_width / (float) d3d.current_height;
d3d.render_target_height = d3d.current_height;
d3d.per_frame_cb_data.noise_scale_x = 120 * aspect_ratio; // 120 = N64 height resolution (240) / 2
d3d.per_frame_cb_data.noise_scale_y = 120;
D3D11_MAPPED_SUBRESOURCE ms;
ZeroMemory(&ms, sizeof(D3D11_MAPPED_SUBRESOURCE));
d3d.context->Map(d3d.per_frame_cb.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &ms);
memcpy(ms.pData, &d3d.per_frame_cb_data, sizeof(PerFrameCB));
d3d.context->Unmap(d3d.per_frame_cb.Get(), 0);
d3d.copied_depth_buffer = false;
}
static void gfx_d3d11_end_frame(void) {
SohImGui::Draw();
d3d.context->Flush();
}
@ -847,43 +752,13 @@ static void gfx_d3d11_finish_render(void) {
d3d.context->Flush();
}
void gfx_d3d11_resize_framebuffer(int fb, uint32_t width, uint32_t height) {
FramebufferData& fd = d3d.framebuffers[fb];
TextureData& td = d3d.textures[fd.texture_id];
ComPtr<ID3D11Texture2D> texture, depth_stencil_texture;
D3D11_TEXTURE2D_DESC texture_desc;
texture_desc.Width = width;
texture_desc.Height = height;
texture_desc.Usage = D3D11_USAGE_DEFAULT;
texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = 0;
texture_desc.ArraySize = 1;
texture_desc.MipLevels = 1;
texture_desc.SampleDesc.Count = 1;
texture_desc.SampleDesc.Quality = 0;
ThrowIfFailed(d3d.device->CreateTexture2D(&texture_desc, nullptr, texture.GetAddressOf()));
create_depth_stencil_objects(width, height, depth_stencil_texture.GetAddressOf(), fd.depth_stencil_view.ReleaseAndGetAddressOf(), nullptr);
ThrowIfFailed(d3d.device->CreateRenderTargetView(texture.Get(), nullptr, fd.render_target_view.ReleaseAndGetAddressOf()));
ThrowIfFailed(d3d.device->CreateShaderResourceView(texture.Get(), nullptr, td.resource_view.ReleaseAndGetAddressOf()));
td.width = width;
td.height = height;
}
int gfx_d3d11_create_framebuffer(uint32_t width, uint32_t height) {
int gfx_d3d11_create_framebuffer(void) {
uint32_t texture_id = gfx_d3d11_new_texture();
TextureData& t = d3d.textures[texture_id];
t.width = width;
t.height = height;
size_t index = d3d.framebuffers.size();
d3d.framebuffers.resize(d3d.framebuffers.size() + 1);
FramebufferData& data = d3d.framebuffers.back();
Framebuffer& data = d3d.framebuffers.back();
data.texture_id = texture_id;
uint32_t tile = 0;
@ -892,24 +767,109 @@ int gfx_d3d11_create_framebuffer(uint32_t width, uint32_t height) {
gfx_d3d11_set_sampler_parameters(0, true, G_TX_WRAP, G_TX_WRAP);
d3d.current_texture_ids[tile] = saved;
gfx_d3d11_resize_framebuffer(index, width, height);
return (int)index;
}
void gfx_d3d11_set_framebuffer(int fb) {
d3d.render_target_height = d3d.textures[d3d.framebuffers[fb].texture_id].height;
static void gfx_d3d11_update_framebuffer_parameters(int fb_id, uint32_t width, uint32_t height, uint32_t msaa_level, bool opengl_invert_y, bool render_target, bool has_depth_buffer, bool can_extract_depth) {
Framebuffer& fb = d3d.framebuffers[fb_id];
TextureData& tex = d3d.textures[fb.texture_id];
d3d.context->OMSetRenderTargets(1, d3d.framebuffers[fb].render_target_view.GetAddressOf(), d3d.framebuffers[fb].depth_stencil_view.Get());
width = max(width, 1U);
height = max(height, 1U);
while (msaa_level > 1 && d3d.msaa_num_quality_levels[msaa_level - 1] == 0) {
--msaa_level;
}
const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
d3d.context->ClearRenderTargetView(d3d.framebuffers[fb].render_target_view.Get(), clearColor);
d3d.context->ClearDepthStencilView(d3d.framebuffers[fb].depth_stencil_view.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0);
bool diff = tex.width != width || tex.height != height || fb.msaa_level != msaa_level;
if (diff || (fb.render_target_view.Get() != nullptr) != render_target) {
if (fb_id != 0) {
D3D11_TEXTURE2D_DESC texture_desc;
texture_desc.Width = width;
texture_desc.Height = height;
texture_desc.Usage = D3D11_USAGE_DEFAULT;
texture_desc.BindFlags = (msaa_level <= 1 ? D3D11_BIND_SHADER_RESOURCE : 0) | (render_target ? D3D11_BIND_RENDER_TARGET : 0);
texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = 0;
texture_desc.ArraySize = 1;
texture_desc.MipLevels = 1;
texture_desc.SampleDesc.Count = msaa_level;
texture_desc.SampleDesc.Quality = 0;
ThrowIfFailed(d3d.device->CreateTexture2D(&texture_desc, nullptr, tex.texture.ReleaseAndGetAddressOf()));
if (msaa_level <= 1) {
ThrowIfFailed(d3d.device->CreateShaderResourceView(tex.texture.Get(), nullptr, tex.resource_view.ReleaseAndGetAddressOf()));
}
} else if (diff) {
DXGI_SWAP_CHAIN_DESC1 desc1;
ThrowIfFailed(d3d.swap_chain->GetDesc1(&desc1));
if (desc1.Width != width || desc1.Height != height) {
fb.render_target_view.Reset();
tex.texture.Reset();
ThrowIfFailed(d3d.swap_chain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, desc1.Flags));
}
ThrowIfFailed(d3d.swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID *)tex.texture.ReleaseAndGetAddressOf()));
}
if (render_target) {
ThrowIfFailed(d3d.device->CreateRenderTargetView(tex.texture.Get(), nullptr, fb.render_target_view.ReleaseAndGetAddressOf()));
}
tex.width = width;
tex.height = height;
}
if (has_depth_buffer && (diff || !fb.has_depth_buffer || (fb.depth_stencil_srv.Get() != nullptr) != can_extract_depth)) {
fb.depth_stencil_srv.Reset();
create_depth_stencil_objects(width, height, msaa_level, fb.depth_stencil_view.ReleaseAndGetAddressOf(), can_extract_depth ? fb.depth_stencil_srv.GetAddressOf() : nullptr);
}
if (!has_depth_buffer) {
fb.depth_stencil_view.Reset();
fb.depth_stencil_srv.Reset();
}
fb.has_depth_buffer = has_depth_buffer;
fb.msaa_level = msaa_level;
}
void gfx_d3d11_reset_framebuffer(void) {
d3d.render_target_height = d3d.current_height;
d3d.context->OMSetRenderTargets(1, d3d.backbuffer_view.GetAddressOf(), d3d.depth_stencil_view.Get());
void gfx_d3d11_start_draw_to_framebuffer(int fb_id, float noise_scale) {
Framebuffer& fb = d3d.framebuffers[fb_id];
d3d.render_target_height = d3d.textures[fb.texture_id].height;
d3d.context->OMSetRenderTargets(1, fb.render_target_view.GetAddressOf(), fb.has_depth_buffer ? fb.depth_stencil_view.Get() : nullptr);
d3d.current_framebuffer = fb_id;
if (noise_scale != 0.0f) {
d3d.per_frame_cb_data.noise_scale = 1.0f / noise_scale;
}
D3D11_MAPPED_SUBRESOURCE ms;
ZeroMemory(&ms, sizeof(D3D11_MAPPED_SUBRESOURCE));
d3d.context->Map(d3d.per_frame_cb.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &ms);
memcpy(ms.pData, &d3d.per_frame_cb_data, sizeof(PerFrameCB));
d3d.context->Unmap(d3d.per_frame_cb.Get(), 0);
}
void gfx_d3d11_clear_framebuffer(void) {
Framebuffer& fb = d3d.framebuffers[d3d.current_framebuffer];
const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
d3d.context->ClearRenderTargetView(fb.render_target_view.Get(), clearColor);
if (fb.has_depth_buffer) {
d3d.context->ClearDepthStencilView(fb.depth_stencil_view.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0);
}
}
void gfx_d3d11_resolve_msaa_color_buffer(int fb_id_target, int fb_id_source) {
Framebuffer& fb_dst = d3d.framebuffers[fb_id_target];
Framebuffer& fb_src = d3d.framebuffers[fb_id_source];
d3d.context->ResolveSubresource(d3d.textures[fb_dst.texture_id].texture.Get(), 0, d3d.textures[fb_src.texture_id].texture.Get(), 0, DXGI_FORMAT_R8G8B8A8_UNORM);
}
void *gfx_d3d11_get_framebuffer_texture_id(int fb_id) {
return (void *)d3d.textures[d3d.framebuffers[fb_id].texture_id].resource_view.Get();
}
void gfx_d3d11_select_texture_fb(int fbID) {
@ -917,72 +877,117 @@ void gfx_d3d11_select_texture_fb(int fbID) {
gfx_d3d11_select_texture(tile, d3d.framebuffers[fbID].texture_id);
}
uint16_t gfx_d3d11_get_pixel_depth(float x, float y) {
std::map<std::pair<float, float>, uint16_t> gfx_d3d11_get_pixel_depth(int fb_id, const std::set<std::pair<float, float>>& coordinates) {
Framebuffer& fb = d3d.framebuffers[fb_id];
TextureData& td = d3d.textures[fb.texture_id];
if (coordinates.size() > d3d.coord_buffer_size) {
d3d.coord_buffer.Reset();
d3d.coord_buffer_srv.Reset();
d3d.depth_value_output_buffer.Reset();
d3d.depth_value_output_uav.Reset();
d3d.depth_value_output_buffer_copy.Reset();
D3D11_BUFFER_DESC coord_buf_desc;
coord_buf_desc.Usage = D3D11_USAGE_DYNAMIC;
coord_buf_desc.ByteWidth = sizeof(Coord) * coordinates.size();
coord_buf_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
coord_buf_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
coord_buf_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
coord_buf_desc.StructureByteStride = sizeof(Coord);
ThrowIfFailed(d3d.device->CreateBuffer(&coord_buf_desc, nullptr, d3d.coord_buffer.GetAddressOf()));
D3D11_SHADER_RESOURCE_VIEW_DESC coord_buf_srv_desc;
coord_buf_srv_desc.Format = DXGI_FORMAT_UNKNOWN;
coord_buf_srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
coord_buf_srv_desc.Buffer.FirstElement = 0;
coord_buf_srv_desc.Buffer.NumElements = coordinates.size();
ThrowIfFailed(d3d.device->CreateShaderResourceView(d3d.coord_buffer.Get(), &coord_buf_srv_desc, d3d.coord_buffer_srv.GetAddressOf()));
D3D11_BUFFER_DESC output_buffer_desc;
output_buffer_desc.Usage = D3D11_USAGE_DEFAULT;
output_buffer_desc.ByteWidth = sizeof(float) * coordinates.size();
output_buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
output_buffer_desc.CPUAccessFlags = 0;
output_buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
output_buffer_desc.StructureByteStride = sizeof(float);
ThrowIfFailed(d3d.device->CreateBuffer(&output_buffer_desc, nullptr, d3d.depth_value_output_buffer.GetAddressOf()));
D3D11_UNORDERED_ACCESS_VIEW_DESC output_buffer_uav_desc;
output_buffer_uav_desc.Format = DXGI_FORMAT_UNKNOWN;
output_buffer_uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
output_buffer_uav_desc.Buffer.FirstElement = 0;
output_buffer_uav_desc.Buffer.NumElements = coordinates.size();
output_buffer_uav_desc.Buffer.Flags = 0;
ThrowIfFailed(d3d.device->CreateUnorderedAccessView(d3d.depth_value_output_buffer.Get(), &output_buffer_uav_desc, d3d.depth_value_output_uav.GetAddressOf()));
output_buffer_desc.Usage = D3D11_USAGE_STAGING;
output_buffer_desc.BindFlags = 0;
output_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
ThrowIfFailed(d3d.device->CreateBuffer(&output_buffer_desc, nullptr, d3d.depth_value_output_buffer_copy.GetAddressOf()));
d3d.coord_buffer_size = coordinates.size();
}
D3D11_MAPPED_SUBRESOURCE ms;
if (fb.msaa_level > 1 && d3d.compute_shader_msaa.Get() == nullptr) {
ThrowIfFailed(d3d.device->CreateComputeShader(d3d.compute_shader_msaa_blob->GetBufferPointer(), d3d.compute_shader_msaa_blob->GetBufferSize(), nullptr, d3d.compute_shader_msaa.GetAddressOf()));
}
// ImGui overwrites these values, so we cannot set them once at init
d3d.context->CSSetShader(d3d.compute_shader.Get(), nullptr, 0);
d3d.context->CSSetConstantBuffers(0, 1, d3d.coord_buffer.GetAddressOf());
d3d.context->CSSetSamplers(0, 1, d3d.depth_value_sampler.GetAddressOf());
d3d.context->CSSetShader(fb.msaa_level > 1 ? d3d.compute_shader_msaa.Get() : d3d.compute_shader.Get(), nullptr, 0);
d3d.context->CSSetUnorderedAccessViews(0, 1, d3d.depth_value_output_uav.GetAddressOf(), nullptr);
ThrowIfFailed(d3d.context->Map(d3d.coord_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &ms));
CoordCB* coord_cb = (CoordCB*)ms.pData;
coord_cb->x = x / d3d.current_width;
// We invert y because the game assumes OpenGL coordinates (bottom-left corner is origin), while DX's origin is top-left corner
coord_cb->y = 1 - y / d3d.current_height;
Coord *coord_cb = (Coord *)ms.pData;
{
size_t i = 0;
for (const auto& coord : coordinates) {
coord_cb[i].x = coord.first;
// We invert y because the gfx_pc assumes OpenGL coordinates (bottom-left corner is origin), while DX's origin is top-left corner
coord_cb[i].y = td.height - 1 - coord.second;
++i;
}
}
d3d.context->Unmap(d3d.coord_buffer.Get(), 0);
// The depth stencil texture can only have one mapping at a time, so temporarily unbind from the OM
d3d.context->OMSetRenderTargets(1, d3d.backbuffer_view.GetAddressOf(), nullptr);
d3d.context->CSSetShaderResources(0, 1, d3d.depth_stencil_srv.GetAddressOf());
// The depth stencil texture can only have one mapping at a time, so unbind from the OM
ID3D11RenderTargetView* null_arr1[1] = { nullptr };
d3d.context->OMSetRenderTargets(1, null_arr1, nullptr);
d3d.context->Dispatch(1, 1, 1);
ID3D11ShaderResourceView *srvs[] = { fb.depth_stencil_srv.Get(), d3d.coord_buffer_srv.Get() };
d3d.context->CSSetShaderResources(0, 2, srvs);
d3d.context->Dispatch(coordinates.size(), 1, 1);
d3d.context->CopyResource(d3d.depth_value_output_buffer_copy.Get(), d3d.depth_value_output_buffer.Get());
ThrowIfFailed(d3d.context->Map(d3d.depth_value_output_buffer_copy.Get(), 0, D3D11_MAP_READ, 0, &ms));
float res = *(float *)ms.pData;
d3d.context->Unmap(d3d.depth_value_output_buffer_copy.Get(), 0);
ID3D11ShaderResourceView *null_arr[1] = { nullptr };
d3d.context->CSSetShaderResources(0, 1, null_arr);
d3d.context->OMSetRenderTargets(1, d3d.backbuffer_view.GetAddressOf(), d3d.depth_stencil_view.Get());
return res * 65532.0f;
}
uint16_t gfx_d3d11_get_pixel_depth_old(float x, float y) {
// This approach, compared to using a compute shader, might have better performance on nvidia cards
if (!d3d.copied_depth_buffer) {
d3d.context->CopyResource(d3d.depth_stencil_copy_texture.Get(), d3d.depth_stencil_texture.Get());
d3d.copied_depth_buffer = true;
}
D3D11_MAPPED_SUBRESOURCE mapping_desc;
d3d.context->Map(d3d.depth_stencil_copy_texture.Get(), 0, D3D11_MAP_READ, 0, &mapping_desc);
float res = 0;
if (mapping_desc.pData != nullptr) {
float *addr = (float *)mapping_desc.pData;
uint32_t num_pixels = mapping_desc.DepthPitch / sizeof(float);
uint32_t width = mapping_desc.RowPitch / sizeof(float);
uint32_t height = width == 0 ? 0 : num_pixels / width;
if (x >= 0 && x < width && y >= 0 && y < height) {
res = addr[width * (height - 1 - (int)y) + (int)x];
std::map<std::pair<float, float>, uint16_t> res;
{
size_t i = 0;
for (const auto& coord : coordinates) {
res.emplace(coord, ((float *)ms.pData)[i++] * 65532.0f);
}
}
d3d.context->Unmap(d3d.depth_stencil_copy_texture.Get(), 0);
return res * 65532.0f;
d3d.context->Unmap(d3d.depth_value_output_buffer_copy.Get(), 0);
ID3D11ShaderResourceView *null_arr[2] = { nullptr, nullptr };
d3d.context->CSSetShaderResources(0, 2, null_arr);
return res;
}
} // namespace
void* SohImGui::GetTextureByID(int id) {
return d3d.textures[id].resource_view.Get();
ImTextureID SohImGui::GetTextureByID(int id) {
return impl.backend == Backend::DX11 ? d3d.textures[id].resource_view.Get() : reinterpret_cast<ImTextureID>(id);
}
struct GfxRenderingAPI gfx_direct3d11_api = {
gfx_d3d11_z_is_from_0_to_1,
gfx_d3d11_get_clip_parameters,
gfx_d3d11_unload_shader,
gfx_d3d11_load_shader,
gfx_d3d11_create_and_load_new_shader,
@ -993,7 +998,6 @@ struct GfxRenderingAPI gfx_direct3d11_api = {
gfx_d3d11_upload_texture,
gfx_d3d11_set_sampler_parameters,
gfx_d3d11_set_depth_test_and_mask,
gfx_d3d11_get_pixel_depth,
gfx_d3d11_set_zmode_decal,
gfx_d3d11_set_viewport,
gfx_d3d11_set_scissor,
@ -1005,9 +1009,12 @@ struct GfxRenderingAPI gfx_direct3d11_api = {
gfx_d3d11_end_frame,
gfx_d3d11_finish_render,
gfx_d3d11_create_framebuffer,
gfx_d3d11_resize_framebuffer,
gfx_d3d11_set_framebuffer,
gfx_d3d11_reset_framebuffer,
gfx_d3d11_update_framebuffer_parameters,
gfx_d3d11_start_draw_to_framebuffer,
gfx_d3d11_clear_framebuffer,
gfx_d3d11_resolve_msaa_color_buffer,
gfx_d3d11_get_pixel_depth,
gfx_d3d11_get_framebuffer_texture_id,
gfx_d3d11_select_texture_fb,
gfx_d3d11_delete_texture
};

View File

@ -134,9 +134,6 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
}
}
}
if (cc_features.opt_alpha && cc_features.opt_noise) {
append_line(buf, &len, " float4 screenPos : TEXCOORD2;");
}
if (cc_features.opt_fog) {
append_line(buf, &len, " float4 fog : FOG;");
num_floats += 4;
@ -163,7 +160,7 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
if (cc_features.opt_alpha && cc_features.opt_noise) {
append_line(buf, &len, "cbuffer PerFrameCB : register(b0) {");
append_line(buf, &len, " uint noise_frame;");
append_line(buf, &len, " float2 noise_scale;");
append_line(buf, &len, " float noise_scale;");
append_line(buf, &len, "}");
append_line(buf, &len, "float random(in float3 value) {");
@ -217,9 +214,6 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
append_line(buf, &len, ") {");
append_line(buf, &len, " PSInput result;");
append_line(buf, &len, " result.position = position;");
if (cc_features.opt_alpha && cc_features.opt_noise) {
append_line(buf, &len, " result.screenPos = position;");
}
for (int i = 0; i < 2; i++) {
if (cc_features.used_textures[i]) {
len += sprintf(buf + len, " result.uv%d = uv%d;\r\n", i, i);
@ -244,7 +238,11 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
if (include_root_signature) {
append_line(buf, &len, "[RootSignature(RS)]");
}
append_line(buf, &len, "float4 PSMain(PSInput input) : SV_TARGET {");
if (cc_features.opt_alpha && cc_features.opt_noise) {
append_line(buf, &len, "float4 PSMain(PSInput input, float4 screenSpace : SV_Position) : SV_TARGET {");
} else {
append_line(buf, &len, "float4 PSMain(PSInput input) : SV_TARGET {");
}
for (int i = 0; i < 2; i++) {
if (cc_features.used_textures[i]) {
len += sprintf(buf + len, " float2 tc%d = input.uv%d;\r\n", i, i);
@ -301,7 +299,7 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
}
if (cc_features.opt_alpha && cc_features.opt_noise) {
append_line(buf, &len, " float2 coords = (input.screenPos.xy / input.screenPos.w) * noise_scale;");
append_line(buf, &len, " float2 coords = screenSpace.xy * noise_scale;");
append_line(buf, &len, " texel.a *= round(saturate(random(float3(floor(coords), noise_frame)) + texel.a - 0.5));");
}

View File

@ -10,6 +10,7 @@
#include <windows.h>
#include <wrl/client.h>
#include <dxgi1_3.h>
#include <dxgi1_4.h>
#include <versionhelpers.h>
#include <shellscalingapi.h>
@ -61,6 +62,7 @@ static struct {
RECT last_window_rect;
bool is_full_screen, last_maximized_state;
bool dxgi1_4;
ComPtr<IDXGIFactory2> factory;
ComPtr<IDXGISwapChain1> swap_chain;
HANDLE waitable_object;
@ -197,17 +199,6 @@ static void toggle_borderless_window_full_screen(bool enable, bool call_callback
}
}
static void gfx_dxgi_on_resize(void) {
if (dxgi.swap_chain.Get() != nullptr) {
gfx_get_current_rendering_api()->on_resize();
DXGI_SWAP_CHAIN_DESC1 desc1;
ThrowIfFailed(dxgi.swap_chain->GetDesc1(&desc1));
dxgi.current_width = desc1.Width;
dxgi.current_height = desc1.Height;
}
}
static void onkeydown(WPARAM w_param, LPARAM l_param) {
int key = ((l_param >> 16) & 0x1ff);
if (dxgi.on_key_down != nullptr) {
@ -227,7 +218,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par
SohImGui::Update(event_impl);
switch (message) {
case WM_SIZE:
gfx_dxgi_on_resize();
dxgi.current_width = (uint32_t)(l_param & 0xffff);
dxgi.current_height = (uint32_t)(l_param >> 16);
break;
case WM_DESTROY:
exit(0);
@ -573,6 +565,13 @@ void gfx_dxgi_create_factory_and_device(bool debug, int d3d_version, bool (*crea
ThrowIfFailed(dxgi.CreateDXGIFactory1(__uuidof(IDXGIFactory2), &dxgi.factory));
}
{
ComPtr<IDXGIFactory4> factory4;
if (dxgi.factory->QueryInterface(__uuidof(IDXGIFactory4), &factory4) == S_OK) {
dxgi.dxgi1_4 = true;
}
}
ComPtr<IDXGIAdapter1> adapter;
for (UINT i = 0; dxgi.factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; i++) {
DXGI_ADAPTER_DESC1 desc;
@ -604,7 +603,9 @@ ComPtr<IDXGISwapChain1> gfx_dxgi_create_swap_chain(IUnknown *device) {
swap_chain_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.Scaling = win8 ? DXGI_SCALING_NONE : DXGI_SCALING_STRETCH;
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // Apparently this was backported to Win 7 Platform Update
swap_chain_desc.SwapEffect = dxgi.dxgi1_4 ?
DXGI_SWAP_EFFECT_FLIP_DISCARD : // Introduced in DXGI 1.4 and Windows 10
DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // Apparently flip sequential was also backported to Win 7 Platform Update
swap_chain_desc.Flags = dxgi_13 ? DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT : 0;
swap_chain_desc.SampleDesc.Count = 1;

View File

@ -52,19 +52,33 @@ struct ShaderProgram {
uint8_t num_attribs;
bool used_noise;
GLint frame_count_location;
GLint window_height_location;
GLint noise_scale_location;
};
struct Framebuffer {
uint32_t width, height;
bool has_depth_buffer;
uint32_t msaa_level;
bool invert_y;
GLuint fbo, clrbuf, clrbuf_msaa, rbo;
};
static map<pair<uint64_t, uint32_t>, struct ShaderProgram> shader_program_pool;
static GLuint opengl_vbo;
static uint32_t frame_count;
static uint32_t current_height;
static map<int, pair<GLuint, GLuint>> fb2tex;
static bool current_depth_mask;
static bool gfx_opengl_z_is_from_0_to_1(void) {
return false;
static uint32_t frame_count;
static vector<Framebuffer> framebuffers;
static size_t current_framebuffer;
static float current_noise_scale;
GLuint pixel_depth_rb, pixel_depth_fb;
size_t pixel_depth_rb_size;
static struct GfxClipParameters gfx_opengl_get_clip_parameters(void) {
return { false, framebuffers[current_framebuffer].invert_y };
}
static void gfx_opengl_vertex_array_set_attribs(struct ShaderProgram *prg) {
@ -81,7 +95,7 @@ static void gfx_opengl_vertex_array_set_attribs(struct ShaderProgram *prg) {
static void gfx_opengl_set_uniforms(struct ShaderProgram *prg) {
if (prg->used_noise) {
glUniform1i(prg->frame_count_location, frame_count);
glUniform1i(prg->window_height_location, current_height);
glUniform1f(prg->noise_scale_location, current_noise_scale);
}
}
@ -277,7 +291,7 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
if (cc_features.opt_alpha && cc_features.opt_noise) {
append_line(fs_buf, &fs_len, "uniform int frame_count;");
append_line(fs_buf, &fs_len, "uniform int window_height;");
append_line(fs_buf, &fs_len, "uniform float noise_scale;");
append_line(fs_buf, &fs_len, "float random(in vec3 value) {");
append_line(fs_buf, &fs_len, " float random = dot(sin(value), vec3(12.9898, 78.233, 37.719));");
@ -338,7 +352,7 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
}
if (cc_features.opt_alpha && cc_features.opt_noise) {
append_line(fs_buf, &fs_len, "texel.a *= floor(clamp(random(vec3(floor(gl_FragCoord.xy * (240.0 / float(window_height))), float(frame_count))) + texel.a, 0.0, 1.0));");
append_line(fs_buf, &fs_len, "texel.a *= floor(clamp(random(vec3(floor(gl_FragCoord.xy * noise_scale), float(frame_count))) + texel.a, 0.0, 1.0));");
}
if (cc_features.opt_alpha) {
@ -460,7 +474,7 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
if (cc_features.opt_alpha && cc_features.opt_noise) {
prg->frame_count_location = glGetUniformLocation(shader_program, "frame_count");
prg->window_height_location = glGetUniformLocation(shader_program, "window_height");
prg->noise_scale_location = glGetUniformLocation(shader_program, "noise_scale");
prg->used_noise = true;
} else {
prg->used_noise = false;
@ -496,7 +510,7 @@ static void gfx_opengl_select_texture(int tile, GLuint texture_id) {
}
static void gfx_opengl_upload_texture(const uint8_t *rgba32_buf, uint32_t width, uint32_t height) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba32_buf);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba32_buf);
}
static uint32_t gfx_cm_to_opengl(uint32_t val) {
@ -543,7 +557,6 @@ static void gfx_opengl_set_zmode_decal(bool zmode_decal) {
static void gfx_opengl_set_viewport(int x, int y, int width, int height) {
glViewport(x, y, width, height);
current_height = height;
}
static void gfx_opengl_set_scissor(int x, int y, int width, int height) {
@ -564,10 +577,6 @@ static void gfx_opengl_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_
glDrawArrays(GL_TRIANGLES, 0, 3 * buf_vbo_num_tris);
}
static unsigned int framebuffer;
static unsigned int textureColorbuffer;
static unsigned int rbo;
static void gfx_opengl_init(void) {
//#if FOR_WINDOWS
glewInit();
@ -576,143 +585,214 @@ static void gfx_opengl_init(void) {
glGenBuffers(1, &opengl_vbo);
glBindBuffer(GL_ARRAY_BUFFER, opengl_vbo);
glGenFramebuffers(1, &framebuffer);
glGenTextures(1, &textureColorbuffer);
glGenRenderbuffers(1, &rbo);
SohUtils::saveEnvironmentVar("framebuffer", std::to_string(textureColorbuffer));
glDepthFunc(GL_LEQUAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
framebuffers.resize(1); // for the default screen buffer
glGenRenderbuffers(1, &pixel_depth_rb);
glBindRenderbuffer(GL_RENDERBUFFER, pixel_depth_rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 1, 1);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glGenFramebuffers(1, &pixel_depth_fb);
glBindFramebuffer(GL_FRAMEBUFFER, pixel_depth_fb);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, pixel_depth_rb);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
pixel_depth_rb_size = 1;
}
static void gfx_opengl_on_resize(void) {
}
static void gfx_opengl_start_frame(void) {
GLsizei framebuffer_width = gfx_current_dimensions.width;
GLsizei framebuffer_height = gfx_current_dimensions.height;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
std::shared_ptr<Ship::Window> wnd = Ship::GlobalCtx2::GetInstance()->GetWindow();
glBindTexture(GL_TEXTURE_2D, textureColorbuffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, framebuffer_width, framebuffer_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorbuffer, 0);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, framebuffer_width, framebuffer_height); // use a single renderbuffer object for both a depth AND stencil buffer.
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo); // now actually attach it
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
frame_count++;
glDisable(GL_SCISSOR_TEST);
glDepthMask(GL_TRUE);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glEnable(GL_DEPTH_CLAMP);
current_depth_mask = true;
}
static void gfx_opengl_end_frame(void) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
GLint last_program;
glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
glUseProgram(0);
SohImGui::Draw();
glUseProgram(last_program);
glFlush();
}
static void gfx_opengl_finish_render(void) {
}
static int gfx_opengl_create_framebuffer(uint32_t width, uint32_t height) {
GLuint textureColorbuffer;
glGenTextures(1, &textureColorbuffer);
glBindTexture(GL_TEXTURE_2D, textureColorbuffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
static int gfx_opengl_create_framebuffer() {
GLuint clrbuf;
glGenTextures(1, &clrbuf);
glBindTexture(GL_TEXTURE_2D, clrbuf);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
GLuint clrbuf_msaa;
glGenRenderbuffers(1, &clrbuf_msaa);
GLuint rbo;
glGenRenderbuffers(1, &rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 1, 1);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorbuffer, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
size_t i = framebuffers.size();
framebuffers.resize(i + 1);
fb2tex[fbo] = make_pair(textureColorbuffer, rbo);
framebuffers[i].fbo = fbo;
framebuffers[i].clrbuf = clrbuf;
framebuffers[i].clrbuf_msaa = clrbuf_msaa;
framebuffers[i].rbo = rbo;
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
return fbo;
return i;
}
static void gfx_opengl_resize_framebuffer(int fb, uint32_t width, uint32_t height) {
glBindTexture(GL_TEXTURE_2D, fb2tex[fb].first);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
static void gfx_opengl_update_framebuffer_parameters(int fb_id, uint32_t width, uint32_t height, uint32_t msaa_level, bool opengl_invert_y, bool render_target, bool has_depth_buffer, bool can_extract_depth) {
Framebuffer& fb = framebuffers[fb_id];
glBindRenderbuffer(GL_RENDERBUFFER, fb2tex[fb].second);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
width = max(width, 1U);
height = max(height, 1U);
void gfx_opengl_set_framebuffer(int fb)
{
if (GLEW_ARB_clip_control || GLEW_VERSION_4_5) {
// Set origin to upper left corner, to match N64 and DX11
// If this function is not supported, the texture will be upside down :(
glClipControl(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
glBindFramebuffer(GL_FRAMEBUFFER, fb.fbo);
if (fb_id != 0) {
if (fb.width != width || fb.height != height || fb.msaa_level != msaa_level) {
if (msaa_level <= 1) {
glBindTexture(GL_TEXTURE_2D, fb.clrbuf);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.clrbuf, 0);
} else {
glBindRenderbuffer(GL_RENDERBUFFER, fb.clrbuf_msaa);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa_level, GL_RGB8, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fb.clrbuf_msaa);
}
}
if (has_depth_buffer && (fb.width != width || fb.height != height || fb.msaa_level != msaa_level || !fb.has_depth_buffer)) {
glBindRenderbuffer(GL_RENDERBUFFER, fb.rbo);
if (msaa_level <= 1) {
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
} else {
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa_level, GL_DEPTH24_STENCIL8, width, height);
}
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
if (!fb.has_depth_buffer && has_depth_buffer) {
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fb.rbo);
} else if (fb.has_depth_buffer && !has_depth_buffer) {
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
}
}
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb);
fb.width = width;
fb.height = height;
fb.has_depth_buffer = has_depth_buffer;
fb.msaa_level = msaa_level;
fb.invert_y = opengl_invert_y;
}
void gfx_opengl_start_draw_to_framebuffer(int fb_id, float noise_scale) {
Framebuffer& fb = framebuffers[fb_id];
if (noise_scale != 0.0f) {
current_noise_scale = 1.0f / noise_scale;
}
glBindFramebuffer(GL_FRAMEBUFFER, fb.fbo);
current_framebuffer = fb_id;
}
void gfx_opengl_clear_framebuffer() {
glDisable(GL_SCISSOR_TEST);
glDepthMask(GL_TRUE);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthMask(current_depth_mask ? GL_TRUE : GL_FALSE);
glEnable(GL_SCISSOR_TEST);
}
void gfx_opengl_reset_framebuffer(void)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, framebuffer);
if (GLEW_ARB_clip_control || GLEW_VERSION_4_5) {
glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
}
void gfx_opengl_resolve_msaa_color_buffer(int fb_id_target, int fb_id_source) {
Framebuffer& fb_dst = framebuffers[fb_id_target];
Framebuffer& fb_src = framebuffers[fb_id_source];
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb_dst.fbo);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb_src.fbo);
glBlitFramebuffer(0, 0, fb_src.width, fb_src.height, 0, 0, fb_dst.width, fb_dst.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, current_framebuffer);
}
void gfx_opengl_select_texture_fb(int fbID)
{
void *gfx_opengl_get_framebuffer_texture_id(int fb_id) {
return (void *)(uintptr_t)framebuffers[fb_id].clrbuf;
}
void gfx_opengl_select_texture_fb(int fb_id) {
//glDisable(GL_DEPTH_TEST);
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, fb2tex[fbID].first);
glBindTexture(GL_TEXTURE_2D, framebuffers[fb_id].clrbuf);
}
static uint16_t gfx_opengl_get_pixel_depth(float x, float y) {
float depth;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return depth * 65532.0f;
static std::map<std::pair<float, float>, uint16_t> gfx_opengl_get_pixel_depth(int fb_id, const std::set<std::pair<float, float>>& coordinates) {
std::map<std::pair<float, float>, uint16_t> res;
Framebuffer& fb = framebuffers[fb_id];
if (coordinates.size() == 1) {
uint32_t depth_stencil_value;
glBindFramebuffer(GL_FRAMEBUFFER, fb.fbo);
int x = coordinates.begin()->first;
int y = coordinates.begin()->second;
glReadPixels(x, fb.invert_y ? fb.height - y : y, 1, 1, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, &depth_stencil_value);
res.emplace(*coordinates.begin(), (depth_stencil_value >> 18) << 2);
} else {
if (pixel_depth_rb_size < coordinates.size()) {
glBindRenderbuffer(GL_RENDERBUFFER, pixel_depth_rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, coordinates.size(), 1);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
pixel_depth_rb_size = coordinates.size();
}
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb.fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, pixel_depth_fb);
glDisable(GL_SCISSOR_TEST); // needed for the blit operation
{
size_t i = 0;
for (const auto& coord : coordinates) {
int x = coord.first;
int y = coord.second;
if (fb.invert_y) {
y = fb.height - y;
}
glBlitFramebuffer(x, y, x + 1, y + 1, i, 0, i + 1, 1, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
++i;
}
}
glBindFramebuffer(GL_READ_FRAMEBUFFER, pixel_depth_fb);
vector<uint32_t> depth_stencil_values(coordinates.size());
glReadPixels(0, 0, coordinates.size(), 1, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, depth_stencil_values.data());
{
size_t i = 0;
for (const auto& coord : coordinates) {
res.emplace(coord, (depth_stencil_values[i++] >> 18) << 2);
}
}
}
glBindFramebuffer(GL_FRAMEBUFFER, current_framebuffer);
return res;
}
struct GfxRenderingAPI gfx_opengl_api = {
gfx_opengl_z_is_from_0_to_1,
gfx_opengl_get_clip_parameters,
gfx_opengl_unload_shader,
gfx_opengl_load_shader,
gfx_opengl_create_and_load_new_shader,
@ -723,7 +803,6 @@ struct GfxRenderingAPI gfx_opengl_api = {
gfx_opengl_upload_texture,
gfx_opengl_set_sampler_parameters,
gfx_opengl_set_depth_test_and_mask,
gfx_opengl_get_pixel_depth,
gfx_opengl_set_zmode_decal,
gfx_opengl_set_viewport,
gfx_opengl_set_scissor,
@ -735,9 +814,12 @@ struct GfxRenderingAPI gfx_opengl_api = {
gfx_opengl_end_frame,
gfx_opengl_finish_render,
gfx_opengl_create_framebuffer,
gfx_opengl_resize_framebuffer,
gfx_opengl_set_framebuffer,
gfx_opengl_reset_framebuffer,
gfx_opengl_update_framebuffer_parameters,
gfx_opengl_start_draw_to_framebuffer,
gfx_opengl_clear_framebuffer,
gfx_opengl_resolve_msaa_color_buffer,
gfx_opengl_get_pixel_depth,
gfx_opengl_get_framebuffer_texture_id,
gfx_opengl_select_texture_fb,
gfx_opengl_delete_texture
};

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>
@ -27,6 +28,8 @@
#include "../../luslog.h"
#include "../StrHash64.h"
#include "../../SohImGuiImpl.h"
#include "../../Environment.h"
// OTRTODO: fix header files for these
extern "C" {
@ -71,10 +74,6 @@ struct RGBA {
uint8_t r, g, b, a;
};
struct XYWidthHeight {
uint16_t x, y, width, height;
};
struct LoadedVertex {
float x, y, z, w;
float u, v;
@ -174,8 +173,16 @@ static struct RenderingState {
TextureCacheNode *textures[2];
} rendering_state;
struct GfxDimensions gfx_current_window_dimensions;
struct GfxDimensions gfx_current_dimensions;
static struct GfxDimensions gfx_prev_dimensions;
struct XYWidthHeight gfx_current_game_window_viewport;
static bool game_renders_to_framebuffer;
static int game_framebuffer;
static int game_framebuffer_msaa_resolved;
uint32_t gfx_msaa_level = 1;
static bool dropped_frame;
@ -198,6 +205,9 @@ static bool fbActive = 0;
static map<int, FBInfo>::iterator active_fb;
static map<int, FBInfo> framebuffers;
static set<pair<float, float>> get_pixel_depth_pending;
static map<pair<float, float>, uint16_t> get_pixel_depth_cached;
#ifdef _MSC_VER
// TODO: Properly implement for MSVC
static unsigned long get_time(void)
@ -1326,11 +1336,11 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
gfx_rapi->shader_get_info(prg, &num_inputs, used_textures);
bool z_is_from_0_to_1 = gfx_rapi->z_is_from_0_to_1();
struct GfxClipParameters clip_parameters = gfx_rapi->get_clip_parameters();
for (int i = 0; i < 3; i++) {
float z = v_arr[i]->z, w = v_arr[i]->w;
if (z_is_from_0_to_1) {
if (clip_parameters.z_is_from_0_to_1) {
z = (z + w) / 2.0f;
}
@ -1340,7 +1350,7 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
}
buf_vbo[buf_vbo_len++] = v_arr[i]->x;
buf_vbo[buf_vbo_len++] = v_arr[i]->y;
buf_vbo[buf_vbo_len++] = clip_parameters.invert_y ? -v_arr[i]->y : v_arr[i]->y;
buf_vbo[buf_vbo_len++] = z;
buf_vbo[buf_vbo_len++] = w;
@ -1491,6 +1501,27 @@ static void gfx_sp_geometry_mode(uint32_t clear, uint32_t set) {
rsp.geometry_mode |= set;
}
static void gfx_adjust_viewport_or_scissor(XYWidthHeight *area) {
if (!fbActive) {
area->width *= RATIO_X;
area->height *= RATIO_Y;
area->x *= RATIO_X;
area->y = SCREEN_HEIGHT - area->y;
area->y *= RATIO_Y;
if (!game_renders_to_framebuffer || (gfx_msaa_level > 1 && gfx_current_dimensions.width == gfx_current_game_window_viewport.width && gfx_current_dimensions.height == gfx_current_game_window_viewport.height)) {
area->x += gfx_current_game_window_viewport.x;
area->y += gfx_current_window_dimensions.height - (gfx_current_game_window_viewport.y + gfx_current_game_window_viewport.height);
}
} else {
area->width *= RATIO_Y;
area->height *= RATIO_Y;
area->x *= RATIO_Y;
area->y = active_fb->second.orig_height - area->y;
area->y *= RATIO_Y;
}
}
static void gfx_calc_and_set_viewport(const Vp_t *viewport) {
// 2 bits fraction
float width = 2.0f * viewport->vscale[0] / 4.0f;
@ -1498,25 +1529,13 @@ static void gfx_calc_and_set_viewport(const Vp_t *viewport) {
float x = (viewport->vtrans[0] / 4.0f) - width / 2.0f;
float y = ((viewport->vtrans[1] / 4.0f) + height / 2.0f);
if (!fbActive) {
width *= RATIO_X;
height *= RATIO_Y;
x *= RATIO_X;
y = SCREEN_HEIGHT - y;
y *= RATIO_Y;
} else {
width *= RATIO_Y;
height *= RATIO_Y;
x *= RATIO_Y;
y = active_fb->second.orig_height - y;
y *= RATIO_Y;
}
rdp.viewport.x = x;
rdp.viewport.y = y;
rdp.viewport.width = width;
rdp.viewport.height = height;
gfx_adjust_viewport_or_scissor(&rdp.viewport);
rdp.viewport_or_scissor_changed = true;
}
@ -1585,11 +1604,6 @@ static void gfx_sp_texture(uint16_t sc, uint16_t tc, uint8_t level, uint8_t tile
rdp.textures_changed[1] = true;
}
if (tile > 8)
{
int bp = 0;
}
rdp.first_tile_index = tile;
}
@ -1599,25 +1613,13 @@ static void gfx_dp_set_scissor(uint32_t mode, uint32_t ulx, uint32_t uly, uint32
float width = (lrx - ulx) / 4.0f;
float height = (lry - uly) / 4.0f;
if (!fbActive) {
x *= RATIO_X;
y = SCREEN_HEIGHT - y;
y *= RATIO_Y;
width *= RATIO_X;
height *= RATIO_Y;
} else {
width *= RATIO_Y;
height *= RATIO_Y;
x *= RATIO_Y;
y = active_fb->second.orig_height - y;
y *= RATIO_Y;
}
rdp.scissor.x = x;
rdp.scissor.y = y;
rdp.scissor.width = width;
rdp.scissor.height = height;
gfx_adjust_viewport_or_scissor(&rdp.scissor);
rdp.viewport_or_scissor_changed = true;
}
@ -1887,10 +1889,12 @@ static void gfx_draw_rectangle(int32_t ulx, int32_t uly, int32_t lrx, int32_t lr
ur->w = 1.0f;
// The coordinates for texture rectangle shall bypass the viewport setting
struct XYWidthHeight default_viewport = { 0, 0, gfx_current_dimensions.width, gfx_current_dimensions.height };
struct XYWidthHeight default_viewport = { 0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT };
struct XYWidthHeight viewport_saved = rdp.viewport;
uint32_t geometry_mode_saved = rsp.geometry_mode;
gfx_adjust_viewport_or_scissor(&default_viewport);
rdp.viewport = default_viewport;
rdp.viewport_or_scissor_changed = true;
rsp.geometry_mode = 0;
@ -2456,14 +2460,15 @@ static void gfx_run_dl(Gfx* cmd) {
gfx_flush();
fbActive = 1;
active_fb = framebuffers.find(cmd->words.w1);
gfx_rapi->set_framebuffer(active_fb->first);
gfx_rapi->start_draw_to_framebuffer(active_fb->first, (float)active_fb->second.applied_height / active_fb->second.orig_height);
gfx_rapi->clear_framebuffer();
}
break;
case G_RESETFB:
{
gfx_flush();
fbActive = 0;
gfx_rapi->reset_framebuffer();
gfx_rapi->start_draw_to_framebuffer(game_renders_to_framebuffer ? game_framebuffer : 0, (float)gfx_current_dimensions.height / SCREEN_HEIGHT);
break;
}
break;
@ -2547,7 +2552,7 @@ static void gfx_run_dl(Gfx* cmd) {
gfx_dp_texture_rectangle(ulx, uly, lrx, lry, tile, uls, ult, dsdx, dtdy, opcode == G_TEXRECTFLIP);
break;
}
case G_TEXRECT_WIDE:
case G_TEXRECT_WIDE:
{
int32_t lrx, lry, tile, ulx, uly;
uint32_t uls, ult, dsdx, dtdy;
@ -2630,9 +2635,12 @@ void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, co
gfx_rapi = rapi;
gfx_wapi->init(game_name, start_in_fullscreen);
gfx_rapi->init();
gfx_rapi->update_framebuffer_parameters(0, SCREEN_WIDTH, SCREEN_HEIGHT, 1, false, true, true, true);
gfx_current_dimensions.internal_mul = 1;
gfx_current_dimensions.width = SCREEN_WIDTH;
gfx_current_dimensions.height = SCREEN_HEIGHT;
game_framebuffer = gfx_rapi->create_framebuffer();
game_framebuffer_msaa_resolved = gfx_rapi->create_framebuffer();
for (int i = 0; i < 16; i++)
segmentPointers[i] = NULL;
@ -2681,7 +2689,8 @@ struct GfxRenderingAPI *gfx_get_current_rendering_api(void) {
void gfx_start_frame(void) {
gfx_wapi->handle_events();
// gfx_wapi->get_dimensions(&gfx_current_dimensions.width, &gfx_current_dimensions.height);
gfx_wapi->get_dimensions(&gfx_current_window_dimensions.width, &gfx_current_window_dimensions.height);
SohImGui::DrawMainMenuAndCalculateGameSize();
if (gfx_current_dimensions.height == 0) {
// Avoid division by zero
gfx_current_dimensions.height = 1;
@ -2693,7 +2702,7 @@ void gfx_start_frame(void) {
uint32_t width = fb.second.orig_width, height = fb.second.orig_height;
gfx_adjust_width_height_for_scale(width, height);
if (width != fb.second.applied_width || height != fb.second.applied_height) {
gfx_rapi->resize_framebuffer(fb.first, width, height);
gfx_rapi->update_framebuffer_parameters(fb.first, width, height, 1, true, true, true, true);
fb.second.applied_width = width;
fb.second.applied_height = height;
}
@ -2701,6 +2710,22 @@ void gfx_start_frame(void) {
}
gfx_prev_dimensions = gfx_current_dimensions;
bool different_size = gfx_current_dimensions.width != gfx_current_game_window_viewport.width || gfx_current_dimensions.height != gfx_current_game_window_viewport.height;
if (different_size || gfx_msaa_level > 1) {
game_renders_to_framebuffer = true;
if (different_size) {
gfx_rapi->update_framebuffer_parameters(game_framebuffer, gfx_current_dimensions.width, gfx_current_dimensions.height, gfx_msaa_level, true, true, true, true);
} else {
// MSAA framebuffer needs to be resolved to an equally sized target when complete, which must therefore match the window size
gfx_rapi->update_framebuffer_parameters(game_framebuffer, gfx_current_window_dimensions.width, gfx_current_window_dimensions.height, gfx_msaa_level, false, true, true, true);
}
if (gfx_msaa_level > 1 && different_size) {
gfx_rapi->update_framebuffer_parameters(game_framebuffer_msaa_resolved, gfx_current_dimensions.width, gfx_current_dimensions.height, 1, false, false, false, false);
}
} else {
game_renders_to_framebuffer = false;
}
fbActive = 0;
}
@ -2708,17 +2733,44 @@ void gfx_run(Gfx *commands) {
gfx_sp_reset();
//puts("New frame");
get_pixel_depth_pending.clear();
get_pixel_depth_cached.clear();
if (!gfx_wapi->start_frame()) {
dropped_frame = true;
SohImGui::DrawFramebufferAndGameInput();
SohImGui::CancelFrame();
return;
}
dropped_frame = false;
double t0 = gfx_wapi->get_time();
gfx_rapi->update_framebuffer_parameters(0, gfx_current_window_dimensions.width, gfx_current_window_dimensions.height, 1, false, true, true, !game_renders_to_framebuffer);
gfx_rapi->start_frame();
gfx_rapi->start_draw_to_framebuffer(game_renders_to_framebuffer ? game_framebuffer : 0, (float)gfx_current_dimensions.height / SCREEN_HEIGHT);
gfx_rapi->clear_framebuffer();
gfx_run_dl(commands);
gfx_flush();
SohUtils::saveEnvironmentVar("framebuffer", string());
if (game_renders_to_framebuffer) {
gfx_rapi->start_draw_to_framebuffer(0, 1);
gfx_rapi->clear_framebuffer();
if (gfx_msaa_level > 1) {
bool different_size = gfx_current_dimensions.width != gfx_current_game_window_viewport.width || gfx_current_dimensions.height != gfx_current_game_window_viewport.height;
if (different_size) {
gfx_rapi->resolve_msaa_color_buffer(game_framebuffer_msaa_resolved, game_framebuffer);
SohUtils::saveEnvironmentVar("framebuffer", std::to_string((uintptr_t)gfx_rapi->get_framebuffer_texture_id(game_framebuffer_msaa_resolved)));
} else {
gfx_rapi->resolve_msaa_color_buffer(0, game_framebuffer);
}
} else {
SohUtils::saveEnvironmentVar("framebuffer", std::to_string((uintptr_t)gfx_rapi->get_framebuffer_texture_id(game_framebuffer)));
}
}
SohImGui::DrawFramebufferAndGameInput();
SohImGui::Render();
double t1 = gfx_wapi->get_time();
//printf("Process %f %f\n", t1, t1 - t0);
gfx_rapi->end_frame();
@ -2739,21 +2791,47 @@ void gfx_set_framedivisor(int divisor) {
int gfx_create_framebuffer(uint32_t width, uint32_t height) {
uint32_t orig_width = width, orig_height = height;
gfx_adjust_width_height_for_scale(width, height);
int fb = gfx_rapi->create_framebuffer(width, height);
int fb = gfx_rapi->create_framebuffer();
gfx_rapi->update_framebuffer_parameters(fb, width, height, 1, true, true, true, true);
framebuffers[fb] = { orig_width, orig_height, width, height };
return fb;
}
void gfx_set_framebuffer(int fb)
{
gfx_rapi->set_framebuffer(fb);
void gfx_set_framebuffer(int fb, float noise_scale) {
gfx_rapi->start_draw_to_framebuffer(fb, noise_scale);
gfx_rapi->clear_framebuffer();
}
void gfx_reset_framebuffer()
{
gfx_rapi->reset_framebuffer();
void gfx_reset_framebuffer() {
gfx_rapi->start_draw_to_framebuffer(0, (float)gfx_current_dimensions.height / SCREEN_HEIGHT);
}
static void adjust_pixel_depth_coordinates(float& x, float& y) {
x = x * RATIO_Y - (SCREEN_WIDTH * RATIO_Y - gfx_current_dimensions.width) / 2;
y *= RATIO_Y;
if (!game_renders_to_framebuffer || (gfx_msaa_level > 1 && gfx_current_dimensions.width == gfx_current_game_window_viewport.width && gfx_current_dimensions.height == gfx_current_game_window_viewport.height)) {
x += gfx_current_game_window_viewport.x;
y += gfx_current_window_dimensions.height - (gfx_current_game_window_viewport.y + gfx_current_game_window_viewport.height);
}
}
void gfx_get_pixel_depth_prepare(float x, float y) {
adjust_pixel_depth_coordinates(x, y);
get_pixel_depth_pending.emplace(x, y);
}
uint16_t gfx_get_pixel_depth(float x, float y) {
return gfx_rapi->get_pixel_depth(x * RATIO_Y - (SCREEN_WIDTH * RATIO_Y - gfx_current_dimensions.width) / 2, y * RATIO_Y);
adjust_pixel_depth_coordinates(x, y);
if (auto it = get_pixel_depth_cached.find(make_pair(x, y)); it != get_pixel_depth_cached.end()) {
return it->second;
}
get_pixel_depth_pending.emplace(x, y);
map<pair<float, float>, uint16_t> res = gfx_rapi->get_pixel_depth(game_renders_to_framebuffer ? game_framebuffer : 0, get_pixel_depth_pending);
get_pixel_depth_cached.merge(res);
get_pixel_depth_pending.clear();
return get_pixel_depth_cached.find(make_pair(x, y))->second;
}

View File

@ -8,8 +8,11 @@
struct GfxRenderingAPI;
struct GfxWindowManagerAPI;
struct GfxDimensions
{
struct XYWidthHeight {
int16_t x, y, width, height;
};
struct GfxDimensions {
uint32_t internal_mul;
uint32_t width, height;
float aspect_ratio;
@ -50,7 +53,10 @@ struct TextureCacheValue {
#ifdef __cplusplus
extern "C" {
#endif
extern struct GfxDimensions gfx_current_dimensions;
extern struct GfxDimensions gfx_current_window_dimensions; // The dimensions of the window
extern struct GfxDimensions gfx_current_dimensions; // The dimensions of the draw area the game draws to, before scaling (if applicable)
extern struct XYWidthHeight gfx_current_game_window_viewport; // The area of the window the game is drawn to, (0, 0) is top-left corner
extern uint32_t gfx_msaa_level;
void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen);
struct GfxRenderingAPI* gfx_get_current_rendering_api(void);
@ -60,6 +66,7 @@ void gfx_end_frame(void);
void gfx_set_framedivisor(int);
void gfx_texture_cache_clear();
int gfx_create_framebuffer(uint32_t width, uint32_t height);
void gfx_get_pixel_depth_prepare(float x, float y);
uint16_t gfx_get_pixel_depth(float x, float y);
#ifdef __cplusplus

View File

@ -5,10 +5,18 @@
#include <stdint.h>
#include <stdbool.h>
#include <map>
#include <set>
struct ShaderProgram;
struct GfxClipParameters {
bool z_is_from_0_to_1;
bool invert_y;
};
struct GfxRenderingAPI {
bool (*z_is_from_0_to_1)(void);
struct GfxClipParameters (*get_clip_parameters)(void);
void (*unload_shader)(struct ShaderProgram *old_prg);
void (*load_shader)(struct ShaderProgram *new_prg);
struct ShaderProgram *(*create_and_load_new_shader)(uint64_t shader_id0, uint32_t shader_id1);
@ -19,7 +27,6 @@ struct GfxRenderingAPI {
void (*upload_texture)(const uint8_t *rgba32_buf, uint32_t width, uint32_t height);
void (*set_sampler_parameters)(int sampler, bool linear_filter, uint32_t cms, uint32_t cmt);
void (*set_depth_test_and_mask)(bool depth_test, bool z_upd);
uint16_t (*get_pixel_depth)(float x, float y);
void (*set_zmode_decal)(bool zmode_decal);
void (*set_viewport)(int x, int y, int width, int height);
void (*set_scissor)(int x, int y, int width, int height);
@ -30,11 +37,14 @@ struct GfxRenderingAPI {
void (*start_frame)(void);
void (*end_frame)(void);
void (*finish_render)(void);
int (*create_framebuffer)(uint32_t width, uint32_t height);
void (*resize_framebuffer)(int fb, uint32_t width, uint32_t height);
void (*set_framebuffer)(int fb);
void (*reset_framebuffer)();
void (*select_texture_fb)(int fbID);
int (*create_framebuffer)();
void (*update_framebuffer_parameters)(int fb_id, uint32_t width, uint32_t height, uint32_t msaa_level, bool opengl_invert_y, bool render_target, bool has_depth_buffer, bool can_extract_depth);
void (*start_draw_to_framebuffer)(int fb_id, float noise_scale);
void (*clear_framebuffer)(void);
void (*resolve_msaa_color_buffer)(int fb_id_target, int fb_id_source);
std::map<std::pair<float, float>, uint16_t> (*get_pixel_depth)(int fb_id, const std::set<std::pair<float, float>>& coordinates);
void *(*get_framebuffer_texture_id)(int fb_id);
void (*select_texture_fb)(int fb_id);
void (*delete_texture)(uint32_t texID);
};

View File

@ -502,7 +502,6 @@ namespace ImGui
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0); // flexible button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape
IMGUI_API void ImageRotated(ImTextureID tex_id, ImVec2 center, ImVec2 size, float angle);
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
IMGUI_API bool Checkbox(const char* label, bool* v);

View File

@ -1007,33 +1007,6 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
return held;
}
void ImGui::ImageRotated(ImTextureID tex_id, ImVec2 center, ImVec2 size, float angle) {
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return;
ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImRect bb(window->DC.CursorPos + ImVec2(size.x / 2, size.y / 2), window->DC.CursorPos + size);
ImVec2 pos[4] =
{
center + bb.Min + ImVec2(-size.x * 0.5f, -size.y * 0.5f),
center + bb.Min + ImVec2(+size.x * 0.5f, -size.y * 0.5f),
center + bb.Min + ImVec2(+size.x * 0.5f, +size.y * 0.5f),
center + bb.Min + ImVec2(-size.x * 0.5f, +size.y * 0.5f)
};
ImVec2 uvs[4] =
{
ImVec2(0.0f, 1.0f),
ImVec2(1.0f, 1.0f),
ImVec2(1.0f, 0.0f),
ImVec2(0.0f, 0.0f)
};
draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE);
}
void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)
{
ImGuiWindow* window = GetCurrentWindow();

View File

@ -217,9 +217,12 @@ namespace Ship {
std::shared_ptr<Ship::Resource> ResourceMgr::GetCachedFile(std::string FilePath) {
auto resCacheFind = ResourceCache.find(FilePath);
if (resCacheFind != ResourceCache.end())
if (resCacheFind != ResourceCache.end() &&
resCacheFind->second.use_count() > 0)
{
return resCacheFind->second;
}
else
return nullptr;
}

View File

@ -1,6 +1,7 @@
#include "SohImGuiImpl.h"
#include <iostream>
#include <map>
#include <utility>
#include "Archive.h"
@ -14,9 +15,11 @@
#include "TextureMod.h"
#include "Window.h"
#include "Cvar.h"
#include "Texture.h"
#include "../Fast3D/gfx_pc.h"
#include "Lib/stb/stb_image.h"
#include "Lib/Fast3D/gfx_rendering_api.h"
#include "Lib/spdlog/include/spdlog/common.h"
#include "Utils/StringHelper.h"
#ifdef ENABLE_OPENGL
@ -66,6 +69,9 @@ namespace SohImGui {
float navi_prop_i_col[3] = { 0.0f, 0.0f, 0.0f };
float navi_prop_o_col[3] = { 0.0f, 0.0f, 0.0f };
std::map<std::string, std::vector<std::string>> windowCategories;
std::map<std::string, CustomWindow> customWindows;
void ImGuiWMInit() {
switch (impl.backend) {
case Backend::SDL:
@ -175,14 +181,6 @@ namespace SohImGui {
}
}
bool UseInternalRes() {
switch (impl.backend) {
case Backend::SDL:
return true;
}
return false;
}
bool UseViewports() {
switch (impl.backend) {
case Backend::DX11:
@ -211,7 +209,7 @@ namespace SohImGui {
}
}
void LoadTexture(std::string name, std::string path) {
void LoadTexture(const std::string& name, const std::string& path) {
GfxRenderingAPI* api = gfx_get_current_rendering_api();
const auto res = GlobalCtx2::GetInstance()->GetResourceManager()->LoadFile(normalize(path));
@ -231,6 +229,50 @@ namespace SohImGui {
stbi_image_free(img_data);
}
void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint) {
GfxRenderingAPI* api = gfx_get_current_rendering_api();
const auto res = static_cast<Ship::Texture*>(GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(normalize(path)).get());
std::vector<uint8_t> texBuffer;
texBuffer.reserve(res->width * res->height * 4);
switch (res->texType) {
case Ship::TextureType::RGBA32bpp:
texBuffer.assign(res->imageData, res->imageData + (res->width * res->height * 4));
break;
case Ship::TextureType::GrayscaleAlpha8bpp:
for (int32_t i = 0; i < res->width * res->height; i++) {
uint8_t ia = res->imageData[i];
uint8_t color = ((ia >> 4) & 0xF) * 255 / 15;
uint8_t alpha = (ia & 0xF) * 255 / 15;
texBuffer.push_back(color);
texBuffer.push_back(color);
texBuffer.push_back(color);
texBuffer.push_back(alpha);
}
break;
default:
// TODO convert other image types
SPDLOG_WARN("SohImGui::LoadResource: Attempting to load unsupporting image type %s", path.c_str());
return;
}
for (size_t pixel = 0; pixel < texBuffer.size() / 4; pixel++) {
texBuffer[pixel * 4 + 0] *= tint.x;
texBuffer[pixel * 4 + 1] *= tint.y;
texBuffer[pixel * 4 + 2] *= tint.z;
texBuffer[pixel * 4 + 3] *= tint.w;
}
const auto asset = new GameAsset{ api->new_texture() };
api->select_texture(0, asset->textureId);
api->set_sampler_parameters(0, false, 0, 0);
api->upload_texture(texBuffer.data(), res->width, res->height);
DefaultAssets[name] = asset;
}
void Init(WindowImpl window_impl) {
impl = window_impl;
Game::LoadSettings();
@ -277,7 +319,7 @@ namespace SohImGui {
ImGuiProcessEvent(event);
}
#define BindButton(btn, status) ImGui::Image(impl.backend == Backend::DX11 ? GetTextureByID(DefaultAssets[btn]->textureId) : (ImTextureID)(DefaultAssets[btn]->textureId), ImVec2(16.0f * scale, 16.0f * scale), ImVec2(0, 0), ImVec2(1.0f, 1.0f), ImVec4(255, 255, 255, (status) ? 255 : 0));
#define BindButton(btn, status) ImGui::Image(GetTextureByID(DefaultAssets[btn]->textureId), ImVec2(16.0f * scale, 16.0f * scale), ImVec2(0, 0), ImVec2(1.0f, 1.0f), ImVec4(255, 255, 255, (status) ? 255 : 0));
void BindAudioSlider(const char* name, const char* key, float* value, SeqPlayers playerId) {
ImGui::Text(name, static_cast<int>(100 * *(value)));
@ -289,20 +331,16 @@ namespace SohImGui {
}
}
void Draw() {
void DrawMainMenuAndCalculateGameSize() {
console->Update();
ImGuiBackendNewFrame();
ImGuiWMNewFrame();
ImGui::NewFrame();
const std::shared_ptr<Window> wnd = GlobalCtx2::GetInstance()->GetWindow();
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoBackground |
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoResize;
if (UseViewports()) {
window_flags |= ImGuiWindowFlags_NoBackground;
}
if (Game::Settings.debug.menu_bar) window_flags |= ImGuiWindowFlags_MenuBar;
const ImGuiViewport* viewport = ImGui::GetMainViewport();
@ -310,8 +348,12 @@ namespace SohImGui {
ImGui::SetNextWindowSize(ImVec2(wnd->GetCurrentWidth(), wnd->GetCurrentHeight()));
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
ImGui::Begin("Main - Deck", nullptr, window_flags);
ImGui::PopStyleVar();
ImGui::PopStyleVar(3);
ImVec2 top_left_pos = ImGui::GetWindowPos();
const ImGuiID dockId = ImGui::GetID("main_dock");
@ -336,7 +378,7 @@ namespace SohImGui {
if (ImGui::BeginMenuBar()) {
if (DefaultAssets.contains("Game_Icon")) {
ImGui::SetCursorPos(ImVec2(5, 2.5f));
ImGui::Image(impl.backend == Backend::DX11 ? GetTextureByID(DefaultAssets["Game_Icon"]->textureId) : reinterpret_cast<ImTextureID>(DefaultAssets["Game_Icon"]->textureId), ImVec2(16.0f, 16.0f));
ImGui::Image(GetTextureByID(DefaultAssets["Game_Icon"]->textureId), ImVec2(16.0f, 16.0f));
ImGui::SameLine();
ImGui::SetCursorPos(ImVec2(25, 0));
}
@ -386,6 +428,23 @@ namespace SohImGui {
needs_save = true;
}
ImGui::Separator();
if (ImGui::Checkbox("Dpad Support on Pause and File Select", &Game::Settings.controller.dpad_pause_name)) {
CVar_SetS32("gDpadPauseName", Game::Settings.controller.dpad_pause_name);
needs_save = true;
}
if (ImGui::Checkbox("DPad Support in Ocarina and Text Choice", &Game::Settings.controller.dpad_ocarina_text)) {
CVar_SetS32("gDpadOcarinaText", Game::Settings.controller.dpad_ocarina_text);
needs_save = true;
}
if (ImGui::Checkbox("DPad Support for Browsing Shop Items", &Game::Settings.controller.dpad_shop)) {
CVar_SetS32("gDpadShop", Game::Settings.controller.dpad_shop);
needs_save = true;
}
ImGui::EndMenu();
}
@ -394,22 +453,31 @@ namespace SohImGui {
ImGui::Text("Gameplay");
ImGui::Separator();
if (ImGui::Checkbox("Fast Text", &Game::Settings.enhancements.fast_text)) {
CVar_SetS32("gFastText", Game::Settings.enhancements.fast_text);
ImGui::Text("Text Speed", Game::Settings.enhancements.text_speed);
if (ImGui::SliderInt("##TEXTSPEED", &Game::Settings.enhancements.text_speed, 1, 5)) {
CVar_SetS32("gTextSpeed", Game::Settings.enhancements.text_speed);
needs_save = true;
}
if (ImGui::Checkbox("Skip Text", &Game::Settings.enhancements.skip_text)) {
CVar_SetS32("gSkipText", Game::Settings.enhancements.skip_text);
needs_save = true;
}
if (ImGui::Checkbox("Minimal UI", &Game::Settings.enhancements.minimal_ui)) {
CVar_SetS32(const_cast<char*>("gMinimalUI"), Game::Settings.enhancements.minimal_ui);
CVar_SetS32("gMinimalUI", Game::Settings.enhancements.minimal_ui);
needs_save = true;
}
if (ImGui::Checkbox("MM Bunny Hood", &Game::Settings.enhancements.mm_bunny_hood)) {
CVar_SetS32("gMMBunnyHood", Game::Settings.enhancements.mm_bunny_hood);
needs_save = true;
}
ImGui::Text("Graphics");
ImGui::Separator();
if (UseInternalRes()) {
HOOK(ImGui::Checkbox("N64 Mode", &Game::Settings.debug.n64mode));
}
HOOK(ImGui::Checkbox("N64 Mode", &Game::Settings.debug.n64mode));
if (ImGui::Checkbox("Animated Link in Pause Menu", &Game::Settings.enhancements.animated_pause_menu)) {
CVar_SetS32("gPauseLiveLink", Game::Settings.enhancements.animated_pause_menu);
@ -421,16 +489,21 @@ namespace SohImGui {
needs_save = true;
}
if (ImGui::Checkbox("Dynamic Wallet Icon", &Game::Settings.enhancements.dynamic_wallet_icon)) {
CVar_SetS32(const_cast<char*>("gDynamicWalletIcon"), Game::Settings.enhancements.dynamic_wallet_icon);
needs_save = true;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Developer Tools")) {
HOOK(ImGui::MenuItem("Stats", nullptr, &Game::Settings.debug.soh));
HOOK(ImGui::MenuItem("Console", nullptr, &console->opened));
ImGui::Text("Debug");
ImGui::Separator();
if (ImGui::Checkbox("Debug Mode", &Game::Settings.cheats.debug_mode)) {
CVar_SetS32("gDebugEnabled", Game::Settings.cheats.debug_mode);
needs_save = true;
@ -438,48 +511,63 @@ namespace SohImGui {
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Graphics")) {
HOOK(ImGui::MenuItem("Anti-aliasing", nullptr, &Game::Settings.graphics.show));
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Cheats")) {
if (ImGui::Checkbox("Infinite Money", &Game::Settings.cheats.infinite_money)) {
CVar_SetS32("gInfiniteMoney", Game::Settings.cheats.infinite_money);
needs_save = true;
if (ImGui::BeginMenu("Infinite...")) {
if (ImGui::Checkbox("Money", &Game::Settings.cheats.infinite_money)) {
CVar_SetS32("gInfiniteMoney", Game::Settings.cheats.infinite_money);
needs_save = true;
}
if (ImGui::Checkbox("Health", &Game::Settings.cheats.infinite_health)) {
CVar_SetS32("gInfiniteHealth", Game::Settings.cheats.infinite_health);
needs_save = true;
}
if (ImGui::Checkbox("Ammo", &Game::Settings.cheats.infinite_ammo)) {
CVar_SetS32("gInfiniteAmmo", Game::Settings.cheats.infinite_ammo);
needs_save = true;
}
if (ImGui::Checkbox("Magic", &Game::Settings.cheats.infinite_magic)) {
CVar_SetS32("gInfiniteMagic", Game::Settings.cheats.infinite_magic);
needs_save = true;
}
if (ImGui::Checkbox("Nayru's Love", &Game::Settings.cheats.infinite_nayru)) {
CVar_SetS32("gInfiniteNayru", Game::Settings.cheats.infinite_nayru);
needs_save = true;
}
ImGui::EndMenu();
}
if (ImGui::Checkbox("Infinite Health", &Game::Settings.cheats.infinite_health)) {
CVar_SetS32("gInfiniteHealth", Game::Settings.cheats.infinite_health);
needs_save = true;
}
if (ImGui::Checkbox("Infinite Ammo", &Game::Settings.cheats.infinite_ammo)) {
CVar_SetS32("gInfiniteAmmo", Game::Settings.cheats.infinite_ammo);
needs_save = true;
}
if (ImGui::Checkbox("Infinite Magic", &Game::Settings.cheats.infinite_magic)) {
CVar_SetS32("gInfiniteMagic", Game::Settings.cheats.infinite_magic);
needs_save = true;
}
if (ImGui::Checkbox("No Clip", &Game::Settings.cheats.no_clip)) {
CVar_SetS32("gNoClip", Game::Settings.cheats.no_clip);
needs_save = true;
}
if (ImGui::Checkbox("Climb Everything", &Game::Settings.cheats.climb_everything)) {
CVar_SetS32("gClimbEverything", Game::Settings.cheats.climb_everything);
needs_save = true;
}
if (ImGui::Checkbox("Moon Jump on L", &Game::Settings.cheats.moon_jump_on_l)) {
CVar_SetS32("gMoonJumpOnL", Game::Settings.cheats.moon_jump_on_l);
needs_save = true;
}
if (ImGui::Checkbox("Super Tunic", &Game::Settings.cheats.super_tunic)) {
CVar_SetS32("gSuperTunic", Game::Settings.cheats.super_tunic);
needs_save = true;
}
if (ImGui::BeginMenu("Cosmetics")) {
ImGui::Text("Tunics");
ImGui::Separator();
@ -599,42 +687,36 @@ namespace SohImGui {
if (ImGui::BeginMenu("Developer Tools")) {
HOOK(ImGui::MenuItem("Stats", nullptr, &Game::Settings.debug.soh));
HOOK(ImGui::MenuItem("Console", nullptr, &console->opened));
if (ImGui::Checkbox("Easy ISG", &Game::Settings.cheats.ez_isg)) {
CVar_SetS32("gEzISG", Game::Settings.cheats.ez_isg);
needs_save = true;
}
if (ImGui::Checkbox("Unrestricted Items", &Game::Settings.cheats.no_restrict_item)) {
CVar_SetS32("gNoRestrictItems", Game::Settings.cheats.no_restrict_item);
needs_save = true;
}
if (ImGui::Checkbox("Freeze Time", &Game::Settings.cheats.freeze_time)) {
CVar_SetS32("gFreezeTime", Game::Settings.cheats.freeze_time);
needs_save = true;
}
ImGui::EndMenu();
}
for (const auto& category : windowCategories) {
if (ImGui::BeginMenu(category.first.c_str())) {
for (const std::string& name : category.second) {
HOOK(ImGui::MenuItem(name.c_str(), nullptr, &customWindows[name].enabled));
}
ImGui::EndMenu();
}
}
ImGui::EndMenuBar();
}
ImGui::End();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
if (UseViewports()) {
flags |= ImGuiWindowFlags_NoBackground;
}
ImGui::Begin("OoT Master Quest", nullptr, flags);
ImGui::PopStyleVar();
ImGui::PopStyleColor();
ImVec2 main_pos = ImGui::GetWindowPos();
ImVec2 size = ImGui::GetContentRegionAvail();
ImVec2 pos = ImVec2(0, 0);
gfx_current_dimensions.width = size.x * gfx_current_dimensions.internal_mul;
gfx_current_dimensions.height = size.y * gfx_current_dimensions.internal_mul;
if (UseInternalRes()) {
if (Game::Settings.debug.n64mode) {
gfx_current_dimensions.width = 320;
gfx_current_dimensions.height = 240;
const int sw = size.y * 320 / 240;
pos = ImVec2(size.x / 2 - sw / 2, 0);
size = ImVec2(sw, size.y);
}
}
if (UseInternalRes()) {
int fbuf = std::stoi(SohUtils::getEnvironmentVar("framebuffer"));
ImGui::ImageRotated(reinterpret_cast<ImTextureID>(fbuf), pos, size, 0.0f);
}
ImGui::End();
if (Game::Settings.debug.soh) {
@ -644,18 +726,84 @@ namespace SohImGui {
ImGui::Text("Platform: Windows");
ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate);
if (UseInternalRes()) {
ImGui::Text("Internal Resolution:");
ImGui::SliderInt("Mul", reinterpret_cast<int*>(&gfx_current_dimensions.internal_mul), 1, 8);
}
ImGui::End();
ImGui::PopStyleColor();
}
if (Game::Settings.graphics.show) {
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
ImGui::Begin("Anti-aliasing settings", nullptr, ImGuiWindowFlags_None);
ImGui::Text("Internal Resolution:");
ImGui::SliderInt("Mul", reinterpret_cast<int*>(&gfx_current_dimensions.internal_mul), 1, 8);
ImGui::Text("MSAA:");
ImGui::SliderInt("MSAA", reinterpret_cast<int*>(&gfx_msaa_level), 1, 8);
ImGui::End();
ImGui::PopStyleColor();
}
console->Draw();
for (auto& windowIter : customWindows) {
CustomWindow& window = windowIter.second;
if (window.drawFunc != nullptr) {
window.drawFunc(window.enabled);
}
}
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground;
ImGui::Begin("OoT Master Quest", nullptr, flags);
ImGui::PopStyleVar(3);
ImGui::PopStyleColor();
ImVec2 main_pos = ImGui::GetWindowPos();
main_pos.x -= top_left_pos.x;
main_pos.y -= top_left_pos.y;
ImVec2 size = ImGui::GetContentRegionAvail();
ImVec2 pos = ImVec2(0, 0);
gfx_current_dimensions.width = size.x * gfx_current_dimensions.internal_mul;
gfx_current_dimensions.height = size.y * gfx_current_dimensions.internal_mul;
gfx_current_game_window_viewport.x = main_pos.x;
gfx_current_game_window_viewport.y = main_pos.y;
gfx_current_game_window_viewport.width = size.x;
gfx_current_game_window_viewport.height = size.y;
if (Game::Settings.debug.n64mode) {
gfx_current_dimensions.width = 320;
gfx_current_dimensions.height = 240;
const int sw = size.y * 320 / 240;
gfx_current_game_window_viewport.x += (size.x - sw) / 2;
gfx_current_game_window_viewport.width = sw;
pos = ImVec2(size.x / 2 - sw / 2, 0);
size = ImVec2(sw, size.y);
}
}
void DrawFramebufferAndGameInput() {
ImVec2 main_pos = ImGui::GetWindowPos();
ImVec2 size = ImGui::GetContentRegionAvail();
ImVec2 pos = ImVec2(0, 0);
if (Game::Settings.debug.n64mode) {
const int sw = size.y * 320 / 240;
pos = ImVec2(size.x / 2 - sw / 2, 0);
size = ImVec2(sw, size.y);
}
std::string fb_str = SohUtils::getEnvironmentVar("framebuffer");
if (!fb_str.empty()) {
uintptr_t fbuf = (uintptr_t)std::stoull(fb_str);
//ImGui::ImageSimple(reinterpret_cast<ImTextureID>(fbuf), pos, size);
ImGui::SetCursorPos(pos);
ImGui::Image(reinterpret_cast<ImTextureID>(fbuf), size);
}
ImGui::End();
const float scale = Game::Settings.controller.input_scale;
ImVec2 BtnPos = ImVec2(160 * scale, 85 * scale);
if(Game::Settings.controller.input_enabled) {
if (Game::Settings.controller.input_enabled) {
ImGui::SetNextWindowSize(BtnPos);
ImGui::SetNextWindowPos(ImVec2(main_pos.x + size.x - BtnPos.x - 20, main_pos.y + size.y - BtnPos.y - 20));
@ -701,9 +849,9 @@ namespace SohImGui {
ImGui::End();
}
}
}
console->Draw();
void Render() {
ImGui::Render();
ImGuiRenderDrawData(ImGui::GetDrawData());
if (UseViewports()) {
@ -712,7 +860,32 @@ namespace SohImGui {
}
}
void CancelFrame() {
ImGui::EndFrame();
if (UseViewports()) {
ImGui::UpdatePlatformWindows();
}
}
void BindCmd(const std::string& cmd, CommandEntry entry) {
console->Commands[cmd] = std::move(entry);
}
void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc) {
if (customWindows.contains(name)) {
SPDLOG_ERROR("SohImGui::AddWindow: Attempting to add duplicate window name %s", name.c_str());
return;
}
customWindows[name] = {
.enabled = false,
.drawFunc = drawFunc
};
windowCategories[category].emplace_back(name);
}
ImTextureID GetTextureByName(const std::string& name) {
return GetTextureByID(DefaultAssets[name]->textureId);
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "Lib/ImGui/imgui.h"
#include "SohConsole.h"
struct GameAsset {
@ -47,11 +48,26 @@ namespace SohImGui {
} sdl;
} EventImpl;
extern WindowImpl impl;
using WindowDrawFunc = void(*)(bool& enabled);
typedef struct {
bool enabled;
WindowDrawFunc drawFunc;
} CustomWindow;
extern Console* console;
void Init(WindowImpl window_impl);
void Update(EventImpl event);
void Draw(void);
void DrawMainMenuAndCalculateGameSize(void);
void DrawFramebufferAndGameInput(void);
void Render(void);
void CancelFrame(void);
void ShowCursor(bool hide, Dialogues w);
void BindCmd(const std::string& cmd, CommandEntry entry);
void* GetTextureByID(int id);
void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc);
void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint = ImVec4(1, 1, 1, 1));
ImTextureID GetTextureByID(int id);
ImTextureID GetTextureByName(const std::string& name);
}

View File

@ -286,6 +286,10 @@ namespace Ship {
//gfx_set_framedivisor(0);
}
void Window::GetPixelDepthPrepare(float x, float y) {
gfx_get_pixel_depth_prepare(x, y);
}
uint16_t Window::GetPixelDepth(float x, float y) {
return gfx_get_pixel_depth(x, y);
}

View File

@ -20,6 +20,7 @@ namespace Ship {
void Init();
void RunCommands(Gfx* Commands);
void SetFrameDivisor(int divisor);
void GetPixelDepthPrepare(float x, float y);
uint16_t GetPixelDepth(float x, float y);
void ToggleFullscreen();
void SetFullscreen(bool bIsFullscreen);

View File

@ -977,6 +977,7 @@ void LightContext_RemoveLight(GlobalContext* globalCtx, LightContext* lightCtx,
Lights* Lights_NewAndDraw(GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambientB, u8 numLights, u8 r, u8 g,
u8 b, s8 x, s8 y, s8 z);
Lights* Lights_New(GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambientB);
void Lights_GlowCheckPrepare(GlobalContext* globalCtx);
void Lights_GlowCheck(GlobalContext* globalCtx);
void Lights_DrawGlow(GlobalContext* globalCtx);
void ZeldaArena_CheckPointer(void* ptr, size_t size, const char* name, const char* action);
@ -2397,6 +2398,9 @@ void FileChoose_Destroy(GameState* thisx);
char* SetQuote();
void Heaps_Alloc(void);
void Heaps_Free(void);
#ifdef __cplusplus
};
#endif

View File

@ -237,8 +237,8 @@ extern void(*D_801755D0)(void);
extern u8 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE]; // 0xC00 bytes
extern u8 gGfxSPTaskStack[0x400]; // 0x400 bytes
extern GfxPool gGfxPools[2]; // 0x24820 bytes
extern u8 gAudioHeap[0x38000]; // 0x38000 bytes
extern u8 gSystemHeap[];
extern u8* gAudioHeap;
extern u8* gSystemHeap;
#ifdef __cplusplus
};

View File

@ -178,11 +178,14 @@
<ItemGroup>
<ClCompile Include="soh\Enhancements\bootcommands.c" />
<ClCompile Include="soh\Enhancements\debugconsole.cpp" />
<ClCompile Include="soh\Enhancements\debugger\debugger.cpp" />
<ClCompile Include="soh\Enhancements\debugger\debugSaveEditor.cpp" />
<ClCompile Include="soh\Enhancements\gameconsole.c" />
<ClCompile Include="soh\GbiWrap.cpp" />
<ClCompile Include="soh\gu_pc.c" />
<ClCompile Include="soh\OTRGlobals.cpp" />
<ClCompile Include="soh\stubs.c" />
<ClCompile Include="soh\util.cpp" />
<ClCompile Include="soh\z_message_OTR.cpp" />
<ClCompile Include="soh\z_play_otr.cpp" />
<ClCompile Include="soh\z_scene_otr.cpp" />
@ -922,8 +925,11 @@
<ClInclude Include="soh\Enhancements\bootcommands.h" />
<ClInclude Include="soh\Enhancements\cvar.h" />
<ClInclude Include="soh\Enhancements\debugconsole.h" />
<ClInclude Include="soh\Enhancements\debugger\debugger.h" />
<ClInclude Include="soh\Enhancements\debugger\debugSaveEditor.h" />
<ClInclude Include="soh\gameconsole.h" />
<ClInclude Include="soh\OTRGlobals.h" />
<ClInclude Include="soh\util.h" />
<ClInclude Include="src\overlays\actors\ovl_Arms_Hook\z_arms_hook.h" />
<ClInclude Include="src\overlays\actors\ovl_Arrow_Fire\z_arrow_fire.h" />
<ClInclude Include="src\overlays\actors\ovl_Arrow_Ice\z_arrow_ice.h" />

View File

@ -76,6 +76,12 @@
<Filter Include="Source Files\src\overlays\actors">
<UniqueIdentifier>{18b9727f-30de-4ab8-a317-916090d4a110}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\soh\Enhancements\debugger">
<UniqueIdentifier>{9a4378ec-e30f-47b6-9ad6-5ce738b4cf99}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\soh\Enhancements\debugger">
<UniqueIdentifier>{04fc1c52-49ff-48e2-ae23-2c00867374f8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\boot\assert.c">
@ -2169,6 +2175,15 @@
<ClCompile Include="src\overlays\actors\ovl_Shot_Sun\z_shot_sun.c">
<Filter>Source Files\src\overlays\actors</Filter>
</ClCompile>
<ClCompile Include="soh\Enhancements\debugger\debugger.cpp">
<Filter>Source Files\soh\Enhancements\debugger</Filter>
</ClCompile>
<ClCompile Include="soh\Enhancements\debugger\debugSaveEditor.cpp">
<Filter>Source Files\soh\Enhancements\debugger</Filter>
</ClCompile>
<ClCompile Include="soh\util.cpp">
<Filter>Source Files\soh</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\overlays\actors\ovl_kaleido_scope\z_kaleido_scope.h">
@ -3710,6 +3725,15 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="soh\Enhancements\debugger\debugger.h">
<Filter>Header Files\soh\Enhancements\debugger</Filter>
</ClInclude>
<ClInclude Include="soh\Enhancements\debugger\debugSaveEditor.h">
<Filter>Header Files\soh\Enhancements\debugger</Filter>
</ClInclude>
<ClInclude Include="soh\util.h">
<Filter>Header Files\soh</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="include\macro.inc">

View File

@ -25,6 +25,7 @@ void BootCommands_Init()
CVar_RegisterS32("gDebugEnabled", 0);
CVar_RegisterS32("gPauseLiveLink", 0);
CVar_RegisterS32("gMinimalUI", 0);
CVar_RegisterS32("gVisualAgony", 0);
}
//void BootCommands_ParseBootArgs(char* str)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
#pragma once
void InitSaveEditor();

View File

@ -0,0 +1,6 @@
#include "debugger.h"
#include "debugSaveEditor.h"
void Debug_Init(void) {
InitSaveEditor();
}

View File

@ -0,0 +1,3 @@
#pragma once
void Debug_Init(void);

View File

@ -9,6 +9,7 @@ void Graph_ProcessGfxCommands(Gfx* commands);
void OTRLogString(const char* src);
void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char));
void OTRSetFrameDivisor(int divisor);
void OTRGetPixelDepthPrepare(float x, float y);
uint16_t OTRGetPixelDepth(float x, float y);
int32_t OTRGetLastScancode();
void ResourceMgr_CacheDirectory(const char* resName);

View File

@ -22,10 +22,19 @@
#include "Lib/stb/stb_image.h"
#include "AudioPlayer.h"
#include "../soh/Enhancements/debugconsole.h"
#include "../soh/Enhancements/debugger/debugger.h"
#include "Utils/BitConverter.h"
#include "variables.h"
OTRGlobals* OTRGlobals::Instance;
static struct {
std::condition_variable cv_to_thread, cv_from_thread;
std::mutex mutex;
bool initialized;
bool processing;
} audio;
OTRGlobals::OTRGlobals() {
context = Ship::GlobalCtx2::CreateInstance("Ship of Harkinian");
context->GetWindow()->Init();
@ -38,6 +47,10 @@ extern uintptr_t clearMtx;
extern "C" Mtx gMtxClear;
extern "C" MtxF gMtxFClear;
extern "C" void OTRMessage_Init();
extern "C" void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len);
extern "C" int AudioPlayer_Buffered(void);
extern "C" int AudioPlayer_GetDesiredBuffered(void);
// C->C++ Bridge
extern "C" void InitOTR() {
@ -54,6 +67,7 @@ extern "C" void InitOTR() {
clearMtx = (uintptr_t)&gMtxClear;
OTRMessage_Init();
DebugConsole_Init();
Debug_Init();
}
extern "C" uint64_t GetFrequency() {
@ -78,8 +92,67 @@ extern "C" void Graph_ProcessFrame(void (*run_one_game_iter)(void)) {
// C->C++ Bridge
extern "C" void Graph_ProcessGfxCommands(Gfx* commands) {
OTRGlobals::Instance->context->GetWindow()->SetFrameDivisor(R_UPDATE_RATE);
if (!audio.initialized) {
audio.initialized = true;
std::thread([]() {
for (;;) {
{
std::unique_lock<std::mutex> Lock(audio.mutex);
while (!audio.processing) {
audio.cv_to_thread.wait(Lock);
}
}
//AudioMgr_ThreadEntry(&gAudioMgr);
// 528 and 544 relate to 60 fps at 32 kHz 32000/60 = 533.333..
// in an ideal world, one third of the calls should use num_samples=544 and two thirds num_samples=528
#define SAMPLES_HIGH 560
#define SAMPLES_LOW 528
// PAL values
//#define SAMPLES_HIGH 656
//#define SAMPLES_LOW 624
#define AUDIO_FRAMES_PER_UPDATE (R_UPDATE_RATE > 0 ? R_UPDATE_RATE : 1 )
#define NUM_AUDIO_CHANNELS 2
int samples_left = AudioPlayer_Buffered();
u32 num_audio_samples = samples_left < AudioPlayer_GetDesiredBuffered() ? SAMPLES_HIGH : SAMPLES_LOW;
// printf("Audio samples: %d %u\n", samples_left, num_audio_samples);
// 3 is the maximum authentic frame divisor.
s16 audio_buffer[SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 3];
for (int i = 0; i < AUDIO_FRAMES_PER_UPDATE; i++) {
AudioMgr_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS), num_audio_samples);
}
//for (uint32_t i = 0; i < 2 * num_audio_samples; i++) {
// audio_buffer[i] = Rand_Next() & 0xFF;
//}
// printf("Audio samples before submitting: %d\n", audio_api->buffered());
AudioPlayer_Play((u8*)audio_buffer, num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE));
{
std::unique_lock<std::mutex> Lock(audio.mutex);
audio.processing = false;
}
audio.cv_from_thread.notify_one();
}
}).detach();
}
{
std::unique_lock<std::mutex> Lock(audio.mutex);
audio.processing = true;
}
audio.cv_to_thread.notify_one();
OTRGlobals::Instance->context->GetWindow()->RunCommands(commands);
{
std::unique_lock<std::mutex> Lock(audio.mutex);
while (audio.processing) {
audio.cv_from_thread.wait(Lock);
}
}
// OTRTODO: FIGURE OUT END FRAME POINT
/* if (OTRGlobals::Instance->context->GetWindow()->lastScancode != -1)
OTRGlobals::Instance->context->GetWindow()->lastScancode = -1;*/
@ -88,8 +161,8 @@ extern "C" void Graph_ProcessGfxCommands(Gfx* commands) {
float divisor_num = 0.0f;
extern "C" void OTRSetFrameDivisor(int divisor) {
OTRGlobals::Instance->context->GetWindow()->SetFrameDivisor(divisor);
extern "C" void OTRGetPixelDepthPrepare(float x, float y) {
OTRGlobals::Instance->context->GetWindow()->GetPixelDepthPrepare(x, y);
}
extern "C" uint16_t OTRGetPixelDepth(float x, float y) {

View File

@ -24,7 +24,7 @@ void Graph_ProcessFrame(void (*run_one_game_iter)(void));
void Graph_ProcessGfxCommands(Gfx* commands);
void OTRLogString(const char* src);
void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char));
void OTRSetFrameDivisor(int divisor);
void OTRGetPixelDepthPrepare(float x, float y);
uint16_t OTRGetPixelDepth(float x, float y);
int32_t OTRGetLastScancode();
uint32_t ResourceMgr_GetGameVersion();

314
soh/soh/util.cpp Normal file
View File

@ -0,0 +1,314 @@
#include "util.h"
#include <vector>
std::vector<std::string> sceneNames = {
"Inside the Deku Tree",
"Dodongo's Cavern",
"Inside Jabu-Jabu's Belly",
"Forest Temple",
"Fire Temple",
"Water Temple",
"Spirit Temple",
"Shadow Temple",
"Bottom of the Well",
"Ice Cavern",
"Ganon's Tower",
"Gerudo Training Ground",
"Thieves' Hideout",
"Inside Ganon's Castle",
"Ganon's Tower (Collapsing)",
"Inside Ganon's Castle (Collapsing)",
"Treasure Box Shop",
"Gohma's Lair",
"King Dodongo's Lair",
"Barinade's Lair",
"Phantom Ganon's Lair",
"Volvagia's Lair",
"Morpha's Lair",
"Twinrova's Lair & Nabooru's Mini-Boss Room",
"Bongo Bongo's Lair",
"Ganondorf's Lair",
"Tower Collapse Exterior",
"Market Entrance (Child - Day)",
"Market Entrance (Child - Night)",
"Market Entrance (Ruins)",
"Back Alley (Child - Day)",
"Back Alley (Child - Night)",
"Market (Child - Day)",
"Market (Child - Night)",
"Market (Ruins)",
"Temple of Time Exterior (Child - Day)",
"Temple of Time Exterior (Child - Night)",
"Temple of Time Exterior (Ruins)",
"Know-It-All Brothers' House",
"House of Twins",
"Mido's House",
"Saria's House",
"Carpenter Boss's House",
"Back Alley House (Man in Green)",
"Bazaar",
"Kokiri Shop",
"Goron Shop",
"Zora Shop",
"Kakariko Potion Shop",
"Market Potion Shop",
"Bombchu Shop",
"Happy Mask Shop",
"Link's House",
"Back Alley House (Dog Lady)",
"Stable",
"Impa's House",
"Lakeside Laboratory",
"Carpenters' Tent",
"Gravekeeper's Hut",
"Great Fairy's Fountain (Upgrades)",
"Fairy's Fountain",
"Great Fairy's Fountain (Spells)",
"Grottos",
"Grave (Redead)",
"Grave (Fairy's Fountain)",
"Royal Family's Tomb",
"Shooting Gallery",
"Temple of Time",
"Chamber of the Sages",
"Castle Hedge Maze (Day)",
"Castle Hedge Maze (Night)",
"Cutscene Map",
"Dampé's Grave & Windmill",
"Fishing Pond",
"Castle Courtyard",
"Bombchu Bowling Alley",
"Ranch House & Silo",
"Guard House",
"Granny's Potion Shop",
"Ganon's Tower Collapse & Battle Arena",
"House of Skulltula",
"Spot 00 - Hyrule Field",
"Spot 01 - Kakariko Village",
"Spot 02 - Graveyard",
"Spot 03 - Zora's River",
"Spot 04 - Kokiri Forest",
"Spot 05 - Sacred Forest Meadow",
"Spot 06 - Lake Hylia",
"Spot 07 - Zora's Domain",
"Spot 08 - Zora's Fountain",
"Spot 09 - Gerudo Valley",
"Spot 10 - Lost Woods",
"Spot 11 - Desert Colossus",
"Spot 12 - Gerudo's Fortress",
"Spot 13 - Haunted Wasteland",
"Spot 15 - Hyrule Castle",
"Spot 16 - Death Mountain Trail",
"Spot 17 - Death Mountain Crater",
"Spot 18 - Goron City",
"Spot 20 - Lon Lon Ranch",
"Ganon's Castle Exterior",
"Jungle Gym",
"Ganondorf Test Room",
"Depth Test",
"Stalfos Mini-Boss Room",
"Stalfos Boss Room",
"Sutaru",
"Castle Hedge Maze (Early)",
"Sasa Test",
"Treasure Chest Room",
};
std::vector<std::string> itemNames = {
"Deku Stick",
"Deku Nut",
"Bomb",
"Fairy Bow",
"Fire Arrow",
"Din's Fire",
"Fairy Slingshot",
"Fairy Ocarina",
"Ocarina of Time",
"Bombchu",
"Hookshot",
"Longshot",
"Ice Arrow",
"Farore's Wind",
"Boomerang",
"Lens of Truth",
"Magic Bean",
"Megaton Hammer",
"Light Arrow",
"Nayru's Love",
"Empty Bottle",
"Red Potion",
"Green Potion",
"Blue Potion",
"Bottled Fairy",
"Fish",
"Lon Lon Milk & Bottle",
"Ruto's Letter",
"Blue Fire",
"Bug",
"Big Poe",
"Lon Lon Milk (Half)",
"Poe",
"Weird Egg",
"Chicken",
"Zelda's Letter",
"Keaton Mask",
"Skull Mask",
"Spooky Mask",
"Bunny Hood",
"Goron Mask",
"Zora Mask",
"Gerudo Mask",
"Mask of Truth",
"SOLD OUT",
"Pocket Egg",
"Pocket Cucco",
"Cojiro",
"Odd Mushroom",
"Odd Potion",
"Poacher's Saw",
"Goron's Sword (Broken)",
"Prescription",
"Eyeball Frog",
"Eye Drops",
"Claim Check",
"Fairy Bow & Fire Arrow",
"Fairy Bow & Ice Arrow",
"Fairy Bow & Light Arrow",
"Kokiri Sword",
"Master Sword",
"Giant's Knife & Biggoron's Sword",
"Deku Shield",
"Hylian Shield",
"Mirror Shield",
"Kokiri Tunic",
"Goron Tunic",
"Zora Tunic",
"Kokiri Boots",
"Iron Boots",
"Hover Boots",
"Bullet Bag (30)",
"Bullet Bag (40)",
"Bullet Bag (50)",
"Quiver (30)",
"Big Quiver (40)",
"Biggest Quiver (50)",
"Bomb Bag (20)",
"Big Bomb Bag (30)",
"Biggest Bomb Bag (40)",
"Goron's Bracelet",
"Silver Gauntlets",
"Golden Gauntlets",
"Silver Scale",
"Golden Scale",
"Giant's Knife (Broken)",
"Adult's Wallet",
"Giant's Wallet",
"Deku Seeds (5)",
"Fishing Pole",
"Minuet of Forest",
"Bolero of Fire",
"Serenade of Water",
"Requiem of Spirit",
"Nocturne of Shadow",
"Prelude of Light",
"Zelda's Lullaby",
"Epona's Song",
"Saria's Song",
"Sun's Song",
"Song of Time",
"Song of Storms",
"Forest Medallion",
"Fire Medallion",
"Water Medallion",
"Spirit Medallion",
"Shadow Medallion",
"Light Medallion",
"Kokiri's Emerald",
"Goron's Ruby",
"Zora's Sapphire",
"Stone of Agony",
"Gerudo's Card",
"Gold Skulltula Token",
"Heart Container",
"Piece of Heart [?]",
"Big Key",
"Compass",
"Dungeon Map",
"Small Key",
"Small Magic Jar",
"Large Magic Jar",
"Piece of Heart",
"[Removed]",
"[Removed]",
"[Removed]",
"[Removed]",
"[Removed]",
"[Removed]",
"[Removed]",
"Lon Lon Milk",
"Recovery Heart",
"Green Rupee",
"Blue Rupee",
"Red Rupee",
"Purple Rupee",
"Huge Rupee",
"[Removed]",
"Deku Sticks (5)",
"Deku Sticks (10)",
"Deku Nuts (5)",
"Deku Nuts (10)",
"Bombs (5)",
"Bombs (10)",
"Bombs (20)",
"Bombs (30)",
"Arrows (Small)",
"Arrows (Medium)",
"Arrows (Large)",
"Deku Seeds (30)",
"Bombchu (5)",
"Bombchu (20)",
"Deku Stick Upgrade (20)",
"Deku Stick Upgrade (30)",
"Deku Nut Upgrade (30)",
"Deku Nut Upgrade (40)",
};
std::vector<std::string> questItemNames = {
"Forest Medallion",
"Fire Medallion",
"Water Medallion",
"Spirit Medallion",
"Shadow Medallion",
"Light Medallion",
"Minuet of Forest",
"Bolero of Fire",
"Serenade of Water",
"Requiem of Spirit",
"Nocturne of Shadow",
"Prelude of Light",
"Zelda's Lullaby",
"Epona's Song",
"Saria's Song",
"Sun's Song",
"Song of Time",
"Song of Storms",
"Kokiri's Emerald",
"Goron's Ruby",
"Zora's Sapphire",
"Stone of Agony",
"Gerudo's Card",
"Gold Skulltula Token",
};
const std::string& SohUtils::GetSceneName(int32_t scene) {
return sceneNames[scene];
}
const std::string& SohUtils::GetItemName(int32_t item) {
return itemNames[item];
}
const std::string& SohUtils::GetQuestItemName(int32_t item) {
return questItemNames[item];
}

11
soh/soh/util.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <string>
#include <stdint.h>
namespace SohUtils {
const std::string& GetSceneName(int32_t scene);
const std::string& GetItemName(int32_t item);
const std::string& GetQuestItemName(int32_t item);
} // namespace SohUtils

View File

@ -1,7 +1,43 @@
#include "z64.h"
#include <assert.h>
#include <malloc.h>
// 0x38000 bytes
u8 gAudioHeap[0x38000];
#ifndef _MSC_VER
#include <unistd.h>
#endif
//u8 gSystemHeap[UNK_SIZE];
u8 gSystemHeap[1024 * 1024 * 128];
#define AUDIO_HEAP_SIZE 0x38000
#define SYSTEM_HEAP_SIZE (1024 * 1024 * 128)
u8* gAudioHeap;
u8* gSystemHeap;
void Heaps_Alloc(void)
{
#ifdef _MSC_VER
gAudioHeap = (u8*)_aligned_malloc(AUDIO_HEAP_SIZE, 0x10);
gSystemHeap = (u8*)_aligned_malloc(SYSTEM_HEAP_SIZE, 0x10);
#elif defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L)
if (posix_memalign((void**)&gAudioHeap, 0x10, AUDIO_HEAP_SIZE) != 0)
gAudioHeap = NULL;
if (posix_memalign((void**)&gSystemHeap, 0x10, SYSTEM_HEAP_SIZE) != 0)
gSystemHeap = NULL;
#else
gAudioHeap = (u8*)memalign(0x10, AUDIO_HEAP_SIZE);
gSystemHeap = (u8*)memalign(0x10, SYSTEM_HEAP_SIZE);
#endif
assert(gAudioHeap != NULL);
assert(gSystemHeap != NULL);
}
void Heaps_Free(void)
{
#ifdef _MSC_VER
_aligned_free(gAudioHeap);
_aligned_free(gSystemHeap);
#else
free(gAudioHeap);
free(gSystemHeap);
#endif
}

View File

@ -824,10 +824,12 @@ NatureAmbienceDataIO sNatureAmbienceDataIO[20] = {
},
};
u32 sOcarinaAllowedBtnMask = 0x800F;
s32 sOcarinaABtnMap = 0x8000;
s32 sOcarinaCUPBtnMap = 8;
s32 sOcarinaCDownBtnMap = 4;
u32 sOcarinaAllowedBtnMask = (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT);
s32 sOcarinaABtnMap = BTN_A;
s32 sOcarinaCUPBtnMap = BTN_CUP;
s32 sOcarinaCDownBtnMap = BTN_CDOWN;
s32 sOcarinaCLeftBtnMap = BTN_CLEFT;
s32 sOcarinaCRightBtnMap = BTN_CRIGHT;
u8 sOcarinaInpEnabled = 0;
s8 D_80130F10 = 0; // "OCA", ocarina active?
u8 sCurOcarinaBtnVal = 0xFF;
@ -1245,19 +1247,23 @@ void func_800F56A8(void);
void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId);
s32 Audio_SetGanonDistVol(u8 targetVol);
void func_800EC960(u8 custom) {
if (!custom) {
osSyncPrintf("AUDIO : Ocarina Control Assign Normal\n");
// Function originally not called, so repurposing for DPad input
void func_800EC960(u8 dpad) {
if (dpad) {
sOcarinaAllowedBtnMask =
(BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT | BTN_DUP | BTN_DDOWN | BTN_DLEFT | BTN_DRIGHT);
sOcarinaABtnMap = BTN_A;
sOcarinaCUPBtnMap = BTN_CUP | BTN_DUP;
sOcarinaCDownBtnMap = BTN_CDOWN | BTN_DDOWN;
sOcarinaCLeftBtnMap = BTN_CLEFT | BTN_DLEFT;
sOcarinaCRightBtnMap = BTN_CRIGHT | BTN_DRIGHT;
} else {
sOcarinaAllowedBtnMask = (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT);
sOcarinaABtnMap = BTN_A;
sOcarinaCUPBtnMap = BTN_CUP;
sOcarinaCDownBtnMap = BTN_CDOWN;
} else {
osSyncPrintf("AUDIO : Ocarina Control Assign Custom\n");
sOcarinaAllowedBtnMask = (BTN_A | BTN_B | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT);
sOcarinaABtnMap = BTN_B;
sOcarinaCUPBtnMap = BTN_CDOWN;
sOcarinaCDownBtnMap = BTN_A;
sOcarinaCLeftBtnMap = BTN_CLEFT;
sOcarinaCRightBtnMap = BTN_CRIGHT;
}
}
@ -1542,6 +1548,7 @@ void func_800ED200(void) {
void func_800ED458(s32 arg0) {
u32 phi_v1_2;
bool dpad = CVar_GetS32("gDpadOcarinaText", 0);
if (D_80130F3C != 0 && D_80131880 != 0) {
D_80131880--;
@ -1561,6 +1568,7 @@ void func_800ED458(s32 arg0) {
D_8016BA18 &= phi_v1_2;
}
func_800EC960(dpad);
if (D_8016BA18 & sOcarinaABtnMap) {
osSyncPrintf("Presss NA_KEY_D4 %08x\n", sOcarinaABtnMap);
sCurOcarinaBtnVal = 2;
@ -1569,12 +1577,12 @@ void func_800ED458(s32 arg0) {
osSyncPrintf("Presss NA_KEY_F4 %08x\n", sOcarinaCDownBtnMap);
sCurOcarinaBtnVal = 5;
sCurOcarinaBtnIdx = 1;
} else if (D_8016BA18 & 1) {
osSyncPrintf("Presss NA_KEY_A4 %08x\n", 1);
} else if (D_8016BA18 & sOcarinaCRightBtnMap) {
osSyncPrintf("Presss NA_KEY_A4 %08x\n", sOcarinaCRightBtnMap);
sCurOcarinaBtnVal = 9;
sCurOcarinaBtnIdx = 2;
} else if (D_8016BA18 & 2) {
osSyncPrintf("Presss NA_KEY_B4 %08x\n", 2);
} else if (D_8016BA18 & sOcarinaCLeftBtnMap) {
osSyncPrintf("Presss NA_KEY_B4 %08x\n", sOcarinaCRightBtnMap);
sCurOcarinaBtnVal = 0xB;
sCurOcarinaBtnIdx = 3;
} else if (D_8016BA18 & sOcarinaCUPBtnMap) {
@ -1671,7 +1679,7 @@ void Audio_OcaSetSongPlayback(s8 songIdxPlusOne, s8 playbackState) {
void Audio_OcaPlayback(void) {
u32 noteTimerStep;
u32 nextNoteTimerStep;
u32 nextNoteTimerStep = 0;
if (sPlaybackState != 0) {
if (sStaffPlaybackPos == 0) {
@ -4772,7 +4780,7 @@ void Audio_SetCodeReverb(s8 reverb) {
}
void func_800F6700(s8 arg0) {
s8 sp1F;
s8 sp1F = 0;
switch (arg0) {
case 0:

View File

@ -381,6 +381,11 @@ void GameState_Update(GameState* gameState) {
gSaveContext.magic = (gSaveContext.doubleMagic + 1) * 0x30;
}
}
// Inf Nayru's Love Timer
if (CVar_GetS32("gInfiniteNayru", 0) != 0) {
gSaveContext.nayrusLoveTimer = 0x44B;
}
// Moon Jump On L
if (CVar_GetS32("gMoonJumpOnL", 0) != 0) {
@ -393,6 +398,32 @@ void GameState_Update(GameState* gameState) {
}
}
// Permanent infinite sword glitch (ISG)
if (CVar_GetS32("gEzISG", 0) != 0) {
if (gGlobalCtx) {
Player* player = GET_PLAYER(gGlobalCtx);
player->swordState = 1;
}
}
// Unrestricted Items
if (CVar_GetS32("gNoRestrictItems", 0) != 0) {
if (gGlobalCtx) {
memset(&gGlobalCtx->interfaceCtx.restrictions, 0, sizeof(gGlobalCtx->interfaceCtx.restrictions));
}
}
// Freeze Time
if (CVar_GetS32("gFreezeTime", 0) != 0) {
if (CVar_GetS32("gPrevTime", -1) == -1) {
CVar_SetS32("gPrevTime", gSaveContext.dayTime);
}
int32_t prevTime = CVar_GetS32("gPrevTime", gSaveContext.dayTime);
gSaveContext.dayTime = prevTime;
}
gameState->frames++;
}

View File

@ -468,35 +468,6 @@ static void RunFrame()
{
uint64_t ticksA, ticksB;
ticksA = GetPerfCounter();
OTRSetFrameDivisor(R_UPDATE_RATE);
//OTRSetFrameDivisor(0);
//AudioMgr_ThreadEntry(&gAudioMgr);
// 528 and 544 relate to 60 fps at 32 kHz 32000/60 = 533.333..
// in an ideal world, one third of the calls should use num_samples=544 and two thirds num_samples=528
#define SAMPLES_HIGH 560
#define SAMPLES_LOW 528
// PAL values
//#define SAMPLES_HIGH 656
//#define SAMPLES_LOW 624
#define AUDIO_FRAMES_PER_UPDATE (R_UPDATE_RATE > 0 ? R_UPDATE_RATE : 1 )
#define NUM_AUDIO_CHANNELS 2
int samples_left = AudioPlayer_Buffered();
u32 num_audio_samples = samples_left < AudioPlayer_GetDesiredBuffered() ? SAMPLES_HIGH : SAMPLES_LOW;
// printf("Audio samples: %d %u\n", samples_left, num_audio_samples);
// 3 is the maximum authentic frame divisor.
s16 audio_buffer[SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 3];
for (int i = 0; i < AUDIO_FRAMES_PER_UPDATE; i++) {
AudioMgr_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS), num_audio_samples);
}
//for (uint32_t i = 0; i < 2 * num_audio_samples; i++) {
// audio_buffer[i] = Rand_Next() & 0xFF;
//}
// printf("Audio samples before submitting: %d\n", audio_api->buffered());
AudioPlayer_Play((u8*)audio_buffer, num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE));
PadMgr_ThreadEntry(&gPadMgr);

View File

@ -63,6 +63,7 @@ void Main(void* arg) {
PreNmiBuff_Init(gAppNmiBufferPtr);
Fault_Init();
SysCfb_Init(0);
Heaps_Alloc();
sysHeap = gSystemHeap;
fb = SysCfb_GetFbPtr(0);
gSystemHeapSize = 1024 * 1024 * 4;
@ -131,4 +132,6 @@ void Main(void* arg) {
osDestroyThread(&sGraphThread);
func_800FBFD8();
osSyncPrintf("mainproc 実行終了\n"); // "End of execution"
Heaps_Free();
}

View File

@ -1857,7 +1857,7 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) {
}
}
if (minDistSq != 1.e38f) {
if (minDistSq != (f32)1.e38f) {
return true;
}

View File

@ -226,6 +226,9 @@ u16 Environment_GetPixelDepth(s32 x, s32 y) {
void Environment_GraphCallback(GraphicsContext* gfxCtx, void* param) {
GlobalContext* globalCtx = (GlobalContext*)param;
OTRGetPixelDepthPrepare(D_8015FD7E, D_8015FD80);
Lights_GlowCheckPrepare(globalCtx);
D_8011FB44 = Environment_GetPixelDepth(D_8015FD7E, D_8015FD80);
Lights_GlowCheck(globalCtx);
}

View File

@ -323,6 +323,44 @@ Lights* Lights_New(GraphicsContext* gfxCtx, u8 ambientR, u8 ambientG, u8 ambient
return lights;
}
void Lights_GlowCheckPrepare(GlobalContext* globalCtx) {
LightNode* node;
LightPoint* params;
Vec3f pos;
Vec3f multDest;
f32 wDest;
f32 wX;
f32 wY;
node = globalCtx->lightCtx.listHead;
while (node != NULL) {
params = &node->info->params.point;
if (node->info->type == LIGHT_POINT_GLOW) {
f32 x, y;
u32 shrink;
uint32_t height;
pos.x = params->x;
pos.y = params->y;
pos.z = params->z;
func_8002BE04(globalCtx, &pos, &multDest, &wDest);
wX = multDest.x * wDest;
wY = multDest.y * wDest;
x = wX * 160 + 160;
y = wY * 120 + 120;
shrink = ShrinkWindow_GetCurrentVal();
if ((multDest.z > 1.0f) && y >= shrink && y <= SCREEN_HEIGHT - shrink) {
OTRGetPixelDepthPrepare(x, y);
}
}
node = node->next;
}
}
void Lights_GlowCheck(GlobalContext* globalCtx) {
LightNode* node;
LightPoint* params;

View File

@ -166,7 +166,7 @@ void Message_UpdateOcarinaGame(GlobalContext* globalCtx) {
u8 Message_ShouldAdvance(GlobalContext* globalCtx) {
Input* input = &globalCtx->state.input[0];
bool isB_Held = CVar_GetS32("gFastText", 0) != 0 ? CHECK_BTN_ALL(input->cur.button, BTN_B)
bool isB_Held = CVar_GetS32("gSkipText", 0) != 0 ? CHECK_BTN_ALL(input->cur.button, BTN_B)
: CHECK_BTN_ALL(input->press.button, BTN_B);
if (CHECK_BTN_ALL(input->press.button, BTN_A) || isB_Held || CHECK_BTN_ALL(input->press.button, BTN_CUP)) {
@ -178,7 +178,7 @@ u8 Message_ShouldAdvance(GlobalContext* globalCtx) {
u8 Message_ShouldAdvanceSilent(GlobalContext* globalCtx) {
Input* input = &globalCtx->state.input[0];
bool isB_Held = CVar_GetS32("gFastText", 0) != 0 ? CHECK_BTN_ALL(input->cur.button, BTN_B)
bool isB_Held = CVar_GetS32("gSkipText", 0) != 0 ? CHECK_BTN_ALL(input->cur.button, BTN_B)
: CHECK_BTN_ALL(input->press.button, BTN_B);
return CHECK_BTN_ALL(input->press.button, BTN_A) || isB_Held || CHECK_BTN_ALL(input->press.button, BTN_CUP);
@ -203,8 +203,9 @@ void Message_HandleChoiceSelection(GlobalContext* globalCtx, u8 numChoices) {
static s16 sAnalogStickHeld = false;
MessageContext* msgCtx = &globalCtx->msgCtx;
Input* input = &globalCtx->state.input[0];
bool dpad = CVar_GetS32("gDpadOcarinaText", 0);
if (input->rel.stick_y >= 30 && !sAnalogStickHeld) {
if ((input->rel.stick_y >= 30 && !sAnalogStickHeld) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
sAnalogStickHeld = true;
msgCtx->choiceIndex--;
if (msgCtx->choiceIndex > 128) {
@ -212,7 +213,7 @@ void Message_HandleChoiceSelection(GlobalContext* globalCtx, u8 numChoices) {
} else {
Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
} else if (input->rel.stick_y <= -30 && !sAnalogStickHeld) {
} else if ((input->rel.stick_y <= -30 && !sAnalogStickHeld) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
sAnalogStickHeld = true;
msgCtx->choiceIndex++;
if (msgCtx->choiceIndex > numChoices) {
@ -950,7 +951,7 @@ void Message_DrawText(GlobalContext* globalCtx, Gfx** gfxP) {
}
}
i = j - 1;
msgCtx->textDrawPos = i + 1;
msgCtx->textDrawPos = i + CVar_GetS32("gTextSpeed", 1);
if (character) {}
}
@ -1060,7 +1061,7 @@ void Message_DrawText(GlobalContext* globalCtx, Gfx** gfxP) {
msgCtx->textDelay = msgCtx->msgBufDecoded[++i];
break;
case MESSAGE_UNSKIPPABLE:
msgCtx->textUnskippable = CVar_GetS32("gFastText", 0) != 1;
msgCtx->textUnskippable = CVar_GetS32("gSkipText", 0) != 1;
break;
case MESSAGE_TWO_CHOICE:
msgCtx->textboxEndType = TEXTBOX_ENDTYPE_2_CHOICE;
@ -1143,7 +1144,7 @@ void Message_DrawText(GlobalContext* globalCtx, Gfx** gfxP) {
}
}
if (msgCtx->textDelayTimer == 0) {
msgCtx->textDrawPos = i + 1;
msgCtx->textDrawPos = i + CVar_GetS32("gTextSpeed", 1);
msgCtx->textDelayTimer = msgCtx->textDelay;
} else {
msgCtx->textDelayTimer--;
@ -2025,7 +2026,7 @@ void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) {
gDPSetCombineLERP(gfx++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE,
0);
bool isB_Held = CVar_GetS32("gFastText", 0) != 0 ? CHECK_BTN_ALL(globalCtx->state.input[0].cur.button, BTN_B)
bool isB_Held = CVar_GetS32("gSkipText", 0) != 0 ? CHECK_BTN_ALL(globalCtx->state.input[0].cur.button, BTN_B)
: CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B);
switch (msgCtx->msgMode) {
@ -3032,7 +3033,7 @@ void Message_Update(GlobalContext* globalCtx) {
Input* input = &globalCtx->state.input[0];
s16 var;
s16 focusScreenPosX;
s16 averageY;
s16 averageY = 0;
s16 playerFocusScreenPosY;
s16 actorFocusScreenPosY;
@ -3066,7 +3067,7 @@ void Message_Update(GlobalContext* globalCtx) {
return;
}
bool isB_Held = CVar_GetS32("gFastText", 0) != 0 ? CHECK_BTN_ALL(input->cur.button, BTN_B) && !sTextboxSkipped
bool isB_Held = CVar_GetS32("gSkipText", 0) != 0 ? CHECK_BTN_ALL(input->cur.button, BTN_B) && !sTextboxSkipped
: CHECK_BTN_ALL(input->press.button, BTN_B);
switch (msgCtx->msgMode) {

View File

@ -919,7 +919,11 @@ void func_80083108(GlobalContext* globalCtx) {
if (interfaceCtx->restrictions.tradeItems != 0) {
for (i = 1; i < 4; i++) {
if ((gSaveContext.equips.buttonItems[i] >= ITEM_WEIRD_EGG) &&
if ((CVar_GetS32("gMMBunnyHood", 0) != 0)
&& (gSaveContext.equips.buttonItems[i] >= ITEM_MASK_KEATON)
&& (gSaveContext.equips.buttonItems[i] <= ITEM_MASK_TRUTH)) {
gSaveContext.buttonStatus[i] = BTN_ENABLED;
} else if ((gSaveContext.equips.buttonItems[i] >= ITEM_WEIRD_EGG) &&
(gSaveContext.equips.buttonItems[i] <= ITEM_CLAIM_CHECK)) {
if (gSaveContext.buttonStatus[i] == BTN_ENABLED) {
sp28 = 1;
@ -3125,6 +3129,14 @@ void Interface_Draw(GlobalContext* globalCtx) {
};
static s16 rupeeDigitsFirst[] = { 1, 0, 0 };
static s16 rupeeDigitsCount[] = { 2, 3, 3 };
// courtesy of https://github.com/TestRunnerSRL/OoT-Randomizer/blob/Dev/ASM/c/hud_colors.c
static s16 rupeeWalletColors[3][3] = {
{ 0xC8, 0xFF, 0x64 }, // Base Wallet (Green)
{ 0x82, 0x82, 0xFF }, // Adult's Wallet (Blue)
{ 0xFF, 0x64, 0x64 }, // Giant's Wallet (Red)
};
static s16 spoilingItemEntrances[] = { 0x01AD, 0x0153, 0x0153 };
static f32 D_80125B54[] = { -40.0f, -35.0f }; // unused
static s16 D_80125B5C[] = { 91, 91 }; // unused
@ -3167,7 +3179,15 @@ void Interface_Draw(GlobalContext* globalCtx) {
if (fullUi) {
// Rupee Icon
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 200, 255, 100, interfaceCtx->magicAlpha);
s16* rColor;
if (CVar_GetS32("gDynamicWalletIcon", 0)) {
rColor = &rupeeWalletColors[CUR_UPG_VALUE(UPG_WALLET)];
} else {
rColor = &rupeeWalletColors[0];
}
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, rColor[0], rColor[1], rColor[2], interfaceCtx->magicAlpha);
gDPSetEnvColor(OVERLAY_DISP++, 0, 80, 0, 255);
OVERLAY_DISP = Gfx_TextureIA8(OVERLAY_DISP, gRupeeCounterIconTex, 16, 16, OTRGetRectDimensionFromLeftEdge(26),
206, 16, 16, 1 << 10, 1 << 10);
@ -3265,7 +3285,7 @@ void Interface_Draw(GlobalContext* globalCtx) {
Gfx_TextureI8(OVERLAY_DISP, ((u8*)digitTextures[interfaceCtx->counterDigits[svar2]]), 8, 16,
OTRGetRectDimensionFromLeftEdge(svar3), 206, 8, 16, 1 << 10, 1 << 10);
}
}
}
else {
// Make sure item counts have black backgrounds
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 0, 0, 0, interfaceCtx->magicAlpha);

View File

@ -1274,7 +1274,7 @@ void BossGanondrof_CollisionCheck(BossGanondrof* this, GlobalContext* globalCtx)
this->actor.colChkInfo.health -= dmg;
}
if ((s8)this->actor.colChkInfo.health <= 0 || 1) {
if ((s8)this->actor.colChkInfo.health <= 0) {
BossGanondrof_SetupDeath(this, globalCtx);
Enemy_StartFinishingBlow(globalCtx, &this->actor);
return;

View File

@ -496,7 +496,7 @@ void EnExItem_DrawMagic(EnExItem* this, GlobalContext* globalCtx, s16 magicIndex
}
void EnExItem_DrawKey(EnExItem* this, GlobalContext* globalCtx, s32 index) {
static s32 keySegments[] = { 0x0403F140 };
static void* keySegments[] = { gDropKeySmallTex };
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_en_ex_item.c", 880);

View File

@ -948,7 +948,9 @@ s32 EnOssan_FacingShopkeeperDialogResult(EnOssan* this, GlobalContext* globalCtx
}
void EnOssan_State_FacingShopkeeper(EnOssan* this, GlobalContext* globalCtx, Player* player) {
Input* input = &globalCtx->state.input[0];
u8 nextIndex;
bool dpad = CVar_GetS32("gDpadShop", 0);
if ((Message_GetState(&globalCtx->msgCtx) == TEXT_STATE_CHOICE) &&
!EnOssan_TestEndInteraction(this, globalCtx, &globalCtx->state.input[0])) {
@ -957,7 +959,7 @@ void EnOssan_State_FacingShopkeeper(EnOssan* this, GlobalContext* globalCtx, Pla
return;
}
// Stick Left
if (this->stickAccumX < 0) {
if ((this->stickAccumX < 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
nextIndex = EnOssan_SetCursorIndexFromNeutral(this, 4);
if (nextIndex != CURSOR_INVALID) {
this->cursorIndex = nextIndex;
@ -966,7 +968,7 @@ void EnOssan_State_FacingShopkeeper(EnOssan* this, GlobalContext* globalCtx, Pla
this->stickLeftPrompt.isEnabled = false;
func_80078884(NA_SE_SY_CURSOR);
}
} else if (this->stickAccumX > 0) {
} else if ((this->stickAccumX > 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
nextIndex = EnOssan_SetCursorIndexFromNeutral(this, 0);
if (nextIndex != CURSOR_INVALID) {
this->cursorIndex = nextIndex;
@ -1023,11 +1025,13 @@ void EnOssan_State_LookToRightShelf(EnOssan* this, GlobalContext* globalCtx, Pla
}
}
void EnOssan_CursorUpDown(EnOssan* this) {
void EnOssan_CursorUpDown(EnOssan* this, GlobalContext* globalCtx) {
Input* input = &globalCtx->state.input[0];
u8 curTemp = this->cursorIndex;
u8 curScanTemp;
bool dpad = CVar_GetS32("gDpadShop", 0);
if (this->stickAccumY < 0) {
if ((this->stickAccumY < 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
curTemp &= 0xFE;
if (this->shelfSlots[curTemp] != NULL) {
this->cursorIndex = curTemp;
@ -1066,7 +1070,7 @@ void EnOssan_CursorUpDown(EnOssan* this) {
}
}
}
} else if (this->stickAccumY > 0) {
} else if ((this->stickAccumY > 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
curTemp |= 1;
if (this->shelfSlots[curTemp] != NULL) {
this->cursorIndex = curTemp;
@ -1172,11 +1176,13 @@ s32 EnOssan_HasPlayerSelectedItem(GlobalContext* globalCtx, EnOssan* this, Input
}
void EnOssan_State_BrowseLeftShelf(EnOssan* this, GlobalContext* globalCtx, Player* player) {
Input* input = &globalCtx->state.input[0];
s32 a;
s32 b;
u8 prevIndex = this->cursorIndex;
s32 c;
s32 d;
bool dpad = CVar_GetS32("gDpadShop", 0);
if (!EnOssan_ReturnItemToShelf(this)) {
osSyncPrintf("%s[%d]:" VT_FGCOL(GREEN) "ズーム中!!" VT_RST "\n", "../z_en_oB1.c", 2152);
@ -1193,7 +1199,7 @@ void EnOssan_State_BrowseLeftShelf(EnOssan* this, GlobalContext* globalCtx, Play
if ((Message_GetState(&globalCtx->msgCtx) == TEXT_STATE_EVENT) &&
!EnOssan_HasPlayerSelectedItem(globalCtx, this, &globalCtx->state.input[0])) {
if (this->moveHorizontal) {
if (this->stickAccumX > 0) {
if ((this->stickAccumX > 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
a = EnOssan_CursorRight(this, this->cursorIndex, 4);
if (a != CURSOR_INVALID) {
this->cursorIndex = a;
@ -1201,14 +1207,14 @@ void EnOssan_State_BrowseLeftShelf(EnOssan* this, GlobalContext* globalCtx, Play
EnOssan_SetLookToShopkeeperFromShelf(globalCtx, this);
return;
}
} else if (this->stickAccumX < 0) {
} else if ((this->stickAccumX < 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
b = EnOssan_CursorLeft(this, this->cursorIndex, 8);
if (b != CURSOR_INVALID) {
this->cursorIndex = b;
}
}
} else {
if (this->stickAccumX > 0 && this->stickAccumX > 500) {
if ((this->stickAccumX > 0 && this->stickAccumX > 500) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
c = EnOssan_CursorRight(this, this->cursorIndex, 4);
if (c != CURSOR_INVALID) {
this->cursorIndex = c;
@ -1216,14 +1222,14 @@ void EnOssan_State_BrowseLeftShelf(EnOssan* this, GlobalContext* globalCtx, Play
EnOssan_SetLookToShopkeeperFromShelf(globalCtx, this);
return;
}
} else if (this->stickAccumX < 0 && this->stickAccumX < -500) {
} else if ((this->stickAccumX < 0 && this->stickAccumX < -500) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
d = EnOssan_CursorLeft(this, this->cursorIndex, 8);
if (d != CURSOR_INVALID) {
this->cursorIndex = d;
}
}
}
EnOssan_CursorUpDown(this);
EnOssan_CursorUpDown(this, globalCtx);
if (this->cursorIndex != prevIndex) {
Message_ContinueTextbox(globalCtx, this->shelfSlots[this->cursorIndex]->actor.textId);
func_80078884(NA_SE_SY_CURSOR);
@ -1232,9 +1238,11 @@ void EnOssan_State_BrowseLeftShelf(EnOssan* this, GlobalContext* globalCtx, Play
}
void EnOssan_State_BrowseRightShelf(EnOssan* this, GlobalContext* globalCtx, Player* player) {
Input* input = &globalCtx->state.input[0];
s32 pad[2];
u8 prevIndex;
u8 nextIndex;
bool dpad = CVar_GetS32("gDpadShop", 0);
prevIndex = this->cursorIndex;
if (!EnOssan_ReturnItemToShelf(this)) {
@ -1252,7 +1260,7 @@ void EnOssan_State_BrowseRightShelf(EnOssan* this, GlobalContext* globalCtx, Pla
if ((Message_GetState(&globalCtx->msgCtx) == TEXT_STATE_EVENT) &&
!EnOssan_HasPlayerSelectedItem(globalCtx, this, &globalCtx->state.input[0])) {
if (this->moveHorizontal) {
if (this->stickAccumX < 0) {
if ((this->stickAccumX < 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
nextIndex = EnOssan_CursorRight(this, this->cursorIndex, 0);
if (nextIndex != CURSOR_INVALID) {
this->cursorIndex = nextIndex;
@ -1260,14 +1268,14 @@ void EnOssan_State_BrowseRightShelf(EnOssan* this, GlobalContext* globalCtx, Pla
EnOssan_SetLookToShopkeeperFromShelf(globalCtx, this);
return;
}
} else if (this->stickAccumX > 0) {
} else if ((this->stickAccumX > 0) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
nextIndex = EnOssan_CursorLeft(this, this->cursorIndex, 4);
if (nextIndex != CURSOR_INVALID) {
this->cursorIndex = nextIndex;
}
}
} else {
if (this->stickAccumX < 0 && this->stickAccumX < -500) {
if ((this->stickAccumX < 0 && this->stickAccumX < -500) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
nextIndex = EnOssan_CursorRight(this, this->cursorIndex, 0);
if (nextIndex != CURSOR_INVALID) {
this->cursorIndex = nextIndex;
@ -1275,14 +1283,14 @@ void EnOssan_State_BrowseRightShelf(EnOssan* this, GlobalContext* globalCtx, Pla
EnOssan_SetLookToShopkeeperFromShelf(globalCtx, this);
return;
}
} else if (this->stickAccumX > 0 && this->stickAccumX > 500) {
} else if ((this->stickAccumX > 0 && this->stickAccumX > 500) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
nextIndex = EnOssan_CursorLeft(this, this->cursorIndex, 4);
if (nextIndex != CURSOR_INVALID) {
this->cursorIndex = nextIndex;
}
}
}
EnOssan_CursorUpDown(this);
EnOssan_CursorUpDown(this, globalCtx);
if (this->cursorIndex != prevIndex) {
Message_ContinueTextbox(globalCtx, this->shelfSlots[this->cursorIndex]->actor.textId);
func_80078884(NA_SE_SY_CURSOR);

View File

@ -19,6 +19,7 @@
#include "overlays/effects/ovl_Effect_Ss_Fhg_Flash/z_eff_ss_fhg_flash.h"
#include "objects/gameplay_keep/gameplay_keep.h"
#include "objects/object_link_child/object_link_child.h"
#include "textures/icon_item_24_static/icon_item_24_static.h"
typedef struct {
/* 0x00 */ u8 itemId;
@ -1875,10 +1876,20 @@ void func_80833DF8(Player* this, GlobalContext* globalCtx) {
s32 i;
if (this->currentMask != PLAYER_MASK_NONE) {
maskActionParam = this->currentMask - 1 + PLAYER_AP_MASK_KEATON;
if (!func_80833C98(C_BTN_ITEM(0), maskActionParam) && !func_80833C98(C_BTN_ITEM(1), maskActionParam) &&
!func_80833C98(C_BTN_ITEM(2), maskActionParam)) {
this->currentMask = PLAYER_MASK_NONE;
if (CVar_GetS32("gMMBunnyHood", 0) != 0) {
s32 maskItem = this->currentMask - PLAYER_MASK_KEATON + ITEM_MASK_KEATON;
if (gSaveContext.equips.buttonItems[0] != maskItem && gSaveContext.equips.buttonItems[1] != maskItem &&
gSaveContext.equips.buttonItems[2] != maskItem && gSaveContext.equips.buttonItems[3] != maskItem) {
this->currentMask = PLAYER_MASK_NONE;
func_808328EC(this, NA_SE_PL_CHANGE_ARMS);
}
} else {
maskActionParam = this->currentMask - 1 + PLAYER_AP_MASK_KEATON;
if (!func_80833C98(C_BTN_ITEM(0), maskActionParam) && !func_80833C98(C_BTN_ITEM(1), maskActionParam) &&
!func_80833C98(C_BTN_ITEM(2), maskActionParam)) {
this->currentMask = PLAYER_MASK_NONE;
}
}
}
@ -5942,7 +5953,11 @@ void func_8083DFE0(Player* this, f32* arg1, s16* arg2) {
s16 yawDiff = this->currentYaw - *arg2;
if (this->swordState == 0) {
this->linearVelocity = CLAMP(this->linearVelocity, -(R_RUN_SPEED_LIMIT / 100.0f), (R_RUN_SPEED_LIMIT / 100.0f));
float maxSpeed = R_RUN_SPEED_LIMIT / 100.0f;
if (CVar_GetS32("gMMBunnyHood", 0) != 0 && this->currentMask == PLAYER_MASK_BUNNY) {
maxSpeed *= 1.5f;
}
this->linearVelocity = CLAMP(this->linearVelocity, -maxSpeed, maxSpeed);
}
if (ABS(yawDiff) > 0x6000) {
@ -7523,6 +7538,9 @@ void func_80842180(Player* this, GlobalContext* globalCtx) {
func_80837268(this, &sp2C, &sp2A, 0.018f, globalCtx);
if (!func_8083C484(this, &sp2C, &sp2A)) {
if (CVar_GetS32("gMMBunnyHood", 0) != 0 && this->currentMask == PLAYER_MASK_BUNNY) {
sp2C *= 1.5f;
}
func_8083DF68(this, sp2C, sp2A);
func_8083DDC8(this, globalCtx);
@ -10248,7 +10266,7 @@ void func_80848C74(GlobalContext* globalCtx, Player* this) {
}
}
void func_80848EF8(Player* this) {
void func_80848EF8(Player* this, GlobalContext* globalCtx) {
if (CHECK_QUEST_ITEM(QUEST_STONE_OF_AGONY)) {
f32 temp = 200000.0f - (this->unk_6A4 * 5.0f);
@ -10257,8 +10275,45 @@ void func_80848EF8(Player* this) {
}
this->unk_6A0 += temp;
/*Prevent it on horse, while jumping and on title screen.
If you fly around no stone of agony for you! */
if (CVar_GetS32("gVisualAgony", 0) !=0 && !this->stateFlags1) {
int rectLeft = OTRGetRectDimensionFromLeftEdge(26); //Left X Pos
int rectTop = 60; //Top Y Pos
int rectWidth = 24; //Texture Width
int rectHeight = 24; //Texture Heigh
int DefaultIconA= 50; //Default icon alphe (55 on 255)
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_player.c", 2824);
gDPPipeSync(OVERLAY_DISP++);
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, DefaultIconA);
gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0);
if (this->unk_6A0 > 4000000.0f) {
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, 255);
} else {
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, DefaultIconA);
}
if (temp == 0 || temp <= 0.1f) {
/*Fail check, it is used to draw off the icon when
link is standing out range but do not refresh unk_6A0.
Also used to make a default value in my case.*/
gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, DefaultIconA);
}
gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255);
gDPSetOtherMode(OVERLAY_DISP++, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_IA16 | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PRIM | G_RM_XLU_SURF | G_RM_XLU_SURF2);
gDPLoadTextureBlock(OVERLAY_DISP++, gStoneOfAgonyIconTex, G_IM_FMT_RGBA, G_IM_SIZ_32b, 24, 24, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gDPSetOtherMode(OVERLAY_DISP++, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_IA16 | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PRIM | G_RM_XLU_SURF | G_RM_XLU_SURF2);
gSPWideTextureRectangle(OVERLAY_DISP++, rectLeft << 2, rectTop << 2, (rectLeft + rectWidth) << 2, (rectTop + rectHeight) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10);
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_player.c", 3500);
}
if (this->unk_6A0 > 4000000.0f) {
this->unk_6A0 = 0.0f;
if (CVar_GetS32("gVisualAgony", 0) !=0 && !this->stateFlags1) {
//This audio is placed here and not in previous CVar check to prevent ears ra.. :)
Audio_PlaySoundGeneral(NA_SE_SY_MESSAGE_WOMAN, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E0);
}
func_8083264C(this, 120, 20, 10, 0);
}
}
@ -10530,7 +10585,7 @@ void Player_UpdateCommon(Player* this, GlobalContext* globalCtx, Input* input) {
else {
this->fallStartHeight = this->actor.world.pos.y;
}
func_80848EF8(this);
func_80848EF8(this, globalCtx);
}
}

View File

@ -179,6 +179,7 @@ void FileChoose_UpdateMainMenu(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
SramContext* sramCtx = &this->sramCtx;
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (CHECK_BTN_ALL(input->press.button, BTN_START) || CHECK_BTN_ALL(input->press.button, BTN_A)) {
if (this->buttonIndex <= FS_BTN_MAIN_FILE_3) {
@ -237,10 +238,10 @@ void FileChoose_UpdateMainMenu(GameState* thisx) {
}
}
} else {
if (ABS(this->stickRelY) > 30) {
if ((ABS(this->stickRelY) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
if (this->stickRelY > 30) {
if ((this->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
this->buttonIndex--;
if (this->buttonIndex < FS_BTN_MAIN_FILE_1) {
this->buttonIndex = FS_BTN_MAIN_OPTIONS;
@ -1318,6 +1319,7 @@ void FileChoose_FadeInFileInfo(GameState* thisx) {
void FileChoose_ConfirmFile(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (CHECK_BTN_ALL(input->press.button, BTN_START) || (CHECK_BTN_ALL(input->press.button, BTN_A))) {
if (this->confirmButtonIndex == FS_BTN_CONFIRM_YES) {
@ -1332,7 +1334,7 @@ void FileChoose_ConfirmFile(GameState* thisx) {
} else if (CHECK_BTN_ALL(input->press.button, BTN_B)) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->selectMode++;
} else if (ABS(this->stickRelY) >= 30) {
} else if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->confirmButtonIndex ^= 1;
}

View File

@ -62,6 +62,7 @@ void FileChoose_SelectCopySource(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
SramContext* sramCtx = &this->sramCtx;
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) ||
CHECK_BTN_ALL(input->press.button, BTN_B)) {
@ -82,10 +83,10 @@ void FileChoose_SelectCopySource(GameState* thisx) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
} else {
if (ABS(this->stickRelY) >= 30) {
if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
if (this->stickRelY >= 30) {
if ((this->stickRelY >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
this->buttonIndex--;
if (this->buttonIndex < FS_BTN_COPY_FILE_1) {
@ -174,6 +175,7 @@ void FileChoose_SelectCopyDest(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
SramContext* sramCtx = &this->sramCtx;
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) ||
CHECK_BTN_ALL(input->press.button, BTN_B)) {
@ -194,10 +196,10 @@ void FileChoose_SelectCopyDest(GameState* thisx) {
}
} else {
if (ABS(this->stickRelY) >= 30) {
if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
if (this->stickRelY >= 30) {
if ((this->stickRelY >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
this->buttonIndex--;
if ((this->buttonIndex == this->selectedFileIndex)) {
@ -360,6 +362,7 @@ void FileChoose_CopyConfirm(GameState* thisx) {
SramContext* sramCtx = &this->sramCtx;
Input* input = &this->state.input[0];
u16 dayTime;
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (((this->buttonIndex != FS_BTN_CONFIRM_YES) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) ||
CHECK_BTN_ALL(input->press.button, BTN_B)) {
@ -377,7 +380,7 @@ void FileChoose_CopyConfirm(GameState* thisx) {
this->configMode = CM_COPY_ANIM_1;
func_800AA000(300.0f, 0xB4, 0x14, 0x64);
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
} else if (ABS(this->stickRelY) >= 30) {
} else if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->buttonIndex ^= 1;
}
@ -680,6 +683,7 @@ void FileChoose_EraseSelect(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
SramContext* sramCtx = &this->sramCtx;
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) ||
CHECK_BTN_ALL(input->press.button, BTN_B)) {
@ -700,10 +704,10 @@ void FileChoose_EraseSelect(GameState* thisx) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
} else {
if (ABS(this->stickRelY) >= 30) {
if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
if (this->stickRelY >= 30) {
if ((this->stickRelY >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
this->buttonIndex--;
if (this->buttonIndex < FS_BTN_ERASE_FILE_1) {
this->buttonIndex = FS_BTN_ERASE_QUIT;
@ -817,6 +821,7 @@ void FileChoose_SetupEraseConfirm2(GameState* thisx) {
void FileChoose_EraseConfirm(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (((this->buttonIndex != FS_BTN_CONFIRM_YES) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) ||
CHECK_BTN_ALL(input->press.button, BTN_B)) {
@ -833,7 +838,7 @@ void FileChoose_EraseConfirm(GameState* thisx) {
this->nextTitleLabel = FS_TITLE_ERASE_COMPLETE;
func_800AA000(200.0f, 0xFF, 0x14, 0x96);
sEraseDelayTimer = 15;
} else if (ABS(this->stickRelY) >= 30) {
} else if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->buttonIndex ^= 1;
}

View File

@ -509,12 +509,14 @@ void FileChoose_StartNameEntry(GameState* thisx) {
*/
void FileChoose_UpdateKeyboardCursor(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
Input* input = &this->state.input[0];
s16 prevKbdX;
bool dpad = CVar_GetS32("gDpadPauseName", 0);
this->kbdButton = 99;
if (this->kbdY != 5) {
if (this->stickRelX < -30) {
if ((this->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->charIndex--;
this->kbdX--;
@ -522,7 +524,7 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) {
this->kbdX = 12;
this->charIndex = (this->kbdY * 13) + this->kbdX;
}
} else if (this->stickRelX > 30) {
} else if ((this->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->charIndex++;
this->kbdX++;
@ -532,13 +534,13 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) {
}
}
} else {
if (this->stickRelX < -30) {
if ((this->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->kbdX--;
if (this->kbdX < 3) {
this->kbdX = 4;
}
} else if (this->stickRelX > 30) {
} else if ((this->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->kbdX++;
if (this->kbdX > 4) {
@ -547,7 +549,7 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) {
}
}
if (this->stickRelY > 30) {
if ((this->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->kbdY--;
@ -578,7 +580,7 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) {
this->charIndex += this->kbdX;
}
}
} else if (this->stickRelY < -30) {
} else if ((this->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
this->kbdY++;
@ -655,6 +657,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) {
FileChooseContext* this = (FileChooseContext*)thisx;
SramContext* sramCtx = &this->sramCtx;
Input* input = &this->state.input[0];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (CHECK_BTN_ALL(input->press.button, BTN_B)) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
@ -675,7 +678,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) {
return;
}
if (this->stickRelX < -30) {
if ((this->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
if (sSelectedSetting == FS_SETTING_AUDIO) {
@ -688,7 +691,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) {
} else {
gSaveContext.zTargetSetting ^= 1;
}
} else if (this->stickRelX > 30) {
} else if ((this->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
if (sSelectedSetting == FS_SETTING_AUDIO) {
@ -702,7 +705,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) {
}
}
if ((this->stickRelY < -30) || (this->stickRelY > 30)) {
if ((ABS(this->stickRelY) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
sSelectedSetting ^= 1;
} else if (CHECK_BTN_ALL(input->press.button, BTN_A)) {

View File

@ -74,6 +74,7 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx
s16 pad2;
s16 phi_s0_2;
s16 sp208[3];
bool dpad = CVar_GetS32("gDpadPauseName", 0);
OPEN_DISPS(gfxCtx, "../z_kaleido_collect.c", 248);
@ -83,96 +84,92 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx
if (pauseCtx->cursorSpecialPos == 0) {
pauseCtx->nameColorSet = 0;
sp216 = pauseCtx->cursorSlot[PAUSE_QUEST];
phi_s3 = pauseCtx->cursorPoint[PAUSE_QUEST];
if ((pauseCtx->state != 6) || ((pauseCtx->stickRelX == 0) && (pauseCtx->stickRelY == 0))) {
sp216 = pauseCtx->cursorSlot[PAUSE_QUEST];
} else {
phi_s3 = pauseCtx->cursorPoint[PAUSE_QUEST];
if (pauseCtx->stickRelX < -30) {
phi_s0 = D_8082A1AC[phi_s3][2];
if (phi_s0 == -3) {
KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_LEFT);
pauseCtx->unk_1E4 = 0;
} else {
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][2];
}
}
} else if (pauseCtx->stickRelX > 30) {
phi_s0 = D_8082A1AC[phi_s3][3];
if (phi_s0 == -2) {
KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_RIGHT);
pauseCtx->unk_1E4 = 0;
} else {
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][3];
}
}
}
if (pauseCtx->stickRelY < -30) {
phi_s0 = D_8082A1AC[phi_s3][1];
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][1];
}
} else if (pauseCtx->stickRelY > 30) {
phi_s0 = D_8082A1AC[phi_s3][0];
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][0];
}
}
if (phi_s3 != pauseCtx->cursorPoint[PAUSE_QUEST]) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
phi_s0 = D_8082A1AC[phi_s3][2];
if (phi_s0 == -3) {
KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_LEFT);
pauseCtx->unk_1E4 = 0;
Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
if (pauseCtx->cursorPoint[PAUSE_QUEST] != 0x18) {
if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) {
if (pauseCtx->cursorPoint[PAUSE_QUEST] < 6) {
phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x66;
osSyncPrintf("000 ccc=%d\n", phi_s0_2);
} else if (pauseCtx->cursorPoint[PAUSE_QUEST] < 0x12) {
phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x54;
osSyncPrintf("111 ccc=%d\n", phi_s0_2);
} else {
phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x5A;
osSyncPrintf("222 ccc=%d (%d, %d, %d)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST],
0x12, 0x6C);
} else {
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][2];
}
}
} else if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
phi_s0 = D_8082A1AC[phi_s3][3];
if (phi_s0 == -2) {
KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_RIGHT);
pauseCtx->unk_1E4 = 0;
} else {
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][3];
}
}
}
if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
phi_s0 = D_8082A1AC[phi_s3][1];
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][1];
}
} else if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
phi_s0 = D_8082A1AC[phi_s3][0];
while (phi_s0 >= 0) {
if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) {
break;
}
phi_s0 = D_8082A1AC[phi_s0][0];
}
}
if (phi_s3 != pauseCtx->cursorPoint[PAUSE_QUEST]) {
pauseCtx->unk_1E4 = 0;
Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
if (pauseCtx->cursorPoint[PAUSE_QUEST] != 0x18) {
if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) {
if (pauseCtx->cursorPoint[PAUSE_QUEST] < 6) {
phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x66;
osSyncPrintf("000 ccc=%d\n", phi_s0_2);
} else if (pauseCtx->cursorPoint[PAUSE_QUEST] < 0x12) {
phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x54;
osSyncPrintf("111 ccc=%d\n", phi_s0_2);
} else {
phi_s0_2 = PAUSE_ITEM_NONE;
osSyncPrintf("999 ccc=%d (%d, %d)\n", PAUSE_ITEM_NONE, pauseCtx->cursorPoint[PAUSE_QUEST],
0x18);
phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x5A;
osSyncPrintf("222 ccc=%d (%d, %d, %d)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST],
0x12, 0x6C);
}
} else {
if ((gSaveContext.inventory.questItems & 0xF0000000) != 0) {
phi_s0_2 = 0x72;
} else {
phi_s0_2 = PAUSE_ITEM_NONE;
}
osSyncPrintf("888 ccc=%d (%d, %d, %x)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST], 0x72,
gSaveContext.inventory.questItems & 0xF0000000);
phi_s0_2 = PAUSE_ITEM_NONE;
osSyncPrintf("999 ccc=%d (%d, %d)\n", PAUSE_ITEM_NONE, pauseCtx->cursorPoint[PAUSE_QUEST],
0x18);
}
sp216 = pauseCtx->cursorPoint[PAUSE_QUEST];
pauseCtx->cursorItem[pauseCtx->pageIndex] = phi_s0_2;
pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216;
} else {
if ((gSaveContext.inventory.questItems & 0xF0000000) != 0) {
phi_s0_2 = 0x72;
} else {
phi_s0_2 = PAUSE_ITEM_NONE;
}
osSyncPrintf("888 ccc=%d (%d, %d, %x)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST], 0x72,
gSaveContext.inventory.questItems & 0xF0000000);
}
sp216 = pauseCtx->cursorPoint[PAUSE_QUEST];
pauseCtx->cursorItem[pauseCtx->pageIndex] = phi_s0_2;
pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216;
KaleidoScope_SetCursorVtx(pauseCtx, sp216 * 4, pauseCtx->questVtx);
if ((pauseCtx->state == 6) && (pauseCtx->unk_1E4 == 0) && (pauseCtx->cursorSpecialPos == 0)) {
@ -215,7 +212,7 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx
}
}
} else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
pauseCtx->cursorPoint[PAUSE_QUEST] = 0x15;
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;
@ -232,7 +229,7 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx
pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216;
}
} else {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
pauseCtx->cursorPoint[PAUSE_QUEST] = 0;
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;

View File

@ -140,6 +140,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
s16 cursorX;
s16 cursorY;
volatile s16 oldCursorPoint;
bool dpad = CVar_GetS32("gDpadPauseName", 0);
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kaleido_equipment.c", 219);
@ -174,7 +175,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
cursorMoveResult = 0;
while (cursorMoveResult == 0) {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
if (pauseCtx->cursorX[PAUSE_EQUIP] != 0) {
pauseCtx->cursorX[PAUSE_EQUIP] -= 1;
pauseCtx->cursorPoint[PAUSE_EQUIP] -= 1;
@ -216,7 +217,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
cursorMoveResult = 3;
}
}
} else if (pauseCtx->stickRelX > 30) {
} else if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
if (pauseCtx->cursorX[PAUSE_EQUIP] < 3) {
pauseCtx->cursorX[PAUSE_EQUIP] += 1;
pauseCtx->cursorPoint[PAUSE_EQUIP] += 1;
@ -264,7 +265,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
cursorMoveResult = 0;
while (cursorMoveResult == 0) {
if (pauseCtx->stickRelY > 30) {
if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
if (pauseCtx->cursorY[PAUSE_EQUIP] != 0) {
pauseCtx->cursorY[PAUSE_EQUIP] -= 1;
pauseCtx->cursorPoint[PAUSE_EQUIP] -= 4;
@ -286,7 +287,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
pauseCtx->cursorPoint[PAUSE_EQUIP] = cursorPoint;
cursorMoveResult = 3;
}
} else if (pauseCtx->stickRelY < -30) {
} else if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
if (pauseCtx->cursorY[PAUSE_EQUIP] < 3) {
pauseCtx->cursorY[PAUSE_EQUIP] += 1;
pauseCtx->cursorPoint[PAUSE_EQUIP] += 4;
@ -309,7 +310,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
}
}
} else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;
@ -356,7 +357,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
}
}
} else {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;
Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
@ -594,7 +595,6 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
gSPInvalidateTexCache(POLY_KAL_DISP++, pauseCtx->iconItemSegment);
//gSPInvalidateTexCache(POLY_KAL_DISP++, pauseCtx->iconItem24Segment);
gSPInvalidateTexCache(POLY_KAL_DISP++, pauseCtx->nameSegment);
gSPInvalidateTexCache(POLY_KAL_DISP++, globalCtx->interfaceCtx.mapSegment);
//gSPSegment(POLY_KAL_DISP++, 0x07, pauseCtx->playerSegment);
gSPSegment(POLY_KAL_DISP++, 0x08, pauseCtx->iconItemSegment);

View File

@ -96,6 +96,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
s16 cursorY;
s16 oldCursorPoint;
s16 moveCursorResult;
bool dpad = CVar_GetS32("gDpadPauseName", 0);
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kaleido_item.c", 234);
@ -120,7 +121,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
pauseCtx->stickRelX = 40;
}
if (ABS(pauseCtx->stickRelX) > 30) {
if ((ABS(pauseCtx->stickRelX) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DLEFT | BTN_DRIGHT))) {
cursorPoint = pauseCtx->cursorPoint[PAUSE_ITEM];
cursorX = pauseCtx->cursorX[PAUSE_ITEM];
cursorY = pauseCtx->cursorY[PAUSE_ITEM];
@ -132,7 +133,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
if (gSaveContext.inventory.items[pauseCtx->cursorPoint[PAUSE_ITEM]]) {}
while (moveCursorResult == 0) {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
if (pauseCtx->cursorX[PAUSE_ITEM] != 0) {
pauseCtx->cursorX[PAUSE_ITEM] -= 1;
pauseCtx->cursorPoint[PAUSE_ITEM] -= 1;
@ -164,7 +165,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
moveCursorResult = 2;
}
}
} else if (pauseCtx->stickRelX > 30) {
} else if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
if (pauseCtx->cursorX[PAUSE_ITEM] < 5) {
pauseCtx->cursorX[PAUSE_ITEM] += 1;
pauseCtx->cursorPoint[PAUSE_ITEM] += 1;
@ -208,7 +209,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
cursorItem, pauseCtx->cursorSpecialPos);
}
} else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;
@ -242,7 +243,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
}
}
} else {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;
@ -280,13 +281,13 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
if (pauseCtx->cursorSpecialPos == 0) {
if (cursorItem != PAUSE_ITEM_NONE) {
if (ABS(pauseCtx->stickRelY) > 30) {
if ((ABS(pauseCtx->stickRelY) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) {
moveCursorResult = 0;
cursorPoint = pauseCtx->cursorPoint[PAUSE_ITEM];
cursorY = pauseCtx->cursorY[PAUSE_ITEM];
while (moveCursorResult == 0) {
if (pauseCtx->stickRelY > 30) {
if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
if (pauseCtx->cursorY[PAUSE_ITEM] != 0) {
pauseCtx->cursorY[PAUSE_ITEM] -= 1;
pauseCtx->cursorPoint[PAUSE_ITEM] -= 6;
@ -300,7 +301,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
moveCursorResult = 2;
}
} else if (pauseCtx->stickRelY < -30) {
} else if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
if (pauseCtx->cursorY[PAUSE_ITEM] < 3) {
pauseCtx->cursorY[PAUSE_ITEM] += 1;
pauseCtx->cursorPoint[PAUSE_ITEM] += 6;

View File

@ -36,6 +36,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
static u16 mapBgPulseStage = 0;
InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx;
PauseContext* pauseCtx = &globalCtx->pauseCtx;
Input* input = &globalCtx->state.input[0];
s16 i;
s16 j;
s16 oldCursorPoint;
@ -43,6 +44,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
s16 stepG;
s16 stepB;
u16 rgba16;
bool dpad = CVar_GetS32("gDpadPauseName", 0);
OPEN_DISPS(gfxCtx, "../z_kaleido_map_PAL.c", 123);
@ -51,7 +53,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
oldCursorPoint = pauseCtx->cursorPoint[PAUSE_MAP];
if (pauseCtx->cursorSpecialPos == 0) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
if (pauseCtx->cursorX[PAUSE_MAP] != 0) {
KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_RIGHT);
} else {
@ -67,7 +69,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
}
}
}
} else if (pauseCtx->stickRelX < -30) {
} else if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
if (pauseCtx->cursorX[PAUSE_MAP] == 0) {
KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_LEFT);
} else {
@ -82,7 +84,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
}
if (pauseCtx->cursorPoint[PAUSE_MAP] < 3) {
if (pauseCtx->stickRelY > 30) {
if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
if (pauseCtx->cursorPoint[PAUSE_MAP] != 0) {
for (i = pauseCtx->cursorPoint[PAUSE_MAP] - 1; i >= 0; i--) {
if (CHECK_DUNGEON_ITEM(i, gSaveContext.mapIndex)) {
@ -92,7 +94,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
}
}
} else {
if (pauseCtx->stickRelY < -30) {
if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
if (pauseCtx->cursorPoint[PAUSE_MAP] != 2) {
for (i = pauseCtx->cursorPoint[PAUSE_MAP] + 1; i < 3; i++) {
if (CHECK_DUNGEON_ITEM(i, gSaveContext.mapIndex)) {
@ -104,7 +106,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
}
}
} else {
if (pauseCtx->stickRelY > 30) {
if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) {
if (pauseCtx->cursorPoint[PAUSE_MAP] >= 4) {
for (i = pauseCtx->cursorPoint[PAUSE_MAP] - 3 - 1; i >= 0; i--) {
if ((gSaveContext.sceneFlags[gSaveContext.mapIndex].floors & gBitFlags[i]) ||
@ -115,7 +117,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
}
}
}
} else if (pauseCtx->stickRelY < -30) {
} else if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) {
if (pauseCtx->cursorPoint[PAUSE_MAP] != 10) {
for (i = pauseCtx->cursorPoint[PAUSE_MAP] - 3 + 1; i < 11; i++) {
if ((gSaveContext.sceneFlags[gSaveContext.mapIndex].floors & gBitFlags[i]) ||
@ -138,7 +140,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
}
}
} else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;
pauseCtx->cursorSlot[PAUSE_MAP] = pauseCtx->cursorPoint[PAUSE_MAP] = pauseCtx->dungeonMapSlot;
@ -148,7 +150,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
} else {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
pauseCtx->nameDisplayTimer = 0;
pauseCtx->cursorSpecialPos = 0;
pauseCtx->cursorX[PAUSE_MAP] = 1;
@ -330,6 +332,10 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC
gSPVertex(POLY_KAL_DISP++, &pauseCtx->mapPageVtx[60], 8, 0);
// The dungeon map textures are recreated each frame, so always invalidate them
gSPInvalidateTexCache(POLY_KAL_DISP++, interfaceCtx->mapSegment);
gSPInvalidateTexCache(POLY_KAL_DISP++, interfaceCtx->mapSegment + 0x800);
gDPLoadTextureBlock_4b(POLY_KAL_DISP++, interfaceCtx->mapSegment, G_IM_FMT_CI, 48, 85, 0, G_TX_WRAP | G_TX_NOMIRROR,
G_TX_WRAP | G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
@ -396,6 +402,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx
};
static u16 D_8082A6D4 = 0;
PauseContext* pauseCtx = &globalCtx->pauseCtx;
Input* input = &globalCtx->state.input[0];
s16 i;
s16 j;
s16 t;
@ -404,6 +411,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx
s16 stepR;
s16 stepG;
s16 stepB;
bool dpad = CVar_GetS32("gDpadPauseName", 0);
OPEN_DISPS(gfxCtx, "../z_kaleido_map_PAL.c", 556);
@ -412,7 +420,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx
oldCursorPoint = pauseCtx->cursorPoint[PAUSE_WORLD_MAP];
if (pauseCtx->cursorSpecialPos == 0) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
D_8082A6D4 = 0;
do {
@ -423,7 +431,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx
break;
}
} while (pauseCtx->worldMapPoints[pauseCtx->cursorPoint[PAUSE_WORLD_MAP]] == 0);
} else if (pauseCtx->stickRelX < -30) {
} else if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
D_8082A6D4 = 0;
do {
@ -444,7 +452,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx
} else {
pauseCtx->cursorItem[PAUSE_MAP] = gSaveContext.worldMapArea + 0x18;
if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
pauseCtx->cursorPoint[PAUSE_WORLD_MAP] = 0;
pauseCtx->cursorSpecialPos = 0;
@ -459,7 +467,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx
D_8082A6D4 = 0;
}
} else {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
pauseCtx->cursorPoint[PAUSE_WORLD_MAP] = 11;
pauseCtx->cursorSpecialPos = 0;
@ -663,7 +671,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx
gDPLoadTextureBlock(POLY_KAL_DISP++, gWorldMapDotTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 8, 0, G_TX_WRAP | G_TX_NOMIRROR,
G_TX_WRAP | G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
for (j = i = 0; i < 12; i++, t++, j += 4) {
for (j = t = i = 0; i < 12; i++, t++, j += 4) {
if (pauseCtx->worldMapPoints[i] != 0) {
gDPPipeSync(POLY_KAL_DISP++);

View File

@ -7,12 +7,13 @@ void KaleidoScope_UpdatePrompt(GlobalContext* globalCtx) {
Input* input = &globalCtx->state.input[0];
s8 relStickX = input->rel.stick_x;
s16 step;
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (((pauseCtx->state == 7) && (pauseCtx->unk_1EC == 1)) || (pauseCtx->state == 0xE) || (pauseCtx->state == 0x10)) {
if ((pauseCtx->promptChoice == 0) && (relStickX >= 30)) {
if ((pauseCtx->promptChoice == 0) && ((relStickX >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT)))) {
Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
pauseCtx->promptChoice = 4;
} else if ((pauseCtx->promptChoice != 0) && (relStickX <= -30)) {
} else if ((pauseCtx->promptChoice != 0) && ((relStickX <= -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT)))) {
Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
pauseCtx->promptChoice = 0;
}

View File

@ -936,8 +936,9 @@ void KaleidoScope_HandlePageToggles(PauseContext* pauseCtx, Input* input) {
return;
}
bool dpad = CVar_GetS32("gDpadPauseName", 0);
if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) {
if (pauseCtx->stickRelX < -30) {
if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) {
pauseCtx->pageSwitchTimer++;
if ((pauseCtx->pageSwitchTimer >= 10) || (pauseCtx->pageSwitchTimer == 0)) {
KaleidoScope_SwitchPage(pauseCtx, 0);
@ -946,7 +947,7 @@ void KaleidoScope_HandlePageToggles(PauseContext* pauseCtx, Input* input) {
pauseCtx->pageSwitchTimer = -1;
}
} else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_RIGHT) {
if (pauseCtx->stickRelX > 30) {
if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) {
pauseCtx->pageSwitchTimer++;
if ((pauseCtx->pageSwitchTimer >= 10) || (pauseCtx->pageSwitchTimer == 0)) {
KaleidoScope_SwitchPage(pauseCtx, 2);