- 注册时间
- 2004-12-28
- 最后登录
- 2019-5-26
⑥精研
- 积分
- 1387
|
发表于 2006-4-26 12:50:19
|
显示全部楼层
毕竟个人作品还是不能跟M$比的么[s:4]
举个极端点的例子,下面这两个程序执行相同效果的运算,所花费的时间比却是1:800左右(ASM的执行100W*1024次,HSP的执行1W*1024次)
- .386
- .model flat,stdcall
- option casemap:none
- include \\masm32\\include\\windows.inc
- include \\masm32\\include\\kernel32.inc
- includelib \\masm32\\lib\\kernel32.lib
- include \\masm32\\include\\user32.inc
- includelib \\masm32\\lib\\user32.lib
- include \\masm32\\include\\winmm.inc
- includelib \\masm32\\lib\\winmm.lib
- .DATA?
- PlayerPositionX DWORD ?
- PlayerPositionY DWORD ?
- PlayerHitBoxW DWORD ?
- PlayerHitBoxH DWORD ?
- Time DWORD ?
- IsHitting db 1024 dup(?)
- MessageBuffer db 64 dup(?)
- .DATA
- EnemyPositionX dd 1024 dup(1)
- EnemyPositionY dd 1024 dup(1)
- EnemyHitBoxW dd 1024 dup(99999)
- EnemyHitBoxH dd 1024 dup(99999)
- EnemyCounter DWORD 1024
- MessageFormat db "Time spent : %u ms"
- .CODE
- start:
- call timeGetTime
- mov Time,eax
- mov PlayerPositionX,12345
- mov PlayerPositionY,67890
- mov PlayerHitBoxW,12345 + 123
- mov PlayerHitBoxH,67890 + 456
- xor ecx,ecx
- @@:
- mov eax,PlayerPositionX
- add eax,ecx
- mov PlayerPositionX,eax
- mov eax,PlayerPositionY
- sub eax,ecx
- mov PlayerPositionY,eax
- call HitCheck
- inc ecx
- cmp ecx,1000000
- jne @b
- call timeGetTime
- sub eax,Time
- push eax
- push OFFSET MessageFormat
- push OFFSET MessageBuffer
- call wsprintf
- add esp,3 * 4
- xor eax,eax
- push eax
- push eax
- push OFFSET MessageBuffer
- call GetForegroundWindow
- push eax
- call MessageBox
- xor eax,eax
- push eax
- call ExitProcess
- HitCheck:
- cmp EnemyCounter,0
- je CheckFinish
- pushad
- xor eax,eax
- mov edi,OFFSET IsHitting
- mov ecx,EnemyCounter
- mov edx,ecx
- and edx,SIZEOF BYTE + SIZEOF WORD
- shr ecx,2
- cld
- rep stosd
- or ecx,edx
- jne MemoryMisalignment
- jmp @f
- MemoryMisalignment:
- rep stosb
- @@:
- mov ebx,OFFSET EnemyPositionX
- mov edx,OFFSET EnemyPositionY
- mov esi,OFFSET EnemyHitBoxW
- mov edi,OFFSET EnemyHitBoxH
- xor ecx,ecx
- CheckLoop:
- mov eax,[edi + ecx * 4]
- cmp PlayerPositionY,eax
- ja CheckEnd
- mov eax,[esi + ecx * 4]
- cmp PlayerPositionX,eax
- ja CheckEnd
- mov eax,[edx + ecx * 4]
- cmp PlayerHitBoxH,eax
- jb CheckEnd
- mov eax,[ebx + ecx * 4]
- cmp PlayerHitBoxW,eax
- jb CheckEnd
- mov BYTE PTR[ecx + OFFSET IsHitting],1
-
- CheckEnd:
- inc ecx
- cmp ecx,EnemyCounter
- jne CheckLoop
- popad
- CheckFinish:
- retn
- end start
复制代码- #include "llmod.as"
- dim prm,1
- dim hDLL,1
- dim TIME,1
- dim ENEMY_COUNTER,1
- dim PLAYER_POSITION_X,1
- dim PLAYER_POSITION_Y,1
- dim PLAYER_HITBOX_W,1
- dim PLAYER_HITBOX_H,1
- dim ENEMY_POSITION_X,1024
- dim ENEMY_POSITION_Y,1024
- dim ENEMY_HITBOX_W,1024
- dim ENEMY_HITBOX_H,1024
- dim IS_HITTING,1024
- ENEMY_COUNTER = 1024
- PLAYER_POSITION_X = 12345
- PLAYER_POSITION_Y = 67890
- PLAYER_HITBOX_W = 12345 + 123
- PLAYER_HITBOX_H = 67890 + 456
- repeat ENEMY_COUNTER
- ENEMY_POSITION_X = 1
- ENEMY_POSITION_Y = 1
- ENEMY_HITBOX_W = 99999
- ENEMY_HITBOX_H = 99999
- loop
- ll_libload hDLL,"winmm.dll"
- dllproc "timeGetTime",prm,0,hDLL
- TIME = dllret
- repeat 10000
- PLAYER_POSITION_X += cnt
- PLAYER_POSITION_Y -= cnt
- gosub HitCheck
- loop
- dllproc "timeGetTime",prm,0,hDLL
- TIME = dllret - TIME
- dialog "Time spent : " + TIME + " ms"
- end
- *HitCheck
- if ENEMY_COUNTER = 0 : return
- repeat ENEMY_COUNTER
- IS_HITTING.cnt = 0
- if (ENEMY_HITBOX_H.cnt < PLAYER_POSITION_Y) | (ENEMY_HITBOX_W.cnt < PLAYER_POSITION_X) | (ENEMY_POSITION_Y.cnt > PLAYER_HITBOX_H) | (ENEMY_POSITION_X.cnt > PLAYER_HITBOX_W) {
- continue
- }
- IS_HITTING.cnt = 1
- loop
- return
复制代码 |
|