feat(input): add context-aware mouse look with automatic cursor locking

This commit is contained in:
Игорь Федосеев 2026-10-14 00:14:34 +03:00
parent 4c89864afb
commit 342eb16e04
4 changed files with 95 additions and 0 deletions

Binary file not shown.

View file

@ -41,6 +41,10 @@ WaitForSingleObject PROTO :DWORD,:DWORD
timeBeginPeriod PROTO :DWORD timeBeginPeriod PROTO :DWORD
timeEndPeriod PROTO :DWORD timeEndPeriod PROTO :DWORD
timeGetTime PROTO timeGetTime PROTO
GetCursorPos PROTO :DWORD
SetCursorPos PROTO :DWORD,:DWORD
ShowCursor PROTO :DWORD
ClientToScreen PROTO :DWORD,:DWORD
C3D_POINT STRUCT C3D_POINT STRUCT
x dd ? x dd ?
@ -178,6 +182,9 @@ hRaycastDoneEvent dd 0
bRaycastQuit dd 0 bRaycastQuit dd 0
raycastThreadId dd 0 raycastThreadId dd 0
ALIGN 4
mouseLocked3D dd 0
bmi3D C3D_BITMAPINFO <> bmi3D C3D_BITMAPINFO <>
msg3D C3D_MSG <> msg3D C3D_MSG <>
wc3D C3D_WNDCLASSEX <> wc3D C3D_WNDCLASSEX <>
@ -4389,10 +4396,95 @@ skill_render_keys:
ret ret
RenderSkillGame ENDP RenderSkillGame ENDP
; --- Mouse Lock & Unlock Routines for Free Camera Look ---
LockMouse3D PROC
LOCAL rcClient[16]:BYTE
LOCAL ptCenter:C3D_POINT
cmp mouseLocked3D, 1
je lock_done
mov mouseLocked3D, 1
invoke ShowCursor, 0
lea eax, rcClient
invoke GetClientRect, h3DWnd, eax
mov eax, dword ptr rcClient[8]
shr eax, 1
mov ptCenter.x, eax
mov eax, dword ptr rcClient[12]
shr eax, 1
mov ptCenter.y, eax
lea eax, ptCenter
invoke ClientToScreen, h3DWnd, eax
invoke SetCursorPos, ptCenter.x, ptCenter.y
lock_done:
ret
LockMouse3D ENDP
UnlockMouse3D PROC
cmp mouseLocked3D, 0
je unlock_done
mov mouseLocked3D, 0
invoke ShowCursor, 1
unlock_done:
ret
UnlockMouse3D ENDP
UpdateMouseLockState PROC
cmp engineMode, MODE_WALK
jne unlock_it
cmp paused3D, 0
jne unlock_it
invoke GetForegroundWindow
cmp eax, h3DWnd
jne unlock_it
invoke IsIconic, h3DWnd
test eax, eax
jnz unlock_it
call LockMouse3D
ret
unlock_it:
call UnlockMouse3D
ret
UpdateMouseLockState ENDP
HandlePlayerInput PROC uses ebx esi edi HandlePlayerInput PROC uses ebx esi edi
local speed:DWORD local speed:DWORD
local nextX:DWORD local nextX:DWORD
local nextY:DWORD local nextY:DWORD
local rcClient[16]:BYTE
local ptCenter:C3D_POINT
local ptCursor:C3D_POINT
; --- Mouse Look Camera Rotation ---
cmp mouseLocked3D, 1
jne skip_mouse_look
lea eax, rcClient
invoke GetClientRect, h3DWnd, eax
mov eax, dword ptr rcClient[8]
shr eax, 1
mov ptCenter.x, eax
mov eax, dword ptr rcClient[12]
shr eax, 1
mov ptCenter.y, eax
lea eax, ptCenter
invoke ClientToScreen, h3DWnd, eax
lea eax, ptCursor
invoke GetCursorPos, eax
mov eax, ptCursor.x
sub eax, ptCenter.x
test eax, eax
jz mouse_recenter
cmp eax, 64
jle @F
mov eax, 64
@@:
cmp eax, -64
jge @F
mov eax, -64
@@:
add playerAngle, eax
mouse_recenter:
invoke SetCursorPos, ptCenter.x, ptCenter.y
skip_mouse_look:
mov eax, deltaTime3D mov eax, deltaTime3D
imul eax, 200 imul eax, 200
mov speed, eax mov speed, eax
@ -5080,6 +5172,7 @@ leave_idle_table:
call ClearKeys3D call ClearKeys3D
invoke PlayCasinoSound3D, 0, 0, 0 invoke PlayCasinoSound3D, 0, 0, 0
engine_tick: engine_tick:
call UpdateMouseLockState
cmp paused3D, 0 cmp paused3D, 0
jne draw_pause jne draw_pause
mov eax, deltaTime3D mov eax, deltaTime3D
@ -5342,9 +5435,11 @@ present_frame:
invoke Sleep, ecx invoke Sleep, ecx
jmp engine_loop jmp engine_loop
engine_idle: engine_idle:
call UnlockMouse3D
invoke Sleep, 50 invoke Sleep, 50
jmp engine_loop jmp engine_loop
engine_shutdown: engine_shutdown:
call UnlockMouse3D
cmp hRaycastThread, 0 cmp hRaycastThread, 0
je @F je @F
mov bRaycastQuit, 1 mov bRaycastQuit, 1

BIN
poker.exe

Binary file not shown.

BIN
poker.obj

Binary file not shown.