- refactor ProcessMDSLump and check MODELS.C

This commit is contained in:
Ilya Shurumov 2020-11-07 23:37:23 +06:00
parent d8a2f00f9d
commit fedbbc26ab
4 changed files with 60 additions and 78 deletions

View File

@ -16,6 +16,10 @@ extern unsigned char lightsOnDelay[MAX_CARS];
extern CAR_MODEL NewCarModel[MAX_CAR_MODELS];
extern CAR_MODEL NewLowCarModel[MAX_CAR_MODELS];
extern MODEL* gCarLowModelPtr[MAX_CAR_MODELS];
extern MODEL* gCarDamModelPtr[MAX_CAR_MODELS];
extern MODEL* gCarCleanModelPtr[MAX_CAR_MODELS];
extern int whichCP; // car poly counter
extern int baseSpecCP; // special car poly counter

View File

@ -12,12 +12,14 @@ MODEL dummyModel = { 0 };
char* modelname_buffer = NULL;
char *car_models_lump = NULL;
MODEL* modelpointers[1536] = { NULL };
MODEL* modelpointers[MAX_MODEL_SLOTS];
MODEL* pLodModels[MAX_MODEL_SLOTS];
int num_models_in_pack = 0;
unsigned short *Low2HighDetailTable = NULL;
unsigned short *Low2LowerDetailTable = NULL;
MODEL* pLodModels[1536];
// decompiled code
// original method signature:
@ -47,52 +49,41 @@ MODEL* pLodModels[1536];
/* end block 3 */
// End Line: 79
// [D]
// [D] [T]
void ProcessMDSLump(char *lump_file, int lump_size)
{
int iVar1;
MODEL **ppMVar2;
char* ptr;
char* mdsfile;
MODEL *model;
MODEL *parentmodel;
int iVar4;
int modelAmts;
int i;
int i, size;
modelAmts = *(int *)lump_file;
ptr = (lump_file + 4);
mdsfile = (lump_file + 4);
num_models_in_pack = modelAmts;
// assign model pointers
if (0 < modelAmts)
for (i = 0; i < MAX_MODEL_SLOTS; i++) // [A] bug fix. Init with dummyModel
{
for (i = 0; i < 1536; i++) // [A] bug fix. Init with dummyModel
modelpointers[i] = &dummyModel;
ppMVar2 = modelpointers;
iVar4 = modelAmts;
pLodModels[i] = &dummyModel;
}
for (i = 0; i < modelAmts; i++)
{
int size = *(int*)ptr;
ptr += sizeof(int);
size = *(int*)mdsfile;
mdsfile += sizeof(int);
if (size)
modelpointers[i] = (MODEL*)ptr;
modelpointers[i] = (MODEL*)mdsfile;
ptr += size;
mdsfile += size;
}
}
if (0 < modelAmts)
{
ppMVar2 = modelpointers;
iVar4 = modelAmts;
// process parent instances
do {
model = *ppMVar2;
for (i = 0; i < modelAmts; i++)
{
model = modelpointers[i];
if (model->instance_number != -1)
{
@ -106,18 +97,12 @@ void ProcessMDSLump(char *lump_file, int lump_size)
model->normals = (int)(char*)parentmodel + parentmodel->normals;
model->point_normals = (int)(char*)parentmodel + parentmodel->point_normals;
}
iVar4--;
ppMVar2++;
} while (iVar4 != 0);
}
// process models without parents
if (0 < modelAmts)
for (i = 0; i < modelAmts; i++)
{
ppMVar2 = modelpointers;
do {
model = *ppMVar2;
model = modelpointers[i];
if (model->instance_number == -1)
{
@ -130,10 +115,6 @@ void ProcessMDSLump(char *lump_file, int lump_size)
}
model->poly_block += (int)(char*)model;
modelAmts--;
ppMVar2++;
} while (modelAmts != 0);
}
}
@ -185,10 +166,9 @@ void ProcessMDSLump(char *lump_file, int lump_size)
/* end block 5 */
// End Line: 460
// [D]
// [D] [T]
int ProcessCarModelLump(char *lump_ptr, int lump_size)
{
int size;
int *offsets;
char *models_offset;
@ -346,7 +326,7 @@ int ProcessCarModelLump(char *lump_ptr, int lump_size)
/* end block 3 */
// End Line: 1175
// [D]
// [D] [T]
MODEL* GetCarModel(char *src, char **dest, int KeepNormals)
{
int size;
@ -357,11 +337,11 @@ MODEL* GetCarModel(char *src, char **dest, int KeepNormals)
char* mem = src;
if (KeepNormals == 0)
size = ((MODEL*)src)->normals;
size = ((MODEL*)mem)->normals;
else
size = ((MODEL*)src)->poly_block;
size = ((MODEL*)mem)->poly_block;
memcpy(*dest, src, size);
memcpy(*dest, mem, size);
if (KeepNormals == 0)
size = model->normals;
@ -372,7 +352,7 @@ MODEL* GetCarModel(char *src, char **dest, int KeepNormals)
model->vertices += (int)model;
model->normals += (int)model;
model->poly_block = (int)src + model->poly_block;
model->poly_block = (int)mem + model->poly_block;
if (KeepNormals == 0)
model->point_normals = 0;

View File

@ -5,15 +5,12 @@ extern MODEL dummyModel;
extern char* modelname_buffer;
extern char *car_models_lump;
extern MODEL* modelpointers[1536];
extern MODEL* modelpointers[MAX_MODEL_SLOTS];
extern MODEL* pLodModels[MAX_MODEL_SLOTS];
extern unsigned short *Low2HighDetailTable;
extern unsigned short *Low2LowerDetailTable;
extern MODEL* pLodModels[1536];
extern MODEL* gCarLowModelPtr[5];
extern MODEL* gCarDamModelPtr[5];
extern MODEL* gCarCleanModelPtr[5];
extern int num_models_in_pack;

View File

@ -4,6 +4,7 @@
// DRIVER 2 game engine limits
// please populate this file only with engine limits during refactoring
#define MAX_MODEL_SLOTS 1536 // DO NOT CHANGE. No effect in upping it - limited by cell types
#define MAX_CARS 20
#define MAX_CAR_MODELS 5