-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Allow allocating models server-side #2533
base: master
Are you sure you want to change the base?
Changes from all commits
5698387
e4bfd86
dc5bbf6
b7be58e
be0d106
231ca90
b83eba2
84cc9e5
bb32626
e7a8dfc
2fe28e6
9b244ba
4f49306
b1b19c2
7cc086f
8c69d0c
f6a2701
a53f37a
5a879d8
faf18c5
e69562d
c926786
d94c450
51e3497
90d000f
2d06b28
f290bf1
f88cb0b
695cdf3
5ebc232
51c25c9
e3d3d71
fc710c3
ea20924
e42b687
4e96f2f
cee659c
e50f7b7
2e13146
aeb3a12
edbb2a7
e63ff7b
2b60f79
4e6c087
11ec287
323970e
b2c7172
e07956c
8af33b3
309f5b1
5f018f6
a1a3a5e
911b091
04f6f98
1288dae
9b534e9
791dd4c
ddb35c7
4edb200
4dab556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* (Shared logic for modifications) | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: mods/deathmatch/logic/CClientModelManager.cpp | ||
* PURPOSE: Model manager class | ||
* | ||
*****************************************************************************/ | ||
|
||
#include "StdInc.h" | ||
|
||
CClientModelManager::CClientModelManager() : m_Models(std::make_unique<std::shared_ptr<CClientModel>[]>(g_pGame->GetBaseIDforCOL())) | ||
{ | ||
const unsigned int uiMaxModelID = g_pGame->GetBaseIDforCOL(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
@@ -44,9 +44,8 @@ void CClientModelManager::Add(const std::shared_ptr<CClientModel>& pModel) | |
m_modelCount++; | ||
} | ||
|
||
bool CClientModelManager::Remove(const std::shared_ptr<CClientModel>& pModel) | ||
bool CClientModelManager::Remove(const int modelId) | ||
{ | ||
int modelId = pModel->GetModelID(); | ||
if (m_Models[modelId] != nullptr) | ||
{ | ||
m_Models[modelId]->RestoreEntitiesUsingThisModel(); | ||
|
@@ -57,6 +56,18 @@ bool CClientModelManager::Remove(const std::shared_ptr<CClientModel>& pModel) | |
return false; | ||
} | ||
|
||
bool CClientModelManager::RemoveClientModel(const int modelId) | ||
{ | ||
if (m_Models[modelId] == nullptr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!m_Models[modelId]) |
||
return false; | ||
|
||
// Model was allocated clientside | ||
if (!m_Models[modelId]->GetParentResource()) | ||
return false; | ||
|
||
return Remove(modelId); | ||
} | ||
|
||
int CClientModelManager::GetFirstFreeModelID(void) | ||
{ | ||
const unsigned int uiMaxModelID = g_pGame->GetBaseIDforCOL(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
@@ -124,6 +135,47 @@ void CClientModelManager::DeallocateModelsAllocatedByResource(CResource* pResour | |
for (unsigned int i = 0; i < uiMaxModelID; i++) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
if (m_Models[i] != nullptr && m_Models[i]->GetParentResource() == pResource) | ||
Remove(m_Models[i]); | ||
Remove(i); | ||
} | ||
} | ||
|
||
bool CClientModelManager::AllocateModelFromParent(uint32_t uiNewModelID, uint32_t uiParentModelID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
eModelInfoType eModelType = g_pGame->GetModelInfo(uiParentModelID)->GetModelType(); | ||
|
||
std::shared_ptr<CClientModel> pModel = FindModelByID(uiNewModelID); | ||
if (pModel) | ||
return false; | ||
|
||
eClientModelType clientModelType; | ||
|
||
switch (eModelType) | ||
{ | ||
case eModelInfoType::ATOMIC: | ||
clientModelType = eClientModelType::OBJECT; | ||
break; | ||
case eModelInfoType::TIMED_OBJECT: | ||
clientModelType = eClientModelType::TIMED_OBJECT; | ||
break; | ||
case eModelInfoType::CLUMP: | ||
clientModelType = eClientModelType::CLUMP; | ||
break; | ||
case eModelInfoType::VEHICLE: | ||
clientModelType = eClientModelType::VEHICLE; | ||
break; | ||
case eModelInfoType::PED: | ||
clientModelType = eClientModelType::PED; | ||
break; | ||
default: | ||
return false; | ||
} | ||
|
||
pModel = std::make_shared<CClientModel>(g_pClientGame->GetManager(), uiNewModelID, clientModelType); | ||
|
||
Add(pModel); | ||
|
||
if (pModel->Allocate(uiParentModelID)) | ||
return true; | ||
|
||
return false; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* (Shared logic for modifications) | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: mods/deathmatch/logic/CClientModelManager.h | ||
* PURPOSE: Model manager class | ||
* | ||
* Multi Theft Auto is available from https://multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
class CClientModelManager; | ||
|
@@ -32,7 +33,8 @@ class CClientModelManager | |
void RemoveAll(void); | ||
|
||
void Add(const std::shared_ptr<CClientModel>& pModel); | ||
bool Remove(const std::shared_ptr<CClientModel>& pModel); | ||
bool Remove(const int modelId); | ||
bool RemoveClientModel(const int modelId); | ||
|
||
int GetFirstFreeModelID(void); | ||
int GetFreeTxdModelID(); | ||
|
@@ -43,6 +45,7 @@ class CClientModelManager | |
std::vector<std::shared_ptr<CClientModel>> GetModelsByType(eClientModelType type, const unsigned int minModelID = 0); | ||
|
||
void DeallocateModelsAllocatedByResource(CResource* pResource); | ||
bool AllocateModelFromParent(uint32_t usModelID, uint32_t usParentModel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
private: | ||
std::unique_ptr<std::shared_ptr<CClientModel>[]> m_Models; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto v1.0 | ||
* (Shared logic for modifications) | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: mods/shared_logic/CClientVehicleManager.cpp | ||
* FILE: mods/deathmatch/logic/CClientVehicleManager.cpp | ||
* PURPOSE: Vehicle entity manager class | ||
* | ||
* Multi Theft Auto is available from https://multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#include "StdInc.h" | ||
|
@@ -432,6 +433,14 @@ bool CClientVehicleManager::IsStandardModel(unsigned long ulModel) | |
return ulModel >= 400 && ulModel <= 611; | ||
} | ||
|
||
unsigned long CClientVehicleManager::GetRootModelId(unsigned long ulModel) | ||
{ | ||
if (IsStandardModel(ulModel)) | ||
return ulModel; | ||
|
||
return g_pGame->GetModelInfo(ulModel)->GetParentID(); | ||
} | ||
|
||
Comment on lines
+436
to
+443
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to change |
||
eClientVehicleType CClientVehicleManager::GetVehicleType(unsigned long ulModel) | ||
{ | ||
// Valid vehicle id? | ||
|
@@ -625,42 +634,42 @@ unsigned char CClientVehicleManager::ConvertIndexToGameSeat(unsigned long ulMode | |
|
||
bool CClientVehicleManager::HasTurret(unsigned long ulModel) | ||
{ | ||
return (IsStandardModel(ulModel) && (g_ulVehicleAttributes[ulModel - 400] & VEHICLE_HAS_TURRENT)); | ||
return ((g_ulVehicleAttributes[GetRootModelId(ulModel) - 400] & VEHICLE_HAS_TURRENT)); | ||
} | ||
|
||
bool CClientVehicleManager::HasSirens(unsigned long ulModel) | ||
{ | ||
return (IsStandardModel(ulModel) && (g_ulVehicleAttributes[ulModel - 400] & VEHICLE_HAS_SIRENS)); | ||
return ((g_ulVehicleAttributes[GetRootModelId(ulModel) - 400] & VEHICLE_HAS_SIRENS)); | ||
} | ||
|
||
bool CClientVehicleManager::HasTaxiLight(unsigned long ulModel) | ||
{ | ||
return (IsStandardModel(ulModel) && (g_ulVehicleAttributes[ulModel - 400] & VEHICLE_HAS_TAXI_LIGHTS)); | ||
return ((g_ulVehicleAttributes[GetRootModelId(ulModel) - 400] & VEHICLE_HAS_TAXI_LIGHTS)); | ||
} | ||
|
||
bool CClientVehicleManager::HasSearchLight(unsigned long ulModel) | ||
{ | ||
return (IsStandardModel(ulModel) && (g_ulVehicleAttributes[ulModel - 400] & VEHICLE_HAS_SEARCH_LIGHT)); | ||
return ((g_ulVehicleAttributes[GetRootModelId(ulModel) - 400] & VEHICLE_HAS_SEARCH_LIGHT)); | ||
} | ||
|
||
bool CClientVehicleManager::HasLandingGears(unsigned long ulModel) | ||
{ | ||
return (IsStandardModel(ulModel) && (g_ulVehicleAttributes[ulModel - 400] & VEHICLE_HAS_LANDING_GEARS)); | ||
return ((g_ulVehicleAttributes[GetRootModelId(ulModel) - 400] & VEHICLE_HAS_LANDING_GEARS)); | ||
} | ||
|
||
bool CClientVehicleManager::HasAdjustableProperty(unsigned long ulModel) | ||
{ | ||
return (IsStandardModel(ulModel) && (g_ulVehicleAttributes[ulModel - 400] & VEHICLE_HAS_ADJUSTABLE_PROPERTY)); | ||
return ((g_ulVehicleAttributes[GetRootModelId(ulModel) - 400] & VEHICLE_HAS_ADJUSTABLE_PROPERTY)); | ||
} | ||
|
||
bool CClientVehicleManager::HasSmokeTrail(unsigned long ulModel) | ||
{ | ||
return (IsStandardModel(ulModel) && (g_ulVehicleAttributes[ulModel - 400] & VEHICLE_HAS_SMOKE_TRAIL)); | ||
return ((g_ulVehicleAttributes[GetRootModelId(ulModel) - 400] & VEHICLE_HAS_SMOKE_TRAIL)); | ||
} | ||
|
||
bool CClientVehicleManager::HasDamageModel(unsigned long ulModel) | ||
{ | ||
return HasDamageModel(GetVehicleType(ulModel)); | ||
return HasDamageModel(GetVehicleType(GetRootModelId(ulModel))); | ||
} | ||
|
||
bool CClientVehicleManager::HasDamageModel(eClientVehicleType Type) | ||
|
@@ -681,6 +690,8 @@ bool CClientVehicleManager::HasDamageModel(eClientVehicleType Type) | |
|
||
bool CClientVehicleManager::HasDoors(unsigned long ulModel) | ||
{ | ||
ulModel = GetRootModelId(ulModel); | ||
|
||
bool bHasDoors = false; | ||
|
||
if (HasDamageModel(ulModel) == true) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto v1.0 | ||
* (Shared logic for modifications) | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: mods/shared_logic/CClientVehicleManager.h | ||
* FILE: mods/deathmatch/logic/CClientVehicleManager.h | ||
* PURPOSE: Vehicle entity manager class header | ||
* | ||
* Multi Theft Auto is available from https://multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#pragma once | ||
|
@@ -35,6 +36,7 @@ class CClientVehicleManager | |
static bool IsTrainModel(unsigned long ulModel); | ||
static bool IsValidModel(unsigned long ulModel); | ||
static bool IsStandardModel(unsigned long ulModel); | ||
static unsigned long GetRootModelId(unsigned long ulModel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to change |
||
static eClientVehicleType GetVehicleType(unsigned long ulModel); | ||
static unsigned char GetMaxPassengerCount(unsigned long ulModel); | ||
static unsigned char ConvertIndexToGameSeat(unsigned long ulModel, unsigned char ucIndex); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change
std::uint8_t
touint8_t
. Let's stick to C++ headers and namespacesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer
uint8_t
in all cases. cstdint types are standard these days.I think
std::
for numbers adds too much noise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cstdint
doesnt guarantee standard types in the global namespace but does guarantee having them in thestd
namespacestdint.h
doesnt guarantee standard types in thestd
namespace but does guarantee having them in the global namespaceIf we go with
cstdint
(as we should) thenstd::
is required by a C++ standard (unless you dousing
on them)In the end, its the matter of preference, right?