feat: major engine overhaul - scene demo with lighting, sphere, ground

- Scene Demo: cube + sphere + ground plane with proper lighting
- Audio: XAudio2 dynamic loading + WAV playback
- Physics: expanded collision system
- Renderer: improved pipeline with materials
- UI: extended widget system
- VisualScript: enhanced serializer + block interactions
- ASM: optimized math/memory/profiling routines
- Window: mouse input + scroll support
This commit is contained in:
shuiyu1123 committed 2026-07-12 08:21:07 +08:00
1 parent 2653926d85
commit 0669d102ce
35 files changed
+1844 -314

No files matched your search

+25 -49
View File
@@ -28,14 +28,12 @@ prof_rdtsc PROC
prof_rdtsc ENDP
; uint64_t prof_get_freq(void) -> RAX
; 获取 CPU 频率 (通过 OS 或推断)
; 获取 CPU 频率 (Hz), 使用 QPC 校准 TSC
prof_get_freq PROC
; 检查是否已初始化
cmp byte ptr [cpu_freq_init], 0
jnz prof_freq_return
; 初始化 CPU 频率
; 方法: 使用 QueryPerformanceCounter 测量 RDTSC
push rbx
push rdi
push rsi
@@ -46,7 +44,7 @@ prof_get_freq PROC
call QueryPerformanceFrequency
; 获取起始 QPC 和 TSC
lea rcx, [rsp + 16]
lea rcx, [rsp + 24]
call QueryPerformanceCounter
rdtscp
shl rdx, 32
@@ -54,37 +52,31 @@ prof_get_freq PROC
mov rbx, rax ; rbx = 起始 TSC
; 等待约 10ms
mov rcx, 10000 ; 10,000 微秒
mov rcx, 10 ; 10 毫秒
call Sleep
; 获取结束 QPC 和 TSC
lea rcx, [rsp]
lea rcx, [rsp + 16]
call QueryPerformanceCounter
rdtscp
shl rdx, 32
or rax, rdx
mov rdi, rax ; rdi = 结束 TSC
; 计算经过的 QPC ticks
mov rax, [rsp]
sub rax, [rsp + 16] ; qpc_diff
; qpc_diff = end_qpc - start_qpc
mov rax, [rsp + 16]
sub rax, [rsp + 24]
mov rsi, rax ; rsi = qpc_diff
; 计算 QPC 频率 (ticks/sec)
mov rsi, [rsp + 32]
; tsc_diff = end_tsc - start_tsc
mov rcx, rdi
sub rcx, rbx ; rcx = tsc_diff
; TSC diff
mov rax, rdi
sub rax, rbx ; tsc_diff
; CPU freq = tsc_diff * qpc_freq / qpc_diff
; 但 qpc_diff 对应 10ms, 所以要 * 100
mov rdx, rsi
mul rdx ; tsc_diff * qpc_freq
; rdx:rax = result
div qword ptr [rsp + 16] ; / qpc_diff
; rax = freq * 100 (因为等待了 10ms)
mov rcx, 100
mul rcx
; cpu_freq = tsc_diff * qpc_freq / qpc_diff
mov rax, rcx ; rax = tsc_diff
mov rdx, [rsp + 32] ; rdx = qpc_freq
mul rdx ; rdx:rax = tsc_diff * qpc_freq
div rsi ; rax = freq (Hz)
mov [cpu_freq], rax
mov byte ptr [cpu_freq_init], 1
@@ -100,33 +92,17 @@ prof_freq_return:
prof_get_freq ENDP
; double prof_cycles_to_ms(uint64_t cycles) -> XMM0
; 将 TSC cycles 转换为毫秒
; 将 TSC cycles 转换为毫秒: ms = cycles * 1000 / freq
prof_cycles_to_ms PROC
; 先获取频率
call prof_get_freq
; rax = CPU freq (Hz)
mov rdx, rcx ; 保存 cycles
call prof_get_freq ; rax = CPU freq (Hz)
; ms = cycles / (freq / 1000)
; 或: ms = cycles * 1000 / freq
mov rdx, 1000
mul rdx ; freq * 1000
; rdx:rax = freq * 1000
; 转换为 double
cvtsi2sd xmm0, qword ptr [rsp - 8] ; 需要栈存储
; 简化: 使用整数除法再转 double
mov rcx, rax
mov rax, [cpu_freq]
; 重新计算
mov rax, rcx
; cycles * 1000 / freq
; 已经: rax = freq * 1000, 需要 cycles * 1000 / freq
; 调整: cycles * 1000 / freq = cycles / (freq/1000)
; 简化实现
cvtsi2sd xmm0, rcx ; cycles * 1000 (转 double)
cvtsi2sd xmm1, rax ; freq (转 double)
divsd xmm0, xmm1 ; (cycles*1000) / freq = ms
cvtsi2sd xmm0, rdx ; xmm0 = cycles (double)
mov rcx, 1000
cvtsi2sd xmm1, rcx ; xmm1 = 1000.0
mulsd xmm0, xmm1 ; cycles * 1000
cvtsi2sd xmm1, rax ; xmm1 = freq
divsd xmm0, xmm1 ; ms
ret
prof_cycles_to_ms ENDP