From f8007cc84bda03c0ce83d57cbb4f91c87213dc55 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Fri, 26 Aug 2022 18:03:48 -0400 Subject: [PATCH] [decomp] Jak 2 mips2c, collide-func (#1805) --- common/versions.h | 2 +- decompiler/analysis/mips2c.cpp | 15 +- decompiler/config/jak2/all-types.gc | 4 +- decompiler/config/jak2/hacks.jsonc | 5 +- game/CMakeLists.txt | 51 +- game/kernel/common/kmachine.cpp | 11 + game/kernel/common/kmachine.h | 1 + game/kernel/jak1/klink.cpp | 7 +- game/kernel/jak1/kmachine.cpp | 11 - game/kernel/jak2/klink.cpp | 11 +- game/kernel/jak2/kmachine.cpp | 2 +- game/kernel/jak2/kscheme.h | 2 + .../{functions => jak1_functions}/bones.cpp | 6 +- .../collide_cache.cpp | 26 +- .../collide_edge_grab.cpp | 8 +- .../collide_func.cpp | 4 +- .../collide_mesh.cpp | 8 +- .../collide_probe.cpp | 4 +- .../draw_string.cpp | 2 +- .../generic_effect.cpp | 8 +- .../generic_effect2.cpp | 6 +- .../generic_merc.cpp | 12 +- .../generic_tie.cpp | 4 +- .../{functions => jak1_functions}/joint.cpp | 14 +- .../merc_blend_shape.cpp | 4 +- .../{functions => jak1_functions}/ocean.cpp | 8 +- .../ocean_vu0.cpp | 4 +- .../{functions => jak1_functions}/ripple.cpp | 8 +- .../{functions => jak1_functions}/shadow.cpp | 30 +- .../{functions => jak1_functions}/sky_tng.cpp | 30 +- .../sparticle.cpp | 4 +- .../sparticle_launcher.cpp | 6 +- .../test_func.cpp | 8 +- .../{functions => jak1_functions}/texture.cpp | 2 +- .../{functions => jak1_functions}/tfrag.cpp | 6 +- .../tie_methods.cpp | 4 +- .../time_of_day.cpp | 2 +- game/mips2c/jak2_functions/collide_func.cpp | 500 +++++++++++++++ game/mips2c/mips2c_table.cpp | 579 ++++++------------ game/mips2c/mips2c_table.h | 3 +- goal_src/jak2/engine/collide/collide-func.gc | 396 +++++++++++- goal_src/jak2/engine/data/art-h.gc | 2 +- goal_src/jak2/engine/load/loader-h.gc | 6 +- goal_src/jak2/engine/load/loader.gc | 20 + .../process-drawable/process-drawable.gc | 10 + goal_src/jak2/kernel-defs.gc | 1 + goal_src/jak2/kernel/gkernel-h.gc | 14 + .../reference/jak2/engine/data/art-h_REF.gc | 2 +- .../jak2/engine/load/loader-h_REF.gc | 2 +- test/goalc/test_with_game.cpp | 10 +- 50 files changed, 1321 insertions(+), 564 deletions(-) rename game/mips2c/{functions => jak1_functions}/bones.cpp (99%) rename game/mips2c/{functions => jak1_functions}/collide_cache.cpp (99%) rename game/mips2c/{functions => jak1_functions}/collide_edge_grab.cpp (99%) rename game/mips2c/{functions => jak1_functions}/collide_func.cpp (99%) rename game/mips2c/{functions => jak1_functions}/collide_mesh.cpp (99%) rename game/mips2c/{functions => jak1_functions}/collide_probe.cpp (99%) rename game/mips2c/{functions => jak1_functions}/draw_string.cpp (99%) rename game/mips2c/{functions => jak1_functions}/generic_effect.cpp (99%) rename game/mips2c/{functions => jak1_functions}/generic_effect2.cpp (99%) rename game/mips2c/{functions => jak1_functions}/generic_merc.cpp (99%) rename game/mips2c/{functions => jak1_functions}/generic_tie.cpp (99%) rename game/mips2c/{functions => jak1_functions}/joint.cpp (99%) rename game/mips2c/{functions => jak1_functions}/merc_blend_shape.cpp (99%) rename game/mips2c/{functions => jak1_functions}/ocean.cpp (99%) rename game/mips2c/{functions => jak1_functions}/ocean_vu0.cpp (99%) rename game/mips2c/{functions => jak1_functions}/ripple.cpp (99%) rename game/mips2c/{functions => jak1_functions}/shadow.cpp (99%) rename game/mips2c/{functions => jak1_functions}/sky_tng.cpp (99%) rename game/mips2c/{functions => jak1_functions}/sparticle.cpp (99%) rename game/mips2c/{functions => jak1_functions}/sparticle_launcher.cpp (99%) rename game/mips2c/{functions => jak1_functions}/test_func.cpp (94%) rename game/mips2c/{functions => jak1_functions}/texture.cpp (99%) rename game/mips2c/{functions => jak1_functions}/tfrag.cpp (99%) rename game/mips2c/{functions => jak1_functions}/tie_methods.cpp (99%) rename game/mips2c/{functions => jak1_functions}/time_of_day.cpp (99%) create mode 100644 game/mips2c/jak2_functions/collide_func.cpp diff --git a/common/versions.h b/common/versions.h index f7121a4be2..f3d41089f3 100644 --- a/common/versions.h +++ b/common/versions.h @@ -46,7 +46,7 @@ enum class GameVersion { Jak1 = 1, Jak2 = 2 }; template struct PerGameVersion { constexpr PerGameVersion(T jak1, T jak2) : data{jak1, jak2} {} - constexpr T operator[](GameVersion v) const { return data[(int)v - 1]; } + constexpr const T& operator[](GameVersion v) const { return data[(int)v - 1]; } T data[2]; }; diff --git a/decompiler/analysis/mips2c.cpp b/decompiler/analysis/mips2c.cpp index d2418a1d0a..2d87f917ac 100644 --- a/decompiler/analysis/mips2c.cpp +++ b/decompiler/analysis/mips2c.cpp @@ -153,14 +153,17 @@ struct Mips2C_Output { * Convert the output to a string. */ std::string write_to_string(const FunctionName& goal_func_name, + GameVersion version, const std::string& extra = "") const { std::string name = goal_to_c_function_name(goal_func_name); std::string result = "//--------------------------MIPS2C---------------------\n"; + result += "// clang-format off\n"; result += "#include \"game/mips2c/mips2c_private.h\"\n"; - result += "#include \"game/kernel/kscheme.h\"\n"; + result += fmt::format("#include \"game/kernel/{}/kscheme.h\"\n", game_version_names[version]); + result += fmt::format("using ::{}::intern_from_c;\n", game_version_names[version]); // start of namespace for this function - result += "namespace Mips2C {\n"; + result += fmt::format("namespace Mips2C::{} {{\n", game_version_names[version]); result += fmt::format("namespace {} {{\n", name); // definition of the symbol cache. @@ -227,8 +230,8 @@ struct Mips2C_Output { result += fmt::format(" cache.{} = intern_from_c(\"{}\").c();\n", goal_to_c_name(sym), sym); } // this adds us to a table for lookup later, and also allocates our trampoline. - result += - fmt::format(" gLinkedFunctionTable.reg(\"{}\", execute);\n", goal_func_name.to_string()); + result += fmt::format(" gLinkedFunctionTable.reg(\"{}\", execute, PUT_STACK_SIZE_HERE);\n", + goal_func_name.to_string()); result += "}\n\n"; result += extra; @@ -1313,7 +1316,7 @@ void run_mips2c_jump_table(Function* f, } jump_loc_table += "};\n\n"; - f->mips2c_output = output.write_to_string(f->guessed_name, jump_loc_table); + f->mips2c_output = output.write_to_string(f->guessed_name, version, jump_loc_table); if (g_unknown > 0) { lg::error("Mips to C pass in {} hit {} unknown instructions", f->name(), g_unknown); } @@ -1431,7 +1434,7 @@ void run_mips2c(Function* f, GameVersion version) { } } - f->mips2c_output = output.write_to_string(f->guessed_name); + f->mips2c_output = output.write_to_string(f->guessed_name, version); if (g_unknown > 0) { lg::error("Mips to C pass in {} hit {} unknown instructions", f->name(), g_unknown); } diff --git a/decompiler/config/jak2/all-types.gc b/decompiler/config/jak2/all-types.gc index 4f3ddb4dc3..cbce542189 100644 --- a/decompiler/config/jak2/all-types.gc +++ b/decompiler/config/jak2/all-types.gc @@ -4562,7 +4562,7 @@ (:methods (new (symbol type int level) _type_ 0) (load-dir-method-9 () none 9) ;; (load-to-heap-by-name (_type_ string symbol kheap int) art-group 9) - (load-dir-method-10 () none 10) ;; (set-loaded-art (_type_ art-group) art-group 10) + (set-loaded-art (_type_ art-group) art-group 10) ) ) @@ -9876,7 +9876,7 @@ :size-assert #x74 :flag-assert #x1000000074 (:methods - (add-to-loading-level (_type_) none 15) + (add-to-loading-level (_type_) skeleton-group 15) ) ) diff --git a/decompiler/config/jak2/hacks.jsonc b/decompiler/config/jak2/hacks.jsonc index 860bc3a186..8d22e31ad6 100644 --- a/decompiler/config/jak2/hacks.jsonc +++ b/decompiler/config/jak2/hacks.jsonc @@ -229,7 +229,10 @@ // where "op" is the op number for the call to format. "dynamic_format_arg_counts": {}, - "mips2c_functions_by_name": [], + "mips2c_functions_by_name": [ + "collide-do-primitives", + "moving-sphere-triangle-intersect" + ], "mips2c_jump_table_functions": {}, diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 79913848a0..908a5d5e72 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -57,31 +57,32 @@ set(RUNTIME_SOURCE kernel/jak2/ksound.cpp kernel/asm_funcs.asm mips2c/mips2c_table.cpp - mips2c/functions/bones.cpp - mips2c/functions/collide_cache.cpp - mips2c/functions/collide_edge_grab.cpp - mips2c/functions/collide_func.cpp - mips2c/functions/collide_mesh.cpp - mips2c/functions/collide_probe.cpp - mips2c/functions/draw_string.cpp - mips2c/functions/generic_effect.cpp - mips2c/functions/generic_effect2.cpp - mips2c/functions/generic_merc.cpp - mips2c/functions/generic_tie.cpp - mips2c/functions/joint.cpp - mips2c/functions/merc_blend_shape.cpp - mips2c/functions/ocean.cpp - mips2c/functions/ocean_vu0.cpp - mips2c/functions/ripple.cpp - mips2c/functions/shadow.cpp - mips2c/functions/sky_tng.cpp - mips2c/functions/sparticle.cpp - mips2c/functions/sparticle_launcher.cpp - mips2c/functions/test_func.cpp - mips2c/functions/texture.cpp - mips2c/functions/tfrag.cpp - mips2c/functions/tie_methods.cpp - mips2c/functions/time_of_day.cpp + mips2c/jak1_functions/bones.cpp + mips2c/jak1_functions/collide_cache.cpp + mips2c/jak1_functions/collide_edge_grab.cpp + mips2c/jak1_functions/collide_func.cpp + mips2c/jak1_functions/collide_mesh.cpp + mips2c/jak1_functions/collide_probe.cpp + mips2c/jak1_functions/draw_string.cpp + mips2c/jak1_functions/generic_effect.cpp + mips2c/jak1_functions/generic_effect2.cpp + mips2c/jak1_functions/generic_merc.cpp + mips2c/jak1_functions/generic_tie.cpp + mips2c/jak1_functions/joint.cpp + mips2c/jak1_functions/merc_blend_shape.cpp + mips2c/jak1_functions/ocean.cpp + mips2c/jak1_functions/ocean_vu0.cpp + mips2c/jak1_functions/ripple.cpp + mips2c/jak1_functions/shadow.cpp + mips2c/jak1_functions/sky_tng.cpp + mips2c/jak1_functions/sparticle.cpp + mips2c/jak1_functions/sparticle_launcher.cpp + mips2c/jak1_functions/test_func.cpp + mips2c/jak1_functions/texture.cpp + mips2c/jak1_functions/tfrag.cpp + mips2c/jak1_functions/tie_methods.cpp + mips2c/jak1_functions/time_of_day.cpp + mips2c/jak2_functions/collide_func.cpp overlord/dma.cpp overlord/fake_iso.cpp overlord/iso.cpp diff --git a/game/kernel/common/kmachine.cpp b/game/kernel/common/kmachine.cpp index 3e1dd47077..bf808b6804 100644 --- a/game/kernel/common/kmachine.cpp +++ b/game/kernel/common/kmachine.cpp @@ -11,6 +11,7 @@ #include "game/kernel/common/kernel_types.h" #include "game/kernel/common/kprint.h" #include "game/kernel/common/kscheme.h" +#include "game/mips2c/mips2c_table.h" #include "game/sce/libcdvd_ee.h" #include "game/sce/libpad.h" #include "game/sce/libscf.h" @@ -491,3 +492,13 @@ void vif_interrupt_callback() { u32 offset_of_s7() { return s7.offset; } + +/*! + * Called from the game thread at initialization. + * The game thread is the only one to touch the mips2c function table (through the linker and + * through this function), so no locking is needed. + */ +u64 pc_get_mips2c(u32 name) { + const char* n = Ptr(name).c()->data(); + return Mips2C::gLinkedFunctionTable.get(n); +} \ No newline at end of file diff --git a/game/kernel/common/kmachine.h b/game/kernel/common/kmachine.h index eb429ef0b2..da8dba1bc9 100644 --- a/game/kernel/common/kmachine.h +++ b/game/kernel/common/kmachine.h @@ -78,3 +78,4 @@ u32 get_collision_mask(GfxGlobalSettings::CollisionRendererMode mode, int mask); void set_gfx_hack(u64 which, u32 symptr); u32 offset_of_s7(); void vif_interrupt_callback(); +u64 pc_get_mips2c(u32 name); \ No newline at end of file diff --git a/game/kernel/jak1/klink.cpp b/game/kernel/jak1/klink.cpp index de2b56f9d4..5b21d65d22 100644 --- a/game/kernel/jak1/klink.cpp +++ b/game/kernel/jak1/klink.cpp @@ -531,8 +531,11 @@ void link_control::jak1_finish(bool jump_from_c_to_goal) { // todo check function type of entry // setup mips2c functions - for (auto& x : Mips2C::gMips2CLinkCallbacks[m_object_name]) { - x(); + const auto& it = Mips2C::gMips2CLinkCallbacks[GameVersion::Jak1].find(m_object_name); + if (it != Mips2C::gMips2CLinkCallbacks[GameVersion::Jak1].end()) { + for (auto& x : it->second) { + x(); + } } // execute top level! diff --git a/game/kernel/jak1/kmachine.cpp b/game/kernel/jak1/kmachine.cpp index 6f2b268947..bba8e36e3d 100644 --- a/game/kernel/jak1/kmachine.cpp +++ b/game/kernel/jak1/kmachine.cpp @@ -36,7 +36,6 @@ #include "game/kernel/jak1/kscheme.h" #include "game/kernel/jak1/ksound.h" #include "game/kernel/svnrev.h" -#include "game/mips2c/mips2c_table.h" #include "game/sce/deci2.h" #include "game/sce/libcdvd_ee.h" #include "game/sce/libdma.h" @@ -405,16 +404,6 @@ void pc_texture_relocate(u32 dst, u32 src, u32 format) { Gfx::texture_relocate(dst, src, format); } -/*! - * Called from the game thread at initialization. - * The game thread is the only one to touch the mips2c function table (through the linker and - * through this function), so no locking is needed. - */ -u64 pc_get_mips2c(u32 name) { - const char* n = Ptr(name).c()->data(); - return Mips2C::gLinkedFunctionTable.get(n); -} - /*! * Called from the game thread at each frame to tell the PC rendering code which levels to start * loading. The loader internally handles locking. diff --git a/game/kernel/jak2/klink.cpp b/game/kernel/jak2/klink.cpp index 89377d1a2f..00e933df52 100644 --- a/game/kernel/jak2/klink.cpp +++ b/game/kernel/jak2/klink.cpp @@ -11,8 +11,10 @@ #include "game/kernel/common/kscheme.h" #include "game/kernel/common/memory_layout.h" #include "game/kernel/jak2/kscheme.h" +#include "game/mips2c/mips2c_table.h" #include "third-party/fmt/core.h" + static constexpr bool link_debug_printfs = false; /*! @@ -540,11 +542,12 @@ void link_control::jak2_finish(bool jump_from_c_to_goal) { // todo check function type of entry // setup mips2c functions - /* - for (auto& x : Mips2C::gMips2CLinkCallbacks[m_object_name]) { - x(); + const auto& it = Mips2C::gMips2CLinkCallbacks[GameVersion::Jak2].find(m_object_name); + if (it != Mips2C::gMips2CLinkCallbacks[GameVersion::Jak2].end()) { + for (auto& x : it->second) { + x(); + } } - */ // execute top level! if (m_entry.offset && (m_flags & LINK_FLAG_EXECUTE)) { diff --git a/game/kernel/jak2/kmachine.cpp b/game/kernel/jak2/kmachine.cpp index 6cc370b12b..bc8a5f20a1 100644 --- a/game/kernel/jak2/kmachine.cpp +++ b/game/kernel/jak2/kmachine.cpp @@ -465,7 +465,7 @@ void InitMachine_PCPort() { // make_function_symbol_from_c("__send-gfx-dma-chain", (void*)send_gfx_dma_chain); // make_function_symbol_from_c("__pc-texture-upload-now", (void*)pc_texture_upload_now); // make_function_symbol_from_c("__pc-texture-relocate", (void*)pc_texture_relocate); - // make_function_symbol_from_c("__pc-get-mips2c", (void*)pc_get_mips2c); + make_function_symbol_from_c("__pc-get-mips2c", (void*)pc_get_mips2c); // make_function_symbol_from_c("__pc-set-levels", (void*)pc_set_levels); // pad stuff diff --git a/game/kernel/jak2/kscheme.h b/game/kernel/jak2/kscheme.h index 1b6798d487..fc571d937e 100644 --- a/game/kernel/jak2/kscheme.h +++ b/game/kernel/jak2/kscheme.h @@ -57,4 +57,6 @@ u64 loado(u32 file_name_in, u32 heap_in); u64 unload(u32 name); u64 call_method_of_type(u32 arg, Ptr type, u32 method_id); u64 call_goal_function_by_name(const char* name); +u64 alloc_heap_object(u32 heap, u32 type, u32 size, u32 pp); +u32 u32_in_fixed_sym(u32 offset); } // namespace jak2 \ No newline at end of file diff --git a/game/mips2c/functions/bones.cpp b/game/mips2c/jak1_functions/bones.cpp similarity index 99% rename from game/mips2c/functions/bones.cpp rename to game/mips2c/jak1_functions/bones.cpp index dcd4aa6f30..2201bf5027 100644 --- a/game/mips2c/functions/bones.cpp +++ b/game/mips2c/jak1_functions/bones.cpp @@ -4,7 +4,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace bones_mtx_calc { struct Cache { @@ -693,7 +693,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_bones_merc { struct Cache { void* merc_bucket_info; // *merc-bucket-info* @@ -1046,7 +1046,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_bones_check_longest_edge_asm { struct Cache { void* math_camera; // *math-camera* diff --git a/game/mips2c/functions/collide_cache.cpp b/game/mips2c/jak1_functions/collide_cache.cpp similarity index 99% rename from game/mips2c/functions/collide_cache.cpp rename to game/mips2c/jak1_functions/collide_cache.cpp index f489aac1d0..05b8989053 100644 --- a/game/mips2c/functions/collide_cache.cpp +++ b/game/mips2c/jak1_functions/collide_cache.cpp @@ -16,7 +16,7 @@ void vlqi(Mips2C::ExecutionContext* c, int reg) { } } // namespace -namespace Mips2C { +namespace Mips2C::jak1 { namespace pc_upload_collide_frag { u64 execute(void* ctxt) { @@ -508,7 +508,7 @@ void link() { } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { // clip by box namespace method_26_collide_cache { @@ -794,7 +794,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_28_collide_cache { struct Cache { void* already_printed_exeeded_max_cache_tris; // *already-printed-exeeded-max-cache-tris* @@ -1077,7 +1077,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_27_collide_cache { struct Cache { void* already_printed_exeeded_max_cache_tris; // *already-printed-exeeded-max-cache-tris* @@ -1373,7 +1373,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_29_collide_cache { struct Cache { void* collide_work; // *collide-work* @@ -1562,7 +1562,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_12_collide_shape_prim_mesh { struct Cache { void* already_printed_exeeded_max_cache_tris; // *already-printed-exeeded-max-cache-tris* @@ -1808,7 +1808,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_14_collide_shape_prim_mesh { struct Cache { void* already_printed_exeeded_max_cache_tris; // *already-printed-exeeded-max-cache-tris* @@ -2053,7 +2053,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_13_collide_shape_prim_mesh { struct Cache { void* already_printed_exeeded_max_cache_tris; // *already-printed-exeeded-max-cache-tris* @@ -2304,7 +2304,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_30_collide_cache { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -2506,7 +2506,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_9_collide_cache_prim { struct Cache { void* moving_sphere_triangle_intersect; // moving-sphere-triangle-intersect @@ -2694,7 +2694,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_10_collide_cache_prim { struct Cache { void* moving_sphere_sphere_intersect; // moving-sphere-sphere-intersect @@ -2906,7 +2906,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_10_collide_puss_work { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -3075,7 +3075,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_9_collide_puss_work { struct Cache { void* closest_pt_in_triangle; // closest-pt-in-triangle diff --git a/game/mips2c/functions/collide_edge_grab.cpp b/game/mips2c/jak1_functions/collide_edge_grab.cpp similarity index 99% rename from game/mips2c/functions/collide_edge_grab.cpp rename to game/mips2c/jak1_functions/collide_edge_grab.cpp index 5f7a61d18d..7d4b3b2805 100644 --- a/game/mips2c/functions/collide_edge_grab.cpp +++ b/game/mips2c/jak1_functions/collide_edge_grab.cpp @@ -2,7 +2,7 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_16_collide_edge_work { struct Cache { void* format; // format @@ -195,7 +195,7 @@ void link() { } // namespace method_16_collide_edge_work } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_15_collide_edge_work { struct Cache { void* format; // format @@ -596,7 +596,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_10_collide_edge_hold_list { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -690,7 +690,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_18_collide_edge_work { struct Cache { void* collide_edge_hold_list; // collide-edge-hold-list diff --git a/game/mips2c/functions/collide_func.cpp b/game/mips2c/jak1_functions/collide_func.cpp similarity index 99% rename from game/mips2c/functions/collide_func.cpp rename to game/mips2c/jak1_functions/collide_func.cpp index c0c6a0ccdf..ff6eae4b29 100644 --- a/game/mips2c/functions/collide_func.cpp +++ b/game/mips2c/jak1_functions/collide_func.cpp @@ -3,7 +3,7 @@ #include "game/mips2c/mips2c_private.h" using namespace jak1; // clang-format off -namespace Mips2C { +namespace Mips2C::jak1 { namespace collide_do_primitives { struct Cache { void* ray_cylinder_intersect; // ray-cylinder-intersect @@ -262,7 +262,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace moving_sphere_triangle_intersect { struct Cache { void* collide_do_primitives; // collide-do-primitives diff --git a/game/mips2c/functions/collide_mesh.cpp b/game/mips2c/jak1_functions/collide_mesh.cpp similarity index 99% rename from game/mips2c/functions/collide_mesh.cpp rename to game/mips2c/jak1_functions/collide_mesh.cpp index 0128af6224..716aa745bd 100644 --- a/game/mips2c/functions/collide_mesh.cpp +++ b/game/mips2c/jak1_functions/collide_mesh.cpp @@ -4,7 +4,7 @@ #include "game/mips2c/mips2c_private.h" using namespace jak1; // clang-format off -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_12_collide_mesh { struct Cache { void* closest_pt_in_triangle; // closest-pt-in-triangle @@ -204,7 +204,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_11_collide_mesh { struct Cache { void* closest_pt_in_triangle; // closest-pt-in-triangle @@ -379,7 +379,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_14_collide_mesh { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -583,7 +583,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace method_15_collide_mesh { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; diff --git a/game/mips2c/functions/collide_probe.cpp b/game/mips2c/jak1_functions/collide_probe.cpp similarity index 99% rename from game/mips2c/functions/collide_probe.cpp rename to game/mips2c/jak1_functions/collide_probe.cpp index aaf7513906..3b5d540916 100644 --- a/game/mips2c/functions/collide_probe.cpp +++ b/game/mips2c/jak1_functions/collide_probe.cpp @@ -4,7 +4,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace collide_probe_node { struct Cache { void* collide_probe_stack; // *collide-probe-stack* @@ -355,7 +355,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace collide_probe_instance_tie { struct Cache { void* collide_probe_stack; // *collide-probe-stack* diff --git a/game/mips2c/functions/draw_string.cpp b/game/mips2c/jak1_functions/draw_string.cpp similarity index 99% rename from game/mips2c/functions/draw_string.cpp rename to game/mips2c/jak1_functions/draw_string.cpp index 31aceffe66..a24034277b 100644 --- a/game/mips2c/functions/draw_string.cpp +++ b/game/mips2c/jak1_functions/draw_string.cpp @@ -3,7 +3,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_string { struct Cache { void* font_work; // *font-work* diff --git a/game/mips2c/functions/generic_effect.cpp b/game/mips2c/jak1_functions/generic_effect.cpp similarity index 99% rename from game/mips2c/functions/generic_effect.cpp rename to game/mips2c/jak1_functions/generic_effect.cpp index 13032c7a6c..b7496aeb56 100644 --- a/game/mips2c/functions/generic_effect.cpp +++ b/game/mips2c/jak1_functions/generic_effect.cpp @@ -6,7 +6,7 @@ using namespace jak1; // clang-format off -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_prepare_dma_double { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -451,7 +451,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_light_proc { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -891,7 +891,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_envmap_proc { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -1660,7 +1660,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_prepare_dma_single { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* diff --git a/game/mips2c/functions/generic_effect2.cpp b/game/mips2c/jak1_functions/generic_effect2.cpp similarity index 99% rename from game/mips2c/functions/generic_effect2.cpp rename to game/mips2c/jak1_functions/generic_effect2.cpp index bb44dd2f26..69e0b03ef8 100644 --- a/game/mips2c/functions/generic_effect2.cpp +++ b/game/mips2c/jak1_functions/generic_effect2.cpp @@ -3,7 +3,7 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { // clang-format off void vcallms48(ExecutionContext* c) { @@ -659,7 +659,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_interp_dproc { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -838,7 +838,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_no_light_dproc { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* diff --git a/game/mips2c/functions/generic_merc.cpp b/game/mips2c/jak1_functions/generic_merc.cpp similarity index 99% rename from game/mips2c/functions/generic_merc.cpp rename to game/mips2c/jak1_functions/generic_merc.cpp index 7b0f8afe7a..06182938ce 100644 --- a/game/mips2c/functions/generic_merc.cpp +++ b/game/mips2c/jak1_functions/generic_merc.cpp @@ -2,7 +2,7 @@ #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_prepare_dma_single { u64 execute(void* ctxt); } @@ -21,11 +21,11 @@ u64 execute(void* ctxt); namespace high_speed_reject { u64 execute(void* ctxt); } -} // namespace Mips2C +} // namespace Mips2C::jak1 //--------------------------MIPS2C--------------------- // clang-format off -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_merc_init_asm { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -284,7 +284,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_merc_execute_asm { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -1352,7 +1352,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace mercneric_convert { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -3539,7 +3539,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace high_speed_reject { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* diff --git a/game/mips2c/functions/generic_tie.cpp b/game/mips2c/jak1_functions/generic_tie.cpp similarity index 99% rename from game/mips2c/functions/generic_tie.cpp rename to game/mips2c/jak1_functions/generic_tie.cpp index 3d14810105..6d11bb0cbb 100644 --- a/game/mips2c/functions/generic_tie.cpp +++ b/game/mips2c/jak1_functions/generic_tie.cpp @@ -3,7 +3,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_tie_dma_to_spad_sync { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -108,7 +108,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace generic_prepare_dma_double { extern u64 execute(void* ctxt); diff --git a/game/mips2c/functions/joint.cpp b/game/mips2c/jak1_functions/joint.cpp similarity index 99% rename from game/mips2c/functions/joint.cpp rename to game/mips2c/jak1_functions/joint.cpp index d358e759dc..79a7cfcdc7 100644 --- a/game/mips2c/functions/joint.cpp +++ b/game/mips2c/jak1_functions/joint.cpp @@ -16,7 +16,7 @@ struct Cache { } cache; } -namespace Mips2C { +namespace Mips2C::jak1 { namespace decompress_frame_data_pair_to_accumulator { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -820,7 +820,7 @@ u32 jump_table_vals[16] = { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace decompress_frame_data_to_accumulator { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -1420,7 +1420,7 @@ u32 jump_table_vals[16] = { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace decompress_fixed_data_to_accumulator { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -2036,7 +2036,7 @@ u32 jump_table_vals[16] = { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace normalize_frame_quaternions { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -2090,7 +2090,7 @@ u64 execute(void* ctxt) { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace clear_frame_accumulator { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -2150,7 +2150,7 @@ u64 execute(void* ctxt) { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace calc_animation_from_spr { @@ -2396,7 +2396,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace cspace_parented_transformq_joint { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; diff --git a/game/mips2c/functions/merc_blend_shape.cpp b/game/mips2c/jak1_functions/merc_blend_shape.cpp similarity index 99% rename from game/mips2c/functions/merc_blend_shape.cpp rename to game/mips2c/jak1_functions/merc_blend_shape.cpp index 069447c0f0..0938b3f976 100644 --- a/game/mips2c/functions/merc_blend_shape.cpp +++ b/game/mips2c/jak1_functions/merc_blend_shape.cpp @@ -4,7 +4,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace blerc_execute { struct Cache { void* blerc_globals; // *blerc-globals* @@ -408,7 +408,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace setup_blerc_chains_for_one_fragment { struct Cache { void* blerc_globals; // *blerc-globals* diff --git a/game/mips2c/functions/ocean.cpp b/game/mips2c/jak1_functions/ocean.cpp similarity index 99% rename from game/mips2c/functions/ocean.cpp rename to game/mips2c/jak1_functions/ocean.cpp index aaebe4f7c1..26bbbf5fa4 100644 --- a/game/mips2c/functions/ocean.cpp +++ b/game/mips2c/jak1_functions/ocean.cpp @@ -4,7 +4,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { ExecutionContext ocean_regs_vfs; namespace init_ocean_far_regs { @@ -64,7 +64,7 @@ void link() { } // namespace init_ocean_far_regs } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace clip_polygon_against_positive_hyperplane { u64 execute(void* ctxt); } @@ -75,7 +75,7 @@ u64 execute(void* ctxt); //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_large_polygon_ocean { struct Cache { void* clip_polygon_against_negative_hyperplane; // clip-polygon-against-negative-hyperplane @@ -269,7 +269,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace render_ocean_quad { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* diff --git a/game/mips2c/functions/ocean_vu0.cpp b/game/mips2c/jak1_functions/ocean_vu0.cpp similarity index 99% rename from game/mips2c/functions/ocean_vu0.cpp rename to game/mips2c/jak1_functions/ocean_vu0.cpp index bcdcb63a66..a840880030 100644 --- a/game/mips2c/functions/ocean_vu0.cpp +++ b/game/mips2c/jak1_functions/ocean_vu0.cpp @@ -3,7 +3,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace ocean_interp_wave { struct Cache { void* ocean_wave_frames; // *ocean-wave-frames* @@ -204,7 +204,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace ocean_generate_verts { struct Cache { void* ocean_vu0_work; // *ocean-vu0-work* diff --git a/game/mips2c/functions/ripple.cpp b/game/mips2c/jak1_functions/ripple.cpp similarity index 99% rename from game/mips2c/functions/ripple.cpp rename to game/mips2c/jak1_functions/ripple.cpp index e75a904200..8fc1245f51 100644 --- a/game/mips2c/functions/ripple.cpp +++ b/game/mips2c/jak1_functions/ripple.cpp @@ -3,7 +3,7 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { struct RippleVu0 { Vf data_mem[256]; @@ -90,7 +90,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace ripple_create_wave_table { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -421,7 +421,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace ripple_apply_wave_table { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -525,7 +525,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace ripple_matrix_scale { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; diff --git a/game/mips2c/functions/shadow.cpp b/game/mips2c/jak1_functions/shadow.cpp similarity index 99% rename from game/mips2c/functions/shadow.cpp rename to game/mips2c/jak1_functions/shadow.cpp index 9413f991ca..73fefbcf8e 100644 --- a/game/mips2c/functions/shadow.cpp +++ b/game/mips2c/jak1_functions/shadow.cpp @@ -2,7 +2,7 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { // clang-format off namespace { void exec_0(ExecutionContext* c) { @@ -376,7 +376,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_calc_dual_verts { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -582,7 +582,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_scissor_edges { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -690,7 +690,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_scissor_top { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -766,7 +766,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_init_vars { struct Cache { void* math_camera; // *math-camera* @@ -832,7 +832,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_find_facing_single_tris { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -1136,7 +1136,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_find_single_edges { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -1236,7 +1236,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_find_facing_double_tris { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -1518,7 +1518,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_find_double_edges { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -1624,7 +1624,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_add_verts { struct Cache { void* shadow_data; // *shadow-data* @@ -1808,7 +1808,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_add_facing_single_tris { struct Cache { void* shadow_data; // *shadow-data* @@ -1887,7 +1887,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_add_single_edges { struct Cache { void* shadow_data; // *shadow-data* @@ -1970,7 +1970,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_add_double_tris { struct Cache { void* shadow_data; // *shadow-data* @@ -2047,7 +2047,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_add_double_edges { struct Cache { void* shadow_data; // *shadow-data* @@ -2130,7 +2130,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace shadow_execute { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* diff --git a/game/mips2c/functions/sky_tng.cpp b/game/mips2c/jak1_functions/sky_tng.cpp similarity index 99% rename from game/mips2c/functions/sky_tng.cpp rename to game/mips2c/jak1_functions/sky_tng.cpp index 8aef0c43a5..efa5a58a69 100644 --- a/game/mips2c/functions/sky_tng.cpp +++ b/game/mips2c/jak1_functions/sky_tng.cpp @@ -3,17 +3,17 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { ExecutionContext sky_regs_vfs; -} // namespace Mips2C +} // namespace Mips2C::jak1 // clang-format off //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace init_sky_regs { struct Cache { void* math_camera; // *math-camera* @@ -108,7 +108,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace set_tex_offset { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -156,7 +156,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace clip_polygon_against_positive_hyperplane { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -441,7 +441,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace clip_polygon_against_negative_hyperplane { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -736,7 +736,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_large_polygon { struct Cache { void* clip_polygon_against_negative_hyperplane; // clip-polygon-against-negative-hyperplane @@ -886,7 +886,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace render_sky_quad { struct Cache { void* math_camera; // *math-camera* @@ -990,7 +990,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace render_sky_tri { struct Cache { void* draw_large_polygon; // draw-large-polygon @@ -1075,7 +1075,7 @@ void link() { } // namespace render_sky_tri } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace set_sky_vf27 { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -1091,7 +1091,7 @@ void link() { } // namespace set_sky_vf27 } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace set_sky_vf23_value { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -1108,7 +1108,7 @@ void link() { } // namespace set_sky_vf23_value } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace init_boundary_regs { struct Cache { void* math_camera; // *math-camera* @@ -1169,7 +1169,7 @@ void link() { } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_boundary_polygon { struct Cache { void* clip_polygon_against_negative_hyperplane; // clip-polygon-against-negative-hyperplane @@ -1303,7 +1303,7 @@ void link() { } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace render_boundary_quad { struct Cache { void* math_camera; // *math-camera* @@ -1437,7 +1437,7 @@ void link() { } // namespace render_boundary_quad } // namespace Mips2C -namespace Mips2C { +namespace Mips2C::jak1 { namespace render_boundary_tri { struct Cache { void* draw_boundary_polygon; // draw-boundary-polygon diff --git a/game/mips2c/functions/sparticle.cpp b/game/mips2c/jak1_functions/sparticle.cpp similarity index 99% rename from game/mips2c/functions/sparticle.cpp rename to game/mips2c/jak1_functions/sparticle.cpp index 1d0cdfb798..5c23977d1f 100644 --- a/game/mips2c/functions/sparticle.cpp +++ b/game/mips2c/jak1_functions/sparticle.cpp @@ -3,7 +3,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace sp_process_block_3d { struct Cache { void* sp_frame_time; // *sp-frame-time* @@ -371,7 +371,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace sp_process_block_2d { struct Cache { void* sp_frame_time; // *sp-frame-time* diff --git a/game/mips2c/functions/sparticle_launcher.cpp b/game/mips2c/jak1_functions/sparticle_launcher.cpp similarity index 99% rename from game/mips2c/functions/sparticle_launcher.cpp rename to game/mips2c/jak1_functions/sparticle_launcher.cpp index e78128f90e..caa8143f8e 100644 --- a/game/mips2c/functions/sparticle_launcher.cpp +++ b/game/mips2c/jak1_functions/sparticle_launcher.cpp @@ -3,7 +3,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace sp_init_fields { struct Cache { void* part_id_table; // *part-id-table* @@ -343,7 +343,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace particle_adgif { struct Cache { void* particle_adgif_cache; // *particle-adgif-cache* @@ -479,7 +479,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace sp_launch_particles_var { struct Cache { void* level; // *level* diff --git a/game/mips2c/functions/test_func.cpp b/game/mips2c/jak1_functions/test_func.cpp similarity index 94% rename from game/mips2c/functions/test_func.cpp rename to game/mips2c/jak1_functions/test_func.cpp index 6f770af8e0..a4b238b67f 100644 --- a/game/mips2c/functions/test_func.cpp +++ b/game/mips2c/jak1_functions/test_func.cpp @@ -2,7 +2,7 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace test_func { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; @@ -16,12 +16,12 @@ u64 execute(void* ctxt) { return 0; } } // namespace test_func -} // namespace Mips2C +} // namespace Mips2C::jak1 //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace goal_call_test { struct Cache { void* goal_check_function; @@ -65,4 +65,4 @@ void link() { } } // namespace goal_call_test -} // namespace Mips2C +} // namespace Mips2C::jak1 diff --git a/game/mips2c/functions/texture.cpp b/game/mips2c/jak1_functions/texture.cpp similarity index 99% rename from game/mips2c/functions/texture.cpp rename to game/mips2c/jak1_functions/texture.cpp index 04dae9f04a..6675f78766 100644 --- a/game/mips2c/functions/texture.cpp +++ b/game/mips2c/jak1_functions/texture.cpp @@ -3,7 +3,7 @@ #include "game/mips2c/mips2c_private.h" #include "game/kernel/jak1/kscheme.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace adgif_shader_texture_with_update { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; diff --git a/game/mips2c/functions/tfrag.cpp b/game/mips2c/jak1_functions/tfrag.cpp similarity index 99% rename from game/mips2c/functions/tfrag.cpp rename to game/mips2c/jak1_functions/tfrag.cpp index 6bb421e9e1..6baf04440a 100644 --- a/game/mips2c/functions/tfrag.cpp +++ b/game/mips2c/jak1_functions/tfrag.cpp @@ -3,7 +3,7 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_inline_array_tfrag { struct Cache { void* tfrag_work; // *tfrag-work* @@ -710,13 +710,13 @@ void link() { } } // namespace draw_inline_array_tfrag -} // namespace Mips2C +} // namespace Mips2C::jak1 // clang-format off //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace stats_tfrag_asm { struct Cache { void* tfrag_work; // *tfrag-work* diff --git a/game/mips2c/functions/tie_methods.cpp b/game/mips2c/jak1_functions/tie_methods.cpp similarity index 99% rename from game/mips2c/functions/tie_methods.cpp rename to game/mips2c/jak1_functions/tie_methods.cpp index e240e25d71..0100333907 100644 --- a/game/mips2c/functions/tie_methods.cpp +++ b/game/mips2c/jak1_functions/tie_methods.cpp @@ -3,7 +3,7 @@ #include "game/kernel/jak1/kscheme.h" #include "game/mips2c/mips2c_private.h" using namespace jak1; -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_inline_array_instance_tie { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* @@ -1349,7 +1349,7 @@ void link() { //--------------------------MIPS2C--------------------- #include "game/mips2c/mips2c_private.h" -namespace Mips2C { +namespace Mips2C::jak1 { namespace draw_inline_array_prototype_tie_generic_asm { struct Cache { void* fake_scratchpad_data; // *fake-scratchpad-data* diff --git a/game/mips2c/functions/time_of_day.cpp b/game/mips2c/jak1_functions/time_of_day.cpp similarity index 99% rename from game/mips2c/functions/time_of_day.cpp rename to game/mips2c/jak1_functions/time_of_day.cpp index 7ab849afd6..23e2997de5 100644 --- a/game/mips2c/functions/time_of_day.cpp +++ b/game/mips2c/jak1_functions/time_of_day.cpp @@ -6,7 +6,7 @@ using namespace jak1; // clang-format off -namespace Mips2C { +namespace Mips2C::jak1 { namespace time_of_day_interp_colors_scratch { struct Cache { diff --git a/game/mips2c/jak2_functions/collide_func.cpp b/game/mips2c/jak2_functions/collide_func.cpp new file mode 100644 index 0000000000..b5018a9184 --- /dev/null +++ b/game/mips2c/jak2_functions/collide_func.cpp @@ -0,0 +1,500 @@ +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak2/kscheme.h" +using ::jak2::intern_from_c; +namespace Mips2C::jak2 { +namespace moving_sphere_triangle_intersect { +struct Cache { + void* collide_do_primitives; // collide-do-primitives +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -16); // daddiu sp, sp, -16 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->lqc2(vf14, 0, a0); // lqc2 vf14, 0(a0) + c->lqc2(vf15, 0, a1); // lqc2 vf15, 0(a1) + c->lqc2(vf11, 0, a3); // lqc2 vf11, 0(a3) + c->lqc2(vf12, 16, a3); // lqc2 vf12, 16(a3) + c->lqc2(vf13, 32, a3); // lqc2 vf13, 32(a3) + c->mov128_vf_gpr(vf1, a2); // qmtc2.i vf1, a2 + c->vadd(DEST::xyzw, vf6, vf14, vf15); // vadd.xyzw vf6, vf14, vf15 + c->vsub(DEST::xyzw, vf11, vf11, vf12); // vsub.xyzw vf11, vf11, vf12 + c->vsub(DEST::xyzw, vf13, vf13, vf12); // vsub.xyzw vf13, vf13, vf12 + c->vsub(DEST::xyzw, vf14, vf14, vf12); // vsub.xyzw vf14, vf14, vf12 + c->vsub(DEST::xyzw, vf6, vf6, vf12); // vsub.xyzw vf6, vf6, vf12 + c->vmini(DEST::xyzw, vf2, vf11, vf0); // vmini.xyzw vf2, vf11, vf0 + c->vopmula(vf13, vf11); // vopmula.xyz acc, vf13, vf11 + c->vopmsub(vf16, vf11, vf13); // vopmsub.xyz vf16, vf11, vf13 + c->vmax(DEST::xyzw, vf3, vf11, vf0); // vmax.xyzw vf3, vf11, vf0 + c->vmini(DEST::xyzw, vf4, vf14, vf6); // vmini.xyzw vf4, vf14, vf6 + c->vmax(DEST::xyzw, vf5, vf14, vf6); // vmax.xyzw vf5, vf14, vf6 + c->vmul(DEST::xyzw, vf7, vf16, vf16); // vmul.xyzw vf7, vf16, vf16 + c->vmini(DEST::xyzw, vf2, vf2, vf13); // vmini.xyzw vf2, vf2, vf13 + c->vmax(DEST::xyzw, vf3, vf3, vf13); // vmax.xyzw vf3, vf3, vf13 + c->vsub_bc(DEST::xyzw, BC::x, vf4, vf4, vf1); // vsubx.xyzw vf4, vf4, vf1 + c->vadd_bc(DEST::x, BC::y, vf7, vf7, vf7); // vaddy.x vf7, vf7, vf7 + c->vadd_bc(DEST::xyzw, BC::x, vf5, vf5, vf1); // vaddx.xyzw vf5, vf5, vf1 + // nop // sll r0, r0, 0 + c->vsub(DEST::xyzw, vf3, vf3, vf4); // vsub.xyzw vf3, vf3, vf4 + c->vadd_bc(DEST::x, BC::z, vf7, vf7, vf7); // vaddz.x vf7, vf7, vf7 + c->vsub(DEST::xyzw, vf5, vf5, vf2); // vsub.xyzw vf5, vf5, vf2 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t2, vf3); // qmfc2.i t2, vf3 + c->mov128_gpr_vf(v1, vf5); // qmfc2.i v1, vf5 + c->vrsqrt(vf0, BC::w, vf7, BC::x); // vrsqrt Q, vf0.w, vf7.x + c->or_(v1, t2, v1); // or v1, t2, v1 + c->pcgtw(v1, r0, v1); // pcgtw v1, r0, v1 + c->ppach(v1, r0, v1); // ppach v1, r0, v1 + c->dsll(v1, v1, 16); // dsll v1, v1, 16 + bc = c->sgpr64(v1) != 0; // bne v1, r0, L14 + // nop // sll r0, r0, 0 + if (bc) {goto block_14;} // branch non-likely + + c->vmul(DEST::xyzw, vf2, vf16, vf15); // vmul.xyzw vf2, vf16, vf15 + c->vmul(DEST::xyzw, vf3, vf16, vf14); // vmul.xyzw vf3, vf16, vf14 + c->vadd_bc(DEST::x, BC::y, vf2, vf2, vf2); // vaddy.x vf2, vf2, vf2 + c->vsub_bc(DEST::y, BC::y, vf3, vf0, vf3); // vsuby.y vf3, vf0, vf3 + c->vadd_bc(DEST::x, BC::z, vf2, vf2, vf2); // vaddz.x vf2, vf2, vf2 + c->vsub_bc(DEST::y, BC::x, vf3, vf3, vf3); // vsubx.y vf3, vf3, vf3 + c->vsub_bc(DEST::y, BC::z, vf3, vf3, vf3); // vsubz.y vf3, vf3, vf3 + c->vadd_bc(DEST::x, BC::x, vf3, vf0, vf0); // vaddx.x vf3, vf0, vf0 + c->vadd_bc(DEST::x, BC::x, vf4, vf0, vf0); // vaddx.x vf4, vf0, vf0 + c->vwaitq(); // vwaitq + c->vmulq(DEST::xyzw, vf16, vf16); // vmulq.xyzw vf16, vf16, Q + c->vmove(DEST::w, vf16, vf0); // vmove.w vf16, vf0 + c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q + c->vmulq(DEST::xyzw, vf4, vf3); // vmulq.xyzw vf4, vf3, Q + c->vmulq(DEST::xyzw, vf3, vf3); // vmulq.xyzw vf3, vf3, Q + c->sqc2(vf16, 0, t1); // sqc2 vf16, 0(t1) + // nop // vnop + // nop // vnop + c->vdiv(vf0, BC::w, vf2, BC::x); // vdiv Q, vf0.w, vf2.x + c->vadd_bc(DEST::y, BC::x, vf3, vf3, vf1); // vaddx.y vf3, vf3, vf1 + c->vsub_bc(DEST::y, BC::x, vf4, vf4, vf1); // vsubx.y vf4, vf4, vf1 + c->vwaitq(); // vwaitq + c->vmulq(DEST::xyzw, vf3, vf3); // vmulq.xyzw vf3, vf3, Q + c->vmulq(DEST::xyzw, vf4, vf4); // vmulq.xyzw vf4, vf4, Q + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3 + c->mov128_gpr_vf(t1, vf4); // qmfc2.i t1, vf4 + bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L12 + // nop // sll r0, r0, 0 + if (bc) {goto block_11;} // branch non-likely + + bc = ((s64)c->sgpr64(t1)) < 0; // bltz t1, L13 + // nop // sll r0, r0, 0 + if (bc) {goto block_12;} // branch non-likely + + c->dsubu(v1, v1, t1); // dsubu v1, v1, t1 + bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L9 + // nop // sll r0, r0, 0 + if (bc) {goto block_6;} // branch non-likely + + c->vsub_bc(DEST::xyzw, BC::w, vf2, vf4, vf0); // vsubw.xyzw vf2, vf4, vf0 + c->mov128_gpr_vf(v1, vf2); // qmfc2.i v1, vf2 + bc = ((s64)c->sgpr64(v1)) >= 0; // bgez v1, L14 + // nop // sll r0, r0, 0 + if (bc) {goto block_14;} // branch non-likely + + c->mov128_gpr_vf(v0, vf4); // qmfc2.i v0, vf4 + c->vmula_bc(DEST::xyzw, BC::w, vf14, vf0); // vmulaw.xyzw acc, vf14, vf0 + c->vmadd_bc(DEST::xyzw, BC::y, vf8, vf15, vf4); // vmaddy.xyzw vf8, vf15, vf4 + //beq r0, r0, L10 // beq r0, r0, L10 + // nop // sll r0, r0, 0 + goto block_8; // branch always + + + block_6: + c->vsub_bc(DEST::xyzw, BC::w, vf2, vf3, vf0); // vsubw.xyzw vf2, vf3, vf0 + c->mov128_gpr_vf(v1, vf2); // qmfc2.i v1, vf2 + bc = ((s64)c->sgpr64(v1)) >= 0; // bgez v1, L14 + // nop // sll r0, r0, 0 + if (bc) {goto block_14;} // branch non-likely + + c->vmula_bc(DEST::xyzw, BC::w, vf14, vf0); // vmulaw.xyzw acc, vf14, vf0 + c->vmadd_bc(DEST::xyzw, BC::y, vf8, vf15, vf3); // vmaddy.xyzw vf8, vf15, vf3 + c->mov128_gpr_vf(v0, vf3); // qmfc2.i v0, vf3 + + block_8: + c->dsra32(v0, v0, 0); // dsra32 v0, v0, 0 + c->vsub(DEST::xyzw, vf9, vf8, vf13); // vsub.xyzw vf9, vf8, vf13 + c->vsub(DEST::xyzw, vf10, vf8, vf11); // vsub.xyzw vf10, vf8, vf11 + c->vopmula(vf13, vf8); // vopmula.xyz acc, vf13, vf8 + c->vopmsub(vf5, vf8, vf13); // vopmsub.xyz vf5, vf8, vf13 + c->vopmula(vf8, vf11); // vopmula.xyz acc, vf8, vf11 + c->vopmsub(vf6, vf11, vf8); // vopmsub.xyz vf6, vf11, vf8 + c->vopmula(vf9, vf10); // vopmula.xyz acc, vf9, vf10 + c->vopmsub(vf7, vf10, vf9); // vopmsub.xyz vf7, vf10, vf9 + c->vmul(DEST::xyzw, vf5, vf5, vf16); // vmul.xyzw vf5, vf5, vf16 + c->vmul(DEST::xyzw, vf6, vf6, vf16); // vmul.xyzw vf6, vf6, vf16 + c->vmul(DEST::xyzw, vf7, vf7, vf16); // vmul.xyzw vf7, vf7, vf16 + c->vadd_bc(DEST::y, BC::x, vf5, vf5, vf5); // vaddx.y vf5, vf5, vf5 + c->vadd_bc(DEST::y, BC::x, vf6, vf6, vf6); // vaddx.y vf6, vf6, vf6 + c->vadd_bc(DEST::y, BC::x, vf7, vf7, vf7); // vaddx.y vf7, vf7, vf7 + c->vadd_bc(DEST::y, BC::z, vf5, vf5, vf5); // vaddz.y vf5, vf5, vf5 + c->vadd_bc(DEST::y, BC::z, vf6, vf6, vf6); // vaddz.y vf6, vf6, vf6 + c->vadd_bc(DEST::y, BC::z, vf7, vf7, vf7); // vaddz.y vf7, vf7, vf7 + c->mov128_gpr_vf(t1, vf5); // qmfc2.i t1, vf5 + c->mov128_gpr_vf(t2, vf6); // qmfc2.i t2, vf6 + c->mov128_gpr_vf(v1, vf7); // qmfc2.i v1, vf7 + c->or_(t1, t1, t2); // or t1, t1, t2 + c->or_(v1, t1, v1); // or v1, t1, v1 + bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L11 + // nop // sll r0, r0, 0 + if (bc) {goto block_10;} // branch non-likely + + c->vopmula(vf8, vf16); // vopmula.xyz acc, vf8, vf16 + c->vopmsub(vf5, vf16, vf8); // vopmsub.xyz vf5, vf16, vf8 + c->vopmula(vf16, vf5); // vopmula.xyz acc, vf16, vf5 + c->vopmsub(vf5, vf5, vf16); // vopmsub.xyz vf5, vf5, vf16 + c->vadd(DEST::xyzw, vf5, vf5, vf12); // vadd.xyzw vf5, vf5, vf12 + c->sqc2(vf5, 0, t0); // sqc2 vf5, 0(t0) + //beq r0, r0, L15 // beq r0, r0, L15 + // nop // sll r0, r0, 0 + goto block_15; // branch always + + + block_10: + c->load_symbol(t9, cache.collide_do_primitives); // lw t9, collide-do-primitives(s7) + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + //beq r0, r0, L15 // beq r0, r0, L15 + // nop // sll r0, r0, 0 + goto block_15; // branch always + + + block_11: + bc = ((s64)c->sgpr64(t1)) < 0; // bltz t1, L14 + // nop // sll r0, r0, 0 + if (bc) {goto block_14;} // branch non-likely + + + block_12: + c->vsub(DEST::xyzw, vf9, vf14, vf13); // vsub.xyzw vf9, vf14, vf13 + c->vsub(DEST::xyzw, vf10, vf14, vf11); // vsub.xyzw vf10, vf14, vf11 + c->vopmula(vf13, vf14); // vopmula.xyz acc, vf13, vf14 + c->vopmsub(vf5, vf14, vf13); // vopmsub.xyz vf5, vf14, vf13 + c->vopmula(vf14, vf11); // vopmula.xyz acc, vf14, vf11 + c->vopmsub(vf6, vf11, vf14); // vopmsub.xyz vf6, vf11, vf14 + c->vopmula(vf9, vf10); // vopmula.xyz acc, vf9, vf10 + c->vopmsub(vf7, vf10, vf9); // vopmsub.xyz vf7, vf10, vf9 + c->vmul(DEST::xyzw, vf5, vf5, vf16); // vmul.xyzw vf5, vf5, vf16 + c->vmul(DEST::xyzw, vf6, vf6, vf16); // vmul.xyzw vf6, vf6, vf16 + c->vmul(DEST::xyzw, vf7, vf7, vf16); // vmul.xyzw vf7, vf7, vf16 + c->vadd_bc(DEST::y, BC::x, vf5, vf5, vf5); // vaddx.y vf5, vf5, vf5 + c->vadd_bc(DEST::y, BC::x, vf6, vf6, vf6); // vaddx.y vf6, vf6, vf6 + c->vadd_bc(DEST::y, BC::x, vf7, vf7, vf7); // vaddx.y vf7, vf7, vf7 + c->vadd_bc(DEST::y, BC::z, vf5, vf5, vf5); // vaddz.y vf5, vf5, vf5 + c->vadd_bc(DEST::y, BC::z, vf6, vf6, vf6); // vaddz.y vf6, vf6, vf6 + c->vadd_bc(DEST::y, BC::z, vf7, vf7, vf7); // vaddz.y vf7, vf7, vf7 + c->mov128_gpr_vf(t1, vf5); // qmfc2.i t1, vf5 + c->mov128_gpr_vf(t2, vf6); // qmfc2.i t2, vf6 + c->mov128_gpr_vf(v1, vf7); // qmfc2.i v1, vf7 + c->or_(t1, t1, t2); // or t1, t1, t2 + c->or_(v1, t1, v1); // or v1, t1, v1 + bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L11 + // nop // sll r0, r0, 0 + if (bc) {goto block_10;} // branch non-likely + + c->vopmula(vf14, vf16); // vopmula.xyz acc, vf14, vf16 + c->vopmsub(vf5, vf16, vf14); // vopmsub.xyz vf5, vf16, vf14 + c->vopmula(vf16, vf5); // vopmula.xyz acc, vf16, vf5 + c->vopmsub(vf5, vf5, vf16); // vopmsub.xyz vf5, vf5, vf16 + c->vadd(DEST::xyzw, vf5, vf5, vf12); // vadd.xyzw vf5, vf5, vf12 + c->sqc2(vf5, 0, t0); // sqc2 vf5, 0(t0) + //beq r0, r0, L15 // beq r0, r0, L15 + c->addiu(v0, r0, 0); // addiu v0, r0, 0 + goto block_15; // branch always + + + block_14: + c->lui(v0, -13122); // lui v0, -13122 + c->ori(v0, v0, 48160); // ori v0, v0, 48160 + + block_15: + c->ld(ra, 0, sp); // ld ra, 0(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 16); // daddiu sp, sp, 16 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.collide_do_primitives = intern_from_c("collide-do-primitives").c(); + gLinkedFunctionTable.reg("moving-sphere-triangle-intersect", execute, 512); +} + +} // namespace moving_sphere_triangle_intersect +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak2/kscheme.h" +using ::jak2::intern_from_c; +namespace Mips2C::jak2 { +namespace collide_do_primitives { +struct Cache { + void* ray_cylinder_intersect; // ray-cylinder-intersect + void* ray_sphere_intersect; // ray-sphere-intersect +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + bool cop1_bc = false; + c->daddiu(sp, sp, -144); // daddiu sp, sp, -144 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sq(s1, 32, sp); // sq s1, 32(sp) + c->sq(s2, 48, sp); // sq s2, 48(sp) + c->sq(s3, 64, sp); // sq s3, 64(sp) + c->sq(s4, 80, sp); // sq s4, 80(sp) + c->sq(s5, 96, sp); // sq s5, 96(sp) + c->sq(gp, 112, sp); // sq gp, 112(sp) + c->swc1(f28, 128, sp); // swc1 f28, 128(sp) + c->swc1(f30, 132, sp); // swc1 f30, 132(sp) + c->mov64(s4, a0); // or s4, a0, r0 + c->mov64(s3, a1); // or s3, a1, r0 + c->mov64(s1, a2); // or s1, a2, r0 + c->mov64(s5, a3); // or s5, a3, r0 + c->mov64(gp, t0); // or gp, t0, r0 + c->daddiu(s2, sp, 16); // daddiu s2, sp, 16 + c->lui(v1, 16384); // lui v1, 16384 + c->mtc1(f31, v1); // mtc1 f31, v1 + c->mtc1(f28, r0); // mtc1 f28, r0 + c->load_symbol(t9, cache.ray_sphere_intersect); // lw t9, ray-sphere-intersect(s7) + c->mov64(a0, s4); // or a0, s4, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->daddu(a2, r0, s5); // daddu a2, r0, s5 + c->mov64(a3, s1); // or a3, s1, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + c->mtc1(f30, v0); // mtc1 f30, v0 + cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28 + bc = cop1_bc; // bc1t L17 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + c->mtc1(f31, v0); // mtc1 f31, v0 + c->lqc2(vf31, 0, s5); // lqc2 vf31, 0(s5) + + block_2: + c->load_symbol(t9, cache.ray_sphere_intersect); // lw t9, ray-sphere-intersect(s7) + c->mov64(a0, s4); // or a0, s4, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->daddiu(a2, s5, 16); // daddiu a2, s5, 16 + c->mov64(a3, s1); // or a3, s1, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + c->mtc1(f30, v0); // mtc1 f30, v0 + cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28 + bc = cop1_bc; // bc1t L18 + cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31 + if (bc) {goto block_5;} // branch non-likely + + bc = !cop1_bc; // bc1f L18 + // nop // sll r0, r0, 0 + if (bc) {goto block_5;} // branch non-likely + + c->mtc1(f31, v0); // mtc1 f31, v0 + c->lqc2(vf31, 16, s5); // lqc2 vf31, 16(s5) + + block_5: + c->load_symbol(t9, cache.ray_sphere_intersect); // lw t9, ray-sphere-intersect(s7) + c->mov64(a0, s4); // or a0, s4, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->daddiu(a2, s5, 32); // daddiu a2, s5, 32 + c->mov64(a3, s1); // or a3, s1, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + c->mtc1(f30, v0); // mtc1 f30, v0 + cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28 + bc = cop1_bc; // bc1t L19 + cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31 + if (bc) {goto block_8;} // branch non-likely + + bc = !cop1_bc; // bc1f L19 + // nop // sll r0, r0, 0 + if (bc) {goto block_8;} // branch non-likely + + c->mtc1(f31, v0); // mtc1 f31, v0 + c->lqc2(vf31, 32, s5); // lqc2 vf31, 32(s5) + + block_8: + c->lqc2(vf1, 0, s5); // lqc2 vf1, 0(s5) + c->lqc2(vf2, 16, s5); // lqc2 vf2, 16(s5) + c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1 + c->vmul(DEST::xyzw, vf3, vf2, vf2); // vmul.xyzw vf3, vf2, vf2 + c->vadd_bc(DEST::x, BC::y, vf3, vf3, vf3); // vaddy.x vf3, vf3, vf3 + c->vadd_bc(DEST::x, BC::z, vf3, vf3, vf3); // vaddz.x vf3, vf3, vf3 + c->vrsqrt(vf0, BC::w, vf3, BC::x); // vrsqrt Q, vf0.w, vf3.x + c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3 + c->mtc1(f30, v1); // mtc1 f30, v1 + c->sqrts(f30, f30); // sqrt.s f30, f30 + c->vwaitq(); // vwaitq + c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q + c->sqc2(vf2, 0, s2); // sqc2 vf2, 0(s2) + c->mfc1(t1, f30); // mfc1 t1, f30 + c->load_symbol(t9, cache.ray_cylinder_intersect); // lw t9, ray-cylinder-intersect(s7) + c->mov64(a0, s4); // or a0, s4, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->daddu(a2, r0, s5); // daddu a2, r0, s5 + c->mov64(a3, s2); // or a3, s2, r0 + c->mov64(t0, s1); // or t0, s1, r0 + c->mov64(t2, gp); // or t2, gp, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + c->mtc1(f30, v0); // mtc1 f30, v0 + cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28 + bc = cop1_bc; // bc1t L20 + cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31 + if (bc) {goto block_11;} // branch non-likely + + bc = !cop1_bc; // bc1f L20 + // nop // sll r0, r0, 0 + if (bc) {goto block_11;} // branch non-likely + + c->mtc1(f31, v0); // mtc1 f31, v0 + c->lqc2(vf31, 0, gp); // lqc2 vf31, 0(gp) + + block_11: + c->lqc2(vf1, 16, s5); // lqc2 vf1, 16(s5) + c->lqc2(vf2, 32, s5); // lqc2 vf2, 32(s5) + c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1 + c->vmul(DEST::xyzw, vf3, vf2, vf2); // vmul.xyzw vf3, vf2, vf2 + c->vadd_bc(DEST::x, BC::y, vf3, vf3, vf3); // vaddy.x vf3, vf3, vf3 + c->vadd_bc(DEST::x, BC::z, vf3, vf3, vf3); // vaddz.x vf3, vf3, vf3 + c->vrsqrt(vf0, BC::w, vf3, BC::x); // vrsqrt Q, vf0.w, vf3.x + c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3 + c->mtc1(f30, v1); // mtc1 f30, v1 + c->sqrts(f30, f30); // sqrt.s f30, f30 + c->vwaitq(); // vwaitq + c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q + c->sqc2(vf2, 0, s2); // sqc2 vf2, 0(s2) + c->mfc1(t1, f30); // mfc1 t1, f30 + c->load_symbol(t9, cache.ray_cylinder_intersect); // lw t9, ray-cylinder-intersect(s7) + c->mov64(a0, s4); // or a0, s4, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->daddiu(a2, s5, 16); // daddiu a2, s5, 16 + c->mov64(a3, s2); // or a3, s2, r0 + c->mov64(t0, s1); // or t0, s1, r0 + c->mov64(t2, gp); // or t2, gp, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + c->mtc1(f30, v0); // mtc1 f30, v0 + cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28 + bc = cop1_bc; // bc1t L21 + cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31 + if (bc) {goto block_14;} // branch non-likely + + bc = !cop1_bc; // bc1f L21 + // nop // sll r0, r0, 0 + if (bc) {goto block_14;} // branch non-likely + + c->mtc1(f31, v0); // mtc1 f31, v0 + c->lqc2(vf31, 0, gp); // lqc2 vf31, 0(gp) + + block_14: + c->lqc2(vf1, 32, s5); // lqc2 vf1, 32(s5) + c->lqc2(vf2, 0, s5); // lqc2 vf2, 0(s5) + c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1 + c->vmul(DEST::xyzw, vf3, vf2, vf2); // vmul.xyzw vf3, vf2, vf2 + c->vadd_bc(DEST::x, BC::y, vf3, vf3, vf3); // vaddy.x vf3, vf3, vf3 + c->vadd_bc(DEST::x, BC::z, vf3, vf3, vf3); // vaddz.x vf3, vf3, vf3 + c->vrsqrt(vf0, BC::w, vf3, BC::x); // vrsqrt Q, vf0.w, vf3.x + c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3 + c->mtc1(f30, v1); // mtc1 f30, v1 + c->sqrts(f30, f30); // sqrt.s f30, f30 + c->vwaitq(); // vwaitq + c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q + c->sqc2(vf2, 0, s2); // sqc2 vf2, 0(s2) + c->mfc1(t1, f30); // mfc1 t1, f30 + c->load_symbol(t9, cache.ray_cylinder_intersect); // lw t9, ray-cylinder-intersect(s7) + c->daddiu(a2, s5, 32); // daddiu a2, s5, 32 + c->mov64(t2, gp); // or t2, gp, r0 + c->mov64(a0, s4); // or a0, s4, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->mov64(a3, s2); // or a3, s2, r0 + c->mov64(t0, s1); // or t0, s1, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + c->mtc1(f30, v0); // mtc1 f30, v0 + cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28 + bc = cop1_bc; // bc1t L22 + cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31 + if (bc) {goto block_17;} // branch non-likely + + bc = !cop1_bc; // bc1f L22 + // nop // sll r0, r0, 0 + if (bc) {goto block_17;} // branch non-likely + + c->mtc1(f31, v0); // mtc1 f31, v0 + c->lqc2(vf31, 0, gp); // lqc2 vf31, 0(gp) + + block_17: + c->lui(v1, 16256); // lui v1, 16256 + c->mtc1(f0, v1); // mtc1 f0, v1 + c->lui(v1, -13122); // lui v1, -13122 + c->ori(v1, v1, 48160); // ori v1, v1, 48160 + cop1_bc = c->fprs[f0] < c->fprs[f31]; // c.lt.s f0, f31 + if (cop1_bc) { // bc1tl L23 + c->mtc1(f31, v1); // mtc1 f31, v1 + goto block_19; + } + + block_19: + c->mfc1(v0, f31); // mfc1 v0, f31 + c->sqc2(vf31, 0, gp); // sqc2 vf31, 0(gp) + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->lwc1(f30, 132, sp); // lwc1 f30, 132(sp) + c->lwc1(f28, 128, sp); // lwc1 f28, 128(sp) + c->lq(gp, 112, sp); // lq gp, 112(sp) + c->lq(s5, 96, sp); // lq s5, 96(sp) + c->lq(s4, 80, sp); // lq s4, 80(sp) + c->lq(s3, 64, sp); // lq s3, 64(sp) + c->lq(s2, 48, sp); // lq s2, 48(sp) + c->lq(s1, 32, sp); // lq s1, 32(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 144); // daddiu sp, sp, 144 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.ray_cylinder_intersect = intern_from_c("ray-cylinder-intersect").c(); + cache.ray_sphere_intersect = intern_from_c("ray-sphere-intersect").c(); + gLinkedFunctionTable.reg("collide-do-primitives", execute, 512); +} + +} // namespace collide_do_primitives +} // namespace Mips2C diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index 4133c91e61..e18278cbf9 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -6,405 +6,195 @@ #include "game/kernel/common/kmalloc.h" #include "game/kernel/common/kscheme.h" #include "game/kernel/jak1/kscheme.h" - -using namespace jak1_symbols; +#include "game/kernel/jak2/kscheme.h" +#include "game/runtime.h" extern "C" { void _mips2c_call_linux(); void _mips2c_call_windows(); } +// clang-format off namespace Mips2C { -namespace draw_string { -extern void link(); -} +namespace jak1 { +namespace draw_string { extern void link(); } +namespace sp_init_fields { extern void link(); } +namespace particle_adgif { extern void link(); } +namespace sp_launch_particles_var { extern void link(); } +namespace sp_process_block_3d { extern void link(); } +namespace sp_process_block_2d { extern void link(); } +namespace draw_large_polygon { extern void link(); } +namespace init_sky_regs { extern void link(); } +namespace clip_polygon_against_positive_hyperplane { extern void link(); } +namespace render_sky_quad { extern void link(); } +namespace render_sky_tri { extern void link(); } +namespace set_tex_offset { extern void link(); } +namespace set_sky_vf27 { extern void link(); } +namespace set_sky_vf23_value { extern void link(); } +namespace adgif_shader_texture_with_update { extern void link(); } +namespace init_boundary_regs { extern void link(); } +namespace render_boundary_quad { extern void link(); } +namespace render_boundary_tri { extern void link(); } +namespace draw_boundary_polygon { extern void link(); } +namespace draw_inline_array_tfrag { extern void link(); } +namespace stats_tfrag_asm { extern void link(); } +namespace time_of_day_interp_colors_scratch { extern void link(); } +namespace collide_do_primitives { extern void link(); } +namespace moving_sphere_triangle_intersect { extern void link(); } +namespace method_12_collide_mesh { extern void link(); } +namespace method_11_collide_mesh { extern void link(); } +namespace collide_probe_node { extern void link(); } +namespace collide_probe_instance_tie { extern void link(); } +namespace method_26_collide_cache { extern void link(); } +namespace method_32_collide_cache { extern void link(); } +namespace pc_upload_collide_frag { extern void link(); } +namespace method_28_collide_cache { extern void link(); } +namespace method_27_collide_cache { extern void link(); } +namespace method_29_collide_cache { extern void link(); } +namespace method_12_collide_shape_prim_mesh { extern void link(); } +namespace method_14_collide_shape_prim_mesh { extern void link(); } +namespace method_13_collide_shape_prim_mesh { extern void link(); } +namespace method_30_collide_cache { extern void link(); } +namespace method_9_collide_cache_prim { extern void link(); } +namespace method_10_collide_cache_prim { extern void link(); } +namespace method_10_collide_puss_work { extern void link(); } +namespace method_9_collide_puss_work { extern void link(); } +namespace method_15_collide_mesh { extern void link(); } +namespace method_14_collide_mesh { extern void link(); } +namespace method_16_collide_edge_work { extern void link(); } +namespace method_15_collide_edge_work { extern void link(); } +namespace method_10_collide_edge_hold_list { extern void link(); } +namespace method_18_collide_edge_work { extern void link(); } +namespace calc_animation_from_spr { extern void link(); } +namespace bones_mtx_calc { extern void link(); } +namespace cspace_parented_transformq_joint { extern void link(); } +namespace draw_bones_merc { extern void link(); } +namespace draw_bones_check_longest_edge_asm { extern void link(); } +namespace blerc_execute { extern void link(); } +namespace setup_blerc_chains_for_one_fragment { extern void link(); } +namespace generic_merc_init_asm { extern void link(); } +namespace generic_merc_execute_asm { extern void link(); } +namespace mercneric_convert { extern void link(); } +namespace generic_prepare_dma_double { extern void link(); } +namespace generic_light_proc { extern void link(); } +namespace generic_envmap_proc { extern void link(); } +namespace high_speed_reject { extern void link(); } +namespace generic_prepare_dma_single { extern void link(); } +namespace ripple_create_wave_table { extern void link(); } +namespace ripple_execute_init { extern void link(); } +namespace ripple_apply_wave_table { extern void link(); } +namespace ripple_matrix_scale { extern void link(); } +namespace init_ocean_far_regs { extern void link(); } +namespace render_ocean_quad { extern void link(); } +namespace draw_large_polygon_ocean { extern void link(); } +namespace ocean_interp_wave { extern void link(); } +namespace ocean_generate_verts { extern void link(); } +namespace shadow_execute { extern void link(); } +namespace shadow_add_double_edges { extern void link(); } +namespace shadow_add_double_tris { extern void link(); } +namespace shadow_add_single_edges { extern void link(); } +namespace shadow_add_facing_single_tris { extern void link(); } +namespace shadow_add_verts { extern void link(); } +namespace shadow_find_double_edges { extern void link(); } +namespace shadow_find_facing_double_tris { extern void link(); } +namespace shadow_find_single_edges { extern void link(); } +namespace shadow_find_facing_single_tris { extern void link(); } +namespace shadow_init_vars { extern void link(); } +namespace shadow_scissor_top { extern void link(); } +namespace shadow_scissor_edges { extern void link(); } +namespace shadow_calc_dual_verts { extern void link(); } +namespace shadow_xform_verts { extern void link(); } +namespace draw_inline_array_instance_tie { extern void link(); } +namespace draw_inline_array_prototype_tie_generic_asm { extern void link(); } +namespace generic_tie_dma_to_spad_sync { extern void link(); } +namespace generic_envmap_dproc { extern void link(); } +namespace generic_interp_dproc { extern void link(); } +namespace generic_no_light_dproc { extern void link(); } +namespace generic_tie_convert { extern void link(); } +} // namespace jak1 -namespace sp_init_fields { -extern void link(); -} +namespace jak2 { +namespace collide_do_primitives { extern void link(); } +namespace moving_sphere_triangle_intersect { extern void link(); } -namespace particle_adgif { -extern void link(); } +// clang-format on -namespace sp_launch_particles_var { -extern void link(); -} - -namespace sp_process_block_3d { -extern void link(); -} - -namespace sp_process_block_2d { -extern void link(); -} - -namespace draw_large_polygon { -extern void link(); -} - -namespace init_sky_regs { -extern void link(); -} - -namespace clip_polygon_against_positive_hyperplane { -extern void link(); -} - -namespace render_sky_quad { -extern void link(); -} - -namespace render_sky_tri { -extern void link(); -} - -namespace set_tex_offset { -extern void link(); -} - -namespace set_sky_vf27 { -extern void link(); -} - -namespace set_sky_vf23_value { -extern void link(); -} - -namespace adgif_shader_texture_with_update { -extern void link(); -} - -namespace init_boundary_regs { -extern void link(); -} - -namespace render_boundary_quad { -extern void link(); -} - -namespace render_boundary_tri { -extern void link(); -} - -namespace draw_boundary_polygon { -extern void link(); -} - -namespace draw_inline_array_tfrag { -extern void link(); -} - -namespace stats_tfrag_asm { -extern void link(); -} - -namespace time_of_day_interp_colors_scratch { -extern void link(); -} - -namespace collide_do_primitives { -extern void link(); -} - -namespace moving_sphere_triangle_intersect { -extern void link(); -} - -namespace method_12_collide_mesh { -extern void link(); -} - -namespace method_11_collide_mesh { -extern void link(); -} - -namespace collide_probe_node { -extern void link(); -} - -namespace collide_probe_instance_tie { -extern void link(); -} - -namespace method_26_collide_cache { -extern void link(); -} - -namespace method_32_collide_cache { -extern void link(); -} - -namespace pc_upload_collide_frag { -extern void link(); -} - -namespace method_28_collide_cache { -extern void link(); -} - -namespace method_27_collide_cache { -extern void link(); -} - -namespace method_29_collide_cache { -extern void link(); -} - -namespace method_12_collide_shape_prim_mesh { -extern void link(); -} - -namespace method_14_collide_shape_prim_mesh { -extern void link(); -} - -namespace method_13_collide_shape_prim_mesh { -extern void link(); -} - -namespace method_30_collide_cache { -extern void link(); -} - -namespace method_9_collide_cache_prim { -extern void link(); -} - -namespace method_10_collide_cache_prim { -extern void link(); -} - -namespace method_10_collide_puss_work { -extern void link(); -} - -namespace method_9_collide_puss_work { -extern void link(); -} -namespace method_15_collide_mesh { -extern void link(); -} - -namespace method_14_collide_mesh { -extern void link(); -} - -namespace method_16_collide_edge_work { -extern void link(); -} - -namespace method_15_collide_edge_work { -extern void link(); -} - -namespace method_10_collide_edge_hold_list { -extern void link(); -} - -namespace method_18_collide_edge_work { -extern void link(); -} - -namespace calc_animation_from_spr { -extern void link(); -} -namespace bones_mtx_calc { -extern void link(); -} -namespace cspace_parented_transformq_joint { -extern void link(); -} -namespace draw_bones_merc { -extern void link(); -} -namespace draw_bones_check_longest_edge_asm { -extern void link(); -} -namespace blerc_execute { -extern void link(); -} -namespace setup_blerc_chains_for_one_fragment { -extern void link(); -} -namespace generic_merc_init_asm { -extern void link(); -} -namespace generic_merc_execute_asm { -extern void link(); -} -namespace mercneric_convert { -extern void link(); -} -namespace generic_prepare_dma_double { -extern void link(); -} -namespace generic_light_proc { -extern void link(); -} -namespace generic_envmap_proc { -extern void link(); -} -namespace high_speed_reject { -extern void link(); -} -namespace generic_prepare_dma_single { -extern void link(); -} -namespace ripple_create_wave_table { -extern void link(); -} -namespace ripple_execute_init { -extern void link(); -} -namespace ripple_apply_wave_table { -extern void link(); -} -namespace ripple_matrix_scale { -extern void link(); -} -namespace init_ocean_far_regs { -extern void link(); -} -namespace render_ocean_quad { -extern void link(); -} -namespace draw_large_polygon_ocean { -extern void link(); -} -namespace ocean_interp_wave { -extern void link(); -} -namespace ocean_generate_verts { -extern void link(); -} -namespace shadow_execute { -extern void link(); -} -namespace shadow_add_double_edges { -extern void link(); -} -namespace shadow_add_double_tris { -extern void link(); -} -namespace shadow_add_single_edges { -extern void link(); -} -namespace shadow_add_facing_single_tris { -extern void link(); -} -namespace shadow_add_verts { -extern void link(); -} -namespace shadow_find_double_edges { -extern void link(); -} -namespace shadow_find_facing_double_tris { -extern void link(); -} -namespace shadow_find_single_edges { -extern void link(); -} -namespace shadow_find_facing_single_tris { -extern void link(); -} -namespace shadow_init_vars { -extern void link(); -} -namespace shadow_scissor_top { -extern void link(); -} -namespace shadow_scissor_edges { -extern void link(); -} -namespace shadow_calc_dual_verts { -extern void link(); -} -namespace shadow_xform_verts { -extern void link(); -} -namespace draw_inline_array_instance_tie { -extern void link(); -} -namespace draw_inline_array_prototype_tie_generic_asm { -extern void link(); -} - -namespace generic_tie_dma_to_spad_sync { -extern void link(); -} -namespace generic_envmap_dproc { -extern void link(); -} -namespace generic_interp_dproc { -extern void link(); -} -namespace generic_no_light_dproc { -extern void link(); -} - -namespace generic_tie_convert { -extern void link(); -} LinkedFunctionTable gLinkedFunctionTable; Rng gRng; -std::unordered_map> gMips2CLinkCallbacks = { - {"font", {draw_string::link}}, - {"sparticle-launcher", - {sp_init_fields::link, particle_adgif::link, sp_launch_particles_var::link}}, - {"sparticle", {sp_process_block_3d::link, sp_process_block_2d::link}}, - {"texture", {adgif_shader_texture_with_update::link}}, - {"sky-tng", - {draw_large_polygon::link, init_sky_regs::link, clip_polygon_against_positive_hyperplane::link, - render_sky_quad::link, render_sky_tri::link, set_tex_offset::link, set_sky_vf27::link, - set_sky_vf23_value::link}}, - {"load-boundary", - {init_boundary_regs::link, render_boundary_quad::link, render_boundary_tri::link, - draw_boundary_polygon::link}}, - {"tfrag", {draw_inline_array_tfrag::link, stats_tfrag_asm::link}}, - {"time-of-day", {time_of_day_interp_colors_scratch::link}}, - {"collide-func", {collide_do_primitives::link, moving_sphere_triangle_intersect::link}}, - {"collide-probe", {collide_probe_node::link, collide_probe_instance_tie::link}}, - {"collide-mesh", - {method_12_collide_mesh::link, method_11_collide_mesh::link, method_15_collide_mesh::link, - method_14_collide_mesh::link}}, - {"collide-cache", - {method_26_collide_cache::link, method_32_collide_cache::link, pc_upload_collide_frag::link, - method_28_collide_cache::link, method_27_collide_cache::link, method_29_collide_cache::link, - method_12_collide_shape_prim_mesh::link, method_14_collide_shape_prim_mesh::link, - method_13_collide_shape_prim_mesh::link, method_30_collide_cache::link, - method_9_collide_cache_prim::link, method_10_collide_cache_prim::link, - method_10_collide_puss_work::link, method_9_collide_puss_work::link}}, - {"collide-edge-grab", - {method_16_collide_edge_work::link, method_15_collide_edge_work::link, - method_10_collide_edge_hold_list::link, method_18_collide_edge_work::link}}, - {"joint", {calc_animation_from_spr::link, cspace_parented_transformq_joint::link}}, - {"bones", - {bones_mtx_calc::link, draw_bones_merc::link, draw_bones_check_longest_edge_asm::link}}, - {"merc-blend-shape", {blerc_execute::link, setup_blerc_chains_for_one_fragment::link}}, - {"generic-merc", - {generic_merc_init_asm::link, generic_merc_execute_asm::link, mercneric_convert::link, - high_speed_reject::link}}, - {"generic-effect", - {generic_prepare_dma_double::link, generic_light_proc::link, generic_envmap_proc::link, - generic_prepare_dma_single::link, generic_envmap_dproc::link, generic_interp_dproc::link, - generic_no_light_dproc::link}}, - {"ripple", - {ripple_execute_init::link, ripple_create_wave_table::link, ripple_apply_wave_table::link, - ripple_matrix_scale::link}}, - {"ocean", {init_ocean_far_regs::link, render_ocean_quad::link, draw_large_polygon_ocean::link}}, - {"ocean-vu0", {ocean_interp_wave::link, ocean_generate_verts::link}}, - {"shadow-cpu", - {shadow_execute::link, shadow_add_double_edges::link, shadow_add_double_tris::link, - shadow_add_single_edges::link, shadow_add_facing_single_tris::link, shadow_add_verts::link, - shadow_find_double_edges::link, shadow_find_facing_double_tris::link, - shadow_find_single_edges::link, shadow_find_facing_single_tris::link, shadow_init_vars::link, - shadow_scissor_top::link, shadow_scissor_edges::link, shadow_calc_dual_verts::link, - shadow_xform_verts::link}}, - {"tie-methods", - {draw_inline_array_instance_tie::link, draw_inline_array_prototype_tie_generic_asm::link}}, - {"generic-tie", {generic_tie_dma_to_spad_sync::link, generic_tie_convert::link}}}; +PerGameVersion>> gMips2CLinkCallbacks = { + //////// JAK 1 + {{"font", {jak1::draw_string::link}}, + {"sparticle-launcher", + {jak1::sp_init_fields::link, jak1::particle_adgif::link, + jak1::sp_launch_particles_var::link}}, + {"sparticle", {jak1::sp_process_block_3d::link, jak1::sp_process_block_2d::link}}, + {"texture", {jak1::adgif_shader_texture_with_update::link}}, + {"sky-tng", + {jak1::draw_large_polygon::link, jak1::init_sky_regs::link, + jak1::clip_polygon_against_positive_hyperplane::link, jak1::render_sky_quad::link, + jak1::render_sky_tri::link, jak1::set_tex_offset::link, jak1::set_sky_vf27::link, + jak1::set_sky_vf23_value::link}}, + {"load-boundary", + {jak1::init_boundary_regs::link, jak1::render_boundary_quad::link, + jak1::render_boundary_tri::link, jak1::draw_boundary_polygon::link}}, + {"tfrag", {jak1::draw_inline_array_tfrag::link, jak1::stats_tfrag_asm::link}}, + {"time-of-day", {jak1::time_of_day_interp_colors_scratch::link}}, + {"collide-func", + {jak1::collide_do_primitives::link, jak1::moving_sphere_triangle_intersect::link}}, + {"collide-probe", {jak1::collide_probe_node::link, jak1::collide_probe_instance_tie::link}}, + {"collide-mesh", + {jak1::method_12_collide_mesh::link, jak1::method_11_collide_mesh::link, + jak1::method_15_collide_mesh::link, jak1::method_14_collide_mesh::link}}, + {"collide-cache", + {jak1::method_26_collide_cache::link, jak1::method_32_collide_cache::link, + jak1::pc_upload_collide_frag::link, jak1::method_28_collide_cache::link, + jak1::method_27_collide_cache::link, jak1::method_29_collide_cache::link, + jak1::method_12_collide_shape_prim_mesh::link, jak1::method_14_collide_shape_prim_mesh::link, + jak1::method_13_collide_shape_prim_mesh::link, jak1::method_30_collide_cache::link, + jak1::method_9_collide_cache_prim::link, jak1::method_10_collide_cache_prim::link, + jak1::method_10_collide_puss_work::link, jak1::method_9_collide_puss_work::link}}, + {"collide-edge-grab", + {jak1::method_16_collide_edge_work::link, jak1::method_15_collide_edge_work::link, + jak1::method_10_collide_edge_hold_list::link, jak1::method_18_collide_edge_work::link}}, + {"joint", {jak1::calc_animation_from_spr::link, jak1::cspace_parented_transformq_joint::link}}, + {"bones", + {jak1::bones_mtx_calc::link, jak1::draw_bones_merc::link, + jak1::draw_bones_check_longest_edge_asm::link}}, + {"merc-blend-shape", + {jak1::blerc_execute::link, jak1::setup_blerc_chains_for_one_fragment::link}}, + {"generic-merc", + {jak1::generic_merc_init_asm::link, jak1::generic_merc_execute_asm::link, + jak1::mercneric_convert::link, jak1::high_speed_reject::link}}, + {"generic-effect", + {jak1::generic_prepare_dma_double::link, jak1::generic_light_proc::link, + jak1::generic_envmap_proc::link, jak1::generic_prepare_dma_single::link, + jak1::generic_envmap_dproc::link, jak1::generic_interp_dproc::link, + jak1::generic_no_light_dproc::link}}, + {"ripple", + {jak1::ripple_execute_init::link, jak1::ripple_create_wave_table::link, + jak1::ripple_apply_wave_table::link, jak1::ripple_matrix_scale::link}}, + {"ocean", + {jak1::init_ocean_far_regs::link, jak1::render_ocean_quad::link, + jak1::draw_large_polygon_ocean::link}}, + {"ocean-vu0", {jak1::ocean_interp_wave::link, jak1::ocean_generate_verts::link}}, + {"shadow-cpu", + {jak1::shadow_execute::link, jak1::shadow_add_double_edges::link, + jak1::shadow_add_double_tris::link, jak1::shadow_add_single_edges::link, + jak1::shadow_add_facing_single_tris::link, jak1::shadow_add_verts::link, + jak1::shadow_find_double_edges::link, jak1::shadow_find_facing_double_tris::link, + jak1::shadow_find_single_edges::link, jak1::shadow_find_facing_single_tris::link, + jak1::shadow_init_vars::link, jak1::shadow_scissor_top::link, + jak1::shadow_scissor_edges::link, jak1::shadow_calc_dual_verts::link, + jak1::shadow_xform_verts::link}}, + {"tie-methods", + {jak1::draw_inline_array_instance_tie::link, + jak1::draw_inline_array_prototype_tie_generic_asm::link}}, + {"generic-tie", {jak1::generic_tie_dma_to_spad_sync::link, jak1::generic_tie_convert::link}}}, + /////////// JAK 2 + {{"collide-func", + {jak2::collide_do_primitives::link, jak2::moving_sphere_triangle_intersect::link}}}}; void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 stack_size) { const auto& it = m_executes.insert({name, {exec, Ptr()}}); @@ -414,9 +204,22 @@ void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 s } // this is short stub that will jump to the appropriate function. - // todo jak1 - auto jump_to_asm = Ptr(jak1::alloc_heap_object( - s7.offset + FIX_SYM_GLOBAL_HEAP, *(s7 + FIX_SYM_FUNCTION_TYPE), 0x40, UNKNOWN_PP)); + Ptr jump_to_asm; + switch (g_game_version) { + case GameVersion::Jak1: + jump_to_asm = Ptr(::jak1::alloc_heap_object(s7.offset + jak1_symbols::FIX_SYM_GLOBAL_HEAP, + *(s7 + jak1_symbols::FIX_SYM_FUNCTION_TYPE), + 0x40, UNKNOWN_PP)); + break; + case GameVersion::Jak2: + jump_to_asm = Ptr(::jak2::alloc_heap_object( + s7.offset + jak2_symbols::FIX_SYM_GLOBAL_HEAP, + ::jak2::u32_in_fixed_sym(jak2_symbols::FIX_SYM_FUNCTION_TYPE), 0x40, UNKNOWN_PP)); + break; + default: + ASSERT(false); + } + it.first->second.goal_trampoline = jump_to_asm; u8* ptr = jump_to_asm.c(); diff --git a/game/mips2c/mips2c_table.h b/game/mips2c/mips2c_table.h index a95e9fad77..04e91eb0af 100644 --- a/game/mips2c/mips2c_table.h +++ b/game/mips2c/mips2c_table.h @@ -26,7 +26,8 @@ class LinkedFunctionTable { std::unordered_map m_executes; }; -extern std::unordered_map> gMips2CLinkCallbacks; +extern PerGameVersion>> + gMips2CLinkCallbacks; extern LinkedFunctionTable gLinkedFunctionTable; struct Rng { diff --git a/goal_src/jak2/engine/collide/collide-func.gc b/goal_src/jak2/engine/collide/collide-func.gc index e4d5855012..9270199f6d 100644 --- a/goal_src/jak2/engine/collide/collide-func.gc +++ b/goal_src/jak2/engine/collide/collide-func.gc @@ -3,7 +3,399 @@ ;; name: collide-func.gc ;; name in dgo: collide-func -;; dgos: ENGINE, GAME +;; dgos: GAME, ENGINE -;; DECOMP BEGINS +;; This file contains the primitive intersection functions used for collision. +;; Most take a description of primitive and a "probe" +;; The probe has an origin and a direction. The length of the direction vector is the length +;; of the probe. +;; Generally, collision functions will return the fraction of the probe to reach the primitive. +;; For example, if the probe is 5.0 long, and hits the primitive 2.0 away from the probe origin, +;; the return value (u) would be 0.4. + +;; If (u) would be > 1.0, then it counts as "not intersecting" (object too far away) +;; If (u) would be < 0.0, then it counts as "not intersecting" (object behind probe) +;; If there's a miss, return COLLISION_MISS, a large negative number. +;; If we are inside of the primitive, return 0.0 + + +(defconstant COLLISION_MISS -100000000.0) + + +(defun raw-ray-sphere-intersect ((arg0 float)) + "DANGER: this function takes two arguments by vf registers. + As a result, it doesn't work properly in OpenGOAL. See the functions below." + (local-vars + (v1-1 float) + (v1-2 float) + (v1-4 number) + (a0-1 float) + (a0-2 float) + (a0-3 int) + (a1-0 float) + ) + (crash!) + (rlet ((Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.mov vf3 arg0) ;; vf3 = radius + ;; sphere is at the origin, vf1 is source of the ray (o) + ;; vf2 is the ray's unit vector (u) + (.mul.vf vf4 vf2 vf2) ;; vf4 = u.^2 + (.mul.vf vf3 vf3 vf3) ;; vf3 = r^2 + (.mul.vf vf6 vf1 vf1) ;; vf6 = o.^2 + (.mul.vf vf5 vf2 vf1) ;; vf5 = u . o + (.add.y.vf vf4 vf4 vf4 :mask #b1) + (let ((result (the-as float 0))) + (.add.x.vf vf6 vf6 vf6 :mask #b10) + (.sub.x.vf vf6 vf6 vf3 :mask #b100) + (.add.z.vf vf4 vf4 vf4 :mask #b1) + (.add.x.vf vf5 vf5 vf5 :mask #b10) + (let ((v1-0 (the-as float 0))) + (.add.z.vf vf6 vf6 vf6 :mask #b10) + (.div.vf Q vf0 vf4 :fsf #b11 :ftf #b0) + (.add.z.vf vf5 vf5 vf5 :mask #b10) + (.mov a0-1 vf4) + (.mul.x.vf vf7 vf6 vf4) + (.mov a1-0 vf6) + (.mul.vf vf8 vf5 vf5) + (b! (< (the-as int a1-0) 0) cfg-7 :delay (set! a0-2 a0-1)) + (.mul.vf vf4 vf0 Q :mask #b1000) + (.sub.vf vf9 vf8 vf7) + (b! (= a0-2 v1-0) cfg-6 :delay (.mov v1-1 vf5)) + ) + (.sqrt.vf Q vf9 :ftf #b1) + (b! (>= (the-as int v1-1) 0) cfg-6 :delay (.mov v1-2 vf9)) + (b! (< (the-as int v1-2) 0) cfg-6 :delay 1.0) + (.add.x.vf vf6 vf5 vf4) + (.mov v1-4 vf6) + (.mul.vf vf6 vf6 vf6) + (.mul.vf vf9 vf0 Q :mask #b1000) + (.sub.vf vf6 vf9 vf6) + (.add.w.vf vf9 vf5 vf9 :mask #b10) + (.mov a0-3 vf6) + (.mul.w.vf vf9 vf9 vf4 :mask #b10) + (b! + (< (logand (the-as uint v1-4) (the-as uint a0-3)) 0) + cfg-6 + :delay + (.sub.y.vf vf4 vf0 vf9) + ) + (b! #t cfg-7 :delay (.mov result vf4)) + (label cfg-6) + (set! result -100000000.0) + (label cfg-7) + (the-as float result) + ) + ) + ) + +(defmacro pc-port-do-raw-ray-sphere-intersect (rad vf1-val vf2-val) + "Calls to raw-ray-sphere-intersect should be replaced with this macro, + and this should be given vf1, vf2, which contain the origin and direction of the probe." + `(let ((vf1-storage (new 'stack-no-clear 'vector)) + (vf2-storage (new 'stack-no-clear 'vector)) + ) + (.svf (&-> vf1-storage quad) ,vf1-val) + (.svf (&-> vf2-storage quad) ,vf2-val) + (pc-port-raw-ray-sphere-implementation ,rad vf1-storage vf2-storage) + ) + ) + + +(defun pc-port-raw-ray-sphere-implementation ((rad float) (vf1-val vector) (vf2-val vector)) + "This is one of the main primitives for collision. + Assumes a sphere of radius rad is at the origin. + Handles: + - miss (return MISS) + - behind (return MISS) + - too far away (return MISS) + - inside (return 0) + " + (local-vars + (v1-1 int) + (v1-2 int) + (v1-4 int) + (a0-1 float) + (a0-2 float) + (a0-3 int) + (a1-0 int) + ) + (rlet ((Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> vf1-val quad)) + (.lvf vf2 (&-> vf2-val quad)) + (.mov vf3 rad) + (.mul.vf vf4 vf2 vf2) + (.mul.vf vf3 vf3 vf3) + (.mul.vf vf6 vf1 vf1) + (.mul.vf vf5 vf2 vf1) + (.add.y.vf vf4 vf4 vf4 :mask #b1) + (let ((result (the-as float 0))) + (.add.x.vf vf6 vf6 vf6 :mask #b10) + (.sub.x.vf vf6 vf6 vf3 :mask #b100) + (.add.z.vf vf4 vf4 vf4 :mask #b1) + (.add.x.vf vf5 vf5 vf5 :mask #b10) + (let ((v1-0 (the-as float 0))) + (.add.z.vf vf6 vf6 vf6 :mask #b10) + (.div.vf Q vf0 vf4 :fsf #b11 :ftf #b0) + (.add.z.vf vf5 vf5 vf5 :mask #b10) + (.mov a0-1 vf4) + (.mul.x.vf vf7 vf6 vf4) + (.mov a1-0 vf6) + (.mul.vf vf8 vf5 vf5) + (b! (< (the-as int a1-0) 0) cfg-7 :delay (set! a0-2 a0-1)) ;; in the sphere + (.mul.vf vf4 vf0 Q :mask #b1000) + (.sub.vf vf9 vf8 vf7) + (b! (= a0-2 v1-0) cfg-6 :delay (.mov v1-1 vf5)) ;; bad denominator in division + ) + (.sqrt.vf Q vf9 :ftf #b1) + (b! (>= (the-as int v1-1) 0) cfg-6 :delay (.mov v1-2 vf9)) ;; wrong dir + (b! (< (the-as int v1-2) 0) cfg-6 :delay 1.0) ;; bad sqrt + (.add.x.vf vf6 vf5 vf4) + (.mov v1-4 vf6) + (.mul.vf vf6 vf6 vf6) + (.mul.vf vf9 vf0 Q :mask #b1000) + (.sub.vf vf6 vf9 vf6) + (.add.w.vf vf9 vf5 vf9 :mask #b10) + (.mov a0-3 vf6) + (.mul.w.vf vf9 vf9 vf4 :mask #b10) + + ;; too far. + (b! (< (logand (the-as int v1-4) (the-as int a0-3)) 0) + cfg-6 + :delay (.sub.y.vf vf4 vf0 vf9) + ) + (b! #t cfg-7 :delay (.mov result vf4)) + (label cfg-6) + (set! result -100000000.0) + (label cfg-7) + (the-as float result) + ) + ) + ) + + +(defun ray-sphere-intersect ((ray-origin vector) (ray-dir vector) (sph-origin vector) (radius float)) + "Intersect a ray and sphere. Will return 0 if you are in the sphere, -huge number if you don't hit it. + Returns the length of the ray to the first intersection." + + ;; offset stuff as if the sphere is at the origin. + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> ray-origin quad)) + (.lvf vf2 (&-> sph-origin quad)) + (.sub.vf vf1 vf1 vf2) ;; the sphere is at the origin in the actual intersection. + (.lvf vf2 (&-> ray-dir quad)) + ;;(raw-ray-sphere-intersect radius) + (pc-port-do-raw-ray-sphere-intersect radius vf1 vf2) + ) + ) + +(defun ray-circle-intersect ((ray-origin vector) (ray-dir vector) (circle-origin vector) (radius float)) + "Intersect ray with circle. Circle is on the y plane and this throws out the y components + of ray-origin, circle-origin, and ray-dir" + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> ray-origin quad)) + (.mov.vf vf1 vf0 :mask #b10) + (.lvf vf2 (&-> circle-origin quad)) + (.mov.vf vf2 vf0 :mask #b10) + (.sub.vf vf1 vf1 vf2) + (.lvf vf2 (&-> ray-dir quad)) + (.mov.vf vf2 vf0 :mask #b10) + ;;(raw-ray-sphere-intersect radius) + (pc-port-do-raw-ray-sphere-intersect radius vf1 vf2) + ) + ) + +(defun ray-cylinder-intersect ((ray-origin vector) (ray-dir vector) (cyl-origin vector) (cyl-axis vector) (cyl-rad float) (cyl-len float) (pt-out vector)) + "Intersect with a cylinder. + Currently this is untested." + (local-vars + (v0-1 float) + (v1-0 int) + (v1-2 int) + (a0-1 int) + (a0-2 int) + (a0-4 int) + (a0-5 int) + ) + (rlet ((vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf2 :class vf) + (vf20 :class vf) + (vf21 :class vf) + ) + (.lvf vf10 (&-> ray-origin quad)) + (.lvf vf12 (&-> cyl-origin quad)) + (.sub.vf vf15 vf10 vf12) + (.lvf vf11 (&-> ray-dir quad)) + (.lvf vf13 (&-> cyl-axis quad)) + (.mov vf14 cyl-len) + (.mul.vf vf16 vf15 vf13) + (.mul.vf vf17 vf11 vf13) + (.add.x.vf vf16 vf16 vf16 :mask #b10) + (.add.x.vf vf17 vf17 vf17 :mask #b10) + (.add.z.vf vf16 vf16 vf16 :mask #b10) + (.add.z.vf vf17 vf17 vf17 :mask #b10) + (.mul.y.vf vf1 vf13 vf16) + (.add.vf vf18 vf17 vf16) + (.sub.x.vf vf19 vf16 vf14) + (.mul.y.vf vf2 vf13 vf17) + (.mov v1-0 vf16) + (.sub.x.vf vf20 vf18 vf14) + (.mov a0-1 vf18) + (let ((v1-1 (logand v1-0 (the-as uint a0-1)))) + (.sub.vf vf1 vf15 vf1) + (b! (< v1-1 0) cfg-6 :delay (.sub.vf vf2 vf11 vf2)) + ) + (.mov v1-2 vf19) + (.mov a0-2 vf20) + (b! (>= (the-as int (logior v1-2 (the-as uint a0-2))) 0) cfg-6 :delay (nop!)) + ;;(let ((v1-4 (raw-ray-sphere-intersect cyl-rad))) + (let ((v1-4 (pc-port-do-raw-ray-sphere-intersect cyl-rad vf1 vf2))) + (b! (< (the-as int v1-4) 0) cfg-6 :delay (.mov vf21 v1-4)) + (.mul.x.vf vf17 vf17 vf21) + (.add.vf vf16 vf16 vf17) + (.mul.y.vf vf13 vf13 vf16) + (.sub.x.vf vf19 vf16 vf14) + (.mov a0-4 vf16) + (b! + (< (the-as int a0-4) 0) + cfg-6 + :delay + (.add.vf vf12 vf12 vf13 :mask #b111) + ) + (.mov a0-5 vf19) + (b! (>= (the-as int a0-5) 0) cfg-6 :delay (.svf (&-> pt-out quad) vf12)) + (b! #t cfg-7 :delay (set! v0-1 v1-4)) + ) + (label cfg-6) + (set! v0-1 -100000000.0) + (label cfg-7) + v0-1 + ) + ) + +(defun ray-plane-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector) (arg4 vector) (arg5 vector) (arg6 vector)) + "Unused." + (local-vars (v1-0 float) (v1-1 float) (a2-1 float)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf3 (&-> arg5 quad)) + (.lvf vf1 (&-> arg4 quad)) + (.lvf vf2 (&-> arg6 quad)) + (.sub.vf vf1 vf3 vf1) + (.sub.vf vf2 vf3 vf2) + (.lvf vf6 (&-> arg2 quad)) + (.lvf vf7 (&-> arg3 quad)) + (.sub.vf vf8 vf3 vf6) + (.outer.product.a.vf acc vf2 vf1) + (.outer.product.b.vf vf4 vf1 vf2 acc) + (.mul.vf vf8 vf8 vf4) + (.mul.vf vf9 vf7 vf4) + (.mul.vf vf5 vf4 vf4) + (.add.y.vf vf8 vf8 vf8 :mask #b1) + (.add.y.vf vf9 vf9 vf9 :mask #b1) + (.add.y.vf vf5 vf5 vf5 :mask #b1) + (.add.z.vf vf8 vf8 vf8 :mask #b1) + (.add.z.vf vf9 vf9 vf9 :mask #b1) + (.add.z.vf vf5 vf5 vf5 :mask #b1) + (.mov v1-0 vf9) + (.mov a2-1 vf8) + (.isqrt.vf Q vf0 vf5 :fsf #b11 :ftf #b0) + (let ((f1-0 a2-1) + (f2-0 v1-0) + ) + (cond + ((!= f2-0 0.0) + (let ((f1-1 (/ f1-0 f2-0))) + (.mov.vf vf4 vf0 :mask #b1000) + (.wait.vf) + (.mul.vf vf4 vf4 Q :mask #b111) + (let ((v0-0 f1-1)) + (.mov vf8 v0-0) + (.svf (&-> arg1 quad) vf4) + (.mul.x.vf acc vf7 vf8) + (.add.mul.w.vf vf7 vf6 vf0 acc :mask #b111) + (.svf (&-> arg0 quad) vf7) + (.mov v1-1 vf7) + v0-0 + ) + ) + ) + (else + -100000000.0 + ) + ) + ) + ) + ) + +;; ray-triangle-intersect (unused) +;; collide-do-primitives (used in moving-sphere-triangle-intersect) +(def-mips2c collide-do-primitives (function float)) +;; moving-sphere-triangle-intersect (used in cam) +(def-mips2c moving-sphere-triangle-intersect (function vector vector float collide-cache-tri vector vector float)) +;; moving-sphere-sphere-intersect (used in collide) +(defun moving-sphere-sphere-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector)) + (let ((f30-0 (ray-sphere-intersect arg0 arg1 arg2 (+ (-> arg0 w) (-> arg2 w))))) + (when (>= f30-0 0.0) + (let ((s3-1 (vector-normalize! (vector-! (new-stack-vector0) arg2 arg0) (-> arg0 w)))) + (vector+*! arg3 arg0 arg1 f30-0) + (vector+! arg3 arg3 s3-1) + ) + ) + f30-0 + ) + ) + +;; moving-sphere-moving-sphere-intersect (unused) diff --git a/goal_src/jak2/engine/data/art-h.gc b/goal_src/jak2/engine/data/art-h.gc index 82f9a29229..b099b3416a 100644 --- a/goal_src/jak2/engine/data/art-h.gc +++ b/goal_src/jak2/engine/data/art-h.gc @@ -309,7 +309,7 @@ :size-assert #x74 :flag-assert #x1000000074 (:methods - (add-to-loading-level (_type_) none 15) + (add-to-loading-level (_type_) skeleton-group 15) ) ) diff --git a/goal_src/jak2/engine/load/loader-h.gc b/goal_src/jak2/engine/load/loader-h.gc index e89dff591b..81a1992619 100644 --- a/goal_src/jak2/engine/load/loader-h.gc +++ b/goal_src/jak2/engine/load/loader-h.gc @@ -9,6 +9,8 @@ ;; todo: more specific (define-extern external-art-buffer-init function) +(declare-type art basic) +(declare-type art-group art) ;; DECOMP BEGINS @@ -23,12 +25,10 @@ (:methods (new (symbol type int level) _type_ 0) (load-dir-method-9 () none 9) - (load-dir-method-10 () none 10) + (set-loaded-art (_type_ art-group) art-group 10) ) ) -(declare-type art-group basic) - (deftype load-dir-art-group (load-dir) ((art-group-array (array art-group) :offset 12) ) diff --git a/goal_src/jak2/engine/load/loader.gc b/goal_src/jak2/engine/load/loader.gc index b6fe42b655..f204d56d46 100644 --- a/goal_src/jak2/engine/load/loader.gc +++ b/goal_src/jak2/engine/load/loader.gc @@ -5,5 +5,25 @@ ;; name in dgo: loader ;; dgos: ENGINE, GAME +;; temporary hack to avoid crash at startup + +(defmethod set-loaded-art load-dir-art-group ((obj load-dir-art-group) (arg0 art-group)) + (let ((s4-0 (-> obj string-array))) + (dotimes (s3-0 (-> s4-0 length)) + (when (string= (-> arg0 name) (-> s4-0 s3-0)) + (set! (-> obj art-group-array s3-0) arg0) + (set! arg0 (-> obj art-group-array s3-0)) + (goto cfg-7) + ) + ) + (set! (-> s4-0 (-> s4-0 length)) (-> arg0 name)) + (set! (-> obj art-group-array (-> s4-0 length)) arg0) + (+! (-> s4-0 length) 1) + ) + (+! (-> obj art-group-array length) 1) + (label cfg-7) + arg0 + ) + ;; DECOMP BEGINS diff --git a/goal_src/jak2/engine/process-drawable/process-drawable.gc b/goal_src/jak2/engine/process-drawable/process-drawable.gc index 563ef7797d..cb00e4c93b 100644 --- a/goal_src/jak2/engine/process-drawable/process-drawable.gc +++ b/goal_src/jak2/engine/process-drawable/process-drawable.gc @@ -5,5 +5,15 @@ ;; name in dgo: process-drawable ;; dgos: ENGINE, GAME +;; temp hacks to avoid crash at startup +(defmethod add-to-loading-level skeleton-group ((obj skeleton-group)) + (let ((v1-1 (-> *level* loading-level))) + (if v1-1 + (set-loaded-art (-> v1-1 art-group) obj) + ) + ) + obj + ) + ;; DECOMP BEGINS diff --git a/goal_src/jak2/kernel-defs.gc b/goal_src/jak2/kernel-defs.gc index 7da91bafd0..0ef464cda0 100644 --- a/goal_src/jak2/kernel-defs.gc +++ b/goal_src/jak2/kernel-defs.gc @@ -143,6 +143,7 @@ (define-extern link-begin (function pointer (pointer uint8) int kheap link-flag int)) (define-extern kset-language (function language-enum int)) (define-extern syncv (function int int)) +(define-extern __pc-get-mips2c (function string function)) ;; PC stuff diff --git a/goal_src/jak2/kernel/gkernel-h.gc b/goal_src/jak2/kernel/gkernel-h.gc index 3b136dc48e..d6df11c754 100644 --- a/goal_src/jak2/kernel/gkernel-h.gc +++ b/goal_src/jak2/kernel/gkernel-h.gc @@ -701,3 +701,17 @@ (deactivate pp) ) ) + +;; Some assembly functions in GOAL are ported to C++, then accessed from GOAL using these mips2c macros. +(defmacro def-mips2c (name type) + "Define a mips2c object (typically a function)." + `(begin + (define-extern ,name ,type) + (set! ,name (the-as ,type (__pc-get-mips2c ,(symbol->string name)))) + ) + ) + +(defmacro defmethod-mips2c (name method-id method-type) + "Define a mips2c method." + `(method-set! ,method-type ,method-id (__pc-get-mips2c ,name)) + ) \ No newline at end of file diff --git a/test/decompiler/reference/jak2/engine/data/art-h_REF.gc b/test/decompiler/reference/jak2/engine/data/art-h_REF.gc index c170420ffe..d5b6bb6b00 100644 --- a/test/decompiler/reference/jak2/engine/data/art-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/data/art-h_REF.gc @@ -471,7 +471,7 @@ :size-assert #x74 :flag-assert #x1000000074 (:methods - (add-to-loading-level (_type_) none 15) + (add-to-loading-level (_type_) skeleton-group 15) ) ) diff --git a/test/decompiler/reference/jak2/engine/load/loader-h_REF.gc b/test/decompiler/reference/jak2/engine/load/loader-h_REF.gc index 6af026470b..14d58b1ebf 100644 --- a/test/decompiler/reference/jak2/engine/load/loader-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/load/loader-h_REF.gc @@ -13,7 +13,7 @@ (:methods (new (symbol type int level) _type_ 0) (load-dir-method-9 () none 9) - (load-dir-method-10 () none 10) + (set-loaded-art (_type_ art-group) art-group 10) ) ) diff --git a/test/goalc/test_with_game.cpp b/test/goalc/test_with_game.cpp index 18b1218355..a657968255 100644 --- a/test/goalc/test_with_game.cpp +++ b/test/goalc/test_with_game.cpp @@ -844,7 +844,7 @@ TEST_F(WithGameTests, StackSingletonType) { {"#t\n0\n"}); } -namespace Mips2C { +namespace Mips2C::jak1 { namespace test_func { extern u64 execute(void*); } @@ -852,16 +852,16 @@ namespace goal_call_test { extern u64 execute(void*); extern void link(); } // namespace goal_call_test -} // namespace Mips2C +} // namespace Mips2C::jak1 TEST_F(WithGameTests, Mips2CBasic) { - Mips2C::gLinkedFunctionTable.reg("test-func", Mips2C::test_func::execute, 0); + Mips2C::gLinkedFunctionTable.reg("test-func", Mips2C::jak1::test_func::execute, 0); shared_compiler->runner.run_static_test(testCategory, "test-mips2c-call.gc", {"36\n0\n"}); } TEST_F(WithGameTests, Mips2C_CallGoal) { - Mips2C::gLinkedFunctionTable.reg("test-func2", Mips2C::goal_call_test::execute, 128); - Mips2C::goal_call_test::link(); + Mips2C::gLinkedFunctionTable.reg("test-func2", Mips2C::jak1::goal_call_test::execute, 128); + Mips2C::jak1::goal_call_test::link(); shared_compiler->runner.run_static_test(testCategory, "test-mips2c-goal.gc", {"1 2 3 4 5 6 7 8\n12\n"}); }