scope.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include <windows.h>
  2. #include <math.h>
  3. #define M_PI 3.14159265358979323846
  4. extern int (*warand)(void);
  5. extern void line(unsigned char *fb, int X0, int Y0, int X1, int Y1, int w, int h);
  6. static double sc_curtime;
  7. static unsigned int sc_starttime;
  8. static int __inline myftol(double d)
  9. {
  10. int a;
  11. __asm
  12. {
  13. fld d
  14. fistp a
  15. mov eax, a
  16. }
  17. }
  18. static void __doscope(int fx, int ipos, double i, double v, double &x, double &y, double &sc_tmp)
  19. {
  20. double r,d;
  21. switch (fx)
  22. {
  23. case 0: x=2.0*(i-0.5); y=v*0.5; return;
  24. case 1:
  25. x=cos(i*M_PI*3.0+sc_curtime)*(0.5+v*0.2);
  26. y=sin(i*M_PI*6.0+sc_curtime)*(0.5+v*0.2);
  27. return;
  28. case 2:
  29. r=i*M_PI*128+sc_curtime;
  30. x=cos(r/(64.0+32.0*cos(sc_curtime*M_PI)))*0.4+sin(r)*0.05;
  31. y=sin(r/(64.0+32.0*cos(sc_curtime*M_PI)))*0.4+cos(r)*0.05;
  32. return;
  33. case 3:
  34. r=M_PI*cos(sc_curtime*0.5)*2;
  35. x=cos(r)*0.3+cos(i*M_PI*2)*v*0.5;
  36. y=sin(r)*0.3+sin(i*M_PI*2)*v*0.5;
  37. return;
  38. case 4:
  39. r=M_PI*cos(sc_curtime*0.5)*2;
  40. x=cos(r)*0.3+cos(i*M_PI*2)*(1.0+v)*0.23;
  41. y=sin(r*1.5)*0.3+sin(i*M_PI*2)*(1.0+v)*0.23;
  42. return;
  43. case 5:
  44. y=2.0*(i-0.5);
  45. x=v*0.5 + 0.4*cos(sc_curtime);
  46. return;
  47. case 6:
  48. d=i+v*0.2;
  49. r=sc_curtime+i*3.14159*4;
  50. x=cos(r)*d*0.6;
  51. y=sin(r)*d*0.6;
  52. return;
  53. case 7:
  54. x=(i-0.5)*2.0;
  55. y=0.25-0.5*fabs(sin(i*M_PI*4 + sc_curtime)) + v*0.2;
  56. return;
  57. case 8:
  58. r=i*3.14159*2;
  59. d=sin(r*3)+v*0.5;
  60. x=cos(sc_curtime+r)*d;
  61. y=sin(sc_curtime-r)*d;
  62. return;
  63. case 9:
  64. x=2.0*(i-0.5);
  65. y=v*v*v*0.7;
  66. return;
  67. case 10:
  68. x=cos(i*8)*0.9*sin(sc_curtime);
  69. y=sin(i*8)*0.5*v;
  70. return;
  71. case 11:
  72. d=i-0.9;
  73. sc_tmp=sc_tmp+v*0.1;
  74. x=cos(sc_tmp)*d+sin(sc_tmp)*v+0.3;
  75. y=sin(sc_tmp)*d-cos(sc_tmp)*v;
  76. return;
  77. case 12:
  78. r=i*8;
  79. x=cos(r)*0.3+sin(r*(3+cos(sc_curtime*0.5+i*3.0)))*0.2;
  80. y=sin(r)*0.3+cos(r*(2+2*cos(sc_curtime*0.5+i*3.0)))*0.2;
  81. return;
  82. case 13:
  83. x=v*0.3+sin(i*4*3.14159)*cos(sc_curtime)*0.4;
  84. y=2.0*(i-0.5);
  85. return;
  86. case 14:
  87. if (!(ipos&3)) x=y=0;
  88. else
  89. {
  90. x=v;
  91. y=(ipos&8)?1.0:-1.0;
  92. if (ipos & 4)
  93. {
  94. sc_tmp=y;
  95. y=x;
  96. x=sc_tmp;
  97. }
  98. }
  99. return;
  100. case 15:
  101. x=(ipos&1)?-1:1;
  102. y=(ipos&30)?0:v;
  103. return;
  104. case 16:
  105. r=ipos * 3.14159 * (0.3);
  106. x=(0.3+v*0.1)*cos(r);
  107. y=(0.3+v*0.1)*sin(r);
  108. return;
  109. }
  110. }
  111. //#define TEST_SCOPE 14
  112. #define NUM_SC 17
  113. static unsigned int start;
  114. #define INTERVAL 5000
  115. static int curfx[2]={0,NUM_SC},lastfx[2]={0,NUM_SC}, interval_l=INTERVAL;
  116. static double fxblend, lastfxblend;
  117. void drawscope(unsigned char *out, int w, int h, unsigned char *visdata)
  118. {
  119. double tmp1=0.0;
  120. double tmp2=0.0;
  121. double tmp3=0.0;
  122. double tmp4=0.0;
  123. int x;
  124. int lx=0;
  125. int ly=0;
  126. double w2=w*65536.0/2.0;
  127. double h2=h*65536.0/2.0;
  128. if (!sc_starttime) sc_starttime=GetTickCount();
  129. sc_curtime=(GetTickCount()-sc_curtime)/1000.0;
  130. if (GetTickCount()>=start+INTERVAL)
  131. {
  132. lastfxblend=fxblend;
  133. lastfx[0]=curfx[0];
  134. lastfx[1]=curfx[1];
  135. start=GetTickCount();
  136. curfx[0]=warand()%NUM_SC;
  137. curfx[1]=warand()%NUM_SC;
  138. interval_l=2500+(warand()&8191);
  139. if (interval_l > INTERVAL) interval_l=INTERVAL;
  140. for (x = 0; x < 2; x ++)
  141. if (curfx[x] == 14 || curfx[x] == 15) curfx[x]=warand()%NUM_SC;
  142. fxblend=0.25+(warand()&511)/1023.0;
  143. #ifdef TEST_SCOPE
  144. curfx[0]=TEST_SCOPE;
  145. lastfx[0]=curfx[0];
  146. curfx[1]=NUM_SC;
  147. lastfx[1]=NUM_SC;
  148. fxblend=lastfxblend=0.0;
  149. #endif
  150. }
  151. double weight=(double)(GetTickCount()-start)*(1.0/(double)(interval_l));
  152. if (weight > 1.0) weight=1.0;
  153. for (x = 0; x < 576; x ++)
  154. {
  155. int xp;
  156. int yp;
  157. double xof=0.0, yof=0.0;
  158. double ix=x/576.0;
  159. double iy=((visdata[x]^128)-128)/127.5;
  160. __doscope(curfx[0],x,ix,iy,xof,yof,tmp1);
  161. {
  162. double xof2=0.0,yof2=0.0;
  163. __doscope(curfx[1],x,ix,iy,xof2,yof2,tmp3);
  164. xof=xof*(1.0-fxblend) + xof2*fxblend;
  165. yof=yof*(1.0-fxblend) + yof2*fxblend;
  166. }
  167. {
  168. double xof2=0.0, yof2=0.0;
  169. __doscope(lastfx[0],x,ix,iy,xof2,yof2,tmp2);
  170. {
  171. double xof3=0.0,yof3=0.0;
  172. __doscope(lastfx[1],x,ix,iy,xof3,yof3,tmp4);
  173. xof2=xof2*(1.0-lastfxblend) + xof3*lastfxblend;
  174. yof2=yof2*(1.0-lastfxblend) + yof3*lastfxblend;
  175. }
  176. xof=xof*weight + xof2*(1.0-weight);
  177. yof=yof*weight + yof2*(1.0-weight);
  178. }
  179. xp = myftol(xof * w2 + w2);
  180. yp = myftol(yof * h2 + h2);
  181. if (x) line(out,lx,ly,xp,yp,w,h);
  182. lx=xp;
  183. ly=yp;
  184. }
  185. }