Merge pull request #957 from erorcun/miami

Fix build without FIX_BUGS, divide to 0 fixes
This commit is contained in:
erorcun 2021-01-13 14:03:48 +03:00 committed by GitHub
commit 679755de35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 14 deletions

View File

@ -238,12 +238,16 @@ enum Config {
# define TIMEBARS // print debug timers
#endif
#define FIX_BUGS // fixes bugs that we've came across during reversing, TODO: use this more
#define FIX_BUGS // fixes bugs that we've came across during reversing. You can undefine this only on release builds.
//#define MORE_LANGUAGES // Add more translations to the game
#define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible
#define LOAD_INI_SETTINGS // as the name suggests. fundamental for CUSTOM_FRONTEND_OPTIONS
#define FIX_HIGH_FPS_BUGS_ON_FRONTEND
#if defined(__LP64__) || defined(_WIN64)
#define FIX_BUGS_64 // Must have fixes to be able to run 64 bit build
#endif
// Just debug menu entries
#ifdef DEBUGMENU
#define RELOADABLES // some debug menu options to reload TXD files

View File

@ -883,9 +883,13 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
if(B->GetStatus() == STATUS_PLAYER)
pointposB *= 0.8f;
if(CWorld::bNoMoreCollisionTorque){
// BUG: the game actually uses A here, but this can't be right
#ifdef FIX_BUGS
B->ApplyFrictionMoveForce(fB*-0.3f);
B->ApplyFrictionTurnForce(fB*-0.3f, pointposB);
#else
A->ApplyFrictionMoveForce(fB*-0.3f);
A->ApplyFrictionTurnForce(fB*-0.3f, pointposB);
#endif
}
}
if(!A->bInfiniteMass){
@ -1054,7 +1058,13 @@ CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
fOtherSpeedA = vOtherSpeedA.Magnitude();
fOtherSpeedB = vOtherSpeedB.Magnitude();
#ifdef FIX_BUGS // division by 0
frictionDir = vOtherSpeedA;
frictionDir.Normalise();
#else
frictionDir = vOtherSpeedA * (1.0f/fOtherSpeedA);
#endif
speedSum = (B->m_fMass*fOtherSpeedB + A->m_fMass*fOtherSpeedA)/(B->m_fMass + A->m_fMass);
if(fOtherSpeedA > speedSum){
impulseA = (speedSum - fOtherSpeedA) * A->m_fMass;
@ -1084,7 +1094,12 @@ CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
fOtherSpeedA = vOtherSpeedA.Magnitude();
fOtherSpeedB = vOtherSpeedB.Magnitude();
#ifdef FIX_BUGS // division by 0
frictionDir = vOtherSpeedA;
frictionDir.Normalise();
#else
frictionDir = vOtherSpeedA * (1.0f/fOtherSpeedA);
#endif
float massB = B->GetMass(pointposB, frictionDir);
speedSum = (massB*fOtherSpeedB + A->m_fMass*fOtherSpeedA)/(massB + A->m_fMass);
if(fOtherSpeedA > speedSum){
@ -1112,7 +1127,12 @@ CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
fOtherSpeedA = vOtherSpeedA.Magnitude();
fOtherSpeedB = vOtherSpeedB.Magnitude();
#ifdef FIX_BUGS // division by 0
frictionDir = vOtherSpeedA;
frictionDir.Normalise();
#else
frictionDir = vOtherSpeedA * (1.0f/fOtherSpeedA);
#endif
float massA = A->GetMass(pointposA, frictionDir);
speedSum = (B->m_fMass*fOtherSpeedB + massA*fOtherSpeedA)/(B->m_fMass + massA);
if(fOtherSpeedA > speedSum){
@ -1140,7 +1160,12 @@ CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
fOtherSpeedA = vOtherSpeedA.Magnitude();
fOtherSpeedB = vOtherSpeedB.Magnitude();
#ifdef FIX_BUGS // division by 0
frictionDir = vOtherSpeedA;
frictionDir.Normalise();
#else
frictionDir = vOtherSpeedA * (1.0f/fOtherSpeedA);
#endif
float massA = A->GetMass(pointposA, frictionDir);
float massB = B->GetMass(pointposB, frictionDir);
speedSum = (massB*fOtherSpeedB + massA*fOtherSpeedA)/(massB + massA);
@ -1178,7 +1203,12 @@ CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint)
fOtherSpeed = vOtherSpeed.Magnitude();
if(fOtherSpeed > 0.0f){
#ifdef FIX_BUGS // division by 0
frictionDir = vOtherSpeed;
frictionDir.Normalise();
#else
frictionDir = vOtherSpeed * (1.0f/fOtherSpeed);
#endif
// not really impulse but speed
// maybe use ApplyFrictionMoveForce instead?
fImpulse = -fOtherSpeed;
@ -1196,7 +1226,12 @@ CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint)
fOtherSpeed = vOtherSpeed.Magnitude();
if(fOtherSpeed > 0.0f){
#ifdef FIX_BUGS // division by 0
frictionDir = vOtherSpeed;
frictionDir.Normalise();
#else
frictionDir = vOtherSpeed * (1.0f/fOtherSpeed);
#endif
fImpulse = -fOtherSpeed * m_fMass;
impulseLimit = adhesiveLimit*CTimer::GetTimeStep() * 1.5;
if(fImpulse < -impulseLimit) fImpulse = -impulseLimit;

View File

@ -93,7 +93,7 @@ MemoryMgrFree(void *ptr)
void *
RwMallocAlign(RwUInt32 size, RwUInt32 align)
{
#ifdef FIX_BUGS
#if defined (FIX_BUGS) || defined(FIX_BUGS_64)
uintptr ptralign = align-1;
void *mem = (void *)MemoryMgrMalloc(size + sizeof(uintptr) + ptralign);

View File

@ -255,7 +255,8 @@ SkinGetBonePositionsToTable(RpClump *clump, RwV3d *boneTable)
parent = stack[sp--];
else
parent = i;
assert(parent >= 0 && parent < numBones);
//assert(parent >= 0 && parent < numBones);
}
}
@ -263,7 +264,7 @@ RpHAnimAnimation*
HAnimAnimationCreateForHierarchy(RpHAnimHierarchy *hier)
{
int i;
#ifdef FIX_BUGS
#if defined FIX_BUGS || defined LIBRW
int numNodes = hier->numNodes*2; // you're supposed to have at least two KFs per node
#else
int numNodes = hier->numNodes;
@ -277,7 +278,7 @@ HAnimAnimationCreateForHierarchy(RpHAnimHierarchy *hier)
frame->q.real = 1.0f;
frame->q.imag.x = frame->q.imag.y = frame->q.imag.z = 0.0f;
frame->t.x = frame->t.y = frame->t.z = 0.0f;
#ifdef FIX_BUGS
#if defined FIX_BUGS || defined LIBRW
// times are subtracted and divided giving NaNs
// so they can't both be 0
frame->time = i/hier->numNodes;
@ -483,7 +484,7 @@ CameraSize(RwCamera * camera, RwRect * rect,
RwRaster *zRaster;
// BUG: game just changes camera raster's sizes, but this is a hack
#ifdef FIX_BUGS
#if defined FIX_BUGS || defined LIBRW
/*
* Destroy rasters...
*/

View File

@ -111,14 +111,14 @@ wchar*
CText::Get(const char *key)
{
uint8 result = false;
#ifdef FIX_BUGS
#if defined (FIX_BUGS) || defined(FIX_BUGS_64)
wchar *outstr = keyArray.Search(key, data.chars, &result);
#else
wchar *outstr = keyArray.Search(key, &result);
#endif
if (!result && bHasMissionTextOffsets && bIsMissionTextLoaded)
#ifdef FIX_BUGS
#if defined (FIX_BUGS) || defined(FIX_BUGS_64)
outstr = mission_keyArray.Search(key, mission_data.chars, &result);
#else
outstr = mission_keyArray.Search(key, &result);
@ -340,7 +340,7 @@ CKeyArray::Unload(void)
void
CKeyArray::Update(wchar *chars)
{
#ifndef FIX_BUGS
#if !defined(FIX_BUGS) && !defined(FIX_BUGS_64)
int i;
for(i = 0; i < numEntries; i++)
entries[i].value = (wchar*)((uint8*)chars + (uintptr)entries[i].value);
@ -368,7 +368,7 @@ CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 hi
}
wchar*
#ifdef FIX_BUGS
#if defined (FIX_BUGS) || defined(FIX_BUGS_64)
CKeyArray::Search(const char *key, wchar *data, uint8 *result)
#else
CKeyArray::Search(const char *key, uint8 *result)
@ -378,7 +378,7 @@ CKeyArray::Search(const char *key, uint8 *result)
char errstr[25];
int i;
#ifdef FIX_BUGS
#if defined (FIX_BUGS) || defined(FIX_BUGS_64)
found = BinarySearch(key, entries, 0, numEntries-1);
if (found) {
*result = true;

View File

@ -7,7 +7,7 @@ void TextCopy(wchar *dst, const wchar *src);
struct CKeyEntry
{
#ifdef FIX_BUGS
#if defined(FIX_BUGS) || defined(FIX_BUGS_64)
uint32 valueOffset;
#else
wchar *value;
@ -30,7 +30,7 @@ public:
void Unload(void);
void Update(wchar *chars);
CKeyEntry *BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high);
#ifdef FIX_BUGS
#if defined (FIX_BUGS) || defined(FIX_BUGS_64)
wchar *Search(const char *key, wchar *data, uint8 *result);
#else
wchar *Search(const char *key, uint8* result);