- 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; sdPlane* plane;
int iVar1; int iVar1;
short* BSPSurface; short* BSPSurface;
int cellPos_x; XYPAIR cellPos;
int cellPos_z;
XYPAIR cell; XYPAIR cell;
short* surface; short* surface;
short* HSurface;
short* buffer; short* buffer;
bool nextLevel; int nextLevel;
cellPos_x = pos->vx - 512; cellPos.x = pos->vx - 512;
cellPos_z = pos->vz - 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;
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 & 4 ^ cellPos.y >> 13 & 8 ^ sdSelfModifyingCode));
cell.x = cellPos_x & 1023; plane = NULL;
cell.y = cellPos_z & 1023;
surface = &buffer[(cellPos_x >> 10 & 0x3fU) + (cellPos_z >> 10 & 0x3fU) * MAP_REGION_SIZE * 2 + 4]; if (*buffer == 2)
if (*surface == -1)
{
plane = NULL;
}
else
{ {
sdPlane* planeData = (sdPlane*)((char*)buffer + buffer[1]); sdPlane* planeData = (sdPlane*)((char*)buffer + buffer[1]);
short* bspData = (short*)((char*)buffer + buffer[2]); short* bspData = (short*)((char*)buffer + buffer[2]);
sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]); 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) // check surface has overlapping planes flag (aka multiple levels)
if (*surface & 0x8000) if (*surface & 0x8000)
{ {
@ -133,25 +138,29 @@ sdPlane* sdGetCell_alpha16(VECTOR* pos)
// iterate surfaces if BSP // iterate surfaces if BSP
do { do {
nextLevel = false; nextLevel = 0;
BSPSurface = surface;
// check if it's has BSP properties // check if it's has BSP properties
// basically it determines surface bounds // basically it determines surface bounds
if (*surface & 0x4000) if (*surface & 0x4000)
{ {
BSPSurface = sdGetBSP(&nodeData[*surface & 0x1fff], &cell); // get closest surface by BSP lookup
if (*BSPSurface == 0x7fff) BSPSurface = sdGetBSP(&nodeData[*surface & 0x1fff], &cell); // 0x3fff in final
if (*BSPSurface == 0x7fff)
{ {
nextLevel = true; sdLevel++;
BSPSurface = surface + 2; nextLevel = 1;
BSPSurface = surface + 2; // get to the next node
} }
surface = BSPSurface;
} }
surface = BSPSurface;
} while (nextLevel); } while (nextLevel);
plane = &planeData[*BSPSurface]; plane = &planeData[*surface];
} }
return plane; return plane;
} }
@ -204,7 +213,7 @@ int RoadInCell_alpha16(VECTOR *pos)
// basically it determines surface bounds // basically it determines surface bounds
if (*check & 0x4000) if (*check & 0x4000)
{ {
sdNode* search = &nodeData[*check & 0x1fff]; sdNode* search = &nodeData[*check & 0x1fff]; // 0x3fff in final
while (search->value < 0) while (search->value < 0)
{ {

View File

@ -311,9 +311,7 @@ sdPlane* sdGetCell(VECTOR *pos)
#ifndef PSX #ifndef PSX
if (gDemoLevel) if (gDemoLevel)
{
return sdGetCell_alpha16(pos); return sdGetCell_alpha16(pos);
}
#endif #endif
sdLevel = 0; sdLevel = 0;
@ -321,27 +319,25 @@ sdPlane* sdGetCell(VECTOR *pos)
cellPos.x = pos->vx - 512; cellPos.x = pos->vx - 512;
cellPos.y = pos->vz - 512; cellPos.y = pos->vz - 512;
// [A] WARNING! cell.x = cellPos.x & 1023;
// retail version of game with exe dated before 20th October 2000 (so called 1.0) is only supported cell.y = cellPos.y & 1023;
// 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
buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1U) ^ (regions_across / 2 & 1) + buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1) ^ (regions_across / 2 & 1) +
(cellPos.y >> 15 & 2U) ^ (regions_down & 2)]; (cellPos.y >> 15 & 2) ^ (regions_down & 2)];
// Alpha 1.6 code, works too; not widely tested yet // 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; plane = NULL;
if (*buffer == 2) if (*buffer == 2)
{ {
sdPlane* planeData = (sdPlane*)((char*)buffer + buffer[1]); sdPlane* planeData = (sdPlane*)((char*)buffer + buffer[1]);
short* bspData = (short*)((char*)buffer + buffer[2]); short* bspData = (short*)((char*)buffer + buffer[2]);
sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]); sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]);
surface = &buffer[(cellPos.x >> 10 & 0x3fU) + surface = &buffer[(cellPos.x >> 10 & 63) +
(cellPos.y >> 10 & 0x3fU) * MAP_REGION_SIZE*2 + 4]; (cellPos.y >> 10 & 63) * 64 + 4];
// initial surface // initial surface
if (*surface == -1) if (*surface == -1)
@ -371,10 +367,7 @@ sdPlane* sdGetCell(VECTOR *pos)
// check if it's has BSP properties // check if it's has BSP properties
// basically it determines surface bounds // basically it determines surface bounds
if (*surface & 0x4000) if (*surface & 0x4000)
{ {
cell.x = cellPos.x & 0x3ff;
cell.y = cellPos.y & 0x3ff;
// get closest surface by BSP lookup // get closest surface by BSP lookup
BSPSurface = sdGetBSP(&nodeData[*surface & 0x3fff], &cell); BSPSurface = sdGetBSP(&nodeData[*surface & 0x3fff], &cell);
@ -458,8 +451,8 @@ int RoadInCell(VECTOR *pos)
cellPos.x = pos->vx - 512; cellPos.x = pos->vx - 512;
cellPos.y = pos->vz - 512; cellPos.y = pos->vz - 512;
buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1U) ^ (regions_across / 2 & 1) + buffer = RoadMapDataRegions[(cellPos.x >> 16 & 1) ^ (regions_across / 2 & 1) +
(cellPos.y >> 15 & 2U) ^ (regions_down & 2)]; (cellPos.y >> 15 & 2) ^ (regions_down & 2)];
if (*buffer == 2) if (*buffer == 2)
{ {
@ -467,8 +460,8 @@ int RoadInCell(VECTOR *pos)
short* bspData = (short*)((char*)buffer + buffer[2]); short* bspData = (short*)((char*)buffer + buffer[2]);
sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]); sdNode* nodeData = (sdNode*)((char*)buffer + buffer[3]);
check = &buffer[(cellPos.x >> 10 & 0x3fU) + check = &buffer[(cellPos.x >> 10 & 63) +
(cellPos.y >> 10 & 0x3fU) * MAP_REGION_SIZE * 2 + 4]; (cellPos.y >> 10 & 63) * 64 + 4];
if (*check == -1) if (*check == -1)
return -1; return -1;

View File

@ -1002,6 +1002,7 @@ void ProcessSpoolInfoLump(char *lump_ptr, int lump_size)
cell_objects_add[4] += objects_count; cell_objects_add[4] += objects_count;
// by the fact it's a roadmap size + pvs size // 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; pvsSize[i] = pvsSizes[i] + 0x7ffU & 0xfffff800;
D_MALLOC_BEGIN(); D_MALLOC_BEGIN();