summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2021-02-09 17:35:41 +0100
committeraap <aap@papnet.eu>2021-02-09 17:45:02 +0100
commit031df369351eebc5fe8c5e77d9de7f5525831c92 (patch)
treebd961e6d524150d16f2d0b7affd1cf1dd1ad526a /src/core
parentMerge pull request #1013 from Nick007J/lcs (diff)
downloadre3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar
re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.gz
re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.bz2
re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.lz
re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.xz
re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.zst
re3-031df369351eebc5fe8c5e77d9de7f5525831c92.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/FileLoader.cpp68
-rw-r--r--src/core/FileLoader.h1
-rw-r--r--src/core/main.cpp1
-rw-r--r--src/core/main.h1
4 files changed, 64 insertions, 7 deletions
diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp
index 2818007b..f2d925fc 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,8 @@ 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));
buf += 24;
@@ -329,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]);
@@ -341,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));
@@ -359,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 == vB || 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
diff --git a/src/core/FileLoader.h b/src/core/FileLoader.h
index 077e7bdd..3a7d43a7 100644
--- a/src/core/FileLoader.h
+++ b/src/core/FileLoader.h
@@ -11,6 +11,7 @@ public:
static bool LoadCollisionFileFirstTime(uint8 *buffer, uint32 size, uint8 colSlot);
static bool LoadCollisionFile(uint8 *buffer, uint32 size, uint8 colSlot);
static void LoadCollisionModel(uint8 *buf, struct CColModel &model, char *name);
+ static void SplitColTrianglesIntoSections(CColModel &model);
static void LoadModelFile(const char *filename);
static RpAtomic *FindRelatedModelInfoCB(RpAtomic *atomic, void *data);
static void LoadClumpFile(const char *filename);
diff --git a/src/core/main.cpp b/src/core/main.cpp
index c3286ea9..936b0c31 100644
--- a/src/core/main.cpp
+++ b/src/core/main.cpp
@@ -88,6 +88,7 @@ bool gUseChunkFiles = false;
bool gSecondExportPass;
bool gUseModelResources;
bool gUseResources;
+bool gNASTY_NASTY_MEM_SHUTDOWN_HACK; // rather unused
float FramesPerSecond = 30.0f;
diff --git a/src/core/main.h b/src/core/main.h
index 98813470..8e4123ff 100644
--- a/src/core/main.h
+++ b/src/core/main.h
@@ -30,6 +30,7 @@ extern bool gUseChunkFiles;
extern bool gSecondExportPass;
extern bool gUseModelResources;
extern bool gUseResources;
+extern bool gNASTY_NASTY_MEM_SHUTDOWN_HACK;
class CSprite2d;