From 40ee144b424ef7eeab0d3ba635b8e1f8ca3c626f Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 3 Sep 2020 21:03:36 +0600 Subject: [PATCH 1/6] - refactored SPOOL.C --- src_rebuild/GAME/C/EVENT.C | 2 +- src_rebuild/GAME/C/SPOOL.C | 474 ++++++++++++++++++------------------- 2 files changed, 228 insertions(+), 248 deletions(-) diff --git a/src_rebuild/GAME/C/EVENT.C b/src_rebuild/GAME/C/EVENT.C index 10ffdff8..9cb4e6ff 100644 --- a/src_rebuild/GAME/C/EVENT.C +++ b/src_rebuild/GAME/C/EVENT.C @@ -4168,7 +4168,7 @@ void DrawEvents(int camera) } } else -{ + { SetCamera(ev); DrawMapPSX((int*)&ObjectDrawnValue); } diff --git a/src_rebuild/GAME/C/SPOOL.C b/src_rebuild/GAME/C/SPOOL.C index 8de3940f..92596885 100644 --- a/src_rebuild/GAME/C/SPOOL.C +++ b/src_rebuild/GAME/C/SPOOL.C @@ -323,12 +323,10 @@ void startReadLevSectorsPC(int sector) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void test_changemode(void) { #ifndef SIMPLE_SPOOL - char bVar1; - SPOOLQ *current = &spooldata[spoolpos_reading]; if (spoolpos_reading == spoolcounter) @@ -346,10 +344,9 @@ void test_changemode(void) else if (current_sector == current->sector) { target_address = current->addr; - bVar1 = current->type; switch_spooltype = 1; - if (bVar1 == 0) + if (current->type == 0) { sectors_to_read = spool_regioninfo[spool_regionpos + 1].nsectors; sectors_this_chunk = (current->nsectors); @@ -359,21 +356,21 @@ void test_changemode(void) levelSpoolerPCReadyCallback(ready_cb_regions); #endif // PSX } - else if (bVar1 == 1) + else if (current->type == 1) { sectors_to_read = 17; target_address += 0x4000; nTPchunks_reading = 0; nTPchunks_writing = 0; ntpages = tsetcounter; - sectors_this_chunk = (uint)bVar1; + sectors_this_chunk = 1; #ifdef PSX CdReadyCallback(ready_cb_textures); #else levelSpoolerPCReadyCallback(ready_cb_textures); #endif // PSX } - else if (bVar1 == 2) + else if (current->type == 2) { sectors_to_read = (current->nsectors); send_bank = (current->data); @@ -381,7 +378,7 @@ void test_changemode(void) nTPchunks_reading = 0; nTPchunks_writing = 0; target_address = target_address + (loadbank_read & 1U) * 0x1000; - sectors_this_chunk = (uint)bVar1; + sectors_this_chunk = 2; #ifdef PSX CdReadyCallback(ready_cb_soundbank); @@ -389,7 +386,7 @@ void test_changemode(void) levelSpoolerPCReadyCallback(ready_cb_soundbank); #endif // PSX } - else if (bVar1 == 3) + else if (current->type == 3) { sectors_to_read = (current->nsectors); #ifdef PSX @@ -428,7 +425,7 @@ void test_changemode(void) /* end block 2 */ // End Line: 5398 -// [D] +// [D] [T] void changemode(SPOOLQ *current) { #ifndef SIMPLE_SPOOL @@ -519,122 +516,139 @@ void changemode(SPOOLQ *current) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] int check_regions_present(void) { - AREA_LOAD_INFO *pAVar1; - int iVar2; - int iVar3; - int iVar4; - int iVar5; - AREA_LOAD_INFO *pAVar6; - AREA_LOAD_INFO region_to_unpack[3]; + int barrel_region; + int x, z; + int region_to_unpack; + int num_regions_to_unpack; + int leftright_unpack; + int topbottom_unpack; + int retval; + AREA_LOAD_INFO regions_to_unpack[3]; char textbuf[128]; - pAVar6 = region_to_unpack; - iVar4 = 0; - iVar5 = 0; - iVar3 = 0; - if (current_barrel_region_xcell < 9) { - region_to_unpack[0].xoffset = -1; - if (region_x != 0) { - iVar4 = 1; - LAB_0007b44c: - iVar3 = 1; - region_to_unpack[0].zoffset = 0; + leftright_unpack = 0; + topbottom_unpack = 0; + num_regions_to_unpack = 0; + + if (current_barrel_region_xcell < 9) + { + regions_to_unpack[0].xoffset = -1; + if (region_x != 0) + { + leftright_unpack = 1; + num_regions_to_unpack = 1; + regions_to_unpack[0].zoffset = 0; } } - else { - if (0x17 < current_barrel_region_xcell) { - iVar2 = cells_across; - if (cells_across < 0) { - iVar2 = cells_across + 0x1f; - } - region_to_unpack[0].xoffset = 1; - if (region_x < iVar2 >> 5) { - iVar4 = 2; - goto LAB_0007b44c; - } + else if (current_barrel_region_xcell > 23) + { + regions_to_unpack[0].xoffset = 1; + + if (region_x < (cells_across >> 5)) + { + leftright_unpack = 2; + num_regions_to_unpack = 1; + regions_to_unpack[0].zoffset = 0; } } - if (current_barrel_region_zcell < 9) { - if (region_z == 0) goto LAB_0007b4e0; - iVar5 = 1; - region_to_unpack[iVar3].xoffset = 0; - iVar2 = -1; + + if (current_barrel_region_zcell < 9 && region_z != 0) + { + topbottom_unpack = 1; + + regions_to_unpack[num_regions_to_unpack].xoffset = 0; + regions_to_unpack[num_regions_to_unpack].zoffset = -1; + num_regions_to_unpack++; } - else { - if ((current_barrel_region_zcell < 0x18) || (region_z == 0)) goto LAB_0007b4e0; - iVar5 = 2; - region_to_unpack[iVar3].xoffset = 0; - iVar2 = 1; + else if(current_barrel_region_zcell > 23 && region_z != 0) + { + topbottom_unpack = 2; + + regions_to_unpack[num_regions_to_unpack].xoffset = 0; + regions_to_unpack[num_regions_to_unpack].zoffset = 1; + num_regions_to_unpack++; } - pAVar1 = region_to_unpack + iVar3; - iVar3 = iVar3 + 1; - pAVar1->zoffset = iVar2; -LAB_0007b4e0: - if (iVar3 == 2) { - if (iVar5 == 1) { - iVar3 = 3; - if (iVar4 == 1) { - region_to_unpack[2].xoffset = -1; - region_to_unpack[2].zoffset = -1; + + if (num_regions_to_unpack == 2) + { + num_regions_to_unpack = 3; + + if (topbottom_unpack == 1) + { + if (leftright_unpack == 1) + { + regions_to_unpack[2].xoffset = -1; + regions_to_unpack[2].zoffset = -1; } - else { - region_to_unpack[2].xoffset = 1; - region_to_unpack[2].zoffset = -1; + else + { + regions_to_unpack[2].xoffset = 1; + regions_to_unpack[2].zoffset = -1; } } - else { - iVar3 = 3; - if (iVar4 == 1) { - region_to_unpack[2].xoffset = -1; - } - else { - region_to_unpack[2].xoffset = 1; - } - region_to_unpack[2].zoffset = 1; + else + { + if (leftright_unpack == 1) + regions_to_unpack[2].xoffset = -1; + else + regions_to_unpack[2].xoffset = 1; + + regions_to_unpack[2].zoffset = 1; } } - iVar4 = 0; - while (iVar3 != 0) { - iVar5 = cells_across; - if (cells_across < 0) { - iVar5 = cells_across + 0x1f; + + retval = 0; + while (num_regions_to_unpack != 0) + { + x = regions_to_unpack[retval].xoffset; + z = regions_to_unpack[retval].zoffset; + + region_to_unpack = current_region + x + z * (cells_across >> 5); + + if (loading_region[(region_x + x & 1U) + (region_z + z & 1U) * 2] != -1 && + spoolinfo_offsets[region_to_unpack] != 0xffff && + loading_region[(region_x + x & 1U) + (region_z + z & 1U) * 2] == region_to_unpack) + { + retval++; } - iVar5 = current_region + *(int *)pAVar6 + ((int *)pAVar6)[1] * (iVar5 >> 5); - if ((((int)loading_region[(region_x + *(int *)pAVar6 & 1U) + (region_z + ((int *)pAVar6)[1] & 1U) * 2] != - -1) && (spoolinfo_offsets[iVar5] != 0xffff)) && - ((int)loading_region - [(region_x + *(int *)pAVar6 & 1U) + (region_z + ((int *)pAVar6)[1] & 1U) * 2] == - iVar5)) { - iVar4 = iVar4 + 1; - } - iVar3 = iVar3 + -1; - pAVar6 = (AREA_LOAD_INFO *)((int *)pAVar6 + 2); + num_regions_to_unpack--; } - if (LoadingArea != 0) { - if (new_area_location == 1) { - if (0x1a < current_barrel_region_xcell) { - iVar4 = iVar4 + 1; + + if (LoadingArea != 0) + { + if (new_area_location == 1) + { + if (current_barrel_region_xcell > 26) + { + retval++; } } - else { - if (new_area_location < 2) { - if ((new_area_location == 0) && (0x1a < current_barrel_region_zcell)) { - iVar4 = iVar4 + 1; + else + { + if (new_area_location < 2) + { + if (new_area_location == 0 && current_barrel_region_zcell > 26) + { + retval++; } } - else { - iVar3 = current_barrel_region_zcell; - if (((new_area_location == 2) || - (iVar3 = current_barrel_region_xcell, new_area_location == 3)) && (iVar3 < 6)) { - iVar4 = iVar4 + 1; + else + { + barrel_region = current_barrel_region_zcell; + if ((new_area_location == 2 || + (barrel_region = current_barrel_region_xcell, new_area_location == 3)) && + barrel_region < 6) + { + retval++; } } } } - return iVar4; + + return retval; } @@ -662,7 +676,7 @@ LAB_0007b4e0: /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void stopgame(void) { StopPadVibration(0); @@ -702,7 +716,7 @@ void stopgame(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void startgame(void) { PutDrawEnv(¤t->draw); @@ -742,7 +756,7 @@ void startgame(void) extern POLY_FT4 cd_sprite; extern unsigned short cd_icon[288]; -// [D] +// [D] [T] void DrawCDicon(void) { ushort *palette; @@ -802,7 +816,7 @@ void DrawCDicon(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void CheckValidSpoolData(void) { if (models_ready) @@ -863,7 +877,7 @@ void CheckValidSpoolData(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void UpdateSpool(void) { #ifdef SIMPLE_SPOOL @@ -1075,7 +1089,7 @@ void UpdateSpool(void) /* end block 3 */ // End Line: 6448 -// [D] +// [D] [T] #ifdef _DEBUG void _RequestSpool(int type, int data, int offset, int loadsize, char *address, spooledFuncPtr func, const char* requestby, int line) #define RequestSpool(type, data, offset, loadsize, loadaddr, func) _RequestSpool(type, data, offset, loadsize, loadaddr, func, __FUNCTION__, __LINE__) @@ -1144,7 +1158,7 @@ void RequestSpool(int type, int data, int offset, int loadsize, char *address, s /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitSpooling(void) { for (int i = 0; i < 4; i++) @@ -1219,25 +1233,26 @@ void InitSpooling(void) int tsetinfo[32]; -// [D] +// [D] [T] void SendTPage(void) { - unsigned char bVar1; + unsigned char old; ulong *clutptr; - int iVar5; + int slot; int npalettes; - int iVar7; + int tpage2send; + int i; RECT16 cluts; - iVar7 = tsetinfo[tsetpos * 2]; - iVar5 = tsetinfo[tsetpos * 2 + 1]; + tpage2send = tsetinfo[tsetpos * 2]; + slot = tsetinfo[tsetpos * 2 + 1]; - if (iVar7 == 0xFF || iVar5 == 0xFF) // [A] bug fix + if (tpage2send == 0xFF || slot == 0xFF) // [A] bug fix return; if (nTPchunks == 0) { - if (iVar5 != tpageloaded[iVar7]-1) + if (slot != tpageloaded[tpage2send]-1) { npalettes = *(int *)(model_spool_buffer + 0xE000); @@ -1245,43 +1260,37 @@ void SendTPage(void) tpage.h = 64; cluts.w = 64; - tpage.x = slot_tpagepos[iVar5].vx; - tpage.y = slot_tpagepos[iVar5].vy; + tpage.x = slot_tpagepos[slot].vx; + tpage.y = slot_tpagepos[slot].vy; - cluts.y = slot_clutpos[iVar5].vy; - cluts.x = slot_clutpos[iVar5].vx; + cluts.y = slot_clutpos[slot].vy; + cluts.x = slot_clutpos[slot].vx; cluts.h = npalettes / 4 + 1; LoadImage(&cluts, (u_long *)(model_spool_buffer + 0xE000 + 4)); - clutptr = (ulong *)(texture_cluts[iVar7]); - iVar5 = 0; + clutptr = (ulong *)(texture_cluts[tpage2send]); + i = 0; - if (0 < npalettes) + while (i < npalettes) { - do { - //int test1 = (uVar3 | iVar2 + 0x10 >> 4 & 0x3fU) << 0x10 | uVar3 | (int)((uint)cluts.x << 0x10) >> 0x14 & 0x3fU; - //int test2 = (uVar3 | iVar2 + 0x30 >> 4 & 0x3fU) << 0x10 | uVar3 | iVar2 + 0x20 >> 4 & 0x3fU; + clutptr[0] = getClut(cluts.x + 16, cluts.y) << 0x10 | getClut(cluts.x, cluts.y); + clutptr[1] = getClut(cluts.x + 48, cluts.y) << 0x10 | getClut(cluts.x + 32, cluts.y); - clutptr[0] = getClut(cluts.x + 16, cluts.y) << 0x10 | getClut(cluts.x, cluts.y); - clutptr[1] = getClut(cluts.x + 48, cluts.y) << 0x10 | getClut(cluts.x + 32, cluts.y); + clutptr+=2; - clutptr+=2; - cluts.y++; - iVar5 += 4;; - } while (iVar5 < npalettes); + cluts.y++; + + i += 4; } - texture_pages[iVar7] = getTPage(0, 0, tpage.x, tpage.y); - - // OLD VALUE: (short)(tpage.y & 0x100U) >> 4 | (ushort)(((uint)(ushort)tpage.x & 0x3ff) >> 6) | (ushort)(((uint)(ushort)tpage.y & 0x200) << 2); - // please check me if above is correct + texture_pages[tpage2send] = getTPage(0, 0, tpage.x, tpage.y); } } else { - if (iVar5 != tpageloaded[iVar7] - 1) + if (slot != tpageloaded[tpage2send] - 1) { LoadImage(&tpage, (u_long *)(model_spool_buffer + 0xA000 + (loadbank_write % 2) * TPAGE_WIDTH * 32)); tpage.y = tpage.y + tpage.h; @@ -1289,13 +1298,13 @@ void SendTPage(void) if (nTPchunks == 4) { - bVar1 = tpageslots[iVar5]; - tpageslots[iVar5] = iVar7; + old = tpageslots[slot]; + tpageslots[slot] = tpage2send; - if(bVar1 != 0xFF) // [A] bug fix - tpageloaded[bVar1] = 0; + if(old != 0xFF) // [A] bug fix + tpageloaded[old] = 0; - tpageloaded[iVar7] = iVar5 + 1; + tpageloaded[tpage2send] = slot + 1; tsetpos++; @@ -1331,7 +1340,7 @@ void SendTPage(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void SpoolSYNC(void) { do { @@ -1376,15 +1385,10 @@ void SpoolSYNC(void) /* end block 4 */ // End Line: 2661 -// [D] +// [D] [T] void LoadInAreaTSets(int area) { - bool bVar1; - - uint uVar3; - int iVar4; int offset; - int *piVar5; int i; int slot; @@ -1404,7 +1408,6 @@ void LoadInAreaTSets(int area) if (slotsused < 19) { - piVar5 = availableslots; slot = slotsused; do { @@ -1412,28 +1415,22 @@ void LoadInAreaTSets(int area) if (tpageslots[slot] == 0xff) // [A] { - *piVar5++ = slot; - navailable++; + availableslots[navailable++] = slot; } else { - if (ntpages_to_load != 0 && tpageslots[slot] != *tpages) // [A] + i = 0; + while (tpageslots[slot] != tpages[i]) // [A] { - uVar3 = 1; - do { - offset = uVar3; + if (ntpages_to_load <= i) + break; - if (ntpages_to_load <= offset) - break; + i++; + }; - uVar3 = offset + 1; - } while (tpageslots[slot] != tpages[offset]); // [A] - } - - if (offset == ntpages_to_load) + if (i == ntpages_to_load) { - *piVar5++ = slot; - navailable++; + availableslots[navailable++] = slot; } } @@ -1446,23 +1443,16 @@ void LoadInAreaTSets(int area) if (ntpages_to_load != 0) { - uVar3 = *tpages; - - if (tpageloaded[uVar3] != 0) // weird goto lol + if (tpageloaded[*tpages] != 0) // weird goto lol { goto LAB_0007bc94; } - bVar1 = 0 < navailable; - navailable--; - - if (bVar1) + if (navailable-- > 0) { - iVar4 = availableslots[navailable]; - while (true) { - tsetinfo[tsetcounter*2 + 1] = iVar4; + tsetinfo[tsetcounter*2 + 1] = availableslots[navailable]; while (true) { @@ -1478,21 +1468,17 @@ void LoadInAreaTSets(int area) if (ntpages_to_load <= i) return; - uVar3 = *tpages; - - if (tpageloaded[uVar3] == 0) + if (tpageloaded[*tpages] == 0) break; LAB_0007bc94: - tsetinfo[tsetcounter * 2 + 1] = tpageloaded[uVar3] - 1; + tsetinfo[tsetcounter * 2 + 1] = tpageloaded[*tpages] - 1; } if (navailable < 1) break; navailable--; - - iVar4 = availableslots[navailable]; } } } @@ -1638,7 +1624,7 @@ void SendSBK(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void init_spooled_models(void) { int nmodels; @@ -1657,12 +1643,6 @@ void init_spooled_models(void) SPOOL_INFO("loading %d model slots\n", nmodels); - //for (i = 0; i < 1536; i++) - //{ - // if (addr <= (char*)&modelpointers[i]) - // modelpointers[i] = &dummyModel; - //} - unsigned short* new_model_numbers = newmodels + 1; for (i = 0; i < nmodels; i++) @@ -1731,7 +1711,7 @@ void init_spooled_models(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void SetupModels(void) { if (old_region == -1) @@ -1771,7 +1751,7 @@ void SetupModels(void) /* end block 4 */ // End Line: 7975 -// [D] +// [D] [T] void LoadInAreaModels(int area) { if (newmodels) @@ -1830,7 +1810,7 @@ void LoadInAreaModels(int area) /* end block 4 */ // End Line: 3523 -// [D] +// [D] [T] void CheckLoadAreaData(int cellx, int cellz) { int nAreas; @@ -1958,7 +1938,7 @@ void CheckLoadAreaData(int cellx, int cellz) /* end block 4 */ // End Line: 7605 -// [D] +// [D] [T] void ClearRegion(int target_region) { long *pvsptr; @@ -2005,7 +1985,7 @@ void ClearRegion(int target_region) extern bool gDemoLevel; extern bool gDriver1Level; -// [D] +// [D] [T] int LoadRegionData(int region, int target_region) { char *cell_buffer; @@ -2099,7 +2079,7 @@ int LoadRegionData(int region, int target_region) int RoadMapRegions[4]; -// [D] +// [D] [T] void UnpackRegion(int region_to_unpack, int target_barrel_region) { if (loading_region[target_barrel_region] == -1) @@ -2151,7 +2131,7 @@ inline int _getIntAdv(char** ptr) #define getIntAdv(ptr) _getIntAdv(&ptr) -// [D] +// [D] [T] void ProcessSpoolInfoLump(char *lump_ptr, int lump_size) { int i; @@ -2261,7 +2241,7 @@ void ProcessSpoolInfoLump(char *lump_ptr, int lump_size) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void WaitCloseLid(void) { #ifdef PSX @@ -2318,7 +2298,7 @@ void WaitCloseLid(void) /* end block 5 */ // End Line: 8769 -// [D] +// [D] [T] void FoundError(char *name, unsigned char intr, unsigned char *result) { #ifndef SIMPLE_SPOOL @@ -2383,7 +2363,7 @@ void FoundError(char *name, unsigned char intr, unsigned char *result) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void GotRegion(void) { uint target_barrel_reg; @@ -2444,7 +2424,7 @@ void GotRegion(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void data_cb_textures(void) { #ifndef SIMPLE_SPOOL @@ -2533,7 +2513,7 @@ void data_cb_textures(void) /* end block 3 */ // End Line: 6774 -// [D] +// [D] [T] void ready_cb_textures(unsigned char intr, unsigned char *result) { #ifndef SIMPLE_SPOOL @@ -2622,6 +2602,7 @@ void ready_cb_textures(unsigned char intr, unsigned char *result) /* end block 3 */ // End Line: 4181 +// [D] [T] void ready_cb_regions(unsigned char intr, unsigned char *result) { #ifndef SIMPLE_SPOOL @@ -2694,7 +2675,7 @@ void ready_cb_regions(unsigned char intr, unsigned char *result) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void data_cb_regions(void) { #ifndef SIMPLE_SPOOL @@ -2918,7 +2899,7 @@ void ready_cb_soundbank(unsigned char intr, unsigned char *result) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void data_cb_misc(void) { #ifndef SIMPLE_SPOOL @@ -2980,7 +2961,7 @@ void data_cb_misc(void) /* end block 2 */ // End Line: 6748 -// [D] +// [D] [T] void ready_cb_misc(unsigned char intr, unsigned char *result) { #ifndef SIMPLE_SPOOL @@ -3040,10 +3021,10 @@ void ready_cb_misc(unsigned char intr, unsigned char *result) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void StartSpooling(void) { - if ((spoolcounter != 0) && !spoolactive) + if (spoolcounter != 0 && !spoolactive) { if (!XAPrepared()) { @@ -3112,69 +3093,68 @@ void StartSpooling(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] [A] - altered declaration +// [D] [T] [A] - altered declaration void unpack_cellpointers(int region_to_unpack, int target_barrel_region, char* cell_addr) { - ushort *puVar1; - ushort *puVar2; - ushort uVar3; + ushort cell; + ushort* short_ptr; + ushort* source_packed_data; int loop; - uint uVar6; - uint uVar7; + uint bitpos; + uint pcode; int packtype; unpack_cellptr_flag = 0; packtype = *(int *)(cell_addr + 4); - puVar1 = (ushort *)(cell_addr + 8); + source_packed_data = (ushort *)(cell_addr + 8); if (packtype == 0) { - puVar1 = cell_ptrs + target_barrel_region * 1024; + short_ptr = cell_ptrs + target_barrel_region * 1024; for (loop = 0; loop < 1024; loop++) - *puVar1++ = 0xffff; + *short_ptr++ = 0xffff; } else if (packtype == 1) { - puVar2 = cell_ptrs + target_barrel_region * 1024; + short_ptr = cell_ptrs + target_barrel_region * 1024; for (loop = 0; loop < 1024; loop++) { - uVar3 = *puVar1++; + cell = *source_packed_data++; - if (uVar3 != 0xffff) - uVar3 += cell_slots_add[target_barrel_region]; + if (cell != 0xffff) + cell += cell_slots_add[target_barrel_region]; - *puVar2++ = uVar3; + *short_ptr++ = cell; } } else if (packtype == 2) { - uVar6 = 0x8000; - uVar7 = (uint)*puVar1; - - puVar2 = (ushort *)(cell_addr + 10); - puVar1 = cell_ptrs + target_barrel_region * 1024; + bitpos = 0x8000; + pcode = (uint)*source_packed_data; + source_packed_data++; + short_ptr = cell_ptrs + target_barrel_region * 1024; for (loop = 0; loop < 1024; loop++) { - if (uVar7 & uVar6) + if (pcode & bitpos) { - uVar3 = *puVar2++; - uVar3 += cell_slots_add[target_barrel_region]; + cell = *source_packed_data++; + cell += cell_slots_add[target_barrel_region]; } else - uVar3 = 0xffff; + cell = 0xffff; - uVar6 >>= 1; - *puVar1++ = uVar3; + bitpos >>= 1; + *short_ptr++ = cell; - if (uVar6 == 0) + if (bitpos == 0) { - uVar6 = 0x8000; - uVar7 = *puVar2++; + bitpos = 0x8000; + pcode = *source_packed_data++; } } } @@ -3220,7 +3200,7 @@ void unpack_cellpointers(int region_to_unpack, int target_barrel_region, char* c /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] [A] altered unpack_cellpointers +// [D] [T] [A] altered unpack_cellpointers void Unpack_CellPtrs(void) { SPL_REGIONINFO* spool = &spool_regioninfo[spool_regionpos]; @@ -3285,7 +3265,7 @@ void Unpack_CellPtrs(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] [A] +// [D] [T] [A] void SpecClutsSpooled(void) { char *loadaddr; @@ -3386,7 +3366,7 @@ int specialState = 0; char specModelValid = 1; int specSpoolComplete; -// [D] +// [D] [T] void CleanModelSpooled(void) { int *loadaddr; @@ -3473,7 +3453,7 @@ void CleanModelSpooled(void) int damOffset; -// [D] +// [D] [T] void DamagedModelSpooled(void) { int *loadaddr; @@ -3557,7 +3537,7 @@ void DamagedModelSpooled(void) int lowOffset; -// [D] +// [D] [T] void LowModelSpooled(void) { int *loadaddr; @@ -3643,7 +3623,7 @@ void LowModelSpooled(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] [A] +// [D] [T] [A] void CleanSpooled(void) { MODEL *model; @@ -3737,7 +3717,7 @@ void CleanSpooled(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void LowSpooled(void) { MODEL *model; @@ -3822,7 +3802,7 @@ void LowSpooled(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void Tada(void) { int spec_tpage; @@ -3918,7 +3898,7 @@ void Tada(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void SpecialStartNextBlock(void) { char *loadaddr; @@ -4060,7 +4040,7 @@ void SpecialStartNextBlock(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void CheckSpecialSpool(void) { int ret; @@ -4137,7 +4117,7 @@ void CheckSpecialSpool(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void QuickSpoolSpecial(void) { quickSpool = 1; @@ -4176,7 +4156,7 @@ void QuickSpoolSpecial(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void PrepareSecretCar(void) { allowSpecSpooling = 0; @@ -4218,7 +4198,7 @@ void PrepareSecretCar(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitSpecSpool(void) { switch (gCurrentMissionNumber) From 39feda48409769c57233d18f5a882e7da6efea3c Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 3 Sep 2020 21:57:09 +0600 Subject: [PATCH 2/6] - refactored MAP.C --- src_rebuild/GAME/C/MAP.C | 408 ++++++++++++++++++--------------------- 1 file changed, 186 insertions(+), 222 deletions(-) diff --git a/src_rebuild/GAME/C/MAP.C b/src_rebuild/GAME/C/MAP.C index 44743a8f..eacaf43f 100644 --- a/src_rebuild/GAME/C/MAP.C +++ b/src_rebuild/GAME/C/MAP.C @@ -58,7 +58,7 @@ CELL_OBJECT** coplist; /* end block 3 */ // End Line: 475 -// [D] +// [D] [T] void NewProcessRoadMapLump(ROAD_MAP_LUMP_DATA *pRoadMapLumpData, char *pLumpFile) { Getlong((char*)&pRoadMapLumpData->width, pLumpFile); @@ -83,7 +83,7 @@ void NewProcessRoadMapLump(ROAD_MAP_LUMP_DATA *pRoadMapLumpData, char *pLumpFile /* end block 2 */ // End Line: 1665 -// [D] +// [D] [T] void ProcessJunctionsLump(char *lump_file, int lump_size) { return; @@ -105,7 +105,7 @@ void ProcessJunctionsLump(char *lump_file, int lump_size) /* end block 2 */ // End Line: 505 -// [D] +// [D] [T] void ProcessRoadsLump(char *lump_file, int lump_size) { return; @@ -122,7 +122,7 @@ void ProcessRoadsLump(char *lump_file, int lump_size) /* end block 1 */ // End Line: 1676 -// [D] +// [D] [T] void ProcessRoadBoundsLump(char *lump_file, int lump_size) { return; @@ -139,7 +139,7 @@ void ProcessRoadBoundsLump(char *lump_file, int lump_size) /* end block 1 */ // End Line: 1678 -// [D] +// [D] [T] void ProcessJuncBoundsLump(char *lump_file, int lump_size) { return; @@ -262,31 +262,25 @@ MODEL * FindModelPtrWithName(char *name) /* end block 3 */ // End Line: 1558 -// [D] +// [D] [T] int FindModelIdxWithName(char *name) { - char cVar1; - int iVar2; - int iVar3; - char *__s1; - int iVar4; + char *str; + int i; - iVar4 = 0; - __s1 = modelname_buffer; - if (0 < num_models_in_pack) { - do { - iVar2 = strcmp(__s1, name); - iVar3 = iVar4 + 1; - if (iVar2 == 0) { - return iVar4; - } - do { - cVar1 = *__s1; - __s1 = __s1 + 1; - } while (cVar1 != '\0'); - iVar4 = iVar3; - } while (iVar3 < num_models_in_pack); + i = 0; + str = modelname_buffer; + + while (i < num_models_in_pack) + { + if (!strcmp(str, name)) + return i; + + while (*str++) {} // go to next string + + i++; } + return -1; } @@ -332,7 +326,7 @@ int sizeof_cell_object_computed_values; CELL_DATA* cells; int num_straddlers; // objects between regions -// [D] +// [D] [T] void InitCellData(void) { int loop; @@ -351,7 +345,7 @@ void InitCellData(void) MALLOC_END(); - sizeof_cell_object_computed_values = (num_straddlers + cell_objects_add[4] + 7) / 8; + sizeof_cell_object_computed_values = (num_straddlers + cell_objects_add[4] + 7) / sizeof(PACKED_CELL_OBJECT); } @@ -387,32 +381,35 @@ void InitCellData(void) /* end block 4 */ // End Line: 1774 -// [D] +// [D] [T] int newPositionVisible(VECTOR *pos, char *pvs, int ccx, int ccz) { + int dx; // $a2 + int dz; // $a0 + int cellx; // $v1 + int cellz; // $v0 + int iVar1; int iVar2; - iVar2 = pos->vx + units_across_halved; - iVar1 = pos->vz + units_down_halved; + dx = pos->vx + units_across_halved; + dz = pos->vz + units_down_halved; - ccx = (iVar2 >> 0xb) - ccx; - ccz = (iVar1 >> 0xb) - ccz; - iVar2 = ccx; + cellx = (dx >> 0xb) - ccx; + cellz = (dz >> 0xb) - ccz; - if (ccx < 0) - iVar2 = -ccx; + if (cellx < 0) + cellx = -cellx; - if (iVar2 <= view_dist) + if (cellx <= view_dist) { - iVar2 = ccz; - - if (ccz < 0) - iVar2 = -ccz; + if (cellz < 0) + cellz = -cellz; - if (iVar2 <= view_dist) - return pvs[ccx + 10 + (ccz + 10) * pvs_square] != 0; + if (cellz <= view_dist) + return pvs[cellx + 10 + (cellz + 10) * pvs_square] != 0; } + return 0; } @@ -449,32 +446,33 @@ int newPositionVisible(VECTOR *pos, char *pvs, int ccx, int ccz) /* end block 4 */ // End Line: 1771 -// [D] +// [D] [T] int PositionVisible(VECTOR *pos) { + int dx; // $a1 + int dz; // $a0 + int cellx; // $v1 + int cellz; // $v0 + int iVar1; int iVar2; - int iVar3; - iVar2 = pos->vx + units_across_halved; - iVar1 = pos->vz + units_down_halved; + dx = pos->vx + units_across_halved; + dz = pos->vz + units_down_halved; - iVar3 = (iVar2 >> 0xb) - current_cell_x; - iVar1 = (iVar1 >> 0xb) - current_cell_z; + cellx = (dx >> 0xb) - current_cell_x; + cellz = (dz >> 0xb) - current_cell_z; - iVar2 = iVar3; + if (cellx < 0) + cellx = -cellx; - if (iVar3 < 0) - iVar2 = -iVar3; - - if (iVar2 <= view_dist) + if (cellx <= view_dist) { - iVar2 = iVar1; - if (iVar1 < 0) - iVar2 = -iVar1; + if (cellz < 0) + cellz = -cellz; - if (iVar2 <= view_dist) - return CurrentPVS[iVar3 + (iVar1 + 10) * pvs_square + 10] != 0; + if (cellz <= view_dist) + return CurrentPVS[cellx + 10 + (cellz + 10) * pvs_square] != 0; } return 0; @@ -558,198 +556,170 @@ int region_z = 0; int current_barrel_region_xcell = 0; int current_barrel_region_zcell = 0; -// [D] +// [D] [T] int CheckUnpackNewRegions(void) { - char bVar1; - ushort uVar2; - bool bVar3; - int iVar4; - uint uVar5; - int iVar6; - int iVar7; - int iVar8; - int iVar9; - ushort *puVar10; - ushort *puVar11; + ushort sort; + ushort *destsort; + ushort *srcsort; + + int x, z; + int i, j; + int sortcount; + int leftright_unpack; + int topbottom_unpack; int target_region; - int iVar12; + int region_to_unpack; + int num_regions_to_unpack; + int force_load_boundary; AREA_LOAD_INFO regions_to_unpack[3]; SVECTOR sortregions[4]; ushort sortorder[4]; - iVar8 = 0; - iVar9 = 0; - iVar12 = 0; + leftright_unpack = 0; + topbottom_unpack = 0; + num_regions_to_unpack = 0; if (saved_leadcar_pos != 0) - { return 0; - } - iVar7 = 0xd; + force_load_boundary = 13; if (lead_car == 0) - { - iVar7 = 0x12; - } + force_load_boundary = 18; - if (current_barrel_region_xcell < iVar7) + if (current_barrel_region_xcell < force_load_boundary) { - iVar4 = -1; - if (region_x != 0) { - iVar8 = 1; - LAB_0005c8f8: - iVar12 = 1; - regions_to_unpack[0].xoffset = iVar4; + leftright_unpack = 1; + num_regions_to_unpack = 1; + regions_to_unpack[0].xoffset = -1; regions_to_unpack[0].zoffset = 0; } } - else if (0x20 - iVar7 < current_barrel_region_xcell) + else if (0x20 - force_load_boundary < current_barrel_region_xcell) { - iVar6 = cells_across; - - if (cells_across < 0) + if (region_x < cells_across >> 5) { - iVar6 = cells_across + 0x1f; - } - - iVar4 = 1; - - if (region_x < iVar6 >> 5) - { - iVar8 = 2; - goto LAB_0005c8f8; // I really don't like this GOTO + leftright_unpack = 2; + num_regions_to_unpack = 1; + regions_to_unpack[0].xoffset = 1; + regions_to_unpack[0].zoffset = 0; } } - if (current_barrel_region_zcell < iVar7) + if (current_barrel_region_zcell < force_load_boundary) { if (region_z != 0) { - iVar9 = 1; - regions_to_unpack[iVar12].xoffset = 0; - iVar7 = -1; - LAB_0005c978: - regions_to_unpack[iVar12].zoffset = iVar7; - iVar12 = iVar12 + 1; + topbottom_unpack = 1; + regions_to_unpack[num_regions_to_unpack].xoffset = 0; + regions_to_unpack[num_regions_to_unpack].zoffset = -1; + num_regions_to_unpack++; } } - else if ((32 - iVar7 < current_barrel_region_zcell) && (region_z != 0)) + else if (32 - force_load_boundary < current_barrel_region_zcell && region_z != 0) { - iVar9 = 2; - regions_to_unpack[iVar12].xoffset = 0; - iVar7 = 1; - goto LAB_0005c978; + topbottom_unpack = 2; + regions_to_unpack[num_regions_to_unpack].xoffset = 0; + regions_to_unpack[num_regions_to_unpack].zoffset = 1; + num_regions_to_unpack++; } - if (iVar12 == 2) + if (num_regions_to_unpack == 2) { - if (iVar9 == 1) + if (topbottom_unpack == 1) { - iVar12 = 3; - if (iVar8 == 1) + num_regions_to_unpack = 3; + + if (leftright_unpack == 1) { regions_to_unpack[2].xoffset = -1; regions_to_unpack[2].zoffset = -1; - goto LAB_0005c9dc; } - - regions_to_unpack[2].xoffset = 1; - regions_to_unpack[2].zoffset = -1; + else + { + regions_to_unpack[2].xoffset = 1; + regions_to_unpack[2].zoffset = -1; + } } else { - if (iVar8 == 1) + if (leftright_unpack == 1) regions_to_unpack[2].xoffset = -1; else regions_to_unpack[2].xoffset = 1; regions_to_unpack[2].zoffset = 1; } - iVar12 = 3; + num_regions_to_unpack = 3; } -LAB_0005c9dc: - iVar9 = 0; - iVar8 = 0; + i = 0; + sortcount = 0; - if (iVar12 != 0) + // get next region a space + while (i < num_regions_to_unpack) { - iVar7 = 0; - do { - iVar4 = regions_to_unpack[iVar9].xoffset; - iVar6 = regions_to_unpack[iVar9].zoffset; + x = regions_to_unpack[i].xoffset; + z = regions_to_unpack[i].zoffset; - iVar7 = cells_across; + target_region = (region_x + x & 1U) + (region_z + z & 1U) * 2; + region_to_unpack = current_region + x + z * (cells_across / 32); - target_region = (region_x + iVar4 & 1U) + (region_z + iVar6 & 1U) * 2; - iVar7 = current_region + iVar4 + iVar6 * (iVar7 / 32); + if (region_to_unpack != regions_unpacked[target_region] && loading_region[target_region] == -1) + { + ClearRegion(target_region); - if ((iVar7 != regions_unpacked[target_region]) && (loading_region[target_region] == -1)) + if (spoolinfo_offsets[region_to_unpack] == 0xffff) { - ClearRegion(target_region); - if (spoolinfo_offsets[iVar7] == 0xffff) - { - regions_unpacked[target_region] = iVar7; - } - else - { - uVar2 = spoolinfo_offsets[iVar7]; - - Spool *spoolptr = (Spool*)(RegionSpoolInfo + spoolinfo_offsets[iVar7]); - - if (old_region == -1 && spoolptr->super_region != 0xFF) - initarea = spoolptr->super_region; - - sortregions[iVar8].vx = iVar7; - sortregions[iVar8].vy = target_region; - sortregions[iVar8].vz = spoolptr->offset;// *(short *)(RegionSpoolInfo + uVar2); - - sortorder[iVar8] = iVar8; - iVar8++; - } + regions_unpacked[target_region] = region_to_unpack; } - iVar9++; - iVar7 = iVar9 * 8; - } while (iVar9 < iVar12); + else + { + Spool *spoolptr = (Spool*)(RegionSpoolInfo + spoolinfo_offsets[region_to_unpack]); + + if (old_region == -1 && spoolptr->super_region != 0xFF) + initarea = spoolptr->super_region; + + sortregions[sortcount].vx = region_to_unpack; + sortregions[sortcount].vy = target_region; + sortregions[sortcount].vz = spoolptr->offset; + + sortorder[sortcount] = sortcount; + sortcount++; + } + } + i++; } - if (0 < iVar8) + i = 0; + while (i < sortcount) { - iVar12 = 0; - iVar9 = 1; + if (sortcount > (i + 1)) + { + srcsort = sortorder + i; + destsort = sortorder + (i + 1); - do { - if (iVar9 < iVar8) - { - puVar11 = sortorder + iVar12; - puVar10 = sortorder + iVar9; - iVar7 = iVar8 - iVar9; + j = sortcount - (i + 1); - do { - uVar2 = *puVar11; + do { + sort = *srcsort; + if (sortregions[*destsort].vz < sortregions[*srcsort].vz) + { + *srcsort = *destsort; + *destsort = sort; + } - if (sortregions[*puVar10].vz < sortregions[uVar2].vz) - { - *puVar11 = *puVar10; - *puVar10 = uVar2; - } + j--; + destsort++; + } while (j > 0); + } - iVar7--; - puVar10++; - } while (iVar7 != 0); - } + UnpackRegion(sortregions[sortorder[i]].vx, sortregions[sortorder[i]].vy); - uVar5 = sortorder[iVar12]; - UnpackRegion(sortregions[uVar5].vx, sortregions[uVar5].vy); - - bVar3 = iVar9 < iVar8; - iVar12 = iVar9; - iVar9 = iVar9 + 1; - } while (bVar3); + i++; } return 1; @@ -809,7 +779,7 @@ LAB_0005c9dc: extern OUT_CELL_FILE_HEADER cell_header; -// [D] +// [D] [T] void ControlMap(void) { #ifdef PSX @@ -979,76 +949,70 @@ void ControlMap(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitMap(void) { - int iVar1; - unsigned char *pbVar2; int region_to_unpack; - int iVar3; - int *piVar4; + int barrel_region; + int i; initarea = -1; LoadedArea = -1; current_region = -1; - if (slotsused < 19) - { - pbVar2 = &tpageslots[slotsused]; - iVar3 = slotsused; - do { - if (*pbVar2 != 0xff) - tpageloaded[*pbVar2] = 0; + i = slotsused; - *pbVar2++ = 0xff; - iVar3++; - } while (iVar3 < 19); + while (i < 19) + { + int tpage = tpageslots[i]; + + if (tpage != 0xff) + tpageloaded[tpage] = 0; + + tpageslots[i] = 0xff; + i++; } // load regions synchronously - if (doSpooling == 0) + if (doSpooling == 0) { old_region = -1; - if (multiplayerregions[1] == -1) + if (multiplayerregions[1] == -1) { multiplayerregions[1] = multiplayerregions[0] + 1; multiplayerregions[2] = multiplayerregions[0] - (cells_across >> 5); multiplayerregions[3] = multiplayerregions[2] + 1; } - piVar4 = multiplayerregions; - iVar3 = 3; + i = 0; do { - region_to_unpack = *piVar4; - iVar1 = cells_across >> 5; + region_to_unpack = multiplayerregions[i]; - if (spoolinfo_offsets[region_to_unpack] != 0xffff) + if (spoolinfo_offsets[region_to_unpack] != 0xffff) { - Spool *spoolptr = (Spool*)(RegionSpoolInfo + spoolinfo_offsets[region_to_unpack]); + Spool* spoolptr = (Spool*)(RegionSpoolInfo + spoolinfo_offsets[region_to_unpack]); if (spoolptr->super_region != 0xff) initarea = spoolptr->super_region; - UnpackRegion(region_to_unpack, (region_to_unpack % iVar1 & 1U) + (region_to_unpack / iVar1 & 1U) * 2); + barrel_region = (region_to_unpack % (cells_across >> 5) & 1U) + (region_to_unpack / (cells_across >> 5) & 1U) * 2; + + UnpackRegion(region_to_unpack, barrel_region); } - iVar3--; - piVar4++; - } while (-1 < iVar3); + i++; + } while (i < 4); LoadInAreaTSets(initarea); LoadInAreaModels(initarea); - current_cell_x = camera_position.vx + units_across_halved; - current_cell_x = current_cell_x >> 0xb; - - current_cell_z = camera_position.vz + units_down_halved; - current_cell_z = current_cell_z >> 0xb; + current_cell_x = camera_position.vx + units_across_halved >> 0xb; + current_cell_z = camera_position.vz + units_down_halved >> 0xb; StartSpooling(); } - else + else { regions_unpacked[0] = -1; regions_unpacked[1] = -1; @@ -1099,7 +1063,7 @@ void InitMap(void) /* end block 3 */ // End Line: 2686 -// [D] [A] +// [D] [T] [A] void GetVisSetAtPosition(VECTOR *pos, char *tgt, int *ccx, int *ccz) { int cz; @@ -1427,7 +1391,7 @@ void PVSDecode(char *output, char *celldata, ushort sz, int havanaCorruptCellBod /* end block 5 */ // End Line: 2055 -// [D] +// [D] [T] void GetPVSRegionCell2(int source_region, int region, int cell, char *output) { int k; From 3f49a8c52545e1f3dbbc89a4c10835a08f183716 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 3 Sep 2020 22:26:40 +0600 Subject: [PATCH 3/6] - tested ASMTEST.C --- src_rebuild/GAME/ASM/ASMTEST.C | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src_rebuild/GAME/ASM/ASMTEST.C b/src_rebuild/GAME/ASM/ASMTEST.C index 7c73fddf..c8e887e3 100644 --- a/src_rebuild/GAME/ASM/ASMTEST.C +++ b/src_rebuild/GAME/ASM/ASMTEST.C @@ -6,13 +6,13 @@ // ASM functions. // don't do this in PSX. -// [D] +// [D] [T] void SetCameraVector(void) { gte_ldfc(&camera_position) } -// [D] +// [D] [T] void Apply_Inv_CameraMatrix(VECTOR *v) { gte_ldlvl(v); @@ -20,6 +20,7 @@ void Apply_Inv_CameraMatrix(VECTOR *v) gte_stlvl(v); } +// [D] [T] int Apply_InvCameraMatrixSetTrans(VECTOR_NOPAD *pos) { VECTOR vfc; @@ -44,6 +45,7 @@ int Apply_InvCameraMatrixSetTrans(VECTOR_NOPAD *pos) return vec.vz + vec.vx; } +// [D] [T] int Apply_InvCameraMatrixAndSetMatrix(VECTOR_NOPAD *pos, MATRIX2 *mtx) { VECTOR vfc; @@ -72,7 +74,7 @@ int Apply_InvCameraMatrixAndSetMatrix(VECTOR_NOPAD *pos, MATRIX2 *mtx) extern MATRIX frustrum_matrix; -// [D] +// [D] [T] int FrustrumCheck16(PACKED_CELL_OBJECT *pcop, int bounding_sphere) { VECTOR local; @@ -95,7 +97,7 @@ int FrustrumCheck16(PACKED_CELL_OBJECT *pcop, int bounding_sphere) return -1; } -// [D] +// [D] [T] int FrustrumCheck(VECTOR *pos, int bounding_sphere) { VECTOR local; From 90ae481120c8f2bbf083e4758f3938e6a28b8682 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 3 Sep 2020 22:26:55 +0600 Subject: [PATCH 4/6] - refactor BCOLL3D.C --- src_rebuild/GAME/C/BCOLL3D.C | 65 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/src_rebuild/GAME/C/BCOLL3D.C b/src_rebuild/GAME/C/BCOLL3D.C index 863a9c13..7e3b5d1d 100644 --- a/src_rebuild/GAME/C/BCOLL3D.C +++ b/src_rebuild/GAME/C/BCOLL3D.C @@ -33,18 +33,13 @@ /* end block 2 */ // End Line: 167 -// [D] +// [D] [T] void PointFaceCheck(_CAR_DATA *cp0, _CAR_DATA *cp1, int i, TestResult *least, int nSign) { - int iVar1; - //short *psVar2; - int iVar3; - int iVar4; - int iVar5; - int iVar6; - //short *psVar7; - SVECTOR_NOPAD *pSVar8; - int iVar9; + int partialDepth; + int depth; + SVECTOR_NOPAD *radii; + int k; VECTOR normal; VECTOR diff; @@ -62,9 +57,9 @@ void PointFaceCheck(_CAR_DATA *cp0, _CAR_DATA *cp1, int i, TestResult *least, in diff.vy = point.vy - cp0->hd.oBox.location.vy; diff.vz = point.vz - cp0->hd.oBox.location.vz; - iVar4 = FIXED(diff.vx * normal.vx + diff.vy * normal.vy + diff.vz * normal.vz); + depth = FIXED(diff.vx * normal.vx + diff.vy * normal.vy + diff.vz * normal.vz); - if (iVar4 < 0) + if (depth < 0) { normal.vx = -normal.vx; normal.vy = -normal.vy; @@ -72,43 +67,43 @@ void PointFaceCheck(_CAR_DATA *cp0, _CAR_DATA *cp1, int i, TestResult *least, in } else { - iVar4 = -iVar4; + depth = -depth; } - pSVar8 = cp1->hd.oBox.radii; - iVar4 += cp0->hd.oBox.length[i]; + radii = cp1->hd.oBox.radii; + depth += cp0->hd.oBox.length[i]; - iVar9 = 2; + k = 2; do { - iVar3 = pSVar8->vx; - iVar5 = pSVar8->vy; - iVar6 = pSVar8->vz; + diff.vx = radii->vx; + diff.vy = radii->vy; + diff.vz = radii->vz; - iVar1 = FIXED(iVar3 * normal.vx + iVar5 * normal.vy + iVar6 * normal.vz); + partialDepth = FIXED(diff.vx * normal.vx + diff.vy * normal.vy + diff.vz * normal.vz); - if (iVar1 < 0) + if (partialDepth < 0) { - iVar1 = -iVar1; + partialDepth = -partialDepth; } else { - iVar3 = -iVar3; - iVar5 = -iVar5; - iVar6 = -iVar6; + diff.vx = -diff.vx; + diff.vy = -diff.vy; + diff.vz = -diff.vz; } - point.vy += iVar5; - point.vx += iVar3; - point.vz += iVar6; + point.vx += diff.vx; + point.vy += diff.vy; + point.vz += diff.vz; - iVar4 += iVar1; + depth += partialDepth; - pSVar8++; - iVar9--; - } while (-1 < iVar9); + radii++; + k--; + } while (k >= 0); - if (iVar4 < least->depth && (least->depth = iVar4, -1 < iVar4)) + if (depth < least->depth && (least->depth = depth, -1 < depth)) { least->location.vx = point.vx; least->location.vy = point.vy; @@ -152,7 +147,7 @@ void PointFaceCheck(_CAR_DATA *cp0, _CAR_DATA *cp1, int i, TestResult *least, in /* end block 3 */ // End Line: 267 -// [D] +// [D] [T] int collided3d(_CAR_DATA *cp0, _CAR_DATA *cp1, TestResult *least) { int i; @@ -209,7 +204,7 @@ int collided3d(_CAR_DATA *cp0, _CAR_DATA *cp1, TestResult *least) /* end block 3 */ // End Line: 361 -// [D] +// [D] [T] int CarCarCollision3(_CAR_DATA *c0, _CAR_DATA *c1, int *depth, VECTOR *where, VECTOR *normal) { int res; From a477cd853c0fa763adc0af60d2e142e565fa3cc3 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 3 Sep 2020 22:27:18 +0600 Subject: [PATCH 5/6] - refactor AI.C - fix MAP.C refactoring --- src_rebuild/GAME/C/AI.C | 43 ++++++++++++++++++---------------------- src_rebuild/GAME/C/MAP.C | 30 +++++++++++++++++----------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src_rebuild/GAME/C/AI.C b/src_rebuild/GAME/C/AI.C index 54bf2632..dac888a8 100644 --- a/src_rebuild/GAME/C/AI.C +++ b/src_rebuild/GAME/C/AI.C @@ -28,7 +28,7 @@ /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void StoreGameFlags(void) { ReplayParameterPtr->weather = gWeather; @@ -68,11 +68,11 @@ void StoreGameFlags(void) /* end block 3 */ // End Line: 661 -// [D] +// [D] [T] int TannerCanEnterCar(_CAR_DATA *cp, int distToCarSq) { - int iVar1; - int iVar2; + int speed; + int carRange; if ((cp->controlFlags & 1) != 0) gCopCarTheftAttempted = 1; @@ -83,20 +83,20 @@ int TannerCanEnterCar(_CAR_DATA *cp, int distToCarSq) (cp->controlFlags & 2) == 0 && cp->hd.where.m[1][1] > 99) // not flipped over { - iVar1 = FIXED(cp->hd.wheel_speed); + speed = FIXED(cp->hd.wheel_speed); - if (iVar1 < 0) - iVar1 = -iVar1; + if (speed < 0) + speed = -speed; - if (iVar1 < 3) + if (speed < 3) { - iVar1 = car_cosmetics[cp->ap.model].colBox.vx * 2; - iVar2 = iVar1 * iVar1; + carRange = car_cosmetics[cp->ap.model].colBox.vx * 2; + carRange *= carRange; - if (5000 < iVar1) - iVar2 = 25000000; + if (5000 < carRange) + carRange = 25000000; - return (iVar2 < distToCarSq) ^ 1; + return (carRange < distToCarSq) ^ 1; } } @@ -132,7 +132,7 @@ int TannerCanEnterCar(_CAR_DATA *cp, int distToCarSq) int TannerStuckInCar(int doSpeedCheck, int player_id) { short *psVar1; - int iVar2; + int speed; int iVar3; _CAR_DATA *cp; @@ -160,12 +160,12 @@ int TannerStuckInCar(int doSpeedCheck, int player_id) { if (doSpeedCheck != 0) { - iVar2 = FIXED(cp->hd.wheel_speed); + speed = FIXED(cp->hd.wheel_speed); - if (iVar2 < 0) - iVar2 = -iVar2; + if (speed < 0) + speed = -speed; - if (2 < iVar2) + if (speed > 2) return 1; } @@ -177,9 +177,4 @@ int TannerStuckInCar(int doSpeedCheck, int player_id) } return 1; -} - - - - - +} \ No newline at end of file diff --git a/src_rebuild/GAME/C/MAP.C b/src_rebuild/GAME/C/MAP.C index eacaf43f..dba48adf 100644 --- a/src_rebuild/GAME/C/MAP.C +++ b/src_rebuild/GAME/C/MAP.C @@ -389,8 +389,7 @@ int newPositionVisible(VECTOR *pos, char *pvs, int ccx, int ccz) int cellx; // $v1 int cellz; // $v0 - int iVar1; - int iVar2; + int ab; dx = pos->vx + units_across_halved; dz = pos->vz + units_down_halved; @@ -399,14 +398,18 @@ int newPositionVisible(VECTOR *pos, char *pvs, int ccx, int ccz) cellz = (dz >> 0xb) - ccz; if (cellx < 0) - cellx = -cellx; + ab = -cellx; + else + ab = cellx; - if (cellx <= view_dist) + if (ab <= view_dist) { if (cellz < 0) - cellz = -cellz; + ab = -cellz; + else + ab = cellz; - if (cellz <= view_dist) + if (ab <= view_dist) return pvs[cellx + 10 + (cellz + 10) * pvs_square] != 0; } @@ -454,8 +457,7 @@ int PositionVisible(VECTOR *pos) int cellx; // $v1 int cellz; // $v0 - int iVar1; - int iVar2; + int ab; dx = pos->vx + units_across_halved; dz = pos->vz + units_down_halved; @@ -464,14 +466,18 @@ int PositionVisible(VECTOR *pos) cellz = (dz >> 0xb) - current_cell_z; if (cellx < 0) - cellx = -cellx; + ab = -cellx; + else + ab = cellx; - if (cellx <= view_dist) + if (ab <= view_dist) { if (cellz < 0) - cellz = -cellz; + ab = -cellz; + else + ab = cellz; - if (cellz <= view_dist) + if (ab <= view_dist) return CurrentPVS[cellx + 10 + (cellz + 10) * pvs_square] != 0; } From d99419c374806ba82bcc30ceef6057175ad79390 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 4 Sep 2020 00:38:25 +0600 Subject: [PATCH 6/6] - mostly refactored BCOLLIDE.C --- src_rebuild/GAME/C/BCOLLIDE.C | 690 ++++++++++++++-------------------- 1 file changed, 284 insertions(+), 406 deletions(-) diff --git a/src_rebuild/GAME/C/BCOLLIDE.C b/src_rebuild/GAME/C/BCOLLIDE.C index 618ac2bb..90409192 100644 --- a/src_rebuild/GAME/C/BCOLLIDE.C +++ b/src_rebuild/GAME/C/BCOLLIDE.C @@ -59,179 +59,128 @@ int boxOverlap = 0; -// Checks of two bodies collides (basic check) +// Checks of two bodies collides (basic check) with Separating Axis Theorem // also initializes axes -// [D] [A] +// [D] [T] int bcollided2d(CDATA2D *body, int needOverlap) { + int dtheta; + int absdist; + int abslim; short ac; short as; - short sVar3; - short sVar4; - int dtheta; - int iVar6; - int iVar7; - int iVar8; - int iVar9; - int *piVar10; - CDATA2D *pCVar11; - VECTOR *pVVar12; - int *piVar13; - int *piVar14; - int *piVar15; - int *piVar16; - int *piVar17; - int iVar18; - int iVar19; - int uVar20; - VECTOR *pVVar21; - int *plVar22; - int *piVar23; - int iVar24; - int *piVar25; + int i; // $t7 + int j; // $a2 + int k; // $t5 VECTOR delta; + int xover; // $t0 + int zover; // $a0 + int tmp2; // $a2 + int FE; // $a3 - iVar19 = 1; - pCVar11 = body + 1; dtheta = body[1].theta - body[0].theta; + // calc axes of each box + i = 1; + do { + as = rcossin_tbl[(body[i].theta & 0xfff) * 2]; + ac = rcossin_tbl[(body[i].theta & 0xfff) * 2 + 1]; + + body[i].axis[0].vx = as; + body[i].axis[0].vz = ac; + + body[i].axis[1].vz = -as; + body[i].axis[1].vx = ac; + + i--; + } while (i != -1); + ac = rcossin_tbl[(dtheta + 0x400 & 0x7ff) * 2]; as = rcossin_tbl[(dtheta & 0x7ff) * 2]; - // calc axes of each box - do { - dtheta = body[iVar19].theta & 0xfff; - sVar3 = rcossin_tbl[dtheta * 2]; - sVar4 = rcossin_tbl[dtheta * 2 + 1]; - - body[iVar19].axis[0].vx = sVar3; - body[iVar19].axis[0].vz = sVar4; - - body[iVar19].axis[1].vz = -sVar3; - body[iVar19].axis[1].vx = sVar4; - - iVar19--; - } while (iVar19 != -1); - - dtheta = 0; - uVar20 = 1; - - piVar23 = body[1].limit; - piVar25 = body[1].dist; - - iVar24 = 100; - delta.vx = body[0].x.vx - body[1].x.vx; delta.vz = body[0].x.vz - body[1].x.vz; + k = 0; + i = 1; + do { - - piVar15 = piVar23 + 1; - piVar10 = piVar25 + 1; - - piVar17 = body[uVar20].length + 1; - piVar16 = body[dtheta].length + 1; - piVar14 = body[dtheta].length; - - pVVar12 = body[uVar20].axis + 1; - - - iVar18 = 1; + j = 1; do { - *piVar10 = FIXED(pVVar12->vx * delta.vx + pVVar12->vz * delta.vz); - iVar7 = *piVar17 + FIXED(*piVar16 * ac + *piVar14 * as); - *piVar15 = iVar7; + body[i].dist[j] = FIXED(body[i].axis[j].vx * delta.vx + body[i].axis[j].vz * delta.vz); + body[i].limit[j] = body[i].length[j] + FIXED(body[k].length[j] * ac + body[k].length[1-j] * as); - if (iVar7 < *piVar10) + if (body[i].limit[j] < body[i].dist[j]) return 0; - if (*piVar10 < -iVar7) + if (body[i].dist[j] < -body[i].limit[j]) return 0; - piVar15--; - piVar10--; + j--; + } while (j != -1); - piVar17--; - piVar16--; + k = i & 1; + i--; - - pVVar12--; - iVar18--; - - piVar14++; - } while (iVar18 != -1); - - dtheta = uVar20 & 1; - - piVar23 -= 25; - piVar25 = piVar25 - 25; - iVar24 -= 100; - - uVar20--; - - if (uVar20 == -1) + if (i == -1) { if (needOverlap != 0) { - iVar19 = body[1].dist[0]; - iVar6 = body[1].limit[0]; + absdist = body[1].dist[0]; - if (iVar19 < 0) - iVar19 = -iVar19; + if (absdist < 0) + absdist = -absdist; - if (iVar6 < 0) - iVar6 = -iVar6; + abslim = body[1].limit[0]; + if (abslim < 0) + abslim = -abslim; - iVar8 = iVar19 - iVar6; - if (iVar8 < 0) - iVar8 = iVar6 - iVar19; + FE = absdist - abslim; + if (FE < 0) + FE = abslim - absdist; - iVar9 = body[0].axis[0].vx; - iVar6 = body[0].axis[0].vz; + tmp2 = FIXED(body->axis[0].vx * body[1].axis[0].vx + body->axis[0].vz * body[1].axis[0].vz); + if (tmp2 < 0) + tmp2 = -tmp2; - iVar19 = FIXED(iVar9 * body[1].axis[0].vx + iVar6 * body[1].axis[0].vz); + if (tmp2 < 11) + xover = -1; + else + xover = (FE << 0xc) / tmp2; - if (iVar19 < 0) - iVar19 = -iVar19; + absdist = body[1].dist[1]; + + if (absdist < 0) + absdist = -absdist; - if (iVar19 < 11) - iVar8 = -1; - else - iVar8 = (iVar8 * 4096) / iVar19; + abslim = body[1].limit[1]; + if (abslim < 0) + abslim = -abslim; + FE = absdist - abslim; - iVar19 = body[1].dist[1]; - iVar24 = body[1].limit[1]; + if (FE < 0) + FE = abslim - absdist; - if (iVar19 < 0) - iVar19 = -iVar19; + tmp2 = FIXED(body->axis[0].vx * body[1].axis[1].vx + body->axis[0].vz * body[1].axis[1].vz); - if (iVar24 < 0) - iVar24 = -iVar24; + if (tmp2 < 0) + tmp2 = -tmp2; - iVar18 = iVar19 - iVar24; - if (iVar18 < 0) - iVar18 = iVar24 - iVar19; + zover = xover; + if (10 < tmp2) + zover = (FE << 0xc) / tmp2; - iVar19 = FIXED(iVar9 * body[1].axis[1].vx + iVar6 * body[1].axis[1].vz); - if (iVar19 < 0) - iVar19 = -iVar19; - - iVar6 = iVar8; - - if (10 < iVar19) - iVar6 = (iVar18 * 4096) / iVar19; - - boxOverlap = iVar6; - - if (-1 < iVar8) + if (xover > -1) { - boxOverlap = iVar8; - - if (iVar6 < iVar8) - boxOverlap = iVar6; + if (zover < xover) + boxOverlap = zover; + else + boxOverlap = xover; } + else + boxOverlap = zover; } return 1; } @@ -300,141 +249,107 @@ int bcollided2d(CDATA2D *body, int needOverlap) /* end block 4 */ // End Line: 432 -// [D] +// [D] [T] void bFindCollisionPoint(CDATA2D *body, CRET2D *collisionResult) { - bool bVar1; - int iVar2; - int iVar3; - int iVar4; - int iVar5; - int *piVar6; - CDATA2D *pCVar7; - uint uVar8; - int *piVar9; - int iVar10; - int iVar11; - int local_t1_132; - int *piVar12; - int *piVar13; - int iVar14; - int iVar15; - int local_t5_4; - VECTOR *pVVar16; - int iVar17; + bool carBarrierCollision; + int lower; + int upper; + int sign1; + int k; + int _k; + int sign0; + int sign; + int smallest; + int besti; + int bestk; + CDATA2D* cd; + int i; - local_t5_4 = 0; - iVar17 = 0; - iVar14 = 0; - bVar1 = false; - iVar15 = body->limit[0] + 1; + besti = 0; + bestk = 0; + sign = 0; + carBarrierCollision = false; - if ((body->isCameraOrTanner == 0) && (body[1].isCameraOrTanner == 0)) + smallest = body->limit[0] + 1; + + if ((body->isCameraOrTanner == 0) && (body[1].isCameraOrTanner == 0) && + (body[1].length[0] << 3 <= body[1].length[1]) || (body[1].length[1] << 3 <= body[1].length[0])) { - if ((body[1].length[0] << 2 <= body[1].length[1]) || - (body[1].length[1] << 2 <= body[1].length[0])) - { - bVar1 = true; - } + carBarrierCollision = true; } - uVar8 = 1; + i = 1; do { - iVar11 = 1; - local_t1_132 = uVar8 - 1; - piVar6 = body[uVar8].dist + 1; - + k = 1; do { - iVar5 = piVar6[2] - *piVar6; - iVar2 = *piVar6 + piVar6[2]; + upper = body[i].limit[k] - body[i].dist[k]; + lower = body[i].dist[k] + body[i].limit[k]; - if ((iVar5 < iVar15) && - (iVar14 = -1, iVar15 = iVar5, local_t5_4 = uVar8, iVar17 = iVar11, uVar8 == 1)) { - iVar14 = 1; + if (upper < smallest && (sign = -1, smallest = upper, besti = i, bestk = k, i == 1)) + { + sign = 1; } - if ((iVar2 < iVar15) && - (iVar14 = 1, iVar15 = iVar2, local_t5_4 = uVar8, iVar17 = iVar11, uVar8 == 1)) { - iVar14 = -1; + if (lower < smallest && (sign = 1, smallest = lower, besti = i, bestk = k, i == 1)) + { + sign = -1; } - iVar11--; - piVar6--; - } while (iVar11 != -1); + k--; + } while (k != -1); - iVar11 = 1; - uVar8 = local_t1_132; - } while (local_t1_132 != -1); + + i--; + } while (i != -1); - if (bVar1) + if (carBarrierCollision) { - piVar9 = body[1].length + 1; - piVar6 = body[1].length; - piVar13 = body[1].dist + 1; - piVar12 = body[1].limit + 1; - + k = 1; do { - iVar5 = *piVar12 - *piVar13; - iVar2 = *piVar13 + *piVar12; + upper = body[1].limit[k] - body[1].dist[k]; + lower = body[1].dist[k] + body[1].limit[k]; - if ((iVar5 < iVar2) && (*piVar9 < *piVar6 << 2)) + if (upper < lower && (body[1].length[k] < body[1].length[1-k] << 2)) { - local_t5_4 = 1; - iVar14 = 1; - iVar17 = iVar11; + besti = 1; + sign = 1; + bestk = k; } - if ((iVar2 < iVar5) && (*piVar9 < *piVar6 << 2)) + if (lower < upper && (body[1].length[k] < body[1].length[1 - k] << 2)) { - local_t5_4 = 1; - iVar14 = -1; - iVar17 = iVar11; + besti = 1; + sign = -1; + bestk = k; } - piVar9--; - piVar6++; - piVar13--; - iVar11--; - piVar12--; - } while (iVar11 != -1); + k--; + } while (k != -1); } - pCVar7 = body + (local_t5_4 ^ 1); - pVVar16 = body[local_t5_4].axis + iVar17; - iVar5 = pCVar7->axis[0].vx; - iVar2 = pVVar16->vx; - piVar6 = (int*)&body[local_t5_4].axis[iVar17].vz; - iVar11 = body[local_t5_4].axis[iVar17].vz; - iVar17 = iVar14; + cd = &body[(besti ^ 1)]; - if (-1 < iVar5 * iVar2 + pCVar7->axis[0].vz * iVar11) - iVar17 = -iVar14; + sign0 = sign; + if (-1 < cd->axis[0].vx * body[besti].axis[bestk].vx + cd->axis[0].vz * body[besti].axis[bestk].vz + 0x800) + sign0 = -sign; - iVar3 = pCVar7->axis[1].vx; - iVar10 = iVar14; + sign1 = sign; - if (-1 < iVar3 * iVar2 + pCVar7->axis[1].vz * iVar11) - iVar10 = -iVar14; + if (-1 < cd->axis[1].vx * body[besti].axis[bestk].vx + cd->axis[1].vz * body[besti].axis[bestk].vz + 0x800) + sign1 = -sign; - collisionResult->hit.vx = pCVar7->x.vx + FIXED(iVar5 * pCVar7->length[0] * iVar17 + iVar3 * pCVar7->length[1] * iVar10); + collisionResult->penetration = smallest; - iVar11 = pCVar7->axis[0].vz; - iVar2 = pCVar7->length[0]; - iVar4 = pCVar7->axis[1].vz; - iVar5 = pCVar7->length[1]; - iVar3 = pCVar7->x.vz; + collisionResult->hit.vx = cd->x.vx + FIXED(cd->axis[0].vx * cd->length[0] * sign0 + cd->axis[1].vx * cd->length[1] * sign1); + collisionResult->hit.vz = cd->x.vz + FIXED(cd->axis[0].vz * cd->length[0] * sign0 + cd->axis[1].vz * cd->length[1] * sign1); - collisionResult->penetration = iVar15; - collisionResult->hit.vz = pCVar7->x.vz + FIXED(iVar11 * iVar2 * iVar17 + iVar4 * iVar5 * iVar10); - - if (local_t5_4 != 0) - iVar14 = -iVar14; - - iVar15 = pVVar16->vx; + if (besti != 0) + sign = -sign; collisionResult->surfNormal.vy = 0; - collisionResult->surfNormal.vx = iVar15 * iVar14; - collisionResult->surfNormal.vz = *piVar6 * iVar14; + collisionResult->surfNormal.vx = body[besti].axis[bestk].vx * sign; + collisionResult->surfNormal.vz = body[besti].axis[bestk].vz * sign; } @@ -468,151 +383,121 @@ void bFindCollisionPoint(CDATA2D *body, CRET2D *collisionResult) /* end block 3 */ // End Line: 639 -// [D] +// [D] [T] int bFindCollisionTime(CDATA2D *cd, CRET2D *collisionResult) { - int *piVar1; - VECTOR *pVVar2; - int iVar3; - long lVar4; - CDATA2D *pCVar5; - int *local_a1_184; - int iVar6; - int *piVar7; - int *piVar8; - int iVar9; - int iVar10; - int iVar11; - int iVar12; - int iVar13; - CDATA2D *pCVar14; - long *plVar15; - int iVar16; - int iVar17; - int iVar18; + CDATA2D* coll; + int hit; + int q; + int time; + int step; + int i; + int neverfree; CDATA2D original[2]; - iVar11 = 1; - iVar18 = 1; - iVar13 = 0x1000; - iVar16 = 0x800; - iVar17 = 1; - pCVar5 = cd + 1; - iVar10 = 100; - + hit = 1; + neverfree = 1; + time = 0x1000; + step = 0x800; + + i = 1; do { - original[iVar17].x.vx = cd[iVar17].x.vx; - original[iVar17].x.vz = cd[iVar17].x.vz; - original[iVar17].theta = cd[iVar17].theta; + original[i].dist[0] = cd[i].dist[0]; + original[i].limit[0] = cd[i].limit[0]; + original[i].dist[1] = cd[i].dist[1]; + original[i].limit[1] = cd[i].limit[1]; + original[i].axis[0] = cd[i].axis[0]; + original[i].axis[1] = cd[i].axis[1]; - original[iVar17].dist[0] = cd[iVar17].dist[0]; - original[iVar17].limit[0] = cd[iVar17].limit[0]; - original[iVar17].dist[1] = cd[iVar17].dist[1]; - original[iVar17].limit[1] = cd[iVar17].limit[1]; - iVar17--; + original[i].x = cd[i].x; + original[i].theta = cd[i].theta; - } while (iVar17 != -1); + i--; - iVar10 = 7; + } while (i != -1); + + i = 7; do { - iVar12 = 1; - iVar17 = iVar10 + -1; - pCVar5 = cd + 1; - do - { - iVar6 = pCVar5->vel.vx / 2; - iVar3 = pCVar5->vel.vz; + + coll = cd + 1; + q = 1; + do { + coll->vel.vx >>= 1; + coll->vel.vz >>= 1; + coll->avel >>= 1; - iVar9 = pCVar5->avel / 2; - - pCVar5->vel.vx = iVar6; - pCVar5->avel = iVar9; - - iVar3 = iVar3 >> 1; - pCVar5->vel.vz = iVar3; - - if (iVar11 == 0) + if (hit == 0) { - pCVar5->x.vx += iVar6; - pCVar5->x.vz += iVar3; - - iVar6 = pCVar5->theta + iVar9; + coll->x.vx += coll->vel.vx; + coll->x.vz += coll->vel.vz; + coll->theta += coll->avel; } - else + else { - pCVar5->x.vx -= iVar6; - pCVar5->x.vz -= iVar3; - iVar6 = pCVar5->theta - iVar9; + coll->x.vx -= coll->vel.vx; + coll->x.vz -= coll->vel.vz; + coll->theta -= coll->avel; } - pCVar5->theta = iVar6; - iVar12--; - pCVar5--; - } while (iVar12 != -1); + q--; + coll--; + } while (q != -1); - if (iVar11 == 0) + if (hit == 0) { - iVar18 = 0; - iVar11 = iVar16; + neverfree = 0; + time += step; } - else + else { - iVar11 = -iVar16; + time -= step; } - iVar13 = iVar13 + iVar11; + hit = bcollided2d(cd, 0); - iVar11 = bcollided2d(cd, 0); + if (i != 0) + step >> 1; - if (iVar10 != 0) - iVar16 = iVar16 >> 1; + i--; + } while (i != -1); - iVar12 = 1; - iVar10 = iVar17; - } while (iVar17 != -1); - - if (iVar11 == 0) + if (hit == 0) { - pCVar5 = cd + 1; + i = 1; + coll = cd + 1; + do { + coll->x.vx += coll->vel.vx; + coll->x.vz += coll->vel.vz; + coll->theta += coll->avel; - do { - pCVar5->x.vx += pCVar5->vel.vx; - pCVar5->x.vz += pCVar5->vel.vz; - pCVar5->theta += pCVar5->avel; - - iVar12--; - pCVar5--; - } while (iVar12 != -1); + coll--; + i--; + } while (i != -1); bcollided2d(cd, 0); - iVar13 = iVar13 + iVar16; + time += step; } - else + else if (neverfree != 0) { - iVar11 = 1; - if (iVar18 != 0) - { - pCVar5 = cd + 1; - pCVar14 = original + 1; + i = 1; + coll = cd + 1; + do { + coll->x.vx = original[i].x.vx; + coll->x.vz = original[i].x.vz; + coll->theta = original[i].theta; - do { - pCVar5->x.vx = pCVar14->x.vx; - pCVar5->x.vz = pCVar14->x.vz; - pCVar5->theta = pCVar14->theta; + bcollided2d(cd, 0); - bcollided2d(cd, 0); + coll--; + i--; + } while (i != -1); - pCVar14--; - pCVar5--; - iVar11--; - } while (iVar11 != -1); - - iVar13 = 0x1000; - } + time = 0x1000; } - collisionResult->neverfree = iVar18; - return iVar13; + collisionResult->neverfree = neverfree; + + return time; } @@ -640,17 +525,12 @@ int bFindCollisionTime(CDATA2D *cd, CRET2D *collisionResult) /* end block 3 */ // End Line: 994 -// [D] +// [D] [T] void ApplyDamage(_CAR_DATA *cp, char region, int value, char fakeDamage) { - ushort uVar1; - int iVar2; - int iVar3; - ushort *puVar4; - short *psVar5; + short *pRegion; - iVar3 = region; - puVar4 = (ushort *)(cp->ap.damage + region); + pRegion = (cp->ap.damage + region); if (cp->controlType == 1 || cp->controlType == 4) value = value * FIXED(gPlayerDamageFactor); @@ -661,20 +541,14 @@ void ApplyDamage(_CAR_DATA *cp, char region, int value, char fakeDamage) { if (gCopDifficultyLevel == 1) { - iVar2 = value * 0xc; + value = value * 12 >> 4; } - else + else if (gCopDifficultyLevel == 2) { - if (gCopDifficultyLevel != 2) - goto LAB_0001cf9c; - - iVar2 = value * 7; + value = value * 7 >> 4; } - value = iVar2 >> 4; } -LAB_0001cf9c: - if (fakeDamage == 0) { if (cp->totalDamage < 0xffff - value) @@ -683,40 +557,39 @@ LAB_0001cf9c: cp->totalDamage = 0xffff; } - uVar1 = *puVar4; - *puVar4 = (uVar1 + value); + *pRegion += value; - if (0xfff < ((uVar1 + value) * 0x10000) >> 0x10) - *puVar4 = 0xfff; + if (*pRegion > 4095) + *pRegion = 4095; - if (iVar3 == 1) - iVar3 = 0; - else if (iVar3 == 0) - iVar3 = 1; - else if (iVar3 == 3) - iVar3 = 4; - else if (iVar3 == 4) - iVar3 = 3; + // adjust symmetric regions + if (region == 1) + region = 0; + else if (region == 0) + region = 1; + else if (region == 3) + region = 4; + else if (region == 4) + region = 3; else - iVar3 = -1; + region = -1; - - if (iVar3 != -1) + if (region != -1) { - psVar5 = cp->ap.damage + iVar3; - value = value >> 1; + pRegion = cp->ap.damage + region; + value >>= 1; - if (*psVar5 < value) + if (*pRegion < value) { if (fakeDamage == 0) { - if (cp->totalDamage < 0xffff - (value - *psVar5)) - cp->totalDamage += (value - *psVar5); + if (cp->totalDamage < 0xffff - (value - *pRegion)) + cp->totalDamage += (value - *pRegion); else cp->totalDamage = 0xffff; } - *psVar5 = value; + *pRegion = value; } } } @@ -763,16 +636,16 @@ LAB_0001cf9c: /* end block 3 */ // End Line: 1169 -// [D] +// [D] [T] int DamageCar3D(_CAR_DATA *cp, long(*delta)[4], int strikeVel, _CAR_DATA *pOtherCar) { char region; int value; - int iVar1; bool fakeDamage; int player_id; int kludge; + int door, nose; strikeVel = strikeVel * 0x177; @@ -789,20 +662,21 @@ int DamageCar3D(_CAR_DATA *cp, long(*delta)[4], int strikeVel, _CAR_DATA *pOther return 0; } - iVar1 = FIXED(cp->hd.where.m[0][2] * (*delta)[0] + cp->hd.where.m[1][2] * (*delta)[1] + cp->hd.where.m[2][2] * (*delta)[2]); + nose = FIXED(cp->hd.where.m[0][2] * (*delta)[0] + cp->hd.where.m[1][2] * (*delta)[1] + cp->hd.where.m[2][2] * (*delta)[2]); + door = FIXED(cp->hd.where.m[0][0] * (*delta)[0] + cp->hd.where.m[1][0] * (*delta)[1] + cp->hd.where.m[2][0] * (*delta)[2]); - if (FIXED(cp->hd.where.m[0][0] * (*delta)[0] + cp->hd.where.m[1][0] * (*delta)[1] + cp->hd.where.m[2][0] * (*delta)[2]) < 1) + if (door < 1) { region = 0; - if ((iVar1 <= value) && (region = 4, -value < iVar1)) + if ((nose <= value) && (region = 4, -value < nose)) region = 5; } else { region = 1; - if ((iVar1 <= value) && (region = 3, -value < iVar1)) + if ((nose <= value) && (region = 3, -value < nose)) region = 2; } @@ -842,8 +716,7 @@ int DamageCar3D(_CAR_DATA *cp, long(*delta)[4], int strikeVel, _CAR_DATA *pOther } else { - iVar1 = (strikeVel / 400 + 0x400) * 7; - value = iVar1 >> 3; + value = ((strikeVel / 400 + 0x400) * 7) >> 3; } fakeDamage = cp->controlType == 3 && pOtherCar->controlType == 3; @@ -902,17 +775,20 @@ int DamageCar3D(_CAR_DATA *cp, long(*delta)[4], int strikeVel, _CAR_DATA *pOther /* end block 3 */ // End Line: 1442 -// [D] +// [D] [T] void DamageCar(_CAR_DATA *cp, CDATA2D *cd, CRET2D *collisionResult, int strikeVel) { int impact; - int iVar1; + int player_id; int value; - int iVar2; - int iVar3; - int iVar4; + int nose; + int door; + int region; + int dz; + int dx; + + player_id = GetPlayerId(cp); - iVar1 = GetPlayerId(cp); value = cp->ap.carCos->colBox.vz << 0x10; impact = strikeVel / 600; @@ -920,22 +796,24 @@ void DamageCar(_CAR_DATA *cp, CDATA2D *cd, CRET2D *collisionResult, int strikeVe if (0x4fff < strikeVel && 9 < cp->hd.speed) { - iVar4 = collisionResult->hit.vx - cd->x.vx; - iVar3 = collisionResult->hit.vz - cd->x.vz; + dx = collisionResult->hit.vx - cd->x.vx; + dz = collisionResult->hit.vz - cd->x.vz; - iVar2 = FIXED(cd->axis[0].vx * iVar4 + cd->axis[0].vz * iVar3); + nose = FIXED(cd->axis[0].vx * dx + cd->axis[0].vz * dz); + door = FIXED(cd->axis[1].vx * dx + cd->axis[1].vz * dz); - if (FIXED(cd->axis[1].vx * iVar4 + cd->axis[1].vz * iVar3) < 1) + if (door < 1) { - iVar3 = 0; - if ((iVar2 <= value) && (iVar3 = 4, -value < iVar2)) - iVar3 = 5; + region = 0; + if ((nose <= value) && (region = 4, -value < nose)) + region = 5; } - else { - iVar3 = 1; + else + { + region = 1; - if ((iVar2 <= value) && (iVar3 = 3, -value < iVar2)) - iVar3 = 2; + if ((nose <= value) && (region = 3, -value < nose)) + region = 2; } if (0x1f4000 < strikeVel) strikeVel = 0x1f4000; @@ -944,7 +822,7 @@ void DamageCar(_CAR_DATA *cp, CDATA2D *cd, CRET2D *collisionResult, int strikeVe if (0x800 < value) value = 0x800; - value -= (value * cp->ap.damage[iVar3] >> 0xd); + value -= (value * cp->ap.damage[region] >> 0xd); if (cp->controlType == 4) { @@ -954,8 +832,8 @@ void DamageCar(_CAR_DATA *cp, CDATA2D *cd, CRET2D *collisionResult, int strikeVe value = value / 2; } - ApplyDamage(cp, iVar3, value, 0); - CollisionSound(iVar1, cp, impact, 0); + ApplyDamage(cp, region, value, 0); + CollisionSound(player_id, cp, impact, 0); } }