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

  1. #include <new.h>
  2. #include <fastgraf.h>
  3. #include <stdlib.h>
  4. #include "standard.h"
  5. #include "hand.h"
  6. #include "keysrvr.h"
  7. #include "kdsrvr.h"
  8. #include "timesrvr.h"
  9. #include "msgsrvr.h"
  10. #include "mcsrvr.h"
  11. #include "mmsrvr.h"
  12. #include "jssrvr.h"
  13. #include "netsrvr.h"
  14. #include "director.h"
  15. #include "theatrix.h"
  16.  
  17. static void memory_exhausted()
  18.   {
  19.   Theatrix::fatal("Out of memory");
  20.   }
  21.  
  22. Director::Director() : Hand(this)
  23.   {
  24.   static int newmemset = 0;
  25.   if (!newmemset)
  26.     {
  27.     set_new_handler(memory_exhausted);
  28.     newmemset = 1;
  29.     }
  30.   done=FALSE;
  31.   downmode = OFF;
  32.   if (Theatrix::current_game != 0)
  33.     Theatrix::current_game->add_director(this);
  34.   next_director = 0;
  35.   }
  36.  
  37. void Director::take_over()
  38.   {
  39.   done=FALSE;
  40.   while (!done)
  41.     {
  42.     if (!downmode)
  43.       Theatrix::kss.check(keyinfo);
  44.     else
  45.       Theatrix::hks.check(kdowninfo);
  46.     Theatrix::ts.check(timeinfo);
  47.     Theatrix::ms.check(msginfo);
  48.     Theatrix::mcs.check(mouseclickinfo);
  49.     Theatrix::mms.check(mousemoveinfo);
  50.     Theatrix::js.check(joystickinfo);
  51.     Theatrix::ns.check(netpackinfo);
  52.     iterate_director();
  53.     }
  54.   }
  55.  
  56. void Director::set_keydownmode(int mode)
  57.   {
  58.   downmode=mode;
  59.   fg_kbinit(downmode);
  60.   }
  61.  
  62. void Director::delete_hand(Hand* h)
  63.   {
  64.   keyinfo.delHand(h);
  65.   kdowninfo.delHand(h);
  66.   timeinfo.delHand(h);
  67.   msginfo.delHand(h);
  68.   }
  69.  
  70. //----------------------------------------------------------
  71. //---------------- Keystroke ---------------------------------
  72. //----------------------------------------------------------
  73.  
  74. void Director::add_keystroke_cue(Hand* h,callback cb,int key)
  75.   {
  76.   keyinfo.register_key(h,key,cb);
  77.   }
  78.  
  79. void Director::del_keystroke_cue(Hand* h,callback cb,int key)
  80.   {
  81.   keyinfo.unregister_key(h,key,cb);
  82.   }
  83.  
  84. //----------------------------------------------------------
  85. //---------------- Keydown ---------------------------------
  86. //----------------------------------------------------------
  87.  
  88. void Director::add_keydown_cue(Hand* h,callback cb,int key)
  89.   {
  90.   kdowninfo.register_key(h,key,cb);
  91.   }
  92.  
  93. void Director::del_keydown_cue(Hand* h,callback cb,int key)
  94.   {
  95.   kdowninfo.unregister_key(h,key,cb);
  96.   }
  97.  
  98. //----------------------------------------------------------
  99. //---------------- Timer -----------------------------------
  100. //----------------------------------------------------------
  101.  
  102. void Director::add_timer_cue(Hand* h,callback cb,int rate)
  103.   {
  104.   timeinfo.add_timer(h,rate,cb);
  105.   }
  106.  
  107. void Director::del_timer_cue(Hand* h,callback cb,int rate)
  108.   {
  109.   timeinfo.del_timer(h,rate,cb);
  110.   }
  111.  
  112. //----------------------------------------------------------
  113. //---------------- Message ---------------------------------
  114. //----------------------------------------------------------
  115.  
  116. void Director::add_message_cue(Hand* hand,callback cb,int msg)
  117.   {
  118.   msginfo.add_message(hand,msg,cb);
  119.   }
  120.  
  121. void Director::del_message_cue(Hand* hand,callback cb,int msg)
  122.   {
  123.   msginfo.del_message(hand,msg,cb);
  124.   }
  125.  
  126. void Director::submit_message(int msg,int data1,int data2)
  127.   {
  128.   msginfo.send(msg,data1,data2);
  129.   }
  130.  
  131. //----------------------------------------------------------
  132. //---------------- mouseclick ------------------------------
  133. //----------------------------------------------------------
  134.  
  135. void Director::add_mouseclick_cue(Hand* hand,callback cb,int b)
  136.   {
  137.   mouseclickinfo.register_mouseclick(hand,b,cb);
  138.   }
  139.  
  140. void Director::del_mouseclick_cue(Hand* hand,callback cb,int b)
  141.   {
  142.   mouseclickinfo.unregister_mouseclick(hand,b,cb);
  143.   }
  144.  
  145. //----------------------------------------------------------
  146. //---------------- mousemove -------------------------------
  147. //----------------------------------------------------------
  148.  
  149. void Director::add_mousemove_cue(Hand* hand,callback cb)
  150.   {
  151.   mousemoveinfo.register_mousemove(hand,cb);
  152.   }
  153.  
  154. void Director::del_mousemove_cue(Hand* hand,callback cb)
  155.   {
  156.   mousemoveinfo.unregister_mousemove(hand,cb);
  157.   }
  158.  
  159. //----------------------------------------------------------
  160. //---------------- joystickbutton ------------------------------
  161. //----------------------------------------------------------
  162.  
  163. void Director::add_joystickbutton_cue(Hand* hand,callback cb,int b)
  164.   {
  165.   joystickinfo.register_joystickbutton(hand,b,cb);
  166.   }
  167.  
  168. void Director::del_joystickbutton_cue(Hand* hand,callback cb,int b)
  169.   {
  170.   joystickinfo.unregister_joystickbutton(hand,b,cb);
  171.   }
  172.  
  173. //----------------------------------------------------------
  174. //---------------- joystickmove -------------------------------
  175. //----------------------------------------------------------
  176.  
  177. void Director::add_joystickmove_cue(Hand* hand,callback cb)
  178.   {
  179.   joystickinfo.register_joystickmove(hand,cb);
  180.   }
  181.  
  182. void Director::del_joystickmove_cue(Hand* hand,callback cb)
  183.   {
  184.   joystickinfo.unregister_joystickmove(hand,cb);
  185.   }
  186.  
  187. //----------------------------------------------------------
  188. //---------------- netpack ---------------------------------
  189. //----------------------------------------------------------
  190.  
  191. void Director::add_netpack_cue(Hand* hand,callback cb,int p)
  192.   {
  193.   netpackinfo.add_netpack(hand,p,cb);
  194.   }
  195.  
  196. void Director::del_netpack_cue(Hand* hand,callback cb,int p)
  197.   {
  198.   netpackinfo.del_netpack(hand,p,cb);
  199.   }
  200.  
  201. void Director::post_netpacket(int p)
  202.   {
  203.   Theatrix::ns.send(p);
  204.   }
  205.