~evan-nelson/armagetronad/armagetronad+pcm

« back to all changes in this revision

Viewing changes to src/render/rConsoleCout.cpp

Attempting to create a timeout for PLAYER_CENTER_MESSAGE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
*************************************************************************
4
 
 
5
 
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
 
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7
 
 
8
 
**************************************************************************
9
 
 
10
 
This program is free software; you can redistribute it and/or
11
 
modify it under the terms of the GNU General Public License
12
 
as published by the Free Software Foundation; either version 2
13
 
of the License, or (at your option) any later version.
14
 
 
15
 
This program is distributed in the hope that it will be useful,
16
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
GNU General Public License for more details.
19
 
 
20
 
You should have received a copy of the GNU General Public License
21
 
along with this program; if not, write to the Free Software
22
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 
 
24
 
***************************************************************************
25
 
 
26
 
*/
27
 
 
28
 
#include "config.h"
29
 
#include "rConsole.h"
30
 
#include "rFont.h"
31
 
#include "tConfiguration.h"
32
 
 
33
 
#include <stdio.h>
34
 
#include <fcntl.h>
35
 
#include <sstream>
36
 
 
37
 
#if HAVE_UNISTD_H
38
 
#include <unistd.h>
39
 
#endif
40
 
#ifdef WIN32
41
 
#include <io.h>
42
 
#include <windows.h>
43
 
//#define fileno _fileno
44
 
//#define fcntl _fcntl
45
 
#else
46
 
#include <signal.h>
47
 
#endif
48
 
 
49
 
void rConsole::DoCenterDisplay(const tString &s,REAL timeout,REAL r,REAL g,REAL b){
50
 
    std::cout << tColoredString::RemoveColors(s) << '\n';
51
 
    DisplayAtNewline();
52
 
}
53
 
 
54
 
static int stdin_descriptor;
55
 
static bool unblocked = false;
56
 
 
57
 
static void sr_HandleSigCont( int signal )
58
 
{
59
 
    // con << "Continuing.\n";
60
 
 
61
 
    // unblock stdin again
62
 
    sr_Unblock_stdin();
63
 
}
64
 
 
65
 
void sr_Unblock_stdin(){
66
 
#ifndef WIN32
67
 
    if ( !unblocked )
68
 
    {
69
 
        signal( SIGCONT, &sr_HandleSigCont );
70
 
    }
71
 
#endif
72
 
 
73
 
    unblocked = true;
74
 
    stdin_descriptor=fileno(stdin);
75
 
#ifndef WIN32
76
 
    // if (isatty(stdin_descriptor))
77
 
    {
78
 
        int flag=fcntl(stdin_descriptor,F_GETFL);
79
 
        fcntl(stdin_descriptor,F_SETFL,flag | O_NONBLOCK);
80
 
    }
81
 
#endif
82
 
}
83
 
 
84
 
 
85
 
 
86
 
#define MAXLINE 1000
87
 
static char line_in[MAXLINE+2];
88
 
static int currentIn=0;
89
 
 
90
 
void sr_Read_stdin(){
91
 
    // stdin commands are executed at owner level
92
 
    tCurrentAccessLevel level( tAccessLevel_Owner, true );
93
 
 
94
 
    tConfItemBase::LoadPlayback( true );
95
 
 
96
 
    if ( !unblocked )
97
 
    {
98
 
        return;
99
 
    }
100
 
#ifdef WIN32
101
 
    //  std::cerr << "\n";
102
 
 
103
 
    HANDLE stdinhandle = GetStdHandle(STD_INPUT_HANDLE);
104
 
    HANDLE stdouthandle = GetStdHandle(STD_OUTPUT_HANDLE);
105
 
    bool goon = true;
106
 
    while (goon)
107
 
    {
108
 
        unsigned long reallyread;
109
 
        INPUT_RECORD input;
110
 
        bool ret=PeekConsoleInput(stdinhandle, &input, 1, &reallyread);
111
 
        if (reallyread > 0)
112
 
        {
113
 
            bool ret=ReadConsoleInput(stdinhandle, &input, 1, &reallyread);
114
 
            if (input.EventType == KEY_EVENT)
115
 
            {
116
 
                char key = input.Event.KeyEvent.uChar.AsciiChar;
117
 
                DWORD written=0;
118
 
 
119
 
                if (key && input.Event.KeyEvent.bKeyDown)
120
 
                {
121
 
                    WriteConsole(stdouthandle, &key, 1, &written, NULL);
122
 
                    line_in[currentIn] = key;
123
 
 
124
 
                    if (key == 13 || currentIn>=MAXLINE-1){
125
 
                        line_in[currentIn]='\n';
126
 
                        line_in[currentIn+1]='\0';
127
 
                        std::istringstream s(line_in);
128
 
                        WriteConsole(stdouthandle, "\n", 1, &written, NULL);
129
 
                        tConfItemBase::LoadAll(s, true);
130
 
                        currentIn=0;
131
 
                    }
132
 
                    else
133
 
                        currentIn++;
134
 
                }
135
 
            }
136
 
            //          bool ret=ReadFile(stdinhandle, &line_in[currentIn], 1, &reallyread, NULL);
137
 
        }
138
 
        else
139
 
            goon = false;
140
 
    }
141
 
 
142
 
 
143
 
#else
144
 
    while ( read(stdin_descriptor,&line_in[currentIn],1)>0){
145
 
        if (line_in[currentIn]=='\n' || currentIn>=MAXLINE-1)
146
 
        {
147
 
            line_in[currentIn+1]='\0';
148
 
            std::istringstream s(line_in);
149
 
            tConfItemBase::LoadAll(s, true);
150
 
            currentIn=0;
151
 
        }
152
 
        else
153
 
            currentIn++;
154
 
    }
155
 
#endif
156
 
}
157
 
 
158
 
 
159
 
void rConsole::DisplayAtNewline(){
160
 
}
161