This commit is contained in:
TakaRikka
2026-03-26 04:52:52 -07:00
42 changed files with 178 additions and 183 deletions
+3
View File
@@ -68,3 +68,6 @@ Pass the disc image as a positional argument. Supported formats: ISO (GCM), RVZ,
build/dusk/dusk /path/to/game.rvz
```
If no path is specified, Dusk defaults to `game.iso` in the current working directory.
#### 30 FPS on Debug
When compiled fully in a Debug the game runs too slowly to hit playable 30 FPS. To avoid this, you can set a CMake cache variable to optimize specific critical files without hampering debuggability in the rest of the program: `-DDUSK_SELECTED_OPT=ON`. When building for MSVC (Windows) you must also modify `CMAKE_CXX_FLAGS_DEBUG` and `CMAKE_C_FLAGS_DEBUG` to remove `/RTC1` from the flags, like so: `-DCMAKE_CXX_FLAGS_DEBUG="/MDd /Zi /Ob0 /Od" -DCMAKE_C_FLAGS_DEBUG="/MDd /Zi /Ob0 /Od"`
+1 -1
+11 -1
View File
@@ -31,7 +31,17 @@ struct cXyz : Vec {
z = vec.z;
}
#else
cXyz() = default;
cXyz() {
if (std::isnan(x)) {
x = 0.0f;
}
if (std::isnan(y)) {
y = 0.0f;
}
if (std::isnan(z)) {
z = 0.0f;
}
}
~cXyz() = default;
cXyz(const cXyz& vec) = default;
#endif
+18
View File
@@ -73,6 +73,20 @@ private:
/* 0x8 */ f32 m_offsetXZ;
}; // Size: 0xC
#if TARGET_PC
#define PLAYER_CREATE_ANM_HEAP_F(heap, type, fmt, ...) \
{ \
char pcah_name_buf[32]; \
sprintf(pcah_name_buf, fmt, ##__VA_ARGS__); \
(heap).createHeap(type, pcah_name_buf); \
\
}
#define PLAYER_CREATE_ANM_HEAP(heap, type, name) (heap).createHeap(type, name)
#else
#define PLAYER_CREATE_ANM_HEAP_F(heap, type, name, ...) (heap).createHeap(type)
#define PLAYER_CREATE_ANM_HEAP(heap, type, name) (heap).createHeap(type)
#endif
class daPy_anmHeap_c {
public:
enum daAlinkHEAP_TYPE {
@@ -87,7 +101,11 @@ public:
~daPy_anmHeap_c();
void initData();
void* mallocBuffer();
#if TARGET_PC
void createHeap(daAlinkHEAP_TYPE i_heapType, const char* name);
#else
void createHeap(daAlinkHEAP_TYPE i_heapType);
#endif
void* loadData(u16 i_resId);
void* loadDataIdx(u16 i_resId);
void* loadDataPriIdx(u16 i_resId);
+7
View File
@@ -32,6 +32,10 @@ public:
J3DModel* getModel() { return mpModel; }
#if TARGET_PC
void setIdx(u8 idx) { this->idx = idx; }
#endif
private:
/* 0x00 */ JKRSolidHeap* mpHeap;
/* 0x04 */ J3DModel* mpModel;
@@ -40,6 +44,9 @@ private:
/* 0x10 */ u8 mDrawBG;
/* 0x11 */ s8 mRoomNo;
/* 0x12 */ u8 field_0x12;
#if TARGET_PC
u8 idx;
#endif
}; // Size: 0x14
class dSmplMdl_draw_c {
@@ -222,9 +222,13 @@ public:
#define JKRHEAP_NAME(heap, name) (heap)->setName(name)
#define JKRHEAP_NAMEF(heap, name, ...) (heap)->setNamef(name, __VA_ARGS__)
#define JKRHEAP_CURRENT_NAME(heap, name) JKRHEAP_NAME(mDoExt_getCurrentHeap(), name)
#define JKRHEAP_CURRENT_NAMEF(heap, name, ...) JKRHEAP_NAMEF(mDoExt_getCurrentHeap(), name, __VA_ARGS__)
#else
#define JKRHEAP_NAME(heap, name)
#define JKRHEAP_NAMEF(heap, name)
#define JKRHEAP_NAMEF(heap, name, ...)
#define JKRHEAP_CURRENT_NAME(heap, name)
#define JKRHEAP_CURRENT_NAMEF(heap, name, ...)
#endif
};
@@ -64,9 +64,9 @@ struct data {
};
struct TBlockData {
u32 size;
u16 scheme;
u16 IDSize;
BE(u32) size;
BE(u16) scheme;
BE(u16) IDSize;
u32 field_0x8[0];
};
+3 -1
View File
@@ -214,7 +214,9 @@ void* JKRExpHeap::do_alloc(u32 size, int alignment) {
#endif
#if TARGET_PC
JUT_ASSERT_MSG_F(__LINE__, ptr != nullptr, "failed to alloc memory! (0x%x byte).\n", size);
JUT_ASSERT_MSG_F(__LINE__, ptr != nullptr,
"Failed to alloc memory! (%s) (0x%X bytes).\n Heap size: %u\n Used size: %u",
this->getName(), size, getSize(), getTotalUsedSize());
#else
if (ptr == NULL) {
JUTWarningConsole_f(":::cannot alloc memory (0x%x byte).\n", size);
+1 -1
View File
@@ -68,7 +68,7 @@ JStudio::ctb::TObject* JStudio::ctb::TControl::getObject_index(u32 param_0) {
JStudio::ctb::TFactory::~TFactory() {}
JStudio::ctb::TObject* JStudio::ctb::TFactory::create(JStudio::ctb::data::TParse_TBlock const& param_0) {
switch(BSWAP16(param_0.get_scheme())) {
switch(param_0.get_scheme()) {
case 1:
return JKR_NEW TObject_TxyzRy(param_0);
default:
@@ -49,7 +49,7 @@ int JStudio::TControl::transformOnGet_setOrigin_TxyzRy(Vec const& param_0, f32 p
int JStudio::TControl::transform_setOrigin_ctb(JStudio::ctb::TObject const& param_0) {
switch (param_0.getScheme()) {
case 1: {
const f32* pfVar4 = (const f32*)param_0.getData();
const BE(f32)* pfVar4 = (const BE(f32)*)param_0.getData();
Vec local_144 = {0.0f, 0.0f, 0.0f};
local_144.x = pfVar4[0];
local_144.y = pfVar4[1];
@@ -153,7 +153,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_PARENT(
switch (param_1) {
case JStudio::data::UNK_0x18:
JUT_ASSERT(313, pContent!=NULL);
JUT_ASSERT(314, uSize==4);
JUT_ASSERT(314, uSize>0);
field_0x1d0 = NULL;
const JStage::TSystem* pJSGSystem = pCreateObject_->get_pJSGSystem_();
JUT_ASSERT(345, pJSGSystem!=NULL);
@@ -172,7 +172,7 @@ void JStudio_JParticle::TAdaptor_particle::adaptor_do_PARENT_NODE(
case JStudio::data::UNK_0x18:
if (field_0x1d0 != NULL) {
JUT_ASSERT(380, pContent!=NULL);
JUT_ASSERT(381, uSize==4);
JUT_ASSERT(381, uSize>0);
field_0x1d4 = field_0x1d0->JSGFindNodeID((const char*)pContent);
if (field_0x1d4 == -1) {
return;
+9 -9
View File
@@ -4453,7 +4453,7 @@ void daAlink_c::playerInit() {
mAtSph.StartCAt(current.pos);
mAnmHeap3.setBufferSize(0x20000);
mAnmHeap3.createHeap(daPy_anmHeap_c::HEAP_TYPE_4);
PLAYER_CREATE_ANM_HEAP(mAnmHeap3, daPy_anmHeap_c::HEAP_TYPE_4, "daAlink_c::mAnmHeap3");
if (checkWolf()) {
changeWolf();
@@ -4462,7 +4462,7 @@ void daAlink_c::playerInit() {
}
mAnmHeap4.setBufferSize(0xB00);
mAnmHeap4.createHeap(daPy_anmHeap_c::HEAP_TYPE_4);
PLAYER_CREATE_ANM_HEAP(mAnmHeap4, daPy_anmHeap_c::HEAP_TYPE_4, "daAlink_c::mAnmHeap4");
setShieldModel();
#if DEBUG
@@ -4507,24 +4507,24 @@ void daAlink_c::playerInit() {
for (i = 0; i < 3; i++) {
mUnderAnmHeap[i].setBuffer(mUnderAnmHeap[0].getBuffer() + (i * 0x2C00));
mUnderAnmHeap[i].createHeap(daPy_anmHeap_c::HEAP_TYPE_3);
PLAYER_CREATE_ANM_HEAP_F(mUnderAnmHeap[i], daPy_anmHeap_c::HEAP_TYPE_3, "daAlink_c::mUnderAnmHeap[%d]", i);
}
mUpperAnmHeap[0].setBuffer(mUnderAnmHeap[0].getBuffer() + 0x8400);
for (i = 0; i < 3; i++) {
mUpperAnmHeap[i].setBuffer(mUpperAnmHeap[0].getBuffer() + (i * 0x2C00));
mUpperAnmHeap[i].createHeap(daPy_anmHeap_c::HEAP_TYPE_3);
PLAYER_CREATE_ANM_HEAP_F(mUpperAnmHeap[i], daPy_anmHeap_c::HEAP_TYPE_3, "daAlink_c::mUpperAnmHeap[%d]", i);
}
mFaceBtpHeap.createHeap(daPy_anmHeap_c::HEAP_TYPE_1);
mFaceBtkHeap.createHeap(daPy_anmHeap_c::HEAP_TYPE_2);
mFaceBckHeap.createHeap(daPy_anmHeap_c::HEAP_TYPE_3);
PLAYER_CREATE_ANM_HEAP(mFaceBtpHeap, daPy_anmHeap_c::HEAP_TYPE_1, "daAlink_c::mFaceBtpHeap");
PLAYER_CREATE_ANM_HEAP(mFaceBtkHeap, daPy_anmHeap_c::HEAP_TYPE_2, "daAlink_c::mFaceBtkHeap");
PLAYER_CREATE_ANM_HEAP(mFaceBckHeap, daPy_anmHeap_c::HEAP_TYPE_3, "daAlink_c::mFaceBckHeap");
for (i = 0; i < 2; i++) {
mItemHeap[i].setBufferSize(0x13200);
mItemHeap[i].createHeap(daPy_anmHeap_c::HEAP_TYPE_4);
PLAYER_CREATE_ANM_HEAP_F(mItemHeap[i], daPy_anmHeap_c::HEAP_TYPE_4, "daAlink_c::mItemHeap[%d]", i);
}
mAnmHeap9.createHeap(daPy_anmHeap_c::HEAP_TYPE_3);
PLAYER_CREATE_ANM_HEAP(mAnmHeap9, daPy_anmHeap_c::HEAP_TYPE_3, "daAlink_c::mAnmHeap9");
resetBasAnime();
mZ2Link.init(&current.pos, &eyePos, &field_0x3720);
+1
View File
@@ -532,6 +532,7 @@ int daBg_c::create() {
if (room_heap != NULL) {
this->heap = JKRCreateSolidHeap(-1, room_heap, false);
JUT_ASSERT(471, heap != NULL);
JKRHEAP_NAME(heap, "d_a_bg Anms");
JKRHeap* old = mDoExt_setCurrentHeap(this->heap);
int rt = createHeap();
+6
View File
@@ -1578,11 +1578,17 @@ bool daE_DT_c::pointInSight(cXyz* i_point) {
f32 width = scissor->width;
f32 height = scissor->height;
mDoLib_project(i_point, &proj);
#if TARGET_PC
view_port_class* viewport = dComIfGp_getWindow(dComIfGp_getCameraWinID(idx))->getViewPort();
return proj.x > 0.0f && proj.x < width && proj.y > (30.0f * viewport->height / FB_HEIGHT) && -(30.0f * viewport->height / FB_HEIGHT) < height;
#else
if (proj.x > 0.0f && proj.x < width && proj.y > 30.0f && -30.0f < height) {
return true;
} else {
return false;
}
#endif
}
void daE_DT_c::executeOpening() {
+4 -4
View File
@@ -565,12 +565,12 @@ cPhs_Step daMidna_c::create() {
mpFunc = &daMidna_c::checkMetamorphoseEnableBase;
for (u16 i = 0; i < 3; i++) {
mBckHeap[i].createHeap(daPy_anmHeap_c::HEAP_TYPE_3);
PLAYER_CREATE_ANM_HEAP_F(mBckHeap[i], daPy_anmHeap_c::HEAP_TYPE_3, "daMidna_c::mBckHeap[%d]", i);
}
mBtpHeap.createHeap(daPy_anmHeap_c::HEAP_TYPE_1);
mBtkHeap.createHeap(daPy_anmHeap_c::HEAP_TYPE_2);
PLAYER_CREATE_ANM_HEAP_F(mBtpHeap, daPy_anmHeap_c::HEAP_TYPE_1, "daMidna_c::mBtpHeap");
PLAYER_CREATE_ANM_HEAP_F(mBtkHeap, daPy_anmHeap_c::HEAP_TYPE_2, "daMidna_c::mBtkHeap");
mSound.init(&current.pos, &eyePos, 3, 1);
mpShadowModel = mpMorf->getModel();
mpShadowModel->setUserArea((uintptr_t)this);
+8
View File
@@ -823,7 +823,15 @@ void daNpcTks_c::playMotion() {
daNpcF_anmPlayData dat4a = {ANM_JUMP_S, 4.0f, 1};
daNpcF_anmPlayData dat4b = {ANM_FLY, 0.0f, 0};
daNpcF_anmPlayData* pDat4[2] = {&dat4a, &dat4b};
#if TARGET_PC
// Note: this fixes a crash in the cutscene after entering city and likely needs to be revisited as its
// unclear why this was 1 in the first place and unclear why this fixes it
daNpcF_anmPlayData dat5 = {ANM_JUMP_E, 0.0f, 0};
#else
daNpcF_anmPlayData dat5 = {ANM_JUMP_E, 0.0f, 1};
#endif
daNpcF_anmPlayData* pDat5[1] = {&dat5};
daNpcF_anmPlayData dat6a = {ANM_LAND, 0.0f, 1};
daNpcF_anmPlayData dat6b = {ANM_WAIT_A, 4.0f, 0};
+2
View File
@@ -1008,6 +1008,7 @@ int daPeru_c::_cutAppear_Init(int const& param_1) {
initTalk(mFlowNodeNo, NULL);
break;
case 140:
{
static cXyz see_pos;
see_pos.set(0.0f, -300.0f, 300.0f);
mDoMtx_stack_c::ZXYrotS(shape_angle);
@@ -1016,6 +1017,7 @@ int daPeru_c::_cutAppear_Init(int const& param_1) {
mJntAnm.lookPos(&see_pos, 0);
setCnt(80);
break;
}
case 150:
mJntAnm.lookNone(0);
setAction(&daPeru_c::demo_walk_to_window, 0);
+7 -3
View File
@@ -237,7 +237,11 @@ void* daPy_anmHeap_c::mallocBuffer() {
return mBuffer;
}
void daPy_anmHeap_c::createHeap(daPy_anmHeap_c::daAlinkHEAP_TYPE i_heapType) {
#if TARGET_PC
void daPy_anmHeap_c::createHeap(daPy_anmHeap_c::daAlinkHEAP_TYPE i_heapType, const char* name) {
#else
void daPy_anmHeap_c::createHeap(daPy_anmHeap_c::daAlinkHEAP_TYPE i_heapType, const char* name) {
#endif
u32 size;
if (i_heapType == 4) {
@@ -260,8 +264,8 @@ void daPy_anmHeap_c::createHeap(daPy_anmHeap_c::daAlinkHEAP_TYPE i_heapType) {
JKRHeap* tmp;
mAnimeHeap = mDoExt_createSolidHeapFromGameToCurrent(&tmp, size, 0x20);
JKRHEAP_NAMEF(mAnimeHeap, "Alink anime type %d", i_heapType);
JKRHEAP_NAME(mAnimeHeap, name);
if (i_heapType == 4) {
tmpWork = JKR_NEW_ARRAY(char, size);
JUT_ASSERT(669, tmpWork != NULL);
+7
View File
@@ -10997,7 +10997,14 @@ static int camera_draw(camera_process_class* i_this) {
#endif
int trim_height = body->TrimHeight();
#if TARGET_PC
trim_height *= viewport->height / FB_HEIGHT;
window->setScissor(0.0f, trim_height, viewport->width, viewport->height - trim_height * 2.0f);
#else
window->setScissor(0.0f, trim_height, FB_WIDTH, FB_HEIGHT - trim_height * 2.0f);
#endif
C_MTXPerspective(process->view.projMtx, process->view.fovy, process->view.aspect, process->view.near_, process->view.far_);
mDoMtx_lookAt(process->view.viewMtx, &process->view.lookat.eye, &process->view.lookat.center,
&process->view.lookat.up, process->view.bank);
+1
View File
@@ -5195,6 +5195,7 @@ void dFile_select3D_c::_create(u8 i_mirrorIdx, u8 i_maskIdx) {
if (mpSolidHeap == NULL) {
JUT_ASSERT(5189, mpSolidHeap != NULL);
}
JKRHEAP_NAME(mpSolidHeap, "dFile_select3D_c::mpSolidHeap");
field_0x03c4 = 0.0f;
field_0x03c8 = 0.0f;
+1
View File
@@ -35,6 +35,7 @@ int dkWmark_c::create() {
mpHeap = mDoExt_createSolidHeapFromGameToCurrent(0x880, 0x20);
if (mpHeap != NULL) {
JKRHEAP_NAME(mpHeap, "dkWmark_c::mpHeap");
J3DModelData* modelData = (J3DModelData*)dComIfG_getObjectRes("Alink", 0x23);
JUT_ASSERT(60, modelData != NULL);
+9 -1
View File
@@ -31,6 +31,9 @@
#include "JSystem/JKernel/JKRSolidHeap.h"
#include <cstdlib>
#include <cstring>
#if TARGET_PC
#include "dusk/imgui/ImGuiConsole.hpp"
#endif
static void GxXFog_set();
@@ -11376,7 +11379,12 @@ void dKy_bg_MAxx_proc(void* bg_model_p) {
Mtx sp1D8;
if (mat_name[6] == '2') {
C_MTXLightPerspective(sp1D8, dComIfGd_getView()->fovy,
camera_p->view.aspect, 1.0f, 1.0f, -0.01f, 0.0f);
camera_p->view.aspect, 1.0f, 1.0f,
#if TARGET_PC
dusk::g_imguiConsole.isWaterProjectionOffsetEnabled() ? -0.01f : 0.0f, 0.0f);
#else
-0.01f, 0.0f);
#endif
} else {
C_MTXLightPerspective(sp1D8, dComIfGd_getView()->fovy,
camera_p->view.aspect, 0.49f, -0.49f, 0.5f, 0.5f);
+2
View File
@@ -26,6 +26,8 @@ int dThunder_c::createHeap() {
if (mpHeap == NULL) {
return 0;
}
JKRHEAP_NAME(mpHeap, "dThunder_c::mpHeap");
}
return 1;
+1
View File
@@ -2222,6 +2222,7 @@ dMenu_Collect3D_c::~dMenu_Collect3D_c() {
void dMenu_Collect3D_c::_create() {
mpHeap->getTotalFreeSize();
mpSolidHeap = mDoExt_createSolidHeapToCurrent(0x25800, mpHeap, 0x20);
JKRHEAP_NAME(mpSolidHeap, "dMenu_Collect3D_c::mpSolidHeap");
mDoExt_setCurrentHeap((JKRHeap*)mpSolidHeap);
daAlink_c* linkActor = daAlink_getAlinkActorClass();
if (linkActor != NULL) {
+1
View File
@@ -1649,6 +1649,7 @@ void dMenu_Dmap_c::_create() {
mDmapHeap = JKRCreateExpHeap(field_0xe8->getFreeSize() - 0x10, field_0xe8, false);
JUT_ASSERT(3732, mDmapHeap != NULL);
JKRHEAP_NAME(mDmapHeap, "dMenu_Dmap_c::mDmapHeap");
JKRHeap* heap = mDoExt_setCurrentHeap(mDmapHeap);
u32 sp28 = mDmapHeap->getTotalFreeSize();
+2
View File
@@ -18,6 +18,7 @@ static void dSmplMdl_modelUpdateDL(J3DModel* i_model) {
dSmplMdl_draw_c::dSmplMdl_draw_c() {
for (int i = 0; i < 8; i++) {
mModel[i].init();
mModel[i].setIdx(i);
}
for (int i = 0; i < 500; i++) {
@@ -128,6 +129,7 @@ BOOL diff_model_c::create(J3DModelData* i_modelData, int roomNo, u8 drawBG) {
JUT_ASSERT(397, i_modelData != NULL);
if (mpHeap == NULL) {
mpHeap = mDoExt_createSolidHeapFromGameToCurrent(0x2000, 0x20);
JKRHEAP_NAMEF(mpHeap, "Simple model (%d)", idx);
if (mpHeap != NULL) {
mpModel = mDoExt_J3DModel__create(i_modelData, 0x80000, 0x11000084);
+1
View File
@@ -384,6 +384,7 @@ static void dummy1(dStage_roomControl_c* roomControl) {
JKRExpHeap* dStage_roomControl_c::createMemoryBlock(int i_blockIdx, u32 i_heapSize) {
if (mMemoryBlock[i_blockIdx] == NULL) {
mMemoryBlock[i_blockIdx] = JKRCreateExpHeap(i_heapSize, mDoExt_getArchiveHeap(), false);
JKRHEAP_NAMEF(mMemoryBlock[i_blockIdx], "Room control memory block %d", i_blockIdx);
}
return mMemoryBlock[i_blockIdx];
+1
View File
@@ -40,6 +40,7 @@ int dTimer_c::_create() {
dComIfGp_setAllMapArchive(resInfo->getArchive());
mp_heap = fopMsgM_createExpHeap(0x11000, NULL);
JKRHEAP_NAME(mp_heap, "dTimer_c::mp_heap");
JKRHeap* prev_heap = mDoExt_setCurrentHeap(mp_heap);
if (mp_heap != NULL) {
mp_heap->getTotalFreeSize();
+6 -47
View File
@@ -14,43 +14,6 @@
#include "JSystem/JKernel/JKRHeap.h"
// ============================================================================
// Malloc-based allocator to bypass JKRHeap operator new/delete
// Without this, side-table allocations call operator new -> JKRHeap::alloc
// -> OSLockMutex -> GetMutexData -> operator new ... infinite recursion.
// ============================================================================
template<typename T>
struct MallocAllocator {
using value_type = T;
MallocAllocator() = default;
template<typename U> MallocAllocator(const MallocAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
void* p = std::malloc(n * sizeof(T));
if (!p) throw std::bad_alloc();
return static_cast<T*>(p);
}
void deallocate(T* p, std::size_t) noexcept { std::free(p); }
template<typename U> bool operator==(const MallocAllocator<U>&) const noexcept { return true; }
template<typename U> bool operator!=(const MallocAllocator<U>&) const noexcept { return false; }
};
template<typename T>
struct MallocDeleter {
void operator()(T* p) const {
p->~T();
std::free(p);
}
};
template<typename T, typename... Args>
std::unique_ptr<T, MallocDeleter<T>> make_malloc_unique(Args&&... args) {
void* mem = std::malloc(sizeof(T));
if (!mem) throw std::bad_alloc();
T* obj = JKR_NEW_ARGS (mem) T(std::forward<Args>(args)...);
return std::unique_ptr<T, MallocDeleter<T>>(obj);
}
// ============================================================================
// Side-table: native mutex per OSMutex
// ============================================================================
@@ -59,17 +22,13 @@ struct PCMutexData {
std::recursive_mutex nativeMutex;
};
template<typename K, typename V>
using MallocMap = std::unordered_map<K, V, std::hash<K>, std::equal_to<K>,
MallocAllocator<std::pair<const K, V>>>;
// Lazy-initialized to avoid DLL static init crashes
static std::mutex& GetMutexMapMutex() {
static std::mutex mtx;
return mtx;
}
static MallocMap<OSMutex*, std::unique_ptr<PCMutexData, MallocDeleter<PCMutexData>>>& GetMutexMap() {
static MallocMap<OSMutex*, std::unique_ptr<PCMutexData, MallocDeleter<PCMutexData>>> map;
static std::unordered_map<OSMutex*, std::unique_ptr<PCMutexData>>& GetMutexMap() {
static std::unordered_map<OSMutex*, std::unique_ptr<PCMutexData>> map;
return map;
}
@@ -78,7 +37,7 @@ static PCMutexData& GetMutexData(OSMutex* mutex) {
auto& map = GetMutexMap();
auto it = map.find(mutex);
if (it == map.end()) {
auto result = map.emplace(mutex, make_malloc_unique<PCMutexData>());
auto result = map.emplace(mutex, std::make_unique<PCMutexData>());
return *result.first->second;
}
return *it->second;
@@ -97,8 +56,8 @@ static std::mutex& GetCondMapMutex() {
static std::mutex mtx;
return mtx;
}
static MallocMap<OSCond*, std::unique_ptr<PCCondData, MallocDeleter<PCCondData>>>& GetCondMap() {
static MallocMap<OSCond*, std::unique_ptr<PCCondData, MallocDeleter<PCCondData>>> map;
static std::unordered_map<OSCond*, std::unique_ptr<PCCondData>>& GetCondMap() {
static std::unordered_map<OSCond*, std::unique_ptr<PCCondData>> map;
return map;
}
@@ -107,7 +66,7 @@ static PCCondData& GetCondData(OSCond* cond) {
auto& map = GetCondMap();
auto it = map.find(cond);
if (it == map.end()) {
auto result = map.emplace(cond, make_malloc_unique<PCCondData>());
auto result = map.emplace(cond, std::make_unique<PCCondData>());
return *result.first->second;
}
return *it->second;
+8 -57
View File
@@ -18,45 +18,6 @@
#include "JSystem/JKernel/JKRHeap.h"
// ============================================================================
// Malloc-based allocator to bypass JKRHeap operator new/delete
// ============================================================================
template<typename T>
struct MallocAllocator {
using value_type = T;
MallocAllocator() = default;
template<typename U> MallocAllocator(const MallocAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
void* p = std::malloc(n * sizeof(T));
if (!p) throw std::bad_alloc();
return static_cast<T*>(p);
}
void deallocate(T* p, std::size_t) noexcept { std::free(p); }
template<typename U> bool operator==(const MallocAllocator<U>&) const noexcept { return true; }
template<typename U> bool operator!=(const MallocAllocator<U>&) const noexcept { return false; }
};
template<typename T>
struct MallocDeleter {
void operator()(T* p) const {
p->~T();
std::free(p);
}
};
template<typename T, typename... Args>
std::unique_ptr<T, MallocDeleter<T>> make_malloc_unique(Args&&... args) {
void* mem = std::malloc(sizeof(T));
if (!mem) throw std::bad_alloc();
T* obj = JKR_NEW_ARGS (mem) T(std::forward<Args>(args)...);
return std::unique_ptr<T, MallocDeleter<T>>(obj);
}
template<typename K, typename V>
using MallocMap = std::unordered_map<K, V, std::hash<K>, std::equal_to<K>,
MallocAllocator<std::pair<const K, V>>>;
// ============================================================================
// Side-table: native thread data per OSThread
// ============================================================================
@@ -76,8 +37,8 @@ static std::mutex& GetThreadDataMutex() {
static std::mutex mtx;
return mtx;
}
static MallocMap<OSThread*, std::unique_ptr<PCThreadData, MallocDeleter<PCThreadData>>>& GetThreadDataMap() {
static MallocMap<OSThread*, std::unique_ptr<PCThreadData, MallocDeleter<PCThreadData>>> map;
static std::unordered_map<OSThread*, std::unique_ptr<PCThreadData>>& GetThreadDataMap() {
static std::unordered_map<OSThread*, std::unique_ptr<PCThreadData>> map;
return map;
}
@@ -86,8 +47,8 @@ static std::mutex& GetQueueCvMutex() {
static std::mutex mtx;
return mtx;
}
static MallocMap<OSThreadQueue*, std::unique_ptr<std::condition_variable, MallocDeleter<std::condition_variable>>>& GetQueueCvMap() {
static MallocMap<OSThreadQueue*, std::unique_ptr<std::condition_variable, MallocDeleter<std::condition_variable>>> map;
static std::unordered_map<OSThreadQueue*, std::unique_ptr<std::condition_variable>>& GetQueueCvMap() {
static std::unordered_map<OSThreadQueue*, std::unique_ptr<std::condition_variable>> map;
return map;
}
@@ -96,7 +57,7 @@ static std::condition_variable& GetQueueCV(OSThreadQueue* queue) {
auto& map = GetQueueCvMap();
auto it = map.find(queue);
if (it == map.end()) {
auto result = map.emplace(queue, make_malloc_unique<std::condition_variable>());
auto result = map.emplace(queue, std::make_unique<std::condition_variable>());
return *result.first->second;
}
return *it->second;
@@ -295,7 +256,7 @@ int OSCreateThread(OSThread* thread, void* (*func)(void*), void* param,
// Create side-table entry (but don't start the thread yet)
{
auto data = make_malloc_unique<PCThreadData>();
auto data = std::make_unique<PCThreadData>();
data->func = func;
data->param = param;
@@ -649,24 +610,14 @@ s32 OSEnableScheduler(void) {
// ============================================================================
BOOL OSDisableInterrupts(void) {
GetInterruptMutex().lock();
sInterruptLockCount++;
return (BOOL)(sInterruptLockCount > 1); // TRUE if was already locked
return FALSE;
}
BOOL OSRestoreInterrupts(BOOL level) {
if (sInterruptLockCount > 0) {
sInterruptLockCount--;
GetInterruptMutex().unlock();
}
return level;
return FALSE;
}
BOOL OSEnableInterrupts(void) {
if (sInterruptLockCount > 0) {
sInterruptLockCount--;
GetInterruptMutex().unlock();
}
return FALSE;
}
+1
View File
@@ -15,6 +15,7 @@ namespace dusk {
void draw();
bool isBloomEnabled() { return m_menuGame.isBloomEnabled(); }
bool isWaterProjectionOffsetEnabled() { return m_menuGame.isWaterProjectionOffsetEnabled(); }
ImGuiMenuTools::CollisionViewSettings& getCollisionViewSettings() { return m_menuTools.getCollisionViewSettings(); }
static bool CheckMenuViewToggle(ImGuiKey key, bool& active);
+5 -5
View File
@@ -12,19 +12,17 @@ namespace dusk {
return;
}
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
ImGui::SetNextWindowBgAlpha(0.65f);
ImGui::SetNextWindowSizeConstraints(ImVec2(300, 0), ImVec2(FLT_MAX, FLT_MAX));
if (!ImGui::Begin("Map Loader", nullptr, windowFlags)) {
if (!ImGui::Begin("Map Loader", &m_showMapLoader, windowFlags)) {
ImGui::End();
return;
}
ImGui::SeparatorText("Map Loader");
ImGui::Checkbox("Show Internal Names", &m_mapLoaderInfo.showInternalNames);
const char* previewRegion = "None";
@@ -38,6 +36,8 @@ namespace dusk {
if (ImGui::Selectable(region.regionName)) {
if (m_mapLoaderInfo.regionIdx != idx) {
m_mapLoaderInfo.mapIdx = 0;
m_mapLoaderInfo.roomNoIdx = 0;
m_mapLoaderInfo.pointNoIdx = 0;
}
m_mapLoaderInfo.regionIdx = idx;
}
@@ -70,7 +70,7 @@ namespace dusk {
m_mapLoaderInfo.pointNoIdx = 0;
}
}
}else {
} else {
ImGui::Text("No region selected.");
}
+6 -1
View File
@@ -23,6 +23,11 @@ namespace dusk {
if (ImGui::BeginMenu("Graphics")) {
ImGui::Checkbox("Native Bloom", &m_graphicsSettings.m_enableBloom);
ImGui::Checkbox("Water Projection Offset", &m_graphicsSettings.m_waterProjectionOffset);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Adds GC-specific -0.01 transS offset\n"
"that causes ~6px ghost artifacts in water reflections");
}
ImGui::EndMenu();
}
@@ -110,7 +115,7 @@ namespace dusk {
ImGui::SetNextWindowBgAlpha(0.65f);
ImGui::SetNextWindowSizeConstraints(ImVec2(850, 400), ImVec2(850, 400));
if (!ImGui::Begin("Controller Config", nullptr, windowFlags)) {
if (!ImGui::Begin("Controller Config", &m_showControllerConfig, windowFlags)) {
ImGui::End();
return;
}
+2
View File
@@ -13,6 +13,7 @@ namespace dusk {
ImGuiMenuGame();
void draw();
bool isBloomEnabled() { return m_graphicsSettings.m_enableBloom; }
bool isWaterProjectionOffsetEnabled() { return m_graphicsSettings.m_waterProjectionOffset; }
void windowInputViewer();
void windowControllerConfig();
@@ -35,6 +36,7 @@ namespace dusk {
struct {
bool m_enableBloom = 1;
bool m_waterProjectionOffset = false;
} m_graphicsSettings;
bool m_showControllerConfig = false;
+2 -2
View File
@@ -61,7 +61,7 @@ namespace dusk {
ShowPlayerInfo();
if (m_showSaveEditor) {
m_saveEditor.draw();
m_saveEditor.draw(m_showSaveEditor);
}
DuskDebugPad(); // temporary, remove later
@@ -141,7 +141,7 @@ namespace dusk {
ImGui::SetNextWindowBgAlpha(0.65f);
ImGui::SetNextWindowSizeConstraints(ImVec2(300, 200), ImVec2(300, 200));
if (ImGui::Begin("Player Info", nullptr, windowFlags)) {
if (ImGui::Begin("Player Info", &m_showPlayerInfo, windowFlags)) {
daAlink_c* player = (daAlink_c*)dComIfGp_getPlayer(0);
daHorse_c* horse = dComIfGp_getHorseActor();
+1 -1
View File
@@ -74,7 +74,7 @@ namespace dusk {
return;
}
if (ImGui::Begin("Processes")) {
if (ImGui::Begin("Processes", &m_showProcessManagement)) {
if (ImGui::BeginTabBar("Tabs")) {
showTreeRecursive = true;
if (ImGui::BeginTabItem("Tree")) {
+2 -2
View File
@@ -282,14 +282,14 @@ namespace dusk {
ImGuiSaveEditor::ImGuiSaveEditor() {}
void ImGuiSaveEditor::draw() {
void ImGuiSaveEditor::draw(bool& open) {
ImGuiIO& io = ImGui::GetIO();
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoResize;
ImGui::SetNextWindowBgAlpha(0.65f);
ImGui::SetNextWindowSizeConstraints(ImVec2(600, 700), ImVec2(600, 700));
if (ImGui::Begin("Save Editor", nullptr, windowFlags)) {
if (ImGui::Begin("Save Editor", &open, windowFlags)) {
if (ImGui::BeginTabBar("SaveEditorTabBar", ImGuiTabBarFlags_NoCloseWithMiddleMouseButton)) {
if (ImGui::BeginTabItem("Player Status")) {
drawPlayerStatusTab();
+1 -1
View File
@@ -11,7 +11,7 @@ namespace dusk {
public:
ImGuiSaveEditor();
void draw();
void draw(bool& open);
void drawPlayerStatusTab();
void drawLocationTab();
void drawInventoryTab();
+4 -39
View File
@@ -5,6 +5,7 @@
#include <string.h>
#include <cstdlib>
#include <cstdint>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <unordered_map>
@@ -55,42 +56,6 @@ u32 OSGetSoundMode() {
// Message Queue (thread-safe implementation)
// ==========================================================================
// Malloc-based allocator to bypass JKRHeap operator new/delete
template<typename T>
struct MallocAllocator {
using value_type = T;
MallocAllocator() = default;
template<typename U> MallocAllocator(const MallocAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
void* p = std::malloc(n * sizeof(T));
if (!p) throw std::bad_alloc();
return static_cast<T*>(p);
}
void deallocate(T* p, std::size_t) noexcept { std::free(p); }
template<typename U> bool operator==(const MallocAllocator<U>&) const noexcept { return true; }
template<typename U> bool operator!=(const MallocAllocator<U>&) const noexcept { return false; }
};
template<typename T>
struct MallocDeleter {
void operator()(T* p) const {
p->~T();
std::free(p);
}
};
template<typename T, typename... Args>
std::unique_ptr<T, MallocDeleter<T>> make_malloc_unique(Args&&... args) {
void* mem = std::malloc(sizeof(T));
if (!mem) throw std::bad_alloc();
T* obj = new (mem) T(std::forward<Args>(args)...);
return std::unique_ptr<T, MallocDeleter<T>>(obj);
}
template<typename K, typename V>
using MallocMap = std::unordered_map<K, V, std::hash<K>, std::equal_to<K>,
MallocAllocator<std::pair<const K, V>>>;
// Side-table for native synchronization per OSMessageQueue
struct PCMessageQueueData {
std::mutex mtx;
@@ -103,8 +68,8 @@ static std::mutex& GetMsgQueueMapMutex() {
static std::mutex mtx;
return mtx;
}
static MallocMap<OSMessageQueue*, std::unique_ptr<PCMessageQueueData, MallocDeleter<PCMessageQueueData>>>& GetMsgQueueMap() {
static MallocMap<OSMessageQueue*, std::unique_ptr<PCMessageQueueData, MallocDeleter<PCMessageQueueData>>> map;
static std::unordered_map<OSMessageQueue*, std::unique_ptr<PCMessageQueueData>>& GetMsgQueueMap() {
static std::unordered_map<OSMessageQueue*, std::unique_ptr<PCMessageQueueData>> map;
return map;
}
@@ -113,7 +78,7 @@ static PCMessageQueueData& GetMsgQueueData(OSMessageQueue* mq) {
auto& map = GetMsgQueueMap();
auto it = map.find(mq);
if (it == map.end()) {
auto result = map.emplace(mq, make_malloc_unique<PCMessageQueueData>());
auto result = map.emplace(mq, std::make_unique<PCMessageQueueData>());
return *result.first->second;
}
return *it->second;
+2
View File
@@ -524,6 +524,7 @@ bool fopAcM_entrySolidHeap_(fopAc_ac_c* i_actor, heapCallbackFunc i_heapCallback
OSReport_Error("最大空きヒープサイズで確保失敗。[%s]\n", procNameString);
return false;
}
JKRHEAP_NAMEF(heap, "Actor mng (%s)", procNameString);
#if DEBUG
if (!fopAcM::HeapAdjustQuiet) {
// Attempting registration with max heap size. %08x
@@ -625,6 +626,7 @@ bool fopAcM_entrySolidHeap_(fopAc_ac_c* i_actor, heapCallbackFunc i_heapCallback
if (alignedSize + adjOffset + 0x10 < freeSize) {
newHeap = mDoExt_createSolidHeapFromGame(alignedSize, 0x20);
JKRHEAP_NAMEF(newHeap, "Actor mng (%s)", procNameString);
}
if (fopAcM::HeapAdjustVerbose) {
+19
View File
@@ -1081,7 +1081,13 @@ static void trimming(view_class* param_0, view_port_class* param_1) {
GXSetDither(GX_TRUE);
GXSetNumIndStages(0);
Mtx44 ortho;
#if TARGET_PC
C_MTXOrtho(ortho, 0.0f, param_1->height, 0.0f, param_1->width, 0.0f, 10.0f);
#else
C_MTXOrtho(ortho, 0.0f, FB_HEIGHT, 0.0f, FB_WIDTH, 0.0f, 10.0f);
#endif
GXLoadPosMtxImm(cMtx_getIdentity(), 0);
GXClearVtxDesc();
GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
@@ -1089,6 +1095,17 @@ static void trimming(view_class* param_0, view_port_class* param_1) {
GXSetProjection(ortho, GX_ORTHOGRAPHIC);
GXSetCurrentMtx(0);
GXBegin(GX_QUADS, GX_VTXFMT0, 8);
#if TARGET_PC
GXPosition3s16(0, 0, -5);
GXPosition3s16(param_1->width, 0, -5);
GXPosition3s16(param_1->width, sc_top, -5);
GXPosition3s16(0, sc_top, -5);
GXPosition3s16(0, sc_bottom, -5);
GXPosition3s16(param_1->width, sc_bottom, -5);
GXPosition3s16(param_1->width, param_1->height, -5);
GXPosition3s16(0, param_1->height, -5);
#else
GXPosition3s16(0, 0, -5);
GXPosition3s16(FB_WIDTH, 0, -5);
GXPosition3s16(FB_WIDTH, sc_top, -5);
@@ -1097,6 +1114,8 @@ static void trimming(view_class* param_0, view_port_class* param_1) {
GXPosition3s16(FB_WIDTH, sc_bottom, -5);
GXPosition3s16(FB_WIDTH, FB_HEIGHT, -5);
GXPosition3s16(0, FB_HEIGHT, -5);
#endif
GXEnd();
}
GXSetScissor(param_1->scissor.x_orig, param_1->scissor.y_orig, param_1->scissor.width,
+1
View File
@@ -272,6 +272,7 @@ int game_main(int argc, char* argv[]) {
config.logLevel = (AuroraLogLevel)parsed_arg_options["log-level"].as<uint8_t>();
config.mem1Size = 256 * 1024 * 1024;
config.mem2Size = 24 * 1024 * 1024;
config.allowJoystickBackgroundEvents = true;
auroraInfo = aurora_initialize(argc, argv, &config);