src/render/rConsoleCout.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "aa_config.h"
00029 #include "rConsole.h"
00030 #include "rFont.h"
00031 #include "tConfiguration.h"
00032 
00033 #include <stdio.h>
00034 #include <fcntl.h>
00035 #include <sstream>
00036 
00037 #if HAVE_UNISTD_H
00038 #include <unistd.h>
00039 #endif
00040 #ifdef WIN32
00041 #include <io.h>
00042 #include <windows.h>
00043 //#define fileno _fileno
00044 //#define fcntl _fcntl
00045 #else
00046 #include <signal.h>
00047 #endif
00048 
00049 void rConsole::DoCenterDisplay(const tString &s,REAL timeout,REAL r,REAL g,REAL b){
00050     std::cout << tColoredString::RemoveColors(s) << '\n';
00051     DisplayAtNewline();
00052 }
00053 
00054 static int stdin_descriptor;
00055 static bool unblocked = false;
00056 
00057 static void sr_HandleSigCont( int signal )
00058 {
00059     // con << "Continuing.\n";
00060 
00061     // unblock stdin again
00062     sr_Unblock_stdin();
00063 }
00064 
00065 void sr_Unblock_stdin(){
00066 #ifndef WIN32
00067     if ( !unblocked )
00068     {
00069         signal( SIGCONT, &sr_HandleSigCont );
00070     }
00071 #endif
00072 
00073     unblocked = true;
00074     stdin_descriptor=fileno(stdin);
00075 #ifndef WIN32
00076     // if (isatty(stdin_descriptor))
00077     {
00078         int flag=fcntl(stdin_descriptor,F_GETFL);
00079         fcntl(stdin_descriptor,F_SETFL,flag | O_NONBLOCK);
00080     }
00081 #endif
00082 }
00083 
00084 
00085 
00086 #define MAXLINE 1000
00087 static char line_in[MAXLINE+2];
00088 static int currentIn=0;
00089 
00090 void sr_Read_stdin(){
00091     tConfItemBase::LoadPlayback( true );
00092 
00093     if ( !unblocked )
00094     {
00095         return;
00096     }
00097 #ifdef WIN32
00098     //  std::cerr << "\n";
00099 
00100     HANDLE stdinhandle = GetStdHandle(STD_INPUT_HANDLE);
00101     HANDLE stdouthandle = GetStdHandle(STD_OUTPUT_HANDLE);
00102     bool goon = true;
00103     while (goon)
00104     {
00105         unsigned long reallyread;
00106         INPUT_RECORD input;
00107         PeekConsoleInput(stdinhandle, &input, 1, &reallyread);
00108         if (reallyread > 0)
00109         {
00110             ReadConsoleInput(stdinhandle, &input, 1, &reallyread);
00111             if (input.EventType == KEY_EVENT)
00112             {
00113                 char key = input.Event.KeyEvent.uChar.AsciiChar;
00114                 DWORD written=0;
00115 
00116                 if (key && input.Event.KeyEvent.bKeyDown)
00117                 {
00118                     WriteConsole(stdouthandle, &key, 1, &written, NULL);
00119                     line_in[currentIn] = key;
00120 
00121                     if (key == 13 || currentIn>=MAXLINE-1){
00122                         line_in[currentIn]='\n';
00123                         line_in[currentIn+1]='\0';
00124                         std::stringstream s(line_in);
00125                         WriteConsole(stdouthandle, "\n", 1, &written, NULL);
00126                         tConfItemBase::LoadAll(s);
00127                         currentIn=0;
00128                     }
00129                     else
00130                         currentIn++;
00131                 }
00132             }
00133             //          bool ret=ReadFile(stdinhandle, &line_in[currentIn], 1, &reallyread, NULL);
00134         }
00135         else
00136             goon = false;
00137     }
00138 
00139 
00140 #else
00141     while ( read(stdin_descriptor,&line_in[currentIn],1)>0){
00142         if (line_in[currentIn]=='\n' || currentIn>=MAXLINE-1)
00143         {
00144             line_in[currentIn+1]='\0';
00145             std::stringstream s(line_in);
00146             tConfItemBase::LoadAll(s);
00147             currentIn=0;
00148         }
00149         else
00150             currentIn++;
00151     }
00152 #endif
00153 }
00154 
00155 
00156 void rConsole::DisplayAtNewline(){
00157 }
00158 

Generated on Sat Mar 15 22:55:52 2008 for Armagetron Advanced by  doxygen 1.5.4