88#include " istudiorender.h"
99#include " cache.h"
1010
11- #if Cache_Experimental == 1
11+ #if Cache_Experimental
1212#include < unordered_map>
1313#include " materialsystem/imaterialsystem.h"
1414#endif
1515
1616static SourceSDK::FactoryLoader vphysics_loader (" vphysics" );
1717static SourceSDK::FactoryLoader datacache_loader (" datacache" );
18- #if Cache_Experimental == 1
18+ #if Cache_Experimental
1919static SourceSDK::FactoryLoader materialsystem_loader (" materialsystem" );
2020#endif
2121
2222static IMDLCache* MDLCache = nullptr ;
2323static IPhysicsCollision* PhysicsCollision = nullptr ;
2424
25- #if Cache_Experimental == 1
25+ #if Cache_Experimental
2626static IMaterialSystem* MaterialSystem = nullptr ;
2727static std::unordered_map<const char *, bool > material_cache;
2828#endif
@@ -73,7 +73,7 @@ class IMDLCacheUpdate : public IMDLCacheNotify
7373 if (type == MDLCACHE_STUDIOHWDATA) {
7474 // MDLCache->RestoreHardwareData(handle, (FSAsyncControl_t*)0, (FSAsyncControl_t*)0); // This fixes some weird engine issue. As soon as you add a IMDLCacheNotify, the Lightning and collision of most models will break.
7575 } else if (type == MDLCACHE_VCOLLIDE) {
76- MDLCache->ReloadVCollide (handle);
76+ // MDLCache->ReloadVCollide(handle);
7777 }
7878 }
7979
@@ -92,8 +92,11 @@ class IMDLCacheUpdate : public IMDLCacheNotify
9292 {
9393 return false ;
9494 }
95+
96+ private:
97+ IMDLCacheNotify* m_pOriginalNotify = nullptr ;
9598};
96- static IMDLCacheUpdate* MDLCacheUpdate = new IMDLCacheUpdate ;
99+ static IMDLCacheUpdate MDLCacheUpdate;
97100
98101/*
99102* ClearCache
@@ -107,7 +110,7 @@ unsigned ClearCache(void* params) {
107110 Msg (" [Cache] Starting to clear the Cache\n " );
108111 CThreadMutex ().Lock ();
109112
110- #if Cache_Debug == 1
113+ #if Cache_Debug
111114 Msg (" ----Cache----\n " );
112115 for (auto & [mdl, entry] : vars->cache ) {
113116 Msg (MDLCache->GetModelName (mdl));
@@ -133,21 +136,21 @@ unsigned ClearCache(void* params) {
133136 vars->MDLCache ->Flush (MDLCACHE_FLUSH_VIRTUALMODEL);
134137 vars->MDLCache ->Flush (MDLCACHE_FLUSH_AUTOPLAY);
135138 vars->MDLCache ->Flush (MDLCACHE_FLUSH_VERTEXES);
136- vars->MDLCache ->Flush (MDLCACHE_FLUSH_COMBINED_DATA);
139+ // vars->MDLCache->Flush(MDLCACHE_FLUSH_COMBINED_DATA);
137140 // vars->MDLCache->Flush(MDLCACHE_FLUSH_IGNORELOCK);
138141 }
139142
140- #if Cache_Experimental == 1
143+ #if Cache_Experimental
141144 bool loop = true ;
142145 MaterialHandle_t last = MaterialSystem->FirstMaterial ();
143- #if Cache_Debug == 1
146+ #if Cache_Debug
144147 Msg (" ----Materials----\n " );
145148#endif
146149 while (loop) {
147150 IMaterial* mat = MaterialSystem->GetMaterial (last);
148151 const char * name = mat->GetName ();
149152 if (!vars->material_cache [name]) {
150- #if Cache_Debug == 1
153+ #if Cache_Debug
151154 Msg (mat->GetName ());
152155 Msg (" \n " );
153156#endif
@@ -164,7 +167,7 @@ unsigned ClearCache(void* params) {
164167#endif
165168
166169 if (vars->fullflush ) {
167- #if Cache_Debug == 1
170+ #if Cache_Debug
168171 Msg (" ----DataCache----\n " );
169172 Msg (" Cleared: " );
170173 Msg (std::to_string (vars->DataCache ->Flush (true ) / 1024 / 1024 ).c_str ());
@@ -185,7 +188,7 @@ unsigned ClearCache(void* params) {
185188*/
186189void CacheMgr::Connect (IGameEvent* event)
187190{
188- #if Cache_AwaysFlush == 0 // We don't need to clear the Cache because it got already cleared when the client disconnected from the server if Cache_AwaysFlush is enabled.
191+ #if ! Cache_AwaysFlush // We don't need to clear the Cache because it got already cleared when the client disconnected from the server if Cache_AwaysFlush is enabled.
189192 const char * new_address = event->GetString (" address" );
190193 const char * new_map = event->GetString (" mapname" );
191194 if (strcmp (this ->last_server , " " ) == 1 && strcmp (this ->last_map , new_map) == 1 ) {
@@ -202,7 +205,7 @@ void CacheMgr::Connect(IGameEvent* event)
202205 this ->last_map = strdup (new_map);
203206#endif
204207
205- #if Cache_Experimental == 1
208+ #if Cache_Experimental
206209 // This will create a list of all Materials that exist before connecting to a server.
207210 bool loop = true ;
208211 MaterialHandle_t last = MaterialSystem->FirstMaterial ();
@@ -275,7 +278,7 @@ bool CacheMgr::Flush(int delay, bool full, bool threaded, bool force)
275278 vars->fullflush = full;
276279 vars->MDLCache = MDLCache;
277280 // vars->DataCache = DataCache;
278- #if Cache_Experimental == 1
281+ #if Cache_Experimental
279282 vars->material_cache = material_cache;
280283 vars->MaterialSystem = MaterialSystem;
281284 #endif
@@ -308,30 +311,28 @@ CacheMgr::CacheMgr()
308311 if (PhysicsCollision == nullptr )
309312 ThrowError (" unable to initialize IPhysicsCollision" );
310313
311- #if Cache_Experimental == 1
314+ #if Cache_Experimental
312315 MaterialSystem = (IMaterialSystem*)materialsystem_loader.GetFactory ()(MATERIAL_SYSTEM_INTERFACE_VERSION, nullptr );
313316 if (MaterialSystem == nullptr )
314317 ThrowError (" unable to initialize IMaterialSystem" );
315318 #endif
316319
317- // MDLCache->SetCacheNotify(MDLCacheUpdate); Why is the MDLCache broken!?!?! using any Set* function breaks the entire cache -> crashes the game.
318-
319- // this->SetAsyncCacheDataType(MDLCACHE_STUDIOHDR, true, false, "MDLCACHE_STUDIOHDR"); cannot be activated
320- // this->SetAsyncCacheDataType(MDLCACHE_STUDIOHWDATA, true, false, "MDLCACHE_STUDIOHWDATA");
321- // this->SetAsyncCacheDataType(MDLCACHE_VCOLLIDE, true, false, "MDLCACHE_VCOLLIDE");
322- // this->SetAsyncCacheDataType(MDLCACHE_ANIMBLOCK, true, false, "MDLCACHE_ANIMBLOCK"); if activated, it breaks some playermodels
323- // this->SetAsyncCacheDataType(MDLCACHE_VIRTUALMODEL, true, false, "MDLCACHE_VIRTUALMODEL"); cannot be activated
324- // this->SetAsyncCacheDataType(MDLCACHE_VERTEXES, true, false, "MDLCACHE_VERTEXES");
325- // this->SetAsyncCacheDataType(MDLCACHE_DECODEDANIMBLOCK, true, false, "MDLCACHE_DECODEDANIMBLOCK"); cannot be activated
320+ // SetAsyncCacheDataType(MDLCACHE_STUDIOHDR, true, false, "MDLCACHE_STUDIOHDR"); cannot be activated
321+ // SetAsyncCacheDataType(MDLCACHE_STUDIOHWDATA, true, false, "MDLCACHE_STUDIOHWDATA");
322+ // SetAsyncCacheDataType(MDLCACHE_VCOLLIDE, true, false, "MDLCACHE_VCOLLIDE");
323+ // SetAsyncCacheDataType(MDLCACHE_ANIMBLOCK, true, false, "MDLCACHE_ANIMBLOCK"); if activated, it breaks some playermodels
324+ // SetAsyncCacheDataType(MDLCACHE_VIRTUALMODEL, true, false, "MDLCACHE_VIRTUALMODEL"); cannot be activated
325+ // SetAsyncCacheDataType(MDLCACHE_VERTEXES, true, false, "MDLCACHE_VERTEXES");
326+ // SetAsyncCacheDataType(MDLCACHE_DECODEDANIMBLOCK, true, false, "MDLCACHE_DECODEDANIMBLOCK"); cannot be activated
326327}
327328
328329void CacheMgr::Shutdown ()
329330{
330- // this-> SetAsyncCacheDataType(MDLCACHE_STUDIOHDR, false, false, "MDLCACHE_STUDIOHDR");
331- this -> SetAsyncCacheDataType (MDLCACHE_STUDIOHWDATA, false , false , " MDLCACHE_STUDIOHWDATA" );
332- this -> SetAsyncCacheDataType (MDLCACHE_VCOLLIDE, false , false , " MDLCACHE_VCOLLIDE" );
333- // this-> SetAsyncCacheDataType(MDLCACHE_ANIMBLOCK, false, false, "MDLCACHE_ANIMBLOCK");
334- // this-> SetAsyncCacheDataType(MDLCACHE_VIRTUALMODEL, false, false, "MDLCACHE_VIRTUALMODEL");
335- this -> SetAsyncCacheDataType (MDLCACHE_VERTEXES, false , false , " MDLCACHE_VERTEXES" );
336- // this-> SetAsyncCacheDataType(MDLCACHE_DECODEDANIMBLOCK, false, false, "MDLCACHE_DECODEDANIMBLOCK");
331+ // SetAsyncCacheDataType(MDLCACHE_STUDIOHDR, false, false, "MDLCACHE_STUDIOHDR");
332+ SetAsyncCacheDataType (MDLCACHE_STUDIOHWDATA, false , false , " MDLCACHE_STUDIOHWDATA" );
333+ SetAsyncCacheDataType (MDLCACHE_VCOLLIDE, false , false , " MDLCACHE_VCOLLIDE" );
334+ // SetAsyncCacheDataType(MDLCACHE_ANIMBLOCK, false, false, "MDLCACHE_ANIMBLOCK");
335+ // SetAsyncCacheDataType(MDLCACHE_VIRTUALMODEL, false, false, "MDLCACHE_VIRTUALMODEL");
336+ SetAsyncCacheDataType (MDLCACHE_VERTEXES, false , false , " MDLCACHE_VERTEXES" );
337+ // SetAsyncCacheDataType(MDLCACHE_DECODEDANIMBLOCK, false, false, "MDLCACHE_DECODEDANIMBLOCK");
337338}
0 commit comments