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         Init();
    00055 }
    00056
    00057 void ExManagerModel::Init(void)
    00058 {
    00059 Guard(void ExManagerModel::Init(void))
    00060         ExManagerObject<ExCModel *>::Init();
    00061 //      Load("Mur.3ds","MUR");
    00062
    00063         /*Load("ogre.md2","OGRE");
    00064         SetCurrentObject("OGRE");*/
    00065 //      GetCurrentObject()->SetPosition(40.0f,0.0f,0.0f);
    00066 /*
    00067         Load("ogre.md2","OGRE1");
    00068         SetCurrentObject("OGRE1");
    00069         GetCurrentObject()->SetPosition(-40.0f,0.0f,0.0f);
    00070
    00071         Load("ogre.md2","OGRE2");
    00072         SetCurrentObject("OGRE2");
    00073         GetCurrentObject()->SetPosition(0.0f,0.0f,40.0f);
    00074
    00075         Load("ogre.md2","OGRE3");
    00076         SetCurrentObject("OGRE3");
    00077         GetCurrentObject()->SetPosition(0.0f,0.0f,-40.0f);
    00078
    00079         Load("sara.md2","SARA");
    00080         SetCurrentObject("SARA");
    00081         GetCurrentObject()->SetPosition(20.0f,0.0f,20.0f);
    00082 */
    00083         //Load("pknight.md2","KNIGHT");
    00084         //SetCurrentObject("KNIGHT");
    00085
    00086 /*      Load("Fleche.3ds","FLECHES");
    00087         SetCurrentObject("FLECHES");
    00088 */
    00089 /*      Load("orc.3ds","GENERAL");
    00090         SetCurrentObject("GENERAL");
    00091         //GetCurrentObject()->SetPosition(100,50,0);
    00092         GetCurrentObject()->m_AlwaysDraw=true;
    00093         GetCurrentObject()->SetPosition(1995,95,4154);*/
    00094 UnGuard
    00095 }
    00096
    00097 void ExManagerModel::Draw(void)
    00098 {
    00099 Guard(void ExManagerModel::Draw(void))
    00100         try
    00101         {
    00102                 for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00103                 {
    00104                         m_ItMap->second->Draw();
    00105                 }
    00106         }catch(...){}
    00107 UnGuard
    00108 }
    00109
    00110 void ExManagerModel::List(void)
    00111 {
    00112 Guard(void ExManagerModel::List(void))
    00113         *Consol<<"---------------List of Model--------------"<<std::endl;
    00114         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00115         {
    00116                 *Consol<<" Id:"<<m_ItMap->second->GetId()<<" Name :"<<m_ItMap->second->GetName()<<" Type :"<<m_ItMap->second->GetType()<<std::endl;
    00117
    00118         }
    00119         *Consol<<"-----------------------------------------------------------------"<<std::endl;
    00120         *Consol<<" Number Total of Object : "<<m_Map->size()<<std::endl;
    00121         *Consol<<" Current Object Id : "<<m_CurrentObjectId<<std::endl;
    00122         *Consol<<"-----------------------------------------------------------------"<<std::endl;
    00123
    00124 UnGuard
    00125 }
    00126
    00127 ModelType ExManagerModel::FindModelType(std::string FileName)
    00128 {
    00129 Guard(ModelType ExManagerModel::FindModelType(std::string FileName))
    00130         if(FileName.find(".md2")==(FileName.length()-4))return MODEL_MD2;
    00131         if(FileName.find(".md3")==(FileName.length()-4))return MODEL_MD3;
    00132         if(FileName.find(".asc")==(FileName.length()-4))return MODEL_ASC;
    00133         //if(FileName.find(".ase")==(FileName.length()-4))return MODEL_ASE;
    00134         if(FileName.find(".3ds")==(FileName.length()-4))return MODEL_3DS;
    00135         if(FileName.find(".obj")==(FileName.length()-4))return MODEL_OBJ;
    00136         if(FileName.find(".exm")==(FileName.length()-4))return MODEL_EXM;
    00137         return MODEL_UNKNOW;
    00138 UnGuard
    00139 }
    00140
    00141 ExNihilo::ExId ExManagerModel::Load(std::string FileName)
    00142 {
    00143 Guard(ExNihilo::ExId ExManagerModel::Load(std::string FileName))
    00144         return Load(FileName,FileName);
    00145 UnGuard
    00146 }
    00147
    00148 ExNihilo::ExId ExManagerModel::Load(std::string FileName,std::string ObjectName)
    00149 {
    00150 Guard(ExNihilo::ExId ExManagerModel::Load(std::string FileName,std::string ObjectName))
    00151         //Check if model already loaded
    00152         try
    00153         {
    00154                 for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00155                 {
    00156                         if(strcmp(m_ItMap->second->GetName().data(),ObjectName.data())==0)
    00157                         {
    00158                                 return m_ItMap->second->GetId();
    00159                         }
    00160                 }
    00161         }catch(...){}
    00162
    00163         FileName="../Data/Modeles/"+FileName;
    00164         try
    00165         {
    00166                 ExCModel *ModelToLoad;
    00167                 switch(FindModelType(FileName))
    00168                 {
    00169                         case MODEL_MD2:ModelToLoad = new ExCModelMD2;break;
    00170                         case MODEL_MD3:ModelToLoad = new ExCModelMD3;break;
    00171                         case MODEL_ASC:ModelToLoad = new ExCModelASC;break;
    00172                 //      case MODEL_ASE:ModelToLoad = new ExCModelMD2;break;
    00173                         case MODEL_3DS:ModelToLoad = new ExCModel3DS;break;
    00174                         case MODEL_OBJ:ModelToLoad = new ExCModelOBJ;break;
    00175                         case MODEL_EXM:ModelToLoad = new ExCModelEXM;break;
    00176                 }
    00177                 ModelToLoad->SetManagerTexture(ManagerTexture);
    00178                 ModelToLoad->SetFileName(FileName);
    00179                 ModelToLoad->Load(FileName);
    00180                 ModelToLoad->SetName(ObjectName);
    00181                 ExManagerObject<ExCModel *>::Add(ModelToLoad);
    00182                 return ModelToLoad->GetId();
    00183         }
    00184         catch(ExCExpFileNotFound)
    00185         {
    00186                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" File not found"<<std::endl;
    00187         }
    00188         catch(ExCExpFileReadError)
    00189         {
    00190                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" Read file error"<<std::endl;
    00191         }
    00192         catch(...)
    00193         {
    00194                 *Consol<<"ExManagerModel::ExCeption =>"<<FileName<<" Unknow exception"<<std::endl;
    00195         }
    00196         return -1;
    00197 UnGuard
    00198 }
    00199
    00200 ExCAction ExManagerModel::InputCommand(ExCCommand Command)
    00201 {
    00202 Guard(ExCAction ExManagerModel::InputCommand(ExCCommand Command))
    00203         switch(Command.m_Command)
    00204         {
    00205         case KEYBOARD_UP_ARROW_DOWN:
    00206                 return NOTHING;
    00207         case KEYBOARD_UP_ARROW_UP:
    00208                 return NOTHING;
    00209         case KEYBOARD_UP_ARROW_LEFT:
    00210                 return NOTHING;
    00211         case KEYBOARD_UP_ARROW_RIGHT:
    00212                 return NOTHING;
    00213         case KEYBOARD_DOWN_ARROW_DOWN:
    00214                 return NOTHING;
    00215         case KEYBOARD_DOWN_ARROW_UP:
    00216                 return NOTHING;
    00217         case KEYBOARD_DOWN_ARROW_LEFT:
    00218                 return NOTHING;
    00219         case KEYBOARD_DOWN_ARROW_RIGHT:
    00220                 return NOTHING;
    00221         default :return NOTHING;
    00222         }
    00223 UnGuard
    00224 }
    00225
    00226 ExCAction ExManagerModel::InputAction(ExCAction Action)
    00227 {
    00228 Guard(ExCAction ExManagerModel::InputAction(ExCAction Action))
    00229 //std::cout<<"MANAGER MODEL"<<Action;
    00230         try
    00231         {
    00232                 switch(Action.m_Action)
    00233                 {
    00234                 case LIST:
    00235                         List();
    00236                         break;
    00237                 case SET_CURRENT_OBJECT_BY_ID:
    00238                         SetCurrentObject(atoi(Action.m_Param.data()));
    00239                         break;
    00240                 case SET_CURRENT_OBJECT_BY_NAME:
    00241                         SetCurrentObject(Action.m_Param);
    00242                         break;
    00243                 case MODEL_LOAD_WITH_NAME:
    00244                         Load(Action.m_Param,Action.m_Param1);
    00245                         break;
    00246                 case MODEL_LOAD:
    00247                         Load(Action.m_Param);
    00248                         break;
    00249                 case MANAGER_MODEL_RELOAD:
    00250                         Reload();
    00251                         break;
    00252                 default:
    00253                         //*Consol<<"Can not file action in MODEL_ACTION_MAP"<<std::endl;
    00254                         return GetObject(m_CurrentObjectId)->InputAction(Action);
    00255                 }
    00256
    00257                 if(Action.m_NextAction){return *Action.m_NextAction;}
    00258                 else{return NOTHING;}
    00259         }
    00260         catch(...)
    00261         {
    00262                 *Consol<<"ExManagerModel::ExCeption =>> Error input action"<<std::endl;
    00263                 return NOTHING;
    00264         }
    00265 UnGuard
    00266 }
    00267
    00268 ExCModel * ExManagerModel::GetObject(ExNihilo::ExId id)
    00269 {
    00270 Guard(ExCModel *ExManagerModel::GetObject(ExNihilo::ExId id))
    00271         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00272         {
    00273                 if(m_ItMap->second->GetId()==id)return m_ItMap->second;
    00274         }
    00275         return NULL;
    00276 UnGuard
    00277 }
    00278
    00279 ExCModel* ExManagerModel::GetCurrentObject(void)
    00280 {
    00281 Guard(ExCModel* ExManagerModel::GetCurrentObject(void))
    00282         return GetObject(m_CurrentObjectId);
    00283 UnGuard
    00284 }
    00285
    00286 void ExManagerModel::Reload(void)
    00287 {
    00288 Guard(void ExManagerModel::Reload(void))
    00289         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00290         {
    00291                 m_ItMap->second->Load(m_ItMap->second->GetFileName());
    00292         }
    00293 UnGuard
    00294 }
    00295
    00296
    00297