QAV.CPP 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "engine.h"
  2. #include "qav.h"
  3. #include "error.h"
  4. #include "misc.h"
  5. #include "tile.h"
  6. #include "trig.h"
  7. #include "debug4g.h"
  8. static void DrawFrame( int x, int y, TILE_FRAME *f, int shade, int flags )
  9. {
  10. short nAngle = f->angle;
  11. flags |= f->flags;
  12. if ( flags & kQFrameXFlip )
  13. {
  14. nAngle = (short)((nAngle + kAngle180) & kAngleMask);
  15. flags &= ~kQFrameXFlip;
  16. flags ^= kQFrameYFlip;
  17. }
  18. rotatesprite(
  19. x + f->x << 16,
  20. y + f->y << 16,
  21. f->zoom,
  22. nAngle,
  23. (short)f->id,
  24. (schar)ClipRange(f->shade + shade, -128, 127),
  25. (char)f->pal,
  26. (char)flags,
  27. windowx1, windowy1, windowx2, windowy2);
  28. }
  29. // render a complete frame for time t
  30. void QAV::Draw( long t, int shade, int flags )
  31. {
  32. dassert(ticksPerFrame > 0);
  33. int nFrame = t / ticksPerFrame;
  34. dassert(nFrame >= 0 && nFrame < nFrames);
  35. FRAME *f = &frame[nFrame];
  36. for (int i = 0; i < kMaxLayers; i++)
  37. {
  38. if ( f->layer[i].id > 0 )
  39. DrawFrame(origin.x, origin.y, &f->layer[i], shade, flags);
  40. }
  41. }
  42. // play a frame for time interval t0 < t <= t1
  43. void QAV::Play( long t0, long t1, QAVCALLBACK callback, void *data)
  44. {
  45. dassert(ticksPerFrame > 0);
  46. int nFrame;
  47. // need to truncate toward -infinity
  48. if ( t0 < 0 )
  49. nFrame = (t0 + 1) / ticksPerFrame;
  50. else
  51. nFrame = t0 / ticksPerFrame + 1;
  52. int t = nFrame * ticksPerFrame;
  53. for ( ; t <= t1; t += ticksPerFrame, nFrame++ )
  54. {
  55. if ( nFrame >= 0 && nFrame < nFrames )
  56. {
  57. FRAME *f = &frame[nFrame];
  58. // Play the sound
  59. // .
  60. // .
  61. // .
  62. // Callback triggers
  63. if ( f->trigger.id > 0 && callback != NULL )
  64. callback( f->trigger.id, data );
  65. }
  66. }
  67. }
  68. void QAV::Preload( void )
  69. {
  70. for (int i = 0; i < nFrames; i++)
  71. {
  72. for (int j = 0; j < kMaxLayers; j++)
  73. {
  74. if ( frame[i].layer[j].id >= 0 )
  75. tilePreloadTile(frame[i].layer[j].id);
  76. }
  77. }
  78. }