summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2024-06-13 13:35:29 -0600
committerGitHub <noreply@github.com>2024-06-13 13:35:29 -0600
commit0d629e466a75a3e7c8ab9ee8ea88bd4c52023a29 (patch)
tree1f832aad7b4f32558b19545f53092bb45b11fb93 /src
parentb594f112e05c46fa4f8da2e4be74ba1a28ee50b4 (diff)
Take7 (#17)
Diffstat (limited to 'src')
-rw-r--r--src/main.c14
-rw-r--r--src/port/Engine.cpp2
-rw-r--r--src/port/GBIMiddleware.cpp11
-rw-r--r--src/port/resource/importers/ActorSpawnDataFactory.cpp2
-rw-r--r--src/port/resource/importers/ArrayFactory.cpp64
-rw-r--r--src/port/resource/importers/ArrayFactory.h11
-rw-r--r--src/port/resource/importers/GenericArrayFactory.cpp8
-rw-r--r--src/port/resource/type/Array.cpp45
-rw-r--r--src/port/resource/type/Array.h85
-rw-r--r--src/port/resource/type/GenericArray.h7
-rw-r--r--src/port/resource/type/ResourceType.h1
-rw-r--r--src/port/ui/ImguiUI.cpp3
-rw-r--r--src/racing/actors.c20
-rw-r--r--src/render_objects.c2
14 files changed, 249 insertions, 26 deletions
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 <debug.h>
#include "crash_screen.h"
#include "buffers/gfx_output_buffer.h"
+#include <bridge/gfxdebuggerbridge.h>
// 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 <Fast3D/Fast3dWindow.h>
#include <Fast3D/gfx_pc.h>
@@ -66,6 +67,7 @@ GameEngine::GameEngine() {
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryDisplayListV0>(), RESOURCE_FORMAT_BINARY, "DisplayList", static_cast<uint32_t>(LUS::ResourceType::DisplayList), 0);
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryMatrixV0>(), RESOURCE_FORMAT_BINARY, "Matrix", static_cast<uint32_t>(LUS::ResourceType::Matrix), 0);
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryBlobV0>(), RESOURCE_FORMAT_BINARY, "Blob", static_cast<uint32_t>(LUS::ResourceType::Blob), 0);
+ loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryArrayV0>(), RESOURCE_FORMAT_BINARY, "Array", static_cast<uint32_t>(MK64::ResourceType::MK_Array), 0);
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryKartAIV0>(), RESOURCE_FORMAT_BINARY, "KartAI", static_cast<uint32_t>(MK64::ResourceType::KartAI), 0);
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryCourseVtxV0>(), RESOURCE_FORMAT_BINARY, "CourseVtx", static_cast<uint32_t>(MK64::ResourceType::CourseVertex), 0);
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryTrackSectionsV0>(), RESOURCE_FORMAT_BINARY, "TrackSections", static_cast<uint32_t>(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<LUS::ResourceType>(res->GetInitData()->Type);
- switch(type) {
- case LUS::ResourceType::DisplayList:
+ if (res->GetInitData()->Type == static_cast<uint32_t>(LUS::ResourceType::DisplayList)) {
texAddr = reinterpret_cast<uintptr_t>(&std::static_pointer_cast<LUS::DisplayList>(res)->Instructions[0]);
- break;
- default:
+ } else if (res->GetInitData()->Type == static_cast<uint32_t>(MK64::ResourceType::MK_Array)) {
+ texAddr = reinterpret_cast<uintptr_t>(std::static_pointer_cast<MK64::Array>(res)->Vertices.data());
+ } else {
texAddr = reinterpret_cast<uintptr_t>(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<Ship::IResource> ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<Ship::File> file) {
+ if (!FileHasValidFormatAndReader(file)) {
+ return nullptr;
+ }
+
+ auto array = std::make_shared<Array>(file->InitData);
+ auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(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<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> 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<Ship::IResource> ResourceFactoryBinaryGenericArrayV0::ReadResour
std::copy_n(reinterpret_cast<uint8_t*>(&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<uint8_t*>(&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<uint8_t*>(&vec), sizeof(Vec4f), std::back_inserter(arr->mData));
@@ -96,6 +101,9 @@ std::shared_ptr<Ship::IResource> ResourceFactoryBinaryGenericArrayV0::ReadResour
std::copy_n(reinterpret_cast<uint8_t*>(&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<Ship::ResourceInitData>()) {
+}
+
+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<void> {
+ 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<ScalarData> Scalars;
+ std::vector<F3DVtx> 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<uint8_t> {
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<int>(Ship::WindowBackend::WINDOW_BACKEND_COUNT)) {
+ if (Ship::Context::GetInstance()->GetWindow()->IsAvailableWindowBackend(configWindowBackendId)) {
configWindowBackend = static_cast<Ship::WindowBackend>(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);