added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / dsys / part.cpp
1 /*
2 This file is part of the 3dengfx demo system.
3
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
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 2 of the License, or
9 (at your option) any later version.
10
11 This program demo 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "3dengfx_config.h"
22
23 #include <iostream>
24 #include <cstring>
25 #include "part.hpp"
26 #include "3dengfx/3dengfx.hpp"
27
28 using namespace dsys;
29
30 Part::Part(const char *name) {
31         if(name) {
32                 this->name = new char[strlen(name)+1];
33                 strcpy(this->name, name);
34         } else {
35                 this->name = 0;
36         }
37         
38         target = RT_FB;
39         clear_fb = false;
40         //timer_reset(&timer);
41 }
42
43 Part::~Part() {
44         if(name) delete [] name;
45 }
46
47
48 void Part::pre_draw() {
49         if(target != RT_FB) {
50                 ::set_render_target(dsys::tex[target]);
51         }
52         
53         if(clear_fb) {
54                 clear(Color(0, 0, 0));
55                 clear_zbuffer_stencil(1.0f, 0);
56         }
57         time = dsys::get_demo_time() - start_time;
58         //timer_getmsec(&timer);
59 }
60
61 void Part::post_draw() {
62         if(target != RT_FB) {
63                 ::set_render_target(0);
64         }
65
66         // reset states
67         for(int i=0; i<8; i++) {
68                 glDisable(GL_LIGHT0 + i);
69         }
70
71         set_ambient_light(0.0f);
72 }
73
74 void Part::set_name(const char *name) {
75         this->name = new char[strlen(name)+1];
76         strcpy(this->name, name);
77 }
78
79 const char *Part::get_name() const {
80         return name;
81 }
82
83 void Part::set_clear(bool enable) {
84         clear_fb = enable;
85 }
86
87 void Part::start() {
88         //timer_start(&timer);
89         start_time = dsys::get_demo_time();
90 }
91
92 void Part::stop() {
93         //timer_stop(&timer);
94 }
95
96 void Part::set_target(RenderTarget targ) {
97         target = targ;
98 }
99
100 void Part::update_graphics() {
101         pre_draw();
102         draw_part();
103         post_draw();
104 }
105
106 bool Part::operator <(const Part &part) const {
107         if(!name) return true;
108         if(!part.name) return false;
109         return strcmp(name, part.name) < 0;
110 }