From ff4e9d59e0f4b94c448b2e18e5b51d35c1026be0 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 15 Jul 2024 17:51:33 +0200 Subject: [PATCH] port HWR_DrawPolyList --- docs/progress.svg | 16 ++++++------- docs/progress.txt | 2 +- src/game/hwr.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ src/game/hwr.h | 1 + src/global/funcs.h | 1 - src/inject_exec.c | 1 + 6 files changed, 67 insertions(+), 10 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index a4fdddf..8007101 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -43.51% (530) · 54.02% (658) · 0% (0) · 2.46% (30) +43.60% (531) · 53.94% (657) · 0% (0) · 2.46% (30) - - + + @@ -1091,7 +1091,7 @@ void __cdecl HWR_EnableColorKey(bool state); void __cdecl HWR_EnableZBuffer(bool z_write_enable, bool z_enable); void __cdecl HWR_BeginScene(void); -void __cdecl HWR_DrawPolyList(void); +void __cdecl HWR_DrawPolyList(void); void __cdecl HWR_LoadTexturePages(int32_t pages_count, void *pages_buf, RGB_888 *palette); void __cdecl HWR_FreeTexturePages(void); void __cdecl HWR_GetPageHandles(void); @@ -1298,10 +1298,10 @@ Tomb2.exe progress according to the function sizes: -39.80% · 59.87% · 0% · 0.33% +39.91% · 59.77% · 0% · 0.33% - - + + @@ -1564,7 +1564,7 @@ int32_t __cdecl Misc_Move3DPosTo3DPos(PHD_3DPOS *src_pos, PHD_3DPOS *dest_pos, int32_t velocity, PHD_ANGLE ang_add); const int16_t *__cdecl Output_CalcVerticeLight(const int16_t *obj_ptr); int32_t __cdecl Lara_TestHangJumpUp(ITEM_INFO *item, COLL_INFO *coll); -void __cdecl HWR_DrawPolyList(void); +void __cdecl HWR_DrawPolyList(void); void __cdecl Boat_Animation(ITEM_INFO *boat, int32_t collide); void __cdecl draw_flare(void); int32_t __cdecl Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num); diff --git a/docs/progress.txt b/docs/progress.txt index d9ebb40..42234a5 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -3203,7 +3203,7 @@ typedef struct { 0x0044D200 0x004A +R void __cdecl HWR_EnableColorKey(bool state); 0x0044D250 0x0082 +R void __cdecl HWR_EnableZBuffer(bool z_write_enable, bool z_enable); 0x0044D2E0 0x0016 +R void __cdecl HWR_BeginScene(void); -0x0044D310 0x016C -R void __cdecl HWR_DrawPolyList(void); +0x0044D310 0x016C +R void __cdecl HWR_DrawPolyList(void); 0x0044D490 0x008E -R void __cdecl HWR_LoadTexturePages(int32_t pages_count, void *pages_buf, RGB_888 *palette); 0x0044D520 0x004A -R void __cdecl HWR_FreeTexturePages(void); 0x0044D570 0x0035 -R void __cdecl HWR_GetPageHandles(void); diff --git a/src/game/hwr.c b/src/game/hwr.c index 0ecf609..86902b5 100644 --- a/src/game/hwr.c +++ b/src/game/hwr.c @@ -158,3 +158,59 @@ void __cdecl HWR_BeginScene(void) WaitPrimaryBufferFlip(); g_D3DDev->lpVtbl->BeginScene(g_D3DDev); } + +void __cdecl HWR_DrawPolyList(void) +{ + HWR_EnableZBuffer(false, true); + + for (int32_t i = 0; i < g_SurfaceCount; i++) { + uint16_t *buf_ptr = (uint16_t *)g_SortBuffer[i]._0; + + uint16_t poly_type = *buf_ptr++; + uint16_t tex_page = + (poly_type == POLY_HWR_GTMAP || poly_type == POLY_HWR_WGTMAP) + ? *buf_ptr++ + : 0; + uint16_t vtx_count = *buf_ptr++; + D3DTLVERTEX *vtx_ptr = *(D3DTLVERTEX **)buf_ptr; + + switch (poly_type) { + // triangle fan (texture) + case POLY_HWR_GTMAP: + // triangle fan (texture + colorkey) + case POLY_HWR_WGTMAP: + HWR_TexSource(g_HWR_PageHandles[tex_page]); + HWR_EnableColorKey(poly_type == POLY_HWR_WGTMAP); + HWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtx_ptr, vtx_count, true); + break; + + // triangle fan (color) + case POLY_HWR_GOURAUD: + HWR_TexSource(0); + HWR_EnableColorKey(false); + HWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtx_ptr, vtx_count, true); + break; + + // line strip (color) + case POLY_HWR_LINE: + HWR_TexSource(0); + HWR_EnableColorKey(false); + HWR_DrawPrimitive(D3DPT_LINESTRIP, vtx_ptr, vtx_count, true); + break; + + // triangle fan (color + semitransparent) + case POLY_HWR_TRANS: { + DWORD alpha_state; + HWR_TexSource(0); + g_D3DDev->lpVtbl->GetRenderState( + g_D3DDev, g_AlphaBlendEnabler, &alpha_state); + g_D3DDev->lpVtbl->SetRenderState( + g_D3DDev, g_AlphaBlendEnabler, TRUE); + HWR_DrawPrimitive(D3DPT_TRIANGLEFAN, vtx_ptr, vtx_count, true); + g_D3DDev->lpVtbl->SetRenderState( + g_D3DDev, g_AlphaBlendEnabler, alpha_state); + break; + } + } + } +} diff --git a/src/game/hwr.h b/src/game/hwr.h index 724d5fb..d7c19c4 100644 --- a/src/game/hwr.h +++ b/src/game/hwr.h @@ -18,3 +18,4 @@ void __cdecl HWR_TexSource(HWR_TEXTURE_HANDLE tex_source); void __cdecl HWR_EnableColorKey(bool state); void __cdecl HWR_EnableZBuffer(bool z_write_enable, bool z_enable); void __cdecl HWR_BeginScene(void); +void __cdecl HWR_DrawPolyList(void); diff --git a/src/global/funcs.h b/src/global/funcs.h index 9e53edb..ed70f1b 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -512,7 +512,6 @@ #define S_FrontEndCheck ((BOOL __cdecl (*)(void))0x0044CCB0) #define S_SaveGame ((int32_t __cdecl (*)(const void *save_data, uint32_t save_size, int32_t slot_num))0x0044CE20) #define S_LoadGame ((int32_t __cdecl (*)(void *save_data, uint32_t save_size, int32_t slot_num))0x0044CF40) -#define HWR_DrawPolyList ((void __cdecl (*)(void))0x0044D310) #define HWR_LoadTexturePages ((void __cdecl (*)(int32_t pages_count, void *pages_buf, RGB_888 *palette))0x0044D490) #define HWR_FreeTexturePages ((void __cdecl (*)(void))0x0044D520) #define HWR_GetPageHandles ((void __cdecl (*)(void))0x0044D570) diff --git a/src/inject_exec.c b/src/inject_exec.c index ae359b6..32a461b 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -180,6 +180,7 @@ static void Inject_HWR(bool enable) INJECT(enable, 0x0044D200, HWR_EnableColorKey); INJECT(enable, 0x0044D250, HWR_EnableZBuffer); INJECT(enable, 0x0044D2E0, HWR_BeginScene); + INJECT(enable, 0x0044D310, HWR_DrawPolyList); } static void Inject_Background(const bool enable)