From 767ba3bb1444ebd10f01c5b2081576843023bd29 Mon Sep 17 00:00:00 2001 From: qwertyquerty Date: Thu, 12 Mar 2026 04:01:03 -0700 Subject: [PATCH] Ongoing gameplay dev (#49) * launch.json cwd * bodge to load gci for testing * stub card stat * gameplay bodges * viewport, ub fixes * add release with debug info cmake variant * be fixes, sound stub * viewport h * d_msg_flow BE * be fopAcM_createItemFromEnemyID * update launch configuration to use iso * more audio stubs * Attempt to set viewport and get messages for brightness check * skip opening scene again, fixed JMessage::TResourceContainer::TCResource::Do_destroy * add guards for viewport changes * moar endian swapping to get Link sitting in PROC_OPENING_SCENE and for dialogues * BE d_msg_class i_data * stub bgm start * fix div by 0 error (for now) * TEMP_BROKEN in d_menu_ring * REQUIRES_GX_LINES * properly stub renderingAmap::draw with REQUIRES_GX_LINES * better stubbing outside of stubs * fix event data getting swapped multiple times * evil draw vp fix * Stub log imgui This redirects all spammy logs to an imgui window that is cleared per frame. This fixes the serious performance dip of the logging, and makes the regular log readable. * Oops move those optimization changes I accidentally committed behind a flag DUSK_SELECTED_OPT * gx_line macro in map * fix audio stubbing * switch to CARD API aurora impl * remove kabufuda from link libs * refactor imgui stuff and add input viewer * merge stub log with refactor * accidentally committed a metaforce header shh * basic map loader * ImGuiConsole: Add missing include * you may now play as luigi (you may now load stages with bridges) * bloom fix * bloom leak fix * cloud shadow fix * add soft reset button to imgui menu * if it broke dont not fix it * i swear i committed this * BE swap indMtx in JPAResource::setPTev * wnark ct fix * frsqrte implementation from kinoko * Fix Clang compile error in JAISeq::prepare_getSeqData_ * Add endian conversions to dMsgFlow_c::getInitNodeIndex This fixes a freeze when Fado tries to stop you from leaving the starting area. * Add RAII GXTexObj wrapper; fix almost all leaks * Update aurora for indirect texturing * Update aurora for CARD fix * Fix Clang build * More d_msg_flow endian fixes Fixes softlock when trying to talk to Fado and possibly other NPCs. * no frame limiter * get pause menu working * proper frame limiting * particle pointer size fix * improve map loader a bit --------- Co-authored-by: Jasper St. Pierre Co-authored-by: TakaRikka Co-authored-by: CraftyBoss Co-authored-by: Luke Street Co-authored-by: Lurs <2795933+Lurs@users.noreply.github.com> Co-authored-by: PJB3005 Co-authored-by: tgsm Co-authored-by: Max Roncace Co-authored-by: Phillip Stephens --- .vscode/launch.json | 4 +- CMakeLists.txt | 32 +- cmake-variants.yaml | 4 + extern/aurora | 2 +- files.cmake | 16 +- include/d/actor/d_a_mirror.h | 4 +- include/d/actor/d_a_obj_flag2.h | 4 +- include/d/actor/d_a_obj_flag3.h | 4 +- include/d/actor/d_a_obj_kamakiri.h | 2 +- include/d/actor/d_a_obj_stoneMark.h | 2 +- include/d/d_com_inf_game.h | 6 +- include/d/d_drawlist.h | 19 +- include/d/d_map_path.h | 4 +- include/d/d_msg_class.h | 8 +- include/d/d_msg_flow.h | 19 +- include/dusk/endian.h | 1 - include/dusk/gx_helper.h | 32 ++ include/dusk/logging.h | 15 + include/dusk/map_loader_definitions.h | 179 ++++++++++ include/dusk/math.h | 138 ++++++++ include/dusk/time.h | 103 ++++++ include/m_Do/m_Do_controller_pad.h | 1 + include/m_Do/m_Do_ext.h | 2 +- include/m_Do/m_Do_graphic.h | 10 +- include/m_Do/m_Do_lib.h | 4 +- .../include/JSystem/J3DGraphBase/J3DStruct.h | 1 - .../include/JSystem/J3DGraphBase/J3DTexture.h | 10 +- libs/JSystem/include/JSystem/JGadget/binary.h | 11 +- .../JSystem/include/JSystem/JKernel/JKRHeap.h | 12 +- libs/JSystem/include/JSystem/JMath/JMath.h | 8 +- .../include/JSystem/JMessage/resource.h | 2 +- .../include/JSystem/JParticle/JPAEmitter.h | 2 +- .../include/JSystem/JUtility/JUTCacheFont.h | 4 +- .../include/JSystem/JUtility/JUTResFont.h | 3 +- .../include/JSystem/JUtility/JUTTexture.h | 3 +- libs/JSystem/src/J2DGraph/J2DWindowEx.cpp | 4 +- libs/JSystem/src/J3DGraphBase/J3DGD.cpp | 12 +- libs/JSystem/src/J3DGraphBase/J3DSys.cpp | 7 +- libs/JSystem/src/J3DGraphBase/J3DTexture.cpp | 6 +- .../JSystem/src/J3DGraphBase/J3DTransform.cpp | 2 +- .../src/J3DGraphLoader/J3DMaterialFactory.cpp | 2 + libs/JSystem/src/JAudio2/JAISeq.cpp | 2 +- libs/JSystem/src/JFramework/JFWDisplay.cpp | 17 +- libs/JSystem/src/JKernel/JKRArchivePri.cpp | 13 +- libs/JSystem/src/JMath/JMath.cpp | 2 - libs/JSystem/src/JMessage/resource.cpp | 8 +- .../src/JParticle/JPADynamicsBlock.cpp | 12 + libs/JSystem/src/JParticle/JPAResource.cpp | 10 +- libs/JSystem/src/JStudio/JStudio/stb.cpp | 6 +- .../JStudio/JStudio_JAudio2/object-sound.cpp | 18 +- .../JStudio_JParticle/object-particle.cpp | 16 +- .../JStudio/JStudio_JStage/object-actor.cpp | 10 +- .../JStudio/JStudio_JStage/object-camera.cpp | 10 +- .../JStudio/JStudio_JStage/object-light.cpp | 2 +- .../src/JStudio/JStudio_JStage/object.cpp | 4 +- libs/JSystem/src/JUtility/JUTCacheFont.cpp | 1 + libs/JSystem/src/JUtility/JUTResFont.cpp | 3 + libs/JSystem/src/JUtility/JUTTexture.cpp | 9 +- libs/dolphin/include/dolphin/card.h | 322 ------------------ src/Z2AudioLib/Z2Creature.cpp | 13 +- src/Z2AudioLib/Z2SeqMgr.cpp | 8 + src/Z2AudioLib/Z2SoundMgr.cpp | 6 +- src/Z2AudioLib/Z2SoundObject.cpp | 12 + src/d/actor/d_a_alink_effect.inc | 7 +- src/d/actor/d_a_e_bg.cpp | 2 +- src/d/actor/d_a_e_rd.cpp | 6 + src/d/actor/d_a_e_sb.cpp | 2 +- src/d/actor/d_a_e_sg.cpp | 2 +- src/d/actor/d_a_formation_mng.cpp | 4 +- src/d/actor/d_a_kytag12.cpp | 4 + src/d/actor/d_a_mant.cpp | 5 +- src/d/actor/d_a_movie_player.cpp | 8 +- src/d/actor/d_a_npc_mk.cpp | 16 +- src/d/actor/d_a_npc_p2.cpp | 16 +- src/d/actor/d_a_npc_shop_maro.cpp | 8 +- src/d/actor/d_a_npc_sola.cpp | 4 +- src/d/actor/d_a_obj_brg.cpp | 4 +- src/d/actor/d_a_obj_flag.cpp | 4 +- src/d/actor/d_a_obj_kbacket.cpp | 2 +- src/d/actor/d_a_obj_stone.cpp | 2 +- src/d/actor/d_a_player.cpp | 2 +- src/d/d_camera.cpp | 4 + src/d/d_com_inf_game.cpp | 4 +- src/d/d_demo.cpp | 3 +- src/d/d_drawlist.cpp | 37 +- src/d/d_error_msg.cpp | 3 + src/d/d_event_data.cpp | 22 +- src/d/d_gameover.cpp | 4 +- src/d/d_home_button.cpp | 3 + src/d/d_k_wmark.cpp | 2 +- src/d/d_kankyo_rain.cpp | 49 ++- src/d/d_map.cpp | 2 + src/d/d_map_path.cpp | 6 +- src/d/d_menu_collect.cpp | 5 + src/d/d_menu_ring.cpp | 4 + src/d/d_menu_window.cpp | 2 +- src/d/d_meter2.cpp | 4 +- src/d/d_msg_class.cpp | 42 +-- src/d/d_msg_flow.cpp | 32 +- src/d/d_ovlp_fade2.cpp | 8 + src/d/d_ovlp_fade3.cpp | 8 + src/d/d_pane_class.cpp | 4 + src/d/d_resorce.cpp | 2 +- src/d/d_s_play.cpp | 19 +- src/dusk/imgui.cpp | 142 -------- src/dusk/imgui/ImGuiCameraOverlay.cpp | 107 ++++++ src/dusk/imgui/ImGuiConsole.cpp | 322 ++++++++++++++++++ src/dusk/imgui/ImGuiConsole.hpp | 67 ++++ src/dusk/imgui/ImGuiControllerOverlay.cpp | 274 +++++++++++++++ .../imgui/{kb_pad.cpp => ImGuiDebugPad.cpp} | 2 +- src/dusk/imgui/ImGuiHeapOverlay.cpp | 102 ++++++ src/dusk/imgui/ImGuiMapLoader.cpp | 100 ++++++ src/dusk/imgui/ImGuiProcessOverlay.cpp | 102 ++++++ src/dusk/imgui/ImGuiStubLog.cpp | 84 +++++ src/dusk/imgui/camera.cpp | 112 ------ src/dusk/imgui/debug_overlay.cpp | 200 ----------- src/dusk/imgui/heaps.cpp | 112 ------ src/dusk/imgui/imgui.hpp | 20 -- src/dusk/imgui/processes.cpp | 110 ------ src/dusk/logging.cpp | 33 ++ src/dusk/stubs.cpp | 191 ----------- src/f_op/f_op_actor_mng.cpp | 4 +- src/f_op/f_op_camera.cpp | 3 + src/f_op/f_op_kankyo.cpp | 6 + src/m_Do/m_Do_MemCard.cpp | 7 +- src/m_Do/m_Do_ext.cpp | 6 +- src/m_Do/m_Do_graphic.cpp | 112 ++++-- src/m_Do/m_Do_lib.cpp | 5 +- src/m_Do/m_Do_main.cpp | 13 +- 129 files changed, 2270 insertions(+), 1541 deletions(-) create mode 100644 include/dusk/map_loader_definitions.h create mode 100644 include/dusk/time.h delete mode 100644 libs/dolphin/include/dolphin/card.h delete mode 100644 src/dusk/imgui.cpp create mode 100644 src/dusk/imgui/ImGuiCameraOverlay.cpp create mode 100644 src/dusk/imgui/ImGuiConsole.cpp create mode 100644 src/dusk/imgui/ImGuiConsole.hpp create mode 100644 src/dusk/imgui/ImGuiControllerOverlay.cpp rename src/dusk/imgui/{kb_pad.cpp => ImGuiDebugPad.cpp} (98%) create mode 100644 src/dusk/imgui/ImGuiHeapOverlay.cpp create mode 100644 src/dusk/imgui/ImGuiMapLoader.cpp create mode 100644 src/dusk/imgui/ImGuiProcessOverlay.cpp create mode 100644 src/dusk/imgui/ImGuiStubLog.cpp delete mode 100644 src/dusk/imgui/camera.cpp delete mode 100644 src/dusk/imgui/debug_overlay.cpp delete mode 100644 src/dusk/imgui/heaps.cpp delete mode 100644 src/dusk/imgui/imgui.hpp delete mode 100644 src/dusk/imgui/processes.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json index 3fa84f5d21..4cc435870a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,10 +6,12 @@ "type": "cppvsdbg", "request": "launch", "program": "${command:cmake.launchTargetPath}", + "args": ["-l", "1", "--dvd", "${workspaceRoot}/orig/GZ2E01/GZ2E01.iso"], "MIMode": "gdb", "miDebuggerPath": "gdb", "symbolSearchPath": "${command:cmake.launchTargetPath}", - "console": "integratedTerminal" + "console": "integratedTerminal", + "cwd":"${workspaceRoot}" } ] } diff --git a/CMakeLists.txt b/CMakeLists.txt index bd86158774..9395f83759 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,11 @@ if (CMAKE_SYSTEM_NAME STREQUAL Linux) set(DAWN_USE_WAYLAND ON CACHE BOOL "Enable support for Wayland surface" FORCE) endif () set(AURORA_ENABLE_DVD ON CACHE BOOL "Enable DVD API support" FORCE) +set(AURORA_ENABLE_CARD ON CACHE BOOL "Enable CARD API support" FORCE) add_subdirectory(extern/aurora EXCLUDE_FROM_ALL) option(DUSK_BUILD_WARNINGS "If off, compiler warnings will be suppressed") +option(DUSK_SELECTED_OPT "If on, selected parts of the project will be compiled with optimizations on Debug, intending to make the game run at 30 FPS. Note for MSVC: you will need to remove '/RTC1' from your debug flags in CMake.") if (CMAKE_SYSTEM_NAME STREQUAL Linux) # -Wno-multichar: Multi-character constants ('ABCD') are implementation-defined but all compilers @@ -64,7 +66,15 @@ FetchContent_MakeAvailable(cxxopts) include(files.cmake) # TODO: version handling for res includes -set(DUSK_TP_VERSION GZ2E01) + +set(DUSK_GAME_NAME "GZ2E") +set(DUSK_GAME_VERSION "01") + +set(DUSK_TP_VERSION ${DUSK_GAME_NAME}${DUSK_GAME_VERSION}) + +message(STATUS "dusk: Game Name: ${DUSK_GAME_NAME}") +message(STATUS "dusk: Game Version: ${DUSK_GAME_VERSION}") +message(STATUS "dusk: TP Version: ${DUSK_TP_VERSION}") source_group("dolzel" FILES ${DOLZEL_FILES} ${Z2AUDIOLIB_FILES} ${JSYSTEM_FILES} ${JSYSTEM_DEBUG_FILES} ${REL_FILES}) source_group("dusk" FILES ${DUSK_FILES}) @@ -84,14 +94,15 @@ target_include_directories(game_debug PUBLIC extern ${CMAKE_SOURCE_DIR}/build/${DUSK_TP_VERSION}/include build/${DUSK_TP_VERSION}/include) -target_link_libraries(game_debug PUBLIC aurora::core aurora::gx aurora::gd aurora::si aurora::vi aurora::pad aurora::mtx aurora::os aurora::dvd) +target_link_libraries(game_debug PUBLIC aurora::core aurora::gx aurora::gd aurora::si aurora::vi aurora::pad aurora::mtx aurora::os aurora::dvd aurora::card) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -add_library(game SHARED ${DOLZEL_FILES} ${Z2AUDIOLIB_FILES} ${SSYSTEM_FILES} ${JSYSTEM_FILES} ${REL_FILES} ${DUSK_FILES} ${DOLPHIN_FILES}) +add_library(game SHARED ${DOLZEL_FILES} ${Z2AUDIOLIB_FILES} ${SSYSTEM_FILES} ${JSYSTEM_FILES} ${REL_FILES} ${DUSK_FILES} ${DOLPHIN_FILES} + src/dusk/imgui/ImGuiStubLog.cpp) target_link_libraries(game PRIVATE game_debug cxxopts::cxxopts) -target_compile_definitions(game PRIVATE TARGET_PC AVOID_UB=1 VERSION=0 NDEBUG=1 NDEBUG_DEFINED=1 DEBUG_DEFINED=0) - +target_compile_definitions(game PRIVATE TARGET_PC AVOID_UB=1 VERSION=0 NDEBUG=1 NDEBUG_DEFINED=1 DEBUG_DEFINED=0 + DUSK_TP_VERSION="${DUSK_TP_VERSION}" DUSK_GAME_NAME="${DUSK_GAME_NAME}" DUSK_GAME_VERSION="${DUSK_GAME_VERSION}") add_executable(dusk src/dusk/main.cpp) target_compile_definitions(dusk PRIVATE TARGET_PC AVOID_UB=1 VERSION=0) target_include_directories(dusk PRIVATE include) @@ -99,3 +110,14 @@ target_link_libraries(dusk PRIVATE game aurora::main) include(extern/aurora/cmake/AuroraCopyRuntimeDLLs.cmake) aurora_copy_runtime_dlls(dusk game) + +if (DUSK_SELECTED_OPT) + if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + set(_opt_flags /O2 /Ob2) + elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") + set(_opt_flags -O2) + endif () + + target_compile_options(xxhash PRIVATE ${_opt_flags}) + target_compile_options(aurora_gx PRIVATE ${_opt_flags}) +endif () diff --git a/cmake-variants.yaml b/cmake-variants.yaml index 08fa19bbad..f9f6ad51bd 100644 --- a/cmake-variants.yaml +++ b/cmake-variants.yaml @@ -9,6 +9,10 @@ buildType: short: Release long: Optimized, no debug symbols buildType: Release + release_debug: + short: RelWithDebInfo + long: Optimized, with debug symbols + buildType: RelWithDebInfo platform: default: win64 diff --git a/extern/aurora b/extern/aurora index 70734a93ee..95803b7e7d 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit 70734a93eef53d4c06995e8d87a8719bd91d3194 +Subproject commit 95803b7e7d6f1580de8a637c0e2ce3d5973f6bcb diff --git a/files.cmake b/files.cmake index d2f452738c..adacbde6ef 100644 --- a/files.cmake +++ b/files.cmake @@ -1327,7 +1327,6 @@ set(DOLPHIN_FILES set(DUSK_FILES include/dusk/endian_gx.hpp src/dusk/asserts.cpp - src/dusk/imgui.cpp src/dusk/logging.cpp src/dusk/stubs.cpp src/dusk/endian.cpp @@ -1335,12 +1334,15 @@ set(DUSK_FILES src/dusk/extras.cpp src/dusk/globals.cpp #src/dusk/m_Do_ext_dusk.cpp - src/dusk/imgui/imgui.hpp - src/dusk/imgui/processes.cpp - src/dusk/imgui/camera.cpp - src/dusk/imgui/debug_overlay.cpp - src/dusk/imgui/heaps.cpp - src/dusk/imgui/kb_pad.cpp + src/dusk/imgui/ImGuiConsole.hpp + src/dusk/imgui/ImGuiConsole.cpp + src/dusk/imgui/ImGuiProcessOverlay.cpp + src/dusk/imgui/ImGuiCameraOverlay.cpp + src/dusk/imgui/ImGuiHeapOverlay.cpp + src/dusk/imgui/ImGuiDebugPad.cpp + src/dusk/imgui/ImGuiControllerOverlay.cpp + src/dusk/imgui/ImGuiStubLog.cpp + src/dusk/imgui/ImGuiMapLoader.cpp src/dusk/offset_ptr.cpp src/dusk/OSContext.cpp src/dusk/OSThread.cpp diff --git a/include/d/actor/d_a_mirror.h b/include/d/actor/d_a_mirror.h index 39ef469fd1..fd69c8682e 100644 --- a/include/d/actor/d_a_mirror.h +++ b/include/d/actor/d_a_mirror.h @@ -15,10 +15,10 @@ public: virtual void draw(); virtual ~dMirror_packet_c(); cXyz& getViewScale() { return mViewScale; } - GXTexObj& getTexObj() { return mTexObj; } + TGXTexObj& getTexObj() { return mTexObj; } cXyz* getQuad() { return mQuad; } - /* 0x010 */ GXTexObj mTexObj; + /* 0x010 */ TGXTexObj mTexObj; /* 0x030 */ u8 mModelCount; /* 0x034 */ J3DModel* mModels[0x40]; /* 0x134 */ cXyz mQuad[4]; diff --git a/include/d/actor/d_a_obj_flag2.h b/include/d/actor/d_a_obj_flag2.h index 4e700f54b2..54b3777ac6 100644 --- a/include/d/actor/d_a_obj_flag2.h +++ b/include/d/actor/d_a_obj_flag2.h @@ -35,11 +35,11 @@ public: void setDecayRate(f32 rate) { mDecayRate = rate; } void setGravity(f32 rate) { mGravity = rate; } void setTornado(f32 tornado) { mTornado = tornado; } - GXTexObj* getImageTexObj() { return &mTexObj; } + TGXTexObj* getImageTexObj() { return &mTexObj; } void setTexCoord_p(void* texCoordP) { mpTexCoord = texCoordP; } /* 0x010 */ dKy_tevstr_c mTevStr; - /* 0x398 */ GXTexObj mTexObj; + /* 0x398 */ TGXTexObj mTexObj; /* 0x3B8 */ dCcD_Stts mStts; /* 0x3F4 */ dCcD_Sph mSph; /* 0x52C */ u8 field_0x52c[0x540 - 0x52c]; diff --git a/include/d/actor/d_a_obj_flag3.h b/include/d/actor/d_a_obj_flag3.h index cae8cfb385..c6a94f6538 100644 --- a/include/d/actor/d_a_obj_flag3.h +++ b/include/d/actor/d_a_obj_flag3.h @@ -34,7 +34,7 @@ public: cXyz* getVec() { return mVecs; } cXyz* getNormal() { return mNormals; } cXyz* getNormalBack() { return mNormalBacks; } - GXTexObj* getImageTexObj() { return &mTexObj; } + TGXTexObj* getImageTexObj() { return &mTexObj; } void setSpringRate(f32 rate) { mSpringRate = rate; } void setWindRate(f32 rate) { mWindRate = rate; } void setDecayRate(f32 rate) { mDecayRate = rate; } @@ -52,7 +52,7 @@ public: void calcFlagFactorSub(cXyz* param_1, cXyz* param_2, cXyz* param_3, f32 param_4); - /* 0x010 */ GXTexObj mTexObj; + /* 0x010 */ TGXTexObj mTexObj; /* 0x030 */ dKy_tevstr_c mTevStr; /* 0x3B8 */ dCcD_Stts mStts; /* 0x3F4 */ dCcD_Sph mSph; diff --git a/include/d/actor/d_a_obj_kamakiri.h b/include/d/actor/d_a_obj_kamakiri.h index 15e3db5d9e..3b2d56e533 100644 --- a/include/d/actor/d_a_obj_kamakiri.h +++ b/include/d/actor/d_a_obj_kamakiri.h @@ -47,7 +47,7 @@ public: mpBrkAnm->entry(model->getModelData()); mpMorfSO->entryDL(); if (field_0x9c0 == 0) { - GXTexObj* texObj = dDlst_shadowControl_c::getSimpleTex(); + TGXTexObj* texObj = dDlst_shadowControl_c::getSimpleTex(); dComIfGd_setSimpleShadow(¤t.pos, mObjAcch.GetGroundH(), 15.0f, mObjAcch.m_gnd, 0, -0.6f, texObj); } } diff --git a/include/d/actor/d_a_obj_stoneMark.h b/include/d/actor/d_a_obj_stoneMark.h index 87c44804de..fbe56ce31d 100644 --- a/include/d/actor/d_a_obj_stoneMark.h +++ b/include/d/actor/d_a_obj_stoneMark.h @@ -25,7 +25,7 @@ public: private: /* 0x0568 */ request_of_phase_process_class mpPhase; - /* 0x0570 */ GXTexObj mTexObj; + /* 0x0570 */ TGXTexObj mTexObj; /* 0x0590 */ dBgS_ObjAcch mObjAcch; /* 0x0768 */ dBgS_AcchCir mAcchCir; /* 0x07A8 */ dCcD_Stts mStts; diff --git a/include/d/d_com_inf_game.h b/include/d/d_com_inf_game.h index ae6a3e4035..0c8752eb44 100644 --- a/include/d/d_com_inf_game.h +++ b/include/d/d_com_inf_game.h @@ -1251,10 +1251,10 @@ int dComLbG_PhaseHandler(request_of_phase_process_class*, request_of_phase_proce BOOL dComIfG_isSceneResetButton(); int dComIfGd_setSimpleShadow(cXyz* i_pos, f32 param_1, f32 param_2, cBgS_PolyInfo& param_3, s16 i_angle, - f32 param_5, GXTexObj* i_tex); + f32 param_5, TGXTexObj* i_tex); int dComIfGd_setShadow(u32 param_0, s8 param_1, J3DModel* param_2, cXyz* param_3, f32 param_4, f32 param_5, f32 param_6, f32 param_7, cBgS_PolyInfo& param_8, - dKy_tevstr_c* param_9, s16 param_10, f32 param_11, GXTexObj* param_12); + dKy_tevstr_c* param_9, s16 param_10, f32 param_11, TGXTexObj* param_12); inline dSv_info_c* dComIfGs_getSaveInfo() { return &g_dComIfG_gameInfo.info; @@ -4489,7 +4489,7 @@ inline int dComIfGd_setRealShadow(u32 param_0, s8 param_1, J3DModel* param_2, cX } inline int dComIfGd_setSimpleShadow(cXyz* pos, f32 param_1, f32 param_2, cXyz* param_3, s16 angle, - f32 param_5, GXTexObj* tex) { + f32 param_5, TGXTexObj* tex) { return g_dComIfG_gameInfo.drawlist.setSimpleShadow(pos, param_1, param_2, param_3, angle, param_5, tex); } diff --git a/include/d/d_drawlist.h b/include/d/d_drawlist.h index 46e00893e5..80dc9035df 100644 --- a/include/d/d_drawlist.h +++ b/include/d/d_drawlist.h @@ -5,9 +5,10 @@ #include "JSystem/J2DGraph/J2DScreen.h" #include "JSystem/J3DGraphBase/J3DSys.h" #include "SSystem/SComponent/c_m3d_g_pla.h" +#include "dusk/gx_helper.h" #include "f_op/f_op_view.h" -#include "m_Do/m_Do_ext.h" #include "global.h" +#include "m_Do/m_Do_ext.h" class J3DDrawBuffer; class J3DModel; @@ -168,7 +169,7 @@ public: void setScaleX(f32 scale) { mScaleX = scale; } void setScaleY(f32 scale) { mScaleY = scale; } - /* 0x04 */ GXTexObj mTexObj; + /* 0x04 */ TGXTexObj mTexObj; /* 0x24 */ f32 field_0x24; /* 0x28 */ f32 field_0x28; /* 0x2C */ f32 field_0x2c; @@ -201,11 +202,11 @@ public: class dDlst_shadowSimple_c { public: void draw(); - void set(cXyz*, f32, f32, cXyz*, s16, f32, GXTexObj*); + void set(cXyz*, f32, f32, cXyz*, s16, f32, TGXTexObj*); dDlst_shadowSimple_c(); /* 0x00 */ u8 mAlpha; - /* 0x04 */ GXTexObj* mpTexObj; + /* 0x04 */ TGXTexObj* mpTexObj; /* 0x08 */ Mtx mVolumeMtx; /* 0x38 */ Mtx mMtx; }; // Size: 0x68 @@ -291,12 +292,12 @@ public: void draw(f32 (*)[4]); int setReal(u32, s8, J3DModel*, cXyz*, f32, f32, dKy_tevstr_c*); bool addReal(u32, J3DModel*); - int setSimple(cXyz*, f32, f32, cXyz*, s16, f32, GXTexObj*); + int setSimple(cXyz*, f32, f32, cXyz*, s16, f32, TGXTexObj*); static void setSimpleTex(ResTIMG const*); - static GXTexObj* getSimpleTex() { return &mSimpleTexObj; } + static TGXTexObj* getSimpleTex() { return &mSimpleTexObj; } - static GXTexObj mSimpleTexObj; + static TGXTexObj mSimpleTexObj; private: /* 0x00000 */ u8 field_0x0; @@ -307,7 +308,7 @@ private: /* 0x0000C */ dDlst_shadowSimple_c mSimple[128]; /* 0x0340C */ int mNextID; /* 0x03410 */ dDlst_shadowReal_c mReal[8]; - /* 0x15EB0 */ GXTexObj field_0x15eb0[2]; + /* 0x15EB0 */ TGXTexObj field_0x15eb0[2]; /* 0x15EF0 */ void* field_0x15ef0[2]; }; @@ -444,7 +445,7 @@ public: } int setSimpleShadow(cXyz* param_0, f32 param_1, f32 param_2, cXyz* param_3, s16 param_4, - f32 param_5, GXTexObj* param_6) { + f32 param_5, TGXTexObj* param_6) { return mShadowControl.setSimple(param_0, param_1, param_2, param_3, param_4, param_5, param_6); } diff --git a/include/d/d_map_path.h b/include/d/d_map_path.h index d665b586c5..3dcfd2b38d 100644 --- a/include/d/d_map_path.h +++ b/include/d/d_map_path.h @@ -246,7 +246,7 @@ struct dMpath_n { void remove(); ~dTexObjAggregate_c() { remove(); }; - GXTexObj* getTexObjPointer(int i_no) { + TGXTexObj* getTexObjPointer(int i_no) { JUT_ASSERT(44, i_no >= 0 && i_no < TEX_OBJ_NUMBER); return mp_texObj[i_no]; } @@ -257,7 +257,7 @@ struct dMpath_n { } } - /* 0x0 */ GXTexObj* mp_texObj[TEX_OBJ_NUMBER]; + /* 0x0 */ TGXTexObj* mp_texObj[TEX_OBJ_NUMBER]; }; static dTexObjAggregate_c m_texObjAgg; diff --git a/include/d/d_msg_class.h b/include/d/d_msg_class.h index d1478f6b43..8ebf3ff5b7 100644 --- a/include/d/d_msg_class.h +++ b/include/d/d_msg_class.h @@ -18,11 +18,11 @@ class JMSMesgEntry_c { public: - /* 0x0 */ u32 string_offset; + /* 0x0 */ BE(u32) string_offset; // Attributes - /* 0x04 */ u16 message_id; - /* 0x06 */ u16 event_label_id; + /* 0x04 */ BE(u16) message_id; + /* 0x06 */ BE(u16) event_label_id; /* 0x08 */ u8 se_speaker; /* 0x09 */ u8 fuki_kind; /* 0x0A */ u8 output_type; @@ -33,7 +33,7 @@ public: /* 0x0F */ u8 camera_id; /* 0x10 */ u8 base_anm_id; /* 0x11 */ u8 face_anm_id; - /* 0x12 */ u16 unk_0x12; + /* 0x12 */ BE(u16) unk_0x12; }; class JMSMesgInfo_c { diff --git a/include/d/d_msg_flow.h b/include/d/d_msg_flow.h index 98a5308385..cd9a7c4e5f 100644 --- a/include/d/d_msg_flow.h +++ b/include/d/d_msg_flow.h @@ -2,6 +2,7 @@ #define D_MSG_D_MSG_FLOW_H #include +#include "dusk/endian.h" enum { NODETYPE_MESSAGE_e = 1, @@ -22,23 +23,23 @@ struct msg_class; struct mesg_flow_node { /* 0x00 */ u8 type; /* 0x01 */ u8 field_0x1; - /* 0x02 */ u16 msg_index; - /* 0x04 */ u16 next_node_idx; - /* 0x06 */ u16 unk_0x6; + /* 0x02 */ BE(u16) msg_index; + /* 0x04 */ BE(u16) next_node_idx; + /* 0x06 */ BE(u16) unk_0x6; }; // Size: 0x8 struct mesg_flow_node_branch { /* 0x00 */ u8 type; /* 0x01 */ u8 field_0x1; - /* 0x02 */ u16 query_idx; - /* 0x04 */ u16 param; - /* 0x06 */ u16 next_node_idx; + /* 0x02 */ BE(u16) query_idx; + /* 0x04 */ BE(u16) param; + /* 0x06 */ BE(u16) next_node_idx; }; struct mesg_flow_node_event { /* 0x00 */ u8 type; /* 0x01 */ u8 event_idx; - /* 0x02 */ u16 next_node_idx; + /* 0x02 */ BE(u16) next_node_idx; /* 0x04 */ u8 params[4]; }; // Size: 0x8 @@ -197,8 +198,8 @@ private: }* mFlowNodeTBL; /* 0x10 */ u16 mNodeIdx; /* 0x12 */ u16 field_0x12; - /* 0x14 */ u16* mFlowIdxTBL; - /* 0x18 */ u16* field_0x18; + /* 0x14 */ BE(u16)* mFlowIdxTBL; + /* 0x18 */ BE(u16)* field_0x18; /* 0x1C */ u16 mFlow; /* 0x20 */ u32 mMsg; /* 0x24 */ u8 mSelectMessage; diff --git a/include/dusk/endian.h b/include/dusk/endian.h index 4ea973b9ff..0fec59411f 100644 --- a/include/dusk/endian.h +++ b/include/dusk/endian.h @@ -237,7 +237,6 @@ void be_swap(T (& val)[N]) { for (u32 i = 0; i < N; i++) { be_swap(val[i]); } - val = BE::swap(val); } template diff --git a/include/dusk/gx_helper.h b/include/dusk/gx_helper.h index b66aaf4e1a..adb547ac29 100644 --- a/include/dusk/gx_helper.h +++ b/include/dusk/gx_helper.h @@ -1,7 +1,10 @@ #ifndef DUSK_GX_HELPER_H #define DUSK_GX_HELPER_H +#include + #include +#include #define GX_DEBUG_GROUP(name, ...) \ do { \ @@ -10,4 +13,33 @@ GXPopDebugGroup(); \ } while (0) +#ifdef TARGET_PC +class GXTexObjRAII : public GXTexObj { +public: + GXTexObjRAII() : GXTexObj() {} + ~GXTexObjRAII() { GXDestroyTexObj(this); } + + void reset() { GXDestroyTexObj(this); } + + GXTexObjRAII(const GXTexObjRAII&) = delete; + GXTexObjRAII& operator=(const GXTexObjRAII&) = delete; + GXTexObjRAII(GXTexObjRAII&& o) = delete;/*noexcept : GXTexObj(o) { + std::memset(static_cast(&o), 0, sizeof(GXTexObj)); + }*/ + GXTexObjRAII& operator=(GXTexObjRAII&& o) = delete;/*noexcept { + if (this != &o) { + GXDestroyTexObj(this); + std::memcpy(static_cast(this), &o, sizeof(GXTexObj)); + std::memset(static_cast(&o), 0, sizeof(GXTexObj)); + } + return *this; + }*/ +}; +static_assert(sizeof(GXTexObjRAII) == sizeof(GXTexObj), + "GXTexObjRAII should have the same size as GXTexObj"); +typedef GXTexObjRAII TGXTexObj; +#else +typedef GXTexObj TGXTexObj; +#endif + #endif // DUSK_GX_HELPER_H diff --git a/include/dusk/logging.h b/include/dusk/logging.h index 7b52a54c1d..7f239d8b45 100644 --- a/include/dusk/logging.h +++ b/include/dusk/logging.h @@ -6,8 +6,23 @@ void aurora_log_callback(AuroraLogLevel level, const char* module, const char* message, unsigned int len); +namespace dusk { + void SendToStubLog(AuroraLogLevel level, const char* module, const char* message); +} + +extern bool StubLogEnabled; + extern aurora::Module DuskLog; #define STUB_LOG() DuskLog.debug("{} is a stub", __FUNCTION__) +#if TARGET_PC +#define STUB_RET(...) \ + STUB_LOG(); \ + return __VA_ARGS__; + +#else +#define STUB_RET() (void)0 +#endif + #endif diff --git a/include/dusk/map_loader_definitions.h b/include/dusk/map_loader_definitions.h new file mode 100644 index 0000000000..ae2a15a5c1 --- /dev/null +++ b/include/dusk/map_loader_definitions.h @@ -0,0 +1,179 @@ +#pragma once + +struct MapEntry { + static constexpr int MAX_ROOMS = 50; + + const char* mapName; + const char* mapFile; + u8 mapRooms[MAX_ROOMS] = {}; + int numRooms; + + constexpr MapEntry() : mapName(nullptr), mapFile(nullptr), numRooms(0) {} + constexpr MapEntry(const MapEntry& other) = default; + + template + constexpr MapEntry(const char* mapName, const char* mapFile, const int (&rooms)[N], const char*) : mapName(mapName), + mapFile(mapFile), numRooms(N) { + static_assert(N <= MAX_ROOMS); + for (int i = 0; i < N; i++) { + mapRooms[i] = rooms[i]; + } + } + + template + constexpr MapEntry(const char* mapName, const char* mapFile, const int (&rooms)[N]) : + mapName(mapName), mapFile(mapFile), numRooms(N) { + static_assert(N <= MAX_ROOMS); + for (int i = 0; i < N; i++) { + mapRooms[i] = rooms[i]; + } + } + + constexpr MapEntry(const char* mapName, const char* mapFile) : mapName(mapName), + mapFile(mapFile), numRooms(0) {} +}; + +struct RegionEntry { + static constexpr int MAX_MAPS = 22; + const char* regionName = nullptr; + int numMaps = 0; + MapEntry maps[MAX_MAPS] = {}; + + template + constexpr RegionEntry(const char* regionName, const MapEntry (&maps)[N]) : regionName(regionName), numMaps(N) { + static_assert(N <= MAX_MAPS); + for (int i = 0; i < N; i++) { + this->maps[i] = maps[i]; + } + } +}; + +constexpr auto gameRegions = std::to_array({ + RegionEntry("Hyrule Field", { + MapEntry("Hyrule Field", "F_SP121", {0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15}), + }), RegionEntry("Ordon", { + MapEntry("Ordon Village", "F_SP103"), + MapEntry("Outside Link's House", "F_SP103", {1}, "F_SP103_1"), + MapEntry("Ordon Ranch", "F_SP00"), + MapEntry("Ordon Spring", "F_SP104", {1}), + MapEntry("Bo's House", "R_SP01", {0}), + MapEntry("Sera's Sundries", "R_SP01", {1}, "R_SP01_1"), + MapEntry("Jaggle's House", "R_SP01", {2}, "R_SP01_2"), + MapEntry("Link's House", "R_SP01", {4, 7}, "R_SP01_4"), + MapEntry("Rusl's House", "R_SP01", {5}, "R_SP01_5"), + }), RegionEntry("Faron", { + MapEntry("South Faron Woods", "F_SP108", {0, 1, 2, 3, 4, 5, 8, 11, 14}), + MapEntry("North Faron Woods", "F_SP108", {6}, "F_SP108"), + MapEntry("Lost Woods", "F_SP117", {3}), + MapEntry("Sacred Grove", "F_SP117", {1}, "F_SP117_1"), + MapEntry("Temple of Time (Past)", "F_SP117", {2}, "F_SP117_2"), + MapEntry("Faron Woods Cave", "D_SB10"), + MapEntry("Coro's House", "R_SP108"), + }), RegionEntry("Eldin", { + MapEntry("Kakariko Village", "F_SP109"), + MapEntry("Death Mountain Trail", "F_SP110", {0, 1, 2, 3}), + MapEntry("Kakariko Graveyard", "F_SP111"), + MapEntry("Hidden Village", "F_SP128"), + MapEntry("Renado's Sanctuary", "R_SP109", {0}), + MapEntry("Sanctuary Basement", "R_SP209", {7}), + MapEntry("Barnes' Bombs", "R_SP109", {1}, "R_SP109_1"), + MapEntry("Elde Inn", "R_SP109", {2}, "R_SP109_2"), + MapEntry("Malo Mart", "R_SP109", {3}, "R_SP109_3"), + MapEntry("Lookout Tower", "R_SP109", {4}, "R_SP109_4"), + MapEntry("Bomb Warehouse", "R_SP109", {5}, "R_SP109_5"), + MapEntry("Abandoned House", "R_SP109", {6}, "R_SP109_6"), + MapEntry("Goron Elder's Hall", "R_SP110"), + }), RegionEntry("Lanayru", { + MapEntry("Outside Castle Town - West", "F_SP122", {8}), + MapEntry("Outside Castle Town - South", "F_SP122", {16}, "F_SP122_16"), + MapEntry("Outside Castle Town - East", "F_SP122", {17}, "F_SP122_17"), + MapEntry("Castle Town", "F_SP116", {0, 1, 2, 3, 4}), + MapEntry("Zora's River", "F_SP112", {1}), + MapEntry("Zora's Domain", "F_SP113", {0, 1}), + MapEntry("Lake Hylia", "F_SP115"), + MapEntry("Lanayru Spring", "F_SP115", {1}, "F_SP115_1"), + MapEntry("Upper Zora's River", "F_SP126", {0}), + MapEntry("Fishing Pond", "F_SP127", {0}), + MapEntry("Castle Town Sewers", "R_SP107", {0, 1, 2, 3}), + MapEntry("Telma's Bar / Secret Passage", "R_SP116", {5, 6}), + MapEntry("Hena's Cabin", "R_SP127", {0}), + MapEntry("Impaz's House", "R_SP128", {0}), + MapEntry("Malo Mart", "R_SP160", {0}), + MapEntry("Fanadi's Palace", "R_SP160", {1}, "R_SP160_1"), + MapEntry("Medical Clinic", "R_SP160", {2}, "R_SP160_2"), + MapEntry("Agitha's Castle", "R_SP160", {3}, "R_SP160_3"), + MapEntry("Goron Shop", "R_SP160", {4}, "R_SP160_4"), + MapEntry("Jovani's House", "R_SP160", {5}, "R_SP160_5"), + MapEntry("STAR Tent", "R_SP161", {7}), + }), RegionEntry("Gerudo Desert", { + MapEntry("Bulblin Camp", "F_SP118", {0, 1, 3}), + MapEntry("Bulblin Camp Beta Room", "F_SP118", {2}, "F_SP118_2"), + MapEntry("Gerudo Desert", "F_SP124", {0}), + MapEntry("Mirror Chamber", "F_SP125", {4}), + }), RegionEntry("Snowpeak", { + MapEntry("Snowpeak Mountain", "F_SP114", {0, 1, 2}), + }), RegionEntry("Forest Temple", { + MapEntry("Forest Temple", "D_MN05", {0, 1, 2, 3, 4, 5, 7, 9, 10, 11, 12, 19, 22}), + MapEntry("Diababa Arena", "D_MN05A", {50}), + MapEntry("Ook Arena", "D_MN05B", {51}), + }), RegionEntry("Goron Mines", { + MapEntry("Goron Mines", "D_MN04", {1, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 16, 17}), + MapEntry("Fyrus Arena", "D_MN04A", {50}), + MapEntry("Dangoro Arena", "D_MN04B", {51}), + }), RegionEntry("Lakebed Temple", { + MapEntry("Lakebed Temple", "D_MN01", {0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13}), + MapEntry("Morpheel Arena", "D_MN01A", {50}), + MapEntry("Deku Toad Arena", "D_MN01B", {51}), + }), RegionEntry("Arbiter's Grounds", { + MapEntry("Arbiter's Grounds", "D_MN10", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}), + MapEntry("Stallord Arena", "D_MN10A", {50}), + MapEntry("Death Sword Arena", "D_MN10B", {51}), + }), RegionEntry("Snowpeak Ruins", { + MapEntry("Snowpeak Ruins", "D_MN11", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13}), + MapEntry("Blizzeta Arena", "D_MN11A", {50}), + MapEntry("Darkhammer Arena", "D_MN11B", {51}), + MapEntry("Darkhammer Beta Arena", "D_MN11B", {49}), + }), RegionEntry("Temple of Time", { + MapEntry("Temple of Time", "D_MN06", {0, 1, 2, 3, 4, 5, 6, 7, 8}), + MapEntry("Armogohma Arena", "D_MN06A", {50}), + MapEntry("Darknut Arena", "D_MN06B", {51}), + }), RegionEntry("City in the Sky", { + MapEntry("City in the Sky", "D_MN07", {0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16}), + MapEntry("Argorok Arena", "D_MN07A", {50}), + MapEntry("Aeralfos Arena", "D_MN07B", {51}), + }), RegionEntry("Palace of Twilight", { + MapEntry("Palace of Twilight", "D_MN08", {0, 1, 2, 4, 5, 7, 8, 9, 10, 11}), + MapEntry("Palace of Twilight Throne Room", "D_MN08A", {10}), + MapEntry("Phantom Zant Arena 1", "D_MN08B", {51}), + MapEntry("Phantom Zant Arena 2", "D_MN08C", {52}), + MapEntry("Zant Arenas", "D_MN08D", {50, 53, 54, 55, 56, 57, 60}), + }), RegionEntry("Hyrule Castle", { + MapEntry("Hyrule Castle", "D_MN09", {1, 2, 3, 4, 5, 6, 8, 9, 11, 12, 13, 14, 15}), + MapEntry("Hyrule Castle Throne Room", "D_MN09A", {50, 51}), + MapEntry("Horseback Ganondorf Arena", "D_MN09B", {0}), + MapEntry("Dark Lord Ganondorf Arena", "D_MN09C", {0}), + }), RegionEntry("Mini-Dungeons and Grottos", { + MapEntry("Ice Cavern", "D_SB00", {0}), + MapEntry("Cave Of Ordeals", "D_SB01", + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49} + ), + MapEntry("Kakariko Gorge Cavern", "D_SB02", {0}), + MapEntry("Lake Hylia Cavern", "D_SB03", {0}), + MapEntry("Goron Stockcave", "D_SB04", {10}), + MapEntry("Grotto 1", "D_SB05"), + MapEntry("Grotto 2", "D_SB06", {1}), + MapEntry("Grotto 3", "D_SB07", {2}), + MapEntry("Grotto 4", "D_SB08", {3}), + MapEntry("Grotto 5", "D_SB09", {4}), + }), RegionEntry("Misc", { + MapEntry("Title Screen / King Bulblin 1", "F_SP102"), + MapEntry("King Bulblin 2", "F_SP123", {13}), + MapEntry("Wolf Howling Cutscene Map", "F_SP200"), + // MapEntry("Cutscene: Light Arrow Area", "R_SP300"), + MapEntry("Cutscene: Hyrule Castle Throne Room", "R_SP301"), + }) +}); \ No newline at end of file diff --git a/include/dusk/math.h b/include/dusk/math.h index 14c50db90a..fe27b3046b 100644 --- a/include/dusk/math.h +++ b/include/dusk/math.h @@ -2,6 +2,9 @@ #define _SRC_DUSK_MATH_H_ #include +#include +#include +#include #ifndef M_PI #define M_PI 3.14159265358979323846f @@ -16,4 +19,139 @@ inline float i_cosf(float x) { return cos(x); } inline float i_tanf(float x) { return tan(x); } inline float i_acosf(float x) { return acos(x); } + +// frsqrte matching courtesy of Geotale, with reference to https://achurch.org/cpu-tests/ppc750cl.s + +struct BaseAndDec32 { + uint32_t base; + int32_t dec; +}; + +struct BaseAndDec64 { + uint64_t base; + int64_t dec; +}; + +union c32 { + constexpr c32(const float p) { + f = p; + } + + constexpr c32(const uint32_t p) { + u = p; + } + + uint32_t u; + float f; +}; + +union c64 { + constexpr c64(const double p) { + f = p; + } + + constexpr c64(const uint64_t p) { + u = p; + } + + uint64_t u; + double f; +}; + +static constexpr uint64_t EXPONENT_SHIFT_F64 = 52; +static constexpr uint64_t MANTISSA_MASK_F64 = 0x000fffffffffffffULL; +static constexpr uint64_t EXPONENT_MASK_F64 = 0x7ff0000000000000ULL; +static constexpr uint64_t SIGN_MASK_F64 = 0x8000000000000000ULL; + +static constexpr std::array RSQRTE_TABLE = {{ + {0x69fa000000000ULL, -0x15a0000000LL}, + {0x5f2e000000000ULL, -0x13cc000000LL}, + {0x554a000000000ULL, -0x1234000000LL}, + {0x4c30000000000ULL, -0x10d4000000LL}, + {0x43c8000000000ULL, -0x0f9c000000LL}, + {0x3bfc000000000ULL, -0x0e88000000LL}, + {0x34b8000000000ULL, -0x0d94000000LL}, + {0x2df0000000000ULL, -0x0cb8000000LL}, + {0x2794000000000ULL, -0x0bf0000000LL}, + {0x219c000000000ULL, -0x0b40000000LL}, + {0x1bfc000000000ULL, -0x0aa0000000LL}, + {0x16ae000000000ULL, -0x0a0c000000LL}, + {0x11a8000000000ULL, -0x0984000000LL}, + {0x0ce6000000000ULL, -0x090c000000LL}, + {0x0862000000000ULL, -0x0898000000LL}, + {0x0416000000000ULL, -0x082c000000LL}, + {0xffe8000000000ULL, -0x1e90000000LL}, + {0xf0a4000000000ULL, -0x1c00000000LL}, + {0xe2a8000000000ULL, -0x19c0000000LL}, + {0xd5c8000000000ULL, -0x17c8000000LL}, + {0xc9e4000000000ULL, -0x1610000000LL}, + {0xbedc000000000ULL, -0x1490000000LL}, + {0xb498000000000ULL, -0x1330000000LL}, + {0xab00000000000ULL, -0x11f8000000LL}, + {0xa204000000000ULL, -0x10e8000000LL}, + {0x9994000000000ULL, -0x0fe8000000LL}, + {0x91a0000000000ULL, -0x0f08000000LL}, + {0x8a1c000000000ULL, -0x0e38000000LL}, + {0x8304000000000ULL, -0x0d78000000LL}, + {0x7c48000000000ULL, -0x0cc8000000LL}, + {0x75e4000000000ULL, -0x0c28000000LL}, + {0x6fd0000000000ULL, -0x0b98000000LL}, +}}; + +[[nodiscard]] static inline double frsqrte(const double val) { + c64 bits(val); + + uint64_t mantissa = bits.u & MANTISSA_MASK_F64; + int64_t exponent = bits.u & EXPONENT_MASK_F64; + bool sign = (bits.u & SIGN_MASK_F64) != 0; + + // Handle 0 case + if (mantissa == 0 && exponent == 0) { + return std::copysign(std::numeric_limits::infinity(), bits.f); + } + + // Handle NaN-like + if (exponent == EXPONENT_MASK_F64) { + if (mantissa == 0) { + return sign ? std::numeric_limits::quiet_NaN() : 0.0; + } + + return val; + } + + // Handle negative inputs + if (sign) { + return std::numeric_limits::quiet_NaN(); + } + + if (exponent == 0) { + // Shift so one bit goes to where the exponent would be, + // then clear that bit to mimic a not-subnormal number! + // Aka, if there are 12 leading zeroes, shift left once + uint32_t shift = std::countl_zero(mantissa) - static_cast(63 - EXPONENT_SHIFT_F64); + + mantissa <<= shift; + mantissa &= MANTISSA_MASK_F64; + // The shift is subtracted by 1 because denormals by default + // are offset by 1 (exponent 0 doesn't have implied 1 bit) + exponent -= static_cast(shift - 1) << EXPONENT_SHIFT_F64; + } + + // In reality this doesn't get the full exponent -- Only the least significant bit + // Only that's needed because square roots of higher exponent bits simply multiply the + // result by 2!! + uint32_t key = static_cast((static_cast(exponent) | mantissa) >> 37); + uint64_t new_exp = + (static_cast((0xbfcLL << EXPONENT_SHIFT_F64) - exponent) >> 1) & EXPONENT_MASK_F64; + + // Remove the bits relating to anything higher than the LSB of the exponent + const auto &entry = RSQRTE_TABLE[0x1f & (key >> 11)]; + + // The result is given by an estimate then an adjustment based on the original + // key that was computed + uint64_t new_mantissa = static_cast(entry.base + entry.dec * static_cast(key & 0x7ff)); + + return c64(new_exp | new_mantissa).f; +} + #endif // _SRC_DUSK_MATH_H_ diff --git a/include/dusk/time.h b/include/dusk/time.h new file mode 100644 index 0000000000..501875971b --- /dev/null +++ b/include/dusk/time.h @@ -0,0 +1,103 @@ +#ifndef DUSK_TIME_H +#define DUSK_TIME_H + +#include +#include +#include + +#ifdef _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#include +#endif + +#include "dusk/logging.h" + +constexpr auto DUSK_FRAME_PERIOD = std::chrono::duration_cast(std::chrono::duration(1001.0 / 30000.0)); + +class Limiter { + using delta_clock = std::chrono::high_resolution_clock; + using duration_t = std::chrono::nanoseconds; + +public: + void Reset() { m_oldTime = delta_clock::now(); } + + void Sleep(duration_t targetFrameTime) { + if (targetFrameTime.count() == 0) { + return; + } + + auto start = delta_clock::now(); + duration_t adjustedSleepTime = SleepTime(targetFrameTime); + if (adjustedSleepTime.count() > 0) { + NanoSleep(adjustedSleepTime); + duration_t overslept = TimeSince(start) - adjustedSleepTime; + if (overslept < duration_t{targetFrameTime}) { + m_overheadTimes[m_overheadTimeIdx] = overslept; + m_overheadTimeIdx = (m_overheadTimeIdx + 1) % m_overheadTimes.size(); + } + } + Reset(); + } + + duration_t SleepTime(duration_t targetFrameTime) { + const auto sleepTime = duration_t{targetFrameTime} - TimeSince(m_oldTime); + m_overhead = std::accumulate(m_overheadTimes.begin(), m_overheadTimes.end(), duration_t{}) / m_overheadTimes.size(); + if (sleepTime > m_overhead) { + return sleepTime - m_overhead; + } + return duration_t{0}; + } + +private: + delta_clock::time_point m_oldTime; + std::array m_overheadTimes{}; + size_t m_overheadTimeIdx = 0; + duration_t m_overhead = duration_t{0}; + + duration_t TimeSince(delta_clock::time_point start) { + return std::chrono::duration_cast(delta_clock::now() - start); + } + +#if _WIN32 + void NanoSleep(const duration_t duration) { + static bool initialized = false; + static double countPerNs; + static size_t numSleeps = 0; + + // QueryPerformanceFrequency's result is constant, but calling it occasionally + // appears to stabilize QueryPerformanceCounter. Without it, the game drifts + // from 60hz to 144hz. (Cursed, but I suspect it's NVIDIA/G-SYNC related) + if (!initialized || numSleeps++ % 1000 == 0) { + LARGE_INTEGER freq; + if (QueryPerformanceFrequency(&freq) == 0) { + DuskLog.warn("QueryPerformanceFrequency failed: {}", GetLastError()); + return; + } + countPerNs = static_cast(freq.QuadPart) / 1e9; + initialized = true; + numSleeps = 0; + } + + LARGE_INTEGER start, current; + QueryPerformanceCounter(&start); + LONGLONG ticksToWait = static_cast(duration.count() * countPerNs); + if (DWORD ms = std::chrono::duration_cast(duration).count(); ms > 1) { + ::Sleep(ms - 1); + } + do { + QueryPerformanceCounter(¤t); + _mm_pause(); // Yield CPU + } while (current.QuadPart - start.QuadPart < ticksToWait); + } +#else + void NanoSleep(const duration_t duration) { std::this_thread::sleep_for(duration); } +#endif +}; + +#endif diff --git a/include/m_Do/m_Do_controller_pad.h b/include/m_Do/m_Do_controller_pad.h index 48d5256ea2..6960a7da7d 100644 --- a/include/m_Do/m_Do_controller_pad.h +++ b/include/m_Do/m_Do_controller_pad.h @@ -46,6 +46,7 @@ public: static u32 getHoldZ(u32 pad) { return getHold(pad) & PAD_TRIGGER_Z; } static u32 getHoldY(u32 pad) { return getHold(pad) & PAD_BUTTON_Y; } static u32 getHoldX(u32 pad) { return getHold(pad) & PAD_BUTTON_X; } + static u32 getHoldStart(u32 pad) { return getHold(pad) & PAD_BUTTON_START; } static f32 getStickX(u32 pad) { return getCpadInfo(pad).mMainStickPosX; } static f32 getStickY(u32 pad) { return getCpadInfo(pad).mMainStickPosY; } static f32 getStickX3D(u32 pad) { return getCpadInfo(pad).mMainStickPosX; } diff --git a/include/m_Do/m_Do_ext.h b/include/m_Do/m_Do_ext.h index 5bcd2f3ac1..ed96e63276 100644 --- a/include/m_Do/m_Do_ext.h +++ b/include/m_Do/m_Do_ext.h @@ -582,7 +582,7 @@ public: f32* getSize(int i_idx) { return mpLines[i_idx].field_0x4; } private: - /* 0x08 */ GXTexObj mTextureObject; + /* 0x08 */ TGXTexObj mTextureObject; /* 0x28 */ GXColor mColor; /* 0x2C */ dKy_tevstr_c* mpTevStr; /* 0x30 */ u16 mNumLines; diff --git a/include/m_Do/m_Do_graphic.h b/include/m_Do/m_Do_graphic.h index 8a22484582..c30c28a517 100644 --- a/include/m_Do/m_Do_graphic.h +++ b/include/m_Do/m_Do_graphic.h @@ -237,8 +237,8 @@ public: static GXColor& getFadeColor() { return mFadeColor; } static GXColor& getBackColor() { return mBackColor; } static void endRender() { JFWDisplay::getManager()->endRender(); } - static GXTexObj* getZbufferTexObj() { return &mZbufferTexObj; } - static GXTexObj* getFrameBufferTexObj() { return &mFrameBufferTexObj; } + static TGXTexObj* getZbufferTexObj() { return &mZbufferTexObj; } + static TGXTexObj* getFrameBufferTexObj() { return &mFrameBufferTexObj; } static void setFrameRate(u16 i_rate) { JFWDisplay::getManager()->setFrameRate(i_rate); } static int getFrameBufferSize() { @@ -285,8 +285,8 @@ public: static void setWindowSize(AuroraWindowSize const& size); #endif - static GXTexObj mFrameBufferTexObj; - static GXTexObj mZbufferTexObj; + static TGXTexObj mFrameBufferTexObj; + static TGXTexObj mZbufferTexObj; static bloom_c m_bloom; static Mtx mBlureMtx; static GXColor mBackColor; @@ -331,7 +331,7 @@ public: static u8 mWideZoom; static ResTIMG* m_fullFrameBufferTimg; static void* m_fullFrameBufferTex; - static GXTexObj m_fullFrameBufferTexObj; + static TGXTexObj m_fullFrameBufferTexObj; static f32 m_aspect; static f32 m_scale; diff --git a/include/m_Do/m_Do_lib.h b/include/m_Do/m_Do_lib.h index c13288103e..afa4b26837 100644 --- a/include/m_Do/m_Do_lib.h +++ b/include/m_Do/m_Do_lib.h @@ -4,6 +4,8 @@ #include "JSystem/J3DU/J3DUClipper.h" #include +#include "dusk/gx_helper.h" + typedef struct Vec Vec; struct ResTIMG; @@ -37,7 +39,7 @@ struct mDoLib_clipper { }; void mDoLib_project(Vec* src, Vec* dst); -u32 mDoLib_setResTimgObj(ResTIMG const* res, GXTexObj* o_texObj, u32 tlut_name, +u32 mDoLib_setResTimgObj(ResTIMG const* res, TGXTexObj* o_texObj, u32 tlut_name, GXTlutObj* o_tlutObj); void mDoLib_pos2camera(Vec* src, Vec* dst); diff --git a/libs/JSystem/include/JSystem/J3DGraphBase/J3DStruct.h b/libs/JSystem/include/JSystem/J3DGraphBase/J3DStruct.h index 422cc0fcf6..d970e14048 100644 --- a/libs/JSystem/include/JSystem/J3DGraphBase/J3DStruct.h +++ b/libs/JSystem/include/JSystem/J3DGraphBase/J3DStruct.h @@ -90,7 +90,6 @@ struct J3DTexMtxInfo { /* 0x01 */ u8 mInfo; /* 0x02 */ u8 field_0x2; /* 0x03 */ u8 field_0x3; - // NOTE: big endian when loaded from file! /* 0x04 */ Vec mCenter; /* 0x10 */ J3DTextureSRTInfo mSRT; /* 0x24 */ Mtx44 mEffectMtx; diff --git a/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h b/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h index 5d5f96b813..e407db84b4 100644 --- a/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h +++ b/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h @@ -7,9 +7,11 @@ #include "global.h" #include +#include "dusk/gx_helper.h" + /** * @ingroup jsystem-j3d - * + * */ class J3DTexture { private: @@ -19,7 +21,7 @@ private: #if TARGET_PC GXTlutObj* mpTlutObj; - GXTexObj* mpTexObj; + TGXTexObj* mpTexObj; u8** mpImgDataPtr; u8** mpTlutDataPtr; #endif @@ -28,7 +30,7 @@ public: J3DTexture(u16 num, ResTIMG* res) : mNum(num), unk_0x2(0), mpRes(res) { J3D_ASSERT_NULLPTR(52, res != NULL || num == 0); #if TARGET_PC - mpTexObj = new GXTexObj[num]; + mpTexObj = new TGXTexObj[num]; mpTlutObj = new GXTlutObj[num]; mpImgDataPtr = new u8*[num]; mpTlutDataPtr = new u8*[num]; @@ -48,8 +50,6 @@ public: void addResTIMG(u16, ResTIMG const*); virtual ~J3DTexture(){ #if TARGET_PC - for (int i = 0; i < mNum; i++) - GXDestroyTexObj(&mpTexObj[i]); delete[] mpTexObj; delete[] mpTlutObj; delete[] mpImgDataPtr; diff --git a/libs/JSystem/include/JSystem/JGadget/binary.h b/libs/JSystem/include/JSystem/JGadget/binary.h index f395076c07..f93e548f88 100644 --- a/libs/JSystem/include/JSystem/JGadget/binary.h +++ b/libs/JSystem/include/JSystem/JGadget/binary.h @@ -3,6 +3,7 @@ #include "JSystem/JUtility/JUTAssert.h" #include "JSystem/JGadget/search.h" +#include "dusk/endian.h" namespace JGadget { namespace binary { @@ -60,7 +61,15 @@ struct TParse_header_block { template struct TParseValue_raw_ { typedef T ParseType; - static T parse(const void* data) { return (T)*(T*)data; } + static T parse(const void* data) { + T val = *(T*)data; +#ifdef TARGET_PC + if constexpr (sizeof(T) > 1) { + be_swap(val); + } +#endif + return val; + } }; template diff --git a/libs/JSystem/include/JSystem/JKernel/JKRHeap.h b/libs/JSystem/include/JSystem/JKernel/JKRHeap.h index 8530a376c5..db4d40b0a3 100644 --- a/libs/JSystem/include/JSystem/JKernel/JKRHeap.h +++ b/libs/JSystem/include/JSystem/JKernel/JKRHeap.h @@ -289,17 +289,17 @@ inline void jkrDelete(void* ptr) { } template -bool constexpr newArgsHasCustomAlignment(Args&&...) { +bool constexpr newArgsHasCustomAlignment() { return false; } -template<> -constexpr bool newArgsHasCustomAlignment(int&&) { +template +constexpr bool newArgsHasCustomAlignment() { return true; } -template<> -constexpr bool newArgsHasCustomAlignment(JKRHeap*&&, int&&) { +template +constexpr bool newArgsHasCustomAlignment() { return true; } @@ -308,7 +308,7 @@ T* jkrNewArray(size_t count, std::in_place_type_t, Args&&... args) { size_t allocSize = count * sizeof(T); if constexpr (!std::is_trivially_destructible()) { static_assert( - !newArgsHasCustomAlignment(args...), + !newArgsHasCustomAlignment(), "jkrNewArray cannot currently handle non-trivially-destructible array allocations with custom alignment"); allocSize += sizeof(size_t); diff --git a/libs/JSystem/include/JSystem/JMath/JMath.h b/libs/JSystem/include/JSystem/JMath/JMath.h index 04d3cd543a..5d0263d669 100644 --- a/libs/JSystem/include/JSystem/JMath/JMath.h +++ b/libs/JSystem/include/JSystem/JMath/JMath.h @@ -4,6 +4,8 @@ #include #include +#include "dusk/math.h" + typedef f32 Mtx33[3][3]; typedef f32 Mtx23[2][3]; typedef f32 (*Mtx3P)[3]; @@ -70,7 +72,11 @@ inline f32 JMAFastSqrt(__REGISTER const f32 input) { return input; } #else - return sqrt(input); + if (input > 0.0f) { + return frsqrte(input) * input; + } else { + return input; + } #endif } diff --git a/libs/JSystem/include/JSystem/JMessage/resource.h b/libs/JSystem/include/JSystem/JMessage/resource.h index 7c93347978..6e4acdd6a7 100644 --- a/libs/JSystem/include/JSystem/JMessage/resource.h +++ b/libs/JSystem/include/JSystem/JMessage/resource.h @@ -42,7 +42,7 @@ struct TResource { char* getMessageText_messageEntry(const void* pEntry) const { JUT_ASSERT(141, pEntry!=NULL); - return pMessageText_ + *(int*)pEntry; + return pMessageText_ + *(BE(s32)*)pEntry; } const char* getMessageText_messageIndex(u16 uMessageIndex) const { diff --git a/libs/JSystem/include/JSystem/JParticle/JPAEmitter.h b/libs/JSystem/include/JSystem/JParticle/JPAEmitter.h index 99013105e0..732591ae6c 100644 --- a/libs/JSystem/include/JSystem/JParticle/JPAEmitter.h +++ b/libs/JSystem/include/JSystem/JParticle/JPAEmitter.h @@ -252,7 +252,7 @@ public: /* 0xB0 */ JGeometry::TVec2 mGlobalPScl; /* 0xB8 */ GXColor mGlobalPrmClr; /* 0xBC */ GXColor mGlobalEnvClr; - /* 0xC0 */ s32 mpUserWork; + /* 0xC0 */ uintptr_t mpUserWork; /* 0xC4 */ JPARandom mRndm; /* 0xC8 */ JPAList mAlivePtclBase; /* 0xD4 */ JPAList mAlivePtclChld; diff --git a/libs/JSystem/include/JSystem/JUtility/JUTCacheFont.h b/libs/JSystem/include/JSystem/JUtility/JUTCacheFont.h index 9d09e3419f..2e089b7cc4 100644 --- a/libs/JSystem/include/JSystem/JUtility/JUTCacheFont.h +++ b/libs/JSystem/include/JSystem/JUtility/JUTCacheFont.h @@ -29,7 +29,7 @@ public: }; struct TCachePage : TGlyphCacheInfo { - /* 0x20 */ GXTexObj mTexObj; + /* 0x20 */ TGXTexObj mTexObj; /* 0x40 */ u8 mImage[]; }; // Size: 0x40 @@ -61,7 +61,7 @@ public: void setPagingType(EPagingType type) { mPagingType = type; } static u32 calcCacheSize(u32 param_0, int param_1) { return (ALIGN_NEXT(param_0, 0x20) + 0x40) * param_1; } - GXTexObj* getTexObj(void* buffer) const { return &((TCachePage*)buffer)->mTexObj; } + TGXTexObj* getTexObj(void* buffer) const { return &((TCachePage*)buffer)->mTexObj; } void delete_and_initialize() { deleteMemBlocks_CacheFont(); initialize_state(); } u32 getCachePage() const { diff --git a/libs/JSystem/include/JSystem/JUtility/JUTResFont.h b/libs/JSystem/include/JSystem/JUtility/JUTResFont.h index 65973b89ad..09d3303da0 100644 --- a/libs/JSystem/include/JSystem/JUtility/JUTResFont.h +++ b/libs/JSystem/include/JSystem/JUtility/JUTResFont.h @@ -2,6 +2,7 @@ #define JUTRESFONT_H #include "JSystem/JUtility/JUTFont.h" +#include "dusk/gx_helper.h" class JKRHeap; @@ -63,7 +64,7 @@ public: // some types uncertain, may need to be fixed /* 0x1C */ int mWidth; /* 0x20 */ int mHeight; - /* 0x24 */ GXTexObj mTexObj; + /* 0x24 */ TGXTexObj mTexObj; /* 0x44 */ int mTexPageIdx; /* 0x48 */ const ResFONT* mResFont; /* 0x4C */ ResFONT::INF1* mInf1Ptr; diff --git a/libs/JSystem/include/JSystem/JUtility/JUTTexture.h b/libs/JSystem/include/JSystem/JUtility/JUTTexture.h index 311f92a6b7..e0f1e15ff0 100644 --- a/libs/JSystem/include/JSystem/JUtility/JUTTexture.h +++ b/libs/JSystem/include/JSystem/JUtility/JUTTexture.h @@ -4,6 +4,7 @@ #include #include #include "dusk/endian.h" +#include "dusk/gx_helper.h" class JUTPalette; @@ -95,7 +96,7 @@ public: } private: - /* 0x00 */ GXTexObj mTexObj; + /* 0x00 */ TGXTexObj mTexObj; /* 0x20 */ const ResTIMG* mTexInfo; /* 0x24 */ void* mTexData; /* 0x28 */ JUTPalette* mEmbPalette; diff --git a/libs/JSystem/src/J2DGraph/J2DWindowEx.cpp b/libs/JSystem/src/J2DGraph/J2DWindowEx.cpp index 95d5f0dfeb..b8c4e5f79e 100644 --- a/libs/JSystem/src/J2DGraph/J2DWindowEx.cpp +++ b/libs/JSystem/src/J2DGraph/J2DWindowEx.cpp @@ -28,11 +28,11 @@ J2DWindowEx::J2DWindowEx(J2DPane* param_0, JSURandomInputStream* param_1, u32 pa mAnmVisibilityFull = NULL; mAnmVtxColor = NULL; s32 position = param_1->getPosition(); - int uStack_88[2]; + BE(int) uStack_88[2]; param_1->read(uStack_88, 8); mKind = uStack_88[0]; s32 iVar2 = param_1->getPosition(); - int auStack_90[2]; + BE(int) auStack_90[2]; param_1->peek(auStack_90, 8); makePaneExStream(param_0, param_1); param_1->seek(iVar2 + auStack_90[1], JSUStreamSeekFrom_SET); diff --git a/libs/JSystem/src/J3DGraphBase/J3DGD.cpp b/libs/JSystem/src/J3DGraphBase/J3DGD.cpp index f38159f937..eb89fc3b81 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DGD.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DGD.cpp @@ -350,11 +350,8 @@ void J3DGDSetTexImgAttr(GXTexMapID id, u16 width, u16 height, GXTexFmt format) { } void J3DGDSetTexImgPtr(GXTexMapID id, void* image_ptr) { -#if TARGET_PC - STUB_LOG(); -#else + STUB_RET(); J3DGDWriteBPCmd(BP_IMAGE_PTR(OSCachedToPhysical(image_ptr) >> 5, J3DGDTexImage3Ids[id])); -#endif } void J3DGDSetTexImgPtrRaw(GXTexMapID id, u32 image_ptr_raw) { @@ -372,10 +369,9 @@ void J3DGDLoadTlut(void* tlut_ptr, u32 tmem_addr, GXTlutSize size) { J3DGDWriteBPCmd(0xFEFFFF00); J3DGDWriteBPCmd(0xF000000); -#if TARGET_PC - STUB_LOG(); - return; -#endif + + STUB_RET(); + J3DGDWriteBPCmd(BP_LOAD_TLUT0(OSCachedToPhysical(tlut_ptr) >> 5, 0x64)); J3DGDWriteBPCmd(BP_LOAD_TLUT1((tmem_addr - 0x80000) >> 9, size, 0x65)); J3DGDWriteBPCmd(0xFEFFFF00); diff --git a/libs/JSystem/src/J3DGraphBase/J3DSys.cpp b/libs/JSystem/src/J3DGraphBase/J3DSys.cpp index b3add6420b..c34ba546f0 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DSys.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DSys.cpp @@ -1,9 +1,10 @@ #include "JSystem/JSystem.h" // IWYU pragma: keep +#include "JSystem/J3DGraphBase/J3DFifo.h" #include "JSystem/J3DGraphBase/J3DSys.h" #include "JSystem/J3DGraphBase/J3DTevs.h" #include "JSystem/J3DGraphBase/J3DTexture.h" -#include "JSystem/J3DGraphBase/J3DFifo.h" +#include "dusk/gx_helper.h" #include "global.h" J3DSys j3dSys; @@ -265,14 +266,14 @@ void J3DSys::reinitTransform() { void J3DSys::reinitTexture() { #if TARGET_PC - static GXTexObj texObj; + static TGXTexObj texObj; static bool initialized = false; if (!initialized) { GXInitTexObj(&texObj, NullTexData, 4, 4, GX_TF_IA8, GX_CLAMP, GX_CLAMP, GX_FALSE); initialized = true; } #else - GXTexObj texObj; + TGXTexObj texObj; GXInitTexObj(&texObj, NullTexData, 4, 4, GX_TF_IA8, GX_CLAMP, GX_CLAMP, GX_FALSE); #endif GXLoadTexObj(&texObj, GX_TEXMAP0); diff --git a/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp b/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp index fde7a537b3..a01e605abb 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp @@ -22,7 +22,7 @@ void J3DTexture::loadGX(u16 idx, GXTexMapID texMapID) const { } GXLoadTexObj(&mpTexObj[idx], texMapID); #else - GXTexObj texObj; + TGXTexObj texObj; GXTlutObj tlutObj; if (!timg->indexTexture) { @@ -54,7 +54,7 @@ void J3DTexture::loadGXTexObj(u16 idx) { ResTIMG* timg = getResTIMG(idx); GXTlutObj& tlutObj = mpTlutObj[idx]; - GXTexObj& texObj = mpTexObj[idx]; + TGXTexObj& texObj = mpTexObj[idx]; if (!timg->indexTexture) { GXInitTexObj(&texObj, mpImgDataPtr[idx], timg->width, timg->height, @@ -88,7 +88,7 @@ void J3DTexture::entryNum(u16 num) { delete[] mpTlutObj; delete[] mpImgDataPtr; delete[] mpTlutDataPtr; - mpTexObj = new GXTexObj[num](); + mpTexObj = new TGXTexObj[num](); mpTlutObj = new GXTlutObj[num](); mpImgDataPtr = new u8*[num](); mpTlutDataPtr = new u8*[num](); diff --git a/libs/JSystem/src/J3DGraphBase/J3DTransform.cpp b/libs/JSystem/src/J3DGraphBase/J3DTransform.cpp index de74086073..44e0711337 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DTransform.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DTransform.cpp @@ -22,7 +22,7 @@ void J3DGQRSetup7(u32 r0, u32 r1, u32 r2, u32 r3) { } // this uses a non-standard sqrtf, not sure why or how its supposed to be setup -#if !PLATFORM_SHIELD +#if !PLATFORM_SHIELD && !TARGET_PC inline f32 J3D_sqrtf(__REGISTER f32 x) { __REGISTER f32 recip; diff --git a/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp b/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp index b67b9b2527..f7f9d92338 100644 --- a/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp +++ b/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp @@ -545,6 +545,8 @@ J3DTexMtx* J3DMaterialFactory::newTexMtx(int i_idx, int i_no) const { be_swap(tex_mtx_info.mSRT.mRotation); be_swap(tex_mtx_info.mSRT.mTranslationX); be_swap(tex_mtx_info.mSRT.mTranslationY); + for (int i = 0; i < 16; i++) + be_swap(tex_mtx_info.mEffectMtx[i / 4][i % 4]); tex_mtx = JKR_NEW J3DTexMtx(tex_mtx_info); #else tex_mtx = JKR_NEW J3DTexMtx(mpTexMtxInfo[mtl_init_data->mTexMtxIdx[i_no]]); diff --git a/libs/JSystem/src/JAudio2/JAISeq.cpp b/libs/JSystem/src/JAudio2/JAISeq.cpp index 038ce5989c..e3d07d5418 100644 --- a/libs/JSystem/src/JAudio2/JAISeq.cpp +++ b/libs/JSystem/src/JAudio2/JAISeq.cpp @@ -108,7 +108,7 @@ bool JAISeq::prepare_getSeqData_() { switch (seqDataMgr->getSeqData(getID(), &inner_.mSeqData)) { case 0: - OS_REPORT("Failed In Loading Sequence Data:SEQ(0x%08x)\n", getID()); + OS_REPORT("Failed In Loading Sequence Data:SEQ(0x%08x)\n", (u32)getID()); status_.state.unk = 2; break; case 1: diff --git a/libs/JSystem/src/JFramework/JFWDisplay.cpp b/libs/JSystem/src/JFramework/JFWDisplay.cpp index 03a1afe94c..6812a81880 100644 --- a/libs/JSystem/src/JFramework/JFWDisplay.cpp +++ b/libs/JSystem/src/JFramework/JFWDisplay.cpp @@ -2,7 +2,9 @@ #include #include +#include #include +#include #include "JSystem/J2DGraph/J2DOrthoGraph.h" #include "JSystem/JFramework/JFWDisplay.h" #include "JSystem/JKernel/JKRHeap.h" @@ -10,13 +12,10 @@ #include "JSystem/JUtility/JUTConsole.h" #include "JSystem/JUtility/JUTDbPrint.h" #include "JSystem/JUtility/JUTProcBar.h" -#include -#include -#include "global.h" #include "aurora/aurora.h" -#include "global.h" -#include "JSystem/JKernel/JKRHeap.h" +#include "dusk/gx_helper.h" #include "dusk/logging.h" +#include "global.h" void JFWDisplay::ctor_subroutine(bool enableAlpha) { mEnableAlpha = enableAlpha; @@ -419,7 +418,7 @@ static u8 clear_z_TX[64] ATTRIBUTE_ALIGN(32) = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; -static GXTexObj clear_z_tobj; +static TGXTexObj clear_z_tobj; void JFWDisplay::clearEfb_init() { GXInitTexObj(&clear_z_tobj, &clear_z_TX, 4, 4, GX_TF_Z24X8, GX_REPEAT, GX_REPEAT, GX_FALSE); @@ -439,10 +438,8 @@ void JFWDisplay::clearEfb(GXColor color) { } void JFWDisplay::clearEfb(int param_0, int param_1, int param_2, int param_3, GXColor color) { -#if TARGET_PC - STUB_LOG(); - return; -#endif + STUB_RET(); + u16 width; u16 height; Mtx44 mtx; diff --git a/libs/JSystem/src/JKernel/JKRArchivePri.cpp b/libs/JSystem/src/JKernel/JKRArchivePri.cpp index dbb734d6ba..9da4c2d1aa 100644 --- a/libs/JSystem/src/JKernel/JKRArchivePri.cpp +++ b/libs/JSystem/src/JKernel/JKRArchivePri.cpp @@ -14,6 +14,9 @@ u32 JKRArchive::sCurrentDirID; JKRArchive::JKRArchive() { mIsMounted = false; mMountDirection = MOUNT_DIRECTION_HEAD; +#if TARGET_PC + mFileData = nullptr; +#endif } JKRArchive::JKRArchive(s32 entryNumber, JKRArchive::EMountMode mountMode) { @@ -21,6 +24,9 @@ JKRArchive::JKRArchive(s32 entryNumber, JKRArchive::EMountMode mountMode) { mMountMode = mountMode; mMountCount = 1; field_0x58 = 1; +#if TARGET_PC + mFileData = nullptr; +#endif mHeap = JKRHeap::findFromRoot(this); if (mHeap == NULL) { @@ -37,7 +43,7 @@ JKRArchive::JKRArchive(s32 entryNumber, JKRArchive::EMountMode mountMode) { JKRArchive::~JKRArchive() { #if TARGET_PC if (mFileData != nullptr) { - mHeap->free(mFileData); + JKRHeap::getSystemHeap()->free(mFileData); mFileData = nullptr; } #endif @@ -251,11 +257,12 @@ void JKRArchive::initFileDataPointers() { assert(mFiles); if (mFileData != nullptr) { - mHeap->free(mFileData); + JKRHeap::getSystemHeap()->free(mFileData); + mFileData = nullptr; } mFileData = static_cast( - mHeap->alloc(mArcInfoBlock->num_file_entries * sizeof(void*), alignof(void*))); + JKRHeap::getSystemHeap()->alloc(mArcInfoBlock->num_file_entries * sizeof(void*), alignof(void*))); memset(mFileData, 0, mArcInfoBlock->num_file_entries * sizeof(void*)); diff --git a/libs/JSystem/src/JMath/JMath.cpp b/libs/JSystem/src/JMath/JMath.cpp index 3fa3b9aa28..43b9680308 100644 --- a/libs/JSystem/src/JMath/JMath.cpp +++ b/libs/JSystem/src/JMath/JMath.cpp @@ -103,8 +103,6 @@ void JMAVECScaleAdd(__REGISTER const Vec* vec1, __REGISTER const Vec* vec2, __RE dst->y = vec1->y * scale + vec2->y; dst->z = vec1->z * scale + vec2->z; #endif // clang-format on - - OSPanic(__FILE__, __LINE__, "UNIMPLEMENTED"); } void JMAMTXApplyScale(__REGISTER const Mtx src, __REGISTER Mtx dst, __REGISTER f32 xScale, diff --git a/libs/JSystem/src/JMessage/resource.cpp b/libs/JSystem/src/JMessage/resource.cpp index 54c3a50730..4e48701c11 100644 --- a/libs/JSystem/src/JMessage/resource.cpp +++ b/libs/JSystem/src/JMessage/resource.cpp @@ -65,12 +65,12 @@ u16 JMessage::TResource::toMessageIndex_messageID(u32 uMsgID, u32 upperHalf, boo int nMsgNumber = oParse_TBlock_messageID_.get_number(); - const u32* pContent = (u32*)oParse_TBlock_messageID_.getContent(); + const BE(u32)* pContent = (const BE(u32)*)oParse_TBlock_messageID_.getContent(); JUT_ASSERT(131, pContent!=NULL); - const u32* pFirst = pContent; - const u32* pLast = pFirst + nMsgNumber; - const u32* pEntry; + const BE(u32)* pFirst = pContent; + const BE(u32)* pLast = pFirst + nMsgNumber; + const BE(u32)* pEntry; if (oParse_TBlock_messageID_.get_isOrdered()) { pEntry = std::lower_bound(pFirst, pLast, uMsgValue); diff --git a/libs/JSystem/src/JParticle/JPADynamicsBlock.cpp b/libs/JSystem/src/JParticle/JPADynamicsBlock.cpp index ee22259d89..26bf457193 100644 --- a/libs/JSystem/src/JParticle/JPADynamicsBlock.cpp +++ b/libs/JSystem/src/JParticle/JPADynamicsBlock.cpp @@ -66,8 +66,20 @@ static void JPAVolumeSphere(JPAEmitterWorkData* work) { s16 phi, r28; if (work->mpEmtr->checkFlag(JPADynFlag_FixedInterval)) { phi = u16(work->mVolumeX * 0x8000 / (work->mDivNumber - 1) + 0x4000); + + #if TARGET_PC + // Fix div by 0 error here + // TODO: maybe review a better way of handling div by 0 UB + r28 = 0x8000; + if (work->mVolumeAngleNum > 1) { + u16 r26 = u16(work->mVolumeAngleNum * 0x10000 / (work->mVolumeAngleMax - 1)); + r28 += f32(r26) * work->mVolumeSweep + 0x8000; + } + #else u16 r26 = u16(work->mVolumeAngleNum * 0x10000 / (work->mVolumeAngleMax - 1)); r28 = f32(r26) * work->mVolumeSweep + 0x8000; + #endif + work->mVolumeAngleNum++; if (work->mVolumeAngleNum == work->mVolumeAngleMax) { work->mVolumeAngleNum = 0; diff --git a/libs/JSystem/src/JParticle/JPAResource.cpp b/libs/JSystem/src/JParticle/JPAResource.cpp index ee4658998c..5c232a09f3 100644 --- a/libs/JSystem/src/JParticle/JPAResource.cpp +++ b/libs/JSystem/src/JParticle/JPAResource.cpp @@ -1,6 +1,10 @@ #include "JSystem/JSystem.h" // IWYU pragma: keep #include "JSystem/JParticle/JPAResource.h" + +#include + +#include #include "JSystem/JKernel/JKRHeap.h" #include "JSystem/JParticle/JPABaseShape.h" #include "JSystem/JParticle/JPAChildShape.h" @@ -11,7 +15,6 @@ #include "JSystem/JParticle/JPAKeyBlock.h" #include "JSystem/JParticle/JPAParticle.h" #include "JSystem/JParticle/JPAResourceManager.h" -#include #include "global.h" JPAResource::JPAResource() { @@ -937,7 +940,10 @@ void JPAResource::setPTev() { if (pEts->isUseIndirect()) { GXSetIndTexOrder(GX_INDTEXSTAGE0, tex_coord, GX_TEXMAP2); GXSetIndTexCoordScale(GX_INDTEXSTAGE0, GX_ITS_1, GX_ITS_1); - GXSetIndTexMtx(GX_ITM_0, (f32(*)[3])pEts->getIndTexMtx(), pEts->getExpScale()); + f32 indMtx[6]; + std::memcpy(indMtx, pEts->getIndTexMtx(), sizeof(indMtx)); + be_swap(indMtx); + GXSetIndTexMtx(GX_ITM_0, indMtx, pEts->getExpScale()); GXSetTevIndirect(GX_TEVSTAGE0, GX_INDTEXSTAGE0, GX_ITF_8, GX_ITB_STU, GX_ITM_0, GX_ITW_OFF, GX_ITW_OFF, 0, 0, GX_ITBA_OFF); ind_stages++; diff --git a/libs/JSystem/src/JStudio/JStudio/stb.cpp b/libs/JSystem/src/JStudio/JStudio/stb.cpp index 5bf857839b..7d52bfa273 100644 --- a/libs/JSystem/src/JStudio/JStudio/stb.cpp +++ b/libs/JSystem/src/JStudio/JStudio/stb.cpp @@ -261,17 +261,17 @@ void TObject::process_paragraph_reserved_(u32 arg1, const void* pContent, u32 uS case 0x1: ASSERT(pContent != NULL); ASSERT(uSize == 4); - setFlag_operation_(*(u32*)pContent); + setFlag_operation_(*(BE(u32)*)pContent); break; case 0x2: ASSERT(pContent != NULL); ASSERT(uSize == 4); - setWait(*(u32*)pContent); + setWait(*(BE(u32)*)pContent); break; case 0x3: { ASSERT(pContent != NULL); ASSERT(uSize == 4); - const void* seq = getSequence_offset(*(s32*)pContent); + const void* seq = getSequence_offset(*(BE(s32)*)pContent); setSequence_next(seq); break; } diff --git a/libs/JSystem/src/JStudio/JStudio_JAudio2/object-sound.cpp b/libs/JSystem/src/JStudio/JStudio_JAudio2/object-sound.cpp index 8b3c5ed9ac..e4ce109f09 100644 --- a/libs/JSystem/src/JStudio/JStudio_JAudio2/object-sound.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JAudio2/object-sound.cpp @@ -153,7 +153,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_SOUND(JStudio::data::TEOperatio case JStudio::data::UNK_0x19: JUT_ASSERT(283, pContent!=NULL); JUT_ASSERT(284, uSize==4); - field_0x124 = *(u32*)pContent; + field_0x124 = *(BE(u32)*)pContent; prepareSound_(); break; } @@ -175,7 +175,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_BEGIN_FADE_IN( case JStudio::data::UNK_0x2: JUT_ASSERT(323, pContent!=NULL); JUT_ASSERT(324, uSize==4); - beginSound_fadeIn_(*(f32*)pContent); + beginSound_fadeIn_(*(BE(f32)*)pContent); break; } } @@ -196,7 +196,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_END_FADE_OUT( case JStudio::data::UNK_0x2: JUT_ASSERT(364, pContent!=NULL); JUT_ASSERT(365, uSize==4); - endSound_fadeOut_(*(f32*)pContent); + endSound_fadeOut_(*(BE(f32)*)pContent); break; } } @@ -235,7 +235,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_PARENT_NODE(JStudio::data::TEOp case JStudio::data::UNK_0x19: JUT_ASSERT(447, uSize==4); JUT_ASSERT(448, pContent!=NULL); - field_0x140 = *(u32*)pContent; + field_0x140 = *(BE(u32)*)pContent; break; } } @@ -245,7 +245,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_PARENT_ENABLE( if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(468, uSize == 4); JUT_ASSERT(469, pContent != NULL); - field_0x144 = *(u32*)pContent ? 1 : 0; + field_0x144 = *(BE(u32)*)pContent ? 1 : 0; } } @@ -254,7 +254,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_REPEAT(JStudio::data::TEOperati if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(490, uSize == 4); JUT_ASSERT(491, pContent != NULL); - field_0x11e = *(u32*)pContent ? 1 : 0; + field_0x11e = *(BE(u32)*)pContent ? 1 : 0; } } @@ -263,7 +263,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_CONTINUOUS(JStudio::data::TEOpe if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(512, uSize == 4); JUT_ASSERT(513, pContent != NULL); - field_0x11d = *(u32*)pContent ? 1 : 0; + field_0x11d = *(BE(u32)*)pContent ? 1 : 0; } } @@ -272,7 +272,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_LOCATED(JStudio::data::TEOperat if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(534, pContent != NULL); JUT_ASSERT(535, uSize == 4); - u32 val = *(u32*)pContent; + u32 val = *(BE(u32)*)pContent; field_0x12c = NULL; if (val != 0) { field_0x12c = &field_0x130; @@ -285,7 +285,7 @@ void JStudio_JAudio2::TAdaptor_sound::adaptor_do_ON_EXIT_NOT_END( if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(512, uSize == 4); JUT_ASSERT(513, pContent != NULL); - field_0x11f = *(u32*)pContent ? 1 : 0; + field_0x11f = *(BE(u32)*)pContent ? 1 : 0; } } diff --git a/libs/JSystem/src/JStudio/JStudio_JParticle/object-particle.cpp b/libs/JSystem/src/JStudio/JStudio_JParticle/object-particle.cpp index 0346ccd812..f2193f42f0 100644 --- a/libs/JSystem/src/JStudio/JStudio_JParticle/object-particle.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JParticle/object-particle.cpp @@ -104,7 +104,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_PARTICLE( if (param_1 == JStudio::data::UNK_0x19) { JUT_ASSERT(232, uSize==4); JUT_ASSERT(233, pContent!=NULL); - field_0x1bc = *(u32*)pContent; + field_0x1bc = *(BE(u32)*)pContent; } } @@ -124,7 +124,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_BEGIN_FADE_IN( case JStudio::data::UNK_0x2: JUT_ASSERT(272, pContent!=NULL); JUT_ASSERT(273, uSize==4); - beginParticle_fadeIn_(*(f32*)pContent); + beginParticle_fadeIn_(*(BE(f32)*)pContent); break; } } @@ -143,7 +143,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_END_FADE_OUT( case JStudio::data::UNK_0x2: JUT_ASSERT(336, pContent!=NULL); JUT_ASSERT(337, uSize==4); - endParticle_fadeOut_(*(f32*)pContent); + endParticle_fadeOut_(*(BE(f32)*)pContent); break; } } @@ -182,7 +182,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_PARENT_NODE( case JStudio::data::UNK_0x19: JUT_ASSERT(397, uSize==4); JUT_ASSERT(396, pContent!=NULL); - field_0x1d4 = *(u32*)pContent; + field_0x1d4 = *(BE(u32)*)pContent; break; } } @@ -192,7 +192,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_PARENT_ENABLE(JStudio::dat if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(417, uSize==4); JUT_ASSERT(418, pContent!=NULL); - field_0x1d8 = *(u32*)pContent ? 1 : 0; + field_0x1d8 = *(BE(u32)*)pContent ? 1 : 0; } } @@ -201,7 +201,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_PARENT_FUNCTION(JStudio::d if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(439, uSize==4); JUT_ASSERT(439, pContent!=NULL); - field_0x1cc = *(u32*)pContent; + field_0x1cc = *(BE(u32)*)pContent; } } @@ -210,7 +210,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_REPEAT(JStudio::data::TEOp if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(460, uSize==4); JUT_ASSERT(461, pContent!=NULL); - field_0x1b5 = *(u32*)pContent ? 1 : 0; + field_0x1b5 = *(BE(u32)*)pContent ? 1 : 0; } } @@ -219,7 +219,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_ON_EXIT_NOT_END(JStudio::d if (param_1 == JStudio::data::UNK_0x2) { JUT_ASSERT(460, uSize==4); JUT_ASSERT(461, pContent!=NULL); - field_0x1b6 = *(u32*)pContent ? 1 : 0; + field_0x1b6 = *(BE(u32)*)pContent ? 1 : 0; } } diff --git a/libs/JSystem/src/JStudio/JStudio_JStage/object-actor.cpp b/libs/JSystem/src/JStudio/JStudio_JStage/object-actor.cpp index 1dc1919a3d..dc0c5c56e8 100644 --- a/libs/JSystem/src/JStudio/JStudio_JStage/object-actor.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JStage/object-actor.cpp @@ -98,7 +98,7 @@ void JStudio_JStage::TAdaptor_actor::adaptor_do_ANIMATION_MODE(JStudio::data::TE case JStudio::data::UNK_0x2: JUT_ASSERT(153, uSize==4); JUT_ASSERT(154, pContent!=NULL); - field_0x130 = *(u32*)pContent; + field_0x130 = *(BE(u32)*)pContent; break; } } @@ -114,7 +114,7 @@ void JStudio_JStage::TAdaptor_actor::adaptor_do_TEXTURE_ANIMATION_MODE( case JStudio::data::UNK_0x2: JUT_ASSERT(182, uSize==4); JUT_ASSERT(183, pContent!=NULL); - field_0x134 = *(u32*)pContent; + field_0x134 = *(BE(u32)*)pContent; break; } } @@ -141,7 +141,7 @@ void JStudio_JStage::TAdaptor_actor::adaptor_do_PARENT_NODE( case JStudio::data::UNK_0x19: JUT_ASSERT(237, uSize==4); JUT_ASSERT(238, pContent!=NULL); - field_0x140 = *(u32*)pContent; + field_0x140 = *(BE(u32)*)pContent; break; } } @@ -152,7 +152,7 @@ void JStudio_JStage::TAdaptor_actor::adaptor_do_PARENT_ENABLE( case JStudio::data::UNK_0x2: JUT_ASSERT(257, uSize==4); JUT_ASSERT(258, pContent!=NULL); - bool v0 = (*(u32*)pContent != 0); + bool v0 = (*(BE(u32)*)pContent != 0); if (field_0x144 != v0) { field_0x144 = v0; switch (field_0x138) { @@ -179,7 +179,7 @@ void JStudio_JStage::TAdaptor_actor::adaptor_do_PARENT_FUNCTION( case JStudio::data::UNK_0x2: JUT_ASSERT(303, uSize==4); JUT_ASSERT(304, pContent!=NULL); - field_0x138 = *(u32*)pContent; + field_0x138 = *(BE(u32)*)pContent; break; } } diff --git a/libs/JSystem/src/JStudio/JStudio_JStage/object-camera.cpp b/libs/JSystem/src/JStudio/JStudio_JStage/object-camera.cpp index 1a3a96b345..afa1fb8ab4 100644 --- a/libs/JSystem/src/JStudio/JStudio_JStage/object-camera.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JStage/object-camera.cpp @@ -99,7 +99,7 @@ void JStudio_JStage::TAdaptor_camera::adaptor_do_PARENT_NODE(JStudio::data::TEOp case JStudio::data::UNK_0x19: JUT_ASSERT(166, uSize==4); JUT_ASSERT(167, pContent!=NULL); - field_0x110 = *(int*)pContent; + field_0x110 = *(BE(s32)*)pContent; break; } } @@ -111,7 +111,7 @@ JStudio_JStage::TAdaptor_camera::adaptor_do_PARENT_ENABLE(JStudio::data::TEOpera case JStudio::data::UNK_0x2: JUT_ASSERT(185, uSize==4); JUT_ASSERT(186, pContent!=NULL); - field_0x114 = *(u32*)pContent ? true : false; + field_0x114 = *(BE(u32)*)pContent ? true : false; switch(field_0x108) { case 1: { JStage::TObject* parent = 0; @@ -137,7 +137,7 @@ JStudio_JStage::TAdaptor_camera::adaptor_do_PARENT_FUNCTION(JStudio::data::TEOpe case JStudio::data::UNK_0x2: JUT_ASSERT(226, uSize==4); JUT_ASSERT(227, pContent!=NULL); - field_0x108 = *(int*)pContent; + field_0x108 = *(BE(s32)*)pContent; break; } } @@ -164,7 +164,7 @@ void JStudio_JStage::TAdaptor_camera::adaptor_do_TARGET_PARENT_NODE( case JStudio::data::UNK_0x19: JUT_ASSERT(282, uSize==4); JUT_ASSERT(283, pContent!=NULL); - field_0x11c = *(int*)pContent; + field_0x11c = *(BE(s32)*)pContent; break; } } @@ -175,7 +175,7 @@ void JStudio_JStage::TAdaptor_camera::adaptor_do_TARGET_PARENT_ENABLE( case JStudio::data::UNK_0x2: JUT_ASSERT(301, uSize==4); JUT_ASSERT(302, pContent!=NULL); - field_0x120 = *(int*)pContent ? 1 : 0; + field_0x120 = *(BE(s32)*)pContent ? 1 : 0; break; } } diff --git a/libs/JSystem/src/JStudio/JStudio_JStage/object-light.cpp b/libs/JSystem/src/JStudio/JStudio_JStage/object-light.cpp index a50643a30f..19a02f09df 100644 --- a/libs/JSystem/src/JStudio/JStudio_JStage/object-light.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JStage/object-light.cpp @@ -125,7 +125,7 @@ void JStudio_JStage::TAdaptor_light::adaptor_do_FACULTY(JStudio::data::TEOperati JUT_ASSERT(198, uSize==4); JUT_ASSERT(199, pContent!=NULL); JStage::TELight lightType; - switch (*(u32*)pContent) { + switch (*(BE(u32)*)pContent) { case 0x301: lightType = JStage::TELIGHT_1; break; diff --git a/libs/JSystem/src/JStudio/JStudio_JStage/object.cpp b/libs/JSystem/src/JStudio/JStudio_JStage/object.cpp index 968b102f0d..4e1d795c25 100644 --- a/libs/JSystem/src/JStudio/JStudio_JStage/object.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JStage/object.cpp @@ -82,7 +82,7 @@ void JStudio_JStage::TAdaptor_object_::adaptor_object_data_(void const* param_1, if (param_2 == 0) { uVar3 = JStage::TActor::ID_NORMAL; } else { - uVar3 = *(int*)param_1; + uVar3 = *(BE(s32)*)param_1; } pJSGObject_->JSGSetData(uVar3, param_3, param_4); } @@ -113,7 +113,7 @@ JStudio_JStage::TAdaptor_object_::adaptor_object_ENABLE_(JStudio::data::TEOperat case JStudio::data::UNK_0x2: JUT_ASSERT(157, uSize==4); JUT_ASSERT(158, pContent!=NULL); - if (*(u32*)pContent != 0) { + if (*(BE(u32)*)pContent != 0) { pJSGObject_->JSGFEnableFlag(2); } else { pJSGObject_->JSGFDisableFlag(2); diff --git a/libs/JSystem/src/JUtility/JUTCacheFont.cpp b/libs/JSystem/src/JUtility/JUTCacheFont.cpp index 430557794e..614fdca6f1 100644 --- a/libs/JSystem/src/JUtility/JUTCacheFont.cpp +++ b/libs/JSystem/src/JUtility/JUTCacheFont.cpp @@ -431,6 +431,7 @@ void JUTCacheFont::invalidiateAllCache() { field_0xa4 = (TGlyphCacheInfo*)mCacheBuffer; field_0x9c = NULL; field_0xa0 = NULL; + // TARGET_PC TODO: we're leaking all GXTexObj here } void JUTCacheFont::unlink(JUTCacheFont::TGlyphCacheInfo* cacheInfo) { diff --git a/libs/JSystem/src/JUtility/JUTResFont.cpp b/libs/JSystem/src/JUtility/JUTResFont.cpp index 04add0774f..e6410defdc 100644 --- a/libs/JSystem/src/JUtility/JUTResFont.cpp +++ b/libs/JSystem/src/JUtility/JUTResFont.cpp @@ -417,6 +417,9 @@ void JUTResFont::loadImage(int code, GXTexMapID id){ if (pageIdx != mTexPageIdx || i != field_0x66) { void* pImg = &mpGlyphBlocks[i]->data[pageIdx * mpGlyphBlocks[i]->textureSize]; +#ifdef TARGET_PC + mTexObj.reset(); +#endif GXInitTexObj(&mTexObj, pImg, mpGlyphBlocks[i]->textureWidth, mpGlyphBlocks[i]->textureHeight, (GXTexFmt)(u16)mpGlyphBlocks[i]->textureFormat, GX_CLAMP, GX_CLAMP, 0); diff --git a/libs/JSystem/src/JUtility/JUTTexture.cpp b/libs/JSystem/src/JUtility/JUTTexture.cpp index 4021bf552c..e82ac6fd89 100644 --- a/libs/JSystem/src/JUtility/JUTTexture.cpp +++ b/libs/JSystem/src/JUtility/JUTTexture.cpp @@ -15,7 +15,6 @@ JUTTexture::~JUTTexture() { if (getEmbPaletteDelFlag()) { JKR_DELETE(mEmbPalette); } - GXDestroyTexObj(&mTexObj); } void JUTTexture::storeTIMG(ResTIMG const* param_0, u8 param_1) { @@ -50,7 +49,7 @@ void JUTTexture::storeTIMG(ResTIMG const* param_0, u8 param_1) { tlut = (GXTlut)param_1; } - u32 palOffset = mTexInfo->paletteOffset; + s32 palOffset = mTexInfo->paletteOffset; if (mEmbPalette == NULL || !getEmbPaletteDelFlag()) { mEmbPalette = JKR_NEW JUTPalette(tlut, (GXTlutFmt)mTexInfo->colorFormat, @@ -148,6 +147,9 @@ void JUTTexture::initTexObj() { u8* image = ((u8*)mTexInfo); u32 imgOffset = mTexInfo->imageOffset; image += (imgOffset ? imgOffset : 0x20); +#ifdef TARGET_PC + mTexObj.reset(); +#endif GXInitTexObj(&mTexObj, image, mTexInfo->width, mTexInfo->height, (GXTexFmt)mTexInfo->format, (GXTexWrapMode)mWrapS, (GXTexWrapMode)mWrapT, mipmapEnabled); @@ -165,6 +167,9 @@ void JUTTexture::initTexObj(GXTlut param_0) { (u16)mTexInfo->height, (void*)mTexInfo); image += (imgOffset ? imgOffset : 0x20); +#ifdef TARGET_PC + mTexObj.reset(); +#endif GXInitTexObjCI(&mTexObj, image, mTexInfo->width, mTexInfo->height, (GXCITexFmt)mTexInfo->format, (GXTexWrapMode)mWrapS, (GXTexWrapMode)mWrapT, mipmapEnabled, param_0); diff --git a/libs/dolphin/include/dolphin/card.h b/libs/dolphin/include/dolphin/card.h deleted file mode 100644 index 6ed175b71c..0000000000 --- a/libs/dolphin/include/dolphin/card.h +++ /dev/null @@ -1,322 +0,0 @@ -#ifndef _DOLPHIN_CARD_H_ -#define _DOLPHIN_CARD_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define CARD_FILENAME_MAX 32 -#define CARD_MAX_FILE 127 -#define CARD_ICON_MAX 8 - -typedef void (*CARDCallback)(s32 chan, s32 result); - -typedef struct CARDFileInfo { - s32 chan; - s32 fileNo; - s32 offset; - s32 length; - u16 iBlock; -} CARDFileInfo; - -typedef struct CARDDir { - u8 gameName[4]; - u8 company[2]; - u8 _padding0; - u8 bannerFormat; - u8 fileName[CARD_FILENAME_MAX]; - u32 time; // seconds since 01/01/2000 midnight - u32 iconAddr; // 0xffffffff if not used - u16 iconFormat; - u16 iconSpeed; - u8 permission; - u8 copyTimes; - u16 startBlock; - u16 length; - u8 _padding1[2]; - u32 commentAddr; // 0xffffffff if not used -} CARDDir; - -typedef struct CARDControl { - /* 0x000 */ BOOL attached; - /* 0x004 */ s32 result; - /* 0x008 */ u16 size; - /* 0x00A */ u16 pageSize; - /* 0x00C */ s32 sectorSize; - /* 0x010 */ u16 cBlock; - /* 0x012 */ u16 vendorID; - /* 0x014 */ s32 latency; - /* 0x018 */ u8 id[12]; - /* 0x024 */ int mountStep; - /* 0x028 */ int formatStep; - /* 0x028 */ u32 scramble; - /* 0x02C */ DSPTaskInfo task; - /* 0x080 */ void* workArea; - /* 0x084 */ CARDDir *currentDir; - /* 0x088 */ u16* currentFat; - /* 0x08C */ OSThreadQueue threadQueue; - /* 0x094 */ u8 cmd[9]; - /* 0x0A0 */ s32 cmdlen; - /* 0x0A4 */ volatile u32 mode; - /* 0x0A8 */ int retry; - /* 0x0AC */ int repeat; - /* 0x0B0 */ u32 addr; - /* 0x0B4 */ void* buffer; - /* 0x0B8 */ s32 xferred; - /* 0x0BC */ u16 freeNo; - /* 0x0BE */ u16 startBlock; - /* 0x0C0 */ CARDFileInfo* fileInfo; - /* 0x0C4 */ CARDCallback extCallback; - /* 0x0C8 */ CARDCallback txCallback; - /* 0x0CC */ CARDCallback exiCallback; - /* 0x0D0 */ CARDCallback apiCallback; - /* 0x0D4 */ CARDCallback xferCallback; - /* 0x0D8 */ CARDCallback eraseCallback; - /* 0x0DC */ CARDCallback unlockCallback; - /* 0x0E0 */ OSAlarm alarm; - /* 0x108 */ u32 cid; - /* 0x10C */ const DVDDiskID* diskID; -} CARDControl; - -typedef struct CARDDecParam { - /* 0x00 */ u8* inputAddr; - /* 0x04 */ u32 inputLength; - /* 0x08 */ u32 aramAddr; - /* 0x0C */ u8* outputAddr; -} CARDDecParam; - -typedef struct CARDID { - /* 0x000 */ u8 serial[32]; - /* 0x020 */ u16 deviceID; - /* 0x022 */ u16 size; - /* 0x024 */ u16 encode; - /* 0x026 */ u8 padding[470]; - /* 0x1FC */ u16 checkSum; - /* 0x1FE */ u16 checkSumInv; -} CARDID; - -typedef struct CARDDirCheck { - /* 0x00 */ u8 padding0[56]; - /* 0x38 */ u16 padding1; - /* 0x3A */ s16 checkCode; - /* 0x3C */ u16 checkSum; - /* 0x3E */ u16 checkSumInv; -} CARDDirCheck; - -typedef struct CARDStat { - /* 0x00 */ char fileName[CARD_FILENAME_MAX]; - /* 0x20 */ u32 length; - /* 0x24 */ u32 time; - /* 0x28 */ u8 gameName[4]; - /* 0x2C */ u8 company[2]; - /* 0x2E */ u8 bannerFormat; - /* 0x30 */ u32 iconAddr; - /* 0x34 */ u16 iconFormat; - /* 0x36 */ u16 iconSpeed; - /* 0x38 */ u32 commentAddr; - /* 0x3C */ u32 offsetBanner; - /* 0x40 */ u32 offsetBannerTlut; - /* 0x44 */ u32 offsetIcon[CARD_ICON_MAX]; - /* 0x64 */ u32 offsetIconTlut; - /* 0x68 */ u32 offsetData; -} CARDStat; - -#define CARD_ATTR_PUBLIC 0x04u -#define CARD_ATTR_NO_COPY 0x08u -#define CARD_ATTR_NO_MOVE 0x10u -#define CARD_ATTR_GLOBAL 0x20u -#define CARD_ATTR_COMPANY 0x40u - -#define CARD_FAT_AVAIL 0x0000u -#define CARD_FAT_CHECKSUM 0x0000u -#define CARD_FAT_CHECKSUMINV 0x0001u -#define CARD_FAT_CHECKCODE 0x0002u -#define CARD_FAT_FREEBLOCKS 0x0003u -#define CARD_FAT_LASTSLOT 0x0004u - -#define CARD_WORKAREA_SIZE (5 * 8 * 1024) - -#define CARD_SEG_SIZE 0x200u -#define CARD_PAGE_SIZE 0x80u -#define CARD_MAX_SIZE 0x01000000U - -#define CARD_NUM_SYSTEM_BLOCK 5 -#define CARD_SYSTEM_BLOCK_SIZE (8 * 1024u) - -#define CARD_MAX_MOUNT_STEP (CARD_NUM_SYSTEM_BLOCK + 2) - -#define CARD_STAT_SPEED_END 0 -#define CARD_STAT_SPEED_FAST 1 -#define CARD_STAT_SPEED_MIDDLE 2 -#define CARD_STAT_SPEED_SLOW 3 -#define CARD_STAT_SPEED_MASK 3 - -#define CARD_STAT_ANIM_LOOP 0 -#define CARD_STAT_ANIM_BOUNCE 4 -#define CARD_STAT_ANIM_MASK 0x4 - -#define CARD_RESULT_UNLOCKED 1 -#define CARD_RESULT_READY 0 -#define CARD_RESULT_BUSY -1 -#define CARD_RESULT_WRONGDEVICE -2 -#define CARD_RESULT_NOCARD -3 -#define CARD_RESULT_NOFILE -4 -#define CARD_RESULT_IOERROR -5 -#define CARD_RESULT_BROKEN -6 -#define CARD_RESULT_EXIST -7 -#define CARD_RESULT_NOENT -8 -#define CARD_RESULT_INSSPACE -9 -#define CARD_RESULT_NOPERM -10 -#define CARD_RESULT_LIMIT -11 -#define CARD_RESULT_NAMETOOLONG -12 -#define CARD_RESULT_ENCODING -13 -#define CARD_RESULT_CANCELED -14 -#define CARD_RESULT_FATAL_ERROR -128 - -#define CARDIsValidBlockNo(card, blockNo) ((blockNo) >= CARD_NUM_SYSTEM_BLOCK && (blockNo) < (card)->cBlock) - -#define CARD_READ_SIZE 512 -#define CARD_COMMENT_SIZE 64 - -#define CARD_ICON_WIDTH 32 -#define CARD_ICON_HEIGHT 32 - -#define CARD_BANNER_WIDTH 96 -#define CARD_BANNER_HEIGHT 32 - -#define CARD_STAT_ICON_NONE 0 -#define CARD_STAT_ICON_C8 1 -#define CARD_STAT_ICON_RGB5A3 2 -#define CARD_STAT_ICON_MASK 3 - -#define CARD_STAT_BANNER_NONE 0 -#define CARD_STAT_BANNER_C8 1 -#define CARD_STAT_BANNER_RGB5A3 2 -#define CARD_STAT_BANNER_MASK 3 - -#define CARD_ENCODE_ANSI 0 -#define CARD_ENCODE_SJIS 1 - -#define CARDGetDirCheck(dir) ((CARDDirCheck*)&(dir)[CARD_MAX_FILE]) -#define CARDGetBannerFormat(stat) (((stat)->bannerFormat) & CARD_STAT_BANNER_MASK) -#define CARDGetIconAnim(stat) (((stat)->bannerFormat) & CARD_STAT_ANIM_MASK) -#define CARDGetIconFormat(stat, n) (((stat)->iconFormat >> (2 * (n))) & CARD_STAT_ICON_MASK) -#define CARDGetIconSpeed(stat, n) (((stat)->iconSpeed >> (2 * (n))) & CARD_STAT_SPEED_MASK) -#define CARDSetBannerFormat(stat, f) \ - ((stat)->bannerFormat = (u8)(((stat)->bannerFormat & ~CARD_STAT_BANNER_MASK) | (f))) -#define CARDSetIconAnim(stat, f) \ - ((stat)->bannerFormat = (u8)(((stat)->bannerFormat & ~CARD_STAT_ANIM_MASK) | (f))) -#define CARDSetIconFormat(stat, n, f) \ - ((stat)->iconFormat = \ - (u16)(((stat)->iconFormat & ~(CARD_STAT_ICON_MASK << (2 * (n)))) | ((f) << (2 * (n))))) -#define CARDSetIconSpeed(stat, n, f) \ - ((stat)->iconSpeed = \ - (u16)(((stat)->iconSpeed & ~(CARD_STAT_SPEED_MASK << (2 * (n)))) | ((f) << (2 * (n))))) -#define CARDSetIconAddress(stat, addr) ((stat)->iconAddr = (u32)(addr)) -#define CARDSetCommentAddress(stat, addr) ((stat)->commentAddr = (u32)(addr)) -#define CARDGetFileNo(fileInfo) ((fileInfo)->fileNo) - -extern u32 __CARDFreq; - -#if DEBUG -#define CARDFreq __CARDFreq -#else -#define CARDFreq EXI_FREQ_16M -#endif - -void CARDInit(void); -s32 CARDGetResultCode(s32 chan); -s32 CARDCheckAsync(s32 chan, CARDCallback callback); -s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed); -s32 CARDRenameAsync(s32 chan, const char* oldName, const char* newName, CARDCallback callback); - -// CARDBios -void CARDInit(void); -s32 CARDGetResultCode(s32 chan); -s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed); -s32 CARDGetEncoding(s32 chan, u16* encode); -s32 CARDGetMemSize(s32 chan, u16* size); -s32 CARDGetSectorSize(s32 chan, u32* size); -const DVDDiskID* CARDGetDiskID(s32 chan); -s32 CARDSetDiskID(s32 chan, const DVDDiskID* diskID); -BOOL CARDSetFastMode(BOOL enable); -BOOL CARDGetFastMode(void); -s32 CARDGetCurrentMode(s32 chan, u32* mode); - -// CARDCheck -s32 CARDCheckExAsync(s32 chan, s32* xferBytes, CARDCallback callback); -s32 CARDCheckAsync(s32 chan, CARDCallback callback); -s32 CARDCheckEx(s32 chan, s32* xferBytes); -s32 CARDCheck(s32 chan); - -// CARDCreate -s32 CARDCreateAsync(s32 chan, const char* fileName, u32 size, CARDFileInfo* fileInfo, CARDCallback callback); -s32 CARDCreate(s32 chan, const char* fileName, u32 size, CARDFileInfo* fileInfo); - -// CARDDelete -s32 CARDFastDeleteAsync(s32 chan, s32 fileNo, CARDCallback callback); -s32 CARDFastDelete(s32 chan, s32 fileNo); -s32 CARDDeleteAsync(s32 chan, const char* fileName, CARDCallback callback); -s32 CARDDelete(s32 chan, const char* fileName); - -// CARDErase -s32 CARDEraseAsync(CARDFileInfo* fileInfo, s32 length, s32 offset, CARDCallback callback); -s32 CARDErase(CARDFileInfo* fileInfo, s32 length, s32 offset); - -// CARDFormat -s32 CARDFormat(s32 chan); - -// CARDMount -int CARDProbe(s32 chan); -s32 CARDProbeEx(s32 chan, s32* memSize, s32* sectorSize); -s32 CARDMountAsync(s32 chan, void* workArea, CARDCallback detachCallback, CARDCallback attachCallback); -s32 CARDMount(s32 chan, void* workArea, CARDCallback detachCallback); -s32 CARDUnmount(s32 chan); - -// CARDNet -u16 CARDSetVendorID(u16 vendorID); -u16 CARDGetVendorID(); -s32 CARDGetSerialNo(s32 chan, u64* serialNo); -s32 CARDGetUniqueCode(s32 chan, u64* uniqueCode); -s32 CARDGetAttributes(s32 chan, s32 fileNo, u8* attr); -s32 CARDSetAttributesAsync(s32 chan, s32 fileNo, u8 attr, CARDCallback callback); -s32 CARDSetAttributes(s32 chan, s32 fileNo, u8 attr); - -// CARDOpen -s32 CARDFastOpen(s32 chan, s32 fileNo, CARDFileInfo* fileInfo); -s32 CARDOpen(s32 chan, const char* fileName, CARDFileInfo* fileInfo); -s32 CARDClose(CARDFileInfo* fileInfo); - -// CARDProgram -s32 CARDProgramAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset, CARDCallback callback); -s32 CARDProgram(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset); - -// CARDRdwr -s32 CARDGetXferredBytes(s32 chan); - -// CARDRead -s32 CARDReadAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset, CARDCallback callback); -s32 CARDRead(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset); -s32 CARDCancel(CARDFileInfo* fileInfo); - -// CARDRename -s32 CARDRename(s32 chan, const char* oldName, const char* newName); - -// CARDStat -s32 CARDGetStatus(s32 chan, s32 fileNo, CARDStat* stat); -s32 CARDSetStatusAsync(s32 chan, s32 fileNo, CARDStat* stat, CARDCallback callback); -s32 CARDSetStatus(s32 chan, s32 fileNo, CARDStat* stat); - -// CARDWrite -s32 CARDWriteAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset, CARDCallback callback); -s32 CARDWrite(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/Z2AudioLib/Z2Creature.cpp b/src/Z2AudioLib/Z2Creature.cpp index 095e799381..3d18bfdda4 100644 --- a/src/Z2AudioLib/Z2Creature.cpp +++ b/src/Z2AudioLib/Z2Creature.cpp @@ -3,7 +3,7 @@ #include "Z2AudioLib/Z2Calc.h" #include "Z2AudioLib/Z2AudioMgr.h" #include "os_report.h" -#include "dusk/logging.h" +#include "dusk/audio.h" static void Z2_E_sw_modPitch(Z2SoundHandlePool*, u32); static void Z2_E_ms_modVol(Z2SoundHandlePool*, u32); @@ -139,10 +139,7 @@ void Z2Creature::setSoundStarter(Z2SoundStarter* soundStarter) { } void Z2Creature::initAnime(void* animation, bool param_1, f32 startFrame, f32 param_3) { -#if TARGET_PC - STUB_LOG(); - return; -#endif + DUSK_AUDIO_SKIP(); mSoundObjAnime.initAnime(animation, param_1, startFrame, param_3); } @@ -182,6 +179,8 @@ Z2SoundHandlePool* Z2Creature::startCreatureSound(JAISoundID soundID, u32 mapinf } Z2SoundHandlePool* Z2Creature::startCreatureSoundLevel(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + switch (soundID) { case Z2SE_FAIRY_S_LV: Z2GetAudioMgr()->seStartLevel(soundID, mpPos, 0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0); @@ -441,6 +440,8 @@ Z2SoundHandlePool* Z2CreatureEnemy::startCreatureSound(JAISoundID soundID, u32 m } Z2SoundHandlePool* Z2CreatureEnemy::startCreatureSoundLevel(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + if (soundID == 0x7FFFF) { Vec pos; Z2GetAudience()->convertAbsToRel(*mpPos, &pos, 0); @@ -924,6 +925,8 @@ void Z2CreatureOI::framework(u32 mapinfo, s8 reverb) { } Z2SoundHandlePool* Z2CreatureOI::startCreatureSoundLevel(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + if (soundID == Z2SE_EN_OI_MOVE) { Z2SoundHandlePool* handle1 = mSoundObjAnime.startLevelSound(soundID, mapinfo, reverb); Z2SoundHandlePool* handle2 = field_0xa4.startLevelSound(soundID, mapinfo, reverb); diff --git a/src/Z2AudioLib/Z2SeqMgr.cpp b/src/Z2AudioLib/Z2SeqMgr.cpp index da56da734e..643b3840c7 100644 --- a/src/Z2AudioLib/Z2SeqMgr.cpp +++ b/src/Z2AudioLib/Z2SeqMgr.cpp @@ -10,6 +10,8 @@ #include "JSystem/JAudio2/JAISeq.h" #include "os_report.h" +#include "dusk/audio.h" + static const char* sSpotName[] = { "F_SP00", "F_SP103", @@ -131,6 +133,8 @@ Z2SeqMgr::Z2SeqMgr() : JASGlobalInstance(true) { } void Z2SeqMgr::bgmStart(u32 bgmID, u32 fadeTime, s32 param_2) { + DUSK_AUDIO_SKIP(); + switch (bgmID) { case 0xFFFFFFFF: return; @@ -591,6 +595,8 @@ static void dummy1() { } void Z2SeqMgr::bgmStreamPrepare(u32 bgmID) { + DUSK_AUDIO_SKIP(); + u32 bgmID2 = bgmID; if (mStreamBgmHandle) { bgmStreamStop(0); @@ -648,6 +654,8 @@ bool Z2SeqMgr::bgmStreamCheckReady() { } void Z2SeqMgr::bgmStreamPlay() { + DUSK_AUDIO_SKIP(); + if (mStreamBgmHandle) { mStreamBgmHandle->unlockIfLocked(); } diff --git a/src/Z2AudioLib/Z2SoundMgr.cpp b/src/Z2AudioLib/Z2SoundMgr.cpp index bcba583ad4..b861475118 100644 --- a/src/Z2AudioLib/Z2SoundMgr.cpp +++ b/src/Z2AudioLib/Z2SoundMgr.cpp @@ -117,6 +117,8 @@ Z2SoundMgr::Z2SoundMgr() : } bool Z2SoundMgr::startSound(JAISoundID soundID, JAISoundHandle* handle, const JGeometry::TVec3* posPtr) { + DUSK_AUDIO_SKIP(true); + int soundType = Z2GetSoundInfo()->getSoundType(soundID); switch (soundType) { case 0: { @@ -180,8 +182,8 @@ bool Z2SoundMgr::startSound(JAISoundID soundID, JAISoundHandle* handle, const JG } return streamMgr_.startSound(soundID, handle, posPtr); default: - char error[32]; - sprintf(error, "Unknown Sound-Type id :%08x\n", *(u32*)&soundID); + char error[64]; + sprintf(error, "Unknown Sound-Type id :%08x\n", (u32)soundID); JUT_WARN(277, "%s", error); } diff --git a/src/Z2AudioLib/Z2SoundObject.cpp b/src/Z2AudioLib/Z2SoundObject.cpp index 5b6a768215..0978842251 100644 --- a/src/Z2AudioLib/Z2SoundObject.cpp +++ b/src/Z2AudioLib/Z2SoundObject.cpp @@ -9,6 +9,8 @@ #include "Z2AudioLib/Z2Audience.h" #include "JSystem/JAudio2/JAUSoundAnimator.h" +#include "dusk/audio.h" + #ifndef __MWERKS__ #include #define FLT_MAX std::numeric_limits::max() @@ -88,6 +90,8 @@ bool Z2SoundObjBase::stopOK(Z2SoundHandlePool& handlePool) { } Z2SoundHandlePool* Z2SoundObjBase::startSound(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + if (!alive_) { return NULL; } @@ -248,6 +252,8 @@ void Z2DopplerSoundObjBase::framework(u32 param_0, s8 reverb) { } Z2SoundHandlePool* Z2DopplerSoundObjBase::startSound(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + JGeometry::TVec3* pos = pos_; pos_ = NULL; @@ -263,6 +269,8 @@ Z2SoundHandlePool* Z2DopplerSoundObjBase::startSound(JAISoundID soundID, u32 map } Z2SoundHandlePool* Z2DopplerSoundObjBase::startLevelSound(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + JGeometry::TVec3* pos = pos_; pos_ = NULL; @@ -284,6 +292,8 @@ void Z2SoundObjSimple::init(Vec* posPtr, u8 handleNum) { } Z2SoundHandlePool* Z2SoundObjSimple::startSound(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + Z2SoundHandlePool* handle = Z2SoundObjBase::startSound(soundID, mapinfo, reverb); if (soundID == Z2SE_AL_UKI_POKOPOKO && handle != NULL && (*handle) != false) { @@ -297,6 +307,8 @@ Z2SoundHandlePool* Z2SoundObjSimple::startSound(JAISoundID soundID, u32 mapinfo, } Z2SoundHandlePool* Z2SoundObjSimple::startLevelSound(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + Z2SoundHandlePool* handle = Z2SoundObjBase::startLevelSound(soundID, mapinfo, reverb); if (handle != NULL && (*handle) != false) { diff --git a/src/d/actor/d_a_alink_effect.inc b/src/d/actor/d_a_alink_effect.inc index af214d6b41..133a615cc0 100644 --- a/src/d/actor/d_a_alink_effect.inc +++ b/src/d/actor/d_a_alink_effect.inc @@ -8,6 +8,7 @@ #include "d/actor/d_a_alink.h" #include "d/d_com_inf_game.h" #include "d/d_k_wmark.h" +#include "dusk/gx_helper.h" const EffParamProc daAlink_c::m_fEffParamProc[] = { &daAlink_c::setEffectFrontRollParam, @@ -2025,7 +2026,11 @@ void daAlink_blur_c::traceBlur(cXyz const* param_0, cXyz const* param_1, s16 par void daAlink_blur_c::draw() { j3dSys.reinitGX(); - static GXTexObj texObj; +#ifdef TARGET_PC + TGXTexObj texObj; +#else + static TGXTexObj texObj; +#endif static GXColor nColor0 = {0xFF, 0xFF, 0xFF, 0x14}; GXSetNumIndStages(0); diff --git a/src/d/actor/d_a_e_bg.cpp b/src/d/actor/d_a_e_bg.cpp index c25d74f423..a9bfcd0272 100644 --- a/src/d/actor/d_a_e_bg.cpp +++ b/src/d/actor/d_a_e_bg.cpp @@ -134,7 +134,7 @@ int daE_BG_c::draw() { cXyz offsetPos; offsetPos.set(current.pos.x, current.pos.y + 100.0f, current.pos.z); - GXTexObj* texObj = dDlst_shadowControl_c::getSimpleTex(); + TGXTexObj* texObj = dDlst_shadowControl_c::getSimpleTex(); mShadowKey = dComIfGd_setShadow(mShadowKey, 0x01, model, &offsetPos, 200.0f, 0.0f, current.pos.y, mObjAcch.GetGroundH(), mObjAcch.m_gnd, &tevStr, 0, 1.0f, texObj); diff --git a/src/d/actor/d_a_e_rd.cpp b/src/d/actor/d_a_e_rd.cpp index 055f2fad7f..54dec13127 100644 --- a/src/d/actor/d_a_e_rd.cpp +++ b/src/d/actor/d_a_e_rd.cpp @@ -6581,6 +6581,12 @@ static int daE_RD_Execute(e_rd_class* i_this) { for (int i = 0; i < 2; i++) { MtxPush(); s16 x, y; + + #if AVOID_UB + x = 0; + y = 0; + #endif + if (i == 0) { mae.set(38.0f, 0.0f, 0.0f); MtxPosition(&mae, &ato); diff --git a/src/d/actor/d_a_e_sb.cpp b/src/d/actor/d_a_e_sb.cpp index 9910cd9848..317d11e161 100644 --- a/src/d/actor/d_a_e_sb.cpp +++ b/src/d/actor/d_a_e_sb.cpp @@ -1048,7 +1048,7 @@ int daE_SB_c::Draw() { mpMorf->entryDL(); cXyz my_vec; my_vec.set(current.pos.x, 100.0f + current.pos.y, current.pos.z); - GXTexObj* tex_obj = dDlst_shadowControl_c::getSimpleTex(); + TGXTexObj* tex_obj = dDlst_shadowControl_c::getSimpleTex(); mShadowKey = dComIfGd_setShadow(mShadowKey, 1, model, &my_vec, 1000.0f, 300.0f, current.pos.y, mAcch.GetGroundH(), mAcch.m_gnd, &tevStr, 0, 1.0f, tex_obj); diff --git a/src/d/actor/d_a_e_sg.cpp b/src/d/actor/d_a_e_sg.cpp index 38cb8ce1ae..8581638454 100644 --- a/src/d/actor/d_a_e_sg.cpp +++ b/src/d/actor/d_a_e_sg.cpp @@ -93,7 +93,7 @@ static int daE_SG_Draw(e_sg_class* i_this) { cXyz shadow_pos(i_this->current.pos.x, i_this->current.pos.y + 100.0f, i_this->current.pos.z); - GXTexObj* tex_obj = dDlst_shadowControl_c::getSimpleTex(); + TGXTexObj* tex_obj = dDlst_shadowControl_c::getSimpleTex(); i_this->mShadowKey = dComIfGd_setShadow(i_this->mShadowKey, 1, i_this->mpModel, &shadow_pos, 400.0f, 0.0f, diff --git a/src/d/actor/d_a_formation_mng.cpp b/src/d/actor/d_a_formation_mng.cpp index c54f3d178e..7e96c6c169 100644 --- a/src/d/actor/d_a_formation_mng.cpp +++ b/src/d/actor/d_a_formation_mng.cpp @@ -320,8 +320,8 @@ void daFmtMng_c::executeFight() { } } -static bool daFmtMng_Draw(daFmtMng_c* param_0) { - return true; +static BOOL daFmtMng_Draw(daFmtMng_c* param_0) { + return TRUE; } static int daFmtMng_Execute(daFmtMng_c* param_0) { diff --git a/src/d/actor/d_a_kytag12.cpp b/src/d/actor/d_a_kytag12.cpp index b19ee7a35a..062828d5dc 100644 --- a/src/d/actor/d_a_kytag12.cpp +++ b/src/d/actor/d_a_kytag12.cpp @@ -82,6 +82,10 @@ static int daKytag12_Execute_standard(kytag12_class* i_this) { f32 var_f29; f32 var_f28; + #if AVOID_UB + var_f30 = 0; + #endif + int var_r24 = 0; int var_r23 = 0; int var_r22 = 0; diff --git a/src/d/actor/d_a_mant.cpp b/src/d/actor/d_a_mant.cpp index 9afc797b77..4388b52c84 100644 --- a/src/d/actor/d_a_mant.cpp +++ b/src/d/actor/d_a_mant.cpp @@ -298,7 +298,7 @@ void daMant_packet_c::draw() { GXTlutObj GStack_80; GXInitTlutObj(&GStack_80, lut, GX_TL_RGB5A3, 0x100); - GXTexObj GStack_74; + TGXTexObj GStack_74; GXInitTexObjCI(&GStack_74, image, 0x80, 0x80, GX_TF_C8, GX_CLAMP, GX_CLAMP, 0, 0); GXInitTexObjLOD(&GStack_74, GX_LINEAR, GX_LINEAR, 0.0, 0.0, 0.0, 0, 0, GX_ANISO_1); @@ -314,6 +314,9 @@ void daMant_packet_c::draw() { GXLoadNrmMtxImm(MStack_54, GX_PNMTX0); GXCallDisplayList(l_Egnd_mantDL, 0x3e0); +#ifdef TARGET_PC + GStack_74.reset(); +#endif GXInitTexObjCI(&GStack_74, l_Egnd_mantTEX_U, 0x80, 0x80, GX_TF_C8, GX_CLAMP, GX_CLAMP, 0, 0); GXInitTexObjLOD(&GStack_74, GX_LINEAR, GX_LINEAR, 0.0, 0.0, 0.0, 0, 0, GX_ANISO_1); GXLoadTexObj(&GStack_74, GX_TEXMAP0); diff --git a/src/d/actor/d_a_movie_player.cpp b/src/d/actor/d_a_movie_player.cpp index 0a548f74d5..3e14df69bb 100644 --- a/src/d/actor/d_a_movie_player.cpp +++ b/src/d/actor/d_a_movie_player.cpp @@ -22,6 +22,8 @@ #include "f_op/f_op_overlap_mng.h" #include +#include "dusk/gx_helper.h" + inline s32 daMP_NEXT_READ_SIZE(daMP_THPReadBuffer* readBuf) { return *(s32*)readBuf->ptr; } @@ -3155,9 +3157,9 @@ static void daMP_THPGXYuv2RgbSetup(const GXRenderModeObj* rmode) { static void daMP_THPGXYuv2RgbDraw(u8* y_data, u8* u_data, u8* v_data, s16 x, s16 y, s16 textureWidth, s16 textureHeight, s16 polygonWidth, s16 polygonHeight) { - GXTexObj tobj0; - GXTexObj tobj1; - GXTexObj tobj2; + TGXTexObj tobj0; + TGXTexObj tobj1; + TGXTexObj tobj2; GXInitTexObj(&tobj0, y_data, textureWidth, textureHeight, GX_TF_I8, GX_CLAMP, GX_CLAMP, GX_FALSE); GXInitTexObjLOD(&tobj0, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1); diff --git a/src/d/actor/d_a_npc_mk.cpp b/src/d/actor/d_a_npc_mk.cpp index 1f28e74e2f..6ba3d54341 100644 --- a/src/d/actor/d_a_npc_mk.cpp +++ b/src/d/actor/d_a_npc_mk.cpp @@ -7,20 +7,20 @@ #include "d/actor/d_a_npc_mk.h" -static bool daNpc_Mk_Create(void* param_0) { - return true; +static BOOL daNpc_Mk_Create(void* param_0) { + return TRUE; } -static bool daNpc_Mk_Delete(void* param_0) { - return true; +static BOOL daNpc_Mk_Delete(void* param_0) { + return TRUE; } -static bool daNpc_Mk_Execute(void* param_0) { - return true; +static BOOL daNpc_Mk_Execute(void* param_0) { + return TRUE; } -static bool daNpc_Mk_Draw(void* param_0) { - return true; +static BOOL daNpc_Mk_Draw(void* param_0) { + return TRUE; } static BOOL daNpc_Mk_IsDelete(void* param_0) { diff --git a/src/d/actor/d_a_npc_p2.cpp b/src/d/actor/d_a_npc_p2.cpp index a3f34d789f..befb665c12 100644 --- a/src/d/actor/d_a_npc_p2.cpp +++ b/src/d/actor/d_a_npc_p2.cpp @@ -7,20 +7,20 @@ #include "d/actor/d_a_npc_p2.h" -static bool daNpc_P2Create(void* param_0) { - return true; +static BOOL daNpc_P2Create(void* param_0) { + return TRUE; } -static bool daNpc_P2Delete(void* param_0) { - return true; +static BOOL daNpc_P2Delete(void* param_0) { + return TRUE; } -static bool daNpc_P2Execute(void* param_0) { - return true; +static BOOL daNpc_P2Execute(void* param_0) { + return TRUE; } -static bool daNpc_P2Draw(void* param_0) { - return true; +static BOOL daNpc_P2Draw(void* param_0) { + return TRUE; } static BOOL daNpc_P2IsDelete(void* param_0) { diff --git a/src/d/actor/d_a_npc_shop_maro.cpp b/src/d/actor/d_a_npc_shop_maro.cpp index 54c4eb882e..4ca52f1cb8 100644 --- a/src/d/actor/d_a_npc_shop_maro.cpp +++ b/src/d/actor/d_a_npc_shop_maro.cpp @@ -16,12 +16,12 @@ static int daNpc_shopMaro_Delete(void* i_this) { return 1; } -static bool daNpc_shopMaro_Execute(void* i_this) { - return false; +static BOOL daNpc_shopMaro_Execute(void* i_this) { + return FALSE; } -static bool daNpc_shopMaro_Draw(void* i_this) { - return false; +static BOOL daNpc_shopMaro_Draw(void* i_this) { + return FALSE; } static BOOL daNpc_shopMaro_IsDelete(void* i_this) { diff --git a/src/d/actor/d_a_npc_sola.cpp b/src/d/actor/d_a_npc_sola.cpp index 5e9c19d8cc..e705e2d2a0 100644 --- a/src/d/actor/d_a_npc_sola.cpp +++ b/src/d/actor/d_a_npc_sola.cpp @@ -485,8 +485,8 @@ static void daNpc_solA_Draw(void* param_0) { return static_cast(param_0)->Draw(); } -static bool daNpc_solA_IsDelete(void* param_0) { - return true; +static BOOL daNpc_solA_IsDelete(void* param_0) { + return TRUE; } static actor_method_class daNpc_solA_MethodTable = { diff --git a/src/d/actor/d_a_obj_brg.cpp b/src/d/actor/d_a_obj_brg.cpp index cfcaab1335..c8dd741ca9 100644 --- a/src/d/actor/d_a_obj_brg.cpp +++ b/src/d/actor/d_a_obj_brg.cpp @@ -1338,7 +1338,7 @@ static int daObj_Brg_Execute(obj_brg_class* i_this) { i_this->mpBgW->CopyBackVtx(); - Vec* vtx_tbl = (Vec*)i_this->mpBgW->GetVtxTbl(); + BE(Vec)* vtx_tbl = (BE(Vec)*)i_this->mpBgW->GetVtxTbl(); int dbg_0x30; int temp; @@ -1622,7 +1622,7 @@ static int CallbackCreateHeap(fopAc_ac_c* i_this) { a_this->mpBgW->SetRideCallback(ride_call_back); a_this->mpBgW->CopyBackVtx(); - Vec* vtx_tbl = (Vec*)a_this->mpBgW->GetVtxTbl(); + BE(Vec)* vtx_tbl = (BE(Vec)*)a_this->mpBgW->GetVtxTbl(); for (int i = 0; i < a_this->mpBgW->GetVtxNum(); i++) { vtx_tbl[i] = i_this->current.pos; } diff --git a/src/d/actor/d_a_obj_flag.cpp b/src/d/actor/d_a_obj_flag.cpp index 9e2e11bdaf..b929854067 100644 --- a/src/d/actor/d_a_obj_flag.cpp +++ b/src/d/actor/d_a_obj_flag.cpp @@ -259,8 +259,8 @@ static int daObjFlag_Execute(daObjFlag_c* param_0) { return param_0->execute(); } -static bool daObjFlag_IsDelete(daObjFlag_c* param_0) { - return true; +static BOOL daObjFlag_IsDelete(daObjFlag_c* param_0) { + return TRUE; } static int daObjFlag_Delete(daObjFlag_c* param_0) { diff --git a/src/d/actor/d_a_obj_kbacket.cpp b/src/d/actor/d_a_obj_kbacket.cpp index 5168288b3c..f8ab3e8f37 100644 --- a/src/d/actor/d_a_obj_kbacket.cpp +++ b/src/d/actor/d_a_obj_kbacket.cpp @@ -530,7 +530,7 @@ int daObj_KBacket_c::Draw() { } else { cM3dGPla plane; if (dComIfG_Bgsp().GetTriPla(mGndChk, &plane) != 0) { - GXTexObj* p_Var4 = dDlst_shadowControl_c::getSimpleTex(); + TGXTexObj* p_Var4 = dDlst_shadowControl_c::getSimpleTex(); dComIfGd_setSimpleShadow(¤t.pos, field_0xa00, 50.0f, &plane.mNormal, 0, 1.0f, p_Var4); } diff --git a/src/d/actor/d_a_obj_stone.cpp b/src/d/actor/d_a_obj_stone.cpp index 1d7c35e86d..7c67edea15 100644 --- a/src/d/actor/d_a_obj_stone.cpp +++ b/src/d/actor/d_a_obj_stone.cpp @@ -980,7 +980,7 @@ int daObjStone_c::draw() { if (!model) { f32 shadow_size = l_shadow_size[mStoneType]; - GXTexObj* pTex = dDlst_shadowControl_c::getSimpleTex(); + TGXTexObj* pTex = dDlst_shadowControl_c::getSimpleTex(); cXyz pos = current.pos; dComIfGd_setSimpleShadow(&pos, mChkObj.GetGroundH(), shadow_size, mChkObj.m_gnd, 0, diff --git a/src/d/actor/d_a_player.cpp b/src/d/actor/d_a_player.cpp index b90c35a58f..7790ba93b7 100644 --- a/src/d/actor/d_a_player.cpp +++ b/src/d/actor/d_a_player.cpp @@ -366,7 +366,7 @@ JKRHeap* daPy_anmHeap_c::setAnimeHeap() { #include "assets/l_sightDL__d_a_player.h" void daPy_sightPacket_c::draw() { - GXTexObj texObj; + TGXTexObj texObj; j3dSys.reinitGX(); GXSetNumIndStages(0); diff --git a/src/d/d_camera.cpp b/src/d/d_camera.cpp index 5a9e79f71c..c177b7bad2 100644 --- a/src/d/d_camera.cpp +++ b/src/d/d_camera.cpp @@ -1017,6 +1017,10 @@ void dCamera_c::debugDrawInit() { } bool dCamera_c::Run() { +#if TARGET_PC + ResetView(); +#endif + daAlink_c* link = daAlink_getAlinkActorClass(); daMidna_c* midna = daPy_py_c::getMidnaActor(); mMidnaRidingAndVisible = link->checkMidnaRide() && !midna->checkNoDraw(); diff --git a/src/d/d_com_inf_game.cpp b/src/d/d_com_inf_game.cpp index 4160cfcf63..1753b81ef9 100644 --- a/src/d/d_com_inf_game.cpp +++ b/src/d/d_com_inf_game.cpp @@ -1366,7 +1366,7 @@ s8 dComIfGp_getReverb(int i_roomNo) { } int dComIfGd_setSimpleShadow(cXyz* i_pos, f32 param_1, f32 param_2, cBgS_PolyInfo& param_3, - s16 i_angle, f32 param_5, GXTexObj* i_tex) { + s16 i_angle, f32 param_5, TGXTexObj* i_tex) { if (param_3.ChkSetInfo() && -G_CM3D_F_INF != param_1) { cM3dGPla plane; dComIfG_Bgsp().GetTriPla(param_3, &plane); @@ -2256,7 +2256,7 @@ void dComIfGp_addSelectItemNum(int i_selItemIdx, s16 i_num) { int dComIfGd_setShadow(u32 param_0, s8 param_1, J3DModel* param_2, cXyz* param_3, f32 param_4, f32 param_5, f32 param_6, f32 param_7, cBgS_PolyInfo& param_8, - dKy_tevstr_c* param_9, s16 param_10, f32 param_11, GXTexObj* param_12) { + dKy_tevstr_c* param_9, s16 param_10, f32 param_11, TGXTexObj* param_12) { if (param_7 <= -G_CM3D_F_INF) { return 0; } else { diff --git a/src/d/d_demo.cpp b/src/d/d_demo.cpp index 25c54edca8..370da262a5 100644 --- a/src/d/d_demo.cpp +++ b/src/d/d_demo.cpp @@ -22,7 +22,7 @@ void jstudio_tAdaptor_message::adaptor_do_MESSAGE(JStudio::data::TEOperationData case JStudio::data::UNK_0x19: { JUT_ASSERT(107, pContent!=NULL); JUT_ASSERT(108, uSize==4); - u32 content = *(u32*)pContent; + u32 content = *(BE(u32)*)pContent; dMsgObject_setDemoMessage(content); break; } @@ -215,7 +215,6 @@ int dDemo_actor_c::getDemoIDData(int* o_arg0, int* o_arg1, int* o_arg2, u16* o_r } u32 var_r31 = *it; - be_swap(var_r31); *o_arg0 = var_r31 >> 0x1E; *o_arg1 = (var_r31 >> 0x18) & 0xF; *o_arg2 = (var_r31 >> 0x10) & 0xF; diff --git a/src/d/d_drawlist.cpp b/src/d/d_drawlist.cpp index 5944c5ec35..77bf915dd9 100644 --- a/src/d/d_drawlist.cpp +++ b/src/d/d_drawlist.cpp @@ -11,10 +11,11 @@ #include "d/d_com_inf_game.h" #include "d/d_drawlist.h" #include "d/d_s_play.h" +#include "dusk/gx_helper.h" +#include "dusk/logging.h" #include "m_Do/m_Do_graphic.h" #include "m_Do/m_Do_lib.h" #include "m_Do/m_Do_mtx.h" -#include "dusk/logging.h" class dDlst_2Dm_c { public: @@ -28,12 +29,12 @@ public: /* 0x10 */ f32 field_0x10; /* 0x14 */ GXColor field_0x14; /* 0x18 */ GXColor field_0x18; - /* 0x1C */ GXTexObj field_0x1c; + /* 0x1C */ TGXTexObj field_0x1c; /* 0x3C */ GXTlutObj field_0x3c; /* 0x48 */ s16 field_0x48; /* 0x4A */ s16 field_0x4a; /* 0x4C */ u8 field_0x4c; - /* 0x50 */ GXTexObj field_0x50; + /* 0x50 */ TGXTexObj field_0x50; /* 0x70 */ GXTlutObj field_0x70; /* 0x7C */ s16 field_0x7c; /* 0x7E */ s16 field_0x7e; @@ -87,7 +88,7 @@ class dDlst_2DMt_tex_c { public: u8 check() { return field_0x0; } int getCI() { return mCI; } - GXTexObj* getTexObj() { return &mTexObj; } + TGXTexObj* getTexObj() { return &mTexObj; } GXTlutObj* getTlutObj() { return &mTlutObj; } GXColor* getColor() { return &mColor; } f32 getS() { return mS; } @@ -97,7 +98,7 @@ public: /* 0x00 */ u8 field_0x0; /* 0x01 */ u8 mCI; - /* 0x04 */ GXTexObj mTexObj; + /* 0x04 */ TGXTexObj mTexObj; /* 0x24 */ GXTlutObj mTlutObj; /* 0x30 */ GXColor mColor; /* 0x34 */ f32 mS; @@ -266,7 +267,7 @@ void dDlst_2DT_c::draw() { u16 var3 = (field_0x1c + var11) / var5 * 32768.0f; u16 var4 = (field_0x20 + var12) / var6 * 32768.0f; - GXTexObj tex; + TGXTexObj tex; GXInitTexObj(&tex, field_0x4, field_0xe, field_0x10, (GXTexFmt)field_0xc, GX_CLAMP, GX_CLAMP, GX_FALSE); GXInitTexObjLOD(&tex, GX_LINEAR, GX_LINEAR, 0.0, 0.0, 0.0, 0, 0, GX_ANISO_1); GXLoadTexObj(&tex, GX_TEXMAP0); @@ -311,9 +312,6 @@ void dDlst_2DT_c::draw() { GXEnd(); GXSetClipMode(GX_CLIP_ENABLE); dComIfGp_getCurrentGrafPort()->setup2D(); -#if TARGET_PC - GXDestroyTexObj(&tex); -#endif } void dDlst_2DT2_c::draw() { @@ -666,7 +664,7 @@ void dDlst_2DM_c::draw() { int r26 = field_0x34 * f3; s16 r25 = r27 + s16(field_0x1e * f4); s16 r24 = r26 + s16(field_0x20 * f3); - GXTexObj tex[2]; + TGXTexObj tex[2]; void** stack_1c = &field_0x18; GXInitTexObj(&tex[0], field_0x18, field_0x1e, field_0x20, GXTexFmt(field_0x1c), GX_CLAMP, GX_CLAMP, 0); GXInitTexObjLOD(&tex[0], GX_LINEAR, GX_LINEAR, 0.0, 0.0, 0.0, 0, 0, GX_ANISO_1); @@ -715,10 +713,6 @@ void dDlst_2DM_c::draw() { GXTexCoord2s16(r27, r24); GXEnd(); dComIfGp_getCurrentGrafPort()->setup2D(); -#if TARGET_PC - GXDestroyTexObj(&tex[0]); - GXDestroyTexObj(&tex[1]); -#endif } @@ -733,7 +727,7 @@ void dDlst_2Dm_c::draw() { int r26 = field_0x7e * f30; s16 r25 = r27 + s16(f31 * GXGetTexObjWidth(&field_0x1c)); s16 r24 = r26 + s16(f30 * GXGetTexObjHeight(&field_0x1c)); - GXTexObj* stack_18 = &field_0x1c; + TGXTexObj* stack_18 = &field_0x1c; GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_CLR_RGBA, GX_RGBA4, 8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX1, GX_CLR_RGBA, GX_RGBA4, 8); @@ -1347,7 +1341,7 @@ void dDlst_shadowSimple_c::draw() { } void dDlst_shadowSimple_c::set(cXyz* param_0, f32 param_1, f32 param_2, cXyz* param_3, - s16 param_4, f32 param_5, GXTexObj* param_6) { + s16 param_4, f32 param_5, TGXTexObj* param_6) { if (param_5 < 0.0f) { mAlpha = param_5 * -255.0f; param_5 = 1.0f; @@ -1424,6 +1418,11 @@ void dDlst_shadowControl_c::reset() { mSimpleNum = 0; mRealNum = 0; field_0x4 = NULL; + +#ifdef TARGET_PC + field_0x15eb0[0].reset(); + field_0x15eb0[1].reset(); +#endif } void dDlst_shadowControl_c::imageDraw(Mtx param_0) { @@ -1529,7 +1528,7 @@ void dDlst_shadowControl_c::draw(Mtx param_0) { for (int i2 = 0, i3 = 0; real != NULL; real = real->getZsortNext()) { if (real->isUse()) { if (i2 == 0) { - GXTexObj* obj = &field_0x15eb0[i3]; + TGXTexObj* obj = &field_0x15eb0[i3]; i3++; GXLoadTexObj(obj, GX_TEXMAP0); @@ -1671,7 +1670,7 @@ bool dDlst_shadowControl_c::addReal(u32 i_key, J3DModel* param_1) { } int dDlst_shadowControl_c::setSimple(cXyz* param_0, f32 param_1, f32 param_2, cXyz* param_3, - s16 param_4, f32 param_5, GXTexObj* param_6) { + s16 param_4, f32 param_5, TGXTexObj* param_6) { if (param_3 == NULL || mSimpleNum >= 128) { return 0; } @@ -1681,7 +1680,7 @@ int dDlst_shadowControl_c::setSimple(cXyz* param_0, f32 param_1, f32 param_2, cX return 1; } -GXTexObj dDlst_shadowControl_c::mSimpleTexObj; +TGXTexObj dDlst_shadowControl_c::mSimpleTexObj; void dDlst_shadowControl_c::setSimpleTex(ResTIMG const* i_timg) { mDoLib_setResTimgObj(i_timg, &mSimpleTexObj, 0, NULL); diff --git a/src/d/d_error_msg.cpp b/src/d/d_error_msg.cpp index 4259e7f08c..b0274b8583 100644 --- a/src/d/d_error_msg.cpp +++ b/src/d/d_error_msg.cpp @@ -251,6 +251,9 @@ static void drawCapture(u8 alpha) { GXSetAlphaUpdate(GX_FALSE); j3dSys.drawInit(); +#ifdef TARGET_PC + mDoGph_gInf_c::getFrameBufferTexObj()->reset(); +#endif GXInitTexObj(mDoGph_gInf_c::getFrameBufferTexObj(), mDoGph_gInf_c::getFrameBufferTex(), FB_WIDTH / 2, FB_HEIGHT / 2, (GXTexFmt)mDoGph_gInf_c::getFrameBufferTimg()->format, GX_CLAMP, GX_CLAMP, GX_FALSE); GXInitTexObjLOD(mDoGph_gInf_c::getFrameBufferTexObj(), GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); GXLoadTexObj(mDoGph_gInf_c::getFrameBufferTexObj(), GX_TEXMAP0); diff --git a/src/d/d_event_data.cpp b/src/d/d_event_data.cpp index 6aafea605e..3b099e891c 100644 --- a/src/d/d_event_data.cpp +++ b/src/d/d_event_data.cpp @@ -1537,6 +1537,12 @@ int dEvDtBase_c::init(char* i_data, int i_roomNo) { setHeaderP((event_binary_data_header*)i_data); +#if TARGET_PC + bool needSwap = mHeaderP->unk[0] == 0; + JUT_ASSERT(1234, mHeaderP->unk[0] == 0 || mHeaderP->unk[0] == 1); + mHeaderP->unk[0] = 1; +#endif + if (getEventNum() > 0) { setEventP((dEvDtEvent_c*)(i_data + getEventTop())); } @@ -1556,9 +1562,11 @@ int dEvDtBase_c::init(char* i_data, int i_roomNo) { if (getFDataNum() > 0) { #if TARGET_PC auto data = (f32*)(i_data + getFDataTop()); - int num = getFDataNum(); - for (int i = 0; i < num; i++) - be_swap(data[i]); + if (needSwap) { + int num = getFDataNum(); + for (int i = 0; i < num; i++) + be_swap(data[i]); + } setFDataP(data); #else setFDataP((f32*)(i_data + getFDataTop())); @@ -1569,9 +1577,11 @@ int dEvDtBase_c::init(char* i_data, int i_roomNo) { #if TARGET_PC // endian swap here auto data = (int*)(i_data + getIDataTop()); - int num = getIDataNum(); - for (int i = 0; i < num; i++) - be_swap(data[i]); + if (needSwap) { + int num = getIDataNum(); + for (int i = 0; i < num; i++) + be_swap(data[i]); + } setIDataP(data); #else setIDataP((int*)(i_data + getIDataTop())); diff --git a/src/d/d_gameover.cpp b/src/d/d_gameover.cpp index 762c8b01fd..1320ebcb7a 100644 --- a/src/d/d_gameover.cpp +++ b/src/d/d_gameover.cpp @@ -14,6 +14,8 @@ #include "JSystem/J2DGraph/J2DGrafContext.h" #include +#include "dusk/gx_helper.h" + class dGov_HIO_c : public mDoHIO_entry_c { public: dGov_HIO_c(); @@ -32,7 +34,7 @@ public: static dGov_HIO_c l_HIO; void dDlst_Gameover_CAPTURE_c::draw() { - GXTexObj tex_obj; + TGXTexObj tex_obj; Mtx44 m; GXSetTexCopySrc(0, 0, FB_WIDTH, FB_HEIGHT); diff --git a/src/d/d_home_button.cpp b/src/d/d_home_button.cpp index 45a1c86ad9..ade10841c6 100644 --- a/src/d/d_home_button.cpp +++ b/src/d/d_home_button.cpp @@ -198,6 +198,9 @@ void dHomeButton_c::drawCapture(u8 param_0, void (*param_1)(J2DOrthoGraph&, void sp30.setPort(); dComIfGp_setCurrentGrafPort(&sp30); +#ifdef TARGET_PC + mDoGph_gInf_c::m_fullFrameBufferTexObj.reset(); +#endif mDoLib_setResTimgObj(mDoGph_gInf_c::m_fullFrameBufferTimg, &mDoGph_gInf_c::m_fullFrameBufferTexObj, 0, NULL); diff --git a/src/d/d_k_wmark.cpp b/src/d/d_k_wmark.cpp index 4594622b95..f3f089d564 100644 --- a/src/d/d_k_wmark.cpp +++ b/src/d/d_k_wmark.cpp @@ -18,7 +18,7 @@ int dkWmark_c::m_nowID; int dkWmark_c::create() { static cXyz wolfFootScale(1.1f, 1.0f, 0.6f); - JKR_NEW_ARGS (this) dkWmark_c(); + new (this) dkWmark_c; field_0x48a = this->parameters >> 0x10; this->parameters &= 0xFFFF; diff --git a/src/d/d_kankyo_rain.cpp b/src/d/d_kankyo_rain.cpp index 4ed11a4411..026df00c96 100644 --- a/src/d/d_kankyo_rain.cpp +++ b/src/d/d_kankyo_rain.cpp @@ -71,7 +71,10 @@ void dKy_set_eyevect_calc2(camera_class* i_camera, Vec* o_out, f32 param_2, f32 } } -static void dKyr_set_btitex_common(GXTexObj* i_obj, ResTIMG* i_img, GXTexMapID i_mapID) { +static void dKyr_set_btitex_common(TGXTexObj* i_obj, ResTIMG* i_img, GXTexMapID i_mapID) { +#ifdef TARGET_PC + i_obj->reset(); +#endif GXInitTexObj(i_obj, (&i_img->format + i_img->imageOffset), i_img->width, i_img->height, (GXTexFmt)i_img->format, (GXTexWrapMode)i_img->wrapS, (GXTexWrapMode)i_img->wrapT, (GXBool)(i_img->mipmapCount > 1)); @@ -84,7 +87,7 @@ static void dKyr_set_btitex_common(GXTexObj* i_obj, ResTIMG* i_img, GXTexMapID i GXLoadTexObj(i_obj, i_mapID); } -static void dKyr_set_btitex(GXTexObj* i_obj, ResTIMG* i_img) { +static void dKyr_set_btitex(TGXTexObj* i_obj, ResTIMG* i_img) { dKyr_set_btitex_common(i_obj, i_img, GX_TEXMAP0); } @@ -2116,7 +2119,7 @@ static void dKyr_draw_rev_moon(Mtx drawMtx, u8** tex) { return; } - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex_common(&texobj, (ResTIMG*)tex[0], GX_TEXMAP0); dKyr_set_btitex_common(&texobj, (ResTIMG*)tex[1], GX_TEXMAP1); dKyr_set_btitex_common(&texobj, (ResTIMG*)tex[texidx + 2], GX_TEXMAP2); @@ -2464,7 +2467,7 @@ void dKyr_drawSun(Mtx drawMtx, cXyz* ppos, GXColor& unused, u8** tex) { return; } - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex_common(&texobj, (ResTIMG*)tex[0], GX_TEXMAP0); dKyr_set_btitex_common(&texobj, (ResTIMG*)tex[1], GX_TEXMAP1); dKyr_set_btitex_common(&texobj, (ResTIMG*)tex[texidx + 2], GX_TEXMAP2); @@ -2724,7 +2727,7 @@ void dKyr_drawLenzflare(Mtx drawMtx, cXyz* ppos, GXColor& param_2, u8** tex) { j3dSys.reinitGX(); - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex(&texobj, (ResTIMG*)tex[0]); GXSetNumChans(0); GXSetTevColor(GX_TEVREG0, color_reg0); @@ -3125,7 +3128,7 @@ void dKyr_drawRain(Mtx drawMtx, u8** tex) { return; } - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex(&texobj, (ResTIMG*)tex[0]); GXSetNumChans(0); GXSetTevColor(GX_TEVREG0, color_reg0); @@ -3290,7 +3293,7 @@ void dKyr_drawSibuki(Mtx drawMtx, u8** tex) { color.b = 0xC8; color.a = rain_packet->mSibukiAlpha * alphaFade; - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex(&texobj, (ResTIMG*)tex[1]); GXSetNumChans(0); GXSetTevColor(GX_TEVREG0, color); @@ -3378,7 +3381,7 @@ void dKyr_drawHousi(Mtx drawMtx, u8** tex) { Mtx camMtx; Mtx rotMtx; cXyz pos[4]; - GXTexObj spDC; + TGXTexObj spDC; cXyz spD0; Vec spC4; Vec spB8; @@ -3795,7 +3798,7 @@ void dKyr_drawSnow(Mtx drawMtx, u8** tex) { } if (tex[0] != NULL) { - GXTexObj spA0; + TGXTexObj spA0; dKyr_set_btitex(&spA0, (ResTIMG*)tex[0]); GXSetNumChans(0); GXSetTevColor(GX_TEVREG0, color_reg0); @@ -4334,7 +4337,7 @@ void drawCloudShadow(Mtx drawMtx, u8** tex) { GXSetClipMode(GX_CLIP_DISABLE); - GXTexObj texobj, fb_texobj; + TGXTexObj texobj, fb_texobj; if (g_env_light.mMoyaMode < 50) { dKy_ParticleColor_get_bg(&camera->view.lookat.eye, NULL, &sp48, &sp44, &sp40, &sp3C, 0.0f); f32 temp_f30 = 0.4f; @@ -4539,7 +4542,7 @@ void drawVrkumo(Mtx drawMtx, GXColor& color, u8** tex) { Mtx camMtx; Mtx rotMtx; - GXTexObj texobj; + TGXTexObj texobj; cXyz proj; f32 rot; @@ -5370,7 +5373,7 @@ void dKyr_odour_draw(Mtx drawMtx, u8** tex) { break; } - GXTexObj texobj, fb_texobj; + TGXTexObj texobj, fb_texobj; dKyr_set_btitex_common(&texobj, (ResTIMG*)tex[0], GX_TEXMAP1); ResTIMG* fb_timg = mDoGph_gInf_c::getFrameBufferTimg(); @@ -5764,7 +5767,7 @@ void dKyr_mud_draw(Mtx drawMtx, u8** tex) { if (g_env_light.camera_water_in_status == 0) { for (int i = 0; i < 1; i++) { - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex(&texobj, (ResTIMG*)tex[0]); GXSetNumChans(0); @@ -5924,7 +5927,7 @@ static void dKyr_evil_draw2(Mtx drawMtx, u8** tex) { color_reg0.b = 0x87; color_reg0.a = 0xFF; - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex(&texobj, (ResTIMG*)tex[1]); rot += 0.7f; @@ -5980,11 +5983,19 @@ static void dKyr_evil_draw2(Mtx drawMtx, u8** tex) { mDoLib_project(&sp7C, &proj); +#if TARGET_PC + if (!(proj.x > -sp34.x) || !(proj.x < (dComIfGd_getViewport()->width + sp34.x)) || + !(proj.y > -sp34.y) || !(proj.y < (dComIfGd_getViewport()->height + sp34.z))) + { + continue; + } +#else if (!(proj.x > -sp34.x) || !(proj.x < (FB_WIDTH + sp34.x)) || !(proj.y > -sp34.y) || !(proj.y < (458.0f + sp34.z))) { continue; } +#endif } f32 sp40; @@ -6147,7 +6158,7 @@ void dKyr_evil_draw(Mtx drawMtx, u8** tex) { color_reg1.b = 10; color_reg1.a = 255; - GXTexObj texobj; + TGXTexObj texobj; dKyr_set_btitex(&texobj, (ResTIMG*)tex[0]); rot += 1.0f; @@ -6205,11 +6216,19 @@ void dKyr_evil_draw(Mtx drawMtx, u8** tex) { mDoLib_project(&spA4, &proj); +#if TARGET_PC + if (!(proj.x > -sp44.x) || !(proj.x < (dComIfGd_getViewport()->width + sp44.x)) || + !(proj.y > -sp44.y) || !(proj.y < (dComIfGd_getViewport()->height + sp44.z))) + { + continue; + } +#else if (!(proj.x > -sp44.x) || !(proj.x < (FB_WIDTH + sp44.x)) || !(proj.y > -sp44.y) || !(proj.y < (458.0f + sp44.z))) { continue; } +#endif } f32 sp5C; diff --git a/src/d/d_map.cpp b/src/d/d_map.cpp index a0ee8d8128..76289d52dd 100644 --- a/src/d/d_map.cpp +++ b/src/d/d_map.cpp @@ -341,6 +341,7 @@ inline u8 twoValueLineInterpolation(u8 param_0, u8 param_1, f32 param_2) { } void renderingAmap_c::draw() { + #if REQUIRES_GX_LINES f32 tmp = ((f32)(g_Counter.mCounter0 % dMap_HIO_prm_res_dst_s::m_res->field_0x1aa) / (f32)dMap_HIO_prm_res_dst_s::m_res->field_0x1aa); tmp = tmp; @@ -376,6 +377,7 @@ void renderingAmap_c::draw() { setAmapPaletteColor(0x2E, temp_r31, temp_r30, temp_r29, temp_r28); renderingDAmap_c::draw(); + #endif } int renderingAmap_c::getDispType() const { diff --git a/src/d/d_map_path.cpp b/src/d/d_map_path.cpp index 614f804a5c..47f0f1e43c 100644 --- a/src/d/d_map_path.cpp +++ b/src/d/d_map_path.cpp @@ -20,7 +20,7 @@ void dMpath_n::dTexObjAggregate_c::create() { }; for (int lp1 = 0; lp1 < 7; lp1++) { - mp_texObj[lp1] = JKR_NEW GXTexObj(); + mp_texObj[lp1] = JKR_NEW TGXTexObj(); JUT_ASSERT(70, mp_texObj[lp1] != NULL); ResTIMG* image = (ResTIMG*)dComIfG_getObjectRes("Always", data[lp1]); JUT_ASSERT(72, image != NULL); @@ -346,11 +346,13 @@ void dRenderingMap_c::makeResTIMG(ResTIMG* p_image, u16 width, u16 height, u8* p void dRenderingMap_c::renderingMap() { preRenderingMap(); if (isDrawPath()) { + #if REQUIRES_GX_LINES preDrawPath(); beforeDrawPath(); drawPath(); afterDrawPath(); postDrawPath(); + #endif } postRenderingMap(); } @@ -471,6 +473,7 @@ void dRenderingFDAmap_c::renderingDecoration(dDrawPath_c::line_class const* p_li GXSetTevColor(GX_TEVREG1, lineColor); for (int i = 0; i < data_num; i++) { +#if REQUIRES_GX_LINES #ifndef HYRULE_FIELD_SPEEDHACK if (i < data_num - 1) { GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0); @@ -490,6 +493,7 @@ void dRenderingFDAmap_c::renderingDecoration(dDrawPath_c::line_class const* p_li GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); +#endif #endif GXBegin(GX_POINTS, GX_VTXFMT0, 1); GXPosition1x16(data_p[0]); diff --git a/src/d/d_menu_collect.cpp b/src/d/d_menu_collect.cpp index d2b5c0ec36..09b13561ed 100644 --- a/src/d/d_menu_collect.cpp +++ b/src/d/d_menu_collect.cpp @@ -2553,7 +2553,12 @@ u8 dMenu_Collect3D_c::getMaskMdlVisible() { f32 dMenu_Collect3D_c::mViewOffsetY = -100.0f; void dMenu_Collect3D_c::setupItem3D(Mtx param_0) { +#if TARGET_PC + f32 scaleFactor = mDoGph_gInf_c::getWidth() / FB_WIDTH; // TODO: get display pixel density from aurora + GXSetViewport(0.0f, mViewOffsetY * scaleFactor, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight(), 0.0f, 1.0f); +#else GXSetViewport(0.0f, mViewOffsetY, FB_WIDTH, FB_HEIGHT, 0.0f, 1.0f); +#endif mViewOffsetY = -100.0f; Mtx44 projection; C_MTXPerspective(projection, 45.0f, mDoGph_gInf_c::getAspect(), 1.0f, 100000.0f); diff --git a/src/d/d_menu_ring.cpp b/src/d/d_menu_ring.cpp index c43479c21f..06588bcfe6 100644 --- a/src/d/d_menu_ring.cpp +++ b/src/d/d_menu_ring.cpp @@ -1262,8 +1262,10 @@ void dMenu_Ring_c::drawItem() { (g_ringHIO.mItemAlphaMin + fVar16 * (g_ringHIO.mItemAlphaMax - g_ringHIO.mItemAlphaMin)); for (int i = 0; i < mItemsTotal; i++) { if (i != mCurrentSlot || (mStatus != STATUS_WAIT && mStatus != STATUS_EXPLAIN && mStatus != STATUS_EXPLAIN_FORCE)) { + #if REQUIRES_GX_LINES J2DDrawFrame(mItemSlotPosX[i] - 24.0f + mCenterPosX, mItemSlotPosY[i] - 24.0f + mCenterPosY, 48.0f, 48.0f, g_ringHIO.mItemFrame[g_ringHIO.UNSELECT_FRAME], 6); + #endif f32 fVar17 = 1.0f; if (i != mCurrentSlot) { fVar17 = ringAlpha / 255.0f; @@ -1306,8 +1308,10 @@ void dMenu_Ring_c::drawItem() { void dMenu_Ring_c::drawItem2() { s32 idx = mCurrentSlot; if (mStatus == STATUS_WAIT || mStatus == STATUS_EXPLAIN || mStatus == STATUS_EXPLAIN_FORCE) { + #if REQUIRES_GX_LINES J2DDrawFrame(mItemSlotPosX[idx] - 24.0f + mCenterPosX, mItemSlotPosY[idx] - 24.0f + mCenterPosY, 48.0f, 48.0f, g_ringHIO.mItemFrame[g_ringHIO.SELECT_FRAME], 6); + #endif for (int i = 0; i < 3; i++) { if (mpItemTex[idx][i] != NULL) { diff --git a/src/d/d_menu_window.cpp b/src/d/d_menu_window.cpp index d43d85d128..04f1184a31 100644 --- a/src/d/d_menu_window.cpp +++ b/src/d/d_menu_window.cpp @@ -37,7 +37,7 @@ public: GXCopyTex(mDoGph_gInf_c::getFrameBufferTex(), GX_FALSE); GXPixModeSync(); } else { - GXTexObj tex; + TGXTexObj tex; GXInitTexObj(&tex, mDoGph_gInf_c::getFrameBufferTex(), FB_WIDTH / 2, FB_HEIGHT / 2, (GXTexFmt)mDoGph_gInf_c::getFrameBufferTimg()->format, GX_CLAMP, GX_CLAMP, GX_FALSE); GXInitTexObjLOD(&tex, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); diff --git a/src/d/d_meter2.cpp b/src/d/d_meter2.cpp index 1baaee81d9..1d236f11bf 100644 --- a/src/d/d_meter2.cpp +++ b/src/d/d_meter2.cpp @@ -26,12 +26,14 @@ #include "dusk/memory.h" +#include "dusk/memory.h" + int dMeter2_c::_create() { stage_stag_info_class* stag_info = dComIfGp_getStageStagInfo(); if (dStage_stagInfo_GetUpButton(stag_info) == 1) { mpHeap = fopMsgM_createExpHeap(HEAP_SIZE(0x5A400, 0xA0000), NULL); } else { - mpHeap = fopMsgM_createExpHeap(HEAP_SIZE(0x60800, 0xA0000), NULL); + mpHeap = fopMsgM_createExpHeap(HEAP_SIZE(0x60800, 0xC1000), NULL); } JKRHEAP_NAME(mpHeap, "dMeter2_c"); diff --git a/src/d/d_msg_class.cpp b/src/d/d_msg_class.cpp index 2a6f76c4a6..e63ffd4412 100644 --- a/src/d/d_msg_class.cpp +++ b/src/d/d_msg_class.cpp @@ -1051,7 +1051,7 @@ bool jmessage_tMeasureProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_siz case MSGTAG_COLOR: return true; case MSGTAG_SCALE: { - u16 scale = *(u16*)i_data; + u16 scale = *(BE(u16)*)i_data; pReference->setLineScale(mTotalLineCnt, scale); do_scale(scale / 100.0f); return true; @@ -1102,13 +1102,13 @@ bool jmessage_tMeasureProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_siz } case MSGTAG_UNK_3: case MSGTAG_AUTOBOX: - if (*(u16*)i_data != 0) { + if (*(BE(u16)*)i_data != 0) { dMsgObject_c* objectPtr = pReference->mpObjectPtr; // fakematch, should be getObjectPtr objectPtr->onAutoMessageFlag(); } return true; case MSGTAG_DEMOBOX: - pReference->setDemoFrame(*(u32*)i_data); + pReference->setDemoFrame(*(BE(u32)*)i_data); return true; case MSGTAG_PLAYER_NAME: { if (field_0x49 != 0) { @@ -1414,7 +1414,7 @@ bool jmessage_tMeasureProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_siz dMsgUnit_setTag(1, (s32)dComIfGp_getMessageCountNumber(), buffer); break; case MSGTAG_FUNDRAISE_REMAIN: { - s16 fund_raise_val = *(u32*)i_data; + s16 fund_raise_val = *(BE(u32)*)i_data; dMsgObject_c* objectPtr = pReference->getObjectPtr(); objectPtr->setFundRaisingValue(fund_raise_val); @@ -1555,7 +1555,7 @@ bool jmessage_tMeasureProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_siz do_space(i_tag); return true; case MSGTAG_WII_MSGID_OVERRIDE: - pReference->setRevoMessageID(*(u32*)i_data); + pReference->setRevoMessageID(*(BE(u32)*)i_data); return true; } } @@ -2169,7 +2169,7 @@ bool jmessage_tSequenceProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_si pReference->setNowColorType(*(u8*)i_data & 0xFF); return true; case MSGTAG_SCALE: - pReference->setNowTagScale(*(u16*)i_data & 0xFFFF); + pReference->setNowTagScale(*(BE(u16)*)i_data & 0xFFFF); return true; case MSGTAG_RUBY: case 0xFFFF02: @@ -2220,7 +2220,7 @@ bool jmessage_tSequenceProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_si return true; case MSGTAG_UNK_3: case MSGTAG_AUTOBOX: - pReference->setSendTimer(*(u16*)i_data); + pReference->setSendTimer(*(BE(u16)*)i_data); if (pReference->getSendTimer() == 0) { pReference->setSendFlag(3); } else { @@ -2228,24 +2228,24 @@ bool jmessage_tSequenceProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_si } return true; case MSGTAG_BOXATMOST: - pReference->setSendTimer(*(u16*)i_data); + pReference->setSendTimer(*(BE(u16)*)i_data); pReference->setSendFlag(2); return true; case MSGTAG_BOXATLEAST: - dMeter2Info_setMsgKeyWaitTimer(*(u16*)i_data); - pReference->setSendTimer(*(u16*)i_data); + dMeter2Info_setMsgKeyWaitTimer(*(BE(u16)*)i_data); + pReference->setSendTimer(*(BE(u16)*)i_data); pReference->setSendFlag(6); return true; case MSGTAG_DEMOBOX: - pReference->setDemoFrame(*(u32*)i_data); + pReference->setDemoFrame(*(BE(u32)*)i_data); pReference->setSendFlag(4); return true; case MSGTAG_UNK_6: - field_0xa8 = *(u16*)i_data; + field_0xa8 = *(BE(u16)*)i_data; field_0xa4 = field_0xa8; return true; case MSGTAG_PAUSE: - field_0xa4 = *(u16*)i_data; + field_0xa4 = *(BE(u16)*)i_data; mMouthCheck = 0; return true; case MSGTAG_SELECT_2WAY: @@ -2361,7 +2361,7 @@ bool jmessage_tSequenceProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_si pReference->resetInputFigure(); pReference->setSendFlag(5); - if (*(u32*)i_data == 1) { + if (*(BE(u32)*)i_data == 1) { dComIfGs_onTmpBit(dSv_event_tmp_flag_c::tempBitLabels[80]); } return true; @@ -2903,7 +2903,7 @@ bool jmessage_tRenderingProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_s do_color(*(u8*)i_data & 0xFF); return 1; case MSGTAG_SCALE: - field_0x13c = *(u16*)i_data & 0xFFFF; + field_0x13c = *(BE(u16)*)i_data & 0xFFFF; do_scale(field_0x13c / 100.0f); return 1; case MSGTAG_RUBY: @@ -2937,7 +2937,7 @@ bool jmessage_tRenderingProcessor::do_tag(u32 i_tag, void const* i_data, u32 i_s stack_pushCurrent(pReference->getObjectPtr()->getLetterName()); return 1; case MSGTAG_LINE_DOWN: - do_linedown(*(u16*)i_data); + do_linedown(*(BE(u16)*)i_data); return 1; case MSGTAG_CURRENT_LETTER_PAGE: case MSGTAG_MAX_LETTER_PAGE: @@ -4178,7 +4178,7 @@ bool jmessage_string_tMeasureProcessor::do_tag(u32 i_tag, void const* i_data, u3 dMsgUnit_setTag(1, (s32)dComIfGp_getMessageCountNumber(), buffer); break; case MSGTAG_FUNDRAISE_REMAIN: { - s16 uVar9 = *(int*)i_data; + s16 uVar9 = *(BE(int)*)i_data; dMsgObject_getMsgObjectClass()->setFundRaisingValue(uVar9); dMsgUnit_setTag(10, uVar9 - dMsgObject_getFundRaising(), buffer); break; @@ -4384,7 +4384,7 @@ bool jmessage_string_tSequenceProcessor::do_tag(u32 i_tag, void const* i_data, u case MSGTAG_GROUP(0): switch(i_tag) { case MSGTAG_BOXATLEAST: - dMeter2Info_setMsgKeyWaitTimer(*(u16*)i_data); + dMeter2Info_setMsgKeyWaitTimer(*(BE(u16)*)i_data); break; } break; @@ -4537,7 +4537,7 @@ bool jmessage_string_tRenderingProcessor::do_tag(u32 i_tag, void const* i_data, do_color(*(u8*)i_data & 0xFF); break; case MSGTAG_SCALE: - do_scale(*(u16*)i_data / 100.0f); + do_scale(*(BE(u16)*)i_data / 100.0f); break; case MSGTAG_RUBY: case 0xFFFF02: @@ -4572,7 +4572,7 @@ bool jmessage_string_tRenderingProcessor::do_tag(u32 i_tag, void const* i_data, push_word(dMsgObject_getMsgObjectClass()->getLetterName()); break; case MSGTAG_LINE_DOWN: - do_linedown(*(u16*)i_data); + do_linedown(*(BE(u16)*)i_data); break; case MSGTAG_CURRENT_LETTER_PAGE: { char buffer[4]; @@ -4788,7 +4788,7 @@ bool jmessage_string_tRenderingProcessor::do_tag(u32 i_tag, void const* i_data, dMsgUnit_setTag(1, (s32)dComIfGp_getMessageCountNumber(), buffer); break; case MSGTAG_FUNDRAISE_REMAIN: { - s16 uVar9 = *(int*)i_data; + s16 uVar9 = *(BE(int)*)i_data; dMsgObject_getMsgObjectClass()->setFundRaisingValue(uVar9); dMsgUnit_setTag(10, uVar9 - dMsgObject_getFundRaising(), buffer); break; diff --git a/src/d/d_msg_flow.cpp b/src/d/d_msg_flow.cpp index 243cba9535..0ad00a7524 100644 --- a/src/d/d_msg_flow.cpp +++ b/src/d/d_msg_flow.cpp @@ -49,8 +49,8 @@ void dMsgFlow_c::init(fopAc_ac_c* i_partner, int i_flowID, int param_2, fopAc_ac labelInfoTBL = mLabelInfo_p + 0x10; mFlowNodeTBL = (mesg_flow*)(mFlow_p + 0x10); - mFlowIdxTBL = (u16*)(mFlowNodeTBL + (*(u16*)(mFlow_p + 8))); - field_0x18 = mFlowIdxTBL + *(u16*)(mFlow_p + 8); + mFlowIdxTBL = (BE(u16)*)(mFlowNodeTBL + (*(BE(u16)*)(mFlow_p + 8))); + field_0x18 = mFlowIdxTBL + *(BE(u16)*)(mFlow_p + 8); mFlow = prevFlowID; @@ -322,8 +322,8 @@ void dMsgFlow_c::setInitValueGroupChange(int i_msgNo, fopAc_ac_c** i_talkPartner labelInfoTBL = mLabelInfo_p + 0x10; mFlowNodeTBL = (mesg_flow*)(mFlow_p + 0x10); - mFlowIdxTBL = (u16*)(mFlowNodeTBL + *(u16*)(mFlow_p + 8)); - field_0x18 = mFlowIdxTBL + *(u16*)(mFlow_p + 8); + mFlowIdxTBL = (BE(u16)*)(mFlowNodeTBL + *(BE(u16)*)(mFlow_p + 8)); + field_0x18 = mFlowIdxTBL + *(BE(u16)*)(mFlow_p + 8); mFlow = var_r28; setNodeIndex(getInitNodeIndex(mFlow), i_talkPartners); } @@ -337,7 +337,7 @@ u8* dMsgFlow_c::getMsgDataBlock(char const* block_tag) { aMsgRes_p = dMsgObject_getMsgDtPtr(); JUT_ASSERT(742, NULL != aMsgRes_p); - u32 num = *(u32*)(aMsgRes_p + 0xC); + u32 num = *(BE(u32)*)(aMsgRes_p + 0xC); aMsgRes_p += 0x20; for (u32 i = 0; i < num; i++) { @@ -348,7 +348,7 @@ u8* dMsgFlow_c::getMsgDataBlock(char const* block_tag) { return aMsgRes_p; } - aMsgRes_p += *(int*)(block_p + 4); + aMsgRes_p += *(BE(int)*)(block_p + 4); } return NULL; @@ -361,9 +361,9 @@ u16 dMsgFlow_c::getInitNodeIndex(u16 param_1) { JUT_ASSERT(777, NULL != mLabelInfo_p); var_r30 = mLabelInfo_p + 0x10; - for (int i = 0; i < *(u16*)(mLabelInfo_p + 8); i++) { - if (*(u32*)var_r30 >> 16 == param_1) { - var_r27 = *(u16*)(var_r30 + 4); + for (int i = 0; i < *(BE(u16)*)(mLabelInfo_p + 8); i++) { + if (*(BE(u32)*)var_r30 >> 16 == param_1) { + var_r27 = *(BE(u16)*)(var_r30 + 4); } var_r30 += 0x8; @@ -441,13 +441,13 @@ void dMsgFlow_c::setNodeIndex(u16 i_nodeIdx, fopAc_ac_c** i_talkPartners) { int dMsgFlow_c::setSelectMsg(mesg_flow_node* i_flowNode_p, mesg_flow_node* param_2, fopAc_ac_c* i_speaker_p) { - u16* inf_p = NULL; + BE(u16)* inf_p = NULL; u16 temp_r25; u16 msg_no; mesg_flow_node* var_r29 = NULL; - inf_p = (u16*)getMsgDataBlock("INF1"); + inf_p = (BE(u16)*)getMsgDataBlock("INF1"); var_r29 = param_2; temp_r25 = ((inf_p + (var_r29->msg_index) * 10))[10]; @@ -491,13 +491,13 @@ int dMsgFlow_c::setSelectMsg(mesg_flow_node* i_flowNode_p, mesg_flow_node* param } int dMsgFlow_c::setNormalMsg(mesg_flow_node* i_flowNode_p, fopAc_ac_c* i_speaker_p) { - u16* inf_p = NULL; + BE(u16)* inf_p = NULL; mesg_flow_node* var_r29 = NULL; u16 msg_no; var_r29 = i_flowNode_p; - inf_p = (u16*)getMsgDataBlock("INF1"); - msg_no = ((inf_p + (var_r29->msg_index) * 10))[10]; + inf_p = (BE(u16)*)getMsgDataBlock("INF1"); + msg_no = (inf_p + (var_r29->msg_index) * 10)[10]; // "Message Set" OS_REPORT("\x1B[44;37mメッセ−ジセット          \x1B[m|:"); @@ -727,8 +727,8 @@ int dMsgFlow_c::nodeProc(fopAc_ac_c* i_speaker_p, fopAc_ac_c** i_talkPartners) { } int dMsgFlow_c::getParam(u16* prm0, u16* prm1, u8* params) { - *prm0 = *(u16*)params; - *prm1 = *(u16*)(params + 2); + *prm0 = *(BE(u16)*)params; + *prm1 = *(BE(u16)*)(params + 2); return *(int*)params; } diff --git a/src/d/d_ovlp_fade2.cpp b/src/d/d_ovlp_fade2.cpp index dffd9900d9..f10c188a7f 100644 --- a/src/d/d_ovlp_fade2.cpp +++ b/src/d/d_ovlp_fade2.cpp @@ -12,8 +12,13 @@ #include "m_Do/m_Do_graphic.h" void dOvlpFd2_dlst_c::draw() { +#if TARGET_PC + GXSetViewport(0.0f, 0.0f, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight(), 0.0f, 1.0f); + GXSetScissor(0, 0, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight()); +#else GXSetViewport(0.0f, 0.0f, FB_WIDTH, FB_HEIGHT, 0.0f, 1.0f); GXSetScissor(0, 0, FB_WIDTH, FB_HEIGHT); +#endif GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGB, GX_RGBA4, 0); GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_DIRECT); @@ -49,6 +54,9 @@ void dOvlpFd2_dlst_c::draw() { C_MTXPerspective(m, 60.0f, mDoGph_gInf_c::getWidthF() / mDoGph_gInf_c::getHeightF(), 100.0f, 100000.0f); GXSetProjection(m, GX_PERSPECTIVE); +#ifdef TARGET_PC + mDoGph_gInf_c::getFrameBufferTexObj()->reset(); +#endif GXInitTexObj(mDoGph_gInf_c::getFrameBufferTexObj(), mDoGph_gInf_c::getFrameBufferTex(), FB_WIDTH / 2, FB_HEIGHT / 2, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GXInitTexObjLOD(mDoGph_gInf_c::getFrameBufferTexObj(), GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, diff --git a/src/d/d_ovlp_fade3.cpp b/src/d/d_ovlp_fade3.cpp index 04f8bced7d..5221c28b83 100644 --- a/src/d/d_ovlp_fade3.cpp +++ b/src/d/d_ovlp_fade3.cpp @@ -20,8 +20,13 @@ void dDlst_snapShot_c::draw() { } void dOvlpFd3_dlst_c::draw() { +#if TARGET_PC + GXSetViewport(0.0f, 0.0f, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight(), 0.0f, 1.0f); + GXSetScissor(0, 0, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight()); +#else GXSetViewport(0.0f, 0.0f, FB_WIDTH, FB_HEIGHT, 0.0f, 1.0f); GXSetScissor(0, 0, FB_WIDTH, FB_HEIGHT); +#endif GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGB, GX_RGBA4, 0); GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_DIRECT); @@ -57,6 +62,9 @@ void dOvlpFd3_dlst_c::draw() { C_MTXPerspective(m, 60.0f, mDoGph_gInf_c::getWidthF() / mDoGph_gInf_c::getHeightF(), 100.0f, 100000.0f); GXSetProjection(m, GX_PERSPECTIVE); +#ifdef TARGET_PC + mDoGph_gInf_c::getFrameBufferTexObj()->reset(); +#endif GXInitTexObj(mDoGph_gInf_c::getFrameBufferTexObj(), mDoGph_gInf_c::getFrameBufferTex(), FB_WIDTH / 2, FB_HEIGHT / 2, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GXInitTexObjLOD(mDoGph_gInf_c::getFrameBufferTexObj(), GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, diff --git a/src/d/d_pane_class.cpp b/src/d/d_pane_class.cpp index 0b12ff7d15..78855b2d1c 100644 --- a/src/d/d_pane_class.cpp +++ b/src/d/d_pane_class.cpp @@ -357,7 +357,11 @@ Vec CPaneMgr::getGlobalVtx(J2DPane* p_pane, Mtx* param_1, u8 param_2, bool param MtxP mp = (MtxP)param_1; J2DPane* parent = p_pane->getParentPane(); +#if TARGET_PC + J2DOrthoGraph ortho(0.0f, 0.0f, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight(), -1.0f, 1.0f); +#else J2DOrthoGraph ortho(0.0f, 0.0f, FB_WIDTH, FB_HEIGHT, -1.0f, 1.0f); +#endif ortho.setOrtho(mDoGph_gInf_c::getMinXF(), mDoGph_gInf_c::getMinYF(), mDoGph_gInf_c::getWidthF(), mDoGph_gInf_c::getHeightF(), -1.0f, 1.0f); if (parent != NULL) { diff --git a/src/d/d_resorce.cpp b/src/d/d_resorce.cpp index 158c267108..50192f5a38 100644 --- a/src/d/d_resorce.cpp +++ b/src/d/d_resorce.cpp @@ -352,7 +352,7 @@ int dRes_info_c::loadResource() { JUT_ASSERT(769, resNameLen <= NAME_MAX); #endif - char arcName[9]; + char arcName[10]; strncpy(arcName, name_p, resNameLen); arcName[resNameLen] = '\0'; diff --git a/src/d/d_s_play.cpp b/src/d/d_s_play.cpp index a95dc5dd40..818f5d3487 100644 --- a/src/d/d_s_play.cpp +++ b/src/d/d_s_play.cpp @@ -24,6 +24,7 @@ #include "f_op/f_op_overlap_mng.h" #include "m_Do/m_Do_Reset.h" #include "m_Do/m_Do_graphic.h" +#include "m_Do/m_Do_machine.h" #include "d/actor/d_a_suspend.h" #include "d/actor/d_a_ykgr.h" #include "JSystem/JHostIO/JORFile.h" @@ -38,6 +39,8 @@ #include "JSystem/JKernel/JKRAram.h" #include "JSystem/JKernel/JKRAramArchive.h" +#include "dusk/memory.h" + #if DEBUG #include "d/d_s_menu.h" #include "d/d_debug_pad.h" @@ -1412,17 +1415,29 @@ static int phase_4(dScnPly_c* i_this) { dComIfGp_setPlayerPtr(i, NULL); } +#if TARGET_PC + dComIfGp_setWindow(0, 0.0f, 0.0f, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight(), 0.0f, + 1.0f, 0, 2); +#else dComIfGp_setWindow(0, 0.0f, 0.0f, FB_WIDTH, FB_HEIGHT, 0.0f, 1.0f, 0, 2); +#endif dComIfGp_setCameraInfo(0, NULL, 0, 0, -1); dComIfGd_setWindow(NULL); dComIfGd_setViewport(NULL); dComIfGd_setView(NULL); - JKRExpHeap* heap = fopMsgM_createExpHeap(0xBB800, NULL); + JKRExpHeap* heap = fopMsgM_createExpHeap(HEAP_SIZE(0xBB800, 0xF0000), NULL); +#if TARGET_PC + heap->setName("Scene2DHeap"); +#endif + JUT_ASSERT(2704, heap != NULL); dComIfGp_setExpHeap2D(heap); - JKRExpHeap* heap2 = fopMsgM_createExpHeap(0xA800, NULL); + JKRExpHeap* heap2 = fopMsgM_createExpHeap(HEAP_SIZE(0xA800, 0x15000), NULL); +#if TARGET_PC + heap2->setName("SceneMsgHeap"); +#endif JUT_ASSERT(2709, heap2 != NULL); dComIfGp_setMsgExpHeap(heap2); diff --git a/src/dusk/imgui.cpp b/src/dusk/imgui.cpp deleted file mode 100644 index f93428382c..0000000000 --- a/src/dusk/imgui.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include "dusk/imgui.h" -#include "imgui/imgui.hpp" - -#include -#include -#include -#include -#include - -#if _WIN32 -#include "Windows.h" -#endif - -static bool ImguiHidden = false; - -void imgui_main(const AuroraInfo *info) -{ - if (ImGui::IsKeyPressed(ImGuiKey_F1)) { - ImguiHidden = !ImguiHidden; - } - - if (ImguiHidden) { - return; - } - - if (ImGui::BeginMainMenuBar()) { - if (ImGui::BeginMenu(MenuView)) { - ImGui::MenuItem("Hide UI", "F1", &ImguiHidden); - ImGui::EndMenu(); - } - - DuskImguiDebugOverlay(info); - DuskImguiProcesses(); - DuskImguiHeaps(); - DuskCameraDebug(); - DuskDebugPad(); - - ImGui::EndMainMenuBar(); - } - -} - -class Limiter -{ - using delta_clock = std::chrono::high_resolution_clock; - using duration_t = std::chrono::nanoseconds; - - public: - void Reset() - { - m_oldTime = delta_clock::now(); - } - - void Sleep(duration_t targetFrameTime) - { - if (targetFrameTime.count() == 0) - { - return; - } - - auto start = delta_clock::now(); - duration_t adjustedSleepTime = SleepTime(targetFrameTime); - if (adjustedSleepTime.count() > 0) - { - NanoSleep(adjustedSleepTime); - duration_t overslept = TimeSince(start) - adjustedSleepTime; - if (overslept < duration_t{targetFrameTime}) - { - m_overheadTimes[m_overheadTimeIdx] = overslept; - m_overheadTimeIdx = (m_overheadTimeIdx + 1) % m_overheadTimes.size(); - } - } - Reset(); - } - - duration_t SleepTime(duration_t targetFrameTime) - { - const auto sleepTime = duration_t{targetFrameTime} - TimeSince(m_oldTime); - m_overhead = std::accumulate(m_overheadTimes.begin(), m_overheadTimes.end(), duration_t{}) / - m_overheadTimes.size(); - if (sleepTime > m_overhead) - { - return sleepTime - m_overhead; - } - return duration_t{0}; - } - - private: - delta_clock::time_point m_oldTime; - std::array m_overheadTimes{}; - size_t m_overheadTimeIdx = 0; - duration_t m_overhead = duration_t{0}; - - duration_t TimeSince(delta_clock::time_point start) - { - return std::chrono::duration_cast(delta_clock::now() - start); - } - -#if _WIN32 - bool m_initialized; - double m_countPerNs; - - void NanoSleep(const duration_t duration) - { - if (!m_initialized) - { - LARGE_INTEGER freq; - QueryPerformanceFrequency(&freq); - m_countPerNs = static_cast(freq.QuadPart) / 1000000000.0; - m_initialized = true; - } - - DWORD ms = std::chrono::duration_cast(duration).count(); - auto tickCount = - static_cast(static_cast(duration.count()) * m_countPerNs); - LARGE_INTEGER count; - QueryPerformanceCounter(&count); - if (ms > 10) - { - // Adjust for Sleep overhead - ::Sleep(ms - 10); - } - auto end = count.QuadPart + tickCount; - do - { - QueryPerformanceCounter(&count); - } while (count.QuadPart < end); - } -#else - void NanoSleep(const duration_t duration) - { - std::this_thread::sleep_for(duration); - } -#endif -}; - -static Limiter g_frameLimiter; -void frame_limiter() -{ - g_frameLimiter.Sleep( - std::chrono::duration_cast(std::chrono::seconds{1}) / 60); -} diff --git a/src/dusk/imgui/ImGuiCameraOverlay.cpp b/src/dusk/imgui/ImGuiCameraOverlay.cpp new file mode 100644 index 0000000000..564956a6d5 --- /dev/null +++ b/src/dusk/imgui/ImGuiCameraOverlay.cpp @@ -0,0 +1,107 @@ +#include "f_op/f_op_camera_mng.h" +#include "SSystem/SComponent/c_xyz.h" + +#include "imgui.h" +#include "ImGuiConsole.hpp" + +namespace dusk { + void ImGuiConsole::ShowCameraOverlay() { + if (!CheckMenuViewToggle(ImGuiKey_F6, m_showCameraOverlay)) { + return; + } + + auto* cam = (camera_process_class*)dCam_getCamera(); + + if (!m_showCameraOverlay || cam == nullptr) + return; + + auto* dCam = &cam->mCamera; + + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; + if (m_cameraOverlayCorner != -1) { + SetOverlayWindowLocation(m_cameraOverlayCorner); + windowFlags |= ImGuiWindowFlags_NoMove; + } + + ImGui::SetNextWindowBgAlpha(0.65f); + ImGui::SetNextWindowSizeConstraints(ImVec2(300, 0), ImVec2(FLT_MAX, FLT_MAX)); + + if (!ImGui::Begin("Camera Debug", nullptr, windowFlags)) { + ImGui::End(); + return; + } + + ImGui::SeparatorText("Camera Transform Data"); + + cXyz center = dCam->mCenter; + cXyz eye = dCam->mEye; + + if (ImGui::InputFloat3("Camera Center", ¢er.x)) { + dCam->Reset(center, eye); + } + if (ImGui::InputFloat3("Camera Eye", &eye.x)) { + dCam->Reset(center, eye); + } + + ImGui::InputFloat("Camera FOV", &dCam->mFovy); + + ImGui::SeparatorText("Free-look Data"); + + static float eyeYawDeg = 0.0f; + static float moveSpeed = 10000.0f; + static float rotSpeed = 5.0f; + static cXyz freeLookPos = cXyz::Zero; + + bool changed = false; + + if (ImGui::IsKeyDown(ImGuiKey_LeftArrow)) { + eyeYawDeg += rotSpeed; + if (eyeYawDeg >= 360.0f) + eyeYawDeg -= 360.0f; + + changed = true; + } + else if (ImGui::IsKeyDown(ImGuiKey_RightArrow)) { + eyeYawDeg -= rotSpeed; + if (eyeYawDeg < 0.0f) + eyeYawDeg += 360.0f; + + changed = true; + } + cSAngle yawAngle = cSAngle(eyeYawDeg); + cXyz frontDir = cXyz(yawAngle.Sin(), 0.0f, yawAngle.Cos()); + + if (ImGui::IsKeyDown(ImGuiKey_UpArrow)) { + freeLookPos -= frontDir * moveSpeed * ImGui::GetIO().DeltaTime; + changed = true; + } + else if (ImGui::IsKeyDown(ImGuiKey_DownArrow)) { + freeLookPos += frontDir * moveSpeed * ImGui::GetIO().DeltaTime; + changed = true; + } + + if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) { + freeLookPos += cXyz::BaseY * moveSpeed * ImGui::GetIO().DeltaTime; + changed = true; + } + + if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl)) { + freeLookPos -= cXyz::BaseY * moveSpeed * ImGui::GetIO().DeltaTime; + changed = true; + } + + if (changed) { + dCam->Reset(freeLookPos, freeLookPos + (frontDir * 100.0f)); + } + + ImGui::InputFloat("Free-look Yaw", &eyeYawDeg); + ImGui::InputFloat3("Free-look Position", &freeLookPos.x); + ImGui::InputFloat("Free-look Move Speed", &moveSpeed); + ImGui::InputFloat("Free-look Rotation Speed", &rotSpeed); + + ShowCornerContextMenu(m_cameraOverlayCorner, 0); + + ImGui::End(); + } +} \ No newline at end of file diff --git a/src/dusk/imgui/ImGuiConsole.cpp b/src/dusk/imgui/ImGuiConsole.cpp new file mode 100644 index 0000000000..99bf1d211c --- /dev/null +++ b/src/dusk/imgui/ImGuiConsole.cpp @@ -0,0 +1,322 @@ +#include +#include +#include +#include +#include + +#include "fmt/format.h" +#include "imgui.h" +#include "aurora/gfx.h" + +#include "ImGuiConsole.hpp" + +#include "JSystem/JUtility/JUTGamePad.h" + +#if _WIN32 +#include "Windows.h" +#endif + +using namespace std::string_literals; +using namespace std::string_view_literals; + +namespace dusk { + void ImGuiStringViewText(std::string_view text) { + // begin()/end() do not work on MSVC + ImGui::TextUnformatted(text.data(), text.data() + text.size()); + } + + std::string BytesToString(size_t bytes) { + constexpr std::array suffixes{ "B"sv, "KB"sv, "MB"sv, "GB"sv, "TB"sv, "PB"sv, "EB"sv }; + uint32_t s = 0; + auto count = static_cast(bytes); + while (count >= 1024.0 && s < 7) { + s++; + count /= 1024.0; + } + if (count - floor(count) == 0.0) + { + return fmt::format(FMT_STRING("{}{}"), static_cast(count), suffixes[s]); + } + return fmt::format(FMT_STRING("{:.1f}{}"), count, suffixes[s]); + } + + void SetOverlayWindowLocation(int corner) { + const ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImVec2 workPos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any! + ImVec2 workSize = viewport->WorkSize; + ImVec2 windowPos; + ImVec2 windowPosPivot; + constexpr float padding = 10.0f; + windowPos.x = (corner & 1) != 0 ? (workPos.x + workSize.x - padding) : (workPos.x + padding); + windowPos.y = (corner & 2) != 0 ? (workPos.y + workSize.y - padding) : (workPos.y + padding); + windowPosPivot.x = (corner & 1) != 0 ? 1.0f : 0.0f; + windowPosPivot.y = (corner & 2) != 0 ? 1.0f : 0.0f; + ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always, windowPosPivot); + } + + bool ShowCornerContextMenu(int& corner, int avoidCorner) { + bool result = false; + if (ImGui::BeginPopupContextWindow()) { + if (ImGui::MenuItem("Custom", nullptr, corner == -1)) { + corner = -1; + result = true; + } + if (ImGui::MenuItem("Top-left", nullptr, corner == 0, avoidCorner != 0)) { + corner = 0; + result = true; + } + if (ImGui::MenuItem("Top-right", nullptr, corner == 1, avoidCorner != 1)) { + corner = 1; + result = true; + } + if (ImGui::MenuItem("Bottom-left", nullptr, corner == 2, avoidCorner != 2)) { + corner = 2; + result = true; + } + if (ImGui::MenuItem("Bottom-right", nullptr, corner == 3, avoidCorner != 3)) { + corner = 3; + result = true; + } + ImGui::EndPopup(); + } + return result; + } + + ImGuiConsole g_imguiConsole; + + ImGuiConsole::ImGuiConsole() {} + + void ImGuiConsole::draw() { + if (CheckMenuViewToggle(ImGuiKey_F1, m_isHidden)) { + return; + } + + if (ImGui::BeginMainMenuBar()) { + if (ImGui::BeginMenu("View")) { + ImGui::MenuItem("Hide UI", "F1", &m_isHidden); + ImGui::MenuItem("Process Management", "F2", &m_showProcessManagement); + ImGui::MenuItem("Debug Overlay", "F3", &m_showDebugOverlay); + ImGui::MenuItem("Heaps", "F4", &m_showHeapOverlay); + ImGui::MenuItem("Stub Log", "F5", &m_showStubLog); + ImGui::MenuItem("Camera", "F6", &m_showCameraOverlay); + ImGui::MenuItem("Input Viewer", nullptr, &m_showInputViewer); + ImGui::MenuItem("Map Loader", nullptr, &m_showMapLoader); + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Game")) { + if (ImGui::Selectable("Reset")) { + JUTGamePad::C3ButtonReset::sResetSwitchPushing = true; + } + ImGui::EndMenu(); + } + + ShowDebugOverlay(); + ShowCameraOverlay(); + ShowProcessManager(); + ShowHeapOverlay(); + ShowInputViewer(); + ShowStubLog(); + ShowMapLoader(); + + DuskDebugPad(); // temporary, remove later + + ImGui::EndMainMenuBar(); + } + } + + void ImGuiConsole::ShowDebugOverlay() { + if (!CheckMenuViewToggle(ImGuiKey_F3, m_showDebugOverlay)) { + return; + } + + ImGuiIO& io = ImGui::GetIO(); + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | + ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoFocusOnAppearing | + ImGuiWindowFlags_NoNav; + if (m_debugOverlayCorner != -1) { + SetOverlayWindowLocation(m_debugOverlayCorner); + windowFlags |= ImGuiWindowFlags_NoMove; + } + + ImGui::SetNextWindowBgAlpha(0.65f); + if (ImGui::Begin("Debug Overlay", nullptr, windowFlags)) { + bool hasPrevious = false; + if (hasPrevious) { + ImGui::Separator(); + } + hasPrevious = true; + + ImGuiStringViewText(fmt::format(FMT_STRING("FPS: {:.2f}\n"), io.Framerate)); + + if (hasPrevious) { + ImGui::Separator(); + } + hasPrevious = true; + + ImGuiStringViewText(fmt::format(FMT_STRING("Backend: {}\n"), backend_name(aurora_get_backend()))); + + if (hasPrevious) { + ImGui::Separator(); + } + hasPrevious = true; + + AuroraStats const* stats = aurora_get_stats(); + + ImGuiStringViewText( + fmt::format(FMT_STRING("Queued pipelines: {}\n"), stats->queuedPipelines)); + ImGuiStringViewText( + fmt::format(FMT_STRING("Done pipelines: {}\n"), stats->createdPipelines)); + ImGuiStringViewText( + fmt::format(FMT_STRING("Draw call count: {}\n"), stats->drawCallCount)); + ImGuiStringViewText(fmt::format(FMT_STRING("Merged draw calls: {}\n"), + stats->mergedDrawCallCount)); + ImGuiStringViewText(fmt::format(FMT_STRING("Vertex size: {}\n"), + BytesToString(stats->lastVertSize))); + ImGuiStringViewText(fmt::format(FMT_STRING("Uniform size: {}\n"), + BytesToString(stats->lastUniformSize))); + ImGuiStringViewText(fmt::format(FMT_STRING("Index size: {}\n"), + BytesToString(stats->lastIndexSize))); + ImGuiStringViewText(fmt::format(FMT_STRING("Storage size: {}\n"), + BytesToString(stats->lastStorageSize))); + ImGuiStringViewText(fmt::format( + FMT_STRING("Total: {}\n"), + BytesToString(stats->lastVertSize + stats->lastUniformSize + + stats->lastIndexSize + stats->lastStorageSize))); + } + ImGui::End(); + } + + bool ImGuiConsole::CheckMenuViewToggle(ImGuiKey key, bool& active) { + if (ImGui::IsKeyPressed(key)) { + active = !active; + } + + return active; + } + + std::string_view backend_name(AuroraBackend backend) { + switch (backend) { + default: + return "Auto"sv; + case BACKEND_D3D12: + return "D3D12"sv; + case BACKEND_D3D11: + return "D3D11"sv; + case BACKEND_METAL: + return "Metal"sv; + case BACKEND_VULKAN: + return "Vulkan"sv; + case BACKEND_OPENGL: + return "OpenGL"sv; + case BACKEND_OPENGLES: + return "OpenGL ES"sv; + case BACKEND_WEBGPU: + return "WebGPU"sv; + case BACKEND_NULL: + return "Null"sv; + } + } +} + +class Limiter +{ + using delta_clock = std::chrono::high_resolution_clock; + using duration_t = std::chrono::nanoseconds; + +public: + void Reset() + { + m_oldTime = delta_clock::now(); + } + + void Sleep(duration_t targetFrameTime) + { + if (targetFrameTime.count() == 0) + { + return; + } + + auto start = delta_clock::now(); + duration_t adjustedSleepTime = SleepTime(targetFrameTime); + if (adjustedSleepTime.count() > 0) + { + NanoSleep(adjustedSleepTime); + duration_t overslept = TimeSince(start) - adjustedSleepTime; + if (overslept < duration_t{ targetFrameTime }) + { + m_overheadTimes[m_overheadTimeIdx] = overslept; + m_overheadTimeIdx = (m_overheadTimeIdx + 1) % m_overheadTimes.size(); + } + } + Reset(); + } + + duration_t SleepTime(duration_t targetFrameTime) + { + const auto sleepTime = duration_t{ targetFrameTime } - TimeSince(m_oldTime); + m_overhead = std::accumulate(m_overheadTimes.begin(), m_overheadTimes.end(), duration_t{}) / + m_overheadTimes.size(); + if (sleepTime > m_overhead) + { + return sleepTime - m_overhead; + } + return duration_t{ 0 }; + } + +private: + delta_clock::time_point m_oldTime; + std::array m_overheadTimes{}; + size_t m_overheadTimeIdx = 0; + duration_t m_overhead = duration_t{ 0 }; + + duration_t TimeSince(delta_clock::time_point start) + { + return std::chrono::duration_cast(delta_clock::now() - start); + } + +#if _WIN32 + bool m_initialized; + double m_countPerNs; + + void NanoSleep(const duration_t duration) + { + if (!m_initialized) + { + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + m_countPerNs = static_cast(freq.QuadPart) / 1000000000.0; + m_initialized = true; + } + + DWORD ms = std::chrono::duration_cast(duration).count(); + auto tickCount = + static_cast(static_cast(duration.count()) * m_countPerNs); + LARGE_INTEGER count; + QueryPerformanceCounter(&count); + if (ms > 10) + { + // Adjust for Sleep overhead + ::Sleep(ms - 10); + } + auto end = count.QuadPart + tickCount; + do + { + QueryPerformanceCounter(&count); + } while (count.QuadPart < end); + } +#else + void NanoSleep(const duration_t duration) + { + std::this_thread::sleep_for(duration); + } +#endif +}; + +static Limiter g_frameLimiter; +void frame_limiter() +{ + g_frameLimiter.Sleep( + std::chrono::duration_cast(std::chrono::seconds{ 1 }) / 60); +} diff --git a/src/dusk/imgui/ImGuiConsole.hpp b/src/dusk/imgui/ImGuiConsole.hpp new file mode 100644 index 0000000000..bf4c9075bd --- /dev/null +++ b/src/dusk/imgui/ImGuiConsole.hpp @@ -0,0 +1,67 @@ +#ifndef DUSK_IMGUI_HPP +#define DUSK_IMGUI_HPP + +#include +#include + +#include "imgui.h" + +namespace dusk { + class ImGuiConsole { + public: + ImGuiConsole(); + + void draw(); + + void ShowDebugOverlay(); + void ShowCameraOverlay(); + void ShowProcessManager(); + void ShowHeapOverlay(); + void ShowInputViewer(); + void ShowStubLog(); + void ShowMapLoader(); + + bool CheckMenuViewToggle(ImGuiKey key, bool& active); + + private: + bool m_isHidden = false; + + bool m_showDebugOverlay = false; + int m_debugOverlayCorner = 0; // top-left + + bool m_showCameraOverlay = false; + int m_cameraOverlayCorner = 3; + + bool m_showProcessManagement = false; + + bool m_showHeapOverlay = false; + + bool m_showStubLog = false; + + bool m_showInputViewer = false; + int m_inputOverlayCorner = 3; + std::string m_controllerName; + + bool m_showMapLoader = false; + struct { + int mapIdx = -1; + int regionIdx = -1; + int roomNoIdx = 0; + int roomNo = -1; + int spawnId = 0; + int layer = -1; + bool showInternalNames = false; + } m_mapLoaderInfo; + }; + + extern ImGuiConsole g_imguiConsole; + + std::string_view backend_name(AuroraBackend backend); + std::string BytesToString(size_t bytes); + void SetOverlayWindowLocation(int corner); + bool ShowCornerContextMenu(int& corner, int avoidCorner); +} + +void DuskDebugPad(); + +#endif // DUSK_IMGUI_HPP diff --git a/src/dusk/imgui/ImGuiControllerOverlay.cpp b/src/dusk/imgui/ImGuiControllerOverlay.cpp new file mode 100644 index 0000000000..87dbad8729 --- /dev/null +++ b/src/dusk/imgui/ImGuiControllerOverlay.cpp @@ -0,0 +1,274 @@ +#include "m_Do/m_Do_controller_pad.h" + +#include "imgui.h" +#include +#include "ImGuiConsole.hpp" + +namespace dusk { + void TextCenter(const std::string& text) { + float font_size = ImGui::GetFontSize() * text.size() / 2; + ImGui::SameLine(ImGui::GetWindowSize().x / 2 - font_size + (font_size / 2)); + + ImGui::TextUnformatted(text.c_str()); + } + + static inline float GetScale() { return ImGui::GetCurrentContext()->CurrentDpiScale; } + + void ImGuiConsole::ShowInputViewer() { + if (!m_showInputViewer) { + return; + } + + const char* controller_name = PADGetName(PAD_1); + if (controller_name != nullptr) { + m_controllerName = controller_name; + } + + ImGuiIO& io = ImGui::GetIO(); + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; + if (m_inputOverlayCorner != -1) { + SetOverlayWindowLocation(m_inputOverlayCorner); + windowFlags |= ImGuiWindowFlags_NoMove; + } + + ImGui::SetNextWindowBgAlpha(0.65f); + if (ImGui::Begin("Input Viewer", nullptr, windowFlags)) { + float scale = GetScale(); + if (!m_controllerName.empty()) { + TextCenter(m_controllerName); + ImGui::Separator(); + } + + ImDrawList* dl = ImGui::GetWindowDrawList(); + ImVec2 p = ImGui::GetCursorScreenPos(); + + // Left Stick vars + float leftStickRadius = 30 * scale; + p.x += 20 * scale; + p.y += 20 * scale; + ImVec2 leftStickCenter; + leftStickCenter.x = p.x + 30 * scale; + leftStickCenter.y = p.y + 45 * scale; + + // Right Stick vars + float rightStickRadius = 20 * scale; + ImVec2 rightStickCenter; + rightStickCenter.x = p.x + 160 * scale; + rightStickCenter.y = p.y + 90 * scale; + + // D-Pad vars + float dpadRadius = 15 * scale; + float dpadWidth = 8 * scale; + ImVec2 dpadCenter; + dpadCenter.x = p.x + 80 * scale; + dpadCenter.y = p.y + 90 * scale; + + // Start Button vars + float startButtonRadius = 5 * scale; + ImVec2 startButtonCenter; + startButtonCenter.x = p.x + 120 * scale; + startButtonCenter.y = p.y + 55 * scale; + + // A Button vars + float aButtonRadius = 16 * scale; + ImVec2 aButtonCenter; + aButtonCenter.x = p.x + 210 * scale; + aButtonCenter.y = p.y + 48 * scale; + + // B Button vars + float bButtonRadius = 8 * scale; + ImVec2 bButtonCenter; + bButtonCenter.x = aButtonCenter.x + -24 * scale; + bButtonCenter.y = aButtonCenter.y + 16 * scale; + + // X Button vars + ImVec2 xButtonRadius{ 7 * scale, 12 * scale}; + ImVec2 xButtonCenter; + xButtonCenter.x = aButtonCenter.x + 24 * scale; + xButtonCenter.y = aButtonCenter.y + -5 * scale; + + // Y Button vars + ImVec2 yButtonRadius{ 12 * scale, 7 * scale }; + ImVec2 yButtonCenter; + yButtonCenter.x = aButtonCenter.x + -8 * scale; + yButtonCenter.y = aButtonCenter.y + -24 * scale; + + // Trigger vars + float triggerWidth = leftStickRadius * 2; + float triggerHeight = 8 * scale; + ImVec2 lTrigCenter; + lTrigCenter.x = leftStickCenter.x + 0 * scale; + lTrigCenter.y = leftStickCenter.y + -60 * scale; + ImVec2 rTrigCenter; + rTrigCenter.x = aButtonCenter.x * scale; + rTrigCenter.y = lTrigCenter.y * scale; + + // Z Button vars + ImVec2 zButtonRadius{ 10 * scale, 5 * scale }; + ImVec2 zButtonCenter; + zButtonCenter.x = aButtonCenter.x + 18 * scale; + zButtonCenter.y = aButtonCenter.y + -30 * scale; + + const float zButtonHalfWidth = triggerWidth / 2; + const float zButtonHalfHeight = 4 * scale; + + constexpr ImU32 stickGray = IM_COL32(150, 150, 150, 255); + constexpr ImU32 darkGray = IM_COL32(60, 60, 60, 255); + constexpr ImU32 red = IM_COL32(230, 0, 0, 255); + constexpr ImU32 yellow = IM_COL32(255, 219, 109, 255); + constexpr ImU32 white = IM_COL32(255, 255, 255, 255); + constexpr ImU32 green = IM_COL32(0, 225, 255, 255); + constexpr ImU32 purple = IM_COL32(165, 75, 165, 255); + + // Draw Left Stick + { + float x = mDoCPd_c::getStickX(PAD_1); + float y = -mDoCPd_c::getStickY(PAD_1); + dl->AddCircleFilled(leftStickCenter, leftStickRadius, stickGray, 8); + + ImVec2 center; + center.x = leftStickCenter.x + x * (leftStickRadius / 2); + center.y = leftStickCenter.y + y * (leftStickRadius / 2); + dl->AddCircleFilled(center, leftStickRadius / 2, white); + } + + // Draw Right Stick + { + float x = mDoCPd_c::getSubStickX(PAD_1); + float y = -mDoCPd_c::getSubStickY(PAD_1); + dl->AddCircleFilled(rightStickCenter, rightStickRadius, stickGray, 8); + + ImVec2 center; + center.x = rightStickCenter.x + x * (rightStickRadius / 2); + center.y = rightStickCenter.y + y * (rightStickRadius / 2); + dl->AddCircleFilled(center, leftStickRadius / 3, yellow); + } + + // Draw D-Pad + { + float halfWidth = dpadWidth / 2; + { + ImVec2 pmin; + pmin.x = dpadCenter.x + -halfWidth; + pmin.y = dpadCenter.y + -dpadRadius; + ImVec2 pmax; + pmax.x = dpadCenter.x + halfWidth; + pmax.y = dpadCenter.y + dpadRadius; + dl->AddRectFilled(pmin, pmax, stickGray); + } + { + ImVec2 pmin; + pmin.x = dpadCenter.x + -dpadRadius; + pmin.y = dpadCenter.y + -halfWidth; + ImVec2 pmax; + pmax.x = dpadCenter.x + dpadRadius; + pmax.y = dpadCenter.y + halfWidth; + dl->AddRectFilled(pmin, pmax, stickGray); + } + + if (mDoCPd_c::getHoldUp(PAD_1)) { + ImVec2 pmin; + pmin.x = dpadCenter.x + -halfWidth; + pmin.y = dpadCenter.y + -dpadRadius; + ImVec2 pmax; + pmax.x = dpadCenter.x + halfWidth; + pmax.y = dpadCenter.y + -dpadRadius / 2; + dl->AddRectFilled(pmin, pmax, white); + } + if (mDoCPd_c::getHoldDown(PAD_1)) { + ImVec2 pmin; + pmin.x = dpadCenter.x + -halfWidth; + pmin.y = dpadCenter.y + dpadRadius; + ImVec2 pmax; + pmax.x = dpadCenter.x + halfWidth; + pmax.y = dpadCenter.y + dpadRadius / 2; + dl->AddRectFilled(pmin, pmax, white); + } + if (mDoCPd_c::getHoldLeft(PAD_1)) { + ImVec2 pmin; + pmin.x = dpadCenter.x + -dpadRadius; + pmin.y = dpadCenter.y + -halfWidth; + ImVec2 pmax; + pmax.x = dpadCenter.x + -dpadRadius / 2; + pmax.y = dpadCenter.y + halfWidth; + dl->AddRectFilled(pmin, pmax, white); + } + if (mDoCPd_c::getHoldRight(PAD_1)) { + ImVec2 pmin; + pmin.x = dpadCenter.x + dpadRadius; + pmin.y = dpadCenter.y + -halfWidth; + ImVec2 pmax; + pmax.x = dpadCenter.x + dpadRadius / 2; + pmax.y = dpadCenter.y + halfWidth; + dl->AddRectFilled(pmin, pmax, white); + } + } + + // Draw Buttons + { + // start + dl->AddCircleFilled(startButtonCenter, startButtonRadius, mDoCPd_c::getHoldStart(PAD_1) ? white : stickGray); + + // a + dl->AddCircleFilled(aButtonCenter, aButtonRadius, mDoCPd_c::getHoldA(PAD_1) ? green : stickGray); + + // b + dl->AddCircleFilled(bButtonCenter, bButtonRadius, mDoCPd_c::getHoldB(PAD_1) ? red : stickGray); + + // x + dl->AddEllipseFilled(xButtonCenter, xButtonRadius, mDoCPd_c::getHoldX(PAD_1) ? white : stickGray, 25); + + // y + dl->AddEllipseFilled(yButtonCenter, yButtonRadius, mDoCPd_c::getHoldY(PAD_1) ? white : stickGray, 25); + + // z + dl->AddEllipseFilled(zButtonCenter, zButtonRadius, mDoCPd_c::getHoldZ(PAD_1) ? purple : stickGray, 35); + } + + // Draw Triggers + { + float halfTriggerWidth = triggerWidth / 2; + ImVec2 lStart; + lStart.x = lTrigCenter.x - halfTriggerWidth; + lStart.y = lTrigCenter.y - 0; + ImVec2 lEnd; + lEnd.x = lTrigCenter.x + halfTriggerWidth; + lEnd.y = lTrigCenter.y + triggerHeight; + + float lValue = triggerWidth * std::min(1.f, mDoCPd_c::getAnalogL(PAD_1)); + ImVec2 p2; + p2.x = lStart.x + lValue; + p2.y = lStart.y + triggerHeight; + dl->AddRectFilled(lStart, p2, mDoCPd_c::getHoldL(PAD_1) ? IM_COL32(0, 225, 0, 255) : white); + p2.x = lStart.x + lValue; + p2.y = lStart.y; + dl->AddRectFilled(p2, lEnd, darkGray); + + ImVec2 rStart; + rStart.x = rTrigCenter.x - halfTriggerWidth; + rStart.y = rTrigCenter.y - 0; + ImVec2 rEnd; + rEnd.x = rTrigCenter.x + halfTriggerWidth; + rEnd.y = rTrigCenter.y + triggerHeight; + + float rValue = triggerWidth * std::min(1.f, mDoCPd_c::getAnalogR(PAD_1)); + p2.x = rEnd.x - rValue; + p2.y = rEnd.y - triggerHeight; + dl->AddRectFilled(p2, rEnd, mDoCPd_c::getHoldR(PAD_1) ? IM_COL32(0, 225, 0, 255) : white); + p2.x = rEnd.x - rValue; + p2.y = rEnd.y; + dl->AddRectFilled(rStart, p2, darkGray); + } + + ImVec2 size; + size.x = 270 * scale; + size.y = 130 * scale; + ImGui::Dummy(size); + + ShowCornerContextMenu(m_inputOverlayCorner, 0); + } + + ImGui::End(); + } +} // namespace dusk \ No newline at end of file diff --git a/src/dusk/imgui/kb_pad.cpp b/src/dusk/imgui/ImGuiDebugPad.cpp similarity index 98% rename from src/dusk/imgui/kb_pad.cpp rename to src/dusk/imgui/ImGuiDebugPad.cpp index 42816a40e8..114bee5a35 100644 --- a/src/dusk/imgui/kb_pad.cpp +++ b/src/dusk/imgui/ImGuiDebugPad.cpp @@ -1,7 +1,7 @@ #include "m_Do/m_Do_controller_pad.h" #include "imgui.h" -#include "imgui.hpp" +#include "ImGuiConsole.hpp" void DuskDebugPad() { if (ImGui::IsKeyPressed(ImGuiKey_K)) { diff --git a/src/dusk/imgui/ImGuiHeapOverlay.cpp b/src/dusk/imgui/ImGuiHeapOverlay.cpp new file mode 100644 index 0000000000..d2660af6eb --- /dev/null +++ b/src/dusk/imgui/ImGuiHeapOverlay.cpp @@ -0,0 +1,102 @@ +#include + +#include "JSystem/JFramework/JFWSystem.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "imgui.h" +#include "ImGuiConsole.hpp" + +namespace dusk { + static void DrawTableCore(); + + void ImGuiConsole::ShowHeapOverlay() { + if (!CheckMenuViewToggle(ImGuiKey_F4, m_showHeapOverlay)) { + return; + } + + if (ImGui::Begin("Heaps", &m_showHeapOverlay)) { + if (ImGui::BeginTable( + "heaps", + 5, + ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable)) { + + DrawTableCore(); + + ImGui::EndTable(); + } + } + + ImGui::End(); + } + + static void DrawHeap(JKRHeap* heap, int depth = 0); + + static void DrawTableCore() { + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("Heap name"); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("Use%"); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("Available"); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("Total"); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("Type"); + + DrawHeap(reinterpret_cast(JFWSystem::rootHeap)); + } + + static std::array GetHeapType(JKRHeap* heap) { + auto type = heap->getHeapType(); + + return { + (char)(type >> 24 & 0xFF), + (char)(type >> 16 & 0xFF), + (char)(type >> 8 & 0xFF), + (char)(type >> 0 & 0xFF), + }; + } + + static const char* GetHeapName(const JKRHeap* heap) { + const auto name = heap->getName(); + if (strlen(name) == 0) { + return "Unknown"; + } + + return name; + } + + static void DrawHeap(JKRHeap* heap, const int depth) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + + auto indentSize = depth * 16; + if (indentSize != 0) + ImGui::Indent(indentSize); + ImGui::TextUnformatted(GetHeapName(heap)); + if (indentSize != 0) + ImGui::Unindent(indentSize); + + ImGui::TableNextColumn(); + ImGui::ProgressBar( + 1 - (f32)heap->getFreeSize() / (f32)heap->getSize(), + ImVec2(ImGui::GetContentRegionAvail().x, 0)); + + ImGui::TableNextColumn(); + auto freeSizeString = BytesToString(heap->getFreeSize()); + ImGui::TextUnformatted(freeSizeString.c_str()); + + ImGui::TableNextColumn(); + auto totalSizeString = BytesToString(heap->getSize()); + ImGui::TextUnformatted(totalSizeString.c_str()); + + ImGui::TableNextColumn(); + auto typeString = GetHeapType(heap); + ImGui::TextUnformatted(typeString.data(), typeString.data() + 4); + + const JSUTree& tree = heap->getHeapTree(); + for (JSUTreeIterator iter(tree.getFirstChild()); iter != tree.getEndChild(); ++iter) { + DrawHeap(*iter, depth + 1); + } + } +} \ No newline at end of file diff --git a/src/dusk/imgui/ImGuiMapLoader.cpp b/src/dusk/imgui/ImGuiMapLoader.cpp new file mode 100644 index 0000000000..50ce3925cf --- /dev/null +++ b/src/dusk/imgui/ImGuiMapLoader.cpp @@ -0,0 +1,100 @@ +#include "d/d_com_inf_game.h" + +#include "imgui.h" +#include +#include "ImGuiConsole.hpp" +#include "dusk/map_loader_definitions.h" + +namespace dusk { + void ImGuiConsole::ShowMapLoader() { + if (!m_showMapLoader) { + return; + } + + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; + + ImGui::SetNextWindowBgAlpha(0.65f); + ImGui::SetNextWindowSizeConstraints(ImVec2(300, 0), ImVec2(FLT_MAX, FLT_MAX)); + + if (!ImGui::Begin("Map Loader", nullptr, windowFlags)) { + ImGui::End(); + return; + } + + ImGui::SeparatorText("Map Loader"); + + ImGui::Checkbox("Show Internal Names", &m_mapLoaderInfo.showInternalNames); + + const char* previewRegion = "None"; + if (m_mapLoaderInfo.regionIdx != -1) { + previewRegion = gameRegions[m_mapLoaderInfo.regionIdx].regionName; + } + + if (ImGui::BeginCombo("Select Region", previewRegion)) { + int idx = 0; + for (const auto& region : gameRegions) { + if (ImGui::Selectable(region.regionName)) { + m_mapLoaderInfo.regionIdx = idx; + m_mapLoaderInfo.mapIdx = -1; + } + idx++; + } + ImGui::EndCombo(); + } + + if (m_mapLoaderInfo.regionIdx != -1) { + const auto& region = gameRegions[m_mapLoaderInfo.regionIdx]; + + std::string previewMap = "None"; + if (m_mapLoaderInfo.mapIdx != -1) { + const auto& map = region.maps[m_mapLoaderInfo.mapIdx]; + previewMap = m_mapLoaderInfo.showInternalNames ? fmt::format("{} ({})", map.mapName, map.mapFile) : map.mapName; + } + + if (ImGui::BeginCombo("Select Map", previewMap.data())) { + for (int i = 0; i < region.numMaps; ++i) { + const auto& map = region.maps[i]; + std::string label = m_mapLoaderInfo.showInternalNames ? fmt::format("{} ({})", map.mapName, map.mapFile) : map.mapName; + if (ImGui::Selectable(label.data())) { + m_mapLoaderInfo.mapIdx = i; + } + } + ImGui::EndCombo(); + } + }else { + ImGui::Text("No region selected."); + } + + if (m_mapLoaderInfo.regionIdx != -1 && m_mapLoaderInfo.mapIdx != -1) { + const auto& region = gameRegions[m_mapLoaderInfo.regionIdx]; + const auto& map = region.maps[m_mapLoaderInfo.mapIdx]; + + if (map.numRooms > 0) { + ImGui::Text("Selected Room: %d", map.mapRooms[m_mapLoaderInfo.roomNoIdx]); + ImGui::SameLine(); + if (ImGui::Button("-###RoomNoIdxDec")) { + m_mapLoaderInfo.roomNoIdx--; + if (m_mapLoaderInfo.roomNoIdx < 0) { + m_mapLoaderInfo.roomNoIdx = 0; + } + } + ImGui::SameLine(); + if (ImGui::Button("+###RoomNoIdxInc")) { + m_mapLoaderInfo.roomNoIdx++; + if (m_mapLoaderInfo.roomNoIdx >= map.numRooms) { + m_mapLoaderInfo.roomNoIdx = map.numRooms - 1; + } + } + } + + if (ImGui::Button("Warp")) { + dComIfGp_setNextStage(map.mapFile, 0, map.mapRooms[m_mapLoaderInfo.roomNoIdx], -1); + } + } + + + ImGui::End(); + } + + } // namespace dusk diff --git a/src/dusk/imgui/ImGuiProcessOverlay.cpp b/src/dusk/imgui/ImGuiProcessOverlay.cpp new file mode 100644 index 0000000000..24d1015603 --- /dev/null +++ b/src/dusk/imgui/ImGuiProcessOverlay.cpp @@ -0,0 +1,102 @@ +#define PROCS_DUMP_NAMES 1 + +#include + +#include "d/d_procname.h" +#include "f_pc/f_pc_create_iter.h" +#include "f_pc/f_pc_create_req.h" +#include "f_pc/f_pc_layer.h" +#include "f_pc/f_pc_layer_iter.h" +#include "f_pc/f_pc_leaf.h" +#include "f_pc/f_pc_node.h" +#include "imgui.h" +#include "ImGuiConsole.hpp" +#include "imgui_internal.h" + +namespace dusk { + bool showTreeRecursive; + + static int ShowProcess(void* p, void*) { + auto proc = static_cast(p); + + char buf[64]; + snprintf(buf, sizeof(buf), "%d", proc->id); + + ImVec2 avail = ImGui::GetContentRegionAvail(); + + ImVec2 vec = { avail.x, 0 }; + if (ImGui::BeginChild(buf, vec, ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY)) { + ImGui::Text("[%d] %s", proc->id, GetProcName(proc->profname)); + ImGui::Text("init_state: %d, create_phase: %d", proc->state.init_state, proc->state.create_phase); + + const char* ofTypeName = "unknown"; + if (proc->subtype == g_fpcNd_type) { + ofTypeName = "Node"; + } + else if (proc->subtype == g_fpcLf_type) { + ofTypeName = "Leaf"; + } + + ImGui::Text("OfType: %d (%s), layer: %d", proc->subtype, ofTypeName, proc->layer_tag.layer->layer_id); + + if (proc->create_req != nullptr) { + ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Pending create request"); + } + + if (showTreeRecursive) { + if (fpcBs_Is_JustOfType(g_fpcNd_type, proc->subtype)) { + auto procNode = static_cast(p); + + ImGui::Text("Owns layer %d", procNode->layer.layer_id); + + fpcLyIt_OnlyHere(&procNode->layer, ShowProcess, nullptr); + } + } + } + + ImGui::EndChild(); + return 1; + } + + static int ShowCreateRequest(void* p, void*) { + create_request* req = (create_request*)p; + + if (req->process != nullptr) { + ShowProcess(req->process, nullptr); + } + + return 1; + } + + void ImGuiConsole::ShowProcessManager() { + if (!CheckMenuViewToggle(ImGuiKey_F2, m_showProcessManagement)) { + return; + } + + if (ImGui::Begin("Processes")) { + if (ImGui::BeginTabBar("Tabs")) { + showTreeRecursive = true; + if (ImGui::BeginTabItem("Tree")) { + fpcLyIt_OnlyHere(fpcLy_RootLayer(), ShowProcess, nullptr); + ImGui::EndTabItem(); + } + + showTreeRecursive = false; + if (ImGui::BeginTabItem("All layers")) { + fpcLyIt_All(ShowProcess, nullptr); + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem("Creation queue")) { + fpcCtIt_Method(ShowCreateRequest, nullptr); + + ImGui::EndTabItem(); + } + + ImGui::EndTabBar(); + } + } + + ImGui::End(); + } +} \ No newline at end of file diff --git a/src/dusk/imgui/ImGuiStubLog.cpp b/src/dusk/imgui/ImGuiStubLog.cpp new file mode 100644 index 0000000000..774ad3f7cc --- /dev/null +++ b/src/dusk/imgui/ImGuiStubLog.cpp @@ -0,0 +1,84 @@ +#include + +#include "dusk/logging.h" +#include "imgui.h" +#include "ImGuiConsole.hpp" + +namespace dusk { + static ImGuiTextBuffer StubLogBuffer; + static std::vector LineOffsets; + static bool StubLogPaused; + + const char* LogLevelName(const AuroraLogLevel level) { + switch (level) { + case LOG_DEBUG: + return "DEBUG"; + case LOG_INFO: + return "INFO"; + case LOG_WARNING: + return "WARNING"; + case LOG_ERROR: + return "ERROR"; + case LOG_FATAL: + return "FATAL"; + default: + return "UNKNOWN"; + } + } + + void SendToStubLog(AuroraLogLevel level, const char* module, const char* message) { + if (StubLogPaused) { + return; + } + + LineOffsets.push_back(StubLogBuffer.size()); + const auto levelName = LogLevelName(level); + StubLogBuffer.appendf("[%s | %s] %s\n", levelName, module, message); + } + + static void ClearPastFrame(); + + void ImGuiConsole::ShowStubLog() { + if (!CheckMenuViewToggle(ImGuiKey_F5, m_showStubLog)) { + ClearPastFrame(); + return; + } + + if (ImGui::Begin("Stub log", &m_showStubLog)) { + ImGui::Checkbox("Redirect stub log", &StubLogEnabled); + ImGui::SameLine(); + ImGui::Checkbox("Pause", &StubLogPaused); + + ImGui::Text("Line count (this frame): %llu", LineOffsets.size()); + + ImGui::Separator(); + + if (ImGui::BeginChild("scrolling")) { + ImGuiListClipper clipper; + clipper.Begin(LineOffsets.size()); + while (clipper.Step()) { + for (int idx = clipper.DisplayStart; idx < clipper.DisplayEnd; idx++) { + const char* lineStart = StubLogBuffer.begin() + LineOffsets[idx]; + const char* lineEnd = idx == LineOffsets.size() - 1 ? StubLogBuffer.end() : StubLogBuffer.begin() + LineOffsets[idx + 1]; + ImGui::TextUnformatted(lineStart, lineEnd); + } + } + + clipper.End(); + } + + ImGui::EndChild(); + } + + ImGui::End(); + ClearPastFrame(); + } + + void ClearPastFrame() { + if (StubLogPaused) { + return; + } + StubLogBuffer.clear(); + LineOffsets.clear(); + } +} \ No newline at end of file diff --git a/src/dusk/imgui/camera.cpp b/src/dusk/imgui/camera.cpp deleted file mode 100644 index 5edc26f905..0000000000 --- a/src/dusk/imgui/camera.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "f_op/f_op_camera_mng.h" -#include "SSystem/SComponent/c_xyz.h" - -#include "imgui.h" -#include "imgui.hpp" - -static bool Active = false; -static int m_cameraOverlayCorner = 3; - -void DuskCameraDebug() { - if (ImGui::BeginMenu(MenuView)) { - ImGui::MenuItem("Camera", "F6", &Active); - - ImGui::EndMenu(); - } - - if (ImGui::IsKeyPressed(ImGuiKey_F6)) { - Active = !Active; - } - - auto* cam = (camera_process_class*)dCam_getCamera(); - - if (!Active || cam == nullptr) - return; - - auto* dCam = &cam->mCamera; - - ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; - if (m_cameraOverlayCorner != -1) { - SetOverlayWindowLocation(m_cameraOverlayCorner); - windowFlags |= ImGuiWindowFlags_NoMove; - } - - ImGui::SetNextWindowBgAlpha(0.65f); - ImGui::SetNextWindowSizeConstraints(ImVec2(300, 0), ImVec2(FLT_MAX, FLT_MAX)); - - if (!ImGui::Begin("Camera Debug", nullptr, windowFlags)) { - ImGui::End(); - return; - } - - ImGui::SeparatorText("Camera Transform Data"); - - cXyz center = dCam->mCenter; - cXyz eye = dCam->mEye; - - if (ImGui::InputFloat3("Camera Center", ¢er.x)) { - dCam->Reset(center, eye); - } - if (ImGui::InputFloat3("Camera Eye", &eye.x)) { - dCam->Reset(center, eye); - } - - ImGui::InputFloat("Camera FOV", &dCam->mFovy); - - ImGui::SeparatorText("Free-look Data"); - - static float eyeYawDeg = 0.0f; - static float moveSpeed = 10000.0f; - static float rotSpeed = 5.0f; - static cXyz freeLookPos = cXyz::Zero; - - bool changed = false; - - if (ImGui::IsKeyDown(ImGuiKey_LeftArrow)) { - eyeYawDeg += rotSpeed; - if (eyeYawDeg >= 360.0f) - eyeYawDeg -= 360.0f; - - changed = true; - } else if (ImGui::IsKeyDown(ImGuiKey_RightArrow)) { - eyeYawDeg -= rotSpeed; - if (eyeYawDeg < 0.0f) - eyeYawDeg += 360.0f; - - changed = true; - } - cSAngle yawAngle = cSAngle(eyeYawDeg); - cXyz frontDir = cXyz(yawAngle.Sin(), 0.0f, yawAngle.Cos()); - - if (ImGui::IsKeyDown(ImGuiKey_UpArrow)) { - freeLookPos -= frontDir * moveSpeed * ImGui::GetIO().DeltaTime; - changed = true; - } else if (ImGui::IsKeyDown(ImGuiKey_DownArrow)) { - freeLookPos += frontDir * moveSpeed * ImGui::GetIO().DeltaTime; - changed = true; - } - - if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) { - freeLookPos += cXyz::BaseY * moveSpeed * ImGui::GetIO().DeltaTime; - changed = true; - } - - if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl)) { - freeLookPos -= cXyz::BaseY * moveSpeed * ImGui::GetIO().DeltaTime; - changed = true; - } - - if (changed) { - dCam->Reset(freeLookPos, freeLookPos + (frontDir * 100.0f)); - } - - ImGui::InputFloat("Free-look Yaw", &eyeYawDeg); - ImGui::InputFloat3("Free-look Position", &freeLookPos.x); - ImGui::InputFloat("Free-look Move Speed", &moveSpeed); - ImGui::InputFloat("Free-look Rotation Speed", &rotSpeed); - - ShowCornerContextMenu(m_cameraOverlayCorner, 0); - - ImGui::End(); -} \ No newline at end of file diff --git a/src/dusk/imgui/debug_overlay.cpp b/src/dusk/imgui/debug_overlay.cpp deleted file mode 100644 index 4e9fb02540..0000000000 --- a/src/dusk/imgui/debug_overlay.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include -#include - -#include "fmt/format.h" -#include "imgui.h" -#include "aurora/gfx.h" - -#include "aurora/gfx.h" -#include "imgui.hpp" - -static bool m_frameRate = true; -static bool m_pipelineInfo = true; -static bool m_graphicsBackend = true; -static int m_debugOverlayCorner = 0; // top-left - -using namespace std::string_literals; -using namespace std::string_view_literals; - -void SetOverlayWindowLocation(int corner) -{ - const ImGuiViewport *viewport = ImGui::GetMainViewport(); - ImVec2 workPos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any! - ImVec2 workSize = viewport->WorkSize; - ImVec2 windowPos; - ImVec2 windowPosPivot; - constexpr float padding = 10.0f; - windowPos.x = (corner & 1) != 0 ? (workPos.x + workSize.x - padding) : (workPos.x + padding); - windowPos.y = (corner & 2) != 0 ? (workPos.y + workSize.y - padding) : (workPos.y + padding); - windowPosPivot.x = (corner & 1) != 0 ? 1.0f : 0.0f; - windowPosPivot.y = (corner & 2) != 0 ? 1.0f : 0.0f; - ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always, windowPosPivot); -} - -bool ShowCornerContextMenu(int& corner, int avoidCorner) { - bool result = false; - if (ImGui::BeginPopupContextWindow()) { - if (ImGui::MenuItem("Custom", nullptr, corner == -1)) { - corner = -1; - result = true; - } - if (ImGui::MenuItem("Top-left", nullptr, corner == 0, avoidCorner != 0)) { - corner = 0; - result = true; - } - if (ImGui::MenuItem("Top-right", nullptr, corner == 1, avoidCorner != 1)) { - corner = 1; - result = true; - } - if (ImGui::MenuItem("Bottom-left", nullptr, corner == 2, avoidCorner != 2)) { - corner = 2; - result = true; - } - if (ImGui::MenuItem("Bottom-right", nullptr, corner == 3, avoidCorner != 3)) { - corner = 3; - result = true; - } - ImGui::EndPopup(); - } - return result; -} - -static void ImGuiStringViewText(std::string_view text) -{ - // begin()/end() do not work on MSVC - ImGui::TextUnformatted(text.data(), text.data() + text.size()); -} - -std::string BytesToString(size_t bytes) -{ - constexpr std::array suffixes{"B"sv, "KB"sv, "MB"sv, "GB"sv, "TB"sv, "PB"sv, "EB"sv}; - uint32_t s = 0; - auto count = static_cast(bytes); - while (count >= 1024.0 && s < 7) - { - s++; - count /= 1024.0; - } - if (count - floor(count) == 0.0) - { - return fmt::format(FMT_STRING("{}{}"), static_cast(count), suffixes[s]); - } - return fmt::format(FMT_STRING("{:.1f}{}"), count, suffixes[s]); -} - -static bool Active = false; - -void DuskImguiDebugOverlay(const AuroraInfo *info) { - if (ImGui::BeginMenu(MenuView)) { - ImGui::MenuItem("Debug overlay", "F3", &Active); - - ImGui::EndMenu(); - } - - if (ImGui::IsKeyPressed(ImGuiKey_F3)) { - Active = !Active; - } - - if (!Active) { - return; - } - - ImGuiIO &io = ImGui::GetIO(); - ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | - ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; - if (m_debugOverlayCorner != -1) - { - SetOverlayWindowLocation(m_debugOverlayCorner); - windowFlags |= ImGuiWindowFlags_NoMove; - } - ImGui::SetNextWindowBgAlpha(0.65f); - if (ImGui::Begin("Debug Overlay", nullptr, windowFlags)) - { - bool hasPrevious = false; - if (m_frameRate) - { - if (hasPrevious) - { - ImGui::Separator(); - } - hasPrevious = true; - - ImGuiStringViewText(fmt::format(FMT_STRING("FPS: {:.1f}\n"), io.Framerate)); - } - if (m_graphicsBackend) - { - if (hasPrevious) - { - ImGui::Separator(); - } - hasPrevious = true; - - std::string_view backendString = "Unknown"sv; - switch (info->backend) - { - case BACKEND_AUTO: - backendString = "Auto"sv; - break; - case BACKEND_D3D11: - backendString = "D3D11"sv; - break; - case BACKEND_D3D12: - backendString = "D3D12"sv; - break; - case BACKEND_METAL: - backendString = "Metal"sv; - break; - case BACKEND_VULKAN: - backendString = "Vulkan"sv; - break; - case BACKEND_OPENGL: - backendString = "OpenGL"sv; - break; - case BACKEND_OPENGLES: - backendString = "OpenGL ES"sv; - break; - case BACKEND_WEBGPU: - backendString = "WebGPU"sv; - break; - case BACKEND_NULL: - backendString = "Null"sv; - break; - } - ImGuiStringViewText(fmt::format(FMT_STRING("Backend: {}\n"), backendString)); - } - if (m_pipelineInfo) - { - if (hasPrevious) - { - ImGui::Separator(); - } - hasPrevious = true; - - AuroraStats const* stats = aurora_get_stats(); - - ImGuiStringViewText( - fmt::format(FMT_STRING("Queued pipelines: {}\n"), stats->queuedPipelines)); - ImGuiStringViewText( - fmt::format(FMT_STRING("Done pipelines: {}\n"), stats->createdPipelines)); - ImGuiStringViewText( - fmt::format(FMT_STRING("Draw call count: {}\n"), stats->drawCallCount)); - ImGuiStringViewText(fmt::format(FMT_STRING("Merged draw calls: {}\n"), - stats->mergedDrawCallCount)); - ImGuiStringViewText(fmt::format(FMT_STRING("Vertex size: {}\n"), - BytesToString(stats->lastVertSize))); - ImGuiStringViewText(fmt::format(FMT_STRING("Uniform size: {}\n"), - BytesToString(stats->lastUniformSize))); - ImGuiStringViewText(fmt::format(FMT_STRING("Index size: {}\n"), - BytesToString(stats->lastIndexSize))); - ImGuiStringViewText(fmt::format(FMT_STRING("Storage size: {}\n"), - BytesToString(stats->lastStorageSize))); - ImGuiStringViewText(fmt::format( - FMT_STRING("Total: {}\n"), - BytesToString(stats->lastVertSize + stats->lastUniformSize + - stats->lastIndexSize + stats->lastStorageSize))); - } - } - ImGui::End(); -} diff --git a/src/dusk/imgui/heaps.cpp b/src/dusk/imgui/heaps.cpp deleted file mode 100644 index aa4de04ba3..0000000000 --- a/src/dusk/imgui/heaps.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include - -#include "JSystem/JFramework/JFWSystem.h" -#include "JSystem/JKernel/JKRHeap.h" -#include "imgui.h" -#include "imgui.hpp" - -static bool Active = false; - -static void DrawTableCore(); - -void DuskImguiHeaps() { - if (ImGui::BeginMenu(MenuView)) { - ImGui::MenuItem("Heaps", "F4", &Active); - - ImGui::EndMenu(); - } - - if (ImGui::IsKeyPressed(ImGuiKey_F4)) { - Active = !Active; - } - - if (!Active) { - return; - } - - if (ImGui::Begin("Heaps", &Active)) { - if (ImGui::BeginTable( - "heaps", - 5, - ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable)) { - - DrawTableCore(); - - ImGui::EndTable(); - } - } - - ImGui::End(); -} - -static void DrawHeap(JKRHeap* heap, int depth = 0); - -static void DrawTableCore() { - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - ImGui::TableNextColumn(); - ImGui::TextUnformatted("Heap name"); - ImGui::TableNextColumn(); - ImGui::TextUnformatted("Use%"); - ImGui::TableNextColumn(); - ImGui::TextUnformatted("Available"); - ImGui::TableNextColumn(); - ImGui::TextUnformatted("Total"); - ImGui::TableNextColumn(); - ImGui::TextUnformatted("Type"); - - DrawHeap(reinterpret_cast(JFWSystem::rootHeap)); -} - -static std::array GetHeapType(JKRHeap* heap) { - auto type = heap->getHeapType(); - - return { - (char)(type >> 24 & 0xFF), - (char)(type >> 16 & 0xFF), - (char)(type >> 8 & 0xFF), - (char)(type >> 0 & 0xFF), - }; -} - -static const char* GetHeapName(const JKRHeap* heap) { - const auto name = heap->getName(); - if (strlen(name) == 0) { - return "Unknown"; - } - - return name; -} - -static void DrawHeap(JKRHeap* heap, const int depth) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - - auto indentSize = depth * 16; - if (indentSize != 0) - ImGui::Indent(indentSize); - ImGui::TextUnformatted(GetHeapName(heap)); - if (indentSize != 0) - ImGui::Unindent(indentSize); - - ImGui::TableNextColumn(); - ImGui::ProgressBar( - 1 - (f32)heap->getFreeSize() / (f32)heap->getSize(), - ImVec2(ImGui::GetContentRegionAvail().x, 0)); - - ImGui::TableNextColumn(); - auto freeSizeString = BytesToString(heap->getFreeSize()); - ImGui::TextUnformatted(freeSizeString.c_str()); - - ImGui::TableNextColumn(); - auto totalSizeString = BytesToString(heap->getSize()); - ImGui::TextUnformatted(totalSizeString.c_str()); - - ImGui::TableNextColumn(); - auto typeString = GetHeapType(heap); - ImGui::TextUnformatted(typeString.data(), typeString.data() + 4); - - const JSUTree& tree = heap->getHeapTree(); - for (JSUTreeIterator iter(tree.getFirstChild()); iter != tree.getEndChild(); ++iter) { - DrawHeap(*iter, depth + 1); - } -} \ No newline at end of file diff --git a/src/dusk/imgui/imgui.hpp b/src/dusk/imgui/imgui.hpp deleted file mode 100644 index 1a66d670a7..0000000000 --- a/src/dusk/imgui/imgui.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef DUSK_IMGUI_HPP -#define DUSK_IMGUI_HPP - -#include -#include - -inline const char* MenuView = "View"; - -void DuskImguiDebugOverlay(const AuroraInfo *info); -void DuskImguiProcesses(); -void DuskImguiHeaps(); -void DuskCameraDebug(); -void DuskDebugPad(); - -void SetOverlayWindowLocation(int corner); -bool ShowCornerContextMenu(int& corner, int avoidCorner); - -std::string BytesToString(size_t bytes); - -#endif // DUSK_IMGUI_HPP diff --git a/src/dusk/imgui/processes.cpp b/src/dusk/imgui/processes.cpp deleted file mode 100644 index 7bbaeaf26e..0000000000 --- a/src/dusk/imgui/processes.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#define PROCS_DUMP_NAMES 1 - -#include - -#include "d/d_procname.h" -#include "f_pc/f_pc_create_iter.h" -#include "f_pc/f_pc_create_req.h" -#include "f_pc/f_pc_layer.h" -#include "f_pc/f_pc_layer_iter.h" -#include "f_pc/f_pc_leaf.h" -#include "f_pc/f_pc_node.h" -#include "imgui.h" -#include "imgui.hpp" -#include "imgui_internal.h" - -bool showTreeRecursive; - -static int ShowProcess(void* p, void*) { - auto proc = static_cast(p); - - char buf[64]; - snprintf(buf, sizeof(buf), "%d", proc->id); - - ImVec2 avail = ImGui::GetContentRegionAvail(); - - ImVec2 vec = {avail.x, 0}; - if (ImGui::BeginChild(buf, vec, ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY)) { - ImGui::Text("[%d] %s", proc->id, GetProcName(proc->profname)); - ImGui::Text("init_state: %d, create_phase: %d", proc->state.init_state, proc->state.create_phase); - - const char* ofTypeName = "unknown"; - if (proc->subtype == g_fpcNd_type) { - ofTypeName = "Node"; - } else if (proc->subtype == g_fpcLf_type) { - ofTypeName = "Leaf"; - } - - ImGui::Text("OfType: %d (%s), layer: %d", proc->subtype, ofTypeName, proc->layer_tag.layer->layer_id); - - if (proc->create_req != nullptr) { - ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Pending create request"); - } - - if (showTreeRecursive) { - if (fpcBs_Is_JustOfType(g_fpcNd_type, proc->subtype)) { - auto procNode = static_cast(p); - - ImGui::Text("Owns layer %d", procNode->layer.layer_id); - - fpcLyIt_OnlyHere(&procNode->layer, ShowProcess, nullptr); - } - } - } - - ImGui::EndChild(); - return 1; -} - -static int ShowCreateRequest(void* p, void*) { - create_request* req = (create_request*)p; - - if (req->process != nullptr) { - ShowProcess(req->process, nullptr); - } - - return 1; -} - -static bool Visible = false; - -void DuskImguiProcesses() { - if (ImGui::BeginMenu(MenuView)) { - ImGui::MenuItem("Process management", "F2", &Visible); - ImGui::EndMenu(); - } - - if (ImGui::IsKeyPressed(ImGuiKey_F2)) { - Visible = !Visible; - } - - if (!Visible) { - return; - } - - if (ImGui::Begin("Processes")) { - if (ImGui::BeginTabBar("Tabs")) { - showTreeRecursive = true; - if (ImGui::BeginTabItem("Tree")) { - fpcLyIt_OnlyHere(fpcLy_RootLayer(), ShowProcess, nullptr); - ImGui::EndTabItem(); - } - - showTreeRecursive = false; - if (ImGui::BeginTabItem("All layers")) { - fpcLyIt_All(ShowProcess, nullptr); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Creation queue")) { - fpcCtIt_Method(ShowCreateRequest, nullptr); - - ImGui::EndTabItem(); - } - - ImGui::EndTabBar(); - } - } - - ImGui::End(); -} diff --git a/src/dusk/logging.cpp b/src/dusk/logging.cpp index d69d52094f..1a92f9ac37 100644 --- a/src/dusk/logging.cpp +++ b/src/dusk/logging.cpp @@ -2,8 +2,41 @@ #include #include +bool StubLogEnabled = true; + +using namespace std::literals::string_view_literals; + +// MSVC is broken and seemingly miscompiles std::string_view::npos without this. +// I wish I was joking. +constexpr size_t npos = std::string_view::npos; + +static constexpr std::string_view StubFragments[] = { + "is a stub"sv, + "Unimplemented: BP register"sv, + "Unhandled BP register"sv, + "Unhandled XF register"sv, + "but selective updates are not implemented"sv, +}; + +static bool IsForStubLog(const char* message) { + std::string_view msg_view(message); + + for (auto& fragment : StubFragments) { + if (msg_view.find(fragment) != ""sv.npos) { + return true; + } + } + + return false; +} + void aurora_log_callback(AuroraLogLevel level, const char* module, const char* message, unsigned int len) { + if (StubLogEnabled && level != LOG_FATAL && IsForStubLog(message)) { + dusk::SendToStubLog(level, module, message); + return; + } + const char* levelStr = "??"; FILE* out = stdout; switch (level) { diff --git a/src/dusk/stubs.cpp b/src/dusk/stubs.cpp index 4b20f5b4a8..03573dfeef 100644 --- a/src/dusk/stubs.cpp +++ b/src/dusk/stubs.cpp @@ -262,171 +262,6 @@ void SoundRevID(int a, int b) { STUB_LOG(); } -#pragma mark CARD - -#include - -extern "C" int CARDProbe(s32 chan) { - STUB_LOG(); - return 0; -} - -s32 CARDCancel(CARDFileInfo* fileInfo) { - STUB_LOG(); - return 0; -} - -s32 CARDCheck(s32 chan) { - STUB_LOG(); - return 0; -} - -s32 CARDCheckAsync(s32 chan, CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDClose(CARDFileInfo* fileInfo) { - STUB_LOG(); - return 0; -} - -s32 CARDCreate(s32 chan, const char* fileName, u32 size, CARDFileInfo* fileInfo) { - STUB_LOG(); - return 0; -} - -s32 CARDCreateAsync(s32 chan, const char* fileName, u32 size, CARDFileInfo* fileInfo, - CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDDelete(s32 chan, const char* fileName) { - STUB_LOG(); - return 0; -} - -s32 CARDDeleteAsync(s32 chan, const char* fileName, CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDFastDeleteAsync(s32 chan, s32 fileNo, CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDFastOpen(s32 chan, s32 fileNo, CARDFileInfo* fileInfo) { - STUB_LOG(); - return 0; -} - -s32 CARDFormat(s32 chan) { - STUB_LOG(); - return 0; -} - -s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed) { - STUB_LOG(); - return 0; -} - -s32 CARDGetResultCode(s32 chan) { - STUB_LOG(); - return 0; -} - -s32 CARDGetStatus(s32 chan, s32 fileNo, CARDStat* stat) { - STUB_LOG(); - return 0; -} - -s32 CARDGetSectorSize(s32 chan, u32* size) { - STUB_LOG(); - return 0; -} - -void CARDInit() { - STUB_LOG(); -} - -s32 CARDMount(s32 chan, void* workArea, CARDCallback detachCallback) { - STUB_LOG(); - return 0; -} - -s32 CARDMountAsync(s32 chan, void* workArea, CARDCallback detachCallback, - CARDCallback attachCallback) { - STUB_LOG(); - return 0; -} - -s32 CARDOpen(s32 chan, const char* fileName, CARDFileInfo* fileInfo) { - STUB_LOG(); - return 0; -} - -s32 CARDProbeEx(s32 chan, s32* memSize, s32* sectorSize) { - STUB_LOG(); - return 0; -} - -s32 CARDRead(CARDFileInfo* fileInfo, void* addr, s32 length, s32 offset) { - STUB_LOG(); - return 0; -} - -s32 CARDReadAsync(CARDFileInfo* fileInfo, void* addr, s32 length, s32 offset, - CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDRename(s32 chan, const char* oldName, const char* newName) { - STUB_LOG(); - return 0; -} - -s32 CARDRenameAsync(s32 chan, const char* oldName, const char* newName, CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDSetStatusAsync(s32 chan, s32 fileNo, CARDStat* stat, CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDUnmount(s32 chan) { - STUB_LOG(); - return 0; -} - -extern "C" s32 CARDWrite(CARDFileInfo* fileInfo, void* addr, s32 length, s32 offset) { - STUB_LOG(); - return 0; -} - -s32 CARDWriteAsync(CARDFileInfo* fileInfo, const void* addr, s32 length, s32 offset, - CARDCallback callback) { - STUB_LOG(); - return 0; -} - -s32 CARDGetSerialNo(s32 chan, u64* serialNo) { - return 0; -} - -s32 CARDSetStatus(s32 chan, s32 fileNo, CARDStat* stat) { - return 0; -} - -s32 __CARDFormatRegionAsync(int a, int b) { - STUB_LOG(); - return 0; -} - #pragma mark DC void DCFlushRange(void* addr, u32 nBytes) { @@ -1167,12 +1002,6 @@ void AIStopDMA(void) { #pragma mark GX #include -// Moved-in GX helpers and helpers for metrics/project -void __GXSetSUTexSize() { - STUB_LOG(); -} -// __GXSetVAT, __GXSetVCD, __GXUpdateBPMask: now provided by Aurora's GXManage.cpp (fifo branch) - void GXSetGPMetric(GXPerf0 perf0, GXPerf1 perf1) { STUB_LOG(); } @@ -1218,12 +1047,6 @@ void GXDrawCylinder(u8 numEdges) { void GXWaitDrawDone(void) { STUB_LOG(); } -void GXSetTevIndTile(GXTevStageID tev_stage, GXIndTexStageID ind_stage, u16 tilesize_s, - u16 tilesize_t, u16 tilespacing_s, u16 tilespacing_t, GXIndTexFormat format, - GXIndTexMtxID matrix_sel, GXIndTexBiasSel bias_sel, - GXIndTexAlphaSel alpha_sel) { - // TODO -} void GXResetWriteGatherPipe(void) { STUB_LOG(); } @@ -1249,13 +1072,6 @@ u16 GXGetNumXfbLines(u16 efbHeight, f32 yScale) { return 0; } -void GXGetScissor(u32* left, u32* top, u32* wd, u32* ht) { - STUB_LOG(); -} -u32 GXGetTexObjTlut(const GXTexObj* tex_obj) { - STUB_LOG(); - return 0; -} f32 GXGetYScaleFactor(u16 efbHeight, u16 xfbHeight) { STUB_LOG(); return 0.0f; @@ -1292,13 +1108,6 @@ void GXSetMisc(GXMiscToken token, u32 val) { STUB_LOG(); } -void GXSetProjectionv(const f32* ptr) { - STUB_LOG(); -} -void GXSetVtxAttrFmtv(GXVtxFmt vtxfmt, const GXVtxAttrFmtList* list) { - STUB_LOG(); -} - #pragma mark KPAD // is this actually used? extern "C" void KPADDisableDPD(s32) { diff --git a/src/f_op/f_op_actor_mng.cpp b/src/f_op/f_op_actor_mng.cpp index d79b2610f0..77134afb01 100644 --- a/src/f_op/f_op_actor_mng.cpp +++ b/src/f_op/f_op_actor_mng.cpp @@ -1476,9 +1476,9 @@ fpc_ProcID fopAcM_createItemFromEnemyID(u8 i_enemyID, cXyz const* i_pos, int i_i f32* i_speedF, f32* i_speedY) { int itemNo; int tableNo = 0xFF; - u32* data = (u32*)dEnemyItem_c::getItemData(); + uintptr_t* data = (uintptr_t*)dEnemyItem_c::getItemData(); data++; - int tableNum = (int) *data; + BE(int) tableNum = (int) *data; data++; EnemyTable* table = (EnemyTable*)data; diff --git a/src/f_op/f_op_camera.cpp b/src/f_op/f_op_camera.cpp index c2d94d0a76..48045aeae7 100644 --- a/src/f_op/f_op_camera.cpp +++ b/src/f_op/f_op_camera.cpp @@ -29,6 +29,9 @@ static s32 fopCam_Draw(camera_class* i_this) { static int fopCam_Execute(camera_class* i_this) { int ret; +#if AVOID_UB + ret = 0; +#endif #if DEBUG fapGm_HIO_c::startCpuTimer(); #endif diff --git a/src/f_op/f_op_kankyo.cpp b/src/f_op/f_op_kankyo.cpp index 2e0563f2c9..c66860e79f 100644 --- a/src/f_op/f_op_kankyo.cpp +++ b/src/f_op/f_op_kankyo.cpp @@ -18,6 +18,9 @@ BOOL fopKy_IsKankyo(void* i_this) { static int fopKy_Draw(void* i_this) { int ret; +#if AVOID_UB + ret = 0; +#endif #if DEBUG fapGm_HIO_c::startCpuTimer(); @@ -37,6 +40,9 @@ static int fopKy_Draw(void* i_this) { static int fopKy_Execute(void* i_this) { kankyo_class* a_this = (kankyo_class*)i_this; int ret; +#if AVOID_UB + ret = 0; +#endif #if DEBUG fapGm_HIO_c::startCpuTimer(); diff --git a/src/m_Do/m_Do_MemCard.cpp b/src/m_Do/m_Do_MemCard.cpp index 0241677e6e..919774d2e0 100644 --- a/src/m_Do/m_Do_MemCard.cpp +++ b/src/m_Do/m_Do_MemCard.cpp @@ -75,12 +75,17 @@ static OSThread MemCardThread; void mDoMemCd_Ctrl_c::ThdInit() { #if !PLATFORM_SHIELD - CARDInit(); + CARDInit(DUSK_GAME_NAME, DUSK_GAME_VERSION); #endif mCopyToPos = 0; mProbeStat = 2; mCardState = CARD_STATE_NO_CARD_e; + + #if TARGET_PC + mCardState = CARD_STATE_READY_e; + #endif + mCardCommand = COMM_NONE_e; mChannel = SLOT_A; diff --git a/src/m_Do/m_Do_ext.cpp b/src/m_Do/m_Do_ext.cpp index 8f3d1f640b..e82800ad51 100644 --- a/src/m_Do/m_Do_ext.cpp +++ b/src/m_Do/m_Do_ext.cpp @@ -1737,10 +1737,8 @@ void mDoExt_McaMorfSO::setAnm(J3DAnmTransform* i_anm, int i_attr, f32 i_morf, f3 setLoopFrame(getFrame()); setMorf(i_morf); -#if TARGET_PC - STUB_LOG(); - return; -#endif + STUB_RET(); + if (mpSound != NULL) { if (i_anm != NULL) { mpBas = static_cast(i_anm)->getBas(); diff --git a/src/m_Do/m_Do_graphic.cpp b/src/m_Do/m_Do_graphic.cpp index 0eecb0deaf..4d1327a8be 100644 --- a/src/m_Do/m_Do_graphic.cpp +++ b/src/m_Do/m_Do_graphic.cpp @@ -47,7 +47,7 @@ #endif #if TARGET_PC -#include "dusk/imgui.h" +#include "dusk/imgui/ImGuiConsole.hpp" #include "dusk/dusk.h" #endif @@ -389,12 +389,12 @@ void mDoGph_gInf_c::onBlure() { } #if PLATFORM_WII || PLATFORM_SHIELD -GXTexObj mDoGph_gInf_c::m_fullFrameBufferTexObj; +TGXTexObj mDoGph_gInf_c::m_fullFrameBufferTexObj; #endif -GXTexObj mDoGph_gInf_c::mFrameBufferTexObj; +TGXTexObj mDoGph_gInf_c::mFrameBufferTexObj; -GXTexObj mDoGph_gInf_c::mZbufferTexObj; +TGXTexObj mDoGph_gInf_c::mZbufferTexObj; mDoGph_gInf_c::bloom_c mDoGph_gInf_c::m_bloom; @@ -918,6 +918,10 @@ static void drawDepth2(view_class* param_0, view_port_class* param_1, int param_ GXSetTexCopyDst(halfWidth, halfHeight, (GXTexFmt)mDoGph_gInf_c::getFrameBufferTimg()->format, GX_TRUE); GXCopyTex(frameBufferTex, GX_FALSE); +#ifdef TARGET_PC + mDoGph_gInf_c::getFrameBufferTexObj()->reset(); + mDoGph_gInf_c::getZbufferTexObj()->reset(); +#endif GXInitTexObj(mDoGph_gInf_c::getZbufferTexObj(), zBufferTex, halfWidth, halfHeight, GX_TF_IA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GXInitTexObjLOD(mDoGph_gInf_c::getZbufferTexObj(), GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, @@ -1131,14 +1135,18 @@ void mDoGph_gInf_c::bloom_c::remove() { } void mDoGph_gInf_c::bloom_c::draw() { -#if TARGET_PC // TODO: fix bloom - bool enabled = false; -#else bool enabled = mEnable && m_buffer != NULL; -#endif if (mMonoColor.a != 0 || enabled) { - GXSetViewport(0.0f, 0.0f, FB_WIDTH, FB_HEIGHT, 0.0f, 1.0f); - GXSetScissor(0, 0, FB_WIDTH, FB_HEIGHT); +#if TARGET_PC + f32 width = mDoGph_gInf_c::getWidth(); + f32 height = mDoGph_gInf_c::getHeight(); +#else + f32 width = FB_WIDTH; + f32 height = FB_HEIGHT; +#endif + GXSetViewport(0.0f, 0.0f, width, height, 0.0f, 1.0f); + GXSetScissor(0, 0, width, height); + GXLoadTexObj(getFrameBufferTexObj(), GX_TEXMAP0); GXSetNumChans(0); GXSetNumTexGens(1); @@ -1181,9 +1189,11 @@ void mDoGph_gInf_c::bloom_c::draw() { mDoGph_drawFilterQuad(4, 4); } if (enabled) { - GXSetTexCopySrc(0, 0, FB_WIDTH / 2, FB_HEIGHT / 2); - GXSetTexCopyDst(FB_WIDTH / 2, FB_HEIGHT / 2, GX_TF_RGBA8, 0); + // Store off m_buffer to copy over again at the end. + GXSetTexCopySrc(0, 0, width / 2, height / 2); + GXSetTexCopyDst(width / 2, height / 2, GX_TF_RGBA8, 0); GXCopyTex(m_buffer, 0); + GXSetNumTevStages(3); GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_TEXC, GX_CC_TEXA, GX_CC_HALF, GX_CC_ZERO); @@ -1215,19 +1225,24 @@ void mDoGph_gInf_c::bloom_c::draw() { GXSetTevColor(GX_TEVREG1, tevColor1); GXPixModeSync(); mDoGph_drawFilterQuad(2, 2); + GXSetTevSwapModeTable(GX_TEV_SWAP1, GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA); GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0); GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP0); + + // Downsample and filter from 1/2 EFB into 1/4 zBufferTex (tmp_tex1). void* zBufferTex = getZbufferTex(); - GXSetTexCopySrc(0, 0, FB_WIDTH / 2, FB_HEIGHT / 2); - GXSetTexCopyDst(FB_WIDTH / 4, FB_HEIGHT / 4, GX_TF_RGBA8, GX_TRUE); + GXSetTexCopySrc(0, 0, width / 2, height / 2); + GXSetTexCopyDst(width / 4, height / 4, GX_TF_RGBA8, GX_TRUE); GXCopyTex(zBufferTex, 0); - GXTexObj auStack_c0; - GXInitTexObj(&auStack_c0, zBufferTex, FB_WIDTH / 4, FB_HEIGHT / 4, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, + + TGXTexObj tmp_tex1; + GXInitTexObj(&tmp_tex1, zBufferTex, width / 4, height / 4, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GXInitTexObjLOD(&auStack_c0, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, + GXInitTexObjLOD(&tmp_tex1, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); - GXLoadTexObj(&auStack_c0, GX_TEXMAP0); + GXLoadTexObj(&tmp_tex1, GX_TEXMAP0); + GXSetNumTexGens(8); u32 iVar11 = 0x1e; int sVar10 = 0; @@ -1263,28 +1278,50 @@ void mDoGph_gInf_c::bloom_c::draw() { GX_TRUE, GX_TEVPREV); } GXPixModeSync(); + + // Blur filter from tmp_tex1 1/4 to EFB 1/4. mDoGph_drawFilterQuad(1, 1); - GXSetTexCopySrc(0, 0, FB_WIDTH / 4, FB_HEIGHT / 4); - GXSetTexCopyDst(FB_WIDTH / 8, FB_HEIGHT / 8, GX_TF_RGBA8, GX_TRUE); + + GXSetTexCopySrc(0, 0, width / 4, height / 4); + GXSetTexCopyDst(width / 8, height / 8, GX_TF_RGBA8, GX_TRUE); + + // Downsample EFB 1/4 to zBufferTex 1/8 (tmp_tex2). GXCopyTex(zBufferTex, GX_FALSE); - GXTexObj auStack_e0; - GXInitTexObj(&auStack_e0, zBufferTex, FB_WIDTH / 8, FB_HEIGHT / 8, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, + + TGXTexObj tmp_tex2; + GXInitTexObj(&tmp_tex2, zBufferTex, width / 8, height / 8, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GXInitTexObjLOD(&auStack_c0, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, +#if TARGET_PC + // typo bug fix + GXInitTexObjLOD(&tmp_tex2, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); - GXLoadTexObj(&auStack_e0, GX_TEXMAP0); +#else + GXInitTexObjLOD(&tmp_tex1, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, + GX_ANISO_1); +#endif + GXLoadTexObj(&tmp_tex2, GX_TEXMAP0); + + // Upsample 1/8 buffer back up to 1/4 buffer. GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_OR); GXPixModeSync(); GXInvalidateTexAll(); mDoGph_drawFilterQuad(1, 1); - GXSetTexCopySrc(0, 0, FB_WIDTH / 4, FB_HEIGHT / 4); - GXSetTexCopyDst(FB_WIDTH / 4, FB_HEIGHT / 4, GX_TF_RGBA8, GX_FALSE); + +#if TARGET_PC + tmp_tex2.reset(); +#endif + + // Now that we've upsampled and filtered our final bloom, copy 1/4 buffer back to zBufferTex. + GXSetTexCopySrc(0, 0, width / 4, height / 4); + GXSetTexCopyDst(width / 4, height / 4, GX_TF_RGBA8, GX_FALSE); GXCopyTex(zBufferTex, GX_FALSE); - GXInitTexObj(&auStack_e0, m_buffer, FB_WIDTH / 2, FB_HEIGHT / 2, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, + + // Copy back m_buffer to screen. + GXInitTexObj(&tmp_tex2, m_buffer, width / 2, height / 2, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GXInitTexObjLOD(&auStack_e0, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, + GXInitTexObjLOD(&tmp_tex2, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); - GXLoadTexObj(&auStack_e0, GX_TEXMAP0); + GXLoadTexObj(&tmp_tex2, GX_TEXMAP0); GXSetNumTexGens(1); GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 0x3c); GXSetNumTevStages(1); @@ -1297,7 +1334,9 @@ void mDoGph_gInf_c::bloom_c::draw() { GX_TEVPREV); GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ONE, GX_LO_OR); mDoGph_drawFilterQuad(2, 2); - GXLoadTexObj(&auStack_c0, GX_TEXMAP0); + + // Now blend our bloom into the real FB. + GXLoadTexObj(&tmp_tex1, GX_TEXMAP0); GXSetTevColor(GX_TEVREG0, mBlendColor); GXSetNumTevStages(1); GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); @@ -1618,8 +1657,13 @@ int mDoGph_Painter() { view_port_class new_port; new_port.x_orig = 0.0f; new_port.y_orig = 0.0f; + #if TARGET_PC + new_port.width = mDoGph_gInf_c::getWidth(); + new_port.height = mDoGph_gInf_c::getHeight(); + #else new_port.width = FB_WIDTH; new_port.height = FB_HEIGHT; + #endif new_port.near_z = view_port->near_z; new_port.far_z = view_port->far_z; new_port.scissor = view_port->scissor; @@ -1913,8 +1957,12 @@ int mDoGph_Painter() { retry_captue_frame(&camera_p->view, view_port, dComIfGp_getCameraZoomForcus(camera_id)); } - + + #if TARGET_PC + GXSetViewport(0.0f, 0.0f, mDoGph_gInf_c::getWidth(), mDoGph_gInf_c::getHeight(), 0.0f, 1.0f); + #else GXSetViewport(0.0f, 0.0f, FB_WIDTH, FB_HEIGHT, 0.0f, 1.0f); + #endif Mtx m2; Mtx44 m; @@ -2147,7 +2195,7 @@ int mDoGph_Painter() { #endif #if TARGET_PC - imgui_main(&auroraInfo); + dusk::g_imguiConsole.draw(); #endif mDoGph_gInf_c::endRender(); diff --git a/src/m_Do/m_Do_lib.cpp b/src/m_Do/m_Do_lib.cpp index 261a7db1f5..e67cc6abf1 100644 --- a/src/m_Do/m_Do_lib.cpp +++ b/src/m_Do/m_Do_lib.cpp @@ -10,8 +10,11 @@ #include "d/d_com_inf_game.h" #include -u32 mDoLib_setResTimgObj(ResTIMG const* i_img, GXTexObj* o_texObj, u32 tlut_name, +u32 mDoLib_setResTimgObj(ResTIMG const* i_img, TGXTexObj* o_texObj, u32 tlut_name, GXTlutObj* o_tlutObj) { +#ifdef TARGET_PC + o_texObj->reset(); +#endif if (i_img->indexTexture) { JUT_ASSERT(44, o_tlutObj != NULL); GXInitTlutObj(o_tlutObj, (void*)((u8*)i_img + i_img->paletteOffset), diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 342eb0d74d..749d607071 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -46,6 +46,7 @@ #include "SSystem/SComponent/c_API.h" #include "dusk/dusk.h" #include "dusk/logging.h" +#include "dusk/time.h" #include #include @@ -102,6 +103,10 @@ s32 LOAD_COPYDATE(void*) { AuroraInfo auroraInfo; void main01(void) { + #if TARGET_PC + Limiter frameLimiter{}; + #endif + OS_REPORT("\x1b[m"); GXSetColorUpdate(GX_ENABLE); // 1. Setup @@ -162,8 +167,6 @@ void main01(void) { static u32 frame = 0; frame++; - - // Game Inputs mDoCPd_c::read(); @@ -175,12 +178,12 @@ void main01(void) { mDoAud_Execute(); + #if TARGET_PC + frameLimiter.Sleep(DUSK_FRAME_PERIOD); + #endif //aurora_end_frame(); - // Limiter - std::this_thread::sleep_for(std::chrono::milliseconds(16)); - } while (true); exit:;