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

# ExManagerEntity.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: ExManagerEntity.cpp,v 1.9 2002/12/03 22:40:03 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExManagerEntity.h"
    00025
    00026 bool ExManagerEntity::m_flag = false;
    00027 ExManagerEntity* ExManagerEntity::m_instance = NULL;
    00028
    00029 ExManagerEntity* ExManagerEntity::CreateSingleton(void){
    00030 Guard(ExManagerEntity* ExManagerEntity::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 ExManagerEntity; // 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 ExManagerEntity::ExManagerEntity(void)
    00044 {
    00045 }
    00046
    00047 ExManagerEntity::~ExManagerEntity(void)
    00048 {
    00049 }
    00050
    00051 void ExManagerEntity::Reset(void)
    00052 {
    00053         ExManagerObject<ExCEntity *>::Reset();
    00054 }
    00055
    00056 void ExManagerEntity::Init(void)
    00057 {
    00058 Guard(void ExManagerEntity::Init(void))
    00059         ExManagerObject<ExCEntity *>::Init();
    00060 UnGuard
    00061 }
    00062
    00063 EntityType ExManagerEntity::GetEntityType(std::string FileName)
    00064 {
    00065         std::string buffstring;
    00066         buffstring=ExNihilo::ExtracStringValueFromFile(FileName,"<Type>","<#Type>");
    00067         if(strcmpi(buffstring.data(),"ExCEntity")==0)return ENTITY;
    00068         if(strcmpi(buffstring.data(),"ExCGroupEntity")==0)return ENTITY_GROUP;
    00069         return ENTITY_UNKNOWN;
    00070 }
    00071
    00072 void ExManagerEntity::Draw(void)
    00073 {
    00074         //Draw here only if PVS is not active
    00075         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00076         {
    00077                 m_ItMap->second->Draw();
    00078         }
    00079 }
    00080
    00081
    00082 void ExManagerEntity::Load(std::string FileName)
    00083 {
    00084 Guard(void ExManagerEntity::Load(std::string FileName))
    00085         ExCEntity *Entity;
    00086         switch(GetEntityType(FileName))
    00087         {
    00088         case ENTITY:    Entity= new ExCEntity;break;
    00089         case ENTITY_GROUP:
    00090                 //Entity = new ExCGroupEntity;
    00091                 LoadGroupe(FileName);
    00092                 return;
    00093                 break;
    00094         case ENTITY_UNKNOWN:std::cout<<"Bad file type"<<std::endl;return;
    00095         }
    00096
    00097         Entity->SetManagerGizmo(ManagerGizmo);
    00098
    00099         Entity->SetManagerMesh(ManagerMesh);
    00100
    00101         Entity->SetManagerModel(ManagerModel);
    00102
    00103         Entity->SetManagerId(ManagerId);
    00104
    00105         Entity->SetFileName(FileName);
    00106
    00107         if(Entity->LoadFile(FileName))Add(Entity);
    00108 UnGuard
    00109 }
    00110 void ExManagerEntity::LoadGroupe(std::string FileName)
    00111 {
    00112 Guard(void ExManagerEntity::LoadGroupe(std::string FileName))
    00113         Groupe Gr;
    00114         ExCEntity       TmpEntity,*TmpEntity2;
    00115         Gr.PropGroupe.SetFileName(FileName);
    00116         std::ifstream fin;
    00117         std::string buffstring;
    00118         char b[256];
    00119         fin.open(FileName.data(),std::ios::in);
    00120         if(fin.is_open())
    00121         {
    00122                 try
    00123                 {
    00124                         //----Read Type
    00125
    00126                         memset(b,0,255);fin.getline(b,256,'\n');
    00127                         //----Read File property
    00128                         memset(b,0,255);fin.getline(b,256,'\n');
    00129                         Gr.PropGroupe.m_FileProperty=ExNihilo::ExtracValueFromSring(b,"<ObjectProperty>","<#ObjectProperty>");
    00130                         //----Read File MEsh
    00131                         memset(b,0,255);fin.getline(b,256,'\n');
    00132                         Gr.PropGroupe.m_FileMesh=ExNihilo::ExtracValueFromSring(b,"<ObjectGraphic>","<#ObjectGraphic>");
    00133                         //----Read File Gizmo
    00134                         memset(b,0,255);fin.getline(b,256,'\n');
    00135                         Gr.PropGroupe.m_FileGizmo=ExNihilo::ExtracValueFromSring(b,"<CollisionGizmo>","<#CollisionGizmo>");
    00136                         //read property later in other file
    00137                         //----Read File Name
    00138                         memset(b,0,255);fin.getline(b,256,'\n');
    00139                         Gr.PropGroupe.SetName(ExNihilo::ExtracValueFromSring(b,"<ObjectName>","<#ObjectName>"));
    00140                         //---- Read Position
    00141                         memset(b,0,255);fin.getline(b,256,'\n');
    00142                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Position>","<#Position>");
    00143                         Gr.PropGroupe.m_Position.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00144                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00145                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00146                         //---- Read Angle
    00147                         memset(b,0,255);fin.getline(b,256,'\n');
    00148                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Angle>","<#Angle>");
    00149                         Gr.PropGroupe.m_Angle.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00150                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00151                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00152                         //---- Read scale
    00153                         memset(b,0,255);fin.getline(b,256,'\n');
    00154                         buffstring=ExNihilo::ExtracValueFromSring(b,"<Scale>","<#Scale>");
    00155                         Gr.PropGroupe.m_Scale.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00156                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00157                                 ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00158                         //read number entity
    00159                         memset(b,0,255);fin.getline(b,256,'\n');
    00160                         Gr.m_NumberEntity=ExNihilo::ExtractIntValueFromSring(b,"<NumberEntity>","<#NumberEntity>");
    00161                         //read entity
    00162                         for(int i=0;i<Gr.m_NumberEntity;i++)
    00163                         {
    00164
    00165                                 TmpEntity2= new ExCEntity;
    00166
    00167                                 TmpEntity2->m_HasGroupe=true;
    00168                                 TmpEntity2->m_GroupeName=TmpEntity.GetName();
    00169                                 TmpEntity2->SetManagerGizmo(ManagerGizmo);
    00170
    00171                                 TmpEntity2->SetManagerMesh(ManagerMesh);
    00172
    00173                                 TmpEntity2->SetManagerModel(ManagerModel);
    00174
    00175                                 TmpEntity2->SetManagerId(ManagerId);
    00176
    00177                                 TmpEntity2->SetFileName(FileName);
    00178
    00179                                 TmpEntity2->LoadFile(&fin);
    00180
    00181                                 TmpEntity2->SetPosition(TmpEntity2->GetPosition()+Gr.PropGroupe.GetPosition());
    00182                                 TmpEntity2->m_Angle=TmpEntity2->m_Angle+Gr.PropGroupe.m_Angle;
    00183                                 TmpEntity2->m_Scale=TmpEntity2->m_Scale+Gr.PropGroupe.m_Scale;
    00184
    00185
    00186                                 Add(TmpEntity2);
    00187                                 Gr.m_VecEntity.push_back(TmpEntity2);
    00188                         }
    00189
    00190                         fin.close();
    00191                 }
    00192                 catch(ExCExpStringNotFound)
    00193                 {
    00194                         std::cout<<"ExCExpStringNotFound"<<std::endl;
    00195                 }
    00196                 catch(...)
    00197                 {
    00198                         std::cout<<"ExCExpFileReadError"<<std::endl;
    00199                         throw ExCExpFileReadError();
    00200                 }
    00201         }else throw   ExCExpFileNotFound();
    00202         m_VecGroupe.push_back(Gr);
    00203 UnGuard
    00204 }
    00205
    00206
    00207
    00208
    00209
    00210
    00211 ExCAction ExManagerEntity::InputCommand(ExCCommand Command)
    00212 {
    00213 Guard(ExCAction ExManagerEntity::InputCommand(ExCCommand Command))
    00214                 return NOTHING;
    00215 UnGuard
    00216 }
    00217
    00218 ExCAction ExManagerEntity::InputAction(ExCAction Action)
    00219 {
    00220 Guard(ExCAction ExManagerEntity::InputAction(ExCAction Action))
    00221         switch(Action.m_Action)
    00222         {
    00223         case MANAGER_ENTITY_RELOAD:
    00224                 Reload();
    00225                 break;
    00226         case MANAGER_ENTITY_SET_CURRENT_OBJECT_BY_ID:
    00227                 SetCurrentObject(atoi(Action.m_Param.data()));
    00228                 break;
    00229         case MANAGER_ENTITY_SET_CURRENT_OBJECT_BY_NAME:
    00230                 SetCurrentObject(Action.m_Param);
    00231                 break;
    00232         case ENTITY_HIDE:
    00233                 GetCurrentObject()->SetVisibleState(false);
    00234                 break;
    00235         case ENTITY_SHOW:
    00236                 GetCurrentObject()->SetVisibleState(true);
    00237                 break;
    00238         case MANAGER_ENTITY_RESET:
    00239                 Reset();
    00240                 break;
    00241         default:
    00242                 *Consol<<"Can not file action in ENTITY_ACTION_MAP"<<std::endl;
    00243         break;
    00244         }
    00245         if(Action.m_NextAction){return *Action.m_NextAction;}
    00246         else{return NOTHING;}
    00247 UnGuard
    00248 }
    00249
    00250 ExCEntity * ExManagerEntity::GetObject(ExNihilo::ExId id)
    00251 {
    00252 Guard(ExCEntity *ExManagerEntity::GetObject(ExNihilo::ExId id))
    00253         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00254         {
    00255                 if(m_ItMap->second->GetId()==id)return m_ItMap->second;
    00256         }
    00257         return NULL;
    00258 UnGuard
    00259 }
    00260
    00261 void  ExManagerEntity::Reload(void)
    00262 {
    00263 Guard(void  ExManagerEntity::Reload(void))
    00264         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
    00265         {
    00266                 if(!m_ItMap->second->m_HasGroupe)
    00267                 {
    00268                         m_ItMap->second->LoadFile(m_ItMap->second->GetFileName());
    00269                 }
    00270         }
    00271         try
    00272         {
    00273                 //chaque groupe
    00274                 for(unsigned int  i=0;i<m_VecGroupe.size();i++)
    00275                 {
    00276                         Groupe oldgr=m_VecGroupe.at(i);
    00277                         //reload groupe
    00278                         std::ifstream fin;
    00279                         std::string buffstring;
    00280                         int m_NumberEntity;
    00281                         char b[256];
    00282                         fin.open(m_VecGroupe.at(i).PropGroupe.GetFileName().data(),std::ios::in);
    00283                         if(fin.is_open())
    00284                         {
    00285
    00286                                 memset(b,0,255);fin.getline(b,256,'\n');//----Read Type
    00287                                 memset(b,0,255);fin.getline(b,256,'\n');//----Read File property
    00288                                 m_VecGroupe.at(i).PropGroupe.m_FileProperty=ExNihilo::ExtracValueFromSring(b,"<ObjectProperty>","<#ObjectProperty>");
    00289                                 memset(b,0,255);fin.getline(b,256,'\n');//----Read File MEsh
    00290                                 m_VecGroupe.at(i).PropGroupe.m_FileMesh=ExNihilo::ExtracValueFromSring(b,"<ObjectGraphic>","<#ObjectGraphic>");
    00291                                 memset(b,0,255);fin.getline(b,256,'\n');//----Read File Gizmo
    00292                                 m_VecGroupe.at(i).PropGroupe.m_FileGizmo=ExNihilo::ExtracValueFromSring(b,"<CollisionGizmo>","<#CollisionGizmo>");
    00293                                 memset(b,0,255);fin.getline(b,256,'\n');//----Read File Name
    00294                                 m_VecGroupe.at(i).PropGroupe.SetName(ExNihilo::ExtracValueFromSring(b,"<ObjectName>","<#ObjectName>"));
    00295                                 memset(b,0,255);fin.getline(b,256,'\n');//---- Read Position
    00296                                 buffstring=ExNihilo::ExtracValueFromSring(b,"<Position>","<#Position>");
    00297                                 m_VecGroupe.at(i).PropGroupe.m_Position.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00298                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00299                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00300                                 memset(b,0,255);fin.getline(b,256,'\n');//---- Read Angle
    00301                                 buffstring=ExNihilo::ExtracValueFromSring(b,"<Angle>","<#Angle>");
    00302                                 m_VecGroupe.at(i).PropGroupe.m_Angle.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00303                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00304                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00305                                 memset(b,0,255);fin.getline(b,256,'\n');//---- Read scale
    00306                                 buffstring=ExNihilo::ExtracValueFromSring(b,"<Scale>","<#Scale>");
    00307                                 m_VecGroupe.at(i).PropGroupe.m_Scale.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00308                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00309                                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00310                                 memset(b,0,255);fin.getline(b,256,'\n');//read number entity
    00311                                 m_NumberEntity=ExNihilo::ExtractIntValueFromSring(b,"<NumberEntity>","<#NumberEntity>");
    00312                         }else throw   ExCExpFileNotFound();
    00313                         std::cout<<"Reload group pro ok"<<std::endl;
    00314                         //chaque entite est rechargée
    00315                         for(unsigned int j=0;j<m_VecGroupe.at(i).m_VecEntity.size();j++)
    00316                         {
    00317
    00318                                 for(int k=0;k<m_NumberEntity;k++)
    00319                                 {
    00320                                         /*m_VecGroupe.at(i).m_VecEntity.at(k)->LoadFile(&fin);
    00321                                         m_VecGroupe.at(i).m_VecEntity.at(k)->SetPosition(m_VecGroupe.at(i).m_VecEntity.at(k)->GetPosition()+m_VecGroupe.at(i).PropGroupe.GetPosition());
    00322                                         m_VecGroupe.at(i).m_VecEntity.at(k)->m_Angle=m_VecGroupe.at(i).m_VecEntity.at(k)->m_Angle+m_VecGroupe.at(i).PropGroupe.m_Angle;
    00323                                         m_VecGroupe.at(i).m_VecEntity.at(k)->m_Scale=m_VecGroupe.at(i).m_VecEntity.at(k)->m_Scale+m_VecGroupe.at(i).PropGroupe.m_Scale;
    00324                                         */
    00325                                         m_VecGroupe.at(i).m_VecEntity.at(k)->SetPosition(m_VecGroupe.at(i).m_VecEntity.at(k)->GetPosition()+m_VecGroupe.at(i).PropGroupe.GetPosition()-oldgr.PropGroupe.GetPosition());
    00326                                         m_VecGroupe.at(i).m_VecEntity.at(k)->m_Angle=m_VecGroupe.at(i).m_VecEntity.at(k)->m_Angle+m_VecGroupe.at(i).PropGroupe.m_Angle-oldgr.PropGroupe.m_Angle;
    00327                                         m_VecGroupe.at(i).m_VecEntity.at(k)->m_Scale=m_VecGroupe.at(i).m_VecEntity.at(k)->m_Scale+m_VecGroupe.at(i).PropGroupe.m_Scale-oldgr.PropGroupe.m_Scale;
    00328
    00329                                 }
    00330                         }
    00331                         fin.close();
    00332                 }
    00333         }
    00334         catch(ExCExpStringNotFound){std::cout<<"ExCExpStringNotFound"<<std::endl;}
    00335         catch(...){     std::cout<<"ExCExpFileReadError"<<std::endl;throw ExCExpFileReadError();}
    00336
    00337
    00338 UnGuard
    00339 }
    00340
    00341 ExCEntity* ExManagerEntity::GetCurrentObject(void)
    00342 {
    00343 Guard(ExCEntity* ExManagerEntity::GetCurrentObject(void))
    00344                 return GetObject(m_CurrentObjectId);
    00345 UnGuard
    00346 }