eqemu
view src/scene.cc @ 6:977bc1cb055b
almost done
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 18 Jul 2014 02:35:06 +0300 |
parents | 3d3656360a82 |
children | 2656099aff12 |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "scene.h"
6 Scene::~Scene()
7 {
8 for(size_t i=0; i<objects.size(); i++) {
9 delete objects[i];
10 }
11 for(size_t i=0; i<meshes.size(); i++) {
12 delete meshes[i];
13 }
14 }
16 bool Scene::load(const char *fname)
17 {
18 FILE *fp = fopen(fname, "rb");
19 if(!fp) {
20 fprintf(stderr, "failed to open scene file: %s\n", fname);
21 return false;
22 }
24 bool res = load_obj(fp);
25 fclose(fp);
26 return res;
27 }
29 void Scene::add_object(Object *obj)
30 {
31 objects.push_back(obj);
32 }
34 void Scene::add_mesh(Mesh *mesh)
35 {
36 meshes.push_back(mesh);
37 }
39 int Scene::get_num_objects() const
40 {
41 return (int)objects.size();
42 }
44 int Scene::get_num_meshes() const
45 {
46 return (int)meshes.size();
47 }
49 Object *Scene::get_object(int idx) const
50 {
51 return objects[idx];
52 }
54 Object *Scene::get_object(const char *name) const
55 {
56 for(size_t i=0; i<objects.size(); i++) {
57 if(strcmp(objects[i]->get_name(), name) == 0) {
58 return objects[i];
59 }
60 }
61 return 0;
62 }
64 bool Scene::remove_object(Object *obj)
65 {
66 for(size_t i=0; i<objects.size(); i++) {
67 if(objects[i] == obj) {
68 objects.erase(objects.begin() + i);
69 return true;
70 }
71 }
72 return false;
73 }
75 Mesh *Scene::get_mesh(int idx) const
76 {
77 return meshes[idx];
78 }
80 void Scene::update(long msec)
81 {
82 }
84 void Scene::render() const
85 {
86 for(size_t i=0; i<objects.size(); i++) {
87 objects[i]->render();
88 }
89 }