Updated to work with freeglut 2.4.0
[crack-attack.git] / src / LightManager.h
blobc666f7bbcda7e5304121395ecc8130861d609f81
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 #include "glext.h"
34 using namespace std;
36 #include "Displayer.h"
37 #include "SparkleManager.h"
38 #include "CountDownManager.h"
39 #include "X.h"
41 #define LL_BELOW (1 << 0)
42 #define LL_ABOVE (1 << 1)
43 #define LL_LEFT (1 << 2)
44 #define LL_RIGHT (1 << 3)
46 class Light {
47 public:
48 int association;
49 GLfloat location[4];
50 GLfloat brightness[4];
51 bool enabled;
52 bool to_be_enabled;
53 bool attenuated;
56 /* static */ class LightManager {
57 public:
58 static void initialize ( );
59 static void setupBlockLights ( float x, float y );
60 static void setupGarbageLights ( float x, float y, int h, int w );
62 static inline void setupHeadLightPlay ( )
64 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
66 if (!(Game::state & GS_SYNC_WAIT) && CountDownManager::state == -1
67 && !X::crazyLights())
68 return;
69 setupHeadLightPlay_inline_split_();
73 static void setupHeadLightMeta ( );
75 static inline void resetHeadLight ( )
77 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
78 if (headlight_normal) return;
79 resetHeadLight_inline_split_();
83 static inline void timeStepInitialize ( )
85 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
86 for (int n = DC_NUMBER_EXTRA_LIGHTS; n--; ) {
87 if (lights[n].enabled) {
88 glDisable((GLenum) (DC_EXTRA_LIGHT_BASE + n));
89 lights[n].enabled = false;
91 lights[n].association = -1;
92 if (lights[n].attenuated)
93 unattenuateLight(lights[n], n);
96 last_associated = 0;
100 private:
101 static void setupHeadLightPlay_inline_split_ ( );
102 static void resetHeadLight_inline_split_ ( );
104 static inline void associateLight ( Light &light, int a, Mote &mote, int m )
106 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
107 light.association = m;
108 mote.associated_light = a;
110 light.location[0] = mote.x;
111 light.location[1] = mote.y;
112 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_POSITION, light.location);
116 static inline void configureBlockBrightness ( Light &light, int a, Mote &mote,
117 float r )
119 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
120 assert(a >= 0);
121 assert(a < DC_NUMBER_EXTRA_LIGHTS);
123 float brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
124 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE))
125 * mote.brightness;
127 if (mote.light_color == 0) {
128 light.brightness[0] = brightness;
129 light.brightness[1] = brightness;
130 light.brightness[2] = brightness;
132 } else {
133 light.brightness[0] = brightness
134 * Displayer::mote_light_colors[mote.light_color][0];
135 light.brightness[1] = brightness
136 * Displayer::mote_light_colors[mote.light_color][1];
137 light.brightness[2] = brightness
138 * Displayer::mote_light_colors[mote.light_color][2];
141 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
142 light.brightness);
143 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
144 light.brightness);
148 static inline void configureGarbageBrightness ( Light &light, int a,
149 Mote &mote, float r)
151 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
152 assert(a >= 0);
153 assert(a < DC_NUMBER_EXTRA_LIGHTS);
155 float brightness;
156 if (r > 0.0f)
157 brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
158 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE)) * mote.brightness;
159 else
160 brightness = mote.brightness;
162 if (mote.light_color == 0) {
163 light.brightness[0] = brightness;
164 light.brightness[1] = brightness;
165 light.brightness[2] = brightness;
167 } else {
168 light.brightness[0] = brightness
169 * Displayer::mote_light_colors[mote.light_color][0];
170 light.brightness[1] = brightness
171 * Displayer::mote_light_colors[mote.light_color][1];
172 light.brightness[2] = brightness
173 * Displayer::mote_light_colors[mote.light_color][2];
176 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
177 light.brightness);
178 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
179 light.brightness);
183 static inline void attenuateLight ( Light &light, int a )
185 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
186 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
187 DC_MOTE_LIGHT_ATTENUATION);
188 light.attenuated = true;
192 static inline void unattenuateLight ( Light &light, int a )
194 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
195 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
196 0.0f);
197 light.attenuated = false;
201 static Light lights[DC_NUMBER_EXTRA_LIGHTS];
202 static int last_associated;
203 static bool headlight_normal;
206 #endif