home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
theatrix
/
theatrix.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-26
|
4KB
|
217 lines
#include <stdlib.h>
#include <fastgraf.h>
#include <iostream.h>
#include <constrea.h>
#include <string.h>
#include <conio.h>
#include <typeinfo.h>
#include "director.h"
#include "perform.h"
#include "vocal.h"
#include "music.h"
#include "timesrvr.h"
#include "kdsrvr.h"
#include "jssrvr.h"
#include "settings.h"
#include "standard.h"
#include "media.h"
#include "netsrvr.h"
#include "theatrix.h"
Theatrix *Theatrix::current_game;
KeystrokeServer Theatrix::kss;
HotkeyServer Theatrix::hks;
TimerServer Theatrix::ts;
MessageServer Theatrix::ms;
MouseclickServer Theatrix::mcs;
MousemoveServer Theatrix::mms;
JoystickServer Theatrix::js;
NetpackServer Theatrix::ns;
void Theatrix::use_video_mode(int vmode)
{
videomode=vmode;
}
void Theatrix::set_xms(int mode)
{
Media::set_xms(mode);
}
void Theatrix::add_director(Director* d)
{
director[dcount++]=d;
}
Theatrix::Theatrix(char* str)
{
dcount = 0;
if (current_game != 0)
fatal("only one Theatrix object can exist at a time");
current_game = this;
fg_waitfor(9);
constream screen;
screen.clrscr();
screen << setattr(31) << setxy(1,1);
for (int i=1;i<80;i++)
screen << ' ';
screen << setxy((80-strlen(str))/2,1) << str;
screen << setattr(7);
cout << "\n\n";
videomode=DEFAULT_VIDEO_MODE;
}
void Theatrix::enable_netpacks()
{
ns.netpacks_active = TRUE;
}
void Theatrix::use_commport(int p)
{
ns.port=p;
}
void Theatrix::enable_joystick()
{
js.joystick_supported = 1;
}
void Theatrix::joystick_extremes(int *x1, int *y1, int *x2, int *y2)
{
*x1 = js.lx;
*y1 = js.ty;
*x2 = js.rx;
*y2 = js.by;
}
void Theatrix::go(const Type_info& id)
{
int index=find_director_index(id);
if (index==-1) fatal("cannot locate initial director");
go(index);
}
void Theatrix::go(int index)
{
fg_waitfor(1);
ts.startup();
hks.startup();
VocalHand::startup();
MusicHand::startup();
if (js.joystick_supported)
js.startup();
ns.startup();
cout << '\n';
Hand::initialize_hands();
cout << "\nstarting...";
fg_waitfor(18);
int oldmode=fg_getmode();
fg_setmode(videomode);
fg_mouseini();
do{
director[index]->display();
director[index]->take_over();
director[index]->hide();
index=find_director_index(director[index]->get_next_director());
} while (index>=0);
fg_mousefin();
fg_setmode(oldmode);
ns.shutdown();
MusicHand::shutdown();
VocalHand::shutdown();
hks.shutdown();
ts.shutdown();
}
Theatrix::~Theatrix()
{
while (kbhit())
getch();
fg_waitfor(9);
current_game = 0;
Hand::numhands=0;
}
int Theatrix::find_director_index(const Type_info& id)
{
static short int index = 0;
if (dcount == 0)
index = -1;
else
{
if (id == typeid(FirstDirector))
index = 0;
else if (id == typeid(LastDirector))
index = dcount-1;
else if (id == typeid(NextDirector))
{
if (++index == dcount)
index = -1;
}
else if (id == typeid(PrevDirector))
--index;
else if (id == typeid(StopDirector))
index = -1;
else
{
for (index=0; index < dcount; index++)
if (id==typeid(*director[index]))
break;
if (index == dcount)
index = -1;
}
}
return index;
}
const char dashedline[] =
"---------------------------------------------------------------------";
static void fatalhdr()
{
fg_kbinit(0);
fg_setmode(3);
cerr << dashedline << endl << " \aFatal Theatrix Error" << endl;
}
void Theatrix::system_shutdown()
{
MusicHand::shutdown();
VocalHand::shutdown();
if (Theatrix::current_game != 0)
{
Theatrix::current_game->hks.shutdown();
Theatrix::current_game->ts.shutdown();
}
exit(1);
}
void Theatrix::fatal(const char *reason)
{
fatalhdr();
cerr << " Reason: " << reason << endl;
system_shutdown();
}
void Theatrix::fatal(const char *reason, const char *fno, int lno)
{
fatalhdr();
cerr << " File: " << fno << endl
<< " Line: " << lno << endl
<< " Assertion: (" << reason << ')' << endl
<< dashedline;
system_shutdown();
}
void fatal(const char *reason, const char *fno, int lno)
{
Theatrix::fatal(reason,fno,lno);
}