- miscellaneous changes & cleanups

This commit is contained in:
Ilya Shurumov 2021-03-27 23:23:37 +06:00
parent 6e08f2452b
commit ac81375296
3 changed files with 49 additions and 46 deletions

View File

@ -86,34 +86,39 @@ sdPlane* sdGetCell_alpha16(VECTOR* pos)
sdPlane* plane;
int iVar1;
short* BSPSurface;
int cellPos_x;
int cellPos_z;
XYPAIR cellPos;
XYPAIR cell;
short* surface;
short* HSurface;
short* buffer;
bool nextLevel;
int nextLevel;
cellPos_x = pos->vx - 512;
cellPos_z = pos->vz - 512;
cellPos.x = pos->vx - 512;
cellPos.y = pos->vz - 512;
buffer = *(short**)((int)RoadMapDataRegions + (cellPos_x >> 14 & 4U ^ cellPos_z >> 13 & 8U ^ sdSelfModifyingCode)); // pointless, but i'll keep it there
cell.x = cellPos.x & 1023;
cell.y = cellPos.y & 1023;
cell.x = cellPos_x & 1023;
cell.y = cellPos_z & 1023;
buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1) ^ (regions_across / 2 & 1) +
(cellPos.y >> 15 & 2) ^ (regions_down & 2)];
surface = &buffer[(cellPos_x >> 10 & 0x3fU) + (cellPos_z >> 10 & 0x3fU) * MAP_REGION_SIZE * 2 + 4];
// Alpha 1.6 code, works too; not widely tested yet
//buffer = *(short**)((int)RoadMapDataRegions + (cellPos.x >> 14 & 4 ^ cellPos.y >> 13 & 8 ^ sdSelfModifyingCode));
if (*surface == -1)
{
plane = NULL;
}
else
plane = NULL;
if (*buffer == 2)
{
sdPlane* planeData = (sdPlane*)((char*)buffer + buffer[1]);
short* bspData = (short*)((char*)buffer + buffer[2]);
sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]);
surface = &buffer[(cellPos.x >> 10 & 63) +
(cellPos.y >> 10 & 63) * 64 + 4];
// initial surface
if (*surface == -1)
return GetSeaPlane();
// check surface has overlapping planes flag (aka multiple levels)
if (*surface & 0x8000)
{
@ -133,25 +138,29 @@ sdPlane* sdGetCell_alpha16(VECTOR* pos)
// iterate surfaces if BSP
do {
nextLevel = false;
BSPSurface = surface;
nextLevel = 0;
// check if it's has BSP properties
// basically it determines surface bounds
if (*surface & 0x4000)
{
BSPSurface = sdGetBSP(&nodeData[*surface & 0x1fff], &cell);
// get closest surface by BSP lookup
BSPSurface = sdGetBSP(&nodeData[*surface & 0x1fff], &cell); // 0x3fff in final
if (*BSPSurface == 0x7fff)
{
nextLevel = true;
BSPSurface = surface + 2;
sdLevel++;
nextLevel = 1;
BSPSurface = surface + 2; // get to the next node
}
surface = BSPSurface;
}
surface = BSPSurface;
} while (nextLevel);
plane = &planeData[*BSPSurface];
plane = &planeData[*surface];
}
return plane;
}
@ -204,7 +213,7 @@ int RoadInCell_alpha16(VECTOR *pos)
// basically it determines surface bounds
if (*check & 0x4000)
{
sdNode* search = &nodeData[*check & 0x1fff];
sdNode* search = &nodeData[*check & 0x1fff]; // 0x3fff in final
while (search->value < 0)
{

View File

@ -311,9 +311,7 @@ sdPlane* sdGetCell(VECTOR *pos)
#ifndef PSX
if (gDemoLevel)
{
return sdGetCell_alpha16(pos);
}
#endif
sdLevel = 0;
@ -321,16 +319,14 @@ sdPlane* sdGetCell(VECTOR *pos)
cellPos.x = pos->vx - 512;
cellPos.y = pos->vz - 512;
// [A] WARNING!
// retail version of game with exe dated before 20th October 2000 (so called 1.0) is only supported
// the later version of the game do have problem with height or BSP, so Havana's secret base ground is not solid
// reason is unknown
cell.x = cellPos.x & 1023;
cell.y = cellPos.y & 1023;
buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1U) ^ (regions_across / 2 & 1) +
(cellPos.y >> 15 & 2U) ^ (regions_down & 2)];
buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1) ^ (regions_across / 2 & 1) +
(cellPos.y >> 15 & 2) ^ (regions_down & 2)];
// Alpha 1.6 code, works too; not widely tested yet
//buffer = *(short**)((int)RoadMapDataRegions + (cellPos.x >> 14 & 4U ^ cellPos.y >> 13 & 8U ^ sdSelfModifyingCode));
//buffer = *(short**)((int)RoadMapDataRegions + (cellPos.x >> 14 & 4 ^ cellPos.y >> 13 & 8 ^ sdSelfModifyingCode));
plane = NULL;
@ -340,8 +336,8 @@ sdPlane* sdGetCell(VECTOR *pos)
short* bspData = (short*)((char*)buffer + buffer[2]);
sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]);
surface = &buffer[(cellPos.x >> 10 & 0x3fU) +
(cellPos.y >> 10 & 0x3fU) * MAP_REGION_SIZE*2 + 4];
surface = &buffer[(cellPos.x >> 10 & 63) +
(cellPos.y >> 10 & 63) * 64 + 4];
// initial surface
if (*surface == -1)
@ -372,9 +368,6 @@ sdPlane* sdGetCell(VECTOR *pos)
// basically it determines surface bounds
if (*surface & 0x4000)
{
cell.x = cellPos.x & 0x3ff;
cell.y = cellPos.y & 0x3ff;
// get closest surface by BSP lookup
BSPSurface = sdGetBSP(&nodeData[*surface & 0x3fff], &cell);
@ -458,8 +451,8 @@ int RoadInCell(VECTOR *pos)
cellPos.x = pos->vx - 512;
cellPos.y = pos->vz - 512;
buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1U) ^ (regions_across / 2 & 1) +
(cellPos.y >> 15 & 2U) ^ (regions_down & 2)];
buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1) ^ (regions_across / 2 & 1) +
(cellPos.y >> 15 & 2) ^ (regions_down & 2)];
if (*buffer == 2)
{
@ -467,8 +460,8 @@ int RoadInCell(VECTOR *pos)
short* bspData = (short*)((char*)buffer + buffer[2]);
sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]);
check = &buffer[(cellPos.x >> 10 & 0x3fU) +
(cellPos.y >> 10 & 0x3fU) * MAP_REGION_SIZE * 2 + 4];
check = &buffer[(cellPos.x >> 10 & 63) +
(cellPos.y >> 10 & 63) * 64 + 4];
if (*check == -1)
return -1;

View File

@ -1002,6 +1002,7 @@ void ProcessSpoolInfoLump(char *lump_ptr, int lump_size)
cell_objects_add[4] += objects_count;
// by the fact it's a roadmap size + pvs size
// FIXME: is that even correct? maybe use MAX instead?
pvsSize[i] = pvsSizes[i] + 0x7ffU & 0xfffff800;
D_MALLOC_BEGIN();