forked from multitheftauto/mtasa-blue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e21c53
commit 8f19ae3
Showing
11 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
Client/mods/deathmatch/logic/CResourceModelStreamer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto v1.0 | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: mods/deathmatch/logic/CResourceModelStreamer.cpp | ||
* PURPOSE: Resource model manager | ||
* | ||
* Multi Theft Auto is available from https://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#include "StdInc.h" | ||
|
||
#include "CResourceModelStreamer.h" | ||
#include "CClientGame.h" | ||
#include <game/CStreaming.h> | ||
|
||
bool CResourceModelStreamer::RequestModel(uint16_t modelId, bool addRef, bool blocking) | ||
{ | ||
CModelInfo* model = g_pGame->GetModelInfo(modelId); | ||
|
||
if (!model) | ||
return false; | ||
|
||
if (addRef) | ||
{ | ||
uint16_t refsCount = ++m_requestedModels[modelId]; | ||
if (refsCount == 1) | ||
{ | ||
model->ModelAddRef(blocking ? EModelRequestType::BLOCKING : EModelRequestType::NON_BLOCKING, "CResourceModelStreamer::RequestModel With reference"); | ||
return true; | ||
} | ||
return false; | ||
} | ||
else | ||
{ | ||
model->Request(blocking ? EModelRequestType::BLOCKING : EModelRequestType::NON_BLOCKING, "CResourceModelStreamer::RequestModel With out reference"); | ||
return true; | ||
} | ||
} | ||
|
||
// Retrun true if model was unloaded | ||
bool CResourceModelStreamer::ReleaseModel(uint16_t modelId, bool removeRef) | ||
{ | ||
if (removeRef) | ||
{ | ||
auto refs = m_requestedModels.find(modelId); | ||
if (refs == m_requestedModels.end()) | ||
return false; | ||
|
||
uint16_t& refsCount = (*refs).second; | ||
|
||
if (refsCount == 0) | ||
return false; | ||
|
||
refsCount--; | ||
|
||
if (refsCount != 0) | ||
return false; | ||
|
||
CModelInfo* model = g_pGame->GetModelInfo(modelId); | ||
|
||
if (!model) | ||
return false; | ||
|
||
// Hack | ||
// This check will update models pending references | ||
model->IsLoaded(); | ||
|
||
// This call can unload the model | ||
model->RemoveRef(); | ||
|
||
return !model->IsLoaded(); | ||
} | ||
else | ||
{ | ||
CModelInfo* model = g_pGame->GetModelInfo(modelId); | ||
|
||
if (!model) | ||
return false; | ||
|
||
return model->UnloadUnused(); | ||
} | ||
} | ||
|
||
void CResourceModelStreamer::ReleaseAll() | ||
{ | ||
for (const auto &modelRefs : m_requestedModels) | ||
{ | ||
if (modelRefs.second > 0) | ||
{ | ||
CModelInfo* model = g_pGame->GetModelInfo(modelRefs.first); | ||
model->RemoveRef(); | ||
} | ||
} | ||
|
||
m_requestedModels.clear(); | ||
} | ||
|
||
void CResourceModelStreamer::FullyReleaseModel(uint16_t modelId) | ||
{ | ||
uint16_t &refsCount = m_requestedModels[modelId]; | ||
|
||
if (refsCount > 0) | ||
{ | ||
refsCount = 0; | ||
|
||
CModelInfo* model = g_pGame->GetModelInfo(modelId); | ||
|
||
if (!model) | ||
return; | ||
|
||
model->RemoveRef(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto v1.0 | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: mods/deathmatch/logic/CResourceModelStreamer.h | ||
* PURPOSE: Resource model manager | ||
* | ||
* Multi Theft Auto is available from https://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <unordered_map> | ||
|
||
class CResourceModelStreamer | ||
{ | ||
public: | ||
CResourceModelStreamer() = default; | ||
~CResourceModelStreamer() = default; | ||
|
||
bool RequestModel(uint16_t modelId, bool addRef = false, bool blocking = false); | ||
bool ReleaseModel(uint16_t modelId, bool removeRef = false); | ||
|
||
void ReleaseAll(); | ||
void FullyReleaseModel(uint16_t modelId); | ||
|
||
private: | ||
std::unordered_map<uint16_t, uint16_t> m_requestedModels; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters