- Converted the TTY startup screen to a class for Linux.

SVN r502 (trunk)
This commit is contained in:
Randy Heit 2007-03-10 01:53:52 +00:00
parent 802a6f3138
commit 453a6250a5
4 changed files with 156 additions and 125 deletions

View file

@ -1,3 +1,6 @@
March 9, 2007
- Converted the TTY startup screen to a class for Linux.
March 8, 2007 March 8, 2007
- Increased the limit for the SorcererBallPop to 3 to be inline with the - Increased the limit for the SorcererBallPop to 3 to be inline with the
other Heresiarch ball sounds. other Heresiarch ball sounds.

View file

@ -2406,6 +2406,53 @@ void D_DoomMain (void)
D_DoomLoop (); // never returns D_DoomLoop (); // never returns
} }
//==========================================================================
//
// FStartupScreen Constructor
//
//==========================================================================
FStartupScreen::FStartupScreen(int max_progress)
{
MaxPos = max_progress;
CurPos = 0;
NotchPos = 0;
}
//==========================================================================
//
// FStartupScreen Destructor
//
//==========================================================================
FStartupScreen::~FStartupScreen()
{
}
//==========================================================================
//
// FStartupScreen :: LoadingStatus
//
// Used by Heretic for the Loading Status "window."
//
//==========================================================================
void FStartupScreen::LoadingStatus(const char *message, int colors)
{
}
//==========================================================================
//
// FStartupScreen :: AppendStatusLine
//
// Used by Heretic for the "status line" at the bottom of the screen.
//
//==========================================================================
void FStartupScreen::AppendStatusLine(const char *status)
{
}
//========================================================================== //==========================================================================
// //
// STAT fps // STAT fps

View file

@ -47,100 +47,137 @@
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
class FTTYStartupScreen : public FStartupScreen
{
public:
FTTYStartupScreen(int max_progress);
~FTTYStartupScreen();
void Progress();
void NetInit(const char *message, int num_players);
void NetProgress(int count);
void NetMessage(const char *format, ...); // cover for printf
void NetDone();
bool NetLoop(bool (*timer_callback)(void *), void *userdata);
protected:
bool DidNetInit;
int NetMaxPos, NetCurPos;
const char *TheNetMessage;
termios OldTermIOS;
};
// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void ST_TTY_Done (); static void DeleteStartupScreen();
static void ST_TTY_Progress ();
static void ST_TTY_NetInit (const char *message, int numplayers);
static void ST_TTY_NetProgress (int count);
static void ST_TTY_NetMessage (const char *format, ...);
static void ST_TTY_NetDone ();
static bool ST_TTY_NetLoop (bool (*timer_callback)(void *), void *userdata);
static void ST_Null_HereticMessage (const char *, int);
static void ST_Null_HereticStatus (const char *);
// EXTERNAL DATA DECLARATIONS ---------------------------------------------- // EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS ------------------------------------------------- // PUBLIC DATA DEFINITIONS -------------------------------------------------
void (*ST_Done)(); FStartupScreen *StartScreen;
void (*ST_Progress)();
void (*ST_HereticMessage)(const char *message, int attributes); CUSTOM_CVAR(Int, showendoom, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
void (*ST_HereticStatus)(const char *status); {
void (*ST_NetInit)(const char *message, int numplayers); if (self < 0) self = 0;
void (*ST_NetProgress)(int count); else if (self > 2) self=2;
void (*ST_NetMessage)(const char *format, ...); }
void (*ST_NetDone)();
bool (*ST_NetLoop)(bool (*timer_callback)(void *), void *userdata);
// PRIVATE DATA DEFINITIONS ------------------------------------------------ // PRIVATE DATA DEFINITIONS ------------------------------------------------
static termios OldTermIOS; static const char SpinnyProgressChars[4] = { '|', '/', '-', '\\' };
static bool DidNetInit;
static int NetProgressMax, NetProgressTicker;
static const char *NetMessage;
static char SpinnyProgressChars[8] = { '|', '/', '-', '\\', '|', '/', '-', '\\' };
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
//==========================================================================
//
// FStartupScreen :: CreateInstance
//
// Initializes the startup screen for the detected game.
// Sets the size of the progress bar and displays the startup screen.
//
//==========================================================================
FStartupScreen *FStartupScreen::CreateInstance(int max_progress)
{
atterm(DeleteStartupScreen);
return new FTTYStartupScreen(max_progress);
}
//=========================================================================== //===========================================================================
// //
// ST_Init // DeleteStartupScreen
//
// Makes sure the startup screen has been deleted before quitting.
//
//===========================================================================
void DeleteStartupScreen()
{
if (StartScreen != NULL)
{
delete StartScreen;
StartScreen = NULL;
}
}
//===========================================================================
//
// FTTYStartupScreen Constructor
// //
// Sets the size of the progress bar and displays the startup screen. // Sets the size of the progress bar and displays the startup screen.
// //
//=========================================================================== //===========================================================================
void ST_Init(int maxProgress) FTTYStartupScreen::FTTYStartupScreen(int max_progress)
: FStartupScreen(max_progress)
{ {
ST_Done = ST_TTY_Done; DidNetInit = false;
ST_Progress = ST_TTY_Progress; NetMaxPos = 0;
ST_NetInit = ST_TTY_NetInit; NetCurPos = 0;
ST_NetProgress = ST_TTY_NetProgress; TheNetMessage = NULL;
ST_NetMessage = ST_TTY_NetMessage;
ST_NetDone = ST_TTY_NetDone;
ST_NetLoop = ST_TTY_NetLoop;
} }
//=========================================================================== //===========================================================================
// //
// ST_TTY_Done // FTTYStartupScreen Destructor
// //
// Called just before entering graphics mode to deconstruct the startup // Called just before entering graphics mode to deconstruct the startup
// screen. // screen.
// //
//=========================================================================== //===========================================================================
static void ST_TTY_Done() FTTYStartupScreen::~FTTYStartupScreen()
{
NetDone(); // Just in case it wasn't called yet and needs to be.
}
//===========================================================================
//
// FTTYStartupScreen :: Progress
//
// If there was a progress bar, this would move it. But the basic TTY
// startup screen doesn't have one, so this function does nothing.
//
//===========================================================================
void FTTYStartupScreen::Progress()
{ {
} }
//=========================================================================== //===========================================================================
// //
// ST_TTY_Progress // FTTYStartupScreen :: NetInit
//
// Bumps the progress meter one notch.
//
//===========================================================================
static void ST_TTY_Progress()
{
}
//===========================================================================
//
// ST_TTY_NetInit
// //
// Sets stdin for unbuffered I/O, displays the given message, and shows // Sets stdin for unbuffered I/O, displays the given message, and shows
// a progress meter. // a progress meter.
// //
//=========================================================================== //===========================================================================
static void ST_TTY_NetInit(const char *message, int numplayers) void FTTYStartupScreen::NetInit(const char *message, int numplayers)
{ {
if (!DidNetInit) if (!DidNetInit)
{ {
@ -154,7 +191,6 @@ static void ST_TTY_NetInit(const char *message, int numplayers)
rawtermios.c_lflag &= ~(ICANON | ECHO); rawtermios.c_lflag &= ~(ICANON | ECHO);
tcsetattr (STDIN_FILENO, TCSANOW, &rawtermios); tcsetattr (STDIN_FILENO, TCSANOW, &rawtermios);
DidNetInit = true; DidNetInit = true;
atterm (ST_NetDone);
} }
if (numplayers == 1) if (numplayers == 1)
{ {
@ -166,21 +202,21 @@ static void ST_TTY_NetInit(const char *message, int numplayers)
fprintf (stderr, "\n%s: ", message); fprintf (stderr, "\n%s: ", message);
} }
fflush (stderr); fflush (stderr);
NetMessage = message; TheNetMessage = message;
NetProgressMax = numplayers; NetMaxPos = numplayers;
NetProgressTicker = 0; NetCurPos = 0;
ST_NetProgress(1); // You always know about yourself NetProgress(1); // You always know about yourself
} }
//=========================================================================== //===========================================================================
// //
// ST_TTY_NetDone // FTTYStartupScreen :: NetDone
// //
// Restores the old stdin tty settings. // Restores the old stdin tty settings.
// //
//=========================================================================== //===========================================================================
static void ST_TTY_NetDone() void FTTYStartupScreen::NetDone()
{ {
// Restore stdin settings // Restore stdin settings
if (DidNetInit) if (DidNetInit)
@ -193,15 +229,15 @@ static void ST_TTY_NetDone()
//=========================================================================== //===========================================================================
// //
// ST_NetMessage // FTTYStartupScreen :: NetMessage
// //
// Call this between ST_NetInit() and ST_NetDone() instead of Printf() to // Call this between NetInit() and NetDone() instead of Printf() to
// display messages, because the progress meter is mixed in the same output // display messages, because the progress meter is mixed in the same output
// stream as normal messages. // stream as normal messages.
// //
//=========================================================================== //===========================================================================
static void ST_TTY_NetMessage(const char *format, ...) void FTTYStartupScreen::NetMessage(const char *format, ...)
{ {
FString str; FString str;
va_list argptr; va_list argptr;
@ -214,47 +250,47 @@ static void ST_TTY_NetMessage(const char *format, ...)
//=========================================================================== //===========================================================================
// //
// ST_NetProgress // FTTYStartupScreen :: NetProgress
// //
// Sets the network progress meter. If count is 0, it gets bumped by 1. // Sets the network progress meter. If count is 0, it gets bumped by 1.
// Otherwise, it is set to count. // Otherwise, it is set to count.
// //
//=========================================================================== //===========================================================================
static void ST_TTY_NetProgress(int count) void FTTYStartupScreen::NetProgress(int count)
{ {
int i; int i;
if (count == 0) if (count == 0)
{ {
NetProgressTicker++; NetCurPos++;
} }
else if (count > 0) else if (count > 0)
{ {
NetProgressTicker = count; NetCurPos = count;
} }
if (NetProgressMax == 0) if (NetMaxPos == 0)
{ {
// Spinny-type progress meter, because we're a guest waiting for the host. // Spinny-type progress meter, because we're a guest waiting for the host.
fprintf (stderr, "\r%s: %c", NetMessage, SpinnyProgressChars[NetProgressTicker & 7]); fprintf (stderr, "\r%s: %c", TheNetMessage, SpinnyProgressChars[NetCurPos & 3]);
fflush (stderr); fflush (stderr);
} }
else if (NetProgressMax > 1) else if (NetMaxPos > 1)
{ {
// Dotty-type progress meter. // Dotty-type progress meter.
fprintf (stderr, "\r%s: ", NetMessage); fprintf (stderr, "\r%s: ", TheNetMessage);
for (i = 0; i < NetProgressTicker; ++i) for (i = 0; i < NetCurPos; ++i)
{ {
fputc ('.', stderr); fputc ('.', stderr);
} }
fprintf (stderr, "%*c[%2d/%2d]", NetProgressMax + 1 - NetProgressTicker, ' ', NetProgressTicker, NetProgressMax); fprintf (stderr, "%*c[%2d/%2d]", NetMaxPos + 1 - NetCurPos, ' ', NetCurPos, NetMaxPos);
fflush (stderr); fflush (stderr);
} }
} }
//=========================================================================== //===========================================================================
// //
// ST_NetLoop // FTTYStartupScreen :: NetLoop
// //
// The timer_callback function is called at least two times per second // The timer_callback function is called at least two times per second
// and passed the userdata value. It should return true to stop the loop and // and passed the userdata value. It should return true to stop the loop and
@ -266,7 +302,7 @@ static void ST_TTY_NetProgress(int count)
// //
//=========================================================================== //===========================================================================
static bool ST_TTY_NetLoop(bool (*timer_callback)(void *), void *userdata) bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata)
{ {
fd_set rfds; fd_set rfds;
struct timeval tv; struct timeval tv;
@ -308,14 +344,6 @@ static bool ST_TTY_NetLoop(bool (*timer_callback)(void *), void *userdata)
} }
} }
static void ST_Null_HereticMessage (const char *, int)
{
}
static void ST_Null_HereticStatus (const char *)
{
}
void ST_Endoom() void ST_Endoom()
{ {
exit(0); exit(0);

View file

@ -335,53 +335,6 @@ FStartupScreen *FStartupScreen::CreateInstance(int max_progress)
return scr; return scr;
} }
//==========================================================================
//
// FStartupScreen Constructor
//
//==========================================================================
FStartupScreen::FStartupScreen(int max_progress)
{
MaxPos = max_progress;
CurPos = 0;
NotchPos = 0;
}
//==========================================================================
//
// FStartupScreen Destructor
//
//==========================================================================
FStartupScreen::~FStartupScreen()
{
}
//==========================================================================
//
// FStartupScreen :: LoadingStatus
//
// Used by Heretic for the Loading Status "window."
//
//==========================================================================
void FStartupScreen::LoadingStatus(const char *message, int colors)
{
}
//==========================================================================
//
// FStartupScreen :: AppendStatusLine
//
// Used by Heretic for the "status line" at the bottom of the screen.
//
//==========================================================================
void FStartupScreen::AppendStatusLine(const char *status)
{
}
//========================================================================== //==========================================================================
// //
// FBasicStartupScreen Constructor // FBasicStartupScreen Constructor