Subversion Repositories Games.Carmageddon

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "demo.h"
  2. #include "globvars.h"
  3. #include "graphics.h"
  4. #include "harness/trace.h"
  5. #include "input.h"
  6. #include "loading.h"
  7. #include "pd/sys.h"
  8. #include "s3/s3.h"
  9. #include "sound.h"
  10. #include "utility.h"
  11. #include <stdlib.h>
  12.  
  13. int gLast_demo;
  14.  
  15. // IDA: void __cdecl DoDemo()
  16. void DoDemo(void) {
  17.     tS32 start_time;
  18.     tS32 frame_time;
  19.     FILE* f;
  20.     tPath_name the_path;
  21.     int i;
  22.     int count;
  23.     char s[256];
  24.     //char* str; // Pierre-Marie Baty -- unused variable
  25.     tS3_sound_tag song_tag;
  26.     LOG_TRACE("()");
  27.  
  28.     PathCat(the_path, gApplication_path, "DEMOFILE.TXT");
  29.     f = DRfopen(the_path, "rt");
  30.     if (f == NULL) {
  31.         return;
  32.     }
  33.     count = GetAnInt(f);
  34.     gLast_demo++;
  35.     if (gLast_demo >= count) {
  36.         gLast_demo = 0;
  37.     }
  38.     for (i = 0; i <= gLast_demo; i++) {
  39.         GetALineAndDontArgue(f, s);
  40.     }
  41.     fclose(f);
  42.     PathCat(the_path, gApplication_path, s);
  43.     f = DRfopen(the_path, "rb");
  44.     if (f == NULL) {
  45.         return;
  46.     }
  47.  
  48.     ClearEntireScreen();
  49.     song_tag = S3StartSound(gEffects_outlet, 10000);
  50.     DRSetPalette(gRender_palette);
  51.     FadePaletteUp();
  52.  
  53.     while (1) {
  54.         SoundService();
  55.         start_time = PDGetTotalTime();
  56.         frame_time = ReadS32(f);
  57.         fread(gBack_screen->pixels, gBack_screen->height * gBack_screen->width, 1, f);
  58.         PDScreenBufferSwap(0);
  59.         while (frame_time > PDGetTotalTime() - start_time && !AnyKeyDown() && !EitherMouseButtonDown()) {
  60.             // FIXME: sleep? SoundService?
  61.         }
  62.         if (!S3SoundStillPlaying(song_tag)) {
  63.             song_tag = S3StartSound(gEffects_outlet, 10000);
  64.         }
  65.         if (AnyKeyDown() || EitherMouseButtonDown() || feof(f)) {
  66.             break;
  67.         }
  68.     }
  69.     S3StopSound(song_tag);
  70.     S3StopOutletSound(gEffects_outlet);
  71.     S3StopAllOutletSounds();
  72.     fclose(f);
  73.     FadePaletteDown();
  74.     WaitForNoKeys();
  75. }
  76.