- hold special car cosmetics in RAM

This commit is contained in:
Ilya Shurumov 2021-04-09 19:01:38 +06:00
parent 8a9b42ee2c
commit 51a32cbc2b

View File

@ -24,17 +24,19 @@ char* CosmeticFiles[] = {
CAR_COSMETICS car_cosmetics[MAX_CAR_MODELS]; CAR_COSMETICS car_cosmetics[MAX_CAR_MODELS];
// [A] storage for spooled models
// remember: we already have more than 1k of free memory with optimizations
CAR_COSMETICS levelSpecCosmetics[5];
// [D] [T] // [D] [T]
void ProcessCosmeticsLump(char *lump_ptr, int lump_size) void ProcessCosmeticsLump(char *lump_ptr, int lump_size)
{ {
int model; int model;
char* ptr;
int i; int i;
int offset; int offset;
i = 0; for (i = 0; i < MAX_CAR_MODELS; i++)
{
do {
model = MissionHeader->residentModels[i]; model = MissionHeader->residentModels[i];
if (model == 13) if (model == 13)
@ -50,16 +52,20 @@ void ProcessCosmeticsLump(char *lump_ptr, int lump_size)
if (model != -1) if (model != -1)
{ {
offset = *(int*)(lump_ptr + model * sizeof(int)); offset = *(int*)(lump_ptr + model * sizeof(int));
memcpy((char*)&car_cosmetics[i], lump_ptr + offset, sizeof(CAR_COSMETICS));
ptr = (lump_ptr + offset);
memcpy((char*)&car_cosmetics[i], ptr, sizeof(CAR_COSMETICS));
FixCarCos(&car_cosmetics[i], model); FixCarCos(&car_cosmetics[i], model);
} }
}
i++; // [A] cache all special vehicle cosmetics
} while (i < MAX_CAR_MODELS); for (i = 0; i < 5; i++)
{
model = 8 + i;
offset = *(int*)(lump_ptr + model * sizeof(int));
memcpy((char*)&levelSpecCosmetics[i], lump_ptr + offset, sizeof(CAR_COSMETICS));
}
} }
// [D] [T] // [D] [T]
@ -112,15 +118,9 @@ void SetupSpecCosmetics(char *loadbuffer)
int model; int model;
model = MissionHeader->residentModels[4]; model = MissionHeader->residentModels[4];
#ifndef PSX #if 1
int offset; // [A] always use cached cosmetics
memcpy((char*)&car_cosmetics[4], (char*)&levelSpecCosmetics[model - 8], sizeof(CAR_COSMETICS));
// [A] always load cosmetics from file
// fixes limo cosmetics as well
LoadfileSeg(CosmeticFiles[GameLevel], (char*)_other_buffer, 0, 3120);
offset = *(int*)(_other_buffer + model * sizeof(int));
memcpy((char*)&car_cosmetics[4], (char*)_other_buffer + offset, sizeof(CAR_COSMETICS));
#else #else
memcpy((char*)&car_cosmetics[4], loadbuffer, sizeof(CAR_COSMETICS)); memcpy((char*)&car_cosmetics[4], loadbuffer, sizeof(CAR_COSMETICS));
#endif #endif
@ -129,8 +129,6 @@ void SetupSpecCosmetics(char *loadbuffer)
FixCarCos(&car_cosmetics[4], model); FixCarCos(&car_cosmetics[4], model);
} }
// [D] [T] // [D] [T]
void AddIndicatorLight(CAR_DATA *cp, int Type) void AddIndicatorLight(CAR_DATA *cp, int Type)
{ {