CEntity and C(Vu)Vector fixes and cleanup

This commit is contained in:
aap 2021-05-23 17:49:55 +02:00 committed by Sergeanur
parent be019c6126
commit 93e9929925
13 changed files with 57 additions and 52 deletions

View File

@ -4101,16 +4101,11 @@ CCamera::IsSphereVisible(const CVector &center, float radius, const CMatrix *mat
bool bool
CCamera::IsSphereVisible(const CVector &center, float radius) CCamera::IsSphereVisible(const CVector &center, float radius)
{ {
CMatrix mat = m_cameraMatrix; return IsSphereVisible(center, radius, &m_cameraMatrix);
return IsSphereVisible(center, radius, &mat);
} }
bool bool
#ifdef GTA_PS2 CCamera::IsBoxVisible(CVUVECTOR *box, const CMatrix *mat)
CCamera::IsBoxVisible(CVuVector *box, const CMatrix *mat)
#else
CCamera::IsBoxVisible(CVector *box, const CMatrix *mat)
#endif
{ {
int i; int i;
int frustumTests[6] = { 0 }; int frustumTests[6] = { 0 };

View File

@ -633,11 +633,7 @@ public:
bool IsPointVisible(const CVector &center, const CMatrix *mat); bool IsPointVisible(const CVector &center, const CMatrix *mat);
bool IsSphereVisible(const CVector &center, float radius, const CMatrix *mat); bool IsSphereVisible(const CVector &center, float radius, const CMatrix *mat);
bool IsSphereVisible(const CVector &center, float radius); bool IsSphereVisible(const CVector &center, float radius);
#ifdef GTA_PS2 bool IsBoxVisible(CVUVECTOR *box, const CMatrix *mat);
bool IsBoxVisible(CVuVector *box, const CMatrix *mat);
#else
bool IsBoxVisible(CVector *box, const CMatrix *mat);
#endif
}; };
VALIDATE_SIZE(CCamera, 0xE9D8); VALIDATE_SIZE(CCamera, 0xE9D8);

View File

@ -39,9 +39,7 @@ CEntity::RegisterReference(CEntity **pent)
ref->pentity = pent; ref->pentity = pent;
ref->next = m_pFirstReference; ref->next = m_pFirstReference;
m_pFirstReference = ref; m_pFirstReference = ref;
return;
} }
return;
} }
// Clean up the reference from *pent -> 'this' // Clean up the reference from *pent -> 'this'

View File

@ -214,6 +214,12 @@ inline uint32 ldb(uint32 p, uint32 s, uint32 w)
#include "maths.h" #include "maths.h"
#include "Vector.h" #include "Vector.h"
#ifdef GTA_PS2
#include "VuVector.h"
#define CVUVECTOR CVuVector
#else
#define CVUVECTOR CVector
#endif
#include "Vector2D.h" #include "Vector2D.h"
#include "Matrix.h" #include "Matrix.h"
#include "Rect.h" #include "Rect.h"

View File

@ -1,5 +1,6 @@
#include "common.h" #include "common.h"
#include "VuVector.h"
#include "General.h" #include "General.h"
#include "RwHelper.h" #include "RwHelper.h"
#include "ModelIndices.h" #include "ModelIndices.h"
@ -70,7 +71,7 @@ CEntity::CEntity(void)
bDistanceFade = false; bDistanceFade = false;
m_flagE1 = false; m_flagE1 = false;
m_flagE2 = false; bDontCastShadowsOn = false;
bOffscreen = false; bOffscreen = false;
bIsStaticWaitingForCollision = false; bIsStaticWaitingForCollision = false;
bDontStream = false; bDontStream = false;
@ -200,7 +201,7 @@ CEntity::GetBoundRect(void)
{ {
CRect rect; CRect rect;
CVector v; CVector v;
CColModel *col = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel(); CColModel *col = CModelInfo::GetColModel(m_modelIndex);
rect.ContainPoint(GetMatrix() * col->boundingBox.min); rect.ContainPoint(GetMatrix() * col->boundingBox.min);
rect.ContainPoint(GetMatrix() * col->boundingBox.max); rect.ContainPoint(GetMatrix() * col->boundingBox.max);
@ -219,21 +220,27 @@ CEntity::GetBoundRect(void)
CVector CVector
CEntity::GetBoundCentre(void) CEntity::GetBoundCentre(void)
{ {
CVector v; return GetMatrix() * CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center;
GetBoundCentre(v);
return v;
} }
#ifdef GTA_PS2
void
CEntity::GetBoundCentre(CVuVector &out)
{
TransformPoint(out, GetMatrix(), CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center);
}
#else
void void
CEntity::GetBoundCentre(CVector &out) CEntity::GetBoundCentre(CVector &out)
{ {
out = GetMatrix() * CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.center; out = GetMatrix() * CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center;
} }
#endif
float float
CEntity::GetBoundRadius(void) CEntity::GetBoundRadius(void)
{ {
return CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.radius; return CModelInfo::GetColModel(m_modelIndex)->boundingSphere.radius;
} }
void void
@ -372,7 +379,7 @@ CEntity::PreRender(void)
CVector pos = GetPosition(); CVector pos = GetPosition();
CShadows::StoreShadowToBeRendered(SHADOWTYPE_DARK, CShadows::StoreShadowToBeRendered(SHADOWTYPE_DARK,
gpShadowPedTex, &pos, gpShadowPedTex, &pos,
0.4f, 0.0f, 0.0f, -0.4f, 0.4f, 0.0f, 0.0f, 0.4f,
CTimeCycle::GetShadowStrength(), CTimeCycle::GetShadowStrength(),
CTimeCycle::GetShadowStrength(), CTimeCycle::GetShadowStrength(),
CTimeCycle::GetShadowStrength(), CTimeCycle::GetShadowStrength(),
@ -418,9 +425,11 @@ CEntity::Render(void)
} }
bool bool
CEntity::GetIsTouching(CVector const &center, float radius) CEntity::GetIsTouching(CVUVECTOR const &center, float radius)
{ {
return sq(GetBoundRadius()+radius) > (GetBoundCentre()-center).MagnitudeSqr(); CVUVECTOR boundCenter;
GetBoundCentre(boundCenter);
return sq(GetBoundRadius()+radius) > (boundCenter-center).MagnitudeSqr();
} }
bool bool
@ -438,8 +447,7 @@ CEntity::IsVisibleComplex(void)
bool bool
CEntity::GetIsOnScreen(void) CEntity::GetIsOnScreen(void)
{ {
return TheCamera.IsSphereVisible(GetBoundCentre(), GetBoundRadius(), return TheCamera.IsSphereVisible(GetBoundCentre(), GetBoundRadius());
&TheCamera.GetCameraMatrix());
} }
bool bool
@ -455,7 +463,7 @@ CEntity::GetIsOnScreenComplex(void)
return true; return true;
CRect rect = GetBoundRect(); CRect rect = GetBoundRect();
CColModel *colmodel = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel(); CColModel *colmodel = CModelInfo::GetColModel(m_modelIndex);
float z = GetPosition().z; float z = GetPosition().z;
float minz = z + colmodel->boundingBox.min.z; float minz = z + colmodel->boundingBox.min.z;
float maxz = z + colmodel->boundingBox.max.z; float maxz = z + colmodel->boundingBox.max.z;
@ -610,7 +618,7 @@ CEntity::Remove(void)
float float
CEntity::GetDistanceFromCentreOfMassToBaseOfModel(void) CEntity::GetDistanceFromCentreOfMassToBaseOfModel(void)
{ {
return -CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingBox.min.z; return -CModelInfo::GetColModel(m_modelIndex)->boundingBox.min.z;
} }
void void
@ -731,11 +739,6 @@ CEntity::PreRenderForGlassWindow(void)
bIsVisible = false; bIsVisible = false;
} }
/*
0x487A10 - SetAtomicAlphaCB
0x4879E0 - SetClumpAlphaCB
*/
RpMaterial* RpMaterial*
SetAtomicAlphaCB(RpMaterial *material, void *data) SetAtomicAlphaCB(RpMaterial *material, void *data)
{ {
@ -834,7 +837,7 @@ CEntity::SaveEntityFlags(uint8*& buf)
if (bDistanceFade) tmp |= BIT(7); if (bDistanceFade) tmp |= BIT(7);
if (m_flagE1) tmp |= BIT(8); if (m_flagE1) tmp |= BIT(8);
if (m_flagE2) tmp |= BIT(9); if (bDontCastShadowsOn) tmp |= BIT(9);
if (bOffscreen) tmp |= BIT(10); if (bOffscreen) tmp |= BIT(10);
if (bIsStaticWaitingForCollision) tmp |= BIT(11); if (bIsStaticWaitingForCollision) tmp |= BIT(11);
if (bDontStream) tmp |= BIT(12); if (bDontStream) tmp |= BIT(12);
@ -890,7 +893,7 @@ CEntity::LoadEntityFlags(uint8*& buf)
bDistanceFade = !!(tmp & BIT(7)); bDistanceFade = !!(tmp & BIT(7));
m_flagE1 = !!(tmp & BIT(8)); m_flagE1 = !!(tmp & BIT(8));
m_flagE2 = !!(tmp & BIT(9)); bDontCastShadowsOn = !!(tmp & BIT(9));
bOffscreen = !!(tmp & BIT(10)); bOffscreen = !!(tmp & BIT(10));
bIsStaticWaitingForCollision = !!(tmp & BIT(11)); bIsStaticWaitingForCollision = !!(tmp & BIT(11));
bDontStream = !!(tmp & BIT(12)); bDontStream = !!(tmp & BIT(12));

View File

@ -84,7 +84,7 @@ public:
// flagsE // flagsE
uint32 m_flagE1 : 1; uint32 m_flagE1 : 1;
uint32 m_flagE2 : 1; uint32 bDontCastShadowsOn : 1; // Dont cast shadows on this object
uint32 bOffscreen : 1; // offscreen flag. This can only be trusted when it is set to true uint32 bOffscreen : 1; // offscreen flag. This can only be trusted when it is set to true
uint32 bIsStaticWaitingForCollision : 1; // this is used by script created entities - they are static until the collision is loaded below them uint32 bIsStaticWaitingForCollision : 1; // this is used by script created entities - they are static until the collision is loaded below them
uint32 bDontStream : 1; // tell the streaming not to stream me uint32 bDontStream : 1; // tell the streaming not to stream me
@ -148,11 +148,11 @@ public:
return (RpClump*)m_rwObject; return (RpClump*)m_rwObject;
} }
void GetBoundCentre(CVector &out); void GetBoundCentre(CVUVECTOR &out);
CVector GetBoundCentre(void); CVector GetBoundCentre(void);
float GetBoundRadius(void); float GetBoundRadius(void);
float GetDistanceFromCentreOfMassToBaseOfModel(void); float GetDistanceFromCentreOfMassToBaseOfModel(void);
bool GetIsTouching(CVector const &center, float r); bool GetIsTouching(CVUVECTOR const &center, float r);
bool GetIsOnScreen(void); bool GetIsOnScreen(void);
bool GetIsOnScreenComplex(void); bool GetIsOnScreenComplex(void);
bool IsVisible(void); bool IsVisible(void);

View File

@ -226,7 +226,7 @@ CPhysical::RemoveAndAdd(void)
CRect CRect
CPhysical::GetBoundRect(void) CPhysical::GetBoundRect(void)
{ {
CVector center; CVUVECTOR center;
float radius; float radius;
GetBoundCentre(center); GetBoundCentre(center);
radius = GetBoundRadius(); radius = GetBoundRadius();
@ -1259,7 +1259,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
CPhysical *A, *B; CPhysical *A, *B;
CObject *Bobj; CObject *Bobj;
bool canshift; bool canshift;
CVector center; CVUVECTOR center;
float radius; float radius;
int numCollisions; int numCollisions;
@ -1418,7 +1418,7 @@ CPhysical::ProcessCollisionSectorList_SimpleCar(CPtrList *lists)
{ {
static CColPoint aColPoints[MAX_COLLISION_POINTS]; static CColPoint aColPoints[MAX_COLLISION_POINTS];
float radius; float radius;
CVector center; CVUVECTOR center;
int listtype; int listtype;
CPhysical *A, *B; CPhysical *A, *B;
int numCollisions; int numCollisions;
@ -1585,7 +1585,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
{ {
static CColPoint aColPoints[MAX_COLLISION_POINTS]; static CColPoint aColPoints[MAX_COLLISION_POINTS];
float radius; float radius;
CVector center; CVUVECTOR center;
CPtrList *list; CPtrList *list;
CPhysical *A, *B; CPhysical *A, *B;
CObject *Aobj, *Bobj; CObject *Aobj, *Bobj;

View File

@ -22,6 +22,8 @@ public:
x = 1.0f; x = 1.0f;
} }
*/ */
// TODO: operator-
}; };
void TransformPoint(CVuVector &out, const CMatrix &mat, const CVuVector &in); void TransformPoint(CVuVector &out, const CMatrix &mat, const CVuVector &in);

View File

@ -38,6 +38,9 @@ public:
return ms_modelInfoPtrs[id]; return ms_modelInfoPtrs[id];
} }
static CBaseModelInfo *GetModelInfo(const char *name, int minIndex, int maxIndex); static CBaseModelInfo *GetModelInfo(const char *name, int minIndex, int maxIndex);
static CColModel *GetColModel(int id){
return ms_modelInfoPtrs[id]->GetColModel();
}
static bool IsBoatModel(int32 id); static bool IsBoatModel(int32 id);
static bool IsBikeModel(int32 id); static bool IsBikeModel(int32 id);

View File

@ -979,27 +979,30 @@ CPopulation::TestSafeForRealObject(CDummyObject *dummy)
{ {
CPtrNode *ptrNode; CPtrNode *ptrNode;
CColModel *dummyCol = dummy->GetColModel(); CColModel *dummyCol = dummy->GetColModel();
float colRadius = dummy->GetBoundRadius();
CVector colCentre = dummy->GetBoundCentre();
int minX = CWorld::GetSectorIndexX(dummy->GetPosition().x - colRadius); float radius = dummyCol->boundingSphere.radius;
int minX = CWorld::GetSectorIndexX(dummy->GetPosition().x - radius);
if (minX < 0) minX = 0; if (minX < 0) minX = 0;
int minY = CWorld::GetSectorIndexY(dummy->GetPosition().y - colRadius); int minY = CWorld::GetSectorIndexY(dummy->GetPosition().y - radius);
if (minY < 0) minY = 0; if (minY < 0) minY = 0;
int maxX = CWorld::GetSectorIndexX(dummy->GetPosition().x + colRadius); int maxX = CWorld::GetSectorIndexX(dummy->GetPosition().x + radius);
#ifdef FIX_BUGS #ifdef FIX_BUGS
if (maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X - 1; if (maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X - 1;
#else #else
if (maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X; if (maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X;
#endif #endif
int maxY = CWorld::GetSectorIndexY(dummy->GetPosition().y + colRadius); int maxY = CWorld::GetSectorIndexY(dummy->GetPosition().y + radius);
#ifdef FIX_BUGS #ifdef FIX_BUGS
if (maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y - 1; if (maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y - 1;
#else #else
if (maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y; if (maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y;
#endif #endif
float colRadius = dummy->GetBoundRadius();
CVUVECTOR colCentre;
dummy->GetBoundCentre(colCentre);
static CColPoint aTempColPoints[MAX_COLLISION_POINTS]; static CColPoint aTempColPoints[MAX_COLLISION_POINTS];
for (int curY = minY; curY <= maxY; curY++) { for (int curY = minY; curY <= maxY; curY++) {

View File

@ -513,8 +513,8 @@ bool CEntity::IsEntityOccluded(void) {
} }
if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) { if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) {
CVector min = m_matrix * CModelInfo::GetModelInfo(GetModelIndex())->GetColModel()->boundingBox.min; CVector min = m_matrix * CModelInfo::GetColModel(m_modelIndex)->boundingBox.min;
CVector max = m_matrix * CModelInfo::GetModelInfo(GetModelIndex())->GetColModel()->boundingBox.max; CVector max = m_matrix * CModelInfo::GetColModel(m_modelIndex)->boundingBox.max;
if (CalcScreenCoors(min, &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; if (CalcScreenCoors(min, &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue;
if (CalcScreenCoors(CVector(max.x, max.y, min.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; if (CalcScreenCoors(CVector(max.x, max.y, min.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue;

View File

@ -1406,7 +1406,7 @@ CShadows::CastShadowSectorList(CPtrList &PtrList, float fStartX, float fStartY,
{ {
pEntity->m_scanCode = CWorld::GetCurrentScanCode(); pEntity->m_scanCode = CWorld::GetCurrentScanCode();
if ( pEntity->bUsesCollision && !pEntity->m_flagE2 ) if ( pEntity->bUsesCollision && !pEntity->bDontCastShadowsOn)
{ {
if ( IsAreaVisible(pEntity->m_area) ) if ( IsAreaVisible(pEntity->m_area) )
{ {

View File

@ -127,7 +127,6 @@ public:
int32 offset, int32 len); int32 offset, int32 len);
static int32 ms_framePluginOffset; static int32 ms_framePluginOffset;
// Not actually used
struct ClumpExt struct ClumpExt
{ {
ClumpVisibilityCB visibilityCB; ClumpVisibilityCB visibilityCB;