Bubba-3D  0.9.0
Awesome game engine!
Scene.cpp
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 #include "Scene.h"
18 #include "GameObject.h"
19 
20 Scene::Scene()
21 {
22 }
23 
24 
25 Scene::~Scene()
26 {
27 }
28 
29 void Scene::addShadowCaster(GameObject* object) {
30  shadowCasters.push_back(object);
31  allObjects.push_back(object);
32 }
33 
34 std::vector<GameObject*> Scene::getShadowCasters() {
35  return shadowCasters;
36 }
37 
38 void Scene::addTransparentObject(GameObject* object){
39  transparentObjects.push_back(object);
40  allObjects.push_back(object);
41 }
42 
43 std::vector<GameObject*> Scene::getTransparentObjects() {
44  return transparentObjects;
45 }
46 
47 std::vector<GameObject*> Scene::getGameObjects() {
48  return allObjects;
49 }
50 
51 
52 void Scene::update(float dt, std::vector<GameObject*> *toDelete) {
53  removeDirty(&shadowCasters, toDelete);
54  removeDirty(&transparentObjects, toDelete);
55  removeDirty(&allObjects, toDelete);
56 
57  auto sCasters = shadowCasters;
58  auto tObjects = transparentObjects;
59 
60  for(auto &object : sCasters ) {
61  object->update(dt);
62  }
63 
64  for(auto &object : tObjects ) {
65  object->update(dt);
66  }
67 }
68 
69 void Scene::removeDirty(std::vector<GameObject*> *v, std::vector<GameObject*> *toDelete) {
70  for(auto i = v->begin(); i < v->end(); )
71  {
72  if((*i)->isDirty())
73  {
74  toDelete->push_back(*i);
75  i = v->erase(i);
76  }
77  else {
78  i++;
79  }
80  }
81 }
A class for containing all information about a object in the game world.
Definition: GameObject.h:67