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

# ExManagerModele.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  *
    00021  */
    00022 #include "ExManagerModele.h"
    00023
    00024 bool ExManagerModel::m_flag = false;
    00025 ExManagerModel* ExManagerModel::m_instance = NULL;
    00026
    00027 ExManagerModel* ExManagerModel::CreateSingleton(void){
    00028 Guard(ExManagerModel* ExManagerModel::CreateSingleton(void))
    00029         if(!m_flag)
    00030         {
    00031                 m_flag = true; // We are creating the error log now, so set flag to true
    00032                 m_instance = new ExManagerModel; // Create the error log
    00033         }else
    00034         {
    00035                 std::cout<<"Error singleton already created"<<std::endl;
    00036         }
    00037         return m_instance;
    00038 UnGuard
    00039 }
    00040
    00041 ExManagerModel::ExManagerModel(void)
    00042 {
    00043                 SetAskForCommand(true);
    00044         SetAskForExclusifCommand(false);
    00045 }
    00046
    00047 ExManagerModel::~ExManagerModel(void)
    00048 {
    00049 }
    00050
    00051 void ExManagerModel::Reset(void)
    00052 {
    00053         ExManagerObject<ExCModel *>::Reset();
    00054                 m_VecMD2.clear();
    00055                 m_VecMD3.clear();
    00056                 m_VecASC.clear();
    00057                 m_Vec3DS.clear();
    00058                 m_VecOBJ.clear();
    00059                 Init();
    00060 }
    00061
    00062 void ExManagerModel::Init(void)
    00063 {
    00064 Guard(void ExManagerModel::Init(void))
    00065         ExManagerObject<ExCModel *>::Init();
    00066 UnGuard
    00067 }
    00068
    00069 void ExManagerModel::Draw(void)
    00070 {
    00071 Guard(void ExManagerModel::Draw(void))
    00072         try
    00073         {
    00074                 unsigned int i;
    00075             for(i =0;i<m_VecMD2.size();++i){m_VecMD2.at(i).Draw();}
    00076                 for(i =0;i<m_VecMD3.size();++i){m_VecMD3.at(i).Draw();}
    00077                 for(i =0;i<m_VecASC.size();++i){m_VecASC.at(i).Draw();}
    00078                 for(i =0;i<m_Vec3DS.size();++i){m_Vec3DS.at(i).Draw();}
    00079                 for(i =0;i<m_VecOBJ.size();++i){m_VecOBJ.at(i).Draw();}
    00080                 //for(i =0;i<m_VecASE.size();++i){m_VecASE.at(i).Draw();}
    00081         }catch(...)
    00082         {
    00083
    00084         }
    00085 UnGuard
    00086 }
    00087
    00088 void ExManagerModel::List(void)
    00089 {
    00090 Guard(void ExManagerModel::List(void))
    00091         unsigned int i;
    00092         *Consol<<"---------------List of Model--------------"<<std::endl;
    00093         for(i =0;i<m_VecASC.size();++i)
    00094         {
    00095                 m_VecASC.at(i).Draw();
    00096                 *Consol<<" Id:"<<m_VecASC.at(i).GetId()<<" Name :"<<m_VecASC.at(i).GetName()<<" Type :"<<typeid(&m_VecASC.at(i)).name()<<std::endl;
    00097         }
    00098         for(i =0;i<m_VecMD2.size();++i)
    00099         {
    00100                 m_VecMD2.at(i).Draw();
    00101                 *Consol<<" Id:"<<m_VecMD2.at(i).GetId()<<" Name :"<<m_VecMD2.at(i).GetName()<<" Type :"<<typeid(&m_VecMD2.at(i)).name()<<std::endl;
    00102         }
    00103         for(i =0;i<m_Vec3DS.size();++i)
    00104         {
    00105                 m_Vec3DS.at(i).Draw();
    00106                 *Consol<<" Id:"<<m_Vec3DS.at(i).GetId()<<" Name :"<<m_Vec3DS.at(i).GetName()<<" Type :"<<typeid(&m_Vec3DS.at(i)).name()<<std::endl;
    00107         }
    00108         for(i =0;i<m_VecOBJ.size();++i)
    00109         {
    00110                 m_VecOBJ.at(i).Draw();
    00111                 *Consol<<" Id:"<<m_VecOBJ.at(i).GetId()<<" Name :"<<m_VecOBJ.at(i).GetName()<<" Type :"<<typeid(&m_VecOBJ.at(i)).name()<<std::endl;
    00112         }
    00113         for(i =0;i<m_VecMD3.size();++i)
    00114         {
    00115                 m_VecMD3.at(i).Draw();
    00116                 *Consol<<" Id:"<<m_VecMD3.at(i).GetId()<<" Name :"<<m_VecMD3.at(i).GetName()<<" Type :"<<typeid(&m_VecMD3.at(i)).name()<<std::endl;
    00117         }
    00118         *Consol<<"-----------------------------------------------------------------"<<std::endl;
    00119         *Consol<<" Number Total of Object : "<<m_Map->size()<<std::endl;
    00120         *Consol<<" Current Object Id : "<<m_CurrentObjectId<<std::endl;
    00121         *Consol<<"-----------------------------------------------------------------"<<std::endl;
    00122
    00123 UnGuard
    00124 }
    00125
    00126 ExNihilo::ExId ExManagerModel::Load(std::string FileName)
    00127 {
    00128 Guard(ExNihilo::ExId ExManagerModel::Load(std::string FileName))
    00129         FileName="../Data/Modeles/"+FileName;
    00130         try
    00131         {
    00132                 if(FileName.find(".md2")==(FileName.length()-4))
    00133                         return LoadMD2(FileName);
    00134                 if(FileName.find(".md3")==(FileName.length()-4))
    00135                         return LoadMD3(FileName);
    00136                 if(FileName.find(".asc")==(FileName.length()-4))
    00137                         return LoadASC(FileName);
    00138                 if(FileName.find(".ase")==(FileName.length()-4))
    00139                         return LoadASE(FileName);
    00140                 if(FileName.find(".3ds")==(FileName.length()-4))
    00141                         return Load3DS(FileName);
    00142                 if(FileName.find(".obj")==(FileName.length()-4))
    00143                         return LoadOBJ(FileName);
    00144         }
    00145         catch(ExCExpFileNotFound)
    00146         {
    00147                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" File not found"<<std::endl;
    00148         }
    00149         catch(ExCExpFileReadError)
    00150         {
    00151                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" Read file error"<<std::endl;
    00152         }
    00153         catch(...)
    00154         {
    00155                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" Unknow exception"<<std::endl;
    00156         }
    00157         return -1;
    00158 UnGuard
    00159 }
    00160
    00161 ExNihilo::ExId ExManagerModel::Load(std::string FileName,std::string ObjectName)
    00162 {
    00163 Guard(ExNihilo::ExId ExManagerModel::Load(std::string FileName,std::string ObjectName))
    00164         FileName="../Data/Modeles/"+FileName;
    00165         try
    00166         {
    00167                 if(FileName.find(".md2")==(FileName.length()-4))
    00168                         return LoadMD2(FileName,ObjectName);
    00169                 if(FileName.find(".md3")==(FileName.length()-4))
    00170                         return LoadMD3(FileName);
    00171                 if(FileName.find(".asc")==(FileName.length()-4))
    00172                         return LoadASC(FileName);
    00173                 if(FileName.find(".ase")==(FileName.length()-4))
    00174                         return LoadASE(FileName);
    00175                 if(FileName.find(".3ds")==(FileName.length()-4))
    00176                         return Load3DS(FileName,ObjectName);
    00177                 if(FileName.find(".obj")==(FileName.length()-4))
    00178                         return LoadOBJ(FileName);
    00179         }
    00180         catch(ExCExpFileNotFound)
    00181         {
    00182                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" File not found"<<std::endl;
    00183         }
    00184         catch(ExCExpFileReadError)
    00185         {
    00186                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" Read file error"<<std::endl;
    00187         }
    00188         catch(...)
    00189         {
    00190                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" Unknow exception"<<std::endl;
    00191         }
    00192         return -1;
    00193 UnGuard
    00194 }
    00195
    00196
    00197
    00198 ExNihilo::ExId ExManagerModel::LoadMD2(std::string FileName)
    00199 {
    00200 Guard(ExNihilo::ExId ExManagerModel::LoadMD2(std::string FileName))
    00201         ExCModelMD2 ModelMD2B;
    00202         ModelMD2B.SetManagerTexture(ManagerTexture);
    00203         ModelMD2B.Load(FileName);
    00204         m_VecMD2.push_back(ModelMD2B);
    00205         return ExManagerObject<ExCModel *>::Add(&m_VecMD2.at(m_VecMD2.size()-1));
    00206 UnGuard
    00207 }
    00208
    00209 ExNihilo::ExId ExManagerModel::LoadMD2(std::string FileName,std::string ObjectName)
    00210 {
    00211 Guard(ExNihilo::ExId ExManagerModel::LoadMD2(std::string FileName,std::string ObjectName))
    00212         ExCModelMD2 ModelMD2B;
    00213         ModelMD2B.SetManagerTexture(ManagerTexture);
    00214         ModelMD2B.Load(FileName);
    00215         ModelMD2B.SetName(ObjectName);
    00216         m_VecMD2.push_back(ModelMD2B);
    00217         ExManagerObject<ExCModel *>::Add(&m_VecMD2.at(m_VecMD2.size()-1));
    00218         return m_VecMD2.at(m_VecMD2.size()-1).GetId();
    00219 UnGuard
    00220 }
    00221
    00222 ExNihilo::ExId ExManagerModel::Load3DS(std::string FileName)
    00223 {
    00224 Guard(ExNihilo::ExId ExManagerModel::Load3DS(std::string FileName))
    00225         ExCModel3DS Model3DS;
    00226         Model3DS.SetManagerTexture(ManagerTexture);
    00227         Model3DS.Load(FileName);
    00228         m_Vec3DS.push_back(Model3DS);
    00229         ExManagerObject<ExCModel *>::Add(&m_Vec3DS.at(m_Vec3DS.size()-1));
    00230         return m_Vec3DS.at(m_Vec3DS.size()-1).GetId();
    00231
    00232 UnGuard
    00233 }
    00234
    00235 ExNihilo::ExId ExManagerModel::Load3DS(std::string FileName,std::string ObjectName)
    00236 {
    00237 Guard(ExNihilo::ExId ExManagerModel::Load3DS(std::string FileName,std::string ObjectName))
    00238         ExCModel3DS Model3DS;
    00239         Model3DS.SetManagerTexture(ManagerTexture);
    00240         Model3DS.Load(FileName);
    00241         Model3DS.SetName(ObjectName);
    00242         m_Vec3DS.push_back(Model3DS);
    00243         ExManagerObject<ExCModel *>::Add(&m_Vec3DS.at(m_Vec3DS.size()-1));
    00244         return m_Vec3DS.at(m_Vec3DS.size()-1).GetId();
    00245 UnGuard
    00246 }
    00247
    00248 ExNihilo::ExId ExManagerModel::LoadMD3(std::string FileName)
    00249 {
    00250 Guard(ExNihilo::ExId ExManagerModel::LoadMD3(std::string FileName))
    00251         return -1;
    00252 UnGuard
    00253 }
    00254
    00255 ExNihilo::ExId ExManagerModel::LoadASC(std::string FileName)
    00256 {
    00257 Guard(ExNihilo::ExId ExManagerModel::LoadASC(std::string FileName))
    00258         ExCModelASC ModelASC;
    00259         ModelASC.LoadFile(FileName);
    00260         ModelASC.SetManagerTexture(ManagerTexture);
    00261         m_VecASC.push_back(ModelASC);
    00262         ExManagerObject<ExCModel *>::Add(&m_VecASC.at(m_VecASC.size()-1));
    00263         return m_VecASC.at(m_VecASC.size()-1).GetId();
    00264 UnGuard
    00265 }
    00266
    00267
    00268
    00269 ExNihilo::ExId ExManagerModel::LoadOBJ(std::string FileName)
    00270 {
    00271 Guard(ExNihilo::ExId ExManagerModel::LoadOBJ(std::string FileName))
    00272         return -1;
    00273 UnGuard
    00274 }
    00275
    00276 ExNihilo::ExId ExManagerModel::LoadASE(std::string FileName)
    00277 {
    00278 Guard(ExNihilo::ExId ExManagerModel::LoadASE(std::string FileName))
    00279          return -1;
    00280 UnGuard
    00281 }
    00282
    00283 ExCAction ExManagerModel::InputCommand(ExCCommand Command)
    00284 {
    00285 Guard(ExCAction ExManagerModel::InputCommand(ExCCommand Command))
    00286         switch(Command.m_Command)
    00287         {
    00288         case KEYBOARD_UP_ARROW_DOWN:
    00289                 return NOTHING;
    00290         case KEYBOARD_UP_ARROW_UP:
    00291                 return NOTHING;
    00292         case KEYBOARD_UP_ARROW_LEFT:
    00293                 return NOTHING;
    00294         case KEYBOARD_UP_ARROW_RIGHT:
    00295                 return NOTHING;
    00296         case KEYBOARD_DOWN_ARROW_DOWN:
    00297                 return NOTHING;
    00298         case KEYBOARD_DOWN_ARROW_UP:
    00299                 return NOTHING;
    00300         case KEYBOARD_DOWN_ARROW_LEFT:
    00301                 return NOTHING;
    00302         case KEYBOARD_DOWN_ARROW_RIGHT:
    00303                 return NOTHING;
    00304         default :return NOTHING;
    00305         }
    00306 UnGuard
    00307 }
    00308
    00309 ExCAction ExManagerModel::InputAction(ExCAction Action)
    00310 {
    00311 Guard(ExCAction ExManagerModel::InputAction(ExCAction Action))
    00312         try
    00313         {
    00314                 switch(Action.m_Action)
    00315                 {
    00316                 case LIST:List();break;
    00317                 case SET_CURRENT_OBJECT_BY_ID:
    00318                         SetCurrentObject(atoi(Action.m_Param.data()));
    00319                         break;
    00320                 case SET_CURRENT_OBJECT_BY_NAME:
    00321                         SetCurrentObject(Action.m_Param);
    00322                         break;
    00323                 case NEXT_FRAME:
    00324                         GetObject(m_CurrentObjectId)->NextFrame();
    00325                         break;
    00326                 case PREVIOUS_FRAME:
    00327                         break;
    00328                 case SET_CURENT_FRAME:
    00329                         break;
    00330                 case START_ACTION:
    00331                         GetObject(m_CurrentObjectId)->StartAction(Action.m_Param);
    00332                         break;
    00333                 case STOP_ACTION:
    00334                         GetObject(m_CurrentObjectId)->StopAction();
    00335                         break;
    00336                 case TURN_LEFT:
    00337                         GetObject(m_CurrentObjectId)->StartAction(Action.m_Param);
    00338                         break;
    00339                 case TURN_RIGHT:
    00340                         GetObject(m_CurrentObjectId)->StartAction(Action.m_Param);
    00341                 case LOOK_UP:
    00342                         GetObject(m_CurrentObjectId)->StartAction(Action.m_Param);
    00343                         break;
    00344                 case LOOK_DOWN:
    00345                         GetObject(m_CurrentObjectId)->StartAction(Action.m_Param);
    00346                         break;
    00347                 case MODEL_SET_POS_X:
    00348                         GetObject(m_CurrentObjectId)->m_Position.SetX(atof(Action.m_Param.data()));
    00349                         break;
    00350                 case MODEL_SET_POS_Y:
    00351                         GetObject(m_CurrentObjectId)->m_Position.SetY(atof(Action.m_Param.data()));
    00352                         break;
    00353                 case MODEL_SET_POS_Z:
    00354                         GetObject(m_CurrentObjectId)->m_Position.SetZ(atof(Action.m_Param.data()));
    00355                         break;
    00356                 case MODEL_SET_ANGLE_X:
    00357                         GetObject(m_CurrentObjectId)->m_AngleX=atof(Action.m_Param.data());
    00358                         break;
    00359                 case MODEL_SET_ANGLE_Y:
    00360                         GetObject(m_CurrentObjectId)->m_AngleY=atof(Action.m_Param.data());
    00361                         break;
    00362                 case MODEL_SET_ANGLE_Z:
    00363                         GetObject(m_CurrentObjectId)->m_AngleZ=atof(Action.m_Param.data());
    00364                         break;
    00365                 case MODEL_SET_ACTION:
    00366                         break;
    00367                 case MODEL_LOAD_WITH_NAME:
    00368                         Load(Action.m_Param,Action.m_Param1);
    00369                         break;
    00370                 case MODEL_LOAD:
    00371                         Load(Action.m_Param);
    00372                         break;
    00373
    00374
    00375                 default:
    00376                         *Consol<<"Can not file action in MODEL_ACTION_MAP"<<std::endl;
    00377                         break;
    00378                 }
    00379
    00380                 if(Action.m_NextAction){return *Action.m_NextAction;}
    00381                 else{return NOTHING;}
    00382         }
    00383         catch(...)
    00384         {
    00385                 *Consol<<"ExManagerModel::ExCeption =>> Error input action"<<std::endl;
    00386                 return NOTHING;
    00387         }
    00388 UnGuard
    00389 }
    00390
    00391 ExCModel * ExManagerModel::GetObject(ExNihilo::ExId id)
    00392 {
    00393 Guard(ExCModel *ExManagerModel::GetObject(ExNihilo::ExId id))
    00394         unsigned int i;
    00395         for(i =0;i<m_VecMD2.size();++i)
    00396         {
    00397                 if(m_VecMD2.at(i).GetId()==id)return &m_VecMD2.at(i);
    00398         }
    00399         for(i =0;i<m_VecASC.size();++i)
    00400         {
    00401                 if(m_VecASC.at(i).GetId()==id)return &m_VecASC.at(i);
    00402         }
    00403         for(i =0;i<m_VecMD3.size();++i)
    00404         {
    00405                 if(m_VecMD3.at(i).GetId()==id)return &m_VecMD3.at(i);
    00406         }
    00407         for(i =0;i<m_Vec3DS.size();++i)
    00408         {
    00409                 if(m_Vec3DS.at(i).GetId()==id)return &m_Vec3DS.at(i);
    00410         }
    00411         for(i =0;i<m_VecOBJ.size();++i)
    00412         {
    00413                 if(m_VecOBJ.at(i).GetId()==id)return &m_VecOBJ.at(i);
    00414         }
    00415         return NULL;
    00416 UnGuard
    00417 }
    00418
    00419 ExCModel* ExManagerModel::GetCurrentObject(void)
    00420 {
    00421 Guard(ExCModel* ExManagerModel::GetCurrentObject(void))
    00422         return GetObject(m_CurrentObjectId);
    00423 UnGuard
    00424 }
    00425
    00426 void ExManagerModel::NextFrame(void)
    00427 {
    00428 Guard(void ExManagerModel::NextFrame(void))
    00429
    00430 UnGuard
    00431 }
    00432 void ExManagerModel::PreviousFrame(void)
    00433 {
    00434 Guard(void ExManagerModel::PreviousFrame(void))
    00435
    00436 UnGuard
    00437 }
    00438
    00439 void ExManagerModel::SetCurrentFrame(int frame)
    00440 {
    00441 Guard(void ExManagerModel::SetCurrentFrame(int frame))
    00442
    00443 UnGuard
    00444 }
    00445