Entity/Physical proof-read 1

This commit is contained in:
erorcun 2021-01-03 23:29:30 +03:00
parent 5b081398b5
commit 22e8202d27
4 changed files with 60 additions and 30 deletions

View File

@ -126,6 +126,7 @@ CEntity::CreateRwObject(void)
m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false); m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false);
else if(RwObjectGetType(m_rwObject) == rpCLUMP) else if(RwObjectGetType(m_rwObject) == rpCLUMP)
m_matrix.AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false); m_matrix.AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false);
mi->AddRef(); mi->AddRef();
} }
} }
@ -139,6 +140,7 @@ CEntity::AttachToRwObject(RwObject *obj)
m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false); m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false);
else if(RwObjectGetType(m_rwObject) == rpCLUMP) else if(RwObjectGetType(m_rwObject) == rpCLUMP)
m_matrix.Attach(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false); m_matrix.Attach(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false);
CModelInfo::GetModelInfo(m_modelIndex)->AddRef(); CModelInfo::GetModelInfo(m_modelIndex)->AddRef();
} }
} }
@ -239,12 +241,8 @@ CEntity::GetBoundRadius(void)
void void
CEntity::UpdateRwFrame(void) CEntity::UpdateRwFrame(void)
{ {
if(m_rwObject){ if(m_rwObject)
if(RwObjectGetType(m_rwObject) == rpATOMIC) RwFrameUpdateObjects(rwObjectGetParent(m_rwObject));
RwFrameUpdateObjects(RpAtomicGetFrame((RpAtomic*)m_rwObject));
else if(RwObjectGetType(m_rwObject) == rpCLUMP)
RwFrameUpdateObjects(RpClumpGetFrame((RpClump*)m_rwObject));
}
} }
void void

View File

@ -235,6 +235,7 @@ CPhysical::GetBoundRect(void)
return CRect(center.x-radius, center.y-radius, center.x+radius, center.y+radius); return CRect(center.x-radius, center.y-radius, center.x+radius, center.y+radius);
} }
// --MIAMI: Proof-read once
void void
CPhysical::AddToMovingList(void) CPhysical::AddToMovingList(void)
{ {
@ -242,6 +243,7 @@ CPhysical::AddToMovingList(void)
m_movingListNode = CWorld::GetMovingEntityList().InsertItem(this); m_movingListNode = CWorld::GetMovingEntityList().InsertItem(this);
} }
// --MIAMI: Proof-read once
void void
CPhysical::RemoveFromMovingList(void) CPhysical::RemoveFromMovingList(void)
{ {
@ -261,12 +263,14 @@ CPhysical::SetDamagedPieceRecord(uint16 piece, float impulse, CEntity *entity, C
m_vecDamageNormal = dir; m_vecDamageNormal = dir;
} }
// --MIAMI: Proof-read once
void void
CPhysical::AddCollisionRecord(CEntity *ent) CPhysical::AddCollisionRecord(CEntity *ent)
{ {
AddCollisionRecord_Treadable(ent); AddCollisionRecord_Treadable(ent);
this->bHasCollided = true; this->bHasCollided = true;
ent->bHasCollided = true; ent->bHasCollided = true;
this->m_nLastTimeCollided = CTimer::GetTimeInMilliseconds();
if(IsVehicle() && ent->IsVehicle()){ if(IsVehicle() && ent->IsVehicle()){
if(((CVehicle*)this)->m_nAlarmState == -1) if(((CVehicle*)this)->m_nAlarmState == -1)
((CVehicle*)this)->m_nAlarmState = 15000; ((CVehicle*)this)->m_nAlarmState = 15000;
@ -280,10 +284,10 @@ CPhysical::AddCollisionRecord(CEntity *ent)
return; return;
if(m_nCollisionRecords < PHYSICAL_MAX_COLLISIONRECORDS) if(m_nCollisionRecords < PHYSICAL_MAX_COLLISIONRECORDS)
m_aCollisionRecords[m_nCollisionRecords++] = ent; m_aCollisionRecords[m_nCollisionRecords++] = ent;
m_nLastTimeCollided = CTimer::GetTimeInMilliseconds();
} }
} }
// --MIAMI: Proof-read once
void void
CPhysical::AddCollisionRecord_Treadable(CEntity *ent) CPhysical::AddCollisionRecord_Treadable(CEntity *ent)
{ {
@ -291,6 +295,7 @@ CPhysical::AddCollisionRecord_Treadable(CEntity *ent)
} }
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::GetHasCollidedWith(CEntity *ent) CPhysical::GetHasCollidedWith(CEntity *ent)
{ {
@ -302,20 +307,23 @@ CPhysical::GetHasCollidedWith(CEntity *ent)
return false; return false;
} }
// --MIAMI: Proof-read once
void void
CPhysical::RemoveRefsToEntity(CEntity *ent) CPhysical::RemoveRefsToEntity(CEntity *ent)
{ {
int i, j; int i = 0, j;
for(i = 0; i < m_nCollisionRecords; i++){ while (i < m_nCollisionRecords){
if(m_aCollisionRecords[i] == ent){ if(m_aCollisionRecords[i] == ent){
for(j = i; j < m_nCollisionRecords-1; j++) for(j = i; j < m_nCollisionRecords-1; j++)
m_aCollisionRecords[j] = m_aCollisionRecords[j+1]; m_aCollisionRecords[j] = m_aCollisionRecords[j+1];
m_nCollisionRecords--; m_nCollisionRecords--;
} } else
i++;
} }
} }
// --MIAMI: Proof-read once
void void
CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phys, CVector localPos) CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phys, CVector localPos)
{ {
@ -332,6 +340,7 @@ CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phy
CWorld::Add(phys); CWorld::Add(phys);
} }
// --MIAMI: Proof-read once
int32 int32
CPhysical::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints) CPhysical::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
{ {
@ -350,6 +359,7 @@ CPhysical::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
return numSpheres; return numSpheres;
} }
// --MIAMI: Proof-read once
void void
CPhysical::ProcessControl(void) CPhysical::ProcessControl(void)
{ {
@ -417,6 +427,7 @@ CPhysical::GetSpeed(const CVector &r)
return m_vecMoveSpeed + m_vecMoveFriction + CrossProduct(m_vecTurnFriction + m_vecTurnSpeed, r); return m_vecMoveSpeed + m_vecMoveFriction + CrossProduct(m_vecTurnFriction + m_vecTurnSpeed, r);
} }
// --MIAMI: Proof-read once
void void
CPhysical::ApplyMoveSpeed(void) CPhysical::ApplyMoveSpeed(void)
{ {
@ -426,7 +437,7 @@ CPhysical::ApplyMoveSpeed(void)
GetMatrix().Translate(m_vecMoveSpeed * CTimer::GetTimeStep()); GetMatrix().Translate(m_vecMoveSpeed * CTimer::GetTimeStep());
} }
// --MIAMI: Proof-read once
void void
CPhysical::ApplyTurnSpeed(void) CPhysical::ApplyTurnSpeed(void)
{ {
@ -442,12 +453,14 @@ CPhysical::ApplyTurnSpeed(void)
} }
} }
// --MIAMI: Proof-read once
void void
CPhysical::ApplyMoveForce(float jx, float jy, float jz) CPhysical::ApplyMoveForce(float jx, float jy, float jz)
{ {
m_vecMoveSpeed += CVector(jx, jy, jz)*(1.0f/m_fMass); m_vecMoveSpeed += CVector(jx, jy, jz)*(1.0f/m_fMass);
} }
// --MIAMI: Proof-read once
void void
CPhysical::ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz) CPhysical::ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz)
{ {
@ -462,6 +475,7 @@ CPhysical::ApplyFrictionMoveForce(float jx, float jy, float jz)
m_vecMoveFriction += CVector(jx, jy, jz)*(1.0f/m_fMass); m_vecMoveFriction += CVector(jx, jy, jz)*(1.0f/m_fMass);
} }
// --MIAMI: Proof-read once
void void
CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float py, float pz) CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float py, float pz)
{ {
@ -470,6 +484,7 @@ CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float
m_vecTurnFriction += turnimpulse*(1.0f/m_fTurnMass); m_vecTurnFriction += turnimpulse*(1.0f/m_fTurnMass);
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector &point, float springRatio, float bias) CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector &point, float springRatio, float bias)
{ {
@ -483,6 +498,7 @@ CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector &
return true; return true;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ApplySpringCollisionAlt(float springConst, CVector &springDir, CVector &point, float springRatio, float bias, CVector &forceDir) CPhysical::ApplySpringCollisionAlt(float springConst, CVector &springDir, CVector &point, float springRatio, float bias, CVector &forceDir)
{ {
@ -500,6 +516,7 @@ CPhysical::ApplySpringCollisionAlt(float springConst, CVector &springDir, CVecto
return true; return true;
} }
// --MIAMI: Proof-read once
// What exactly is speed? // What exactly is speed?
bool bool
CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &point, CVector &speed) CPhysical::ApplySpringDampening(float damping, CVector &springDir, CVector &point, CVector &speed)
@ -560,17 +577,16 @@ CPhysical::ApplyFriction(void)
m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f);
} }
// --MIAMI: Proof-read once
void void
CPhysical::ApplyAirResistance(void) CPhysical::ApplyAirResistance(void)
{ {
if(m_fAirResistance > 0.1f){ if(m_fAirResistance > 0.1f){
if(GetStatus() != STATUS_GHOST){ float f = Pow(m_fAirResistance, CTimer::GetTimeStep());
float f = Pow(m_fAirResistance, CTimer::GetTimeStep()); m_vecMoveSpeed *= f;
m_vecMoveSpeed *= f; m_vecTurnSpeed *= f;
m_vecTurnSpeed *= f; }else if(GetStatus() != STATUS_GHOST){
} float f = Pow(1.0f/Abs(1.0f + m_fAirResistance*0.5f*m_vecMoveSpeed.MagnitudeSqr()), CTimer::GetTimeStep());
}else{
float f = Pow(1.0f/(m_fAirResistance*0.5f*m_vecMoveSpeed.MagnitudeSqr() + 1.0f), CTimer::GetTimeStep());
m_vecMoveSpeed *= f; m_vecMoveSpeed *= f;
m_vecTurnSpeed *= 0.99f; m_vecTurnSpeed *= 0.99f;
} }
@ -1015,6 +1031,7 @@ CPhysical::ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CV
return false; return false;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint) CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
{ {
@ -1044,7 +1061,11 @@ CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
impulseB = (speedSum - fOtherSpeedB) * B->m_fMass; impulseB = (speedSum - fOtherSpeedB) * B->m_fMass;
impulseLimit = adhesiveLimit*CTimer::GetTimeStep(); impulseLimit = adhesiveLimit*CTimer::GetTimeStep();
if(impulseA < -impulseLimit) impulseA = -impulseLimit; if(impulseA < -impulseLimit) impulseA = -impulseLimit;
if(impulseB > impulseLimit) impulseB = impulseLimit; // BUG: game has A's clamp again here, but this can't be right #ifdef FIX_BUGS
if(impulseB > impulseLimit) impulseB = impulseLimit;
#else
if(impulseA < -impulseLimit) impulseA = -impulseLimit; // duplicate
#endif
A->ApplyFrictionMoveForce(frictionDir*impulseA); A->ApplyFrictionMoveForce(frictionDir*impulseA);
B->ApplyFrictionMoveForce(frictionDir*impulseB); B->ApplyFrictionMoveForce(frictionDir*impulseB);
return true; return true;
@ -1139,6 +1160,7 @@ CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
return false; return false;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint) CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint)
{ {
@ -1176,7 +1198,7 @@ CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint)
if(fOtherSpeed > 0.0f){ if(fOtherSpeed > 0.0f){
frictionDir = vOtherSpeed * (1.0f/fOtherSpeed); frictionDir = vOtherSpeed * (1.0f/fOtherSpeed);
fImpulse = -fOtherSpeed * m_fMass; fImpulse = -fOtherSpeed * m_fMass;
impulseLimit = adhesiveLimit*CTimer::GetTimeStep() * 1.5f; impulseLimit = adhesiveLimit*CTimer::GetTimeStep() * 1.5;
if(fImpulse < -impulseLimit) fImpulse = -impulseLimit; if(fImpulse < -impulseLimit) fImpulse = -impulseLimit;
ApplyFrictionMoveForce(frictionDir*fImpulse); ApplyFrictionMoveForce(frictionDir*fImpulse);
ApplyFrictionTurnForce(frictionDir*fImpulse, pointpos); ApplyFrictionTurnForce(frictionDir*fImpulse, pointpos);
@ -1194,6 +1216,7 @@ CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint)
return false; return false;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ProcessShiftSectorList(CPtrList *lists) CPhysical::ProcessShiftSectorList(CPtrList *lists)
{ {
@ -1267,7 +1290,8 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
skipShift = true; skipShift = true;
Aobj->m_pCollidingEntity = B; Aobj->m_pCollidingEntity = B;
} }
} } else
skipShift = true;
}else if(B->IsObject() && A->IsVehicle()){ }else if(B->IsObject() && A->IsVehicle()){
CObject *Bobj = (CObject*)B; CObject *Bobj = (CObject*)B;
if(Bobj->ObjectCreatedBy != TEMP_OBJECT && if(Bobj->ObjectCreatedBy != TEMP_OBJECT &&
@ -1282,7 +1306,8 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
if(size.z < A->GetPosition().z || if(size.z < A->GetPosition().z ||
(Invert(A->GetMatrix(), inv) * size).z < 0.0f) (Invert(A->GetMatrix(), inv) * size).z < 0.0f)
skipShift = true; skipShift = true;
} } else
skipShift = true;
}else if(IsBodyPart(A->GetModelIndex()) && B->IsPed()) }else if(IsBodyPart(A->GetModelIndex()) && B->IsPed())
skipShift = true; skipShift = true;
else if(A->IsPed() && IsBodyPart(B->GetModelIndex())) else if(A->IsPed() && IsBodyPart(B->GetModelIndex()))
@ -1354,6 +1379,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
return true; return true;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ProcessCollisionSectorList_SimpleCar(CPtrList *lists) CPhysical::ProcessCollisionSectorList_SimpleCar(CPtrList *lists)
{ {
@ -1520,6 +1546,7 @@ collision:
return true; return true;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ProcessCollisionSectorList(CPtrList *lists) CPhysical::ProcessCollisionSectorList(CPtrList *lists)
{ {
@ -1656,8 +1683,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
return true; return true;
if(numCollisions == 0 && A == (CEntity*)FindPlayerPed() && Aped->m_pCollidingEntity == B) if(numCollisions == 0 && A == (CEntity*)FindPlayerPed() && Aped->m_pCollidingEntity == B)
Aped->m_pCollidingEntity = nil; Aped->m_pCollidingEntity = nil;
}else if(B->IsBuilding() || B->bIsStuck || B->bInfiniteMass || altcollision){ }else if(B->IsBuilding() || B->bIsStuck || B->m_phy_flagA08 || altcollision){
// This is the case where B doesn't move // This is the case where B doesn't move
B->m_scanCode = CWorld::GetCurrentScanCode(); B->m_scanCode = CWorld::GetCurrentScanCode();
@ -1925,18 +1951,22 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(B->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetModelInfo(B->GetModelIndex())->GetColModel()->boundingBox.GetSize();
size = B->GetMatrix() * size; size = B->GetMatrix() * size;
if(size.z < B->GetPosition().z || if(size.z < A->GetPosition().z ||
(Invert(A->GetMatrix(), inv) * size).z < 0.0f) (Invert(A->GetMatrix(), inv) * size).z < 0.0f)
Bobj->ObjectDamage(50.0f); Bobj->ObjectDamage(50.0f);
} }
}else if(A->IsObject() && A->bUsesCollision && B->IsVehicle()){ }else if(A->IsObject() && A->bUsesCollision && B->IsVehicle()){
if(Aobj->m_nCollisionDamageEffect && maxImpulseB > 20.0f) if(Aobj->m_nCollisionDamageEffect && maxImpulseB > 20.0f)
Aobj->ObjectDamage(maxImpulseB); Aobj->ObjectDamage(maxImpulseB);
#ifdef FIX_BUGS
else if(Aobj->m_nCollisionDamageEffect >= DAMAGE_EFFECT_SMASH_COMPLETELY){ else if(Aobj->m_nCollisionDamageEffect >= DAMAGE_EFFECT_SMASH_COMPLETELY){
#else
else if(Bobj->m_nCollisionDamageEffect >= DAMAGE_EFFECT_SMASH_COMPLETELY){
#endif
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(A->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetModelInfo(A->GetModelIndex())->GetColModel()->boundingBox.GetSize();
size = A->GetMatrix() * size; size = A->GetMatrix() * size;
if(size.z < A->GetPosition().z || if(size.z < B->GetPosition().z ||
(Invert(B->GetMatrix(), inv) * size).z < 0.0f) (Invert(B->GetMatrix(), inv) * size).z < 0.0f)
Aobj->ObjectDamage(50.0f); Aobj->ObjectDamage(50.0f);
} }
@ -1987,6 +2017,7 @@ CPhysical::CheckCollision_SimpleCar(void)
float PHYSICAL_SHIFT_SPEED_DAMP = 0.707f; float PHYSICAL_SHIFT_SPEED_DAMP = 0.707f;
// --MIAMI: Proof-read once
void void
CPhysical::ProcessShift(void) CPhysical::ProcessShift(void)
{ {
@ -1997,8 +2028,8 @@ CPhysical::ProcessShift(void)
RemoveAndAdd(); RemoveAndAdd();
}else{ }else{
CPhysical *surf; CPhysical *surf;
if(bHasHitWall && IsPed() && (surf = ((CPed*)this)->m_pCurrentPhysSurface, surf == nil || !surf->bInfiniteMass || surf->m_phy_flagA08) || if(bHasHitWall && (IsPed() && (surf = ((CPed*)this)->m_pCurrentPhysSurface, surf == nil || !surf->bInfiniteMass || surf->m_phy_flagA08) ||
CWorld::bSecondShift){ CWorld::bSecondShift)){
m_vecMoveSpeed *= Pow(PHYSICAL_SHIFT_SPEED_DAMP, CTimer::GetTimeStep()); m_vecMoveSpeed *= Pow(PHYSICAL_SHIFT_SPEED_DAMP, CTimer::GetTimeStep());
m_vecTurnSpeed *= Pow(PHYSICAL_SHIFT_SPEED_DAMP, CTimer::GetTimeStep()); m_vecTurnSpeed *= Pow(PHYSICAL_SHIFT_SPEED_DAMP, CTimer::GetTimeStep());
} }

View File

@ -14,6 +14,7 @@
using namespace rw; using namespace rw;
RwUInt8 RwObjectGetType(const RwObject *obj) { return obj->type; } RwUInt8 RwObjectGetType(const RwObject *obj) { return obj->type; }
RwFrame* rwObjectGetParent(const RwObject *obj) { return (RwFrame*)obj->parent; }
void *RwMalloc(size_t size) { return engine->memfuncs.rwmalloc(size, 0); } void *RwMalloc(size_t size) { return engine->memfuncs.rwmalloc(size, 0); }

View File

@ -108,12 +108,12 @@ enum RwCorePluginID
//struct RwObject; //struct RwObject;
typedef rw::Object RwObject; typedef rw::Object RwObject;
typedef rw::Frame RwFrame;
typedef RwObject *(*RwObjectCallBack)(RwObject *object, void *data); typedef RwObject *(*RwObjectCallBack)(RwObject *object, void *data);
RwUInt8 RwObjectGetType(const RwObject *obj); RwUInt8 RwObjectGetType(const RwObject *obj);
RwFrame* rwObjectGetParent(const RwObject *obj);
#define rwsprintf sprintf #define rwsprintf sprintf
#define rwvsprintf vsprintf #define rwvsprintf vsprintf