-
-
Notifications
You must be signed in to change notification settings - Fork 470
Add model streaming functions #3611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Dutchman101
merged 7 commits into
multitheftauto:master
from
TheNormalnij:TheNormalnij/requestStreaming
Aug 14, 2024
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f19ae3
Add engineStreamingRequestModel
TheNormalnij cc692bf
fix RequestModel
TheNormalnij 82dcb4d
Add engineStreamingGetModelLoadState
TheNormalnij 5715531
Merge branch 'master' into TheNormalnij/requestStreaming
TheNormalnij 85550bf
Fix style
TheNormalnij 2af2f46
Fix style 2
TheNormalnij 2d8c81f
Merge branch 'master' into TheNormalnij/requestStreaming
Dutchman101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
122 changes: 122 additions & 0 deletions
122
Client/mods/deathmatch/logic/CResourceModelStreamer.cpp
This file contains hidden or 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,122 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto v1.0 | ||
TheNormalnij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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) | ||
Dutchman101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
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 | ||
{ | ||
if (model->IsLoaded()) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
model->Request(blocking ? EModelRequestType::BLOCKING : EModelRequestType::NON_BLOCKING, "CResourceModelStreamer::RequestModel With out reference"); | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
// Retrun true if model was unloaded | ||
TheNormalnij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
TheNormalnij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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]; | ||
TheNormalnij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (refsCount > 0) | ||
{ | ||
refsCount = 0; | ||
|
||
CModelInfo* model = g_pGame->GetModelInfo(modelId); | ||
|
||
if (!model) | ||
return; | ||
|
||
model->RemoveRef(); | ||
} | ||
} |
This file contains hidden or 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 | ||
TheNormalnij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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; | ||
TheNormalnij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.