home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
theatrix
/
director.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-04
|
5KB
|
205 lines
#include <new.h>
#include <fastgraf.h>
#include <stdlib.h>
#include "standard.h"
#include "hand.h"
#include "keysrvr.h"
#include "kdsrvr.h"
#include "timesrvr.h"
#include "msgsrvr.h"
#include "mcsrvr.h"
#include "mmsrvr.h"
#include "jssrvr.h"
#include "netsrvr.h"
#include "director.h"
#include "theatrix.h"
static void memory_exhausted()
{
Theatrix::fatal("Out of memory");
}
Director::Director() : Hand(this)
{
static int newmemset = 0;
if (!newmemset)
{
set_new_handler(memory_exhausted);
newmemset = 1;
}
done=FALSE;
downmode = OFF;
if (Theatrix::current_game != 0)
Theatrix::current_game->add_director(this);
next_director = 0;
}
void Director::take_over()
{
done=FALSE;
while (!done)
{
if (!downmode)
Theatrix::kss.check(keyinfo);
else
Theatrix::hks.check(kdowninfo);
Theatrix::ts.check(timeinfo);
Theatrix::ms.check(msginfo);
Theatrix::mcs.check(mouseclickinfo);
Theatrix::mms.check(mousemoveinfo);
Theatrix::js.check(joystickinfo);
Theatrix::ns.check(netpackinfo);
iterate_director();
}
}
void Director::set_keydownmode(int mode)
{
downmode=mode;
fg_kbinit(downmode);
}
void Director::delete_hand(Hand* h)
{
keyinfo.delHand(h);
kdowninfo.delHand(h);
timeinfo.delHand(h);
msginfo.delHand(h);
}
//----------------------------------------------------------
//---------------- Keystroke ---------------------------------
//----------------------------------------------------------
void Director::add_keystroke_cue(Hand* h,callback cb,int key)
{
keyinfo.register_key(h,key,cb);
}
void Director::del_keystroke_cue(Hand* h,callback cb,int key)
{
keyinfo.unregister_key(h,key,cb);
}
//----------------------------------------------------------
//---------------- Keydown ---------------------------------
//----------------------------------------------------------
void Director::add_keydown_cue(Hand* h,callback cb,int key)
{
kdowninfo.register_key(h,key,cb);
}
void Director::del_keydown_cue(Hand* h,callback cb,int key)
{
kdowninfo.unregister_key(h,key,cb);
}
//----------------------------------------------------------
//---------------- Timer -----------------------------------
//----------------------------------------------------------
void Director::add_timer_cue(Hand* h,callback cb,int rate)
{
timeinfo.add_timer(h,rate,cb);
}
void Director::del_timer_cue(Hand* h,callback cb,int rate)
{
timeinfo.del_timer(h,rate,cb);
}
//----------------------------------------------------------
//---------------- Message ---------------------------------
//----------------------------------------------------------
void Director::add_message_cue(Hand* hand,callback cb,int msg)
{
msginfo.add_message(hand,msg,cb);
}
void Director::del_message_cue(Hand* hand,callback cb,int msg)
{
msginfo.del_message(hand,msg,cb);
}
void Director::submit_message(int msg,int data1,int data2)
{
msginfo.send(msg,data1,data2);
}
//----------------------------------------------------------
//---------------- mouseclick ------------------------------
//----------------------------------------------------------
void Director::add_mouseclick_cue(Hand* hand,callback cb,int b)
{
mouseclickinfo.register_mouseclick(hand,b,cb);
}
void Director::del_mouseclick_cue(Hand* hand,callback cb,int b)
{
mouseclickinfo.unregister_mouseclick(hand,b,cb);
}
//----------------------------------------------------------
//---------------- mousemove -------------------------------
//----------------------------------------------------------
void Director::add_mousemove_cue(Hand* hand,callback cb)
{
mousemoveinfo.register_mousemove(hand,cb);
}
void Director::del_mousemove_cue(Hand* hand,callback cb)
{
mousemoveinfo.unregister_mousemove(hand,cb);
}
//----------------------------------------------------------
//---------------- joystickbutton ------------------------------
//----------------------------------------------------------
void Director::add_joystickbutton_cue(Hand* hand,callback cb,int b)
{
joystickinfo.register_joystickbutton(hand,b,cb);
}
void Director::del_joystickbutton_cue(Hand* hand,callback cb,int b)
{
joystickinfo.unregister_joystickbutton(hand,b,cb);
}
//----------------------------------------------------------
//---------------- joystickmove -------------------------------
//----------------------------------------------------------
void Director::add_joystickmove_cue(Hand* hand,callback cb)
{
joystickinfo.register_joystickmove(hand,cb);
}
void Director::del_joystickmove_cue(Hand* hand,callback cb)
{
joystickinfo.unregister_joystickmove(hand,cb);
}
//----------------------------------------------------------
//---------------- netpack ---------------------------------
//----------------------------------------------------------
void Director::add_netpack_cue(Hand* hand,callback cb,int p)
{
netpackinfo.add_netpack(hand,p,cb);
}
void Director::del_netpack_cue(Hand* hand,callback cb,int p)
{
netpackinfo.del_netpack(hand,p,cb);
}
void Director::post_netpacket(int p)
{
Theatrix::ns.send(p);
}