Support arbitrary amount of numberplates

This commit is contained in:
Silent 2017-04-10 13:18:23 +02:00
parent ca1d2c2496
commit db1481d219
3 changed files with 49 additions and 33 deletions

View File

@ -88,20 +88,17 @@ void CVehicleModelInfo::SetCarCustomPlate()
m_plateText[0] = '\0'; m_plateText[0] = '\0';
m_nPlateType = -1; m_nPlateType = -1;
m_apPlateMaterials = new RpMaterial* [2*CCustomCarPlateMgr::NUM_MAX_PLATES]; m_apPlateMaterials = new PlateMaterialsData;
std::fill_n( m_apPlateMaterials, 2*CCustomCarPlateMgr::NUM_MAX_PLATES, nullptr );
CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials); CCustomCarPlateMgr::SetupClump(reinterpret_cast<RpClump*>(pRwObject), m_apPlateMaterials);
} }
void CCustomCarPlateMgr::PollPlates( RpClump* clump, RpMaterial** materials ) void CCustomCarPlateMgr::PollPlates( RpClump* clump, PlateMaterialsData* materials )
{ {
RpMaterial** carplates = materials; std::vector<RpMaterial*> carplates;
RpMaterial** carpbacks = materials+NUM_MAX_PLATES; std::vector<RpMaterial*> carpbacks;
int numCarplates = 0, numCarpbacks = 0; RpClumpForAllAtomics( clump, [&] ( RpAtomic* atomic ) -> RpAtomic* {
RpClumpForAllAtomics( clump, [carplates, carpbacks, &numCarplates, &numCarpbacks] ( RpAtomic* atomic ) -> RpAtomic* {
RpGeometryForAllMaterials( RpAtomicGetGeometry(atomic), [&] ( RpMaterial* material ) -> RpMaterial* { RpGeometryForAllMaterials( RpAtomicGetGeometry(atomic), [&] ( RpMaterial* material ) -> RpMaterial* {
if ( RwTexture* texture = RpMaterialGetTexture(material) ) if ( RwTexture* texture = RpMaterialGetTexture(material) )
{ {
@ -109,19 +106,11 @@ void CCustomCarPlateMgr::PollPlates( RpClump* clump, RpMaterial** materials )
{ {
if ( _stricmp( texName, "carplate" ) == 0 ) if ( _stricmp( texName, "carplate" ) == 0 )
{ {
assert(numCarplates < NUM_MAX_PLATES); carplates.push_back( material );
if ( numCarplates < NUM_MAX_PLATES )
{
carplates[numCarplates++] = material;
}
} }
else if ( _stricmp( texName, "carpback" ) == 0 ) else if ( _stricmp( texName, "carpback" ) == 0 )
{ {
assert(numCarpbacks < NUM_MAX_PLATES); carpbacks.push_back( material );
if ( numCarpbacks < NUM_MAX_PLATES )
{
carpbacks[numCarpbacks++] = material;
}
} }
} }
} }
@ -130,14 +119,29 @@ void CCustomCarPlateMgr::PollPlates( RpClump* clump, RpMaterial** materials )
} ); } );
return atomic; return atomic;
} ); } );
materials->m_numPlates = carplates.size();
materials->m_numPlatebacks = carpbacks.size();
if ( materials->m_numPlates > 0 )
{
materials->m_plates = new RpMaterial* [materials->m_numPlates];
std::copy( carplates.begin(), carplates.end(), stdext::checked_array_iterator<RpMaterial**>(materials->m_plates, materials->m_numPlates) );
}
if ( materials->m_numPlatebacks > 0 )
{
materials->m_platebacks = new RpMaterial* [materials->m_numPlatebacks];
std::copy( carpbacks.begin(), carpbacks.end(), stdext::checked_array_iterator<RpMaterial**>(materials->m_platebacks, materials->m_numPlatebacks) );
}
} }
void CCustomCarPlateMgr::SetupClump(RpClump* pClump, RpMaterial** pMatsArray) void CCustomCarPlateMgr::SetupClump(RpClump* pClump, PlateMaterialsData* pMatsArray)
{ {
PollPlates( pClump, pMatsArray ); PollPlates( pClump, pMatsArray );
} }
void CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign) void CCustomCarPlateMgr::SetupClumpAfterVehicleUpgrade(RpClump* pClump, PlateMaterialsData* pMatsArray, signed char nDesign)
{ {
UNREFERENCED_PARAMETER(nDesign); UNREFERENCED_PARAMETER(nDesign);
if ( pMatsArray != nullptr ) if ( pMatsArray != nullptr )

View File

@ -222,12 +222,27 @@ public:
virtual void SetClump(RpClump* pClump); virtual void SetClump(RpClump* pClump);
}; };
struct PlateMaterialsData // Added in SilentPatch
{
RpMaterial** m_plates = nullptr;
RpMaterial** m_platebacks = nullptr;
size_t m_numPlates = 0;
size_t m_numPlatebacks = 0;
~PlateMaterialsData()
{
delete m_plates;
delete m_platebacks;
}
};
class NOVMT CVehicleModelInfo : public CClumpModelInfo class NOVMT CVehicleModelInfo : public CClumpModelInfo
{ {
public: public:
static const size_t PLATE_TEXT_LEN = 8; static const size_t PLATE_TEXT_LEN = 8;
RpMaterial** m_apPlateMaterials; // Changed in SilentPatchh PlateMaterialsData* m_apPlateMaterials; // Changed in SilentPatch
char m_plateText[PLATE_TEXT_LEN]; char m_plateText[PLATE_TEXT_LEN];
char field_30; char field_30;
signed char m_nPlateType; signed char m_nPlateType;
@ -321,11 +336,11 @@ public:
static signed char (*GetMapRegionPlateDesign)(); static signed char (*GetMapRegionPlateDesign)();
static void (*SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign); static void (*SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign);
static void SetupClump(RpClump* pClump, RpMaterial** pMatsArray); static void SetupClump(RpClump* pClump, PlateMaterialsData* pMatsArray);
static void SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign); static void SetupClumpAfterVehicleUpgrade(RpClump* pClump, PlateMaterialsData* pMatsArray, signed char nDesign);
private: private:
static void PollPlates( RpClump* clump, RpMaterial** materials ); static void PollPlates( RpClump* clump, PlateMaterialsData* materials );
}; };
static_assert(sizeof(CBaseModelInfo) == 0x20, "Wrong size: CBaseModelInfo"); static_assert(sizeof(CBaseModelInfo) == 0x20, "Wrong size: CBaseModelInfo");

View File

@ -124,17 +124,14 @@ bool CVehicle::CustomCarPlate_TextureCreate(CVehicleModelInfo* pModelInfo)
void CVehicle::CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo) void CVehicle::CustomCarPlate_BeforeRenderingStart(CVehicleModelInfo* pModelInfo)
{ {
for ( ptrdiff_t i = 0; i < CCustomCarPlateMgr::NUM_MAX_PLATES; i++ ) for ( size_t i = 0; i < pModelInfo->m_apPlateMaterials->m_numPlates; i++ )
{ {
if ( pModelInfo->m_apPlateMaterials[i] != nullptr ) RpMaterialSetTexture(pModelInfo->m_apPlateMaterials->m_plates[i], PlateTexture);
{ }
RpMaterialSetTexture(pModelInfo->m_apPlateMaterials[i], PlateTexture);
}
if ( pModelInfo->m_apPlateMaterials[CCustomCarPlateMgr::NUM_MAX_PLATES+i] != nullptr ) for ( size_t i = 0; i < pModelInfo->m_apPlateMaterials->m_numPlatebacks; i++ )
{ {
CCustomCarPlateMgr::SetupMaterialPlatebackTexture(pModelInfo->m_apPlateMaterials[CCustomCarPlateMgr::NUM_MAX_PLATES+i], PlateDesign); CCustomCarPlateMgr::SetupMaterialPlatebackTexture(pModelInfo->m_apPlateMaterials->m_platebacks[i], PlateDesign);
}
} }
} }