summaryrefslogtreecommitdiffstats
path: root/src/entities/Entity.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/entities/Entity.cpp130
1 files changed, 102 insertions, 28 deletions
diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp
index 988649ef..d106898d 100644
--- a/src/entities/Entity.cpp
+++ b/src/entities/Entity.cpp
@@ -26,6 +26,12 @@
#include "Ped.h"
#include "Dummy.h"
#include "WindModifiers.h"
+#include "SpecialFX.h"
+#include "VisibilityPlugins.h"
+#include "RpAnimBlend.h"
+#include "CutsceneMgr.h"
+
+//--LCS: file done except TODO for distance alpha
int gBuildings;
@@ -71,13 +77,18 @@ CEntity::CEntity(void)
bDistanceFade = false;
m_flagE1 = false;
- m_flagE2 = false;
+ bDontCastShadowsOn = false;
bOffscreen = false;
bIsStaticWaitingForCollision = false;
bDontStream = false;
bUnderwater = false;
bHasPreRenderEffects = false;
+ bIsTreeModel = false;
+ m_flagG2 = false;
+ m_flagG4 = false;
+ m_flagG8 = false;
+
m_scanCode = 0;
m_modelIndex = -1;
m_rwObject = nil;
@@ -96,6 +107,8 @@ void
CEntity::SetModelIndex(uint32 id)
{
m_modelIndex = id;
+ bIsTreeModel = IsTreeModel(m_modelIndex);
+ bDrawLast |= bIsTreeModel;
bHasPreRenderEffects = HasPreRenderEffects();
CreateRwObject();
}
@@ -104,6 +117,8 @@ void
CEntity::SetModelIndexNoCreate(uint32 id)
{
m_modelIndex = id;
+ bIsTreeModel = IsTreeModel(m_modelIndex);
+ bDrawLast |= bIsTreeModel;
bHasPreRenderEffects = HasPreRenderEffects();
}
@@ -126,6 +141,7 @@ CEntity::CreateRwObject(void)
else if(RwObjectGetType(m_rwObject) == rpCLUMP)
GetMatrix().AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump *)m_rwObject)), false);
+ // useless IsTextureLoaded();
mi->AddRef();
}
}
@@ -182,9 +198,11 @@ CEntity::DeleteRwObject(void)
if(m_rwObject){
if(RwObjectGetType(m_rwObject) == rpATOMIC){
f = RpAtomicGetFrame((RpAtomic*)m_rwObject);
+ CStreaming::UnregisterInstance((RpAtomic*)m_rwObject, nil);
RpAtomicDestroy((RpAtomic*)m_rwObject);
RwFrameDestroy(f);
}else if(RwObjectGetType(m_rwObject) == rpCLUMP){
+ CStreaming::UnregisterInstance((RpClump*)m_rwObject);
if(IsClumpSkinned((RpClump*)m_rwObject))
RpClumpForAllAtomics((RpClump*)m_rwObject, AtomicRemoveAnimFromSkinCB, nil);
RpClumpDestroy((RpClump*)m_rwObject);
@@ -201,7 +219,7 @@ CEntity::GetBoundRect(void)
{
CRect rect;
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.max);
@@ -220,21 +238,27 @@ CEntity::GetBoundRect(void)
CVector
CEntity::GetBoundCentre(void)
{
- CVector v;
- GetBoundCentre(v);
- return v;
+ return GetMatrix() * CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center;
}
+#ifdef GTA_PS2
+void
+CEntity::GetBoundCentre(CVuVector &out)
+{
+ TransformPoint(out, GetMatrix(), CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center);
+}
+#else
void
CEntity::GetBoundCentre(CVector &out)
{
- out = GetMatrix() * CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.center;
+ out = GetMatrix() * CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center;
}
+#endif
float
CEntity::GetBoundRadius(void)
{
- return CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.radius;
+ return CModelInfo::GetColModel(m_modelIndex)->boundingSphere.radius;
}
void
@@ -244,9 +268,18 @@ CEntity::UpdateRwFrame(void)
RwFrameUpdateObjects((RwFrame*)rwObjectGetParent(m_rwObject));
}
+bool
+PauseEntityAnims(void)
+{
+ return CSpecialFX::bSnapShotActive;
+}
+
void
CEntity::UpdateRpHAnim(void)
{
+ if(PauseEntityAnims())
+ return;
+
if(IsClumpSkinned(GetClump())){
RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump());
RpHAnimHierarchyUpdateMatrices(hier);
@@ -308,9 +341,10 @@ CEntity::PreRender(void)
if(!bHasPreRenderEffects)
return;
+ // separate function in LCS but we don't know the name
switch(m_type){
case ENTITY_TYPE_BUILDING:
- if(IsTreeModel(GetModelIndex())){
+ if(bIsTreeModel){
float dist = (TheCamera.GetPosition() - GetPosition()).Magnitude2D();
CObject::fDistToNearestTree = Min(CObject::fDistToNearestTree, dist);
ModifyMatrixForTreeInWind();
@@ -373,7 +407,7 @@ CEntity::PreRender(void)
CVector pos = GetPosition();
CShadows::StoreShadowToBeRendered(SHADOWTYPE_DARK,
gpShadowPedTex, &pos,
- 0.4f, 0.0f, 0.0f, -0.4f,
+ 0.4f, 0.0f, 0.0f, 0.4f,
CTimeCycle::GetShadowStrength(),
CTimeCycle::GetShadowStrength(),
CTimeCycle::GetShadowStrength(),
@@ -409,19 +443,65 @@ void
CEntity::Render(void)
{
if(m_rwObject){
- bImBeingRendered = true;
- if(RwObjectGetType(m_rwObject) == rpATOMIC)
- RpAtomicRender((RpAtomic*)m_rwObject);
- else
- RpClumpRender((RpClump*)m_rwObject);
- bImBeingRendered = false;
+ if(CVisibilityPlugins::GetObjectDistanceAlpha(m_rwObject) != 0){
+ // NB: LCS does not use bImBeingRendered here,
+ // but that may be due to the streamed world. better keep it for safety
+ bImBeingRendered = true;
+ if(RwObjectGetType(m_rwObject) == rpATOMIC)
+ RpAtomicRender((RpAtomic*)m_rwObject);
+ else
+ RpClumpRender((RpClump*)m_rwObject);
+ bImBeingRendered = false;
+ }
}
}
+void
+CEntity::UpdateDistanceFade(void)
+{
+// TODO(LCS):
+// increasing and decreasing alpha depending on bDistanceFade doesn't make any sense
+// so disable this whole thing until it does.
+return;
+ int alpha = CVisibilityPlugins::GetObjectDistanceAlpha(m_rwObject);
+ if(CCutsceneMgr::IsRunning() || TheCamera.WorldViewerBeingUsed)
+ alpha = 255;
+ else if(bDistanceFade)
+ alpha = Max(alpha-16, 0);
+ else if(alpha < 255)
+ alpha = Min(alpha+32, 255);
+ CVisibilityPlugins::SetObjectDistanceAlpha(m_rwObject, alpha);
+}
+
+void
+CEntity::UpdateAnim(void)
+{
+ if(PauseEntityAnims())
+ return;
+
+ if(m_rwObject && RwObjectGetType(m_rwObject) == rpCLUMP && RpAnimBlendClumpGetFirstAssociation(GetClump())) {
+ if (IsObject())
+ RpAnimBlendClumpUpdateAnimations(GetClump(), CTimer::GetTimeStepNonClippedInSeconds());
+ else {
+ if (!bOffscreen)
+ bOffscreen = !GetIsOnScreen();
+ RpAnimBlendClumpUpdateAnimations(GetClump(), CTimer::GetTimeStepInSeconds(), !bOffscreen);
+ }
+ }
+}
+
+bool
+CEntity::GetIsTouching(CVUVECTOR const &center, float radius)
+{
+ CVUVECTOR boundCenter;
+ GetBoundCentre(boundCenter);
+ return sq(GetBoundRadius()+radius) > (boundCenter-center).MagnitudeSqr();
+}
+
bool
-CEntity::GetIsTouching(CVector const &center, float radius)
+CEntity::GetIsTouching(CEntity *other)
{
- return sq(GetBoundRadius()+radius) > (GetBoundCentre()-center).MagnitudeSqr();
+ return sq(GetBoundRadius()+other->GetBoundRadius()) > (GetBoundCentre()-other->GetBoundCentre()).MagnitudeSqr();
}
bool
@@ -439,8 +519,7 @@ CEntity::IsVisibleComplex(void)
bool
CEntity::GetIsOnScreen(void)
{
- return TheCamera.IsSphereVisible(GetBoundCentre(), GetBoundRadius(),
- &TheCamera.GetCameraMatrix());
+ return TheCamera.IsSphereVisible(GetBoundCentre(), GetBoundRadius());
}
bool
@@ -456,7 +535,7 @@ CEntity::GetIsOnScreenComplex(void)
return true;
CRect rect = GetBoundRect();
- CColModel *colmodel = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel();
+ CColModel *colmodel = CModelInfo::GetColModel(m_modelIndex);
float z = GetPosition().z;
float minz = z + colmodel->boundingBox.min.z;
float maxz = z + colmodel->boundingBox.max.z;
@@ -611,7 +690,7 @@ CEntity::Remove(void)
float
CEntity::GetDistanceFromCentreOfMassToBaseOfModel(void)
{
- return -CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingBox.min.z;
+ return -CModelInfo::GetColModel(m_modelIndex)->boundingBox.min.z;
}
void
@@ -737,11 +816,6 @@ CEntity::PreRenderForGlassWindow(void)
bIsVisible = false;
}
-/*
-0x487A10 - SetAtomicAlphaCB
-0x4879E0 - SetClumpAlphaCB
-*/
-
RpMaterial*
SetAtomicAlphaCB(RpMaterial *material, void *data)
{
@@ -840,7 +914,7 @@ CEntity::SaveEntityFlags(uint8*& buf)
if (bDistanceFade) tmp |= BIT(7);
if (m_flagE1) tmp |= BIT(8);
- if (m_flagE2) tmp |= BIT(9);
+ if (bDontCastShadowsOn) tmp |= BIT(9);
if (bOffscreen) tmp |= BIT(10);
if (bIsStaticWaitingForCollision) tmp |= BIT(11);
if (bDontStream) tmp |= BIT(12);
@@ -896,7 +970,7 @@ CEntity::LoadEntityFlags(uint8*& buf)
bDistanceFade = !!(tmp & BIT(7));
m_flagE1 = !!(tmp & BIT(8));
- m_flagE2 = !!(tmp & BIT(9));
+ bDontCastShadowsOn = !!(tmp & BIT(9));
bOffscreen = !!(tmp & BIT(10));
bIsStaticWaitingForCollision = !!(tmp & BIT(11));
bDontStream = !!(tmp & BIT(12));