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

# ExManagerLoad.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: ExManagerLoad.cpp,v 1.23 2002/11/24 11:58:58 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExManagerLoad.h"
    00025
    00026 bool ExManagerLoad::m_flag = false;
    00027 ExManagerLoad* ExManagerLoad::m_instance = NULL;
    00028
    00029 ExManagerLoad* ExManagerLoad::CreateSingleton(void){
    00030 Guard(ExManagerLoad* ExManagerLoad::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 ExManagerLoad; // 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 ExManagerLoad::ExManagerLoad(void)
    00044 {
    00045 Guard(ExManagerLoad::ExManagerLoad(void))
    00046         m_Draw=false;
    00047         m_Loading=false;
    00048         SetAskForCommand(false);
    00049 UnGuard
    00050 }
    00051
    00052 ExManagerLoad::~ExManagerLoad(void)
    00053 {
    00054 Guard(ExManagerLoad::~ExManagerLoad(void))
    00055 UnGuard
    00056 }
    00057
    00058 void ExManagerLoad::Reset(void)
    00059 {
    00060 Guard(void ExManagerLoad::Reset(void))
    00061         ExManagerObject<ExCLoadingAnimation>::Reset();
    00062         Init();
    00063 UnGuard
    00064 }
    00065
    00066 void ExManagerLoad::Init(void)
    00067 {
    00068 Guard(ExManagerLoad::Init(void))
    00069         ExManagerObject<ExCLoadingAnimation>::Init();
    00070         m_Loading=false;
    00071         m_EntityFilePath="../Data/Entity/";
    00072 UnGuard
    00073 }
    00074
    00075 void ExManagerLoad::Load(std::string FileName)
    00076 {
    00077 Guard(ExManagerLoad::Load(std::string FileName))
    00078 //TO DO here add path for loading file directory
    00079         ExCAction Action;
    00080         try
    00081         {
    00082                 switch(GetFileType(FileName))
    00083                 {
    00084                 case FILE_CONSOL:
    00085                         ManagerConsole->LoadStringActionFile(FileName.data());
    00086                         break;
    00087                 case FILE_SET:
    00088                         LoadSetOfFile(FileName);
    00089                         break;
    00090                 case FILE_SOUND:
    00091                         ManagerSound->LoadSound(FileName);
    00092                         break;
    00093                 case FILE_MODEL:
    00094                         ManagerModel->Load(FileName);
    00095                         break;
    00096                 case FILE_MAP:
    00097                         ManagerMap->Load(FileName);
    00098                         break;
    00099                 case FILE_PARTICUL:
    00100                         ManagerParticuleSystem->Load(FileName);
    00101                         break;
    00102                 case FILE_WINDOW:
    00103                         ManagerObjectWindow->Load(FileName);
    00104                         break;
    00105                 case FILE_INTERFACE:
    00106                         ManagerInterface->Load(FileName);
    00107                         break;
    00108                 case FILE_TEXTURE:
    00109                         ManagerTexture->Load(FileName);
    00110                         break;
    00111                 case FILE_COMMAND:
    00112                         Action.m_Action=LOAD_EXEC_CONFIG_FILE;
    00113                         Action.m_Param=" "+FileName;
    00114                         FluxAction->Push(Action);
    00115                         break;
    00116                 case FILE_MESH:
    00117                         ManagerMesh->Load(FileName);
    00118                         break;
    00119                 case FILE_LOADING_ANIMATION:
    00120                         LoadAnimationFile(FileName);
    00121                         break;
    00122                 case FILE_ANIMATION:
    00123                         ManagerAnimation->Load(FileName);
    00124                         break;
    00125                 case FILE_ENTITY:
    00126                         ManagerEntity->Load(m_EntityFilePath+FileName);
    00127                         break;
    00128                 }
    00129         }
    00130         catch(ExCExpFileNotFound)
    00131         {
    00132                 *Consol<<"ExManagerLoad::ExCeption =>"<<FileName<<" File not found"<<std::endl;
    00133         }
    00134         catch(ExCExpFileReadError)
    00135         {
    00136                 *Consol<<"ExManagerLoad::ExCeption =>"<<FileName<<" Read file error"<<std::endl;
    00137         }
    00138         catch(...)
    00139         {
    00140                 *Consol<<"ExManagerLoad::ExCeption =>"<<FileName<<" Unknow exception"<<std::endl;
    00141         }
    00142 UnGuard
    00143 }
    00144
    00145 void ExManagerLoad::LoadAnimationFile(std::string FileName)
    00146 {
    00147 Guard(ExManagerLoad::LoadAnimationFile(std::string FileName))
    00148         m_CurrentLoadingAniamtion = new ExCLoadingAnimation();
    00149         m_CurrentLoadingAniamtion->SetManagerTexture(ManagerTexture);
    00150         m_CurrentLoadingAniamtion->Load(FileName);
    00151         m_CurrentLoadingAniamtion->SetName(FileName);
    00152         //ExManagerObject<ExCLoadingAnimation>::Add(Animation);
    00153         //SetCurrentObject(Animation.GetName());
    00154         UnGuard
    00155 }
    00156
    00157
    00158 void ExManagerLoad::DrawInAnimation(void)
    00159 {
    00160 Guard(void ExManagerLoad::DrawInAnimation(void))
    00161         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);       //Clear screen
    00162         ManagerCamera->Draw();
    00163         if(m_Draw)m_CurrentLoadingAniamtion->Draw();
    00164         glFlush();
    00165         glutSwapBuffers();
    00166 UnGuard
    00167 }
    00168
    00169
    00170 void ExManagerLoad::Draw(void)
    00171 {
    00172 Guard(void ExManagerLoad::Draw(void))
    00173         if(m_Draw)m_CurrentLoadingAniamtion->Draw();
    00174         if(m_Loading)
    00175         {
    00176                 Load(m_VecFileToLoad.at(m_CurrentFileLoading));
    00177                 m_CurrentLoadingAniamtion->Next();
    00178                 if(m_CurrentFileLoading==m_VecFileToLoad.size()-1)
    00179                 {
    00180                         m_VecFileToLoad.clear();
    00181                         m_CurrentLoadingAniamtion->Last();
    00182                         m_Loading=false;
    00183                 }else
    00184                 {
    00185                         m_CurrentFileLoading++;
    00186                 }
    00187         }
    00188 UnGuard
    00189 }
    00190
    00191
    00192 FileType ExManagerLoad::GetFileType(std::string FileName)
    00193 {
    00194 Guard(FileType ExManagerLoad::GetFileType(std::string FileName))
    00195         std::string Buffext=ExNihilo::GetFileExtension(FileName);
    00196
    00197         if(strcmpi(Buffext.data(),"csl")==0)
    00198         {
    00199                 return FILE_CONSOL;
    00200         }
    00201         if(strcmpi(Buffext.data(),"comd")==0)
    00202         {
    00203                 return FILE_COMMAND;
    00204         }
    00205         if(strcmpi(Buffext.data(),"wav")==0
    00206                 ||strcmpi(Buffext.data(),"mp3")==0
    00207                 ||strcmpi(Buffext.data(),"mid")==0)
    00208         {
    00209                 return FILE_SOUND;
    00210         }
    00211         if(strcmpi(Buffext.data(),"asc")==0
    00212                 ||strcmpi(Buffext.data(),"ase")==0
    00213                 ||strcmpi(Buffext.data(),"3ds")==0
    00214                 ||strcmpi(Buffext.data(),"md2")==0
    00215                 ||strcmpi(Buffext.data(),"md3")==0
    00216                 ||strcmpi(Buffext.data(),"exm")==0
    00217                 ||strcmpi(Buffext.data(),"obj")==0)
    00218         {
    00219                 return FILE_MODEL;
    00220         }
    00221         if(strcmpi(Buffext.data(),"map")==0
    00222                 ||strcmpi(Buffext.data(),"bsp")==0
    00223                 ||strcmpi(Buffext.data(),"hgmp")==0
    00224                 ||strcmpi(Buffext.data(),"skyb")==0)
    00225         {
    00226                 return FILE_MAP;
    00227         }
    00228         if(strcmpi(Buffext.data(),"int")==0)
    00229         {
    00230                 return   FILE_INTERFACE;
    00231         }
    00232         if(strcmpi(Buffext.data(),"set")==0)
    00233         {
    00234                 return FILE_SET;
    00235         }
    00236         if(strcmpi(Buffext.data(),"exec")==0)
    00237         {
    00238                 return FILE_COMMAND;
    00239         }
    00240         if(strcmpi(Buffext.data(),"part")==0)
    00241         {
    00242                 return FILE_PARTICUL;
    00243         }
    00244         if(strcmpi(Buffext.data(),"exw")==0)
    00245         {
    00246                 return FILE_WINDOW;
    00247         }
    00248         if(strcmpi(Buffext.data(),"lanim")==0)
    00249         {
    00250                 return FILE_LOADING_ANIMATION;
    00251         }
    00252         if(strcmpi(Buffext.data(),"anim")==0)
    00253         {
    00254                 return FILE_ANIMATION;
    00255         }
    00256         if(strcmpi(Buffext.data(),"exme")==0)
    00257         {
    00258                 return FILE_MESH;
    00259         }
    00260         if(strcmpi(Buffext.data(),"bmp")==0
    00261                 ||strcmpi(Buffext.data(),"tga")==0
    00262                 ||strcmpi(Buffext.data(),"pcx")==0
    00263                 ||strcmpi(Buffext.data(),"jpg")==0
    00264                 ||strcmpi(Buffext.data(),"rgb")==0
    00265                 ||strcmpi(Buffext.data(),"raw")==0
    00266                 ||strcmpi(Buffext.data(),"dds")==0
    00267                 ||strcmpi(Buffext.data(),"ppm")==0)
    00268         {
    00269                 return FILE_TEXTURE;
    00270         }
    00271         if(strcmpi(Buffext.data(),"ent")==0)
    00272         {
    00273                 return FILE_ENTITY;
    00274         }
    00275         *Consol<<"ExManagerLoad::ExCeption =>"<<FileName<<" Bad file extension"<<std::endl;
    00276         DisplayFileType();
    00277         return FILE_UNKNOWN_TYPE;
    00278 UnGuard
    00279 }
    00280
    00281
    00282
    00283
    00284 ExCAction ExManagerLoad::InputCommand(ExCCommand Command)
    00285 {
    00286 Guard(ExCAction ExManagerLoad::InputCommand(ExCCommand Command))
    00287         if(Command.m_Command>10000&&Command.m_Command<30000)
    00288         {
    00289                 if(!m_Loading)m_Draw=false;
    00290                 SetAskForCommand(false);
    00291                 //return START_BLACK_TO_FADE;
    00292         }
    00293         if(Command.m_Command>40001&&Command.m_Command<40006)
    00294         {
    00295                 if(!m_Loading)m_Draw=false;
    00296                 SetAskForCommand(false);
    00297                 //return START_BLACK_TO_FADE;
    00298         }
    00299         return NOTHING;
    00300 UnGuard
    00301 }
    00302
    00303 ExCAction ExManagerLoad::InputAction(ExCAction Action)
    00304 {
    00305 Guard(ExCAction ExManagerLoad::InputAction(ExCAction Action))
    00306         switch(Action.m_Action)
    00307         {
    00308         case LOAD_PART_CONFIG_FILE:
    00309                 ManagerParticuleSystem->Load(Action.m_Param);
    00310                 break;
    00311         case LOAD_SET_OF_FILE:
    00312                 LoadSetOfFile(Action.m_Param);
    00313                 break;
    00314         case LOAD_FILE:
    00315                 Load(Action.m_Param);
    00316                 break;
    00317         case NEXT_ANIMATION_FRAME:
    00318                 m_CurrentLoadingAniamtion->Next();
    00319                 DrawInAnimation();
    00320                 break;
    00321         case PREV_ANIMATION_FRAME:
    00322                 m_CurrentLoadingAniamtion->Previous();
    00323                 DrawInAnimation();
    00324                 break;
    00325         case LAST_ANIMATION_FRAME:
    00326                 m_CurrentLoadingAniamtion->Last();
    00327                 DrawInAnimation();
    00328                 break;
    00329         case FIRST_ANIMATION_FRAME:
    00330                 m_CurrentLoadingAniamtion->First();
    00331                 DrawInAnimation();
    00332                 break;
    00333         case ENABLE_LOADING_ANIMATION:
    00334                 SetStatus(true);
    00335                 SetAskForCommand(true);
    00336                 m_Loading=false;
    00337                 m_Draw=true;
    00338                 m_CurrentFileLoading=0;
    00339                 DrawInAnimation();
    00340                 break;
    00341         case DISABLE_LOADING_ANIMATION:
    00342                 SetAskForCommand(false);
    00343                 m_Loading=false;
    00344                 m_Draw=false;
    00345                 m_CurrentFileLoading=0;
    00346                 break;
    00347         default:
    00348                 *Consol<<"Can not file action in LOAD_ACTION_MAP"<<std::endl;
    00349                 break;
    00350         }
    00351         if(Action.m_NextAction){return *Action.m_NextAction;}
    00352         else{return NOTHING;}
    00353 UnGuard
    00354 }
    00355
    00356 void ExManagerLoad::LoadSetOfFile(std::string FileName)
    00357 {
    00358 Guard(void ExManagerLoad::LoadSetOfFile(std::string FileName))
    00359         SetStatus(true);
    00360         SetAskForCommand(true);
    00361         m_Loading=true;
    00362         m_Draw=true;
    00363         m_CurrentFileLoading=0;
    00364         char                    buffer[255];
    00365         #ifdef UNIX_SRC
    00366                 sprintf(buffer, PREFIX "/ExNihilo/Data/%s", FileName.data());
    00367         #else
    00368                 sprintf(buffer, "../Data/%s", FileName.data());
    00369         #endif
    00370         std::ifstream fin;
    00371         std::string buffstring;
    00372         char b[256];
    00373         fin.open(buffer,std::ios::in);
    00374         if(fin.is_open())
    00375         {
    00376                 try
    00377                 {
    00378                         //----Read all file
    00379                         do
    00380                         {
    00381                                 memset(b,0,255);
    00382                                 fin.getline(b,256,'\n');
    00383                                 try
    00384                                 {
    00385                                         m_VecFileToLoad.push_back(ExNihilo::ExtracValueFromSring(b,"<file>","<#file>"));
    00386                                 }catch(ExCExpStringNotFound){}
    00387                         }while(!fin.eof());
    00388                         fin.close();
    00389                 }catch(...){throw ExCExpFileReadError();}
    00390         }else throw   ExCExpFileNotFound();
    00391
    00392 UnGuard
    00393 }
    00394
    00395 void ExManagerLoad::DisplayFileType(void)
    00396 {
    00397 Guard(void ExManagerLoad::DisplayFileType(void))
    00398         *Consol<<"*------------------------------------------------------------------------------------------------*"<<std::endl;
    00399         *Consol<<"|                                Extension file supported by Exnihilo                            |"<<std::endl;
    00400         *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
    00401         *Consol<<"|Description                 | Extension |  Status  |  Comment                                   |"<<std::endl;
    00402         *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
    00403         *Consol<<"|Console configuration file  |  .csl     | Aviable  | Asign consol command to action             |"<<std::endl;
    00404         *Consol<<"|Command configuration file  |  .comd    | Aviable  | Asign input (keyboard,mouse,...)to action  |"<<std::endl;
    00405         *Consol<<"|Window files                |  .ExW     | Aviable  | Load a window from a ressource file        |"<<std::endl;
    00406         *Consol<<"|------------------------------------------------------|-----------------------------------------|"<<std::endl;
    00407         *Consol<<"|ExNihilo map file           |  .map     | Aviable  | Create map file with AscToMap converter    |"<<std::endl;
    00408         *Consol<<"|Quake map file              |  .bsp     |          |                                            |"<<std::endl;
    00409         *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
    00410         *Consol<<"|ASC model  file             |  .asc     | Aviable  | Create a 3d model and export him to *.asc  |"<<std::endl;
    00411         *Consol<<"|MD2 (quake 2) model  file   |  .md2     | Aviable  |                                            |"<<std::endl;
    00412         *Consol<<"|MD3 (quake 3) model  file   |  .md3     |          |                                            |"<<std::endl;
    00413         *Consol<<"|ASE model  file             |  .ase     |          |                                            |"<<std::endl;
    00414         *Consol<<"|3d studio max model  file   |  .3ds     | Aviable  |                                            |"<<std::endl;
    00415         *Consol<<"|OBJ model  file             |  .obj     |          |                                            |"<<std::endl;
    00416         *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
    00417         *Consol<<"|Wave sound file             |  .wav     |          |                                            |"<<std::endl;
    00418         *Consol<<"|Midi sound file             |  .mid     |          |                                            |"<<std::endl;
    00419         *Consol<<"|Mp3 sound file              |  .mp3     |          |                                            |"<<std::endl;
    00420         *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
    00421         *Consol<<"|Particule system  file      |  .part    | Aviable  |  Use SDK partiucle to create *.part file   |"<<std::endl;
    00422         *Consol<<"|Interface file              |  .int     | Aviable  |  Use SDK partiucle to create *.int file    |"<<std::endl;
    00423         *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
    00424         *Consol<<"|Groupe of file              |  .set     | Aviable  |                                            |"<<std::endl;
    00425         *Consol<<"|Groupe of action            |  .exec    | Aviable  |                                            |"<<std::endl;
    00426         *Consol<<"*------------------------------------------------------------------------------------------------*"<<std::endl;
    00427 UnGuard
    00428 }