/* bgfx.cpp - Don Yang (uguu.org) Branches could be unrolled further, for more performance and three times as much code. Presumably, those who enabled background particles have processor cycles to spare anyway, so performance should not be much of an issue here, so I saved the trouble of writing those extra codes. 12/21/00 */ #include"global.h" #include"bgfx.h" static int ParticleX[MAX_PARTICLE_COUNT]; static int ParticleY[MAX_PARTICLE_COUNT]; static ParticleParam Param[MAX_PARTICLE_PARAM]; static DWORD ParticlePos[MAX_PARTICLE_COUNT]; static DWORD ParticleCount = 0; static int FRuleCount = 0; static int DVectorX0 = 1; static int DVectorX1 = 1; static int DVectorY0 = 0; static int DVectorY1 = 0; static int DFrame = 0; static int ParticleVX[SWARM_PARTICLE_COUNT]; static int ParticleVY[SWARM_PARTICLE_COUNT]; static void ClipParticles(DWORD bpp); static void ClipParticlesA(DWORD bpp, int x, int y, int w, int h); static void ClipParticlesP(DWORD bpp, int c, int r); /*************************************************************** AnimateDust animate parameters and compute dust particle positions. */ void AnimateDust(void) { int i, vx, vy, *px, *py; if( DFrame > DUST_VECTOR_TIME ) { vx = DVectorX1; vy = DVectorY1; if( DFrame > DUST_VECTOR_TIME * 4 ) { DFrame = 0; DVectorX0 = DVectorX1; DVectorY0 = DVectorY1; do { DVectorX1 = rand() % 31 - 15; DVectorY1 = rand() % 31 - 15; } while( DVectorX1 == 0 && DVectorY1 == 0 ); } } else { vx = DVectorX0 + ((DVectorX1 - DVectorX0) * DFrame) / DUST_VECTOR_TIME; vy = DVectorY0 + ((DVectorY1 - DVectorY0) * DFrame) / DUST_VECTOR_TIME; } DFrame++; px = &ParticleX[0]; py = &ParticleY[0]; for(i = 0; i < DUST_PARTICLE_COUNT / 2; i++) { *px += vx; *py += vy; if( *px < 0 ) *px += APP_WIDTH; if( *py < 0 ) *py += APP_HEIGHT; if( *px >= APP_WIDTH ) *px -= APP_WIDTH; if( *py >= APP_HEIGHT ) *py -= APP_HEIGHT; px++; py++; } vx >>= 1; vy >>= 1; for(; i < DUST_PARTICLE_COUNT; i++) { *px += vx; *py += vy; if( *px < 0 ) *px += APP_WIDTH; if( *py < 0 ) *py += APP_HEIGHT; if( *px >= APP_WIDTH ) *px -= APP_WIDTH; if( *py >= APP_HEIGHT ) *py -= APP_HEIGHT; px++; py++; } RedrawAll = TRUE; } // AnimateDust() /************************************************************ AnimateFractal Animate parameters and compute fractal particle positions. */ void AnimateFractal(void) { static int a[FRACTAL_MAX_RULES]; static int b[FRACTAL_MAX_RULES]; static int c[FRACTAL_MAX_RULES]; static int d[FRACTAL_MAX_RULES]; static int e[FRACTAL_MAX_RULES]; static int f[FRACTAL_MAX_RULES]; int i, j, r, ix, sx, sy, *x, *y; // Initialize rules for(i = 0; i < FRuleCount; i++) { Param[i].x1 += Param[i].dx1; Param[i].y1 += Param[i].dy1; Param[i].x2 += Param[i].dx2; Param[i].y2 += Param[i].dy2; Param[i].x3 += Param[i].dx3; Param[i].y3 += Param[i].dy3; if( Param[i].x1 < 0 ) { Param[i].x1 = 0; Param[i].dx1 = (rand() & 15) + 1; } if( Param[i].x1 > 0x7ff ) { Param[i].x1 = 0x7ff; Param[i].dx1 = -((rand() & 15) + 1); } if( Param[i].x2 < 0 ) { Param[i].x2 = 0; Param[i].dx2 = (rand() & 15) + 1; } if( Param[i].x2 > 0x7ff ) { Param[i].x2 = 0x7ff; Param[i].dx2 = -((rand() & 15) + 1); } if( Param[i].x3 < 0 ) { Param[i].x3 = 0; Param[i].dx3 = (rand() & 15 + 1); } if( Param[i].x3 > 0x7ff ) { Param[i].x3 = 0x7ff; Param[i].dx3 = -((rand() & 15) + 1); } if( Param[i].y1 < 0 ) { Param[i].y1 = 0; Param[i].dy1 = (rand() & 15) + 1; } if( Param[i].y1 > 0x7ff ) { Param[i].y1 = 0x7ff; Param[i].dy1 = -((rand() & 15) + 1); } if( Param[i].y2 < 0 ) { Param[i].y2 = 0; Param[i].dy2 = (rand() & 15) + 1; } if( Param[i].y2 > 0x7ff ) { Param[i].y2 = 0x7ff; Param[i].dy2 = -((rand() & 15) + 1); } if( Param[i].y3 < 0 ) { Param[i].y3 = 0; Param[i].dy3 = (rand() & 15) + 1; } if( Param[i].y3 > 0x7ff ) { Param[i].y3 = 0x7ff; Param[i].dy3 = -((rand() & 15) + 1); } e[i] = Param[i].x1; f[i] = Param[i].y1; a[i] = Param[i].x2 - e[i]; b[i] = Param[i].x3 - e[i]; c[i] = Param[i].y2 - f[i]; d[i] = Param[i].y3 - f[i]; } // Trace dots x = &ParticleX[0]; y = &ParticleY[0]; for(i = 0; i < FRACTAL_DOT_COUNT; i++) { sx = rand() & 0x7ff; sy = rand() & 0x7ff; for(j = 0; j < FRACTAL_INIT_ITER; j++) { r = rand() % FRuleCount; ix = ((a[r] * sx + b[r] * sy) >> 11) + e[r]; sy = ((c[r] * sx + d[r] * sy) >> 11) + f[r]; sx = ix; } for(j = 0; j < FRACTAL_ITER_COUNT; j++) { r = rand() % FRuleCount; ix = ((a[r] * sx + b[r] * sy) >> 11) + e[r]; sy = ((c[r] * sx + d[r] * sy) >> 11) + f[r]; sx = ix; *(x++) = (sx * APP_WIDTH) >> 11; *(y++) = (sy * APP_HEIGHT) >> 11; } } RedrawAll = TRUE; } // AnimateFractal() /************************************************************** AnimateSwarm Animate swarm, a la xlockmore swarm mode. */ void AnimateSwarm(void) { int i, d, dx, dy, x, y, *x0, *y0, *x1, *y1; // Select buffers x0 = &ParticleX[(DFrame & 3) * SWARM_PARTICLE_COUNT]; y0 = &ParticleY[(DFrame & 3) * SWARM_PARTICLE_COUNT]; DFrame++; x1 = &ParticleX[(DFrame & 3) * SWARM_PARTICLE_COUNT]; y1 = &ParticleY[(DFrame & 3) * SWARM_PARTICLE_COUNT]; // Animate wasp ParticleVX[0] += rand() % 9 - 4; ParticleVY[0] += rand() % 9 - 4; if( ParticleVX[0] < -SWARM_WASP_VELOCITY ) ParticleVX[0] = -SWARM_WASP_VELOCITY; if( ParticleVX[0] > SWARM_WASP_VELOCITY ) ParticleVX[0] = SWARM_WASP_VELOCITY; if( ParticleVY[0] < -SWARM_WASP_VELOCITY ) ParticleVY[0] = -SWARM_WASP_VELOCITY; if( ParticleVY[0] > SWARM_WASP_VELOCITY ) ParticleVY[0] = SWARM_WASP_VELOCITY; *x1 = *(x0++) + ParticleVX[0]; *y1 = *(y0++) + ParticleVY[0]; if( *x1 < 0 ) *x1 += APP_WIDTH; if( *x1 >= APP_WIDTH ) *x1 -= APP_WIDTH; if( *y1 < 0 ) *y1 += APP_HEIGHT; if( *y1 >= APP_HEIGHT ) *y1 -= APP_HEIGHT; // Animate bees x = *(x1++); y = *(y1++); for(i = 1; i < SWARM_PARTICLE_COUNT; i++) { dx = x - *x0; dy = y - *y0; d = abs(dx) + abs(dy); if( !d ) d++; ParticleVX[i] += dx * 2 / d; ParticleVY[i] += dy * 2 / d; if( ParticleVX[i] < -SWARM_BEE_VELOCITY ) ParticleVX[i] = -SWARM_BEE_VELOCITY; if( ParticleVX[i] > SWARM_BEE_VELOCITY ) ParticleVX[i] = SWARM_BEE_VELOCITY; if( ParticleVY[i] < -SWARM_BEE_VELOCITY ) ParticleVY[i] = -SWARM_BEE_VELOCITY; if( ParticleVY[i] > SWARM_BEE_VELOCITY ) ParticleVY[i] = SWARM_BEE_VELOCITY; *(x1++) = *(x0++) + ParticleVX[i]; *(y1++) = *(y0++) + ParticleVY[i]; } RedrawAll = TRUE; } // AnimateSwarm() /****************************************************************** InitDust Initialize dust particles. */ void InitDust(void) { int i; DFrame = 0; DVectorX0 = (rand() & 15) + 1; if( rand() & 1 ) DVectorX0 = -DVectorX0; DVectorX1 = (rand() & 15) + 1; if( rand() & 1 ) DVectorX1 = -DVectorX1; DVectorY0 = (rand() & 15) + 1; if( rand() & 1 ) DVectorY0 = -DVectorY0; DVectorY1 = (rand() & 15) + 1; if( rand() & 1 ) DVectorY1 = -DVectorY1; for(i = 0; i < DUST_PARTICLE_COUNT; i++) { ParticleX[i] = rand() % APP_WIDTH; ParticleY[i] = rand() % APP_HEIGHT; } for(; i < MAX_PARTICLE_COUNT; i++) ParticleX[i] = ParticleY[i] = -1; } // InitDust() /*************************************************************** InitFractal Initialize fractal particles. */ void InitFractal(void) { int i; FRuleCount = (rand() % (FRACTAL_MAX_RULES - FRACTAL_MIN_RULES)) + FRACTAL_MIN_RULES; for(i = 0; i < FRuleCount; i++) { Param[i].x1 = rand() & 0x7ff; Param[i].x2 = rand() & 0x7ff; Param[i].x3 = rand() & 0x7ff; Param[i].y1 = rand() & 0x7ff; Param[i].y2 = rand() & 0x7ff; Param[i].y3 = rand() & 0x7ff; Param[i].dx1 = (rand() & (0xf)) + 1; Param[i].dx2 = (rand() & (0xf)) + 1; Param[i].dx3 = (rand() & (0xf)) + 1; Param[i].dy1 = (rand() & (0xf)) + 1; Param[i].dy2 = (rand() & (0xf)) + 1; Param[i].dy3 = (rand() & (0xf)) + 1; if( rand() & 1 ) Param[i].dx1 = -Param[i].dx1; if( rand() & 1 ) Param[i].dx2 = -Param[i].dx2; if( rand() & 1 ) Param[i].dx3 = -Param[i].dx3; if( rand() & 1 ) Param[i].dy1 = -Param[i].dy1; if( rand() & 1 ) Param[i].dy2 = -Param[i].dy2; if( rand() & 1 ) Param[i].dy3 = -Param[i].dy3; } AnimateFractal(); } // InitFractal() /***************************************************************** InitSwarm Initialize swarm particles. */ void InitSwarm(void) { int i; do { ParticleVX[0] = (rand() % 11) - 5; ParticleVY[0] = (rand() % 11) - 5; } while( ParticleVX[0] == 0 && ParticleVY[0] == 0 ); for(DFrame = i = 0; i < SWARM_PARTICLE_COUNT; i++) { ParticleX[i] = rand() % APP_WIDTH; ParticleY[i] = rand() % APP_HEIGHT; ParticleVX[i] = ParticleVY[i] = 0; } for(; i < SWARM_PARTICLE_COUNT * 4; i++) { ParticleX[i] = ParticleX[i - SWARM_PARTICLE_COUNT]; ParticleY[i] = ParticleY[i - SWARM_PARTICLE_COUNT]; } for(; i < MAX_PARTICLE_COUNT; i++) ParticleX[i] = ParticleY[i] = -1; } // InitSwarm() /********************************************************** RenderParticle16 Render particle effects. */ void RenderParticle16(DWORD screen) { DWORD *p; ClipParticles(2); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle16_end mov esi, p mov edi, screen xor eax, eax RenderParticle16_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop RenderParticle16_loop RenderParticle16_end: } } // RenderParticle16() /********************************************************* RenderParticle16a Render particle effects (at screen coordinates). */ void RenderParticle16a(DWORD screen, int x, int y, int w, int h) { DWORD *p; ClipParticlesA(2, x, y, w, h); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle16a_end mov esi, p mov edi, screen xor eax, eax RenderParticle16a_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop RenderParticle16a_loop RenderParticle16a_end: } } // RenderParticle16a() /********************************************************* RenderParticle16p Render particle effects (at grid coordinates). */ void RenderParticle16p(DWORD screen, int c, int r) { DWORD *p; ClipParticlesP(2, c, r); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle16p_end mov esi, p mov edi, screen xor eax, eax RenderParticle16p_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop RenderParticle16p_loop RenderParticle16p_end: } } // RenderParticle16p() /********************************************************** RenderParticle24 Render particle effects. */ void RenderParticle24(DWORD screen) { DWORD *p; ClipParticles(3); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle24_end mov esi, p mov edi, screen xor eax, eax RenderParticle24_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax mov byte ptr [edi+ebx+2], al loop RenderParticle24_loop RenderParticle24_end: } } // RenderParticle24() /********************************************************* RenderParticle24a Render particle effects (at screen coordinates). */ void RenderParticle24a(DWORD screen, int x, int y, int w, int h) { DWORD *p; ClipParticlesA(3, x, y, w, h); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle24a_end mov esi, p mov edi, screen xor eax, eax RenderParticle24a_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax mov byte ptr [edi+ebx+2], al loop RenderParticle24a_loop RenderParticle24a_end: } } // RenderParticle24a() /********************************************************* RenderParticle24p Render particle effects (at grid coordinates). */ void RenderParticle24p(DWORD screen, int c, int r) { DWORD *p; ClipParticlesP(3, c, r); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle24p_end mov esi, p mov edi, screen xor eax, eax RenderParticle24p_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax mov byte ptr [edi+ebx+2], al loop RenderParticle24p_loop RenderParticle24p_end: } } // RenderParticle24p() /********************************************************** RenderParticle32 Render particle effects. */ void RenderParticle32(DWORD screen) { DWORD *p; ClipParticles(4); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle32_end mov esi, p mov edi, screen xor eax, eax RenderParticle32_loop: mov ebx, [esi] add esi, 4 mov dword ptr [edi+ebx], eax loop RenderParticle32_loop RenderParticle32_end: } } // RenderParticle32() /********************************************************* RenderParticle32a Render particle effects (at screen coordinates). */ void RenderParticle32a(DWORD screen, int x, int y, int w, int h) { DWORD *p; ClipParticlesA(4, x, y, w, h); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle32a_end mov esi, p mov edi, screen xor eax, eax RenderParticle32a_loop: mov ebx, [esi] add esi, 4 mov dword ptr [edi+ebx], eax loop RenderParticle32a_loop RenderParticle32a_end: } } // RenderParticle32a() /********************************************************* RenderParticle32p Render particle effects (at grid coordinates). */ void RenderParticle32p(DWORD screen, int c, int r) { DWORD *p; ClipParticlesP(4, c, r); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz RenderParticle32p_end mov esi, p mov edi, screen xor eax, eax RenderParticle32p_loop: mov ebx, [esi] add esi, 4 mov dword ptr [edi+ebx], eax loop RenderParticle32p_loop RenderParticle32p_end: } } // RenderParticle32p() /********************************************************* WRenderParticle15 Render particle effects. */ void WRenderParticle15(DWORD screen) { DWORD *p; ClipParticles(2); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle15_end mov esi, p mov edi, screen mov eax, 7fffh WRenderParticle15_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop WRenderParticle15_loop WRenderParticle15_end: } } // WRenderParticle15() /******************************************************** WRenderParticle15a Render particle effects (at screen coordinates). */ void WRenderParticle15a(DWORD screen, int x, int y, int w, int h) { DWORD *p; ClipParticlesA(2, x, y, w, h); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle15a_end mov esi, p mov edi, screen mov eax, 7fffh WRenderParticle15a_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop WRenderParticle15a_loop WRenderParticle15a_end: } } // WRenderParticle15a() /******************************************************** WRenderParticle15p Render particle effects (at grid coordinates). */ void WRenderParticle15p(DWORD screen, int c, int r) { DWORD *p; ClipParticlesP(2, c, r); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle15p_end mov esi, p mov edi, screen mov eax, 7fffh WRenderParticle15p_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop WRenderParticle15p_loop WRenderParticle15p_end: } } // WRenderParticle15p() /********************************************************* WRenderParticle16 Render particle effects. */ void WRenderParticle16(DWORD screen) { DWORD *p; ClipParticles(2); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle16_end mov esi, p mov edi, screen mov eax, 0ffffh WRenderParticle16_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop WRenderParticle16_loop WRenderParticle16_end: } } // WRenderParticle16() /******************************************************** WRenderParticle16a Render particle effects (at screen coordinates). */ void WRenderParticle16a(DWORD screen, int x, int y, int w, int h) { DWORD *p; ClipParticlesA(2, x, y, w, h); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle16a_end mov esi, p mov edi, screen mov eax, 0ffffh WRenderParticle16a_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop WRenderParticle16a_loop WRenderParticle16a_end: } } // WRenderParticle16a() /******************************************************** WRenderParticle16p Render particle effects (at grid coordinates). */ void WRenderParticle16p(DWORD screen, int c, int r) { DWORD *p; ClipParticlesP(2, c, r); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle16p_end mov esi, p mov edi, screen mov eax, 0ffffh WRenderParticle16p_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax loop WRenderParticle16p_loop WRenderParticle16p_end: } } // WRenderParticle16p() /********************************************************* WRenderParticle24 Render particle effects. */ void WRenderParticle24(DWORD screen) { DWORD *p; ClipParticles(3); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle24_end mov esi, p mov edi, screen mov eax, 00ffffffh WRenderParticle24_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax mov byte ptr [edi+ebx+2], al loop WRenderParticle24_loop WRenderParticle24_end: } } // WRenderParticle24() /******************************************************** WRenderParticle24a Render particle effects (at screen coordinates). */ void WRenderParticle24a(DWORD screen, int x, int y, int w, int h) { DWORD *p; ClipParticlesA(3, x, y, w, h); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle24a_end mov esi, p mov edi, screen mov eax, 00ffffffh WRenderParticle24a_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax mov byte ptr [edi+ebx+2], al loop WRenderParticle24a_loop WRenderParticle24a_end: } } // WRenderParticle24a() /******************************************************** WRenderParticle24p Render particle effects (at grid coordinates). */ void WRenderParticle24p(DWORD screen, int c, int r) { DWORD *p; ClipParticlesP(3, c, r); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle24p_end mov esi, p mov edi, screen mov eax, 00ffffffh WRenderParticle24p_loop: mov ebx, [esi] add esi, 4 mov word ptr [edi+ebx], ax mov byte ptr [edi+ebx+2], al loop WRenderParticle24p_loop WRenderParticle24p_end: } } // WRenderParticle24p() /********************************************************* WRenderParticle32 Render particle effects. */ void WRenderParticle32(DWORD screen) { DWORD *p; ClipParticles(4); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle32_end mov esi, p mov edi, screen mov eax, 00ffffffh WRenderParticle32_loop: mov ebx, [esi] add esi, 4 mov dword ptr [edi+ebx], eax loop WRenderParticle32_loop WRenderParticle32_end: } } // WRenderParticle32() /******************************************************** WRenderParticle32a Render particle effects (at screen coordinates). */ void WRenderParticle32a(DWORD screen, int x, int y, int w, int h) { DWORD *p; ClipParticlesA(4, x, y, w, h); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle32a_end mov esi, p mov edi, screen mov eax, 00ffffffh WRenderParticle32a_loop: mov ebx, [esi] add esi, 4 mov dword ptr [edi+ebx], eax loop WRenderParticle32a_loop WRenderParticle32a_end: } } // WRenderParticle32a() /******************************************************** WRenderParticle32p Render particle effects (at grid coordinates). */ void WRenderParticle32p(DWORD screen, int c, int r) { DWORD *p; ClipParticlesP(4, c, r); p = (DWORD*)&ParticlePos[0]; __asm { mov ecx, ParticleCount or ecx, ecx jz WRenderParticle32p_end mov esi, p mov edi, screen mov eax, 00ffffffh WRenderParticle32p_loop: mov ebx, [esi] add esi, 4 mov dword ptr [edi+ebx], eax loop WRenderParticle32p_loop WRenderParticle32p_end: } } // WRenderParticle32p() /************************************************************* ClipParticles Convert particle coordinates to screen offsets. */ static void ClipParticles(DWORD bpp) { DWORD *x, *y, *p; x = (DWORD*)&ParticleX[0]; y = (DWORD*)&ParticleY[0]; p = (DWORD*)&ParticlePos[0]; __asm { pushf cld xor eax, eax mov ParticleCount, eax mov edi, x mov esi, y mov ebx, p mov ecx, MAX_PARTICLE_COUNT ClipParticles_loop: ; Clip Y lodsd cmp eax, 0 jl ClipParticles_reject cmp eax, APP_HEIGHT jge ClipParticles_reject mov edx, DDPitch mul edx mov [ebx], eax ; Clip X mov eax, [edi] cmp eax, 0 jl ClipParticles_reject cmp eax, APP_WIDTH jge ClipParticles_reject mov edx, bpp mul edx add [ebx], eax add ebx, 4 add edi, 4 inc dword ptr [ParticleCount] loop ClipParticles_loop jmp ClipParticles_end ClipParticles_reject: add edi, 4 loop ClipParticles_loop ClipParticles_end: popf } } // ClipParticles() /************************************************************ ClipParticlesA Convert particle coordinates to screen offsets. */ static void ClipParticlesA(DWORD bpp, int x, int y, int w, int h) { DWORD *sx, *sy, *p; DWORD x0, y0; sx = (DWORD*)&ParticleX[0]; sy = (DWORD*)&ParticleY[0]; p = (DWORD*)&ParticlePos[0]; __asm { pushf cld xor eax, eax mov ParticleCount, eax mov eax, x add eax, w mov x0, eax mov eax, y add eax, h mov y0, eax mov edi, sx mov esi, sy mov ebx, p mov ecx, MAX_PARTICLE_COUNT ClipParticlesA_loop: ; Clip Y lodsd cmp eax, y jl ClipParticlesA_reject cmp eax, y0 jge ClipParticlesA_reject mov edx, DDPitch mul edx mov [ebx], eax ; Clip X mov eax, [edi] cmp eax, x jl ClipParticlesA_reject cmp eax, x0 jge ClipParticlesA_reject mov edx, bpp mul edx add [ebx], eax add ebx, 4 add edi, 4 inc dword ptr [ParticleCount] loop ClipParticlesA_loop jmp ClipParticlesA_end ClipParticlesA_reject: add edi, 4 loop ClipParticlesA_loop ClipParticlesA_end: popf } } // ClipParticlesA() /************************************************************ ClipParticlesP Convert particle coordinates to screen offsets. */ static void ClipParticlesP(DWORD bpp, int c, int r) { DWORD *sx, *sy, *p; DWORD x, y, x0, y0; sx = (DWORD*)&ParticleX[0]; sy = (DWORD*)&ParticleY[0]; p = (DWORD*)&ParticlePos[0]; __asm { pushf cld xor eax, eax mov ParticleCount, eax mov eax, c mov ebx, CELL_SIZE mul ebx add eax, GRID_MARGIN mov x, eax add eax, CELL_SIZE mov x0, eax mov eax, r mul ebx sub eax, APP_HEIGHT - GRID_MARGIN - CELL_SIZE neg eax mov y, eax add eax, CELL_SIZE mov y0, eax mov edi, sx mov esi, sy mov ebx, p mov ecx, MAX_PARTICLE_COUNT ClipParticlesP_loop: ; Clip Y lodsd cmp eax, y jl ClipParticlesP_reject cmp eax, y0 jge ClipParticlesP_reject mov edx, DDPitch mul edx mov [ebx], eax ; Clip X mov eax, [edi] cmp eax, x jl ClipParticlesP_reject cmp eax, x0 jge ClipParticlesP_reject mov edx, bpp mul edx add [ebx], eax add ebx, 4 add edi, 4 inc dword ptr [ParticleCount] loop ClipParticlesP_loop jmp ClipParticlesP_end ClipParticlesP_reject: add edi, 4 loop ClipParticlesP_loop ClipParticlesP_end: popf } } // ClipParticlesP() char *BgfxObjTime = __TIME__ " " __DATE__; int BgfxObjLines = __LINE__;