Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

# ExManagerConsole.cpp

Aller à la documentation de ce fichier.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020  * $Id: ExManagerConsole.cpp,v 1.43 2002/12/13 11:45:00 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExManagerConsole.h"
    00025
    00026 bool ExManagerConsole::m_flag = false;
    00027 ExManagerConsole* ExManagerConsole::m_instance = NULL;
    00028
    00029 ExManagerConsole* ExManagerConsole::CreateSingleton(void){
    00030 Guard(ExManagerConsole* ExManagerConsole::CreateSingleton(void))
    00031         if(!m_flag)
    00032         {
    00033                 m_flag = true; // We are creating the error log now, so set flag to true
    00034                 m_instance = new ExManagerConsole; // Create the error log
    00035         }else
    00036         {
    00037                 std::cout<<"Error singleton already created"<<std::endl;
    00038         }
    00039         return m_instance;
    00040 UnGuard
    00041 }
    00042
    00043 ExManagerConsole::ExManagerConsole(void)
    00044 {
    00045 Guard(ExManagerConsole::ExManagerConsole(void))
    00046         m_ConsoleState=HIDE;
    00047         m_LineCounter=2;
    00048         PosIntoBuffOldCommand=0;
    00049         m_ConsoleTransPalier=20;
    00050         m_fBlending=0.3f;
    00051         m_fBackGroundBlue=1.0f;
    00052         m_fBackGroundRed=1.0f;
    00053         m_fBackGroundGreen=1.0f;
    00054         console_move = false;
    00055         m_BackGroundTextureState=true;
    00056         m_Blending = false;
    00057         LogConsol =true;
    00058         m_AskForCommand=true;
    00059         m_Move=0;
    00060         #ifdef UNIX_SRC
    00061         logfilecsl.open("/tmp/logConsol.txt",std::ios::out);
    00062         #else
    00063         logfilecsl.open("logConsol.txt",std::ios::out);
    00064         #endif
    00065         logfilecsl.close();
    00066         SetStatus(false);
    00067         SetAskForCommand(false);
    00068         SetAskForExclusifCommand(false);
    00069
    00070         TabTextures[0]=0;
    00071         TabTextures[2]=0;TabTextures[3]=0;
    00072         TabTextures[4]=1;TabTextures[5]=0;
    00073         TabTextures[6]=1;
    00074
    00075         TabVertices[0]=0;TabVertices[1]=0;
    00076         TabVertices[2]=0;
    00077         TabVertices[7]=0;
    00078
    00079 UnGuard
    00080 }
    00081
    00082
    00083 void ExManagerConsole::Reset(void)
    00084 {
    00085 Guard(ExManagerConsole::Reset(void))
    00086         m_ConsoleState=HIDE;
    00087         m_LineCounter=2;
    00088         PosIntoBuffOldCommand=0;
    00089         m_ConsoleTransPalier=20;
    00090         //m_BufferConsol.clear();
    00091         m_VecStringAction.clear();
    00092 //      SetConsoleBackGroudTexture("back2.tga");
    00093         console_move = false;
    00094 UnGuard
    00095 }
    00096
    00097 ExManagerConsole::~ExManagerConsole(void)
    00098 {
    00099 Guard(ExManagerConsole::~ExManagerConsole(void))
    00100 UnGuard
    00101 }
    00102
    00103 void ExManagerConsole::Init(void)
    00104 {
    00105 Guard(void ExManagerConsole::init(void))
    00106         SetConsoleBackGroudTexture("back");
    00107 UnGuard
    00108 }
    00109
    00110
    00111 void ExManagerConsole::SetConsoleBackGroudTexture(std::string   FileName)
    00112 {
    00113 Guard(void ExManagerConsole::SetConsoleBackGroudTexture(std::string     FileName))
    00114         if(ManagerTexture->Add(FileName))
    00115         {
    00116                 m_BackGroundTexture=FileName;
    00117         }
    00118
    00119 UnGuard
    00120 }
    00121 void ExManagerConsole::Draw(void)
    00122 {
    00123 Guard(void ExManagerConsole::Draw(void))
    00124         if(!GetStatus())return;
    00125         int i=0;
    00126         float   textcoordy=0;
    00127         float   cordy=0;
    00128         char buffer[80];
    00129         sprintf(buffer,"version %s ",VERSION);
    00130
    00131
    00132
    00133         switch(m_ConsoleState)
    00134         {
    00135         case HIDE:
    00136                 SetStatus(false);
    00137                 break;
    00138
    00139         case HALF:
    00140                 textcoordy=0.5f;
    00141                 cordy=ManagerWindow->GetResolutionY()/2;
    00142                 break;
    00143
    00144         case FULL:
    00145                 textcoordy=1.0f;
    00146                 cordy=ManagerWindow->GetResolutionY();
    00147                 break;
    00148
    00149         case HIDETOHALF:
    00150                 //cout<<"Draw hide to half "<<endl;
    00151                 textcoordy=(1.0f/m_ConsoleTransPalier)*m_ConsoleTrans;
    00152                 cordy=(ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans;
    00153                 m_ConsoleTrans++;
    00154                 if(cordy>((ManagerWindow->GetResolutionY()/2)-(ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)))
    00155                 {
    00156                         m_ConsoleState=m_NextConsoleState;
    00157                 }
    00158                 break;
    00159
    00160         case HIDETOFULL:
    00161                 //cout<<"Draw hide to full "<<endl;
    00162                 textcoordy=((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
    00163                 cordy=(ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans;
    00164                 m_ConsoleTrans++;
    00165                 if(cordy>(ManagerWindow->GetResolutionY()))
    00166                 {
    00167                         m_ConsoleState=m_NextConsoleState;
    00168                 }
    00169                 break;
    00170
    00171         case HALFTOFULL:
    00172                 //cout<<"Draw half to full"<<endl;
    00173                 textcoordy=((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans)+0.5f;
    00174                 cordy=((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans)+ManagerWindow->GetResolutionY()/2;
    00175                 m_ConsoleTrans++;
    00176                 if(cordy>(ManagerWindow->GetResolutionY()))
    00177                 {
    00178                         m_ConsoleState=m_NextConsoleState;
    00179                 }
    00180                 break;
    00181
    00182         case FULLTOHIDE:
    00183                 //cout<<"Draw full to hide"<<endl;
    00184                 textcoordy=1.0f-((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
    00185                 cordy=ManagerWindow->GetResolutionY()-((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans);
    00186                 m_ConsoleTrans++;
    00187                 if(cordy<0)
    00188                 {
    00189                         m_ConsoleState=m_NextConsoleState;
    00190                 }
    00191                 break;
    00192
    00193         case FULLTOHALF:
    00194                 //cout<<"Draw full to half"<<endl;
    00195                 textcoordy=1.0f-((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
    00196                 cordy=(ManagerWindow->GetResolutionY())-((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans);
    00197                 m_ConsoleTrans++;
    00198                 if(cordy<ManagerWindow->GetResolutionY()/2)
    00199                 {
    00200                         m_ConsoleState=m_NextConsoleState;
    00201                 }
    00202                 break;
    00203
    00204         case HALFTOHIDE:
    00205                 //cout<<"Draw half to hide"<<endl;
    00206                 textcoordy=0.5f-((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
    00207                 cordy=(ManagerWindow->GetResolutionY()/2)-((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans);
    00208                 m_ConsoleTrans++;
    00209                 if(cordy<0)
    00210                 {
    00211                         m_ConsoleState=m_NextConsoleState;
    00212                 }
    00213                 break;
    00214         }
    00215         //-------------------
    00216         //Draw back console
    00217         //-------------------
    00218         if(m_Move>0)LineUp();
    00219         if(m_Move<0)LineDown();
    00220
    00221         ExNihilo::EnterOrthoMode();
    00222         glPushAttrib(GL_ALL_ATTRIB_BITS);
    00223         if(m_BackGroundTextureState)glEnable(GL_TEXTURE_2D);
    00224         glDisable(GL_LIGHTING);
    00225         glDisable(GL_DEPTH_TEST);
    00226         ManagerTexture->SetCurrentObject(m_BackGroundTexture);
    00227         if(m_Blending)
    00228         {
    00229                 glColor4f(m_fBackGroundRed,m_fBackGroundGreen,m_fBackGroundBlue,m_fBlending);
    00230                 glEnable(GL_BLEND);
    00231                 glEnable(GL_ALPHA);
    00232                 glBlendFunc(GL_ONE,GL_ONE);
    00233                 glEnable(GL_ALPHA_TEST);
    00234                 glAlphaFunc(GL_GREATER,0);
    00235                 glDisable(GL_LIGHTING);
    00236         }else
    00237         {
    00238                 glColor4f(1,1,1,1);
    00239         }
    00240
    00241         TabTextures[1]=textcoordy;
    00242         TabTextures[7]=textcoordy;
    00243
    00244
    00245         TabVertices[3]=cordy;
    00246         TabVertices[4]=ManagerWindow->GetResolutionX();
    00247         TabVertices[5]=cordy;
    00248         TabVertices[6]=ManagerWindow->GetResolutionX();
    00249
    00250                 glMatrixMode(GL_TEXTURE);
    00251                         glTranslatef(0.0f,-0.0001*glutGet(GLUT_ELAPSED_TIME),0.0f);
    00252                 glMatrixMode(GL_MODELVIEW);
    00253                 ManagerTexture->SetTexture(0,"back3");
    00254                 glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
    00255                 ManagerTexture->SetTexture(1,m_BackGroundTexture);
    00256                 glTexCoordPointer(2,GL_FLOAT,0,TabTextures);
    00257
    00258                 glEnableClientState(GL_VERTEX_ARRAY);
    00259                 glVertexPointer(2,GL_FLOAT,0,TabVertices);
    00260                 glDrawArrays( GL_QUADS, 0, 4 );
    00261                 ManagerTexture->ResetMultitexture();
    00262                 glMatrixMode(GL_TEXTURE);
    00263                 glLoadIdentity();
    00264                 glMatrixMode(GL_MODELVIEW);
    00265         glPopAttrib();
    00266
    00267     //-------------------
    00268         //Draw credits
    00269         //-------------------
    00270         glColor4f(0,0,1,1);
    00271
    00272         ExNihilo::RenderBitmapString(ManagerWindow->GetResolutionX()-160,cordy-40,GLUT_BITMAP_8_BY_13,"ExNihilo Engine ");
    00273         ExNihilo::RenderBitmapString(ManagerWindow->GetResolutionX()-160,cordy-30,GLUT_BITMAP_8_BY_13,buffer);
    00274         ExNihilo::RenderBitmapString(ManagerWindow->GetResolutionX()-160,cordy-20,GLUT_BITMAP_8_BY_13,"Plok Software");
    00275         //-------------------
    00276         //Draw buffer console
    00277         //-------------------
    00278         glColor3f(0.5,0,0);
    00279
    00280         UpdateConsolBuffer();
    00281
    00282
    00283         for(i=0,m_RItBufferConsol=m_BufferConsol.rbegin();i<m_LineToStar;i++)
    00284         {
    00285                 m_RItBufferConsol++;
    00286         }
    00287
    00288         for(i=0;m_RItBufferConsol!=m_BufferConsol.rend();m_RItBufferConsol++,i++)
    00289         {
    00290                 ExNihilo::RenderBitmapString(10,cordy-(10*i)-20,GLUT_BITMAP_8_BY_13,m_RItBufferConsol->data());
    00291                 if(i*10>cordy)break;
    00292         }
    00293
    00294         m_BufferConsol.clear();
    00295
    00296         //--------------------
    00297         //Draw Current Command
    00298         //--------------------
    00299         ExNihilo::RenderBitmapString(10,cordy-10,GLUT_BITMAP_8_BY_13,"]"+m_BuffCommand);
    00300
    00301         glEnable(GL_DEPTH_TEST);
    00302         glEnable(GL_LIGHTING);
    00303         glDisable(GL_TEXTURE_2D);
    00304
    00305         ExNihilo::LeaveOrthoMode();
    00306
    00307         if (m_ConsoleState == m_NextConsoleState && console_move == true) {
    00308                 console_move = false;
    00309         }
    00310
    00311         //DrawBuffer();
    00312 UnGuard
    00313 }
    00314 void ExManagerConsole::UpdateConsolBuffer(void)
    00315 {
    00316 Guard(void ExManagerConsole::UpdateConsolBuffer(void))
    00317         std::string             bufferstring,bufferstring2;
    00318         bufferstring=Consol->rdbuf( )->str();
    00319         Consol->freeze(false);
    00320         Consol->clear();
    00321         Consol->flush();
    00322         //m_BufferConsol.push_back(bufferstring);
    00323
    00324
    00325         m_LineInConsol=0;
    00326         do
    00327         {
    00328                 bufferstring2 = bufferstring.substr(0,bufferstring.find ( "\n" ,0));
    00329                 bufferstring.erase(0,bufferstring.find ( "\n" ,0)+1);
    00330                 do
    00331                 {
    00332                         if(bufferstring2.size()>(unsigned)(ManagerWindow->GetResolutionX()/8)-1)
    00333                         {
    00334                                 m_BufferConsol.push_back(bufferstring2.substr(0,((int)(ManagerWindow->GetResolutionX()/8))-1));
    00335                                 bufferstring2=bufferstring2.substr(((int)(ManagerWindow->GetResolutionX()/8))-1,bufferstring2.size());
    00336                                 m_LineInConsol++;
    00337             }else
    00338                         {
    00339                                 m_BufferConsol.push_back(bufferstring2);
    00340                                 m_LineInConsol++;
    00341                                 break;
    00342                         }
    00343                 }while(1);
    00344         }while((unsigned)-1 != bufferstring.find( "\n" ,0));
    00345
    00346         //-------------------
    00347         //Save Consol Flux
    00348         //-------------------
    00349
    00350         if(LogConsol=true)
    00351         {
    00352                 logfilecsl.open("logConsol.txt",std::ios::out);
    00353                 int i=0;
    00354                 for(m_ItBufferConsol=m_BufferConsol.begin();m_ItBufferConsol!=m_BufferConsol.end();m_ItBufferConsol++,i++)
    00355                 {
    00356                         logfilecsl<<i<<"::"<<m_ItBufferConsol->data()<<std::endl;
    00357                 }
    00358                 //logfilecsl.close();
    00359         }
    00360 UnGuard
    00361 }
    00362
    00363 void ExManagerConsole::LineUp(void)
    00364 {
    00365         m_LineToStar++;
    00366         if(m_LineToStar>m_LineInConsol)m_LineToStar=m_LineInConsol;
    00367 }
    00368 void ExManagerConsole::LineDown(void)
    00369 {
    00370         m_LineToStar--;
    00371         if(m_LineToStar<0){m_LineToStar=0;}
    00372 }
    00373
    00374 void ExManagerConsole::ConsoleMove (bool p) {
    00375         console_move = p;
    00376 }
    00377
    00378 void ExManagerConsole::SetConsoleState(int state)
    00379 {
    00380 Guard(void ExManagerConsole::SetConsoleState(int state))
    00381         //cout<<"set console state :"<<state<<endl;
    00382         SetStatus(true);
    00383         switch(m_ConsoleState)
    00384         {
    00385         case HIDE:
    00386                 m_NextConsoleState=state;
    00387                 switch(state)
    00388                 {
    00389                 case HALF:
    00390                         m_ConsoleState=HIDETOHALF;
    00391                         break;
    00392                 case FULL:
    00393                         m_ConsoleState=HIDETOFULL;
    00394                         break;
    00395                 }
    00396                 break;
    00397         case HALF:
    00398                 m_NextConsoleState=state;
    00399                 switch(state)
    00400                 {
    00401                 case FULL:
    00402                         m_ConsoleState=HALFTOFULL;
    00403                         break;
    00404                 case HIDE:
    00405                         m_ConsoleState=HALFTOHIDE;
    00406                         break;
    00407                 }
    00408                 break;
    00409         case FULL:
    00410                 m_NextConsoleState=state;
    00411                 switch(state)
    00412                 {
    00413                 case HALF:
    00414                         m_ConsoleState=FULLTOHALF;
    00415                         break;
    00416                 case HIDE:
    00417                         m_ConsoleState=FULLTOHIDE;
    00418                         break;
    00419                 }
    00420                 break;
    00421         }
    00422         m_ConsoleTrans=1;
    00423 UnGuard
    00424 }
    00425
    00426 int ExManagerConsole::NextAviableState(void) {
    00427 Guard(int ExManagerConsole::NextAviableState(void))
    00428         switch(m_ConsoleState) {
    00429                 case HIDE: return HALF;
    00430                 case HALF: return FULL;
    00431                 case FULL: return HIDE;
    00432                 case HIDETOHALF : return HALF;
    00433                 case HIDETOFULL : return FULL;
    00434                 case HALFTOFULL : return FULL;
    00435                 case FULLTOHALF : return HALF;
    00436                 case FULLTOHIDE : return HIDE;
    00437                 case HALFTOHIDE : return HIDE;
    00438                 default: return HALF;
    00439         }
    00440 UnGuard
    00441 }
    00442
    00443 void ExManagerConsole::Write(const char *Label)
    00444 {
    00445 Guard(void ExManagerConsole::Write(const char *Label))
    00446         //*Consol<<"<<==================Write to consol===========================>>"<<std::endl;
    00447         *Consol << Label << std::endl;
    00448         //*Consol<<"<<============================================================>>"<<std::endl;
    00449 UnGuard
    00450 }
    00451
    00452 ExCAction ExManagerConsole::InputCommand(ExCCommand Command)
    00453 {
    00454 Guard(ExCAction ExManagerConsole::InputCommand(ExCCommand Command))
    00455         //std::cout<<"ManagerConsol::Input Command consol:"<<Command.m_Command<<std::endl;
    00456         switch(Command.m_Command)
    00457         {
    00458         case KEYBOARD_DOWN_EXP:
    00459                 InputAction(CONSOL_NEXT_AVIABLE_STATE);
    00460                 return NOTHING;
    00461
    00462         case KEYBOARD_DOWN_ESC:
    00463                 InputAction(HIDE_CONSOL);
    00464                 return NOTHING;
    00465
    00466         case KEYBOARD_DOWN_PAGE_UP:
    00467                 m_Move=-1;
    00468                 return NOTHING;
    00469
    00470         case KEYBOARD_DOWN_PAGE_DOWN:
    00471                 m_Move=1;
    00472                 return NOTHING;
    00473
    00474         case KEYBOARD_UP_PAGE_UP:
    00475                 m_Move=0;
    00476                 return NOTHING;
    00477
    00478         case KEYBOARD_UP_PAGE_DOWN:
    00479                 m_Move=0;
    00480                 return NOTHING;
    00481
    00482         case KEYBOARD_DOWN_SPACE:
    00483                 m_BuffCommand.append(" ");
    00484                 return NOTHING;
    00485
    00486         case KEYBOARD_DOWN_ENTER:
    00487                 return ApplyBuffCommand();
    00488
    00489         case KEYBOARD_DOWN_TAB: {
    00490                 std::vector<std::string> vec_tmp;
    00491                 std::vector<std::string>::iterator i_tmp;
    00492
    00493                 vec_tmp.push_back ("load");
    00494                 vec_tmp.push_back ("cmd");
    00495                 vec_tmp.push_back ("help");
    00496                 vec_tmp.push_back ("clear");
    00497                 vec_tmp.push_back ("quit");
    00498
    00499                 for (m_ItVecStringAction = m_VecStringAction.begin(); m_ItVecStringAction != m_VecStringAction.end(); m_ItVecStringAction++) {
    00500                         vec_tmp.push_back (m_ItVecStringAction->first);
    00501                 }
    00502
    00503                 i_tmp = vec_tmp.begin ();
    00504                 std::string tmp;
    00505
    00506                 while (i_tmp != vec_tmp.end ()) {
    00507                         tmp = *i_tmp++;
    00508
    00509                         if (tmp.find (m_BuffCommand) == 0) {
    00510                                 if (tmp.find (' ') < tmp.length ())
    00511                                         m_BuffCommand = tmp.substr (0, tmp.find (' '));
    00512                                 else m_BuffCommand = tmp;
    00513                                 //m_BuffCommand += ' '; // this add a space after command
    00514                                 // but it sucks with some commands like quit :/
    00515                         }
    00516                 }
    00517                 return NOTHING;
    00518         }
    00519
    00520         case KEYBOARD_UP_ARROW_DOWN:
    00521                 PosIntoBuffOldCommand++;
    00522                 if(PosIntoBuffOldCommand<(int)m_BuffOldCommand.size()&&PosIntoBuffOldCommand>=-1)
    00523                 {
    00524                         m_BuffCommand=m_BuffOldCommand.at(PosIntoBuffOldCommand);
    00525                 }else
    00526                 {
    00527                         PosIntoBuffOldCommand=0;
    00528                 }
    00529
    00530
    00531                 return NOTHING;
    00532
    00533         case KEYBOARD_UP_ARROW_UP:
    00534                 PosIntoBuffOldCommand--;
    00535                 if(PosIntoBuffOldCommand<(int)m_BuffOldCommand.size()&&PosIntoBuffOldCommand>=0)
    00536                 {
    00537                         m_BuffCommand=m_BuffOldCommand.at(PosIntoBuffOldCommand);
    00538                 }else
    00539                 {
    00540                         PosIntoBuffOldCommand=0;
    00541                 }
    00542                 return NOTHING;
    00543
    00544         case KEYBOARD_UP_ARROW_LEFT:
    00545                 if(m_BuffCommand.size()>0)
    00546                 {
    00547                         m_BuffCommand.erase(m_BuffCommand.end()-1,m_BuffCommand.end());
    00548                 }
    00549                 return NOTHING;
    00550
    00551         case KEYBOARD_UP_BACKSPACE:
    00552                 if(m_BuffCommand.size()>0)
    00553                 {
    00554                         m_BuffCommand.erase(m_BuffCommand.end()-1,m_BuffCommand.end());
    00555                 }
    00556                 return NOTHING;
    00557         }
    00558         ExNihilo::AddKeyToBuffer(Command.m_Command,m_BuffCommand);
    00559         return NOTHING;
    00560 UnGuard
    00561 }
    00562
    00563 void ExManagerConsole::ListConsoleCommand(void)
    00564 {
    00565 Guard(void ExManagerConsole::ListConsoleCommand(void))
    00566         *Consol<<"*******************************"<<std::endl;
    00567         *Consol<<"*List of all available command*"<<std::endl;
    00568         *Consol<<"*******************************"<<std::endl;
    00569         *Consol<<"load 'FILENAME'"<<std::endl;
    00570         *Consol<<"cmd 'number of command'"<<std::endl;;
    00571         *Consol<<"help 'command'"<<std::endl;
    00572         *Consol<<"clear 'clear console screen'"<<std::endl;
    00573         *Consol<<"Extension ' List aviable Extension'"<<std::endl;
    00574         *Consol<<"quit 'exit ExNihilo'"<<std::endl;
    00575         int i=PREDIFINEDCOMMAND;
    00576         for(m_ItVecStringAction=m_VecStringAction.begin(); m_ItVecStringAction != m_VecStringAction.end(); m_ItVecStringAction++, i++)
    00577         {
    00578                 *Consol<<m_ItVecStringAction->first.data()<<std::endl;
    00579         }
    00580         *Consol<<"*****************************"<<std::endl;
    00581 UnGuard
    00582 }
    00583
    00584 ExCAction ExManagerConsole::ApplyBuffCommand(void)
    00585 {
    00586 Guard(ExCAction ExManagerConsole::ApplyBuffCommand(void))
    00587 bool findaction=false;
    00588         ExCAction Action;
    00589         Action.m_StartingLife=(double)((double)glutGet(GLUT_ELAPSED_TIME)/1000);
    00590         *Consol<<m_BuffCommand.data()<<std::endl;
    00591         for(m_ItVecStringAction=m_VecStringAction.begin();m_ItVecStringAction!=m_VecStringAction.end();m_ItVecStringAction++)
    00592         {
    00593                 if(m_BuffCommand.find(m_ItVecStringAction->first.data())==0)
    00594                 {
    00595                         findaction=true;
    00596                         char buffer[255];
    00597                         memset(buffer,0,255);
    00598                         Action.m_Action=m_ItVecStringAction->second;
    00599                         m_BuffCommand.copy(buffer,(m_BuffCommand.size())-(strlen(m_ItVecStringAction->first.data())),strlen(m_ItVecStringAction->first.data()));
    00600                         Action.SetParam(buffer);
    00601                         m_BuffOldCommand.push_back(m_BuffCommand);
    00602                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00603                 }
    00604         }
    00605         if(!findaction)
    00606         {
    00607                 if(strcmp(m_BuffCommand.data(),"clear")==0)
    00608                 {
    00609                         m_BuffOldCommand.push_back(m_BuffCommand);
    00610                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00611                         m_BufferConsol.clear();
    00612                         ClearConsol();
    00613                         Action.m_Action= NOTHING;
    00614                         return Action;
    00615                 }
    00616
    00617                 if(m_BuffCommand.find("help")==0)
    00618                 {
    00619                         ListConsoleCommand();
    00620                         m_BuffOldCommand.push_back(m_BuffCommand);
    00621                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00622                         Action.m_Action= NOTHING;
    00623                         return Action;
    00624                 }
    00625                 if(m_BuffCommand.find("Extension")==0)
    00626                 {
    00627                         *Consol<<"Extension      :"<<glGetString(GL_EXTENSIONS)<<std::endl;
    00628                         m_BuffOldCommand.push_back(m_BuffCommand);
    00629                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00630                         Action.m_Action= NOTHING;
    00631                         return Action;
    00632                 }
    00633                 if(m_BuffCommand.find("cmd ")==0)
    00634                 {
    00635                         int cmd=0;
    00636                         char *SBuffer;
    00637                         SBuffer=new char[strlen(m_BuffCommand.data())-5] ;
    00638                         memset(SBuffer,0,strlen(m_BuffCommand.data()));
    00639                         m_BuffCommand.copy(SBuffer,m_BuffCommand.size()-4,4);
    00640                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00641                         try
    00642                         {
    00643                                 cmd=atoi(SBuffer);
    00644                                 Action.m_Action= m_VecStringAction.at(cmd-PREDIFINEDCOMMAND).second;
    00645                         }catch(...)
    00646                         {
    00647                                 *Consol<<"Bad argument use list to show command list"<<std::endl;
    00648                                 Action.m_Action= NOTHING;
    00649                                 return Action;
    00650                         }
    00651                 }
    00652
    00653                 if(m_BuffCommand.find("run ")==0)
    00654                 {
    00655                         // stay ton fin space between each param and put it into action
    00656                         if (m_BuffCommand.size()<5)
    00657                         {
    00658                                 *Consol<<"run command need one argument"<<std::endl;
    00659                         }
    00660                         try
    00661                         {
    00662                                 char *SBuffer;
    00663                                 SBuffer=new char[strlen(m_BuffCommand.data())-4] ;
    00664                                 m_BuffCommand.copy(SBuffer,m_BuffCommand.size()-4,m_BuffCommand.find("run ")+4);
    00665                                 Action.m_Action= atoi(SBuffer);
    00666                         }catch(...){Action.m_Action= NOTHING;}
    00667                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00668                         return Action;
    00669                 }
    00670
    00671                 if(strcmp(m_BuffCommand.data(),"quit")==0)
    00672                 {
    00673                         m_BuffOldCommand.push_back(m_BuffCommand);
    00674                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00675                         Action.m_Action= QUIT;
    00676                         return Action;
    00677                 }
    00678
    00679                 if(strcmp(m_BuffCommand.data(),"reset")==0)
    00680                 {
    00681                         m_BuffOldCommand.push_back(m_BuffCommand);
    00682                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00683                         Action.m_Action= RESET;
    00684                         return Action;
    00685                 }
    00686
    00687                 if(m_BuffCommand.find("load")!=(unsigned)-1)
    00688                 {
    00689                         char buffer[255];
    00690                         memset(buffer,0,255);
    00691                         Action.m_Action=LOAD_FILE;
    00692                         m_BuffCommand.copy(buffer,m_BuffCommand.size()-4,4);
    00693                         Action.SetParam(buffer);
    00694                         m_BuffOldCommand.push_back(m_BuffCommand);
    00695                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00696                         return Action;
    00697                 }
    00698
    00699                 *Consol<<"Unknow command"<<std::endl;
    00700                 m_BuffOldCommand.push_back(m_BuffCommand);
    00701                 m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00702                 Action.m_Action= NOTHING;
    00703         }
    00704         return Action;
    00705 UnGuard
    00706 }
    00707
    00708 void ExManagerConsole::AddStringAction(std::string String,int Action)
    00709 {
    00710 Guard(void ExManagerConsole::AddStringAction(std::string String,int Action))
    00711         StringAction ac;
    00712         ac.first=String;
    00713         ac.second=Action;
    00714         m_VecStringAction.push_back(ac);
    00715         *Consol<<"Add new command to console command:"<<String<<" Action:"<<Action<<std::endl;
    00716 UnGuard
    00717 }
    00718
    00719 void ExManagerConsole::AddStringAction(StringAction StrAction)
    00720 {
    00721 Guard(void ExManagerConsole::AddStringAction(StringAction StrAction))
    00722         AddStringAction(StrAction.first.data(),StrAction.second);
    00723 UnGuard
    00724 }
    00725
    00726 void ExManagerConsole::LoadStringActionFile(const char *FileName)
    00727 {
    00728 Guard(void ExManagerConsole::LoadStringActionFile(const char *FileName))
    00729     char                        buffer[255];
    00730
    00731 #ifdef UNIX_SRC
    00732         sprintf(buffer, PREFIX "/ExNihilo/Data/Console/%s", FileName);
    00733 #else
    00734         sprintf(buffer, "../Data/Console/%s", FileName);
    00735 #endif
    00736         StringAction BuffStringAction;
    00737         std::ifstream fin;
    00738         std::string buffstring;
    00739         char b[256];
    00740         fin.open(buffer,std::ios::in);
    00741         if(fin.is_open())
    00742         {
    00743                 try
    00744                 {
    00745                         do
    00746                         {
    00747                                 memset(b,0,255);
    00748                                 fin.getline(b,256,'\n');
    00749                                 try
    00750                                 {
    00751                                         buffstring=ExNihilo::ExtracValueFromSring(b,"<consolcommand>","<#consolcommand>");
    00752                                         AddStringAction(ExNihilo::ExtracValueFromSring(buffstring,"<string>","<#string>")
    00753                                                 ,ExNihilo::ExtractIntValueFromSring(buffstring,"<action>","<#action>"));
    00754                                 }catch(ExCExpStringNotFound){}
    00755                         }while(!fin.eof());
    00756                         fin.close();
    00757                 }catch(...){throw ExCExpFileReadError();}
    00758         }else throw   ExCExpFileNotFound();
    00759 UnGuard
    00760 }
    00761
    00762 void ExManagerConsole::ClearConsol(void)
    00763 {
    00764 Guard(void ExManagerConsole::ClearConsol(void))
    00765         m_BuffOldCommand.push_back(m_BuffCommand);
    00766         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
    00767         m_BufferConsol.clear();
    00768 UnGuard
    00769 }
    00770
    00771
    00772 ExCAction ExManagerConsole::InputAction(ExCAction Action)
    00773 {
    00774 Guard(ExCAction ExManagerConsole::InputAction(ExCAction Action))
    00775         //std::cout<<"ManagerConsol::Input action :"<<Action<<std::endl;
    00776         switch(Action.m_Action)
    00777         {
    00778         case CONSOL_LINE_UP:LineUp();break;
    00779         case CONSOL_LINE_DOWN:LineDown();break;
    00780     case SHOW_HALF_CONSOL:
    00781                 if (!isConsoleMove ())
    00782                 {
    00783                         ConsoleMove (true);
    00784                         SetStatus(true);
    00785                         SetAskForCommand(true);
    00786                         SetAskForExclusifCommand(true);
    00787                         SetConsoleState(HALF);
    00788                 }
    00789                 break;
    00790         case SHOW_FULL_CONSOL:
    00791                 if (!isConsoleMove ())
    00792                 {
    00793                         ConsoleMove (true);
    00794                         SetStatus(true);
    00795                         SetAskForCommand(true);
    00796                         SetAskForExclusifCommand(true);
    00797                         SetConsoleState(FULL);
    00798                 }
    00799                 break;
    00800         case HIDE_CONSOL:
    00801                 if (!isConsoleMove ())
    00802                 {
    00803                         ConsoleMove (true);
    00804                         SetStatus(false);
    00805                         SetConsoleState(HIDE);
    00806                         SetAskForCommand(false);
    00807                         SetAskForExclusifCommand(false);
    00808                 }
    00809                 break;
    00810         case CONSOL_NEXT_AVIABLE_STATE:
    00811                 switch(NextAviableState())
    00812                 {
    00813                 case HIDE:
    00814                 case FULLTOHIDE:
    00815                 case HALFTOHIDE:
    00816                         if (!isConsoleMove ())
    00817                         {
    00818                                 ConsoleMove (true);
    00819                                 SetStatus(false);
    00820                                 SetConsoleState(HIDE);
    00821                                 SetAskForCommand(false);
    00822                                 SetAskForExclusifCommand(false);
    00823                         }
    00824                         break;
    00825                 case HALF:
    00826                 case HIDETOHALF:
    00827                 case FULLTOHALF:
    00828                         if (!isConsoleMove ())
    00829                         {
    00830                                 ConsoleMove (true);
    00831                                 SetStatus(true);
    00832                                 SetAskForCommand(true);
    00833                                 SetAskForExclusifCommand(true);
    00834                                 SetConsoleState(HALF);
    00835                         }
    00836                         break;
    00837                 case FULL:
    00838                 case HIDETOFULL:
    00839                 case HALFTOFULL:
    00840                         if (!isConsoleMove ())
    00841                         {
    00842                                 ConsoleMove (true);
    00843                                 SetStatus(true);
    00844                                 SetAskForCommand(true);
    00845                                 SetAskForExclusifCommand(true);
    00846                                 SetConsoleState(FULL);
    00847                         }
    00848                         break;
    00849                 }
    00850                 break;
    00851
    00852         case SET_CONSOL_BACKGROUND_TEXURE:SetConsoleBackGroudTexture(Action.m_Param);break;
    00853         case ENABLE_CONSOL_BACKGROUND_TEXTURE:SetConsoleBackGroudTextureState(true);break;
    00854         case DISABLE_CONSOL_BACKGROUND_TEXTURE:SetConsoleBackGroudTextureState(false);break;
    00855         case SET_CONSOL_BACKGROUND_COLOR:break;
    00856         case SET_CONSOL_BACKGROUND_COLOR_BLUE:
    00857                 try
    00858                 {
    00859                         SetConsoleBackGroudColorBlue(atof(Action.m_Param.data()));
    00860                 }catch(...)
    00861                 {
    00862                         *Consol<<"Enter a float value"<<std::endl;
    00863                 }
    00864                 break;
    00865         case SET_CONSOL_BACKGROUND_COLOR_GREEN:
    00866                 try
    00867                 {
    00868                         SetConsoleBackGroudColorGreen(atof(Action.m_Param.data()));
    00869                 }catch(...)
    00870                 {
    00871                         *Consol<<"Enter a float value"<<std::endl;
    00872                 }
    00873                 break;
    00874         case SET_CONSOL_BACKGROUND_COLOR_RED:
    00875                 try
    00876                 {
    00877                         SetConsoleBackGroudColorRed(atof(Action.m_Param.data()));
    00878                 }catch(...)
    00879                 {
    00880                         *Consol<<"Enter a float value"<<std::endl;
    00881                 }
    00882         case ENABLE_CONSOL_BACKGROUND_BLENDING:SetConsoleBackGroudBlendingState(true);break;
    00883         case DISABLE_CONSOL_BACKGROUND_BLENDING:SetConsoleBackGroudBlendingState(false);break;
    00884         case SET_CONSOL_BACKGROUND_BLENDING:
    00885                 try
    00886                 {
    00887                         SetConsoleBackGroudBlending(atof(Action.m_Param.data()));
    00888                 }catch(...)
    00889                 {
    00890                         *Consol<<"Enter a float value"<<std::endl;
    00891                 }
    00892                 break;
    00893         }
    00894     if(Action.m_NextAction){return *Action.m_NextAction;}
    00895         else{return NOTHING;}
    00896 UnGuard
    00897 }
    00898