Hey, I wrote a pixel perfect collision routine optimized for 32 bit using MMX back at the FB forums but nobody noticed : /. It goes through two pixels at a time so it should be at least a little faster than the one presented in this topic.
Function PPCollision(img1 As zpIMAGE, ax1 As Integer, ay1 As Integer ,_
img2 As zpIMAGE, bx1 As Integer, by1 As Integer , tcol As Integer) As Integer
Dim As Integer ax2, ay2, bx2, by2
Dim As Integer x1 , y1 , x2 , y2
Dim As Integer ix1, iy1, ix2, iy2, sx, sy, WX1, WX2, C
Dim As Uinteger Ptr sp1, sp2
WX1 = zpGET_WIDTH(img1)
WX2 = zpGET_WIDTH(img2)
ax2 = ax1 + WX1
ay2 = ay1 + zpGET_HEIGHT(img1)
bx2 = bx1 + WX2
by2 = by1 + zpGET_HEIGHT(img2)
If ax2 <= bx1 Then Return 0
If bx2 <= ax1 Then Return 0
If ay2 <= by1 Then Return 0
If by2 <= ay1 Then Return 0
If ax1 < bx1 Then
x1 = bx1
If bx2 < ax2 Then
x2 = bx2
Else
x2 = ax2
Endif
sx = x2 - x1
ix1 = WX1 - sx
ix2 = 0
Else
x1 = ax1
If ax2 < bx2 Then
x2 = ax2
Else
x2 = bx2
Endif
sx = x2 - x1
ix2 = WX2 - sx
ix1 = 0
Endif
If ay1 < by1 Then
y1 = by1
If by2 < ay2 Then
y2 = by2
Else
y2 = ay2
Endif
sy = y2 - y1
iy1 = zpGET_HEIGHT(img1) - sy
iy2 = 0
Else
y1 = ay1
If ay2 < by2 Then
y2 = ay2
Else
y2 = by2
Endif
sy = y2 - y1
iy2 = zpGET_HEIGHT(img2) - sy
iy1 = 0
Endif
sp1 = @img1[(iy1*WX1+ix1)]
sp2 = @img2[(iy2*WX2+ix2)]
WX1 Shl= 2: WX2 Shl= 2
C = 0
Asm
mov eax, [sp1]
mov ebx, [sp2]
add eax, zpIMAGE_HEADER
add ebx, zpIMAGE_HEADER
mov ecx, [tcol]
movd mm2, ecx
mov ecx, [sx]
mov esi, ecx
Shl esi, 2
Sub [WX1], esi
Sub [WX2], esi
mov esi, ecx
mov edx, [sy]
Y_Loop:
X_Loop:
movd mm0, [eax]
movd mm1, [ebx]
pcmpeqw mm0, mm2
pcmpeqw mm1, mm2
por mm0, mm1
movd edi, mm0
Or edi, edi
jnz SkipIt
mov eax, 1
mov [C], eax
jmp EarlyOut
SkipIt:
add eax, 4
add ebx, 4
dec ecx
jnz X_Loop
mov ecx, esi
add eax, [WX1]
add ebx, [WX2]
dec edx
jnz Y_Loop
EarlyOut:
emms
End Asm
Return C
End Function