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

# ExManagerEntite.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: ExManagerEntite.cpp,v 1.13 2002/08/14 15:20:52 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExManagerEntite.h"
    00025
    00026 ExManagerEntite::ExManagerEntite(void)
    00027 {
    00028 Guard(ExManagerEntite::ExManagerEntite(void))
    00029         m_VecPObject    = new std::vector<ExCEntite *>;
    00030         m_VecEntite             = new std::vector<ExCEntite>;
    00031         m_VecComposed   = new std::vector<ExCComposed>;
    00032         m_VecSkeleton   = new std::vector<ExSkeleton>;
    00033         m_CurrentEntite=-1;
    00034 UnGuard
    00035 }
    00036
    00037
    00038 ExManagerEntite::~ExManagerEntite(void)
    00039 {
    00040 Guard(ExManagerEntite::~ExManagerEntite(void))
    00041 UnGuard
    00042 }
    00043
    00044 //---------------------------------------------------------
    00045 bool ExManagerEntite::LoadModel(const char * FileName)
    00046 {
    00047 Guard(bool ExManagerEntite::LoadModel(const char *FileName))
    00048         std::string     SFileName(FileName);
    00049         //cheking file extension to know model type
    00050         if(SFileName.find(".md2")==(SFileName.length()-4))
    00051         {
    00052         }
    00053         if(SFileName.find(".md3")==(SFileName.length()-4))
    00054         {
    00055         }
    00056         if(SFileName.find(".asc")==(SFileName.length()-4))
    00057         {
    00058         }
    00059         if(SFileName.find(".ase")==(SFileName.length()-4))
    00060         {
    00061         }
    00062         if(SFileName.find(".3ds")==(SFileName.length()-4))
    00063         {
    00064         }
    00065         if(SFileName.find(".obj")==(SFileName.length()-4))
    00066         {
    00067         }
    00068         *Consol<<SFileName.data()<<std::endl;
    00069         return true;
    00070 UnGuard
    00071 }
    00072
    00073 void  ExManagerEntite::Reset(void)
    00074 {
    00075 Guard(void  ExManagerEntite::Reset(void))
    00076         m_VecPObject->clear();
    00077         m_VecEntite->clear();
    00078         m_VecComposed->clear();
    00079         m_VecSkeleton->clear();
    00080         RecordToManagerPVS();
    00081 UnGuard
    00082 }
    00083
    00084 void ExManagerEntite::ListEntite(void)
    00085 {
    00086 Guard(void ExManagerEntite::ListEntite(void))
    00087         int i=0;
    00088         *Consol<<"**********************"<<std::endl;
    00089         *Consol<<"*List of all entites *"<<std::endl;
    00090         *Consol<<"**********************"<<std::endl;
    00091         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00092         {
    00093                 *Consol<<"Object ID:"<<m_VecPObject->at(i)->GetId()<<" Name:"<<m_VecPObject->at(i)->GetName();
    00094                 *Consol<<" Postion X:"<<m_VecPObject->at(i)->GetPosition().GetX()<<" Y:"<<m_VecPObject->at(i)->GetPosition().GetY();
    00095                 *Consol<<" Z:"<<m_VecPObject->at(i)->GetPosition().GetZ()<<std::endl;
    00096         }
    00097         *Consol<<"**********************"<<std::endl;
    00098         *Consol<<"Current Entite Id :"<<m_CurrentEntite<<std::endl;
    00099         *Consol<<"**********************"<<std::endl;
    00100 UnGuard
    00101 }
    00102
    00103 void  ExManagerEntite::Init(void)
    00104 {
    00105 Guard(void  ExManagerEntite::Init(void))
    00106         RecordToManagerPVS();
    00107 UnGuard
    00108 }
    00109
    00110
    00111 void ExManagerEntite::LoadAsc(const char *FileName)
    00112 {
    00113 Guard(void ExManagerEntite::LoadAsc(const char *FileName))
    00114         char *Buffer;
    00115         ExCComposed Entite;
    00116         Entite.SetManagerTexture(ManagerTexture);
    00117         Buffer= new char[strlen(FileName)+40];
    00118 #ifdef UNIX_SRC
    00119         sprintf(Buffer, PREFIX "/ExNihilo/Data/Modeles/%s",FileName);
    00120 #else
    00121         sprintf(Buffer, "../Data/Modeles/%s",FileName);
    00122 #endif
    00123         if(Entite.LoadAsc(Buffer))
    00124         {
    00125                 Add(Entite);
    00126         }else
    00127         {
    00128                 *Consol<<"File not found"<<std::endl;
    00129         }
    00130 UnGuard
    00131 }
    00132
    00133 void ExManagerEntite::MakeGlListForAll(void)
    00134 {
    00135         int i=0;
    00136         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00137         {
    00138                 m_VecPObject->at(i)->MakeList();
    00139         }
    00140 }
    00141
    00142 bool  ExManagerEntite::Init(char * FileName)
    00143 {
    00144 Guard(bool  ExManagerEntite::Init(char * FileName))
    00145         //openf file and load object
    00146         return true;
    00147 UnGuard
    00148 }
    00149
    00150
    00151 ExNihilo::ExId  ExManagerEntite::NewObject(void)
    00152 {
    00153 Guard(ExNihilo::ExId  ExManagerEntite::NewObject(void))
    00154         char *Name;
    00155         ExCEntite Entite1;
    00156         Name= new char[strlen("ENTITE ")+3];
    00157         sprintf(Name,"ENTITE %d",m_VecEntite->size()+1);
    00158         ManagerId->RecordObject(Entite1);
    00159         Entite1.SetManagerTexture(ManagerTexture);
    00160         Entite1.SetCurrentState(true);
    00161         m_VecEntite->push_back(Entite1);
    00162         m_VecPObject->push_back(&m_VecEntite->at(m_VecEntite->size()-1));
    00163         Get(m_CurrentEntite)->SetCurrentState(false);
    00164         m_CurrentEntite=Entite1.GetId();
    00165         return m_CurrentEntite;
    00166 UnGuard
    00167 }
    00168
    00169 ExNihilo::ExId  ExManagerEntite::Add(ExCEntite Object)
    00170 {
    00171 Guard(ExNihilo::ExId ExManagerEntite::Add(ExCEntite Object))
    00172         ManagerId->RecordObject(Object);
    00173         Object.SetManagerTexture(ManagerTexture);
    00174         Object.SetCurrentState(true);
    00175         m_VecEntite->push_back(Object);
    00176         m_CurrentEntite=Object.GetId();
    00177         CreateVecPobject();
    00178         return m_CurrentEntite;
    00179 UnGuard
    00180 }
    00181
    00182 ExNihilo::ExId  ExManagerEntite::Add(ExCComposed Object)
    00183 {
    00184 Guard(ExNihilo::ExId ExManagerEntite::Add(ExCComposed Object))
    00185         ManagerId->RecordObject(Object);
    00186         Object.SetManagerTexture(ManagerTexture);
    00187         Object.SetCurrentState(true);
    00188         m_VecComposed->push_back(Object);
    00189         m_CurrentEntite=Object.GetId();
    00190         CreateVecPobject();
    00191         return m_CurrentEntite;
    00192 UnGuard
    00193 }
    00194
    00195 void ExManagerEntite::CreateVecPobject(void)
    00196 {
    00197         m_VecPObject->clear();
    00198
    00199         int i=0;
    00200         for(m_ItVecEntite=m_VecEntite->begin();m_ItVecEntite!=m_VecEntite->end();m_ItVecEntite++,i++)
    00201         {
    00202                 m_VecPObject->push_back(&m_VecEntite->at(i));
    00203         }
    00204         i=0;
    00205         for(m_ItVecComposed=m_VecComposed->begin();m_ItVecComposed!=m_VecComposed->end();m_ItVecComposed++,i++)
    00206         {
    00207                 m_VecPObject->push_back(&m_VecComposed->at(i));
    00208         }
    00209          *Consol<<"Nuber of Entite :"<<m_VecPObject->size()<<std::endl;
    00210 }
    00211
    00212
    00213
    00214
    00215 ExCEntite *  ExManagerEntite::Get(char * Name)
    00216 {
    00217 Guard(ExCEntite * ExManagerEntite::Get(char * Name))
    00218         int i=0;
    00219         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00220         {
    00221                 if(m_VecPObject->at(i)->GetName()==Name)
    00222                 {
    00223                         return m_VecPObject->at(i);
    00224                 }
    00225         }
    00226         return NULL;
    00227 UnGuard
    00228 }
    00229
    00230
    00231 ExCEntite * ExManagerEntite::Get(ExNihilo::ExId Id)
    00232 {
    00233 Guard(ExCEntite * ExManagerEntite::Get(ExNihilo::ExId Id))
    00234         int i=0;
    00235         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00236         {
    00237                 if(m_VecPObject->at(i)->GetId()==Id)
    00238                 {
    00239                         return m_VecPObject->at(i);
    00240                 }
    00241         }
    00242         return NULL;
    00243 UnGuard
    00244 }
    00245
    00246
    00247
    00248
    00249
    00250 bool  ExManagerEntite::Remove(ExNihilo::ExId Id)
    00251 {
    00252 Guard(bool ExManagerEntite::Remove(ExNihilo::ExId Id))
    00253         int i=0;
    00254         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00255         {
    00256                 if(m_VecPObject->at(i)->GetId()==Id)
    00257                 {
    00258
    00259                         //m_VecPObject->at(i)->erase(m_ItVecEntite);
    00260
    00261                         return true;
    00262                 }
    00263         }
    00264         return false;
    00265 UnGuard
    00266 }
    00267
    00268
    00269 ExCEntite *  ExManagerEntite::GetCurrentEntite(void)
    00270 {
    00271 Guard(ExCEntite *  ExManagerEntite::GetCurrentEntite(void))
    00272         int i=0;
    00273         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00274         {
    00275                 if(m_VecPObject->at(i)->GetId()==m_CurrentEntite)
    00276                 {
    00277                         return m_VecPObject->at(i);
    00278                 }
    00279         }
    00280 UnGuard
    00281 return NULL;
    00282 }
    00283
    00284 void  ExManagerEntite::NextEntite(void)
    00285 {
    00286 Guard(void  ExManagerEntite::NextEntite(void))
    00287         int i=0;
    00288         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00289         {
    00290                 m_VecPObject->at(i)->SetCurrentState(false);
    00291         }
    00292         i=0;
    00293         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00294         {
    00295                 if(m_VecPObject->at(i)->GetId()==m_CurrentEntite)
    00296                 {
    00297                         m_ItVecPObject++;
    00298                         if(m_ItVecPObject==m_VecPObject->end())//this is the last
    00299                         {
    00300                                 m_ItVecPObject=m_VecPObject->begin();
    00301                                 m_CurrentEntite=m_VecPObject->at(0)->GetId();
    00302                                 m_VecPObject->at(0)->SetCurrentState(true);
    00303                                 break;
    00304                         }else
    00305                         {
    00306                                 m_CurrentEntite=m_VecPObject->at(i+1)->GetId();
    00307                                 m_VecPObject->at(i+1)->SetCurrentState(true);
    00308                                 break;
    00309                         }
    00310                         m_ItVecPObject--;
    00311                 }
    00312         }
    00313         *Consol<<"Current Entite :"<<m_CurrentEntite<<std::endl;
    00314 UnGuard
    00315 }
    00316
    00317 void  ExManagerEntite::PrevEntite(void)
    00318 {
    00319 Guard(void  ExManagerEntite::PrevEntite(void))
    00320         int i=0;
    00321         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00322         {
    00323                 m_VecPObject->at(i)->SetCurrentState(false);
    00324         }
    00325         i=0;
    00326         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00327         {
    00328                 if(m_VecPObject->at(i)->GetId()==m_CurrentEntite)
    00329                 {
    00330                         if(m_ItVecPObject==m_VecPObject->begin())
    00331                         {
    00332                                 m_ItVecPObject=m_VecPObject->end()-1;
    00333                         }else
    00334                         {
    00335                                 m_ItVecPObject--;
    00336                         }
    00337                         m_CurrentEntite=m_VecPObject->at(i)->GetId();
    00338                         m_VecPObject->at(i)->SetCurrentState(true);
    00339                 }
    00340         }
    00341         *Consol<<"Current Entite :"<<m_CurrentEntite<<std::endl;
    00342 UnGuard
    00343 }
    00344
    00345 bool  ExManagerEntite::SetCurrentEntite(ExNihilo::ExId Id)
    00346 {
    00347 Guard(void  ExManagerEntite::SetCurrentEntite(ExNihilo::ExId Id))
    00348         //checking if id exist before !!!
    00349         int i=0;
    00350         for(m_ItVecPObject=m_VecPObject->begin();m_ItVecPObject!=m_VecPObject->end();m_ItVecPObject++,i++)
    00351         {
    00352                 if(m_VecPObject->at(i)->GetId()==Id)
    00353                 {
    00354                         m_CurrentEntite=Id;
    00355                         *Consol<<"Current Entite :"<<m_CurrentEntite<<std::endl;
    00356                         return true;
    00357                 }
    00358         }
    00359         *Consol<<"MESSAGE FROM MANAGER ENTITE :: Entite Id :"<<Id<<"not found"<<std::endl;
    00360         return false;
    00361 UnGuard
    00362 }
    00363
    00364 bool  ExManagerEntite::SetCurrentEntiteName(const char *Name)
    00365 {
    00366 Guard(void  ExManagerEntite::SetCurrentEntiteName(const char *Name))
    00367 /*      if(ManagerId->isNameAviable((char *)Name) )
    00368         {
    00369                 ManagerId->RemoveIdName((char *)Name);
    00370                 if(ManagerId->RecordIdName(GetCurrentEntite()->GetId(),(char *)Name))
    00371                 {
    00372                         GetCurrentEntite()->SetName(Name);
    00373                         *Consol<<"MESSAGE FROM MANAGER ENTITE ::Name changed for Entite Id :"<<GetCurrentEntite()->GetId()<<" new name:"<<GetCurrentEntite()->GetName()<<std::endl;
    00374                         return true;
    00375                 }
    00376         }
    00377         *Consol<<"MESSAGE FROM MANAGER ENTITE ::Name already take by Entite Id :"<<ManagerId->GetObjectIdByName((char *)Name)<<std::endl;*/
    00378         return false;
    00379 UnGuard
    00380 }
    00381
    00382