summaryrefslogtreecommitdiffstats
path: root/src/modelinfo/VehicleModelInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modelinfo/VehicleModelInfo.cpp')
-rw-r--r--src/modelinfo/VehicleModelInfo.cpp473
1 files changed, 406 insertions, 67 deletions
diff --git a/src/modelinfo/VehicleModelInfo.cpp b/src/modelinfo/VehicleModelInfo.cpp
index d31962ce..21583709 100644
--- a/src/modelinfo/VehicleModelInfo.cpp
+++ b/src/modelinfo/VehicleModelInfo.cpp
@@ -1,6 +1,7 @@
#include "common.h"
#include <rpmatfx.h>
+#include "main.h"
#include "RwHelper.h"
#include "General.h"
#include "NodeName.h"
@@ -14,20 +15,28 @@
#include "Automobile.h"
#include "Boat.h"
#include "Train.h"
+#include "Ferry.h"
#include "Plane.h"
#include "Heli.h"
#include "Bike.h"
#include "ModelIndices.h"
#include "ModelInfo.h"
#include "custompipes.h"
+#include "Streaming.h"
+#include "Leeds.h"
-int8 CVehicleModelInfo::ms_compsToUse[2] = { -2, -2 };
-int8 CVehicleModelInfo::ms_compsUsed[2];
-RwRGBA CVehicleModelInfo::ms_vehicleColourTable[256];
-RwTexture *CVehicleModelInfo::ms_colourTextureTable[256];
+base::cRelocatableChunkClassInfo CVehicleModelInfo::msClassInfo("CVehicleModelInfo", VTABLE_ADDR(&msClassInstance), sizeof(msClassInstance));
+CVehicleModelInfo CVehicleModelInfo::msClassInstance;
-RwTexture *gpWhiteTexture;
-RwFrame *pMatFxIdentityFrame;
+//int8 CVehicleModelInfo::ms_compsToUse[2] = { -2, -2 };
+//int8 CVehicleModelInfo::ms_compsUsed[2];
+//RwRGBA CVehicleModelInfo::ms_vehicleColourTable[256];
+CVehicleModelInfo::Statics *CVehicleModelInfo::mspInfo;
+
+//RwTexture *CVehicleModelInfo::ms_colourTextureTable[256];
+
+//RwTexture *gpWhiteTexture;
+//RwFrame *pMatFxIdentityFrame;
enum {
VEHICLE_FLAG_COLLAPSE = 0x2,
@@ -114,6 +123,22 @@ RwObjectNameIdAssocation trainIds[] = {
{ nil, 0, 0 }
};
+RwObjectNameIdAssocation ferryIds[] = {
+ { "door_front_dummy", FERRY_DOOR_FRONT, VEHICLE_FLAG_LEFT | VEHICLE_FLAG_COLLAPSE },
+ { "door_back_dummy", FERRY_DOOR_BACK, VEHICLE_FLAG_LEFT | VEHICLE_FLAG_COLLAPSE },
+ { "ramp_front_dummy", FERRY_RAMP_FRONT, VEHICLE_FLAG_LEFT | VEHICLE_FLAG_COLLAPSE },
+ { "ramp_back_dummy", FERRY_RAMP_BACK, VEHICLE_FLAG_LEFT | VEHICLE_FLAG_COLLAPSE },
+ { "light_front", FERRY_POS_LIGHT_FRONT, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { "light_rear", FERRY_POS_LIGHT_REAR, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { "chim_left", FERRY_POS_CHIM_LEFT, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { "ped_point", FERRY_POS_PED_POINT, VEHICLE_FLAG_DOOR | VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { "car1_dummy", FERRY_POS_CAR1, VEHICLE_FLAG_DOOR | VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { "car2_dummy", FERRY_POS_CAR2, VEHICLE_FLAG_DOOR | VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { "car3_dummy", FERRY_POS_CAR3, VEHICLE_FLAG_DOOR | VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { "car4_dummy", FERRY_POS_CAR4, VEHICLE_FLAG_DOOR | VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
+ { nil, 0, 0 }
+};
+
RwObjectNameIdAssocation heliIds[] = {
{ "chassis_dummy", HELI_CHASSIS, VEHICLE_FLAG_COLLAPSE },
{ "toprotor", HELI_TOPROTOR, 0 },
@@ -162,12 +187,36 @@ RwObjectNameIdAssocation *CVehicleModelInfo::ms_vehicleDescs[] = {
trainIds,
heliIds,
planeIds,
- bikeIds
+ bikeIds,
+ ferryIds
};
bool gbBlackCars;
bool gbPinkCars;
+void
+CVehicleModelInfo::Load(void *inst)
+{
+ if(inst)
+ mspInfo = (CVehicleModelInfo::Statics*)inst;
+ else{
+ mspInfo = new CVehicleModelInfo::Statics;
+ memset(mspInfo, 0, sizeof(*mspInfo));
+ mspInfo->ms_compsToUse[0] = -2;
+ mspInfo->ms_compsToUse[1] = -2;
+ }
+}
+
+void*
+CVehicleModelInfo::WriteStaticInfo(base::cRelocatableChunkWriter &writer)
+{
+ writer.AllocateRaw(mspInfo, sizeof(*mspInfo), sizeof(void*), false, true);
+ if(mspInfo->unknown)
+ writer.AddPatch(&mspInfo->unknown);
+ return mspInfo;
+
+}
+
CVehicleModelInfo::CVehicleModelInfo(void)
: CClumpModelInfo(MITYPE_VEHICLE)
{
@@ -178,7 +227,12 @@ CVehicleModelInfo::CVehicleModelInfo(void)
m_positions[i].z = 0.0f;
}
m_numColours = 0;
+ CClumpModelInfo::m_animFileIndex = -1;
+
+ memset(m_materials1, 0, sizeof(m_materials1));
+ memset(m_materials2, 0, sizeof(m_materials2));
m_animFileIndex = -1;
+ m_normalSplay = 0.3f;
}
void
@@ -187,16 +241,78 @@ CVehicleModelInfo::DeleteRwObject(void)
int32 i;
RwFrame *f;
- for(i = 0; i < m_numComps; i++){
- f = RpAtomicGetFrame(m_comps[i]);
- RpAtomicDestroy(m_comps[i]);
- RwFrameDestroy(f);
+ if(!gUseChunkFiles){
+ for(i = 0; i < m_numComps; i++){
+ f = RpAtomicGetFrame(m_comps[i]);
+ RpAtomicDestroy(m_comps[i]);
+ RwFrameDestroy(f);
+ }
+#ifdef FIX_BUGS
+ delete[] m_comps;
+ m_comps = nil;
+#endif
+ m_numComps = 0;
}
- m_numComps = 0;
+
+ RemoveWheels();
+
+ for(i = 0; i < ARRAY_SIZE(m_materials1); i++)
+ CStreaming::UnregisterPointer(&m_materials1[i], 2);
+ for(i = 0; i < ARRAY_SIZE(m_materials2); i++)
+ CStreaming::UnregisterPointer(&m_materials2[i], 2);
+
+ if(m_numComps > 0){
+ CStreaming::UnregisterPointer(&m_comps, 2);
+ for(i = 0; i < m_numComps; i++)
+ CStreaming::UnregisterAtomic(m_comps[i], nil);
+ m_comps = nil;
+ }
+
CClumpModelInfo::DeleteRwObject();
}
RwObject*
+RemoveWheelCB(RwObject *object, void *arg)
+{
+ RpAtomic *atomic = (RpAtomic*)object;
+ if(RwObjectGetType(object) == rpATOMIC){
+ RpClumpRemoveAtomic((RpClump*)arg, atomic);
+#ifdef LIBRW
+ CStreaming::UnregisterPointer(&atomic->inClump.next, 2);
+ CStreaming::UnregisterPointer(&atomic->inClump.prev, 2);
+ CStreaming::UnregisterPointer(&atomic->object.object.parent, 2);
+ CStreaming::UnregisterPointer(&atomic->object.inFrame.next, 2);
+ CStreaming::UnregisterPointer(&atomic->object.inFrame.prev, 2);
+ CStreaming::UnregisterPointer(&atomic->clump, 2);
+#endif
+ RpAtomicDestroy(atomic);
+ }
+ return object;
+}
+
+void
+CVehicleModelInfo::RemoveWheels(void)
+{
+#ifdef FIX_BUGS
+ if(m_clump == nil)
+ return;
+#endif
+ RwObjectNameIdAssocation *desc = ms_vehicleDescs[m_vehicleType];
+ for(int i = 0; desc[i].name; i++){
+ RwObjectIdAssociation assoc;
+
+ if(desc[i].flags & (VEHICLE_FLAG_COMP|VEHICLE_FLAG_POS))
+ continue;
+ assoc.frame = nil;
+ assoc.id = desc[i].hierId;
+ RwFrameForAllChildren(RpClumpGetFrame(m_clump),
+ FindFrameFromIdCB, &assoc);
+ if(assoc.frame && desc[i].flags & VEHICLE_FLAG_ADD_WHEEL && m_wheelId != -1)
+ RwFrameForAllObjects(assoc.frame, RemoveWheelCB, m_clump);
+ }
+}
+
+RwObject*
CVehicleModelInfo::CreateInstance(void)
{
RpClump *clump;
@@ -205,7 +321,7 @@ CVehicleModelInfo::CreateInstance(void)
int32 comp1, comp2;
clump = (RpClump*)CClumpModelInfo::CreateInstance();
- if(m_numComps != 0){
+ if(clump && m_numComps != 0 && strcmp(m_gameName, "POLICAR") != 0){
clumpframe = RpClumpGetFrame(clump);
comp1 = ChooseComponent();
@@ -219,7 +335,7 @@ CVehicleModelInfo::CreateInstance(void)
RpClumpAddAtomic(clump, atomic);
RwFrameAddChild(clumpframe, f);
}
- ms_compsUsed[0] = comp1;
+ mspInfo->ms_compsUsed[0] = comp1;
comp2 = ChooseSecondComponent();
if(comp2 != -1 && m_comps[comp2]){
@@ -232,18 +348,27 @@ CVehicleModelInfo::CreateInstance(void)
RpClumpAddAtomic(clump, atomic);
RwFrameAddChild(clumpframe, f);
}
- ms_compsUsed[1] = comp2;
+ mspInfo->ms_compsUsed[1] = comp2;
}else{
- ms_compsUsed[0] = -1;
- ms_compsUsed[1] = -1;
+ mspInfo->ms_compsUsed[0] = -1;
+ mspInfo->ms_compsUsed[1] = -1;
}
+ CStreaming::RegisterInstance(clump);
return (RwObject*)clump;
}
+RpAtomic*
+SplayNormals(RpAtomic *atomic, void *arg)
+{
+ // PSP only?
+ return atomic;
+}
+
void
CVehicleModelInfo::SetClump(RpClump *clump)
{
CClumpModelInfo::SetClump(clump);
+ RpClumpForAllAtomics((RpClump*)GetRwObject(), SplayNormals, this);
SetAtomicRenderCallbacks();
SetFrameIds(ms_vehicleDescs[m_vehicleType]);
PreprocessHierarchy();
@@ -398,35 +523,76 @@ CVehicleModelInfo::SetAtomicRendererCB_Train(RpAtomic *atomic, void *data)
}
RpAtomic*
-CVehicleModelInfo::SetAtomicRendererCB_Boat(RpAtomic *atomic, void *data)
+CVehicleModelInfo::SetAtomicRendererCB_Ferry(RpAtomic *atomic, void *data)
{
- RpClump *clump;
char *name;
bool alpha;
- clump = (RpClump*)data;
name = GetFrameNodeName(RpAtomicGetFrame(atomic));
alpha = false;
RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), HasAlphaMaterialCB, &alpha);
- if(strcmp(name, "boat_hi") == 0 || !CGeneral::faststrncmp(name, "extra", 5))
- CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB_Boat);
- else if(strstr(name, "_hi")){
+ if(strstr(name, "_hi")){
if(alpha)
- CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat);
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderTrainHiDetailAlphaCB);
else
- CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB);
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderTrainHiDetailCB);
}else if(strstr(name, "_lo")){
+ if(alpha)
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleLowDetailAlphaCB_BigVehicle);
+ else
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleLowDetailCB_BigVehicle);
+ }else if(strstr(name, "_vlo"))
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleReallyLowDetailCB_BigVehicle);
+ else
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil);
+ HideDamagedAtomicCB(atomic, nil);
+ return atomic;
+}
+
+RpAtomic*
+CVehicleModelInfo::SetAtomicRendererCB_Boat(RpAtomic *atomic, void *data)
+{
+ RpClump *clump;
+ char *name;
+
+ clump = (RpClump*)data;
+ name = GetFrameNodeName(RpAtomicGetFrame(atomic));
+ if(strcmp(name, "boat_hi") == 0 || !CGeneral::faststrncmp(name, "extra", 5))
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB_Boat);
+ else if(strstr(name, "_hi"))
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB);
+ else if(strstr(name, "_lo")){
RpClumpRemoveAtomic(clump, atomic);
RpAtomicDestroy(atomic);
return atomic; // BUG: not done by gta
}else if(strstr(name, "_vlo"))
CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleLoDetailCB_Boat);
- else{
- if(alpha)
- CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat);
- else
- CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil);
- }
+ else
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil);
+ HideDamagedAtomicCB(atomic, nil);
+ return atomic;
+}
+
+RpAtomic*
+CVehicleModelInfo::SetAtomicRendererCB_Boat_Far(RpAtomic *atomic, void *data)
+{
+ RpClump *clump;
+ char *name;
+
+ clump = (RpClump*)data;
+ name = GetFrameNodeName(RpAtomicGetFrame(atomic));
+ if(strcmp(name, "boat_hi") == 0 || !CGeneral::faststrncmp(name, "extra", 5))
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB_Boat_Far);
+ else if(strstr(name, "_hi"))
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleHiDetailCB);
+ else if(strstr(name, "_lo")){
+ RpClumpRemoveAtomic(clump, atomic);
+ RpAtomicDestroy(atomic);
+ return atomic; // BUG: not done by gta
+ }else if(strstr(name, "_vlo"))
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleLoDetailCB_Boat_Far);
+ else
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil);
HideDamagedAtomicCB(atomic, nil);
return atomic;
}
@@ -434,6 +600,7 @@ CVehicleModelInfo::SetAtomicRendererCB_Boat(RpAtomic *atomic, void *data)
RpAtomic*
CVehicleModelInfo::SetAtomicRendererCB_Heli(RpAtomic *atomic, void *data)
{
+/* // LCS: gone, may be better to keep it though
char *name;
name = GetFrameNodeName(RpAtomicGetFrame(atomic));
@@ -442,6 +609,7 @@ CVehicleModelInfo::SetAtomicRendererCB_Heli(RpAtomic *atomic, void *data)
else if(strncmp(name, "rearrotor", 9) == 0)
CVisibilityPlugins::SetAtomicRenderCallback(atomic, CVisibilityPlugins::RenderVehicleTailRotorAlphaCB);
else
+*/
CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil);
return atomic;
}
@@ -486,13 +654,18 @@ CVehicleModelInfo::SetAtomicRenderCallbacks(void)
RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_Train, nil);
else
#endif
- if(m_vehicleType == VEHICLE_TYPE_HELI)
+ if(m_vehicleType == VEHICLE_TYPE_FERRY)
+ RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_Ferry, nil);
+ else if(m_vehicleType == VEHICLE_TYPE_HELI)
RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_Heli, nil);
else if(m_vehicleType == VEHICLE_TYPE_PLANE)
RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_BigVehicle, nil);
- else if(m_vehicleType == VEHICLE_TYPE_BOAT)
- RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_Boat, m_clump);
- else if(mod_HandlingManager.GetHandlingData((tVehicleType)m_handlingId)->Flags & HANDLING_IS_HELI)
+ else if(m_vehicleType == VEHICLE_TYPE_BOAT){
+ if(strcmp(m_gameName, "REEFER") == 0)
+ RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_Boat_Far, m_clump);
+ else
+ RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_Boat, m_clump);
+ }else if(mod_HandlingManager.GetHandlingData((tVehicleType)m_handlingId)->Flags & HANDLING_IS_HELI)
RpClumpForAllAtomics(m_clump, SetAtomicRendererCB_RealHeli, m_clump);
else
RpClumpForAllAtomics(m_clump, SetAtomicRendererCB, m_clump);
@@ -540,6 +713,8 @@ CVehicleModelInfo::PreprocessHierarchy(void)
m_numDoors = 0;
m_numComps = 0;
+ m_comps = new RpAtomic*[7];
+
for(i = 0; desc[i].name; i++){
RwObjectNameAssociation assoc;
@@ -597,21 +772,23 @@ CVehicleModelInfo::PreprocessHierarchy(void)
SetVehicleComponentFlags(assoc.frame, desc[i].flags);
- if(desc[i].flags & VEHICLE_FLAG_ADD_WHEEL){
- if(m_wheelId == -1)
- RwFrameDestroy(assoc.frame);
- else{
- RwV3d scale;
- atomic = (RpAtomic*)CModelInfo::GetModelInfo(m_wheelId)->CreateInstance();
- RwFrameDestroy(RpAtomicGetFrame(atomic));
- RpAtomicSetFrame(atomic, assoc.frame);
- RpClumpAddAtomic(m_clump, atomic);
- CVisibilityPlugins::SetAtomicRenderCallback(atomic,
- CVisibilityPlugins::RenderWheelAtomicCB);
- scale.x = m_wheelScale;
- scale.y = m_wheelScale;
- scale.z = m_wheelScale;
- RwFrameScale(assoc.frame, &scale, rwCOMBINEPRECONCAT);
+ if(!(gMakeResources && gUseResources)){
+ if(desc[i].flags & VEHICLE_FLAG_ADD_WHEEL){
+ if(m_wheelId == -1)
+ RwFrameDestroy(assoc.frame);
+ else{
+ RwV3d scale;
+ atomic = (RpAtomic*)CModelInfo::GetModelInfo(m_wheelId)->CreateInstance();
+ RwFrameDestroy(RpAtomicGetFrame(atomic));
+ RpAtomicSetFrame(atomic, assoc.frame);
+ RpClumpAddAtomic(m_clump, atomic);
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic,
+ CVisibilityPlugins::RenderWheelAtomicCB);
+ scale.x = m_wheelScale;
+ scale.y = m_wheelScale;
+ scale.z = m_wheelScale;
+ RwFrameScale(assoc.frame, &scale, rwCOMBINEPRECONCAT);
+ }
}
}
}
@@ -756,7 +933,7 @@ CVehicleModelInfo::ChooseComponent(void)
int32 n;
comp = -1;
- if(ms_compsToUse[0] == -2){
+ if(mspInfo->ms_compsToUse[0] == -2){
if(COMPRULE_RULE(m_compRules) && IsValidCompRule(COMPRULE_RULE(m_compRules)))
comp = ::ChooseComponent(COMPRULE_RULE(m_compRules), COMPRULE_COMPS(m_compRules));
else if(CGeneral::GetRandomNumberInRange(0, 3) < 2){
@@ -765,8 +942,8 @@ CVehicleModelInfo::ChooseComponent(void)
comp = comps[(int)CGeneral::GetRandomNumberInRange(0, n)];
}
}else{
- comp = ms_compsToUse[0];
- ms_compsToUse[0] = -2;
+ comp = mspInfo->ms_compsToUse[0];
+ mspInfo->ms_compsToUse[0] = -2;
}
return comp;
}
@@ -779,7 +956,7 @@ CVehicleModelInfo::ChooseSecondComponent(void)
int32 n;
comp = -1;
- if(ms_compsToUse[1] == -2){
+ if(mspInfo->ms_compsToUse[1] == -2){
if(COMPRULE2_RULE(m_compRules) && IsValidCompRule(COMPRULE2_RULE(m_compRules)))
comp = ::ChooseComponent(COMPRULE2_RULE(m_compRules), COMPRULE2_COMPS(m_compRules));
else if(COMPRULE_RULE(m_compRules) && IsValidCompRule(COMPRULE_RULE(m_compRules)) &&
@@ -790,8 +967,8 @@ CVehicleModelInfo::ChooseSecondComponent(void)
comp = comps[(int)CGeneral::GetRandomNumberInRange(0, n)];
}
}else{
- comp = ms_compsToUse[1];
- ms_compsToUse[1] = -2;
+ comp = mspInfo->ms_compsToUse[1];
+ mspInfo->ms_compsToUse[1] = -2;
}
return comp;
}
@@ -859,7 +1036,7 @@ CVehicleModelInfo::SetVehicleColour(uint8 c1, uint8 c2)
RpMaterial **matp;
if(c1 != m_currentColour1){
- col = ms_vehicleColourTable[c1];
+ col = mspInfo->ms_vehicleColourTable[c1];
for(matp = m_materials1; *matp; matp++){
colp = (RwRGBA*)RpMaterialGetColor(*matp); // get rid of const
colp->red = col.red;
@@ -870,7 +1047,7 @@ CVehicleModelInfo::SetVehicleColour(uint8 c1, uint8 c2)
}
if(c2 != m_currentColour2){
- col = ms_vehicleColourTable[c2];
+ col = mspInfo->ms_vehicleColourTable[c2];
for(matp = m_materials2; *matp; matp++){
colp = (RwRGBA*)RpMaterialGetColor(*matp); // get rid of const
colp->red = col.red;
@@ -995,8 +1172,8 @@ CVehicleModelInfo::LoadVehicleColours(void)
fd = CFileMgr::OpenFile("CARCOLS.DAT", "r");
CFileMgr::ChangeDir("\\");
- for(i = 0; i < 256; i++)
- ms_colourTextureTable[i] = nil;
+ //for(i = 0; i < 256; i++)
+ // ms_colourTextureTable[i] = nil;
section = 0;
numCols = 0;
@@ -1028,10 +1205,10 @@ CVehicleModelInfo::LoadVehicleColours(void)
}else if(section == COLOURS){
sscanf(&line[start], // BUG: games doesn't add start
"%d %d %d", &r, &g, &b);
- ms_vehicleColourTable[numCols].red = r;
- ms_vehicleColourTable[numCols].green = g;
- ms_vehicleColourTable[numCols].blue = b;
- ms_vehicleColourTable[numCols].alpha = 0xFF;
+ mspInfo->ms_vehicleColourTable[numCols].red = r;
+ mspInfo->ms_vehicleColourTable[numCols].green = g;
+ mspInfo->ms_vehicleColourTable[numCols].blue = b;
+ mspInfo->ms_vehicleColourTable[numCols].alpha = 0xFF;
numCols++;
}else if(section == CARS){
n = sscanf(&line[start], // BUG: games doesn't add start
@@ -1061,6 +1238,7 @@ CVehicleModelInfo::LoadVehicleColours(void)
void
CVehicleModelInfo::DeleteVehicleColourTextures(void)
{
+/*
int i;
for(i = 0; i < 256; i++){
@@ -1069,6 +1247,7 @@ CVehicleModelInfo::DeleteVehicleColourTextures(void)
ms_colourTextureTable[i] = nil;
}
}
+*/
}
RpMaterial*
@@ -1080,6 +1259,7 @@ CVehicleModelInfo::GetMatFXEffectMaterialCB(RpMaterial *material, void *data)
return nil;
}
+/*
RpMaterial*
CVehicleModelInfo::SetDefaultEnvironmentMapCB(RpMaterial *material, void *data)
{
@@ -1096,7 +1276,9 @@ CVehicleModelInfo::SetDefaultEnvironmentMapCB(RpMaterial *material, void *data)
}
return material;
}
+*/
+/*
RpAtomic*
CVehicleModelInfo::SetEnvironmentMapCB(RpAtomic *atomic, void *data)
{
@@ -1112,10 +1294,12 @@ CVehicleModelInfo::SetEnvironmentMapCB(RpAtomic *atomic, void *data)
}
return atomic;
}
+*/
void
CVehicleModelInfo::SetEnvironmentMap(void)
{
+/*
CSimpleModelInfo *wheelmi;
int32 i;
@@ -1133,6 +1317,7 @@ CVehicleModelInfo::SetEnvironmentMap(void)
for(i = 0; i < wheelmi->m_numAtomics; i++)
SetEnvironmentMapCB(wheelmi->m_atomics[i], nil);
}
+*/
#ifdef EXTENDED_PIPELINES
CustomPipes::AttachVehiclePipe(m_clump);
@@ -1147,21 +1332,23 @@ CVehicleModelInfo::LoadEnvironmentMaps(void)
txdslot = CTxdStore::FindTxdSlot("particle");
CTxdStore::PushCurrentTxd();
CTxdStore::SetCurrentTxd(txdslot);
- if(gpWhiteTexture == nil){
+ /*if(gpWhiteTexture == nil){
gpWhiteTexture = RwTextureRead("white", nil);
RwTextureGetName(gpWhiteTexture)[0] = '@';
RwTextureSetFilterMode(gpWhiteTexture, rwFILTERLINEAR);
- }
+ }*/
CTxdStore::PopCurrentTxd();
}
void
CVehicleModelInfo::ShutdownEnvironmentMaps(void)
{
+/*
RwTextureDestroy(gpWhiteTexture);
gpWhiteTexture = nil;
RwFrameDestroy(pMatFxIdentityFrame);
pMatFxIdentityFrame = nil;
+*/
}
int
@@ -1184,10 +1371,162 @@ CVehicleModelInfo::GetMaximumNumberOfPassengersFromNumberOfDoors(int id)
}
if(n == 0)
- return id == MI_RCBANDIT || id == MI_PIZZABOY || id == MI_BAGGAGE ? 0 : 1;
+ return id == MI_RCBANDIT /*|| id == MI_PIZZABOY || id == MI_BAGGAGE*/ ? 0 : 1;
if(id == MI_COACH)
return 8;
return n - 1;
}
+
+
+struct VehicleChunk
+{
+ RpClump *clump;
+ int32 numComps;
+ RpAtomic **comp;
+ RpMaterial *materials1[NUM_FIRST_MATERIALS];
+ RpMaterial *materials2[NUM_SECOND_MATERIALS];
+};
+
+void
+CVehicleModelInfo::LoadModel(void *data, const void *chunk)
+{
+ int i;
+ VehicleChunk *chk = (VehicleChunk*)data;
+ CClumpModelInfo::LoadModel(chk->clump, chunk);
+
+ // editable materials
+ for(i = 0; i < NUM_FIRST_MATERIALS; i++){
+ m_materials1[i] = chk->materials1[i];
+ if(m_materials1[i])
+ CStreaming::RegisterPointer(&m_materials1[i], 2, true);
+ }
+ for(i = 0; i < NUM_SECOND_MATERIALS; i++){
+ m_materials2[i] = chk->materials2[i];
+ if(m_materials2[i])
+ CStreaming::RegisterPointer(&m_materials2[i], 2, true);
+ }
+
+ // extra components
+ m_numComps = chk->numComps;
+ if(m_numComps > 0){
+ m_comps = chk->comp;
+ CStreaming::RegisterPointer(&m_comps, 2, true);
+ for(i = 0; i < m_numComps; i++){
+ LoadResource(m_comps[i]);
+ CStreaming::RegisterAtomic(m_comps[i], nil);
+ }
+ }else
+ m_comps = nil;
+
+ m_currentColour1 = -1;
+ m_currentColour2 = -1;
+
+ // add wheels
+ RwObjectNameIdAssocation *desc = ms_vehicleDescs[m_vehicleType];
+ for(i = 0; desc[i].name; i++){
+ RwObjectIdAssociation assoc;
+
+ if(desc[i].flags & (VEHICLE_FLAG_COMP|VEHICLE_FLAG_POS))
+ continue;
+ assoc.frame = nil;
+ assoc.id = desc[i].hierId;
+ RwFrameForAllChildren(RpClumpGetFrame(m_clump),
+ FindFrameFromIdCB, &assoc);
+ if(assoc.frame && desc[i].flags & VEHICLE_FLAG_ADD_WHEEL && m_wheelId != -1){
+ RwV3d scale;
+ RpAtomic *atomic = (RpAtomic*)CModelInfo::GetModelInfo(m_wheelId)->CreateInstance();
+ RwFrameDestroy(RpAtomicGetFrame(atomic));
+ RpAtomicSetFrame(atomic, assoc.frame);
+ RpClumpAddAtomic(m_clump, atomic);
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic,
+ CVisibilityPlugins::RenderWheelAtomicCB);
+ scale.x = m_wheelScale;
+ scale.y = m_wheelScale;
+ scale.z = m_wheelScale;
+ RwFrameScale(assoc.frame, &scale, rwCOMBINEPRECONCAT);
+#ifdef LIBRW
+ CStreaming::RegisterPointer(&atomic->inClump.next, 2, true);
+ CStreaming::RegisterPointer(&atomic->inClump.prev, 2, true);
+ CStreaming::RegisterPointer(&atomic->object.object.parent, 2, true);
+ CStreaming::RegisterPointer(&atomic->object.inFrame.next, 2, true);
+ CStreaming::RegisterPointer(&atomic->object.inFrame.prev, 2, true);
+ CStreaming::RegisterPointer(&atomic->clump, 2, true);
+#endif
+ }
+ }
+}
+
+void
+CVehicleModelInfo::Write(base::cRelocatableChunkWriter &writer)
+{
+ CClumpModelInfo::Write(writer);
+}
+
+void*
+CVehicleModelInfo::WriteModel(base::cRelocatableChunkWriter &writer)
+{
+ if(GetRwObject() == nil)
+ return nil;
+
+ int i;
+ VehicleChunk *chk = new VehicleChunk;
+ memset(chk, 0, sizeof(*chk));
+ writer.AllocateRaw(chk, sizeof(*chk), sizeof(void*), false, true);
+
+ // clump
+ chk->clump = (RpClump*)CClumpModelInfo::WriteModel(writer);
+ if(chk->clump)
+ writer.AddPatch(&chk->clump);
+
+ // materials
+ for(i = 0; i < NUM_FIRST_MATERIALS; i++){
+ if(m_materials1[i] == nil || m_vehicleType == VEHICLE_TYPE_FERRY)
+ chk->materials1[i] = nil;
+ else{
+ SaveResource(m_materials1[i], writer);
+ chk->materials1[i] = m_materials1[i];
+ writer.AddPatch(&chk->materials1[i]);
+ }
+ }
+ for(i = 0; i < NUM_SECOND_MATERIALS; i++){
+ if(m_materials2[i] == nil || m_vehicleType == VEHICLE_TYPE_FERRY)
+ chk->materials2[i] = nil;
+ else{
+ SaveResource(m_materials2[i], writer);
+ chk->materials2[i] = m_materials2[i];
+ writer.AddPatch(&chk->materials2[i]);
+ }
+ }
+
+ // extra components
+ chk->numComps = m_numComps;
+ chk->comp = nil;
+ if(m_numComps > 0){
+ chk->comp = m_comps;
+ writer.AddPatch(&chk->comp);
+
+ writer.AllocateRaw(m_comps, m_numComps*sizeof(void*), sizeof(void*), false, true);
+ for(i = 0; i < m_numComps; i++)
+ if(m_comps[i]){
+ SaveResource(m_comps[i], writer);
+ writer.AddPatch(&m_comps[i]);
+ }
+ }
+ return chk;
+}
+
+void
+CVehicleModelInfo::RcWriteThis(base::cRelocatableChunkWriter &writer)
+{
+ writer.AllocateRaw(this, sizeof(*this), sizeof(void*), false, true);
+ writer.Class(VTABLE_ADDR(this), msClassInfo);
+}
+
+void
+CVehicleModelInfo::RcWriteEmpty(base::cRelocatableChunkWriter &writer)
+{
+ writer.AllocateRaw(this, sizeof(*this), sizeof(void*), false, true);
+ writer.Class(VTABLE_ADDR(this), msClassInfo);
+}