Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 8, 2009, 9:17:40 PM (15 years ago)
Author:
scheusso
Message:

more advanced input for the dedicated server console

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp4/src/orxonox/gamestates/GSDedicated.cc

    r3119 r3121  
    4343#include <boost/bind.hpp>
    4444
     45#ifndef ORXONOX_PLATFORM_WINDOWS
     46#include <termios.h>
     47#endif
     48
    4549
    4650namespace orxonox
     
    4953   
    5054    AddGameState(GSDedicated, "dedicated");
     55   
     56    termios* GSDedicated::originalTerminalSettings_;
    5157
    5258    GSDedicated::GSDedicated(const std::string& name)
     
    6167        this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
    6268//         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
     69#ifndef ORXONOX_PLATFORM_WINDOWS
     70        this->originalTerminalSettings_ = new termios;
     71        this->setTerminalMode();
     72#endif
    6373    }
    6474
     
    6979        std::cout << "\033[0G\033[K";
    7080        std::cout.flush();
     81        resetTerminalMode();
     82        delete this->originalTerminalSettings_;
    7183#endif
    7284        //inputThread_->join();
     
    116128            c = getchar();
    117129            {
    118 //                 boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
     130                boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
    119131                if ( inputIterator_>=MAX_COMMAND_LENGTH-1 && c!='\n' )
    120132                    continue;
     
    125137                    boost::recursive_mutex::scoped_lock(this->inputQueueMutex_);
    126138                    this->commandQueue_.push( std::string((const char*)this->commandLine_,inputIterator_) );
     139                    memset( this->commandLine_, 0, inputIterator_ );
    127140                    inputIterator_ = 0;
    128141                }
     142                else if( c == 0x8 ) // Backspace
     143                {
     144                    boost::recursive_mutex::scoped_lock(this->inputQueueMutex_);
     145                    commandLine_[inputIterator_--]=0;
     146                }
    129147            }
    130148        }
     
    134152    {
    135153#ifndef ORXONOX_PLATFORM_WINDOWS
    136         std::cout << "\033[s\033[0G";
    137 //         boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
    138         std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";
    139         if ( this->cleanLine_ )
    140             this->cleanLine_ = false;
    141         else
    142             std::cout <<"\033[u";
     154//         std::cout << "\033[s\033[0G";
     155        std::cout << "\033[0G\033[K";
     156        boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
     157        std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # " << this->commandLine_;
     158        //if ( this->cleanLine_ )
     159        //    this->cleanLine_ = false;
     160        //else
     161        //    std::cout <<"\033[u";
    143162        std::cout.flush();
    144163#endif
     
    164183        }
    165184    }
     185   
     186    void GSDedicated::setTerminalMode()
     187    {
     188      termios new_settings;
     189     
     190      tcgetattr(0,this->originalTerminalSettings_);
     191      new_settings = *this->originalTerminalSettings_;
     192      new_settings.c_lflag &= (~ICANON);
     193      new_settings.c_cc[VTIME] = 0;
     194      new_settings.c_cc[VMIN] = 1;
     195      tcsetattr(0,TCSANOW,&new_settings);
     196      COUT(0) << endl;
     197      atexit(&GSDedicated::resetTerminalMode);
     198    }
     199   
     200    void GSDedicated::resetTerminalMode()
     201    {
     202#ifndef ORXONOX_PLATFORM_WINDOWS
     203      tcsetattr(0, TCSANOW, GSDedicated::originalTerminalSettings_);
     204#endif
     205    }
    166206}
Note: See TracChangeset for help on using the changeset viewer.