diff --git a/CMakeLists.txt b/CMakeLists.txt index 34c3f8e13..ed3840d4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ endif() set(VERSION us) set(USE_NETWORKING OFF) set(SKIP_XCODE_VERSION_CHECK ON) +set(GFX_DEBUG_DISASSEMBLER ON) # Add compile definitions for the target add_compile_definitions( @@ -540,19 +541,23 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") endif() include(ExternalProject) -ExternalProject_Add(Torch +ExternalProject_Add(torch + PREFIX torch SOURCE_DIR ${CMAKE_SOURCE_DIR}/torch CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/torch ) -ExternalProject_Get_Property(Torch install_dir) -set(TORCH_EXECUTABLE ${install_dir}/torch/build/x64/Debug/torch) +ExternalProject_Get_Property(torch install_dir) +set(TORCH_EXECUTABLE ${install_dir}/src/Torch-build/$/torch) +message(STATUS "Torch executable path: ${TORCH_EXECUTABLE}") add_custom_target( ExtractAssets - DEPENDS Torch + DEPENDS torch WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND ${TORCH_EXECUTABLE} header -o baserom.us.z64 + COMMAND ${TORCH_EXECUTABLE} otr baserom.us.z64 COMMAND ${TORCH_EXECUTABLE} pack assets ship.otr COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/spaghetti.otr" "${CMAKE_BINARY_DIR}/spaghetti.otr" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/ship.otr" "${CMAKE_BINARY_DIR}/ship.otr" -) + ) diff --git a/libultraship b/libultraship index c7974d6a2..fccf181b4 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit c7974d6a25853d65b44905df728a0e0249636947 +Subproject commit fccf181b449f82f3e6ae5cdc666319847f78e0a1 diff --git a/src/main.c b/src/main.c index 711d045ad..491034fe4 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ #include #include "crash_screen.h" #include "buffers/gfx_output_buffer.h" +#include // Declarations (not in this file) void func_80091B78(void); @@ -301,7 +302,9 @@ void create_gfx_task_structure(void) { func_8008C214(); // gGfxSPTask->task.t.yield_data_ptr = (u64 *) &gGfxSPTaskYieldBuffer; // gGfxSPTask->task.t.yield_data_size = OS_YIELD_DATA_SIZE; - + if (GfxDebuggerIsDebuggingRequested()) { + GfxDebuggerDebugDisplayList(gGfxPool->gfxPool); + } Graphics_PushFrame(gGfxPool->gfxPool); } @@ -1174,11 +1177,6 @@ void update_gamestate(void) { } void thread5_game_loop(void) { - - // if (GfxDebuggerIsDebugging()) { - // Graphics_PushFrame(gGfxPool->gfxPool); - // return; - // } setup_game_memory(); osCreateMesgQueue(&gGfxVblankQueue, gGfxMesgBuf, 1); osCreateMesgQueue(&gGameVblankQueue, &gGameMesgBuf, 1); @@ -1204,6 +1202,10 @@ void thread5_game_loop(void) { void thread5_iteration(void){ // func_800CB2C4(); + if (GfxDebuggerIsDebugging()) { + Graphics_PushFrame(gGfxPool->gfxPool); + return; + } // Update the gamestate if it has changed (racing, menus, credits, etc.). if (gGamestateNext != gGamestate) { gGamestate = gGamestateNext; diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index c09846732..df9855686 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -12,6 +12,7 @@ #include "resource/importers/TrackSectionsFactory.h" #include "resource/importers/TrackWaypointFactory.h" #include "resource/importers/ActorSpawnDataFactory.h" +#include "resource/importers/ArrayFactory.h" #include #include @@ -66,6 +67,7 @@ GameEngine::GameEngine() { loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "DisplayList", static_cast(LUS::ResourceType::DisplayList), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Matrix", static_cast(LUS::ResourceType::Matrix), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Blob", static_cast(LUS::ResourceType::Blob), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Array", static_cast(MK64::ResourceType::MK_Array), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "KartAI", static_cast(MK64::ResourceType::KartAI), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "CourseVtx", static_cast(MK64::ResourceType::CourseVertex), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "TrackSections", static_cast(MK64::ResourceType::TrackSection), 0); diff --git a/src/port/GBIMiddleware.cpp b/src/port/GBIMiddleware.cpp index b1a03edee..2b1f353fc 100644 --- a/src/port/GBIMiddleware.cpp +++ b/src/port/GBIMiddleware.cpp @@ -2,6 +2,8 @@ #include "Engine.h" #include "DisplayList.h" +#include "resource/type/ResourceType.h" +#include "resource/type/Array.h" extern "C" int GameEngine_OTRSigCheck(const char* data); @@ -33,13 +35,12 @@ extern "C" void gSPInvalidateTexCache(Gfx* pkt, uintptr_t texAddr) { const auto res = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(data); const auto type = static_cast(res->GetInitData()->Type); - switch(type) { - case LUS::ResourceType::DisplayList: + if (res->GetInitData()->Type == static_cast(LUS::ResourceType::DisplayList)) { texAddr = reinterpret_cast(&std::static_pointer_cast(res)->Instructions[0]); - break; - default: + } else if (res->GetInitData()->Type == static_cast(MK64::ResourceType::MK_Array)) { + texAddr = reinterpret_cast(std::static_pointer_cast(res)->Vertices.data()); + } else { texAddr = reinterpret_cast(res->GetRawPointer()); - break; } } diff --git a/src/port/resource/importers/ActorSpawnDataFactory.cpp b/src/port/resource/importers/ActorSpawnDataFactory.cpp index e5a2ea485..93f56111e 100644 --- a/src/port/resource/importers/ActorSpawnDataFactory.cpp +++ b/src/port/resource/importers/ActorSpawnDataFactory.cpp @@ -21,7 +21,7 @@ namespace MK64 { data.pos[0] = reader->ReadInt16(); data.pos[1] = reader->ReadInt16(); data.pos[2] = reader->ReadInt16(); - data.signedSomeId = reader->ReadUByte(); + data.signedSomeId = reader->ReadInt16(); section->ActorSpawnDataList.push_back(data); } diff --git a/src/port/resource/importers/ArrayFactory.cpp b/src/port/resource/importers/ArrayFactory.cpp new file mode 100644 index 000000000..331a3b306 --- /dev/null +++ b/src/port/resource/importers/ArrayFactory.cpp @@ -0,0 +1,64 @@ +#include "ArrayFactory.h" +#include "../type/Array.h" +#include "spdlog/spdlog.h" +#include "graphic/Fast3D/lus_gbi.h" + +namespace MK64 { +std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto array = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + array->ArrayType = (ArrayResourceType)reader->ReadUInt32(); + array->ArrayCount = reader->ReadUInt32(); + + for (uint32_t i = 0; i < array->ArrayCount; i++) { + if (array->ArrayType == ArrayResourceType::Vertex) { + // OTRTODO: Implement Vertex arrays as just a vertex resource. + F3DVtx data; + data.v.ob[0] = reader->ReadInt16(); + data.v.ob[1] = reader->ReadInt16(); + data.v.ob[2] = reader->ReadInt16(); + data.v.flag = reader->ReadUInt16(); + data.v.tc[0] = reader->ReadInt16(); + data.v.tc[1] = reader->ReadInt16(); + data.v.cn[0] = reader->ReadUByte(); + data.v.cn[1] = reader->ReadUByte(); + data.v.cn[2] = reader->ReadUByte(); + data.v.cn[3] = reader->ReadUByte(); + array->Vertices.push_back(data); + } else { + array->ArrayScalarType = (ScalarType)reader->ReadUInt32(); + + int iter = 1; + + if (array->ArrayType == ArrayResourceType::Vector) { + iter = reader->ReadUInt32(); + } + + for (int k = 0; k < iter; k++) { + ScalarData data; + + switch (array->ArrayScalarType) { + case ScalarType::ZSCALAR_S16: + data.s16 = reader->ReadInt16(); + break; + case ScalarType::ZSCALAR_U16: + data.u16 = reader->ReadUInt16(); + break; + default: + throw std::runtime_error("ARRAY FACTORY TYPE NOT IMPLEMENTED"); + break; + } + + array->Scalars.push_back(data); + } + } + } + + return array; +} +} // namespace LUS diff --git a/src/port/resource/importers/ArrayFactory.h b/src/port/resource/importers/ArrayFactory.h new file mode 100644 index 000000000..b170d8c08 --- /dev/null +++ b/src/port/resource/importers/ArrayFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "resource/Resource.h" +#include "resource/ResourceFactoryBinary.h" + +namespace MK64 { +class ResourceFactoryBinaryArrayV0 : public Ship::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +} // namespace LUS \ No newline at end of file diff --git a/src/port/resource/importers/GenericArrayFactory.cpp b/src/port/resource/importers/GenericArrayFactory.cpp index 27abc55f8..5e4c13de1 100644 --- a/src/port/resource/importers/GenericArrayFactory.cpp +++ b/src/port/resource/importers/GenericArrayFactory.cpp @@ -86,6 +86,11 @@ std::shared_ptr ResourceFactoryBinaryGenericArrayV0::ReadResour std::copy_n(reinterpret_cast(&vec), sizeof(Vec3i), std::back_inserter(arr->mData)); break; } + case ArrayType::Vec3iu: { + Vec3i vec(reader->ReadUInt32(), reader->ReadUInt32(), reader->ReadUInt32()); + std::copy_n(reinterpret_cast(&vec), sizeof(Vec3iu), std::back_inserter(arr->mData)); + break; + } case ArrayType::Vec4f: { Vec4f vec(reader->ReadFloat(), reader->ReadFloat(), reader->ReadFloat(), reader->ReadFloat()); std::copy_n(reinterpret_cast(&vec), sizeof(Vec4f), std::back_inserter(arr->mData)); @@ -96,6 +101,9 @@ std::shared_ptr ResourceFactoryBinaryGenericArrayV0::ReadResour std::copy_n(reinterpret_cast(&vec), sizeof(Vec4s), std::back_inserter(arr->mData)); break; } + default: { + throw std::runtime_error("UNIMPLEMENTED GENERICARRAY TYPE"); + } } } diff --git a/src/port/resource/type/Array.cpp b/src/port/resource/type/Array.cpp new file mode 100644 index 000000000..ecaef32c4 --- /dev/null +++ b/src/port/resource/type/Array.cpp @@ -0,0 +1,45 @@ +#include "Array.h" +#include "graphic/Fast3D/lus_gbi.h" +namespace MK64 { +Array::Array() : Resource(std::shared_ptr()) { +} + +void* Array::GetPointer() { + void* dataPointer = nullptr; + switch (ArrayType) { + case ArrayResourceType::Vertex: + dataPointer = Vertices.data(); + break; + case ArrayResourceType::Scalar: + default: + dataPointer = Scalars.data(); + break; + } + + return dataPointer; +} + +size_t Array::GetPointerSize() { + size_t typeSize = 0; + switch (ArrayType) { + case ArrayResourceType::Vertex: + typeSize = sizeof(F3DVtx); + break; + case ArrayResourceType::Scalar: + default: + switch (ArrayScalarType) { + case ScalarType::ZSCALAR_S16: + typeSize = sizeof(int16_t); + break; + case ScalarType::ZSCALAR_U16: + typeSize = sizeof(uint16_t); + break; + default: + // OTRTODO: IMPLEMENT OTHER TYPES! + break; + } + break; + } + return ArrayCount * typeSize; +} +} // namespace LUS \ No newline at end of file diff --git a/src/port/resource/type/Array.h b/src/port/resource/type/Array.h new file mode 100644 index 000000000..0772d25e7 --- /dev/null +++ b/src/port/resource/type/Array.h @@ -0,0 +1,85 @@ +#pragma once + +#include "resource/Resource.h" + +union F3DVtx; +namespace MK64 { +typedef union ScalarData { + uint8_t u8; + int8_t s8; + uint16_t u16; + int16_t s16; + uint32_t u32; + int32_t s32; + uint64_t u64; + int64_t s64; + float f32; + double f64; +} ScalarData; + +enum class ScalarType { + ZSCALAR_NONE, + ZSCALAR_S8, + ZSCALAR_U8, + ZSCALAR_X8, + ZSCALAR_S16, + ZSCALAR_U16, + ZSCALAR_X16, + ZSCALAR_S32, + ZSCALAR_U32, + ZSCALAR_X32, + ZSCALAR_S64, + ZSCALAR_U64, + ZSCALAR_X64, + ZSCALAR_F32, + ZSCALAR_F64 +}; + +// OTRTODO: Replace this with something that can be shared between the exporter and importer... +enum class ArrayResourceType { + Error, + Animation, + Array, + AltHeader, + Background, + Blob, + CollisionHeader, + Cutscene, + DisplayList, + Limb, + LimbTable, + Mtx, + Path, + PlayerAnimationData, + Room, + RoomCommand, + Scalar, + Scene, + Skeleton, + String, + Symbol, + Texture, + TextureAnimation, + TextureAnimationParams, + Vector, + Vertex, + Audio +}; + +class Array : public Ship::Resource { + public: + using Resource::Resource; + + Array(); + + void* GetPointer() override; + size_t GetPointerSize() override; + + ArrayResourceType ArrayType; + ScalarType ArrayScalarType; + size_t ArrayCount; + // OTRTODO: Should be a vector of resource pointers... + std::vector Scalars; + std::vector Vertices; +}; +} // namespace LUS \ No newline at end of file diff --git a/src/port/resource/type/GenericArray.h b/src/port/resource/type/GenericArray.h index 7043faf54..3916f9fb2 100644 --- a/src/port/resource/type/GenericArray.h +++ b/src/port/resource/type/GenericArray.h @@ -26,6 +26,11 @@ struct Vec3i { Vec3i(int32_t x, int32_t y, int32_t z) : x(x), y(y), z(z) {} }; +struct Vec3iu { + uint32_t x, y, z; + Vec3iu(uint32_t x, uint32_t y, uint32_t z) : x(x), y(y), z(z) {} +}; + struct Vec4f { float x, y, z, w; Vec4f(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {} @@ -37,7 +42,7 @@ struct Vec4s { }; enum class ArrayType { - u8, s8, u16, s16, u32, s32, u64, f32, f64, Vec2f, Vec3f, Vec3s, Vec3i, Vec4f, Vec4s, + u8, s8, u16, s16, u32, s32, u64, f32, f64, Vec2f, Vec3f, Vec3s, Vec3i, Vec3iu, Vec4f, Vec4s, }; class GenericArray : public Ship::Resource { diff --git a/src/port/resource/type/ResourceType.h b/src/port/resource/type/ResourceType.h index e8d7d91aa..ab094a261 100644 --- a/src/port/resource/type/ResourceType.h +++ b/src/port/resource/type/ResourceType.h @@ -22,6 +22,7 @@ namespace SF64 { namespace MK64 { enum class ResourceType { + MK_Array = 0x4F415252, // OARR CourseVertex = 0x43565458, // CVTX TrackSection = 0x5343544E, // SCTN Waypoints = 0x57505453, // WPTS diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp index 060185d3b..34ccdaca2 100644 --- a/src/port/ui/ImguiUI.cpp +++ b/src/port/ui/ImguiUI.cpp @@ -314,8 +314,7 @@ void DrawSettingsMenu(){ Ship::WindowBackend runningWindowBackend = Ship::Context::GetInstance()->GetWindow()->GetWindowBackend(); Ship::WindowBackend configWindowBackend; int configWindowBackendId = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1); - if (configWindowBackendId != -1 - && configWindowBackendId < static_cast(Ship::WindowBackend::WINDOW_BACKEND_COUNT)) { + if (Ship::Context::GetInstance()->GetWindow()->IsAvailableWindowBackend(configWindowBackendId)) { configWindowBackend = static_cast(configWindowBackendId); } else { configWindowBackend = runningWindowBackend; diff --git a/src/racing/actors.c b/src/racing/actors.c index c20309e53..aa8051e4e 100644 --- a/src/racing/actors.c +++ b/src/racing/actors.c @@ -1028,16 +1028,16 @@ void spawn_course_actors(void) { struct ActorSpawnData *a_d_course_mario_raceway_piranha_plant_spawns = (struct ActorSpawnData *) LOAD_ASSET(d_course_mario_raceway_piranha_plant_spawns); struct ActorSpawnData *a_d_course_mario_raceway_item_box_spawns = (struct ActorSpawnData *) LOAD_ASSET(d_course_mario_raceway_item_box_spawns); - //spawn_foliage(a_d_course_mario_raceway_tree_spawns); - //spawn_piranha_plants(a_d_course_mario_raceway_piranha_plant_spawns); - //spawn_all_item_boxes(a_d_course_mario_raceway_item_box_spawns); - // vec3f_set(position, 150.0f, 40.0f, -1300.0f); - // position[0] *= gCourseDirection; - // add_actor_to_empty_slot(position, rotation, velocity, ACTOR_MARIO_SIGN); - // vec3f_set(position, 2520.0f, 0.0f, 1240.0f); - // position[0] *= gCourseDirection; - // actor = &gActorList[add_actor_to_empty_slot(position, rotation, velocity, ACTOR_MARIO_SIGN)]; - // actor->flags |= 0x4000; + spawn_foliage(a_d_course_mario_raceway_tree_spawns); + spawn_piranha_plants(a_d_course_mario_raceway_piranha_plant_spawns); + spawn_all_item_boxes(a_d_course_mario_raceway_item_box_spawns); + vec3f_set(position, 150.0f, 40.0f, -1300.0f); + position[0] *= gCourseDirection; + add_actor_to_empty_slot(position, rotation, velocity, ACTOR_MARIO_SIGN); + vec3f_set(position, 2520.0f, 0.0f, 1240.0f); + position[0] *= gCourseDirection; + actor = &gActorList[add_actor_to_empty_slot(position, rotation, velocity, ACTOR_MARIO_SIGN)]; + actor->flags |= 0x4000; break; case COURSE_CHOCO_MOUNTAIN: spawn_all_item_boxes(d_course_choco_mountain_item_box_spawns); diff --git a/src/render_objects.c b/src/render_objects.c index 935a583c3..fd2ef83cc 100644 --- a/src/render_objects.c +++ b/src/render_objects.c @@ -227,7 +227,7 @@ void load_texture_block_i8_nomirror(u8 *texture, s32 width, s32 height) { void func_80044924(u8 *texture, s32 width, s32 height) { // This macro ought to be equivalent to the block of macros below but it doesn't match // See comment above the `gDPLoadBlock` macro - gDPLoadTextureBlock_4b(gDisplayListHead++, texture, G_IM_FMT_I, width, height, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + //gDPLoadTextureBlock_4b(gDisplayListHead++, texture, G_IM_FMT_I, width, height, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); // gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, texture); // gDPSetTile(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 0, G_TX_RENDERTILE, G_TX_LOADTILE, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOLOD); diff --git a/tools/torch b/tools/torch deleted file mode 160000 index 76e90b4dd..000000000 --- a/tools/torch +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 76e90b4ddc9c215132c39ebf8433d5f88813b368 diff --git a/torch b/torch index 6b1f46c81..aa95f29be 160000 --- a/torch +++ b/torch @@ -1 +1 @@ -Subproject commit 6b1f46c81d0cff15f141820fa351d1874cca9f05 +Subproject commit aa95f29be7b9c7b3190c738e17126ba360b3798c diff --git a/yamls/us/mario_raceway_data.yml b/yamls/us/mario_raceway_data.yml index c536ad684..deb2ce173 100644 --- a/yamls/us/mario_raceway_data.yml +++ b/yamls/us/mario_raceway_data.yml @@ -453,7 +453,6 @@ d_course_mario_raceway_dl_90B0: symbol: d_course_mario_raceway_dl_90B0 type: gfx offset: 0x90B0 - otr_mode: index d_course_mario_raceway_dl_90C0: symbol: d_course_mario_raceway_dl_90C0 type: gfx @@ -473,12 +472,10 @@ d_course_mario_raceway_dl_9310: symbol: d_course_mario_raceway_dl_9310 type: gfx offset: 0x9310 - otr_mode: index d_course_mario_raceway_dl_sign: symbol: d_course_mario_raceway_dl_sign type: gfx offset: 0x9330 - otr_mode: index d_course_mario_raceway_dl_9348: symbol: d_course_mario_raceway_dl_9348 type: gfx