diff options
Diffstat (limited to '')
-rw-r--r-- | src/rw/Lights.cpp | 7 | ||||
-rw-r--r-- | src/rw/RwHelper.cpp | 3 | ||||
-rw-r--r-- | src/rw/TexRead.cpp | 12 | ||||
-rw-r--r-- | src/rw/TxdStore.cpp | 93 | ||||
-rw-r--r-- | src/rw/TxdStore.h | 11 | ||||
-rw-r--r-- | src/rw/VisibilityPlugins.cpp | 250 | ||||
-rw-r--r-- | src/rw/VisibilityPlugins.h | 35 |
7 files changed, 325 insertions, 86 deletions
diff --git a/src/rw/Lights.cpp b/src/rw/Lights.cpp index 772e1961..5f8ba823 100644 --- a/src/rw/Lights.cpp +++ b/src/rw/Lights.cpp @@ -24,12 +24,7 @@ RwRGBAReal DirectionalLightColourForFrame; RwRGBAReal AmbientLightColour; RwRGBAReal DirectionalLightColour; -#ifdef EXTENDED_COLOURFILTER -#include "postfx.h" -#define USEBLURCOLORS CPostFX::UseBlurColours() -#else -#define USEBLURCOLORS CMBlur::BlurOn -#endif +#define USEBLURCOLORS true // actually CMBlur::BlurOn, but that's always supposed to be on void SetLightsWithTimeOfDayColour(RpWorld *) diff --git a/src/rw/RwHelper.cpp b/src/rw/RwHelper.cpp index 25cd2eef..8ad57fa1 100644 --- a/src/rw/RwHelper.cpp +++ b/src/rw/RwHelper.cpp @@ -19,7 +19,7 @@ bool gPS2alphaTest = true; #else bool gPS2alphaTest = false; #endif -bool gBackfaceCulling = true; +bool gBackfaceCulling = false; // can we ever enable this in LCS even? #if !defined(FINAL) || defined(DEBUGMENU) static bool charsetOpen; @@ -96,6 +96,7 @@ DefinedState(void) #endif } +//LCS: remove this void SetCullMode(uint32 mode) { diff --git a/src/rw/TexRead.cpp b/src/rw/TexRead.cpp index 1f96180b..ddb178e2 100644 --- a/src/rw/TexRead.cpp +++ b/src/rw/TexRead.cpp @@ -321,11 +321,7 @@ ConvertingTexturesScreen(uint32 num, uint32 count, const char *text) splash->Draw(CRect(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT), CRGBA(255, 255, 255, 255)); CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(200.0f), SCREEN_SCALE_Y(240.0f), SCREEN_SCALE_FROM_RIGHT(200.0f), SCREEN_SCALE_Y(248.0f)), CRGBA(64, 64, 64, 255)); -#ifdef FIX_BUGS - CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(200.0f), SCREEN_SCALE_Y(240.0f), (SCREEN_SCALE_FROM_RIGHT(200.0f) - SCREEN_SCALE_X(200.0f)) * ((float)num / (float)count) + SCREEN_SCALE_X(200.0f), SCREEN_SCALE_Y(248.0f)), CRGBA(255, 150, 225, 255)); -#else - CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(200.0f), SCREEN_SCALE_Y(240.0f), (SCREEN_SCALE_FROM_RIGHT(200.0f) - SCREEN_SCALE_X(200.0f)) * ((float)num / (float)count) + SCREEN_SCALE_X(200.0f), SCREEN_SCALE_Y(248.0f)), CRGBA(255, 217, 106, 255)); -#endif + CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(200.0f), SCREEN_SCALE_Y(240.0f), (SCREEN_SCALE_FROM_RIGHT(200.0f) - SCREEN_SCALE_X(200.0f)) * ((float)num / (float)count) + SCREEN_SCALE_X(200.0f), SCREEN_SCALE_Y(248.0f)), CRGBA(97, 194, 247, 255)); CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(120.0f), SCREEN_SCALE_Y(150.0f), SCREEN_SCALE_FROM_RIGHT(120.0f), SCREEN_HEIGHT - SCREEN_SCALE_Y(220.0f)), CRGBA(50, 50, 50, 210)); CFont::SetBackgroundOff(); @@ -334,11 +330,7 @@ ConvertingTexturesScreen(uint32 num, uint32 count, const char *text) CFont::SetCentreOff(); CFont::SetWrapx(SCREEN_SCALE_FROM_RIGHT(170.0f)); CFont::SetJustifyOff(); -#ifdef FIX_BUGS - CFont::SetColor(CRGBA(255, 150, 225, 255)); -#else - CFont::SetColor(CRGBA(255, 217, 106, 255)); -#endif + CFont::SetColor(CRGBA(115, 173, 216, 255)); CFont::SetBackGroundOnlyTextOff(); CFont::SetFontStyle(FONT_STANDARD); CFont::PrintString(SCREEN_SCALE_X(170.0f), SCREEN_SCALE_Y(160.0f), TheText.Get(text)); diff --git a/src/rw/TxdStore.cpp b/src/rw/TxdStore.cpp index 0bd29718..b7936bcf 100644 --- a/src/rw/TxdStore.cpp +++ b/src/rw/TxdStore.cpp @@ -1,5 +1,7 @@ #include "common.h" +#include "main.h" +#include "smallHeap.h" #include "templates.h" #include "General.h" #include "Streaming.h" @@ -9,13 +11,19 @@ CPool<TxdDef,TxdDef> *CTxdStore::ms_pTxdPool; RwTexDictionary *CTxdStore::ms_pStoredTxd; +// LCS: file done except unused: +// CTexListStore::RemoveTexListChunk(int) +// CTexListStore::validateRefs(void) +// CTexListStore::Write(base::cRelocatableChunkWriter &) + void CTxdStore::Initialise(void) { - if(ms_pTxdPool == nil) + if(gMakeResources && ms_pTxdPool == nil) ms_pTxdPool = new CPool<TxdDef,TxdDef>(TXDSTORESIZE, "TexDictionary"); } +// removed in LCS but we should probably keep it void CTxdStore::Shutdown(void) { @@ -23,6 +31,7 @@ CTxdStore::Shutdown(void) delete ms_pTxdPool; } +// removed in LCS but we should probably keep it void CTxdStore::GameShutdown(void) { @@ -42,6 +51,7 @@ CTxdStore::AddTxdSlot(const char *name) assert(def); def->texDict = nil; def->refCount = 0; + def->refCountGu = 0; strcpy(def->name, name); return ms_pTxdPool->GetJustIndex(def); } @@ -95,7 +105,11 @@ CTxdStore::SetCurrentTxd(int slot) void CTxdStore::Create(int slot) { - GetSlot(slot)->texDict = RwTexDictionaryCreate(); + TxdDef *def = GetSlot(slot); + def->texDict = RwTexDictionaryCreate(); + // LCS: mobile sets the txd name here, but txds don't really have names + def->refCount = 0; + def->refCountGu = 0; } int @@ -111,6 +125,20 @@ CTxdStore::AddRef(int slot) } void +CTxdStore::AddRefEvenIfNotInMemory(int slot) +{ + GetSlot(slot)->refCount++; +} + +void +CTxdStore::AddRefGu(int slot) +{ + TxdDef *def = GetSlot(slot); + def->refCount++; + def->refCountGu++; +} + +void CTxdStore::RemoveRef(int slot) { if(--GetSlot(slot)->refCount <= 0) @@ -118,6 +146,15 @@ CTxdStore::RemoveRef(int slot) } void +CTxdStore::RemoveRefGu(int slot) +{ + TxdDef *def = GetSlot(slot); + def->refCount--; + if(gUseChunkFiles) + def->refCountGu--; +} + +void CTxdStore::RemoveRefWithoutDelete(int slot) { GetSlot(slot)->refCount--; @@ -128,15 +165,32 @@ CTxdStore::LoadTxd(int slot, RwStream *stream) { TxdDef *def = GetSlot(slot); - if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){ - def->texDict = RwTexDictionaryGtaStreamRead(stream); - return def->texDict != nil; + if(stream){ + if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){ + def->texDict = RwTexDictionaryGtaStreamRead(stream); + return def->texDict != nil; + } + }else{ + // TODO(LCS)? fall back reading from file } printf("Failed to load TXD\n"); return false; } bool +CTxdStore::LoadTxd(int slot, void *data, void *chunk) +{ + TxdDef *def = GetSlot(slot); + def->texDict = (RwTexDictionary*)data; + if(strncasecmp(def->name, "radar", 5) == 0){ + def->refCount = 0; + def->refCountGu = 0; + } + CStreaming::RegisterPointer(&def->texDict, 3, true); + return def->texDict != nil; +} + +bool CTxdStore::LoadTxd(int slot, const char *filename) { RwStream *stream; @@ -152,6 +206,7 @@ CTxdStore::LoadTxd(int slot, const char *filename) return ret; } +// removed in LCS but we should probably keep it bool CTxdStore::StartLoadTxd(int slot, RwStream *stream) { @@ -165,6 +220,7 @@ CTxdStore::StartLoadTxd(int slot, RwStream *stream) } } +// removed in LCS but we should probably keep it bool CTxdStore::FinishLoadTxd(int slot, RwStream *stream) { @@ -174,10 +230,31 @@ CTxdStore::FinishLoadTxd(int slot, RwStream *stream) } void -CTxdStore::RemoveTxd(int slot) +CTxdStore::RemoveTxd(int slot, bool notChunk) { TxdDef *def = GetSlot(slot); - if(def->texDict) - RwTexDictionaryDestroy(def->texDict); + if(def->texDict){ + if(!gUseChunkFiles || notChunk) + RwTexDictionaryDestroy(def->texDict); + else{ + // TODO? Rsl3D specific: RslTextureDestroyDispList for all textures + CStreaming::UnregisterPointer(&def->texDict, 3); + cSmallHeap::msInstance.Free(def->texDict); + } + } def->texDict = nil; + def->refCount = 0; + def->refCountGu = 0; +} + +void +CTxdStore::Load(RwTexDictionary *stored, CPool<TxdDef> *pool) +{ + ms_pTxdPool = pool; + ms_pStoredTxd = stored; + for(int i = 0; i < TXDSTORESIZE; i++){ + TxdDef *def = GetSlot(i); + if(def) + def->refCount = def->texDict != nil; + } } diff --git a/src/rw/TxdStore.h b/src/rw/TxdStore.h index 937fd1b7..31fcf87f 100644 --- a/src/rw/TxdStore.h +++ b/src/rw/TxdStore.h @@ -4,7 +4,8 @@ struct TxdDef { RwTexDictionary *texDict; - int refCount; + int16 refCount; + int16 refCountGu; char name[20]; }; @@ -26,13 +27,19 @@ public: static void Create(int slot); static int GetNumRefs(int slot); static void AddRef(int slot); + static void AddRefEvenIfNotInMemory(int slot); + static void AddRefGu(int slot); static void RemoveRef(int slot); + static void RemoveRefGu(int slot); static void RemoveRefWithoutDelete(int slot); static bool LoadTxd(int slot, RwStream *stream); + static bool LoadTxd(int slot, void *data, void *chunk); static bool LoadTxd(int slot, const char *filename); static bool StartLoadTxd(int slot, RwStream *stream); static bool FinishLoadTxd(int slot, RwStream *stream); - static void RemoveTxd(int slot); + static void RemoveTxd(int slot, bool notChunk = false); + + static void Load(RwTexDictionary *stored, CPool<TxdDef> *pool); static TxdDef *GetSlot(int slot) { assert(slot >= 0); diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp index 01f2c8e7..c84c7d8b 100644 --- a/src/rw/VisibilityPlugins.cpp +++ b/src/rw/VisibilityPlugins.cpp @@ -14,10 +14,13 @@ #include "custompipes.h" #include "MemoryHeap.h" +//--LCS: file done +// LCS: no transparent water in LCS so no need for alpha boat and alpha underwater lists + CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaList; -CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaBoatAtomicList; +//CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaBoatAtomicList; CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaEntityList; -CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaUnderwaterEntityList; +//CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaUnderwaterEntityList; #ifdef NEW_RENDERER CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaBuildingList; #endif @@ -34,7 +37,7 @@ float CVisibilityPlugins::ms_vehicleLod1Dist; float CVisibilityPlugins::ms_vehicleFadeDist; float CVisibilityPlugins::ms_bigVehicleLod0Dist; float CVisibilityPlugins::ms_bigVehicleLod1Dist; -float CVisibilityPlugins::ms_pedLod1Dist; +float CVisibilityPlugins::ms_pedLodDist; float CVisibilityPlugins::ms_pedFadeDist; #define RENDERCALLBACK AtomicDefaultRenderCallBack @@ -46,9 +49,9 @@ CVisibilityPlugins::Initialise(void) m_alphaList.head.item.sort = 0.0f; m_alphaList.tail.item.sort = 100000000.0f; - m_alphaBoatAtomicList.Init(NUMBOATALPHALIST); - m_alphaBoatAtomicList.head.item.sort = 0.0f; - m_alphaBoatAtomicList.tail.item.sort = 100000000.0f; +// m_alphaBoatAtomicList.Init(NUMBOATALPHALIST); +// m_alphaBoatAtomicList.head.item.sort = 0.0f; +// m_alphaBoatAtomicList.tail.item.sort = 100000000.0f; #ifdef ASPECT_RATIO_SCALE // default 150 is not enough for bigger FOVs @@ -59,24 +62,44 @@ CVisibilityPlugins::Initialise(void) m_alphaEntityList.head.item.sort = 0.0f; m_alphaEntityList.tail.item.sort = 100000000.0f; - m_alphaUnderwaterEntityList.Init(NUMALPHAUNTERWATERENTITYLIST); - m_alphaUnderwaterEntityList.head.item.sort = 0.0f; - m_alphaUnderwaterEntityList.tail.item.sort = 100000000.0f; +// m_alphaUnderwaterEntityList.Init(NUMALPHAUNTERWATERENTITYLIST); +// m_alphaUnderwaterEntityList.head.item.sort = 0.0f; +// m_alphaUnderwaterEntityList.tail.item.sort = 100000000.0f; #ifdef NEW_RENDERER m_alphaBuildingList.Init(NUMALPHAENTITYLIST); m_alphaBuildingList.head.item.sort = 0.0f; m_alphaBuildingList.tail.item.sort = 100000000.0f; #endif + + base::RegisterRelocatableChunkFunc((void*)RENDERCALLBACK); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleReallyLowDetailCB); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleHiDetailCB); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleHiDetailAlphaCB); + base::RegisterRelocatableChunkFunc((void*)RenderTrainHiDetailCB); + base::RegisterRelocatableChunkFunc((void*)RenderTrainHiDetailAlphaCB); + base::RegisterRelocatableChunkFunc((void*)RenderWheelAtomicCB); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleRotorAlphaCB); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleTailRotorAlphaCB); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleReallyLowDetailCB_BigVehicle); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleLowDetailCB_BigVehicle); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleHiDetailCB_BigVehicle); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleLowDetailAlphaCB_BigVehicle); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleHiDetailAlphaCB_BigVehicle); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleHiDetailCB_Boat); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleLoDetailCB_Boat); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleHiDetailCB_Boat_Far); + base::RegisterRelocatableChunkFunc((void*)RenderVehicleLoDetailCB_Boat_Far); + base::RegisterRelocatableChunkFunc((void*)RenderPedCB); } void CVisibilityPlugins::Shutdown(void) { m_alphaList.Shutdown(); - m_alphaBoatAtomicList.Shutdown(); +// m_alphaBoatAtomicList.Shutdown(); m_alphaEntityList.Shutdown(); - m_alphaUnderwaterEntityList.Shutdown(); +// m_alphaUnderwaterEntityList.Shutdown(); #ifdef NEW_RENDERER m_alphaBuildingList.Shutdown(); #endif @@ -86,8 +109,8 @@ void CVisibilityPlugins::InitAlphaEntityList(void) { m_alphaEntityList.Clear(); - m_alphaBoatAtomicList.Clear(); - m_alphaUnderwaterEntityList.Clear(); +// m_alphaBoatAtomicList.Clear(); +// m_alphaUnderwaterEntityList.Clear(); #ifdef NEW_RENDERER m_alphaBuildingList.Clear(); #endif @@ -104,11 +127,11 @@ CVisibilityPlugins::InsertEntityIntoSortedList(CEntity *e, float dist) item.entity = e; item.sort = dist; #ifdef NEW_RENDERER - if(gbNewRenderer && e->IsBuilding()) + if(!gbPreviewCity && e->IsBuilding()) return !!m_alphaBuildingList.InsertSorted(item); #endif - if(e->bUnderwater && m_alphaUnderwaterEntityList.InsertSorted(item)) - return true; +// if(e->bUnderwater && m_alphaUnderwaterEntityList.InsertSorted(item)) +// return true; return !!m_alphaEntityList.InsertSorted(item); } @@ -127,6 +150,7 @@ CVisibilityPlugins::InsertAtomicIntoSortedList(RpAtomic *a, float dist) return !!m_alphaList.InsertSorted(item); } +/* bool CVisibilityPlugins::InsertAtomicIntoBoatSortedList(RpAtomic *a, float dist) { @@ -135,9 +159,11 @@ CVisibilityPlugins::InsertAtomicIntoBoatSortedList(RpAtomic *a, float dist) item.sort = dist; return !!m_alphaBoatAtomicList.InsertSorted(item); } +*/ // can't increase this yet unfortunately... // probably have to fix fading for this so material alpha isn't overwritten +// LCS: VIS_DISTANCE_ALPHA will probably take care of this #define VEHICLE_LODDIST_MULTIPLIER (TheCamera.GenerationDistMultiplier) void @@ -157,7 +183,7 @@ CVisibilityPlugins::SetRenderWareCamera(RwCamera *camera) ms_vehicleFadeDist = sq(100.0f * VEHICLE_LODDIST_MULTIPLIER); ms_bigVehicleLod0Dist = sq(60.0f * VEHICLE_LODDIST_MULTIPLIER); ms_bigVehicleLod1Dist = sq(150.0f * VEHICLE_LODDIST_MULTIPLIER); - ms_pedLod1Dist = sq(60.0f * TheCamera.LODDistMultiplier); + ms_pedLodDist = sq(70.0f * TheCamera.LODDistMultiplier); ms_pedFadeDist = sq(70.0f * TheCamera.LODDistMultiplier); } @@ -173,7 +199,10 @@ CVisibilityPlugins::SetupVehicleVariables(RpClump *vehicle) RwV3d distToCam; RwV3dSub(&distToCam, ms_pCameraPosn, &RwFrameGetMatrix(RpClumpGetFrame(vehicle))->pos); float dist2d = Sqrt(SQR(distToCam.x) + SQR(distToCam.y)); - PitchToCamera = Atan2(distToCam.z, dist2d); + if(distToCam.z == 0.0f && dist2d == 0.0f) + PitchToCamera = 0.0f; + else + PitchToCamera = Atan2(distToCam.z, dist2d); } RpMaterial* @@ -204,6 +233,8 @@ CVisibilityPlugins::RenderAlphaAtomics(void) RenderAtomicList(m_alphaList); } +/* +//LCS: removed void CVisibilityPlugins::RenderBoatAlphaAtomics(void) { @@ -211,6 +242,7 @@ CVisibilityPlugins::RenderBoatAlphaAtomics(void) RenderAtomicList(m_alphaBoatAtomicList); SetCullMode(rwCULLMODECULLBACK); } +*/ void CVisibilityPlugins::RenderFadingEntities(CLinkList<AlphaObjectInfo> &list) @@ -229,6 +261,8 @@ CVisibilityPlugins::RenderFadingEntities(CLinkList<AlphaObjectInfo> &list) if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite) RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); +#if defined(FIX_BUGS) && !defined(VIS_DISTANCE_ALPHA) + //LCS: removed, but that's dumb cause it breaks distance fading if(e->bDistanceFade){ DeActivateDirectional(); SetAmbientColours(); @@ -238,7 +272,18 @@ CVisibilityPlugins::RenderFadingEntities(CLinkList<AlphaObjectInfo> &list) POP_RENDERGROUP(); e->bImBeingRendered = false; }else +#endif + { +#ifdef VIS_DISTANCE_ALPHA + // BUG: we don't even know if this is a clump + if(GetClumpAlpha((RpClump*)e->m_rwObject) != 255 || + GetObjectDistanceAlpha(e->m_rwObject) != 255) + ; // set blend render states + else + ; // set default render states +#endif CRenderer::RenderOneNonRoad(e); + } if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite) RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); @@ -249,13 +294,13 @@ void CVisibilityPlugins::RenderFadingEntities(void) { RenderFadingEntities(m_alphaEntityList); - RenderBoatAlphaAtomics(); +// RenderBoatAlphaAtomics(); } void CVisibilityPlugins::RenderFadingUnderwaterEntities(void) { - RenderFadingEntities(m_alphaUnderwaterEntityList); +// RenderFadingEntities(m_alphaUnderwaterEntityList); } RpAtomic* @@ -267,7 +312,12 @@ CVisibilityPlugins::RenderWheelAtomicCB(RpAtomic *atomic) mi = GetAtomicModelInfo(atomic); len = Sqrt(DistToCameraSq); +#ifdef FIX_BUGS + len *= 0.5f; // HACK HACK, LOD wheels look shite lodatm = mi->GetAtomicFromDistance(len * TheCamera.LODDistMultiplier / VEHICLE_LODDIST_MULTIPLIER); +#else + lodatm = mi->GetAtomicFromDistance(len); +#endif if(lodatm){ if(RpAtomicGetGeometry(lodatm) != RpAtomicGetGeometry(atomic)) RpAtomicSetGeometry(atomic, RpAtomicGetGeometry(lodatm), rpATOMICSAMEBOUNDINGSPHERE); @@ -308,6 +358,8 @@ CVisibilityPlugins::RenderAlphaAtomic(RpAtomic *atomic, int alpha) return atomic; } +/* +//LCS: removed RpAtomic* CVisibilityPlugins::RenderWeaponCB(RpAtomic *atomic) { @@ -325,7 +377,9 @@ CVisibilityPlugins::RenderWeaponCB(RpAtomic *atomic) RENDERCALLBACK(atomic); return atomic; } +*/ +//LCS: removed, but we want it RpAtomic* CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist) { @@ -364,7 +418,6 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist) } - RpAtomic* CVisibilityPlugins::RenderVehicleHiDetailCB(RpAtomic *atomic) { @@ -381,6 +434,10 @@ CVisibilityPlugins::RenderVehicleHiDetailCB(RpAtomic *atomic) if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*DistToCameraSq < dot*dot)) return atomic; } +#ifdef VIS_DISTANCE_ALPHA + if(GetObjectDistanceAlpha((RwObject*)RpAtomicGetClump(atomic)) == 255 || + !InsertAtomicIntoSortedList(atomic, DistToCameraSq)) +#endif RENDERCALLBACK(atomic); } return atomic; @@ -466,6 +523,16 @@ CVisibilityPlugins::RenderVehicleHiDetailCB_Boat(RpAtomic *atomic) } RpAtomic* +CVisibilityPlugins::RenderVehicleHiDetailCB_Boat_Far(RpAtomic *atomic) +{ + if(DistToCameraSq < ms_bigVehicleLod1Dist) + RENDERCALLBACK(atomic); + return atomic; +} + +/* +//LCS: removed +RpAtomic* CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat(RpAtomic *atomic) { if(DistToCameraSq < ms_vehicleLod0Dist){ @@ -477,6 +544,7 @@ CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat(RpAtomic *atomic) } return atomic; } +*/ RpAtomic* CVisibilityPlugins::RenderVehicleLoDetailCB_Boat(RpAtomic *atomic) @@ -487,9 +555,26 @@ CVisibilityPlugins::RenderVehicleLoDetailCB_Boat(RpAtomic *atomic) clump = RpAtomicGetClump(atomic); if(DistToCameraSq >= ms_vehicleLod0Dist){ alpha = GetClumpAlpha(clump); - if(alpha == 255) - RENDERCALLBACK(atomic); - else +// if(alpha == 255) +// RENDERCALLBACK(atomic); +// else + RenderAlphaAtomic(atomic, alpha); + } + return atomic; +} + +RpAtomic* +CVisibilityPlugins::RenderVehicleLoDetailCB_Boat_Far(RpAtomic *atomic) +{ + RpClump *clump; + int32 alpha; + + clump = RpAtomicGetClump(atomic); + if(DistToCameraSq >= ms_bigVehicleLod1Dist){ + alpha = GetClumpAlpha(clump); +// if(alpha == 255) +// RENDERCALLBACK(atomic); +// else RenderAlphaAtomic(atomic, alpha); } return atomic; @@ -549,9 +634,9 @@ CVisibilityPlugins::RenderVehicleReallyLowDetailCB(RpAtomic *atomic) clump = RpAtomicGetClump(atomic); if(DistToCameraSq >= ms_vehicleLod0Dist){ alpha = GetClumpAlpha(clump); - if(alpha == 255) - RENDERCALLBACK(atomic); - else +// if(alpha == 255) +// RENDERCALLBACK(atomic); +// else RenderAlphaAtomic(atomic, alpha); } return atomic; @@ -649,6 +734,7 @@ CVisibilityPlugins::RenderVehicleTailRotorAlphaCB(RpAtomic *atomic) return atomic; } +/* RpAtomic* CVisibilityPlugins::RenderPlayerCB(RpAtomic *atomic) { @@ -657,6 +743,7 @@ CVisibilityPlugins::RenderPlayerCB(RpAtomic *atomic) RENDERCALLBACK(atomic); return atomic; } +*/ RpAtomic* CVisibilityPlugins::RenderPedCB(RpAtomic *atomic) @@ -667,11 +754,11 @@ CVisibilityPlugins::RenderPedCB(RpAtomic *atomic) clump = RpAtomicGetClump(atomic); dist = GetDistanceSquaredFromCamera(RpClumpGetFrame(clump)); - if(dist < ms_pedLod1Dist){ + if(dist < ms_pedLodDist){ alpha = GetClumpAlpha(clump); - if(alpha == 255) - RENDERCALLBACK(atomic); - else +// if(alpha == 255) +// RENDERCALLBACK(atomic); +// else RenderAlphaAtomic(atomic, alpha); } return atomic; @@ -744,16 +831,7 @@ CVisibilityPlugins::DefaultVisibilityCB(RpClump *clump) bool CVisibilityPlugins::FrustumSphereCB(RpClump *clump) { - RwSphere sphere; - RwFrame *frame = RpClumpGetFrame(clump); - - CClumpModelInfo *modelInfo = (CClumpModelInfo*)GetFrameHierarchyId(frame); - sphere.radius = modelInfo->GetColModel()->boundingSphere.radius; - sphere.center.x = modelInfo->GetColModel()->boundingSphere.center.x; - sphere.center.y = modelInfo->GetColModel()->boundingSphere.center.y; - sphere.center.z = modelInfo->GetColModel()->boundingSphere.center.z; - RwV3dTransformPoints(&sphere.center, &sphere.center, 1, RwFrameGetLTM(frame)); - return RwCameraFrustumTestSphere(ms_pCamera, &sphere) != rwSPHEREOUTSIDE; + return true; } bool @@ -812,9 +890,9 @@ CVisibilityPlugins::PluginAttach(void) return ms_atomicPluginOffset != -1 && ms_clumpPluginOffset != -1; } -#define ATOMICEXT(o) (RWPLUGINOFFSET(AtomicExt, o, ms_atomicPluginOffset)) -#define FRAMEEXT(o) (RWPLUGINOFFSET(FrameExt, o, ms_framePluginOffset)) -#define CLUMPEXT(o) (RWPLUGINOFFSET(ClumpExt, o, ms_clumpPluginOffset)) +#define ATOMICEXT(o) (RWPLUGINOFFSET(CVisibilityPlugins::AtomicExt, o, CVisibilityPlugins::ms_atomicPluginOffset)) +#define FRAMEEXT(o) (RWPLUGINOFFSET(CVisibilityPlugins::FrameExt, o, CVisibilityPlugins::ms_framePluginOffset)) +#define CLUMPEXT(o) (RWPLUGINOFFSET(CVisibilityPlugins::ClumpExt, o, CVisibilityPlugins::ms_clumpPluginOffset)) // // Atomic @@ -823,7 +901,13 @@ CVisibilityPlugins::PluginAttach(void) void* CVisibilityPlugins::AtomicConstructor(void *object, int32, int32) { - ATOMICEXT(object)->modelInfo = nil; + ATOMICEXT(object)->modelId = -1; + ATOMICEXT(object)->flags = 0; +#ifdef VIS_DISTANCE_ALPHA + // This seems strange, want to start out invisible before fading in + // but maybe it's set elsewhere? + ATOMICEXT(object)->distanceAlpha = 255; +#endif return object; } @@ -844,14 +928,29 @@ void CVisibilityPlugins::SetAtomicModelInfo(RpAtomic *atomic, CSimpleModelInfo *modelInfo) { - AtomicExt *ext = ATOMICEXT(atomic); - ext->modelInfo = modelInfo; + int id; + + for(id = 0; id < MODELINFOSIZE; id++) + if(CModelInfo::GetModelInfo(id) == modelInfo){ + ATOMICEXT(atomic)->modelId = id; + return; + } + ATOMICEXT(atomic)->modelId = -1; +} + +void +CVisibilityPlugins::SetAtomicModelIndex(RpAtomic *atomic, int modelId) +{ + ATOMICEXT(atomic)->modelId = modelId; } CSimpleModelInfo* CVisibilityPlugins::GetAtomicModelInfo(RpAtomic *atomic) { - return ATOMICEXT(atomic)->modelInfo; + int id = ATOMICEXT(atomic)->modelId; + if(id == -1) + return nil; + return (CSimpleModelInfo*)CModelInfo::GetModelInfo(id); } void @@ -996,3 +1095,58 @@ CVisibilityPlugins::IsClumpVisible(RpClump *clump) { return CLUMPEXT(clump)->visibilityCB(clump); } + +#ifdef VIS_DISTANCE_ALPHA +// LCS walks the atomic list manually but we want to be compatible with both RW and librw, +// so this code isn't quite original and uses callbacks instead. +static RpAtomic* +SetAtomicDistanceAlphaCB(RpAtomic *atomic, void *data) +{ + ATOMICEXT(atomic)->distanceAlpha = *(int*)data; + return atomic; +} +void +CVisibilityPlugins::SetClumpDistanceAlpha(RpClump *clump, int alpha) +{ + RpClumpForAllAtomics(clump, SetAtomicDistanceAlphaCB, &alpha); +} + +static RpAtomic* +GetAtomicDistanceAlphaCB(RpAtomic *atomic, void *data) +{ + *(int*)data = ATOMICEXT(atomic)->distanceAlpha; + return atomic; +} +int +CVisibilityPlugins::GetClumpDistanceAlpha(RpClump *clump) +{ + int alpha = 255; + RpClumpForAllAtomics(clump, GetAtomicDistanceAlphaCB, &alpha); + return alpha; +} + + + + +void +CVisibilityPlugins::SetObjectDistanceAlpha(RwObject *object, int alpha) +{ + if(object == nil) + return; + if(RwObjectGetType(object) == rpATOMIC) + ATOMICEXT(object)->distanceAlpha = alpha; + else + SetClumpDistanceAlpha((RpClump*)object, alpha); +} + +int +CVisibilityPlugins::GetObjectDistanceAlpha(RwObject *object) +{ + if(object == nil) + return 255; + if(RwObjectGetType(object) == rpATOMIC) + return ATOMICEXT(object)->distanceAlpha; + else + return GetClumpDistanceAlpha((RpClump*)object); +} +#endif diff --git a/src/rw/VisibilityPlugins.h b/src/rw/VisibilityPlugins.h index 90afc0f5..e8ff0735 100644 --- a/src/rw/VisibilityPlugins.h +++ b/src/rw/VisibilityPlugins.h @@ -21,9 +21,9 @@ public: }; static CLinkList<AlphaObjectInfo> m_alphaList; - static CLinkList<AlphaObjectInfo> m_alphaBoatAtomicList; + //static CLinkList<AlphaObjectInfo> m_alphaBoatAtomicList; static CLinkList<AlphaObjectInfo> m_alphaEntityList; - static CLinkList<AlphaObjectInfo> m_alphaUnderwaterEntityList; + //static CLinkList<AlphaObjectInfo> m_alphaUnderwaterEntityList; #ifdef NEW_RENDERER static CLinkList<AlphaObjectInfo> m_alphaBuildingList; #endif @@ -35,7 +35,7 @@ public: static float ms_vehicleFadeDist; static float ms_bigVehicleLod0Dist; static float ms_bigVehicleLod1Dist; - static float ms_pedLod1Dist; + static float ms_pedLodDist; static float ms_pedFadeDist; static void Initialise(void); @@ -44,7 +44,7 @@ public: static bool InsertEntityIntoSortedList(CEntity *e, float dist); static void InitAlphaAtomicList(void); static bool InsertAtomicIntoSortedList(RpAtomic *a, float dist); - static bool InsertAtomicIntoBoatSortedList(RpAtomic *a, float dist); +// static bool InsertAtomicIntoBoatSortedList(RpAtomic *a, float dist); static void SetRenderWareCamera(RwCamera *camera); static void SetupVehicleVariables(RpClump *vehicle); @@ -52,7 +52,7 @@ public: static RpAtomic *RenderWheelAtomicCB(RpAtomic *atomic); static RpAtomic *RenderObjNormalAtomic(RpAtomic *atomic); static RpAtomic *RenderAlphaAtomic(RpAtomic *atomic, int alpha); - static RpAtomic *RenderWeaponCB(RpAtomic *atomic); +// static RpAtomic *RenderWeaponCB(RpAtomic *atomic); static RpAtomic *RenderFadingAtomic(RpAtomic *atm, float dist); static RpAtomic *RenderVehicleHiDetailCB(RpAtomic *atomic); @@ -60,8 +60,10 @@ public: static RpAtomic *RenderVehicleHiDetailCB_BigVehicle(RpAtomic *atomic); static RpAtomic *RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic); static RpAtomic *RenderVehicleHiDetailCB_Boat(RpAtomic *atomic); - static RpAtomic *RenderVehicleHiDetailAlphaCB_Boat(RpAtomic *atomic); +// static RpAtomic *RenderVehicleHiDetailAlphaCB_Boat(RpAtomic *atomic); + static RpAtomic *RenderVehicleHiDetailCB_Boat_Far(RpAtomic *atomic); static RpAtomic *RenderVehicleLoDetailCB_Boat(RpAtomic *atomic); + static RpAtomic *RenderVehicleLoDetailCB_Boat_Far(RpAtomic *atomic); static RpAtomic *RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic); static RpAtomic *RenderVehicleLowDetailAlphaCB_BigVehicle(RpAtomic *atomic); static RpAtomic *RenderVehicleReallyLowDetailCB(RpAtomic *atomic); @@ -71,12 +73,12 @@ public: static RpAtomic *RenderVehicleRotorAlphaCB(RpAtomic *atomic); static RpAtomic *RenderVehicleTailRotorAlphaCB(RpAtomic *atomic); - static RpAtomic *RenderPlayerCB(RpAtomic *atomic); +// static RpAtomic *RenderPlayerCB(RpAtomic *atomic); static RpAtomic *RenderPedCB(RpAtomic *atomic); // for skinned models with only one clump static void RenderAtomicList(CLinkList<AlphaObjectInfo> &list); static void RenderAlphaAtomics(void); - static void RenderBoatAlphaAtomics(void); +// static void RenderBoatAlphaAtomics(void); static void RenderFadingEntities(CLinkList<AlphaObjectInfo> &list); static void RenderFadingEntities(void); static void RenderFadingUnderwaterEntities(void); @@ -96,12 +98,16 @@ public: // RW Plugins // - union AtomicExt + struct AtomicExt { - CSimpleModelInfo *modelInfo; // used by SimpleModelInfo - int flags; // used by ClumpModelInfo + int16 modelId; // used by SimpleModelInfo + uint16 flags; // used by ClumpModelInfo +#ifdef VIS_DISTANCE_ALPHA + int distanceAlpha; +#endif }; static void SetAtomicModelInfo(RpAtomic*, CSimpleModelInfo*); + static void SetAtomicModelIndex(RpAtomic *atomic, int modelId); static CSimpleModelInfo *GetAtomicModelInfo(RpAtomic *atomic); static void SetAtomicFlag(RpAtomic*, int); static void ClearAtomicFlag(RpAtomic*, int); @@ -139,6 +145,8 @@ public: static void SetClumpAlpha(RpClump*, int); static int GetClumpAlpha(RpClump*); static bool IsClumpVisible(RpClump*); + static void SetClumpDistanceAlpha(RpClump*, int); + static int GetClumpDistanceAlpha(RpClump*); static void *ClumpConstructor(void *object, int32 offset, int32 len); static void *ClumpDestructor(void *object, int32 offset, int32 len); @@ -146,6 +154,11 @@ public: int32 offset, int32 len); static int32 ms_clumpPluginOffset; +#ifdef VIS_DISTANCE_ALPHA + static void SetObjectDistanceAlpha(RwObject *object, int alpha); + static int GetObjectDistanceAlpha(RwObject *object); +#endif + static bool PluginAttach(void); }; |