1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-18 05:37:46 +00:00
re3/src/modelinfo/SimpleModelInfo.cpp

190 lines
3.9 KiB
C++
Raw Normal View History

2019-05-15 14:52:37 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
#include "General.h"
2019-05-15 14:52:37 +00:00
#include "Camera.h"
#include "ModelInfo.h"
2020-05-10 09:34:26 +00:00
#include "AnimManager.h"
//--MIAMI: file done
2019-05-15 14:52:37 +00:00
#define LOD_DISTANCE (300.0f)
void
CSimpleModelInfo::DeleteRwObject(void)
{
int i;
RwFrame *f;
for(i = 0; i < m_numAtomics; i++)
if(m_atomics[i]){
f = RpAtomicGetFrame(m_atomics[i]);
RpAtomicDestroy(m_atomics[i]);
RwFrameDestroy(f);
m_atomics[i] = nil;
RemoveTexDictionaryRef();
2020-05-10 09:34:26 +00:00
if(GetAnimFileIndex() != -1)
CAnimManager::RemoveAnimBlockRef(GetAnimFileIndex());
2019-05-15 14:52:37 +00:00
}
}
RwObject*
CSimpleModelInfo::CreateInstance(void)
{
RpAtomic *atomic;
if(m_atomics[0] == nil)
return nil;
atomic = RpAtomicClone(m_atomics[0]);
RpAtomicSetFrame(atomic, RwFrameCreate());
return (RwObject*)atomic;
}
RwObject*
CSimpleModelInfo::CreateInstance(RwMatrix *matrix)
{
RpAtomic *atomic;
RwFrame *frame;
if(m_atomics[0] == nil)
return nil;
atomic = RpAtomicClone(m_atomics[0]);
frame = RwFrameCreate();
*RwFrameGetMatrix(frame) = *matrix;
RpAtomicSetFrame(atomic, frame);
return (RwObject*)atomic;
}
void
CSimpleModelInfo::Init(void)
{
m_atomics[0] = nil;
m_atomics[1] = nil;
m_atomics[2] = nil;
m_numAtomics = 0;
2019-06-17 08:30:02 +00:00
m_firstDamaged = 0;
2020-05-05 21:27:43 +00:00
m_wetRoadReflection = 0;
2019-05-15 14:52:37 +00:00
m_isDamaged = 0;
m_isBigBuilding = 0;
m_noFade = 0;
m_drawLast = 0;
m_additive = 0;
m_isSubway = 0;
m_ignoreLight = 0;
m_noZwrite = 0;
2020-05-05 21:27:43 +00:00
m_noShadows = 0;
m_ignoreDrawDist = 0;
m_isCodeGlass = 0;
m_isArtistGlass = 0;
2019-05-15 14:52:37 +00:00
}
void
CSimpleModelInfo::SetAtomic(int n, RpAtomic *atomic)
{
AddTexDictionaryRef();
m_atomics[n] = atomic;
2020-05-10 09:34:26 +00:00
if(GetAnimFileIndex() != -1)
CAnimManager::AddAnimBlockRef(GetAnimFileIndex());
RpGeometry *geo = RpAtomicGetGeometry(atomic);
if(m_ignoreLight)
2019-05-15 14:52:37 +00:00
RpGeometrySetFlags(geo, RpGeometryGetFlags(geo) & ~rpGEOMETRYLIGHT);
2020-05-10 09:34:26 +00:00
if(RpGeometryGetFlags(geo) & rpGEOMETRYNORMALS &&
RpGeometryGetNumTriangles(geo) > 200)
debug("%s has %d polys\n", m_name, RpGeometryGetNumTriangles(geo));
2019-05-15 14:52:37 +00:00
}
void
CSimpleModelInfo::SetLodDistances(float *dist)
{
m_lodDistances[0] = dist[0];
m_lodDistances[1] = dist[1];
m_lodDistances[2] = dist[2];
}
void
CSimpleModelInfo::IncreaseAlpha(void)
{
if(m_alpha >= 0xEF)
m_alpha = 0xFF;
else
m_alpha += 0x10;
}
float
CSimpleModelInfo::GetLodDistance(int i)
{
return m_lodDistances[i] * TheCamera.LODDistMultiplier;
}
2019-05-15 14:52:37 +00:00
float
CSimpleModelInfo::GetNearDistance(void)
{
return m_lodDistances[2] * TheCamera.LODDistMultiplier;
}
float
CSimpleModelInfo::GetLargestLodDistance(void)
{
float d;
2019-06-17 08:30:02 +00:00
if(m_firstDamaged == 0 || m_isDamaged)
2019-05-15 14:52:37 +00:00
d = m_lodDistances[m_numAtomics-1];
2019-06-17 08:30:02 +00:00
else
d = m_lodDistances[m_firstDamaged-1];
2019-05-15 14:52:37 +00:00
return d * TheCamera.LODDistMultiplier;
}
RpAtomic*
CSimpleModelInfo::GetAtomicFromDistance(float dist)
{
int i;
i = 0;
if(m_isDamaged)
2019-06-17 08:30:02 +00:00
i = m_firstDamaged;
2019-05-15 14:52:37 +00:00
for(; i < m_numAtomics; i++)
if(dist < m_lodDistances[i] * TheCamera.LODDistMultiplier)
2019-05-15 14:52:37 +00:00
return m_atomics[i];
return nil;
}
RpAtomic*
CSimpleModelInfo::GetFirstAtomicFromDistance(float dist)
{
if(dist < m_lodDistances[0] * TheCamera.LODDistMultiplier)
return m_atomics[0];
return nil;
}
2019-05-15 14:52:37 +00:00
void
2020-05-10 09:34:26 +00:00
CSimpleModelInfo::FindRelatedModel(int32 minID, int32 maxID)
2019-05-15 14:52:37 +00:00
{
int i;
CBaseModelInfo *mi;
2020-05-10 09:34:26 +00:00
for(i = minID; i <= maxID; i++){
2019-05-15 14:52:37 +00:00
mi = CModelInfo::GetModelInfo(i);
if(mi && mi != this &&
!CGeneral::faststrcmp(GetName()+3, mi->GetName()+3)){
2019-05-15 14:52:37 +00:00
assert(mi->IsSimple());
this->SetRelatedModel((CSimpleModelInfo*)mi);
return;
}
}
}
2020-05-05 21:27:43 +00:00
#define NEAR_DRAW_DIST 0.0f // 100.0f in liberty city
2019-05-15 14:52:37 +00:00
void
2020-05-10 09:34:26 +00:00
CSimpleModelInfo::SetupBigBuilding(int32 minID, int32 maxID)
2019-05-15 14:52:37 +00:00
{
CSimpleModelInfo *related;
2020-05-10 09:34:26 +00:00
if(m_lodDistances[0] > LOD_DISTANCE && GetRelatedModel() == nil){
2019-05-15 14:52:37 +00:00
m_isBigBuilding = 1;
2020-05-10 09:34:26 +00:00
FindRelatedModel(minID, maxID);
2019-05-15 14:52:37 +00:00
related = GetRelatedModel();
2020-05-05 21:27:43 +00:00
if(related){
2019-05-15 14:52:37 +00:00
m_lodDistances[2] = related->GetLargestLodDistance()/TheCamera.LODDistMultiplier;
2020-05-05 21:27:43 +00:00
if(m_drawLast){
m_drawLast = false;
debug("%s was draw last\n", GetName());
}
}else
m_lodDistances[2] = NEAR_DRAW_DIST;
2019-05-15 14:52:37 +00:00
}
}