vsand_intro.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright (c) 2010 Nokia Corporation.
  3. */
  4. #include <stdlib.h>
  5. #include "TMath.h"
  6. #include "TBase.h"
  7. #include "vsand_intro.h"
  8. #include "TDrawHelpers.h"
  9. #include "intro_digia.cpp"
  10. #include "intro_flare.cpp"
  11. #include "intro_sandpaint.cpp" // 500,83
  12. extern unsigned int sand_texture[];
  13. CVSand_Intro::CVSand_Intro( bool grab_bg) {
  14. m_cancelled = false;
  15. m_flare.setAsReference( intro_flare, 128,128,128, eTSURFACEFORMAT_RGBA8888 );
  16. m_sand.setAsReference( sand_texture, 128,128,128, eTSURFACEFORMAT_RGBA8888 );
  17. m_screenCounter = 0;
  18. m_screenIndex = -1;
  19. m_bg = 0;
  20. m_grabBackground = grab_bg;
  21. for (int f=0; f<1024; f++) m_cosTable[f] = (int)( tmath_cos( (float)f/1024.0f * 3.141549f*2.0f ) * (float)FP_VAL );
  22. };
  23. CVSand_Intro::~CVSand_Intro() {
  24. if (m_bg) delete m_bg;
  25. };
  26. int CVSand_Intro::run( int ft ) {
  27. if (m_cancelled==true) return 0;
  28. #ifdef WIN32
  29. m_screenCounter+=3000;
  30. #else
  31. m_screenCounter+=6600; // was 3000;
  32. #endif
  33. if (m_screenIndex==-1) {
  34. m_currentLogo.setAsReference( intro_digia, 360,180,360, eTSURFACEFORMAT_RGBA8888 );
  35. m_screenIndex = 1;
  36. m_screenCounter = 0;
  37. };
  38. switch (m_screenIndex) {
  39. default:
  40. break;
  41. case 1:
  42. if (m_screenCounter>65536*15) {
  43. m_screenIndex = 3;
  44. m_screenCounter = 0;
  45. m_currentLogo.setAsReference( intro_sandpaint, 481,116,481, eTSURFACEFORMAT_RGBA8888 );
  46. };
  47. break;
  48. case 3:
  49. if (m_screenCounter>65536*15) return 0;
  50. break;
  51. break;
  52. };
  53. return 1; // continue running
  54. };
  55. void vertical_light_line( TDWORD *t, TDWORD *s, int pitch, int h, int oy, int length, int height ) {
  56. t-=pitch*height;
  57. int a;
  58. register TDWORD temp, mask;
  59. for (int y=-height; y<=height; y++) {
  60. if (oy+y>=0 && oy+y<h)
  61. {
  62. TDWORD *t_target = t+length;
  63. int limit = (abs(y)<<8)/height;
  64. while (t!=t_target) {
  65. //a=((((s[0]>>16)&255)*(s[0]>>24))>>8)-limit;
  66. //a =((s[0]>>8)&255)-limit;
  67. a = (((((s[0])&255) + ((s[0]>>16)&255))*((s[0]>>24)&255)*18) >>13)-limit;
  68. if (a>0) {
  69. //a = (a*a)>>8;
  70. if (a>255) a = 255;
  71. mask = (a|(a<<8)|(a<<16));
  72. temp = ((*t&0xFEFEFEFE)>>1)+((mask&0xFEFEFEFE)>>1);
  73. mask = (temp&0x80808080);
  74. temp |= (mask-(mask>>7));
  75. *t = ((temp&0x7F7F7F7F)<<1); // color here
  76. };
  77. //*t = 0xffff00ff;
  78. s++;
  79. t++;
  80. };
  81. s-=length;
  82. t-=length;
  83. }
  84. t+=pitch;
  85. }
  86. };
  87. void CVSand_Intro::effectBlit1( CTSurface_RGBA8888 &target, CTSurface_RGBA8888 &source, int x, int y, int linelen, int fadeaway ) {
  88. //target.blit(x,y, &source);
  89. //return;
  90. TDWORD *t = (TDWORD*)target.getData() + target.getPitch()*y +x;
  91. TDWORD *s = (TDWORD*)source.getData();
  92. int val = (m_screenCounter>>5);
  93. int ytarget = (((source.getHeight()+64) * val)>>FP_BITS);
  94. int delta;
  95. int a;
  96. int ia;
  97. int whitec;
  98. //int r,g,b;
  99. for (int yloop=0; yloop<source.getHeight(); yloop++) {
  100. TDWORD *t_horline_target = t+source.getWidth();
  101. delta = (ytarget-yloop);
  102. //a = abs(delta)*2;
  103. a = 255+delta*32;
  104. if (a>255) a = 255;
  105. a = ((a*fadeaway)>>8);
  106. ia = (32-abs(delta))*8;
  107. if (ia<0) ia = 0;
  108. a -= ia;
  109. //whitec = 700-abs(delta)*5;
  110. whitec = 340-(delta*delta)/36;
  111. if (whitec>255) whitec = 255;
  112. if (whitec<0) whitec = 0;
  113. if (a>0) { // basic alpha horline
  114. while (t != t_horline_target) {
  115. ia = ((a*(*s>>24))>>8);
  116. //if (1) {
  117. if (ia>0) {
  118. *t = (((((*s&255)*(255^whitec)>>8) + whitec)*ia + ((*t)&255)*(255^ia))>>8) |
  119. (((((((*s>>8)&255)*(255^whitec)>>8) + whitec)*ia + (((*t)>>8)&255)*(255^ia) )>>8)<<8) |
  120. (((((((*s>>16)&255)*(255^whitec)>>8) + whitec)*ia + (((*t)>>16)&255)*(255^ia) )>>8)<<16);
  121. }
  122. t++;
  123. s++;
  124. };
  125. t-=source.getWidth();s-=source.getWidth();
  126. }
  127. t+=target.getPitch();
  128. s+=source.getPitch();
  129. };
  130. if (m_grabBackground==false) reflect(target, y+source.getHeight()-7, 100);
  131. if (ytarget<0) ytarget = 0;
  132. if (ytarget>source.getHeight()-1) ytarget = source.getHeight()-1;
  133. vertical_light_line( (TDWORD*)target.getData() + target.getPitch()*(y+ytarget)+x,
  134. (TDWORD*)source.getData()+ytarget*source.getPitch(),
  135. target.getPitch(), target.getHeight(), y+ytarget, source.getWidth(), linelen );
  136. };
  137. void CVSand_Intro::delightRed( CTSurface_RGBA8888 &target, int lx, int amount ) {
  138. int temp, iamount;
  139. for (int x=0; x<target.getWidth(); x++) {
  140. TDWORD *t=(TDWORD*)target.getData() + x;
  141. TDWORD *t_target = t+target.getPitch()*target.getHeight();
  142. iamount = ((x-lx)*16);
  143. if (iamount<0) iamount = 0;
  144. iamount+=amount;
  145. if (iamount>256) iamount = 256;
  146. while (t!=t_target) {
  147. temp = ((int)(((*t)>>16)&255)+iamount) - (int)((((*t)>>8)&255) + ((*t)&255));
  148. //temp = ((temp*amount)>>8);
  149. temp = 255-temp;
  150. if (temp<1) temp = 0;
  151. //if ((unsigned int)temp>0) {
  152. if (temp<256) {
  153. *t = ((((*t)&255)*temp)>>8) |
  154. ((((((*t)>>8)&255)*temp)>>8)<<8) |
  155. ((((((*t)>>16)&255)*temp)>>8)<<16) |
  156. ((*t)&0xFF000000);
  157. };
  158. t+=target.getPitch();
  159. };
  160. };
  161. };
  162. void CVSand_Intro::reflect( CTSurface_RGBA8888 &target, int y, int height ) {
  163. int val = 1;
  164. while (val<height) {
  165. if (y+val>=target.getHeight()) return;
  166. TDWORD *s = (TDWORD*)target.getData()+(y-val)*target.getPitch();
  167. TDWORD *t = (TDWORD*)target.getData()+(y+val)*target.getPitch();
  168. TDWORD *t_target = t+target.getWidth();
  169. int mul = (height-val)*64/height;
  170. while (t!=t_target) {
  171. *t = ((((*s)&255)*mul)>>8) | ((((((*s)>>8)&255)*mul)>>8)<<8) | ((((((*s)>>16)&255)*mul)>>8)<<16);
  172. s++;
  173. t++;
  174. };
  175. val++;
  176. };
  177. };
  178. void CVSand_Intro::sandBlit1( CTSurface_RGBA8888 &target, int x, int y, CTSurface_RGBA8888 &source, int phase ) {
  179. int targetx = -(source.getWidth()/2) + ((source.getWidth() * phase)>>16);
  180. TDWORD *sand = (TDWORD*)m_sand.getData();
  181. int spitch = source.getPitch();
  182. int tpitch = target.getPitch();
  183. TDWORD te, te2;
  184. int a,ia;
  185. int ofs;
  186. int tosand;
  187. int towhite;
  188. int delta, yloop;
  189. for (int xloop=0; xloop<source.getWidth(); xloop++) {
  190. TDWORD *s = (TDWORD*)source.getData() + xloop;
  191. TDWORD *s_target = s+source.getHeight()*spitch;
  192. TDWORD *t = (TDWORD*)target.getData() + (xloop+x) + (y*tpitch);
  193. delta = (targetx-xloop);
  194. a = 255+delta;
  195. if (a>255) a = 255;
  196. tosand = 300-delta*10;
  197. if (tosand<0) tosand = 0;
  198. if (tosand > 255) tosand = 255;
  199. //towhite = 512 - delta*8;
  200. towhite = 300 - ((delta*delta)>>4);
  201. if (towhite > 255) towhite = 255;
  202. if (towhite<0) towhite = 0;
  203. //tosand = 0;
  204. yloop=0;
  205. if (a>0)
  206. while (s!=s_target) {
  207. te = sand[((yloop&127)<<7) + (xloop&127) ]; // sand color
  208. ia = ((a*(*s>>24))>>8);
  209. ofs = (-120-delta*3 + (((*s>>0)&255)>>1) + ((te>>24)>>1) ); // * (int)(255^a) )>>8;
  210. //towhite = 128+ofs;
  211. if (ofs<0) ofs = 0;
  212. //ofs = (ofs * (int)(te>>24)) >> 8;
  213. //int debofs = ofs;
  214. ofs = ((-m_cosTable[ (((ofs<<1)+256)&1023) ]*ofs)>>18) +((((-FP_VAL*3/2+m_cosTable[ (((ofs<<2)+256)&1023) ])*ofs)>>18))*tpitch;
  215. te2 = (((((*s)>>0)&255)*(255^towhite)>>8) + towhite) |
  216. ((((((*s)>>8)&255)*(255^towhite)>>8) + towhite)<<8) |
  217. ((((((*s)>>16)&255)*(255^towhite)>>8) + towhite)<<16);
  218. t[ofs] = ((( (( ( (((te2)>>0)&255)*(255^tosand) + (((te>>0)&255)*tosand) ) * ia ) >> 8) + (((t[ofs])>>0)&255)*(255^ia) ) >> 8)<<0) |
  219. ((( (( ( (((te2)>>8)&255)*(255^tosand) + (((te>>8)&255)*tosand) ) * ia ) >> 8) + (((t[ofs])>>8)&255)*(255^ia) ) >> 8)<<8) |
  220. ((( (( ( (((te2)>>16)&255)*(255^tosand) + (((te>>16)&255)*tosand) ) * ia ) >> 8) + (((t[ofs])>>16)&255)*(255^ia) ) >> 8)<<16);
  221. //*t = *s;
  222. s+=spitch;
  223. t+=tpitch;
  224. yloop++;
  225. //xx+=1024;
  226. };
  227. //addline
  228. //yy+=1024;
  229. };
  230. };
  231. void CVSand_Intro::draw( CTSurface_RGBA8888 *target ) {
  232. // USE BG
  233. if (!m_bg) {
  234. if (m_grabBackground) {
  235. m_bg = new CTSurface_RGBA8888;
  236. m_bg->create( target->getWidth(), target->getHeight(), eTSURFACEFORMAT_RGBA8888 );
  237. m_bg->blit(0,0, target);
  238. } else target->clear();
  239. } else target->blit( 0,0, m_bg );
  240. if (m_screenIndex==3) {
  241. if (m_screenCounter<65536*14) {
  242. sandBlit1( *target, (target->getWidth()- m_currentLogo.getWidth())/2, (target->getHeight()- m_currentLogo.getHeight())/2, m_currentLogo, m_screenCounter>>3 );
  243. } else {
  244. int fadeout = 255-((m_screenCounter-65536*14)>>7);
  245. if (fadeout<0) fadeout = 0;
  246. target->blit( (target->getWidth()- m_currentLogo.getWidth())/2, (target->getHeight()- m_currentLogo.getHeight())/2, &m_currentLogo,eTBLITOPERATION_ALPHA, 0x00FFFFFF | (fadeout<<24) );
  247. }
  248. if (m_grabBackground == false) reflect(*target, target->getHeight()/2+47, 100);
  249. }
  250. if (m_screenIndex == 1) { // ** DIGIA LOGO **, hackthon, logo
  251. int fadeaway = 255;
  252. // digia flare
  253. fadeaway = 255-((m_screenCounter-65536*13)>>9);
  254. if (fadeaway<0) fadeaway = 0;
  255. if (fadeaway>255) fadeaway = 255;
  256. effectBlit1(*target, m_currentLogo, (target->getWidth() - m_currentLogo.getWidth())/2,(target->getHeight() - m_currentLogo.getHeight())/2, 160, fadeaway);
  257. int FLARE_BEGIN = 65536*78/16;
  258. if (m_screenCounter>FLARE_BEGIN) {
  259. int p = (((m_screenCounter-FLARE_BEGIN)>>10)&127);
  260. int a = (((255-p*2) * fadeaway)>>8);
  261. if (a>255) a = 255;
  262. int vx = m_cosTable[ ((m_screenCounter>>8) & 1023) ]*(4+p*3/2);
  263. int vy = m_cosTable[ ((m_screenCounter>>9)+256) & 1023 ]*(4+p*3/2);
  264. CTDrawHelpers::rotateBlit(target, &m_flare, (target->getWidth()-34) << 13, (target->getHeight()+118)<<13, vx,vy, a | (a<<8) | (a<<16), eTBLITOPERATION_ADD );
  265. }
  266. }
  267. };