mirror of
https://gitlab.com/skmp/dca3-game.git
synced 2025-09-02 19:23:16 +02:00
Merge branch 'skmp/improve-asserts' into 'main'
dc.cpp: Set custom assert handlers to redirect system asserts, cleanup stacktrace See merge request skmp/dca3-game!70
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#ifndef DC_THREAD_H
|
||||
#define DC_THREAD_H
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace dc {
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "vmu.h"
|
||||
#include "sampman.h"
|
||||
|
||||
#if !defined(DC_TEXCONV)
|
||||
|
||||
|
@@ -1,9 +1,6 @@
|
||||
#ifndef VMU_H_
|
||||
#define VMU_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "sampman.h"
|
||||
|
||||
#include "thread/thread.h"
|
||||
|
||||
#include <thread>
|
||||
|
@@ -359,16 +359,15 @@ typedef RwCamera *(*RwCameraCallBack)(RwCamera *camera, void *data);
|
||||
|
||||
enum RwCameraClearMode
|
||||
{
|
||||
rwCAMERACLEARIMAGE = 0x1,
|
||||
rwCAMERACLEARZ = 0x2,
|
||||
rwCAMERACLEARSTENCIL = 0x4
|
||||
rwCAMERACLEARIMAGE = rw::Camera::CLEARIMAGE,
|
||||
rwCAMERACLEARZ = rw::Camera::CLEARZ,
|
||||
rwCAMERACLEARSTENCIL = rw::Camera::CLEARSTENCIL
|
||||
};
|
||||
|
||||
enum RwCameraProjection
|
||||
{
|
||||
rwNACAMERAPROJECTION = 0,
|
||||
rwPERSPECTIVE = 1,
|
||||
rwPARALLEL = 2
|
||||
rwPERSPECTIVE = rw::Camera::PERSPECTIVE,
|
||||
rwPARALLEL = rw::Camera::PARALLEL
|
||||
};
|
||||
|
||||
enum RwFrustumTestResult
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#if defined RW_DC
|
||||
#include <assert.h>
|
||||
#undef assert // only included for assert_set_handler
|
||||
|
||||
#include "vmu/vmu.h"
|
||||
#include <dc/maple.h>
|
||||
@@ -1982,13 +1984,13 @@ __attribute__((noinline)) void stacktrace() {
|
||||
:
|
||||
: );
|
||||
dbglog(DBG_CRITICAL, "%s\n", getExecutableTag());
|
||||
dbglog(DBG_CRITICAL, "Stack trace: %p ", (void*)pr);
|
||||
dbglog(DBG_CRITICAL, "Stack trace: %08X ", (uintptr_t)pr);
|
||||
int found = 0;
|
||||
if(!(sp & 3) && sp > 0x8c000000 && sp < _arch_mem_top) {
|
||||
char** sp_ptr = (char**)sp;
|
||||
for (int so = 0; so < 16384; so++) {
|
||||
if (uintptr_t(&sp_ptr[so]) >= _arch_mem_top) {
|
||||
dbglog(DBG_CRITICAL, "(@@%p) ", &sp_ptr[so]);
|
||||
dbglog(DBG_CRITICAL, "(@@%08X) ", (uintptr_t)&sp_ptr[so]);
|
||||
break;
|
||||
}
|
||||
if (sp_ptr[so] > (char*)0x8c000000 && sp_ptr[so] < etext) {
|
||||
@@ -2004,9 +2006,9 @@ __attribute__((noinline)) void stacktrace() {
|
||||
uint16_t instr = instrp[-2];
|
||||
// BSR or BSRF or JSR @Rn ?
|
||||
if (((instr & 0xf000) == 0xB000) || ((instr & 0xf0ff) == 0x0003) || ((instr & 0xf0ff) == 0x400B)) {
|
||||
dbglog(DBG_CRITICAL, "%p ", instrp);
|
||||
dbglog(DBG_CRITICAL, "%08X ", (uintptr_t)instrp);
|
||||
if (found++ > 24) {
|
||||
dbglog(DBG_CRITICAL, "(@%p) ", &sp_ptr[so]);
|
||||
dbglog(DBG_CRITICAL, "(@%08X) ", (uintptr_t)&sp_ptr[so]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -2018,7 +2020,7 @@ __attribute__((noinline)) void stacktrace() {
|
||||
}
|
||||
dbglog(DBG_CRITICAL, "end\n");
|
||||
} else {
|
||||
dbglog(DBG_CRITICAL, "(@%p)\n", (void*)sp);
|
||||
dbglog(DBG_CRITICAL, "(@%08X)\n", (uintptr_t)sp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2039,6 +2041,14 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
dbglog(DBG_CRITICAL, "%s\n", getExecutableTag());
|
||||
|
||||
#if defined(DC_SH4)
|
||||
assert_set_handler([](const char * file, int line, const char * expr, const char * msg, const char * func) {
|
||||
(void)msg;
|
||||
re3_assert(expr, file, line, func);
|
||||
});
|
||||
#endif
|
||||
|
||||
#if !defined(DC_SIM)
|
||||
std::set_terminate([]() {
|
||||
fflush(stdout);
|
||||
|
@@ -359,16 +359,15 @@ typedef RwCamera *(*RwCameraCallBack)(RwCamera *camera, void *data);
|
||||
|
||||
enum RwCameraClearMode
|
||||
{
|
||||
rwCAMERACLEARIMAGE = 0x1,
|
||||
rwCAMERACLEARZ = 0x2,
|
||||
rwCAMERACLEARSTENCIL = 0x4
|
||||
rwCAMERACLEARIMAGE = rw::Camera::CLEARIMAGE,
|
||||
rwCAMERACLEARZ = rw::Camera::CLEARZ,
|
||||
rwCAMERACLEARSTENCIL = rw::Camera::CLEARSTENCIL
|
||||
};
|
||||
|
||||
enum RwCameraProjection
|
||||
{
|
||||
rwNACAMERAPROJECTION = 0,
|
||||
rwPERSPECTIVE = 1,
|
||||
rwPARALLEL = 2
|
||||
rwPERSPECTIVE = rw::Camera::PERSPECTIVE,
|
||||
rwPARALLEL = rw::Camera::PARALLEL
|
||||
};
|
||||
|
||||
enum RwFrustumTestResult
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#if defined RW_DC
|
||||
#include <assert.h>
|
||||
#undef assert // only included for assert_set_handler
|
||||
|
||||
#include "vmu/vmu.h"
|
||||
#include <dc/maple.h>
|
||||
@@ -2016,13 +2018,13 @@ __attribute__((noinline)) void stacktrace() {
|
||||
:
|
||||
: );
|
||||
dbglog(DBG_CRITICAL, "%s\n", getExecutableTag());
|
||||
dbglog(DBG_CRITICAL, "Stack trace: %p ", (void*)pr);
|
||||
dbglog(DBG_CRITICAL, "Stack trace: %08X ", (uintptr_t)pr);
|
||||
int found = 0;
|
||||
if(!(sp & 3) && sp > 0x8c000000 && sp < _arch_mem_top) {
|
||||
char** sp_ptr = (char**)sp;
|
||||
for (int so = 0; so < 16384; so++) {
|
||||
if (uintptr_t(&sp_ptr[so]) >= _arch_mem_top) {
|
||||
dbglog(DBG_CRITICAL, "(@@%p) ", &sp_ptr[so]);
|
||||
dbglog(DBG_CRITICAL, "(@@%08X) ", (uintptr_t)&sp_ptr[so]);
|
||||
break;
|
||||
}
|
||||
if (sp_ptr[so] > (char*)0x8c000000 && sp_ptr[so] < etext) {
|
||||
@@ -2038,9 +2040,9 @@ __attribute__((noinline)) void stacktrace() {
|
||||
uint16_t instr = instrp[-2];
|
||||
// BSR or BSRF or JSR @Rn ?
|
||||
if (((instr & 0xf000) == 0xB000) || ((instr & 0xf0ff) == 0x0003) || ((instr & 0xf0ff) == 0x400B)) {
|
||||
dbglog(DBG_CRITICAL, "%p ", instrp);
|
||||
dbglog(DBG_CRITICAL, "%08X ", (uintptr_t)instrp);
|
||||
if (found++ > 24) {
|
||||
dbglog(DBG_CRITICAL, "(@%p) ", &sp_ptr[so]);
|
||||
dbglog(DBG_CRITICAL, "(@%08X) ", (uintptr_t)&sp_ptr[so]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -2052,7 +2054,7 @@ __attribute__((noinline)) void stacktrace() {
|
||||
}
|
||||
dbglog(DBG_CRITICAL, "end\n");
|
||||
} else {
|
||||
dbglog(DBG_CRITICAL, "(@%p)\n", (void*)sp);
|
||||
dbglog(DBG_CRITICAL, "(@%08X)\n", (uintptr_t)sp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2073,6 +2075,14 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
dbglog(DBG_CRITICAL, "%s\n", getExecutableTag());
|
||||
|
||||
#if defined(DC_SH4)
|
||||
assert_set_handler([](const char * file, int line, const char * expr, const char * msg, const char * func) {
|
||||
(void)msg;
|
||||
re3_assert(expr, file, line, func);
|
||||
});
|
||||
#endif
|
||||
|
||||
#if !defined(DC_SIM)
|
||||
std::set_terminate([]() {
|
||||
fflush(stdout);
|
||||
|
30
vendor/librw/src/dc/rwdc.cpp
vendored
30
vendor/librw/src/dc/rwdc.cpp
vendored
@@ -37,6 +37,8 @@ extern const char* currentFile;
|
||||
#include <functional>
|
||||
#include <fstream>
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
#define errorf(...) dbglog(DBG_CRITICAL, __VA_ARGS__)
|
||||
#define logf(...) // printf(__VA_ARGS__)
|
||||
bool re3RemoveLeastUsedModel();
|
||||
@@ -1178,7 +1180,7 @@ void endUpdate(Camera* cam) {
|
||||
}
|
||||
|
||||
void clearCamera(Camera* cam,RGBA* col,uint32 flags) {
|
||||
if (flags & rwCAMERACLEARIMAGE) {
|
||||
if (flags & rw::Camera::CLEARIMAGE) {
|
||||
cam->clearColor = *col;
|
||||
}
|
||||
UNIMPL_LOG();
|
||||
@@ -1314,7 +1316,7 @@ setRenderState(int32 state, void *pvalue)
|
||||
case FOGCOLOR:
|
||||
#if !defined(DC_TEXCONV)
|
||||
// Set fog color when state changes
|
||||
if(fogColor != value || fogStart != RwCameraGetFogDistance(rwdcCam)) {
|
||||
if(fogColor != value || fogStart != rwdcCam->fogPlane) {
|
||||
fogColor = value;
|
||||
RGBA c;
|
||||
c.red = value;
|
||||
@@ -1323,8 +1325,8 @@ setRenderState(int32 state, void *pvalue)
|
||||
c.alpha = value>>24;
|
||||
pvr_fog_table_color(c.alpha / 255.0f, c.red / 255.0f, c.green / 255.0f, c.blue / 255.0f);
|
||||
|
||||
fogStart = RwCameraGetFogDistance(rwdcCam);
|
||||
float fogEnd = RwCameraGetFarClipPlane(rwdcCam);
|
||||
fogStart = rwdcCam->fogPlane;
|
||||
float fogEnd = rwdcCam->farPlane;
|
||||
float fogIntensity[129];
|
||||
uint8_t idx = 0;
|
||||
float startIntensity = (-fogStart) / (fogEnd - fogStart); //interpolate between start and end to get initial intensity
|
||||
@@ -1888,7 +1890,7 @@ struct MeshInfo {
|
||||
static_assert(sizeof(MeshInfo) == 4);
|
||||
|
||||
struct MeshletInfo {
|
||||
RwSphere boundingSphere;
|
||||
rw::Sphere boundingSphere;
|
||||
uint16_t flags;
|
||||
int8_t pad;
|
||||
int8_t vertexSize;
|
||||
@@ -3543,11 +3545,11 @@ void defaultRenderCB(ObjPipeline *pipe, Atomic *atomic) {
|
||||
// Frustum Culling
|
||||
auto global_frustumTestResult = AtomicFrustumSphereNearCB(atomic, cam);
|
||||
|
||||
if (global_frustumTestResult == rwSPHEREOUTSIDE) {
|
||||
if (global_frustumTestResult == rw::Camera::SPHEREOUTSIDE) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool global_needsNoClip = global_frustumTestResult == rwSPHEREINSIDE;
|
||||
bool global_needsNoClip = global_frustumTestResult == rw::Camera::SPHEREINSIDE;
|
||||
|
||||
// Material *m;
|
||||
|
||||
@@ -3780,8 +3782,8 @@ void defaultRenderCB(ObjPipeline *pipe, Atomic *atomic) {
|
||||
|
||||
if (!global_needsNoClip) {
|
||||
if (!skin) {
|
||||
RwSphere sphere = meshlet->boundingSphere;
|
||||
RwV3dTransformPoints(&sphere.center, &sphere.center, 1, atomic->getFrame()->getLTM());
|
||||
rw::Sphere sphere = meshlet->boundingSphere;
|
||||
rw::V3d::transformPoints(&sphere.center, &sphere.center, 1, atomic->getFrame()->getLTM());
|
||||
|
||||
auto local_frustumTestResult = cam->frustumTestSphereNear(&sphere);;
|
||||
if ( local_frustumTestResult == Camera::SPHEREOUTSIDE) {
|
||||
@@ -5207,7 +5209,7 @@ struct write_vector: std::vector<uint8_t> {
|
||||
std::copy(p, p + sizeof(T), begin() + offset);
|
||||
}
|
||||
|
||||
void packVertex(RwSphere* volume, V3d* vertex, TexCoords* texcoord, V3d* normal, RGBA* color, bool big_vertex, bool pad_xyz, bool big_uv) {
|
||||
void packVertex(rw::Sphere* volume, V3d* vertex, TexCoords* texcoord, V3d* normal, RGBA* color, bool big_vertex, bool pad_xyz, bool big_uv) {
|
||||
if (big_vertex) {
|
||||
write<float>(vertex->x);
|
||||
write<float>(vertex->y);
|
||||
@@ -5327,8 +5329,8 @@ unsigned caluclateVertexSize(bool textured, bool normaled, bool colored, bool bi
|
||||
return vertexBytes;
|
||||
}
|
||||
|
||||
RwSphere calculateBoundingSphere(V3d* vertexData, size_t count) {
|
||||
RwSphere sphere;
|
||||
rw::Sphere calculateBoundingSphere(V3d* vertexData, size_t count) {
|
||||
rw::Sphere sphere;
|
||||
sphere.center = {0, 0, 0};
|
||||
sphere.radius = 0;
|
||||
|
||||
@@ -5377,8 +5379,8 @@ struct meshlet {
|
||||
return false;
|
||||
}
|
||||
|
||||
RwSphere calculateBoundingSphere(V3d* vertexData) {
|
||||
RwSphere sphere;
|
||||
rw::Sphere calculateBoundingSphere(V3d* vertexData) {
|
||||
rw::Sphere sphere;
|
||||
sphere.center = {0, 0, 0};
|
||||
sphere.radius = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user