desktop file ended up in the wrong place.
[crack-attack.git] / src / LightManager.h
blob32e3316459785f99db337c6a59f73cfca7fd9612
1 /*
2 * LightManager.h
3 * Daniel Nelson - 8/24/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
26 #ifndef LIGHTMANAGER_H
27 #define LIGHTMANAGER_H
29 #include <GL/glut.h>
30 #include <cassert>
32 #ifndef _WIN32
33 #else
34 # include <glext.h>
35 #endif
37 using namespace std;
39 #include "Displayer.h"
40 #include "SparkleManager.h"
41 #include "CountDownManager.h"
42 #include "X.h"
44 #define LL_BELOW (1 << 0)
45 #define LL_ABOVE (1 << 1)
46 #define LL_LEFT (1 << 2)
47 #define LL_RIGHT (1 << 3)
49 class Light {
50 public:
51 int association;
52 GLfloat location[4];
53 GLfloat brightness[4];
54 bool enabled;
55 bool to_be_enabled;
56 bool attenuated;
59 /* static */ class LightManager {
60 public:
61 static void initialize ( );
62 static void setupBlockLights ( float x, float y );
63 static void setupGarbageLights ( float x, float y, int h, int w );
65 static inline void setupHeadLightPlay ( )
67 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
69 if (!(Game::state & GS_SYNC_WAIT) && CountDownManager::state == -1
70 && !X::crazyLights())
71 return;
72 setupHeadLightPlay_inline_split_();
76 static void setupHeadLightMeta ( );
78 static inline void resetHeadLight ( )
80 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
81 if (headlight_normal) return;
82 resetHeadLight_inline_split_();
86 static inline void timeStepInitialize ( )
88 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
89 for (int n = DC_NUMBER_EXTRA_LIGHTS; n--; ) {
90 if (lights[n].enabled) {
91 glDisable((GLenum) (DC_EXTRA_LIGHT_BASE + n));
92 lights[n].enabled = false;
94 lights[n].association = -1;
95 if (lights[n].attenuated)
96 unattenuateLight(lights[n], n);
99 last_associated = 0;
103 private:
104 static void setupHeadLightPlay_inline_split_ ( );
105 static void resetHeadLight_inline_split_ ( );
107 static inline void associateLight ( Light &light, int a, Mote &mote, int m )
109 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
110 light.association = m;
111 mote.associated_light = a;
113 light.location[0] = mote.x;
114 light.location[1] = mote.y;
115 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_POSITION, light.location);
119 static inline void configureBlockBrightness ( Light &light, int a, Mote &mote,
120 float r )
122 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
123 assert(a >= 0);
124 assert(a < DC_NUMBER_EXTRA_LIGHTS);
126 float brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
127 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE))
128 * mote.brightness;
130 if (mote.light_color == 0) {
131 light.brightness[0] = brightness;
132 light.brightness[1] = brightness;
133 light.brightness[2] = brightness;
135 } else {
136 light.brightness[0] = brightness
137 * Displayer::mote_light_colors[mote.light_color][0];
138 light.brightness[1] = brightness
139 * Displayer::mote_light_colors[mote.light_color][1];
140 light.brightness[2] = brightness
141 * Displayer::mote_light_colors[mote.light_color][2];
144 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
145 light.brightness);
146 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
147 light.brightness);
151 static inline void configureGarbageBrightness ( Light &light, int a,
152 Mote &mote, float r)
154 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
155 assert(a >= 0);
156 assert(a < DC_NUMBER_EXTRA_LIGHTS);
158 float brightness;
159 if (r > 0.0f)
160 brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
161 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE)) * mote.brightness;
162 else
163 brightness = mote.brightness;
165 if (mote.light_color == 0) {
166 light.brightness[0] = brightness;
167 light.brightness[1] = brightness;
168 light.brightness[2] = brightness;
170 } else {
171 light.brightness[0] = brightness
172 * Displayer::mote_light_colors[mote.light_color][0];
173 light.brightness[1] = brightness
174 * Displayer::mote_light_colors[mote.light_color][1];
175 light.brightness[2] = brightness
176 * Displayer::mote_light_colors[mote.light_color][2];
179 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
180 light.brightness);
181 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
182 light.brightness);
186 static inline void attenuateLight ( Light &light, int a )
188 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
189 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
190 DC_MOTE_LIGHT_ATTENUATION);
191 light.attenuated = true;
195 static inline void unattenuateLight ( Light &light, int a )
197 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
198 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
199 0.0f);
200 light.attenuated = false;
204 static Light lights[DC_NUMBER_EXTRA_LIGHTS];
205 static int last_associated;
206 static bool headlight_normal;
209 #endif