diff options
author | Fire_Head <Fire-Head@users.noreply.github.com> | 2019-07-11 02:48:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-11 02:48:36 +0200 |
commit | aa449b6fe162d8960351c5fe164a9120b8572652 (patch) | |
tree | fa82496d356ac2b77ffa1ab00684b0150907f009 /src/entities/Physical.cpp | |
parent | fixfixfix (diff) | |
parent | Merge pull request #129 from erorcun/erorcun (diff) | |
download | re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.gz re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.bz2 re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.lz re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.xz re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.zst re3-aa449b6fe162d8960351c5fe164a9120b8572652.zip |
Diffstat (limited to 'src/entities/Physical.cpp')
-rw-r--r-- | src/entities/Physical.cpp | 79 |
1 files changed, 46 insertions, 33 deletions
diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index d6a82658..55ed5380 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -3,6 +3,7 @@ #include "World.h" #include "Timer.h" #include "ModelIndices.h" +#include "Treadable.h" #include "Vehicle.h" #include "Ped.h" #include "Object.h" @@ -32,7 +33,7 @@ CPhysical::CPhysical(void) m_nCollisionRecords = 0; for(i = 0; i < 6; i++) - m_aCollisionRecords[0] = nil; + m_aCollisionRecords[i] = nil; field_EF = false; @@ -61,7 +62,7 @@ CPhysical::CPhysical(void) m_phy_flagA10 = false; m_phy_flagA20 = false; - m_nLastCollType = 0; + m_nSurfaceTouched = SURFACE_DEFAULT; } CPhysical::~CPhysical(void) @@ -456,7 +457,7 @@ CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector & float compression = 1.0f - springRatio; if(compression > 0.0f){ float step = min(CTimer::GetTimeStep(), 3.0f); - float impulse = -0.008f*m_fMass*step * springConst * compression * bias*2.0f; + float impulse = -GRAVITY*m_fMass*step * springConst * compression * bias*2.0f; ApplyMoveForce(springDir*impulse); ApplyTurnForce(springDir*impulse, point); } @@ -475,7 +476,7 @@ CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &poin // what is this? float a = m_fTurnMass / ((point.MagnitudeSqr() + 1.0f) * 2.0f * m_fMass); a = min(a, 1.0f); - float b = fabs(impulse / (speedB * m_fMass)); + float b = Abs(impulse / (speedB * m_fMass)); if(a < b) impulse *= a/b; @@ -488,7 +489,7 @@ void CPhysical::ApplyGravity(void) { if(bAffectedByGravity) - m_vecMoveSpeed.z -= 0.008f * CTimer::GetTimeStep(); + m_vecMoveSpeed.z -= GRAVITY * CTimer::GetTimeStep(); } void @@ -504,11 +505,11 @@ void CPhysical::ApplyAirResistance(void) { if(m_fAirResistance > 0.1f){ - float f = powf(m_fAirResistance, CTimer::GetTimeStep()); + float f = Pow(m_fAirResistance, CTimer::GetTimeStep()); m_vecMoveSpeed *= f; m_vecTurnSpeed *= f; }else{ - float f = powf(1.0f/(m_fAirResistance*0.5f*m_vecMoveSpeed.MagnitudeSqr() + 1.0f), CTimer::GetTimeStep()); + float f = Pow(1.0f/(m_fAirResistance*0.5f*m_vecMoveSpeed.MagnitudeSqr() + 1.0f), CTimer::GetTimeStep()); m_vecMoveSpeed *= f; m_vecTurnSpeed *= 0.99f; } @@ -718,7 +719,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl if(!B->bInfiniteMass){ if(fB.z < 0.0f){ fB.z = 0.0f; - if(fabs(speedA) < 0.01f) + if(Abs(speedA) < 0.01f) fB *= 0.5f; } if(ispedcontactA){ @@ -814,9 +815,9 @@ CPhysical::ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CV float minspeed = 0.0104f * CTimer::GetTimeStep(); if((IsObject() || IsVehicle() && GetUp().z < -0.3f) && !bHasContacted && - fabs(m_vecMoveSpeed.x) < minspeed && - fabs(m_vecMoveSpeed.y) < minspeed && - fabs(m_vecMoveSpeed.z) < minspeed*2.0f) + Abs(m_vecMoveSpeed.x) < minspeed && + Abs(m_vecMoveSpeed.y) < minspeed && + Abs(m_vecMoveSpeed.z) < minspeed*2.0f) e = -1.0f; else e = -(m_fElasticity + 1.0f); @@ -1149,14 +1150,14 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists) shift += dir * colpoints[mostColliding].depth * 0.5f; }else if(A->IsPed() && B->IsVehicle() && ((CVehicle*)B)->IsBoat()){ CVector dir = colpoints[mostColliding].normal; - float f = min(fabs(dir.z), 0.9f); + float f = min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); shift += dir * colpoints[mostColliding].depth / (1.0f - f); boat = B; }else if(B->IsPed() && A->IsVehicle() && ((CVehicle*)A)->IsBoat()){ CVector dir = colpoints[mostColliding].normal * -1.0f; - float f = min(fabs(dir.z), 0.9f); + float f = min(Abs(dir.z), 0.9f); dir.z = 0.0f; dir.Normalise(); B->GetPosition() += dir * colpoints[mostColliding].depth / (1.0f - f); @@ -1497,8 +1498,8 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float imp = impulseA; if(A->IsVehicle() && A->GetUp().z < -0.6f && - fabs(A->m_vecMoveSpeed.x) < 0.05f && - fabs(A->m_vecMoveSpeed.y) < 0.05f) + Abs(A->m_vecMoveSpeed.x) < 0.05f && + Abs(A->m_vecMoveSpeed.y) < 0.05f) imp *= 0.1f; float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); @@ -1518,8 +1519,8 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) float imp = impulseA; if(A->IsVehicle() && A->GetUp().z < -0.6f && - fabs(A->m_vecMoveSpeed.x) < 0.05f && - fabs(A->m_vecMoveSpeed.y) < 0.05f) + Abs(A->m_vecMoveSpeed.x) < 0.05f && + Abs(A->m_vecMoveSpeed.y) < 0.05f) imp *= 0.1f; float turnSpeedDiff = A->m_vecTurnSpeed.MagnitudeSqr(); @@ -1556,8 +1557,8 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) m_vecTurnSpeed += turnSpeed / numResponses; if(!CWorld::bNoMoreCollisionTorque && A->m_status == STATUS_PLAYER && A->IsVehicle() && - fabs(A->m_vecMoveSpeed.x) > 0.2f && - fabs(A->m_vecMoveSpeed.y) > 0.2f){ + Abs(A->m_vecMoveSpeed.x) > 0.2f && + Abs(A->m_vecMoveSpeed.y) > 0.2f){ A->m_vecMoveFriction.x += moveSpeed.x * -0.3f / numCollisions; A->m_vecMoveFriction.y += moveSpeed.y * -0.3f / numCollisions; A->m_vecTurnFriction += turnSpeed * -0.3f / numCollisions; @@ -1782,13 +1783,13 @@ CPhysical::ProcessShift(void) } bIsStuck = false; bIsInSafePosition = true; - m_fDistanceTravelled = (GetPosition() - *matrix.GetPosition()).Magnitude(); + m_fDistanceTravelled = (GetPosition() - matrix.GetPosition()).Magnitude(); RemoveAndAdd(); } } // x is the number of units (m) we would like to step -#define NUMSTEPS(x) ceil(sqrt(distSq) * (1.0f/(x))) +#define NUMSTEPS(x) ceil(Sqrt(distSq) * (1.0f/(x))) void CPhysical::ProcessCollision(void) @@ -1882,7 +1883,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && m_vecMoveSpeed.z == 0.0f && !ped->m_ped_flagA2 && ped->bIsStanding) - savedMatrix.GetPosition()->z = GetPosition().z; + savedMatrix.GetPosition().z = GetPosition().z; GetMatrix() = savedMatrix; CTimer::SetTimeStep(savedTimeStep); return; @@ -1890,7 +1891,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && m_vecMoveSpeed.z == 0.0f && !ped->m_ped_flagA2 && ped->bIsStanding) - savedMatrix.GetPosition()->z = GetPosition().z; + savedMatrix.GetPosition().z = GetPosition().z; GetMatrix() = savedMatrix; CTimer::SetTimeStep(savedTimeStep); if(IsVehicle()){ @@ -1917,14 +1918,14 @@ CPhysical::ProcessCollision(void) bHitByTrain || m_status == STATUS_PLAYER || IsPed() && ped->IsPlayer()){ if(IsVehicle()) - ((CVehicle*)this)->m_veh_flagD4 = true; + ((CVehicle*)this)->bVehicleColProcessed = true; if(CheckCollision()){ GetMatrix() = savedMatrix; return; } } bHitByTrain = false; - m_fDistanceTravelled = (GetPosition() - *savedMatrix.GetPosition()).Magnitude(); + m_fDistanceTravelled = (GetPosition() - savedMatrix.GetPosition()).Magnitude(); m_phy_flagA80 = false; bIsStuck = false; @@ -1932,16 +1933,28 @@ CPhysical::ProcessCollision(void) RemoveAndAdd(); } +class CPhysical_ : public CPhysical +{ +public: + void dtor(void) { CPhysical::~CPhysical(); } + void Add_(void) { CPhysical::Add(); } + void Remove_(void) { CPhysical::Remove(); } + CRect GetBoundRect_(void) { return CPhysical::GetBoundRect(); } + void ProcessControl_(void) { CPhysical::ProcessControl(); } + void ProcessShift_(void) { CPhysical::ProcessShift(); } + void ProcessCollision_(void) { CPhysical::ProcessCollision(); } + int32 ProcessEntityCollision_(CEntity *ent, CColPoint *point) { return CPhysical::ProcessEntityCollision(ent, point); } +}; STARTPATCHES - InjectHook(0x495130, &CPhysical::dtor, PATCH_JUMP); - InjectHook(0x4951F0, &CPhysical::Add_, PATCH_JUMP); - InjectHook(0x4954B0, &CPhysical::Remove_, PATCH_JUMP); - InjectHook(0x495540, &CPhysical::RemoveAndAdd, PATCH_JUMP); - InjectHook(0x495F10, &CPhysical::ProcessControl_, PATCH_JUMP); - InjectHook(0x496F10, &CPhysical::ProcessShift_, PATCH_JUMP); - InjectHook(0x4961A0, &CPhysical::ProcessCollision_, PATCH_JUMP); - InjectHook(0x49F790, &CPhysical::ProcessEntityCollision_, PATCH_JUMP); + InjectHook(0x495130, &CPhysical_::dtor, PATCH_JUMP); + InjectHook(0x4951F0, &CPhysical_::Add_, PATCH_JUMP); + InjectHook(0x4954B0, &CPhysical_::Remove_, PATCH_JUMP); + InjectHook(0x495540, &CPhysical_::RemoveAndAdd, PATCH_JUMP); + InjectHook(0x495F10, &CPhysical_::ProcessControl_, PATCH_JUMP); + InjectHook(0x496F10, &CPhysical_::ProcessShift_, PATCH_JUMP); + InjectHook(0x4961A0, &CPhysical_::ProcessCollision_, PATCH_JUMP); + InjectHook(0x49F790, &CPhysical_::ProcessEntityCollision_, PATCH_JUMP); InjectHook(0x4958F0, &CPhysical::AddToMovingList, PATCH_JUMP); InjectHook(0x495940, &CPhysical::RemoveFromMovingList, PATCH_JUMP); InjectHook(0x497180, &CPhysical::AddCollisionRecord, PATCH_JUMP); |