src/Scene.cpp

Go to the documentation of this file.
00001 
00002 #include "Scene.h"
00003 #include "Animator.h"
00004 
00005 
00006 #ifdef DEBUG
00007 __thread long long int Scene::mBounced = 0;
00008 #endif
00009 
00012 Scene::Scene()
00013     : mObjects(),
00014         mLights(),
00015         mTextures(),
00016         mShaders(),
00017         mAnimators(),
00018         mBgColor(),
00019         mCastShadows(true),
00020         mPhysics(),
00021         mFrameNr(0)
00022 {
00023 #ifdef DEBUG
00024     mBounced = 0;
00025 #endif
00026 }
00027 
00028 
00031 Scene::~Scene()
00032 {
00033     clear();
00034 #ifdef DEBUG
00035     LOG("Scene statistics:  bounced " << mBounced << " times");
00036 #endif
00037 }
00038 
00041 void Scene::removeObject(Object * obj)
00042 {
00043     for (std::vector<Object*>::iterator it=mObjects.begin(); it != mObjects.end(); it++)
00044     {
00045         if ((*it) == obj)
00046         {
00047             delete (*it);
00048             mObjects.erase(it);
00049             break;
00050         }
00051     }
00052     mPhysics.remove(obj);
00053 }
00054 
00057 void Scene::removeLight(Light * light)
00058 {
00059     for (std::vector<Light*>::iterator it=mLights.begin(); it != mLights.end(); it++)
00060     {
00061         if ((*it) == light)
00062         {
00063             delete (*it);
00064             mLights.erase(it);
00065             break;
00066         }
00067     }
00068 }
00069 
00070 
00073 void Scene::clear()
00074 {
00075     for (unsigned int i=0; i < mObjects.size(); i++)
00076         delete mObjects[i];
00077     mObjects.clear();
00078 
00079     for (unsigned int i=0; i < mLights.size(); i++)
00080         delete mLights[i];
00081     mLights.clear();
00082 
00083     for(unsigned int i=0; i < mTextures.size(); i++)
00084         delete mTextures[i];
00085     mTextures.clear();
00086 
00087     for(unsigned int i=0; i< mShaders.size(); i++)
00088         delete mShaders[i];
00089     mShaders.clear();
00090 
00091     for(unsigned int i=0; i< mAnimators.size(); i++)
00092         delete mAnimators[i];
00093     mAnimators.clear();
00094 
00095     mFrameNr = 0;
00096 #ifdef DEBUG
00097     mBounced = 0;
00098 #endif
00099 }
00100 
00101 
00104 void Scene::step()
00105 {
00106     // change object properties for the next frame
00107     for(unsigned int i=0; i< mAnimators.size(); i++)
00108         mAnimators[i]->animate(mFrameNr);
00109 
00110     // run physics to update objects
00111     mPhysics.step();
00112     mFrameNr++;
00113 }
00114 
00115 

Generated on Fri Feb 1 00:01:42 2008 for Grayfall by  doxygen 1.5.1