00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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;
00034 m_instance = new ExManagerLoad;
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 UnGuard
00047 }
00048
00049 ExManagerLoad::~ExManagerLoad(void)
00050 {
00051 Guard(ExManagerLoad::~ExManagerLoad(void))
00052 UnGuard
00053 }
00054
00055 void ExManagerLoad::Reset(void)
00056 {
00057 Guard(void ExManagerLoad::Reset(void))
00058 ExManagerObject<ExCLoadingAnimation>::Reset();
00059 Init();
00060 UnGuard
00061 }
00062
00063 void ExManagerLoad::Init(void)
00064 {
00065 Guard(ExManagerLoad::Init(void))
00066 ExManagerObject<ExCLoadingAnimation>::Init();
00067 UnGuard
00068 }
00069
00070 void ExManagerLoad::Load(std::string FileName)
00071 {
00072 Guard(ExManagerLoad::Load(std::string FileName))
00073
00074 UnGuard
00075 }
00076
00077 FileType ExManagerLoad::GetFileType(std::string FileName)
00078 {
00079 Guard(FileType ExManagerLoad::GetFileType(std::string FileName))
00080 std::string Buffext=ExNihilo::GetFileExtension(FileName);
00081
00082 if(strcmp(Buffext.data(),"csl")==0)
00083 {
00084 return FILE_CONSOL;
00085 }
00086 if(strcmp(Buffext.data(),"comd")==0)
00087 {
00088 return FILE_COMMAND;
00089 }
00090 if(strcmp(Buffext.data(),"wav")==0
00091 ||strcmp(Buffext.data(),"mp3")==0
00092 ||strcmp(Buffext.data(),"mid")==0)
00093 {
00094 return FILE_SOUND;
00095 }
00096 if(strcmp(Buffext.data(),"asc")==0
00097 ||strcmp(Buffext.data(),"ase")==0
00098 ||strcmp(Buffext.data(),"3ds")==0
00099 ||strcmp(Buffext.data(),"md2")==0
00100 ||strcmp(Buffext.data(),"md3")==0
00101 ||strcmp(Buffext.data(),"exm")==0
00102 ||strcmp(Buffext.data(),"obj")==0)
00103 {
00104 return FILE_MODEL;
00105 }
00106 if(strcmp(Buffext.data(),"map")==0
00107 ||strcmp(Buffext.data(),"bsp")==0
00108 ||strcmp(Buffext.data(),"hgmp")==0
00109 ||strcmp(Buffext.data(),"skyb")==0)
00110 {
00111 return FILE_MAP;
00112 }
00113 if(strcmp(Buffext.data(),"int")==0)
00114 {
00115 return FILE_INTERFACE;
00116 }
00117 if(strcmp(Buffext.data(),"set")==0)
00118 {
00119 return FILE_SET;
00120 }
00121 if(strcmp(Buffext.data(),"exec")==0)
00122 {
00123 return FILE_COMMAND;
00124 }
00125 if(strcmp(Buffext.data(),"part")==0)
00126 {
00127 return FILE_PARTICUL;
00128 }
00129 if(strcmp(Buffext.data(),"ExW")==0)
00130 {
00131 return FILE_WINDOW;
00132 }
00133 if(strcmp(Buffext.data(),"bmp")==0
00134 ||strcmp(Buffext.data(),"tga")==0
00135 ||strcmp(Buffext.data(),"pcx")==0
00136 ||strcmp(Buffext.data(),"jpg")==0
00137 ||strcmp(Buffext.data(),"rgb")==0
00138 ||strcmp(Buffext.data(),"raw")==0
00139 ||strcmp(Buffext.data(),"dds")==0
00140 ||strcmp(Buffext.data(),"ppm")==0)
00141 {
00142 return FILE_TEXTURE;
00143 }
00144 *Consol<<"ExManagerLoad::ExCeption =>"<<FileName<<" Bad file extension"<<std::endl;
00145 DisplayFileType();
00146 return FILE_UNKNOWN_TYPE;
00147 UnGuard
00148 }
00149
00150
00151
00152
00153 ExCAction ExManagerLoad::InputCommand(ExCCommand Command)
00154 {
00155 Guard(ExCAction ExManagerLoad::InputCommand(ExCCommand Command))
00156 return NOTHING;
00157 UnGuard
00158 }
00159
00160 ExCAction ExManagerLoad::InputAction(ExCAction Action)
00161 {
00162 Guard(ExCAction ExManagerLoad::InputAction(ExCAction Action))
00163 switch(Action.m_Action)
00164 {
00165 case LOAD_PART_CONFIG_FILE:
00166 ManagerParticuleSystem->Load(Action.m_Param);
00167 break;
00168 case LOAD_SET_OF_FILE:
00169 LoadSetOfFile(Action.m_Param.data());
00170 break;
00171 case LOAD_FILE:
00172 try
00173 {
00174 switch(GetFileType(Action.m_Param))
00175 {
00176 case FILE_CONSOL:
00177 ManagerConsole->LoadStringActionFile(Action.m_Param.data());
00178 break;
00179 case FILE_SET:
00180 LoadSetOfFile(Action.m_Param.data());
00181 break;
00182 case FILE_SOUND:
00183 ManagerSound->LoadSound(Action.m_Param);
00184 break;
00185 case FILE_MODEL:
00186 ManagerModel->Load(Action.m_Param);
00187 break;
00188 case FILE_MAP:
00189 ManagerMap->Load(Action.m_Param);
00190 break;
00191 case FILE_PARTICUL:
00192 ManagerParticuleSystem->Load(Action.m_Param);
00193 break;
00194 case FILE_WINDOW:
00195 ManagerObjectWindow->Load(Action.m_Param);
00196 break;
00197 case FILE_INTERFACE:
00198 ManagerInterface->Load(Action.m_Param);
00199 break;
00200 case FILE_TEXTURE:
00201 ManagerTexture->Load(Action.m_Param);
00202 break;
00203 case FILE_COMMAND:
00204 break;
00205 }
00206 }
00207 catch(ExCExpFileNotFound)
00208 {
00209 *Consol<<"ExManagerLoad::ExCeption =>"<<Action.m_Param<<" File not found"<<std::endl;
00210 return false;
00211 }
00212 catch(ExCExpFileReadError)
00213 {
00214 *Consol<<"ExManagerLoad::ExCeption =>"<<Action.m_Param<<" Read file error"<<std::endl;
00215 return false;
00216 }
00217 catch(...)
00218 {
00219 *Consol<<"ExManagerLoad::ExCeption =>"<<Action.m_Param<<" Unknow exception"<<std::endl;
00220 return false;
00221 }
00222 break;
00223 default:
00224 *Consol<<"Can not file action in LOAD_ACTION_MAP"<<std::endl;
00225 break;
00226 }
00227 if(Action.m_NextAction){return *Action.m_NextAction;}
00228 else{return NOTHING;}
00229 UnGuard
00230 }
00231
00232 void ExManagerLoad::LoadSetOfFile(const char *FileName)
00233 {
00234 Guard(void ExManagerLoad::LoadSetOfFile(const char *FileName))
00235 char ch;
00236 int RetVal;
00237 int FileSize;
00238 FILE *MyFile;
00239 bool endfile=false;
00240
00241 std::string StBuffer;
00242 std::string StType;
00243 char buffer[255];
00244
00245 #ifdef UNIX_SRC
00246 sprintf(buffer, PREFIX "/ExNihilo/Data/%s",FileName);
00247 #else
00248 sprintf(buffer, "../Data/%s",FileName);
00249 #endif
00250
00251 MyFile=fopen (buffer,"r");
00252 if(!MyFile)
00253 {
00254 *Consol<<"File not found:"<<buffer<<std::endl;
00255 }else
00256 {
00257 *Consol<<"Loading set File :"<<FileName<<std::endl;
00258
00259 fseek(MyFile,0,SEEK_END);
00260 FileSize=ftell(MyFile);
00261
00262 fseek(MyFile,0,SEEK_SET);
00263 do
00264 {
00265 RetVal=fread(&ch,sizeof(char),1,MyFile);
00266 }while(ch!='#');
00267
00268 do
00269 {
00270 RetVal=fread(&ch,sizeof(char),1,MyFile);
00271 StBuffer=StBuffer+ch;
00272 }while(ch!='#');
00273 if(strcmp(StBuffer.data(),"set#")==0)
00274 {
00275
00276 do
00277 {
00278
00279 StBuffer.erase(StBuffer.begin(),StBuffer.end());
00280 do
00281 {
00282 RetVal=fread(&ch,sizeof(char),1,MyFile);
00283 StBuffer=StBuffer+ch;
00284 }while(ch!='#');
00285 StBuffer.erase(StBuffer.end()-1,StBuffer.end());
00286 StBuffer.erase(StBuffer.begin(),StBuffer.begin()+1);
00287 if(StBuffer.find("end of set file") != (unsigned)-1)
00288 {
00289 endfile=true;
00290 }else
00291 {
00292 StType=StBuffer;
00293 StBuffer.erase(StBuffer.begin(),StBuffer.end());
00294 do
00295 {
00296 RetVal=fread(&ch,sizeof(char),1,MyFile);
00297 StBuffer=StBuffer+ch;
00298 }while(ch!='#');
00299 StBuffer.erase(StBuffer.end()-1,StBuffer.end());
00300
00301 if(strcmp(StType.data(),"command")==0)
00302 {
00303 std::cout<<"Load command file :"<<StBuffer.data()<<std::endl;
00304
00305 }
00306 if(strcmp(StType.data(),"console")==0)
00307 {
00308 std::cout<<"Load console file :"<<StBuffer.data()<<std::endl;
00309 ManagerConsole->LoadStringActionFile(StBuffer.data());
00310 }
00311 if(strcmp(StType.data(),"interface")==0)
00312 {
00313 std::cout<<"Load interface file :"<<StBuffer.data()<<std::endl;
00314 ManagerInterface->Load(StBuffer.data());
00315 }
00316 if(strcmp(StType.data(),"modele")==0)
00317 {
00318 std::cout<<"Load asc file :"<<StBuffer.data()<<std::endl;
00319 ManagerModel->Load(StBuffer);
00320 }
00321 if(strcmp(StType.data(),"sound")==0)
00322 {
00323 std::cout<<"Load sound file :"<<StBuffer.data()<<std::endl;
00324 ManagerSound->LoadSound(StBuffer.data());
00325 }
00326 if(strcmp(StType.data(),"set")==0)
00327 {
00328 std::cout<<"Load set file :"<<StBuffer.data()<<std::endl;
00329 LoadSetOfFile(StBuffer.data());
00330 }
00331 if(strcmp(StType.data(),"exec")==0)
00332 {
00333 std::cout<<"Load set file :"<<StBuffer.data()<<std::endl;
00334
00335 ExCAction action;
00336 action.SetParam(StBuffer.data());
00337
00338 }
00339 if(strcmp(StType.data(),"map")==0
00340 ||strcmp(StType.data(),"bsp")==0
00341 ||strcmp(StType.data(),"hgmp")==0
00342 ||strcmp(StType.data(),"skyb")==0)
00343 {
00344 std::cout<<"Load map file :"<<StBuffer.data()<<std::endl;
00345 ManagerMap->Load(StBuffer);
00346 }
00347 if(strcmp(StType.data(),"ExW")==0)
00348 {
00349 std::cout<<"Load Window file :"<<StBuffer.data()<<std::endl;
00350 ManagerObjectWindow->Load(StBuffer.data());
00351 }
00352
00353 }
00354 }while(!endfile);
00355 fclose(MyFile);
00356 }else
00357 {
00358 *Consol<<FileName<<" is not a valide console file"<<std::endl;
00359 }
00360 }
00361 UnGuard
00362 }
00363
00364 void ExManagerLoad::DisplayFileType(void)
00365 {
00366 Guard(void ExManagerLoad::DisplayFileType(void))
00367 *Consol<<"*------------------------------------------------------------------------------------------------*"<<std::endl;
00368 *Consol<<"| Extension file supported by Exnihilo |"<<std::endl;
00369 *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
00370 *Consol<<"|Description | Extension | Status | Comment |"<<std::endl;
00371 *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
00372 *Consol<<"|Console configuration file | .csl | Aviable | Asign consol command to action |"<<std::endl;
00373 *Consol<<"|Command configuration file | .comd | Aviable | Asign input (keyboard,mouse,...)to action |"<<std::endl;
00374 *Consol<<"|Window files | .ExW | Aviable | Load a window from a ressource file |"<<std::endl;
00375 *Consol<<"|------------------------------------------------------|-----------------------------------------|"<<std::endl;
00376 *Consol<<"|ExNihilo map file | .map | Aviable | Create map file with AscToMap converter |"<<std::endl;
00377 *Consol<<"|Quake map file | .bsp | | |"<<std::endl;
00378 *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
00379 *Consol<<"|ASC model file | .asc | Aviable | Create a 3d model and export him to *.asc |"<<std::endl;
00380 *Consol<<"|MD2 (quake 2) model file | .md2 | Aviable | |"<<std::endl;
00381 *Consol<<"|MD3 (quake 3) model file | .md3 | | |"<<std::endl;
00382 *Consol<<"|ASE model file | .ase | | |"<<std::endl;
00383 *Consol<<"|3d studio max model file | .3ds | Aviable | |"<<std::endl;
00384 *Consol<<"|OBJ model file | .obj | | |"<<std::endl;
00385 *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
00386 *Consol<<"|Wave sound file | .wav | | |"<<std::endl;
00387 *Consol<<"|Midi sound file | .mid | | |"<<std::endl;
00388 *Consol<<"|Mp3 sound file | .mp3 | | |"<<std::endl;
00389 *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
00390 *Consol<<"|Particule system file | .part | Aviable | Use SDK partiucle to create *.part file |"<<std::endl;
00391 *Consol<<"|Interface file | .int | Aviable | Use SDK partiucle to create *.int file |"<<std::endl;
00392 *Consol<<"|------------------------------------------------------------------------------------------------|"<<std::endl;
00393 *Consol<<"|Groupe of file | .set | Aviable | |"<<std::endl;
00394 *Consol<<"|Groupe of action | .exec | Aviable | |"<<std::endl;
00395 *Consol<<"*------------------------------------------------------------------------------------------------*"<<std::endl;
00396 UnGuard
00397 }