perf(engine): implement multi-threaded DDA raycasting with worker thread pool
This commit is contained in:
parent
9d504622ca
commit
36016cc828
4 changed files with 5614 additions and 5517 deletions
Binary file not shown.
103
casino3d.inc
103
casino3d.inc
|
|
@ -34,6 +34,10 @@ CopyFileA PROTO :DWORD,:DWORD,:DWORD
|
|||
lstrcmpiA PROTO :DWORD,:DWORD
|
||||
GetFileSize PROTO :DWORD,:DWORD
|
||||
Sleep PROTO :DWORD
|
||||
CreateThread PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
|
||||
CreateEventA PROTO :DWORD,:DWORD,:DWORD,:DWORD
|
||||
SetEvent PROTO :DWORD
|
||||
WaitForSingleObject PROTO :DWORD,:DWORD
|
||||
|
||||
C3D_POINT STRUCT
|
||||
x dd ?
|
||||
|
|
@ -164,6 +168,13 @@ h3DWnd dd 0
|
|||
h3DDC dd 0
|
||||
hCasinoConsole dd 0
|
||||
|
||||
ALIGN 4
|
||||
hRaycastThread dd 0
|
||||
hRaycastStartEvent dd 0
|
||||
hRaycastDoneEvent dd 0
|
||||
bRaycastQuit dd 0
|
||||
raycastThreadId dd 0
|
||||
|
||||
bmi3D C3D_BITMAPINFO <>
|
||||
msg3D C3D_MSG <>
|
||||
wc3D C3D_WNDCLASSEX <>
|
||||
|
|
@ -696,7 +707,7 @@ DrawString8x8 ENDP
|
|||
; --- True 3D Perspective Floor & Ceiling Rendering ---
|
||||
|
||||
; --- DDA Raycasting Walls ---
|
||||
RenderWalls PROC
|
||||
RenderWallsRange PROC colStart:DWORD, colLimit:DWORD
|
||||
local col:DWORD
|
||||
local originalStart:DWORD
|
||||
local camX:DWORD
|
||||
|
|
@ -746,9 +757,11 @@ RenderWalls PROC
|
|||
idiv ecx
|
||||
mov playerPlaneY, eax
|
||||
|
||||
mov col, 0
|
||||
mov eax, colStart
|
||||
mov col, eax
|
||||
col_loop:
|
||||
cmp col, SCREEN_W
|
||||
mov eax, colLimit
|
||||
cmp col, eax
|
||||
jge walls_done
|
||||
|
||||
mov eax, col
|
||||
|
|
@ -1231,6 +1244,69 @@ walls_done:
|
|||
pop esi
|
||||
pop ebx
|
||||
ret
|
||||
RenderWallsRange ENDP
|
||||
|
||||
; --- Raycasting Background Worker Thread ---
|
||||
RaycastWorkerProc PROC uses ebx esi edi lpParam:DWORD
|
||||
worker_loop:
|
||||
invoke WaitForSingleObject, hRaycastStartEvent, 0FFFFFFFFh
|
||||
cmp bRaycastQuit, 1
|
||||
je worker_exit
|
||||
invoke RenderWallsRange, 320, 640
|
||||
invoke SetEvent, hRaycastDoneEvent
|
||||
jmp worker_loop
|
||||
worker_exit:
|
||||
xor eax, eax
|
||||
ret
|
||||
RaycastWorkerProc ENDP
|
||||
|
||||
; --- Multi-Threaded DDA Raycasting Walls Dispatcher ---
|
||||
RenderWalls PROC
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
|
||||
mov eax, playerAngle
|
||||
and eax, 511
|
||||
mov ebx, [tableCos + eax*4]
|
||||
mov playerDirX, ebx
|
||||
mov ebx, [tableSin + eax*4]
|
||||
mov playerDirY, ebx
|
||||
|
||||
mov eax, ebx
|
||||
imul eax, -66
|
||||
cdq
|
||||
mov ecx, 100
|
||||
idiv ecx
|
||||
mov playerPlaneX, eax
|
||||
|
||||
mov eax, playerDirX
|
||||
imul eax, 66
|
||||
cdq
|
||||
idiv ecx
|
||||
mov playerPlaneY, eax
|
||||
|
||||
cmp hRaycastStartEvent, 0
|
||||
je single_thread_fallback
|
||||
|
||||
; Signal background worker to render columns [320..640)
|
||||
invoke SetEvent, hRaycastStartEvent
|
||||
|
||||
; Main thread processes columns [0..320) in parallel
|
||||
invoke RenderWallsRange, 0, 320
|
||||
|
||||
; Synchronize with worker completion
|
||||
invoke WaitForSingleObject, hRaycastDoneEvent, 0FFFFFFFFh
|
||||
jmp walls_finished
|
||||
|
||||
single_thread_fallback:
|
||||
invoke RenderWallsRange, 0, SCREEN_W
|
||||
|
||||
walls_finished:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
ret
|
||||
RenderWalls ENDP
|
||||
|
||||
; --- Render 3D Billboard Sprites ---
|
||||
|
|
@ -4856,6 +4932,15 @@ Init3DEngine PROC
|
|||
|
||||
call InitializeCasinoSprites3D
|
||||
|
||||
; Initialize raycasting worker thread and sync events
|
||||
invoke CreateEventA, 0, 0, 0, 0
|
||||
mov hRaycastStartEvent, eax
|
||||
invoke CreateEventA, 0, 0, 0, 0
|
||||
mov hRaycastDoneEvent, eax
|
||||
mov bRaycastQuit, 0
|
||||
invoke CreateThread, 0, 65536, OFFSET RaycastWorkerProc, 0, 0, ADDR raycastThreadId
|
||||
mov hRaycastThread, eax
|
||||
|
||||
call InitHall3D
|
||||
call BeginStartup3D
|
||||
call RenderStartup3D
|
||||
|
|
@ -5487,6 +5572,18 @@ engine_idle:
|
|||
invoke Sleep, 50
|
||||
jmp engine_loop
|
||||
engine_shutdown:
|
||||
cmp hRaycastThread, 0
|
||||
je @F
|
||||
mov bRaycastQuit, 1
|
||||
invoke SetEvent, hRaycastStartEvent
|
||||
invoke WaitForSingleObject, hRaycastThread, 1000
|
||||
invoke CloseHandle, hRaycastThread
|
||||
invoke CloseHandle, hRaycastStartEvent
|
||||
invoke CloseHandle, hRaycastDoneEvent
|
||||
mov hRaycastThread, 0
|
||||
mov hRaycastStartEvent, 0
|
||||
mov hRaycastDoneEvent, 0
|
||||
@@:
|
||||
call SaveProgress3D
|
||||
invoke PlayCasinoSound3D, 0, 0, 0
|
||||
call FreeRussianAssets3D
|
||||
|
|
|
|||
BIN
poker.exe
BIN
poker.exe
Binary file not shown.
BIN
poker.obj
BIN
poker.obj
Binary file not shown.
Loading…
Add table
Reference in a new issue