summaryrefslogtreecommitdiffstats
path: root/src/core/FileLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/FileLoader.cpp')
-rw-r--r--src/core/FileLoader.cpp119
1 files changed, 96 insertions, 23 deletions
diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp
index 4ad53572..d57bdd92 100644
--- a/src/core/FileLoader.cpp
+++ b/src/core/FileLoader.cpp
@@ -291,7 +291,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
{
int i;
- model.boundingSphere.radius = *(float*)(buf);
+ model.boundingSphere.radius = Max(*(float*)(buf), 0.1f);
model.boundingSphere.center.x = *(float*)(buf+4);
model.boundingSphere.center.y = *(float*)(buf+8);
model.boundingSphere.center.z = *(float*)(buf+12);
@@ -304,10 +304,13 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
model.numSpheres = *(int16*)(buf+40);
buf += 44;
if(model.numSpheres > 0){
- model.spheres = (CColSphere*)RwMalloc(model.numSpheres*sizeof(CColSphere));
+ model.spheres = new CColSphere[model.numSpheres];
REGISTER_MEMPTR(&model.spheres);
for(i = 0; i < model.numSpheres; i++){
- model.spheres[i].Set(*(float*)buf, *(CVector*)(buf+4), buf[16], buf[17]);
+ float radius = *(float*)buf;
+ if(radius > model.boundingSphere.radius)
+ model.boundingSphere.radius = radius + 0.01f;
+ model.spheres[i].Set(radius, *(CVector*)(buf+4), buf[16], buf[17]);
buf += 20;
}
}else
@@ -316,7 +319,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
model.numLines = *(int16*)buf;
buf += 4;
if(model.numLines > 0){
- //model.lines = (CColLine*)RwMalloc(model.numLines*sizeof(CColLine));
+ //model.lines = new CColLine[model.numLines];;
REGISTER_MEMPTR(&model.lines);
for(i = 0; i < model.numLines; i++){
//model.lines[i].Set(*(CVector*)buf, *(CVector*)(buf+12));
@@ -330,7 +333,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
model.numBoxes = *(int16*)buf;
buf += 4;
if(model.numBoxes > 0){
- model.boxes = (CColBox*)RwMalloc(model.numBoxes*sizeof(CColBox));
+ model.boxes = new CColBox[model.numBoxes];
REGISTER_MEMPTR(&model.boxes);
for(i = 0; i < model.numBoxes; i++){
model.boxes[i].Set(*(CVector*)buf, *(CVector*)(buf+12), buf[24], buf[25]);
@@ -342,7 +345,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
int32 numVertices = *(int16*)buf;
buf += 4;
if(numVertices > 0){
- model.vertices = (CompressedVector*)RwMalloc(numVertices*sizeof(CompressedVector));
+ model.vertices = new CompressedVector[numVertices];
REGISTER_MEMPTR(&model.vertices);
for(i = 0; i < numVertices; i++){
model.vertices[i].Set(*(float*)buf, *(float*)(buf+4), *(float*)(buf+8));
@@ -360,14 +363,64 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
model.numTriangles = *(int16*)buf;
buf += 4;
if(model.numTriangles > 0){
- model.triangles = (CColTriangle*)RwMalloc(model.numTriangles*sizeof(CColTriangle));
+ model.triangles = new CColTriangle[model.numTriangles];
REGISTER_MEMPTR(&model.triangles);
for(i = 0; i < model.numTriangles; i++){
model.triangles[i].Set(*(int32*)buf, *(int32*)(buf+4), *(int32*)(buf+8), buf[12]);
buf += 16;
+
+ // skip small triangles
+ CVector vA = model.vertices[model.triangles[i].a].Get();
+ CVector vB = model.vertices[model.triangles[i].b].Get();
+ CVector vC = model.vertices[model.triangles[i].c].Get();
+ float area = CrossProduct(vA - vB, vA - vC).Magnitude();
+ if(area < 0.001f || vA == vB || vA == vC || vB == vC){
+ i--;
+ model.numTriangles--;
+ }
}
}else
model.triangles = nil;
+
+ SplitColTrianglesIntoSections(model);
+}
+
+void
+CFileLoader::SplitColTrianglesIntoSections(CColModel &model)
+{
+ if(model.triangles == nil || model.numTriangles == 0)
+ return;
+
+ model.numTriBBoxes = 1;
+ model.triBBoxes = new CColTriBBox[1];
+ model.triBBoxes[0].first = 0;
+ model.triBBoxes[0].last = model.numTriangles-1;
+ CVector v = model.vertices[model.triangles[0].a].Get();
+ model.triBBoxes[0].Set(v, v);
+
+ for(int i = 0; i < model.numTriangles; i++){
+ CVector vA = model.vertices[model.triangles[i].a].Get();
+ CVector vB = model.vertices[model.triangles[i].b].Get();
+ CVector vC = model.vertices[model.triangles[i].c].Get();
+ model.triBBoxes[0].min.x = Min(vA.x, model.triBBoxes[0].min.x);
+ model.triBBoxes[0].min.y = Min(vA.y, model.triBBoxes[0].min.y);
+ model.triBBoxes[0].min.z = Min(vA.z, model.triBBoxes[0].min.z);
+ model.triBBoxes[0].min.x = Min(vB.x, model.triBBoxes[0].min.x);
+ model.triBBoxes[0].min.y = Min(vB.y, model.triBBoxes[0].min.y);
+ model.triBBoxes[0].min.z = Min(vB.z, model.triBBoxes[0].min.z);
+ model.triBBoxes[0].min.x = Min(vC.x, model.triBBoxes[0].min.x);
+ model.triBBoxes[0].min.y = Min(vC.y, model.triBBoxes[0].min.y);
+ model.triBBoxes[0].min.z = Min(vC.z, model.triBBoxes[0].min.z);
+ model.triBBoxes[0].max.x = Max(vA.x, model.triBBoxes[0].max.x);
+ model.triBBoxes[0].max.y = Max(vA.y, model.triBBoxes[0].max.y);
+ model.triBBoxes[0].max.z = Max(vA.z, model.triBBoxes[0].max.z);
+ model.triBBoxes[0].max.x = Max(vB.x, model.triBBoxes[0].max.x);
+ model.triBBoxes[0].max.y = Max(vB.y, model.triBBoxes[0].max.y);
+ model.triBBoxes[0].max.z = Max(vB.z, model.triBBoxes[0].max.z);
+ model.triBBoxes[0].max.x = Max(vC.x, model.triBBoxes[0].max.x);
+ model.triBBoxes[0].max.y = Max(vC.y, model.triBBoxes[0].max.y);
+ model.triBBoxes[0].max.z = Max(vC.z, model.triBBoxes[0].max.z);
+ }
}
static void
@@ -608,11 +661,14 @@ CFileLoader::LoadObjectTypes(const char *filename)
int section;
int pathIndex;
int id, pathType;
- int minID, maxID;
+ //int minID, maxID;
+
+ for(int i = 0; i < ARRAY_SIZE(m_sTempIdeData); i++)
+ m_sTempIdeData[i].id = -1;
section = NONE;
- minID = INT32_MAX;
- maxID = -1;
+ //minID = INT32_MAX;
+ //maxID = -1;
pathIndex = -1;
debug("Loading object types from %s...\n", filename);
@@ -636,13 +692,13 @@ CFileLoader::LoadObjectTypes(const char *filename)
}else switch(section){
case OBJS:
id = LoadObject(line);
- if(id > maxID) maxID = id;
- if(id < minID) minID = id;
+ //if(id > maxID) maxID = id;
+ //if(id < minID) minID = id;
break;
case TOBJ:
id = LoadTimeObject(line);
- if(id > maxID) maxID = id;
- if(id < minID) minID = id;
+ //if(id > maxID) maxID = id;
+ //if(id < minID) minID = id;
break;
case WEAP:
LoadWeaponObject(line);
@@ -679,10 +735,10 @@ CFileLoader::LoadObjectTypes(const char *filename)
}
CFileMgr::CloseFile(fd);
- for(id = minID; id <= maxID; id++){
+ for(id = 0; id < MODELINFOSIZE; id++){
CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(id);
if(mi && mi->IsBuilding())
- mi->SetupBigBuilding(minID, maxID);
+ mi->SetupBigBuilding();
}
}
@@ -715,6 +771,13 @@ CFileLoader::LoadObject(const char *line)
if(sscanf(line, "%d %s %s %d", &id, model, txd, &numObjs) != 4)
return 0; // game returns return value
+ for(int i = 0; i < ARRAY_SIZE(m_sTempIdeData); i++)
+ if(m_sTempIdeData[i].id == -1){
+ m_sTempIdeData[i].id = id;
+ strcpy(m_sTempIdeData[i].name, model);
+ break;
+ }
+
switch(numObjs){
case 1:
sscanf(line, "%d %s %s %d %f %d",
@@ -763,6 +826,13 @@ CFileLoader::LoadTimeObject(const char *line)
if(sscanf(line, "%d %s %s %d", &id, model, txd, &numObjs) != 4)
return 0; // game returns return value
+ for(int i = 0; i < ARRAY_SIZE(m_sTempIdeData); i++)
+ if(m_sTempIdeData[i].id < 0){
+ m_sTempIdeData[i].id = id;
+ strcpy(m_sTempIdeData[i].name, model);
+ break;
+ }
+
switch(numObjs){
case 1:
sscanf(line, "%d %s %s %d %f %d %d %d",
@@ -793,7 +863,7 @@ CFileLoader::LoadTimeObject(const char *line)
mi->m_firstDamaged = damaged;
mi->SetTimes(timeOn, timeOff);
mi->SetTexDictionary(txd);
- other = mi->FindOtherTimeModel();
+ other = mi->FindOtherTimeModel(model);
if(other)
other->SetOtherTimeModel(id);
MatchModelString(model, id);
@@ -817,7 +887,7 @@ CFileLoader::LoadWeaponObject(const char *line)
mi->m_lodDistances[0] = dist;
mi->SetTexDictionary(txd);
mi->SetAnimFile(animFile);
- mi->SetColModel(&CTempColModels::ms_colModelWeapon);
+ mi->SetColModel(&gpTempColModels->ms_colModelWeapon);
MatchModelString(model, id);
return id;
}
@@ -833,7 +903,7 @@ CFileLoader::LoadClumpObject(const char *line)
mi = CModelInfo::AddClumpModel(id);
mi->SetModelName(model);
mi->SetTexDictionary(txd);
- mi->SetColModel(&CTempColModels::ms_colModelBBox);
+ mi->SetColModel(&gpTempColModels->ms_colModelBBox);
}
}
@@ -845,14 +915,15 @@ CFileLoader::LoadVehicleObject(const char *line)
char type[8], handlingId[16], gamename[32], animFile[16], vehclass[12];
uint32 frequency, comprules;
int32 level, misc;
- float wheelScale;
+ float wheelScale, normalSplay;
CVehicleModelInfo *mi;
char *p;
- sscanf(line, "%d %s %s %s %s %s %s %s %d %d %x %d %f",
+ sscanf(line, "%d %s %s %s %s %s %s %s %d %d %x %d %f %f",
&id, model, txd,
type, handlingId, gamename, animFile, vehclass,
- &frequency, &level, &comprules, &misc, &wheelScale);
+ &frequency, &level, &comprules, &misc, &wheelScale,
+ &normalSplay);
mi = CModelInfo::AddVehicleModel(id);
mi->SetModelName(model);
@@ -872,6 +943,8 @@ CFileLoader::LoadVehicleObject(const char *line)
mi->m_vehicleType = VEHICLE_TYPE_BOAT;
}else if(strcmp(type, "train") == 0){
mi->m_vehicleType = VEHICLE_TYPE_TRAIN;
+ }else if(strcmp(type, "ferry") == 0){
+ mi->m_vehicleType = VEHICLE_TYPE_FERRY;
}else if(strcmp(type, "heli") == 0){
mi->m_vehicleType = VEHICLE_TYPE_HELI;
}else if(strcmp(type, "plane") == 0){
@@ -937,7 +1010,7 @@ CFileLoader::LoadPedObject(const char *line)
mi->SetModelName(model);
mi->SetTexDictionary(txd);
mi->SetAnimFile(animFile);
- mi->SetColModel(&CTempColModels::ms_colModelPed1);
+ mi->SetColModel(&gpTempColModels->ms_colModelPed1);
mi->m_pedType = CPedType::FindPedType(pedType);
mi->m_pedStatType = CPedStats::GetPedStatType(pedStats);
for(animGroupId = 0; animGroupId < NUM_ANIM_ASSOC_GROUPS; animGroupId++)