summaryrefslogtreecommitdiffstats
path: root/src/rw/VisibilityPlugins.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/rw/VisibilityPlugins.cpp87
1 files changed, 61 insertions, 26 deletions
diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp
index 3f10d12a..68775c72 100644
--- a/src/rw/VisibilityPlugins.cpp
+++ b/src/rw/VisibilityPlugins.cpp
@@ -10,6 +10,7 @@
#include "VisibilityPlugins.h"
#include "World.h"
#include "custompipes.h"
+#include "MemoryHeap.h"
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaList;
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaEntityList;
@@ -30,6 +31,41 @@ float CVisibilityPlugins::ms_pedLod0Dist;
float CVisibilityPlugins::ms_pedLod1Dist;
float CVisibilityPlugins::ms_pedFadeDist;
+#ifdef GTA_PS2
+void
+rpDefaultGeometryInstance(RpGeometry *geo, void *atomic, int unk)
+{
+ // TODO
+ // this function seems to delete the original geometry data
+ // and only keep the instanced data
+ AtomicDefaultRenderCallBack((RpAtomic*)atomic);
+}
+
+RpAtomic*
+PreInstanceRenderCB(RpAtomic *atomic)
+{
+ RpGeometry *geo = RpAtomicGetGeometry(atomic);
+ if(RpGeometryGetTriangles(geo)){
+ PUSH_MEMID(MEMID_STREAM_MODELS);
+ rpDefaultGeometryInstance(geo, atomic, 1);
+ POP_MEMID();
+ }else
+ AtomicDefaultRenderCallBack(atomic);
+ return atomic;
+}
+#define RENDERCALLBACK PreInstanceRenderCB
+#else
+RpAtomic*
+DefaultRenderCB_pushid(RpAtomic *atomic)
+{
+ PUSH_MEMID(MEMID_STREAM_MODELS);
+ AtomicDefaultRenderCallBack(atomic);
+ POP_MEMID();
+ return atomic;
+}
+#define RENDERCALLBACK DefaultRenderCB_pushid
+#endif
+
void
CVisibilityPlugins::Initialise(void)
{
@@ -132,7 +168,7 @@ CVisibilityPlugins::RenderAlphaAtomics(void)
for(node = m_alphaList.tail.prev;
node != &m_alphaList.head;
node = node->prev)
- AtomicDefaultRenderCallBack(node->item.atomic);
+ RENDERCALLBACK(node->item.atomic);
}
void
@@ -201,7 +237,7 @@ CVisibilityPlugins::RenderWheelAtomicCB(RpAtomic *atomic)
if(lodatm){
if(RpAtomicGetGeometry(lodatm) != RpAtomicGetGeometry(atomic))
RpAtomicSetGeometry(atomic, RpAtomicGetGeometry(lodatm), rpATOMICSAMEBOUNDINGSPHERE);
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
return atomic;
}
@@ -218,7 +254,7 @@ CVisibilityPlugins::RenderObjNormalAtomic(RpAtomic *atomic)
len = RwV3dLength(&view);
if(RwV3dDotProduct(&view, RwMatrixGetUp(m)) < -0.3f*len && len > 8.0f)
return atomic;
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
return atomic;
}
@@ -232,7 +268,7 @@ CVisibilityPlugins::RenderAlphaAtomic(RpAtomic *atomic, int alpha)
flags = RpGeometryGetFlags(geo);
RpGeometrySetFlags(geo, flags | rpGEOMETRYMODULATEMATERIALCOLOR);
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha);
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255);
RpGeometrySetFlags(geo, flags);
return atomic;
@@ -250,7 +286,7 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist)
lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE);
if(mi->m_additive){
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
}else{
fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE;
@@ -258,7 +294,7 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist)
fadefactor = 1.0f;
alpha = mi->m_alpha * fadefactor;
if(alpha == 255)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
else{
RpGeometry *geo = RpAtomicGetGeometry(lodatm);
uint32 flags = RpGeometryGetFlags(geo);
@@ -266,7 +302,7 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist)
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha);
if(geo != RpAtomicGetGeometry(atomic))
RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255);
RpGeometrySetFlags(geo, flags);
}
@@ -293,7 +329,7 @@ CVisibilityPlugins::RenderVehicleHiDetailCB(RpAtomic *atomic)
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot))
return atomic;
}
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
return atomic;
}
@@ -318,10 +354,10 @@ CVisibilityPlugins::RenderVehicleHiDetailAlphaCB(RpAtomic *atomic)
if(flags & ATOMIC_FLAG_DRAWLAST){
// sort before clump
if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f))
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}else{
if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
}
return atomic;
@@ -344,7 +380,7 @@ CVisibilityPlugins::RenderVehicleHiDetailCB_BigVehicle(RpAtomic *atomic)
if(dot > 0.0f)
return atomic;
}
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
return atomic;
}
@@ -367,7 +403,7 @@ CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic)
return atomic;
if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
return atomic;
}
@@ -381,7 +417,7 @@ CVisibilityPlugins::RenderVehicleHiDetailCB_Boat(RpAtomic *atomic)
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
distsq = GetDistanceSquaredFromCamera(clumpframe);
if(distsq < ms_bigVehicleLod1Dist)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
return atomic;
}
@@ -403,7 +439,7 @@ CVisibilityPlugins::RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic)
if(dot > 0.0f)
return atomic;
}
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
return atomic;
}
@@ -427,7 +463,7 @@ CVisibilityPlugins::RenderVehicleLowDetailAlphaCB_BigVehicle(RpAtomic *atomic)
return atomic;
if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
return atomic;
}
@@ -444,7 +480,7 @@ CVisibilityPlugins::RenderVehicleReallyLowDetailCB(RpAtomic *atomic)
if(dist >= ms_vehicleLod0Dist){
alpha = GetClumpAlpha(clump);
if(alpha == 255)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
else
RenderAlphaAtomic(atomic, alpha);
}
@@ -461,7 +497,7 @@ CVisibilityPlugins::RenderVehicleReallyLowDetailCB_BigVehicle(RpAtomic *atomic)
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
distsq = GetDistanceSquaredFromCamera(clumpframe);
if(distsq >= ms_bigVehicleLod1Dist)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
return atomic;
}
@@ -482,7 +518,7 @@ CVisibilityPlugins::RenderTrainHiDetailCB(RpAtomic *atomic)
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot))
return atomic;
}
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
return atomic;
}
@@ -507,10 +543,10 @@ CVisibilityPlugins::RenderTrainHiDetailAlphaCB(RpAtomic *atomic)
if(flags & ATOMIC_FLAG_DRAWLAST){
// sort before clump
if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f))
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}else{
if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
}
}
return atomic;
@@ -521,7 +557,7 @@ CVisibilityPlugins::RenderPlayerCB(RpAtomic *atomic)
{
if(CWorld::Players[0].m_pSkinTexture)
RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), SetTextureCB, CWorld::Players[0].m_pSkinTexture);
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
return atomic;
}
@@ -537,7 +573,7 @@ CVisibilityPlugins::RenderPedLowDetailCB(RpAtomic *atomic)
if(dist >= ms_pedLod0Dist){
alpha = GetClumpAlpha(clump);
if(alpha == 255)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
else
RenderAlphaAtomic(atomic, alpha);
}
@@ -556,7 +592,7 @@ CVisibilityPlugins::RenderPedHiDetailCB(RpAtomic *atomic)
if(dist < ms_pedLod0Dist){
alpha = GetClumpAlpha(clump);
if(alpha == 255)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
else
RenderAlphaAtomic(atomic, alpha);
}
@@ -575,7 +611,7 @@ CVisibilityPlugins::RenderPedCB(RpAtomic *atomic)
if(RwV3dDotProduct(&cam2atm, &cam2atm) < ms_pedLod1Dist){
alpha = GetClumpAlpha(RpAtomicGetClump(atomic));
if(alpha == 255)
- AtomicDefaultRenderCallBack(atomic);
+ RENDERCALLBACK(atomic);
else
RenderAlphaAtomic(atomic, alpha);
}
@@ -775,12 +811,11 @@ CVisibilityPlugins::GetAtomicId(RpAtomic *atomic)
return ATOMICEXT(atomic)->flags;
}
-// This is rather useless, but whatever
void
CVisibilityPlugins::SetAtomicRenderCallback(RpAtomic *atomic, RpAtomicCallBackRender cb)
{
if(cb == nil)
- cb = AtomicDefaultRenderCallBack; // not necessary
+ cb = RENDERCALLBACK;
RpAtomicSetRenderCallBack(atomic, cb);
}