home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / theatrix / viddir.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  5KB  |  218 lines

  1. //-------------------------------------------------------------------------
  2.  
  3. #include <fastgraf.h>
  4. #include <fstream.h>
  5. #include <stdlib.h>
  6. #include "standard.h"
  7. #include "viddir.h"
  8. #include "ascii.h"
  9. #include "scancode.h"
  10. #include "theatrix.h"
  11.  
  12. int VideoDirector::vpage;
  13. patch_struct VideoDirector::patch[NUMPATCHES];
  14. int VideoDirector::patchcount;
  15. char VideoDirector::flic_context[16];
  16. FlicHdr VideoDirector::flic_header;
  17. int VideoDirector::flicplaying;
  18. int VideoDirector::flicframes;
  19. int VideoDirector::flicnonstop;
  20. int VideoDirector::delay;
  21. int VideoDirector::first;
  22.  
  23. VideoDirector::VideoDirector()
  24.   {
  25.   request_keystroke_cue('|',(callback)&VideoDirector::on_s);
  26.   request_hotkey_cue(SCAN_PRINTSCREEN,(callback)&VideoDirector::on_hs);
  27.   }
  28.  
  29. VideoDirector::~VideoDirector()
  30.   {
  31.   fg_setpage(0);
  32.   fg_setvpage(0);
  33.   vpage=0;
  34.   }
  35.  
  36. void VideoDirector::init_video()
  37.   {
  38.   fg_setpage(0);
  39.   fg_setcolor(0);
  40.   fg_rect(0,fg_getmaxx(),0,fg_getmaxy());
  41.   fg_setvpage(0);
  42.   fg_setpage(1);
  43.   fg_sethpage(2);
  44.   fg_rect(0,fg_getmaxx(),0,fg_getmaxy());
  45.   vpage=0;
  46.   }
  47.  
  48. int VideoDirector::show_pcx(char* fname)
  49.   {
  50.   fg_move(0,0);
  51.   return fg_showpcx(fname,2)==0;
  52.   }
  53.  
  54. void VideoDirector::show_video(char* fname,int x,int y, int nonstop)
  55.   {
  56.   if (fg_flichead(fname, (char*)&flic_header) != 0)
  57.     Theatrix::fatal("Bad or missing FLC");
  58.   fg_flicopen(fname, flic_context);
  59.   fg_move(x,y);
  60.   flicplaying = 1;
  61.   flicnonstop = nonstop;
  62.   flicframes = flic_header.frames;
  63.   if (mouseinuse)
  64.     fg_mousevis(0);
  65.   fg_setvpage(1-vpage);
  66.   delay = (int) ((flic_header.delay / 55) * fg_measure());
  67.   first = 1;
  68.   }
  69.  
  70. void VideoDirector::iterate_director()
  71.   {
  72.   Director::iterate_director();
  73.   if (flicplaying)
  74.     {
  75.     if (flicframes-- == 0)
  76.       {
  77.       if (!flicnonstop)
  78.         {
  79.         stop_video();
  80.         return;
  81.         }
  82.       fg_flicskip(flic_context, -1);
  83.       flicframes = flic_header.frames;
  84.       }
  85.     if (mouseinuse && !first)
  86.       fg_mousevis(0);
  87.     fg_flicplay(flic_context, 1, 3);
  88.     if (mouseinuse)
  89.       fg_mousevis(1);
  90.     fg_stall(delay);
  91.     first = 0;
  92.     }
  93.   }
  94.  
  95. void VideoDirector::stop_video()
  96.   {
  97.   if (flicplaying)
  98.     {
  99.     fg_flicdone(flic_context);
  100.     flicplaying = 0;
  101.     fg_setvpage(vpage);
  102.     }
  103.   }
  104.  
  105. void VideoDirector::fill_background_buffer(int frompage)
  106.   {
  107.   fg_copypage(frompage,BUFFERPAGE);
  108.   }
  109.  
  110. void VideoDirector::restore_page()
  111.   {
  112.   fg_copypage(BUFFERPAGE,1-vpage);
  113.   }
  114.  
  115. void VideoDirector::swap_video_pages()
  116.   {
  117.   fg_setpage(vpage);
  118.   vpage=1-vpage;
  119.   fg_setvpage(vpage);
  120.   }
  121.  
  122. void VideoDirector::synch_video_pages()
  123.   {
  124.   fg_copypage(vpage,1-vpage);
  125.   }
  126.  
  127. void VideoDirector::synch_patch(int x1,int y1,int x2,int y2)
  128.   {
  129.   fg_sethpage(vpage);
  130.   fg_restore(x1,x2,y1,y2);
  131.   }
  132.  
  133. int VideoDirector::set_synch_patch(int x1,int y1,int x2,int y2)
  134.   {
  135.   if (patchcount>=NUMPATCHES)  return ERROR;
  136.   patch[patchcount].x1=x1;
  137.   patch[patchcount].y1=y1;
  138.   patch[patchcount].x2=x2;
  139.   patch[patchcount].y2=y2;
  140.   patchcount++;
  141.   return OK;
  142.   }
  143.  
  144. int VideoDirector::synch_patches(int frvpage)
  145.   {
  146.   int i,ret=patchcount;
  147.   if (frvpage)
  148.     fg_sethpage(vpage);
  149.   else
  150.     fg_sethpage(BUFFERPAGE);
  151.   for (i=0;i<patchcount;i++)
  152.     fg_restore(patch[i].x1,patch[i].x2,patch[i].y1,patch[i].y2);
  153.   patchcount=0;
  154.   return ret;
  155.   }
  156.  
  157. void VideoDirector::restore_patch(int x1,int y1,int x2,int y2)
  158.   {
  159.   fg_sethpage(BUFFERPAGE);
  160.   fg_restore(x1,x2,y1,y2);
  161.   }
  162.  
  163. void VideoDirector::flush_patch(int x1,int y1,int x2,int y2)
  164.   {
  165.   fg_sethpage(1-vpage);
  166.   fg_setpage(vpage);
  167.   fg_restore(x1,x2,y1,y2);
  168.   fg_setpage(1-vpage);
  169.   }
  170.  
  171. int VideoDirector::install_palette(char* fname)
  172.   {
  173.   struct pal_entry       // struct compadible with the
  174.     {                    // fg_setdacs routine
  175.     unsigned char r;
  176.     unsigned char g;
  177.     unsigned char b;
  178.     };
  179.   char str[80];
  180.   int i,max;
  181.   pal_entry* pal_array;
  182.   int r,g,b;
  183.   ifstream palfile(fname);
  184.   if (palfile.bad())  return NOT_OK;
  185.   palfile.getline(str,80);
  186.   palfile.getline(str,80);
  187.   palfile.getline(str,80);
  188.   max=atoi(str);
  189.   pal_array=new pal_entry[max];
  190.   for (i=0;i<max;i++)
  191.     {
  192.     palfile >> r;
  193.     palfile >> g;
  194.     palfile >> b;
  195.     pal_array[i].r=(unsigned char)r;
  196.     pal_array[i].g=(unsigned char)g;
  197.     pal_array[i].b=(unsigned char)b;
  198.     }
  199.   fg_setdacs(0,max,(char*)pal_array);
  200.   delete pal_array;
  201.   return OK;
  202.   }
  203.  
  204. void VideoDirector::on_s(int)
  205.   {
  206.   swap_video_pages();
  207.   fg_makepcx(0,fg_getmaxx(),0,fg_getmaxy(),"screen.pcx");
  208.   swap_video_pages();
  209.   }
  210.  
  211. void VideoDirector::on_hs(int)
  212.   {
  213.   static int flag;
  214.   if (flag)  return;
  215.   flag=TRUE;
  216.   on_s();
  217.   }
  218.