initial commit, eq circuit emulator
[eqemu] / src / scene.cc
1 /*
2 eqemu - electronic queue system emulator
3 Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>,
4                     Eleni-Maria Stea <eleni@mutantstargoat.com>
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include "scene.h"
23
24 Scene::~Scene()
25 {
26         for(size_t i=0; i<objects.size(); i++) {
27                 delete objects[i];
28         }
29         for(size_t i=0; i<meshes.size(); i++) {
30                 delete meshes[i];
31         }
32 }
33
34 bool Scene::load(const char *fname)
35 {
36         FILE *fp = fopen(fname, "rb");
37         if(!fp) {
38                 fprintf(stderr, "failed to open scene file: %s\n", fname);
39                 return false;
40         }
41
42         bool res = load_obj(fp);
43         fclose(fp);
44         return res;
45 }
46
47 void Scene::add_object(Object *obj)
48 {
49         objects.push_back(obj);
50 }
51
52 void Scene::add_mesh(Mesh *mesh)
53 {
54         meshes.push_back(mesh);
55 }
56
57 int Scene::get_num_objects() const
58 {
59         return (int)objects.size();
60 }
61
62 int Scene::get_num_meshes() const
63 {
64         return (int)meshes.size();
65 }
66
67 Object *Scene::get_object(int idx) const
68 {
69         return objects[idx];
70 }
71
72 Object *Scene::get_object(const char *name) const
73 {
74         for(size_t i=0; i<objects.size(); i++) {
75                 if(strcmp(objects[i]->get_name(), name) == 0) {
76                         return objects[i];
77                 }
78         }
79         return 0;
80 }
81
82 bool Scene::remove_object(Object *obj)
83 {
84         for(size_t i=0; i<objects.size(); i++) {
85                 if(objects[i] == obj) {
86                         objects.erase(objects.begin() + i);
87                         return true;
88                 }
89         }
90         return false;
91 }
92
93 Mesh *Scene::get_mesh(int idx) const
94 {
95         return meshes[idx];
96 }
97
98 void Scene::update(long msec)
99 {
100 }
101
102 void Scene::render() const
103 {
104         for(size_t i=0; i<objects.size(); i++) {
105                 objects[i]->render();
106         }
107 }