PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Pristine-Pro/PLAYER/PLAYANIM.C

http://github.com/AnimatorPro/Animator-Pro
C | 219 lines | 170 code | 37 blank | 12 comment | 42 complexity | 59d0402fb3334a870611365f375010dd MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #include "player.h"
  2. #include "gfx.h"
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #include <ctype.h>
  6. static void true_cmap_fade(Cmap *scmap, Cmap *dcmap, Rgb3 *color,
  7. int p, int q)
  8. {
  9. ULONG vp;
  10. ULONG q2;
  11. int count;
  12. UBYTE *s, *d;
  13. count = dcmap->num_colors;
  14. s = (UBYTE *)(scmap->ctab);
  15. d = (UBYTE *)(dcmap->ctab);
  16. vp = q - p;
  17. q2 = q/2;
  18. while (--count >= 0)
  19. {
  20. *d++ = ((*s++ * vp) + ((UBYTE)(color->r) * p) + q2)/q;
  21. *d++ = ((*s++ * vp) + ((UBYTE)(color->g) * p) + q2)/q;
  22. *d++ = ((*s++ * vp) + ((UBYTE)(color->b) * p) + q2)/q;
  23. }
  24. }
  25. static void sync_load_cmap(Cmap *dcmap)
  26. {
  27. pj_wait_rast_vsync(vb.pencel);
  28. pj_set_colors(vb.pencel, 0, 128, (UBYTE *)(dcmap->ctab));
  29. pj_wait_rast_vsync(vb.pencel);
  30. pj_set_colors(vb.pencel, 128, 128, (UBYTE *)&(dcmap->ctab[128]));
  31. }
  32. static Errcode fade_cmap(Boolean fade_in)
  33. {
  34. extern ULONG pj_clock_1000();
  35. Errcode err;
  36. Cmap *scmap;
  37. Cmap *dcmap;
  38. ULONG start;
  39. LONG elapsed, notdone;
  40. Rgb3 *color;
  41. LONG fade_time, *pp;
  42. ULONG cmapsum;
  43. ULONG newsum;
  44. if(fade_in)
  45. {
  46. color = &pcb.in_from;
  47. pp = &notdone;
  48. fade_time = pcb.fadein;
  49. }
  50. else
  51. {
  52. color = &pcb.out_to;
  53. pp = &elapsed;
  54. fade_time = pcb.fadeout;
  55. }
  56. /* get a clone of the souce color map for reference */
  57. dcmap = vb.pencel->cmap;
  58. if((scmap = clone_cmap(dcmap)) == NULL)
  59. return(Err_no_memory);
  60. start = pj_clock_1000();
  61. elapsed = 0;
  62. cmapsum = -1;
  63. while(elapsed < fade_time)
  64. {
  65. if((err = check_play_abort()) != Success)
  66. goto done;
  67. notdone = fade_time - elapsed;
  68. true_cmap_fade(scmap, dcmap, color, *pp, fade_time);
  69. if((newsum = cmap_crcsum(dcmap)) != cmapsum)
  70. {
  71. cmapsum = newsum;
  72. sync_load_cmap(dcmap);
  73. }
  74. elapsed = pj_clock_1000() - start;
  75. }
  76. /* Make sure we have gone all the way and that it's accurate.
  77. * Note that when fading out the colormap is altered to the fade out
  78. * color */
  79. if(fade_in)
  80. pj_cmap_copy(scmap,dcmap);
  81. else /* fade out */
  82. stuff_cmap(dcmap,color);
  83. if((cmap_crcsum(dcmap)) != cmapsum)
  84. sync_load_cmap(dcmap);
  85. err = Success;
  86. done:
  87. pj_cmap_free(scmap);
  88. return(err);
  89. }
  90. static Errcode wait_play_pause()
  91. /* returns Err_abort if ESCEY (Success + 1) if other abort Success if
  92. * no abort */
  93. {
  94. Errcode err;
  95. ULONG time;
  96. time = pj_clock_1000() + pcb.pause;
  97. while((pcb.pause == 0) || time > pj_clock_1000())
  98. {
  99. if((err = check_play_abort()) != Success)
  100. return(err);
  101. }
  102. return(Success);
  103. }
  104. Errcode play_scripted_anim()
  105. /* plays the previusly parsed scripted animation image. This reports
  106. * errors */
  107. {
  108. Errcode err;
  109. Boolean do_fadein, singleframe;
  110. Cmap *cmap;
  111. int mouse_was_on;
  112. mouse_was_on = hide_mouse();
  113. cmap = vb.pencel->cmap;
  114. if((do_fadein = pcb.fadein > 0) != 0)
  115. {
  116. stuff_cmap(cmap,&pcb.in_from);
  117. sync_load_cmap(cmap);
  118. }
  119. /* These loaders will load the colors into the ram cmap but not into
  120. * the hardware. This is why we must re sync the color map if an error
  121. * occurrs so the menu colors will be correct */
  122. singleframe = TRUE;
  123. if((pcb.loadpdr[0])
  124. || (err = open_curfli(!do_fadein,FALSE)) < Success)
  125. {
  126. if((err = open_curpic(!do_fadein)) < Success)
  127. goto error;
  128. }
  129. else /* fli opened ok */
  130. {
  131. singleframe = pcb.flif.hdr.frame_count == 1;
  132. }
  133. if(do_fadein)
  134. {
  135. if((err = fade_cmap(TRUE)) != Success)
  136. goto error;
  137. }
  138. if(singleframe)
  139. {
  140. if(pcb.pause < 0)
  141. pcb.pause = 5000; /* 5 seconds default */
  142. }
  143. else
  144. {
  145. if(pcb.sspeed < 0)
  146. pcb.speed = pcb.flif.hdr.speed; /* default to file speed */
  147. else
  148. pcb.speed = pcb.sspeed;
  149. }
  150. for(;;)
  151. {
  152. if(singleframe)
  153. err = Success;
  154. else
  155. err = play_fli();
  156. /* unless error or a "soft" abort do the pause */
  157. if(err == Success && pcb.pause >= 0)
  158. err = wait_play_pause();
  159. if(err < Success)
  160. goto error;
  161. if(err > Success && ((UBYTE)pcb.abort_key) == AKEY_REPLAY)
  162. {
  163. pcb.abort_key = 0;
  164. if((pla_seek_frame(0)) < Success)
  165. goto error;
  166. continue;
  167. }
  168. break;
  169. }
  170. if(pcb.fadeout > 0)
  171. {
  172. err = fade_cmap(FALSE);
  173. pj_clear_rast(vb.pencel);
  174. }
  175. error:
  176. if(err < Success) /* color map may be out of sync here */
  177. pj_cmap_load(vb.pencel,vb.pencel->cmap);
  178. if(mouse_was_on)
  179. show_mouse();
  180. close_curfli();
  181. return(err);
  182. }