Didn't set the version as a string
[crack-attack.git] / src / LightManager.h
blob34a727b47fdcfe6b471e77b1a20536c52ce51d8f
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 (!(Game::state & GS_SYNC_WAIT) && CountDownManager::state == -1
68 && !X::crazyLights())
69 return;
70 setupHeadLightPlay_inline_split_();
73 static void setupHeadLightMeta ( );
75 static inline void resetHeadLight ( )
77 if (headlight_normal) return;
78 resetHeadLight_inline_split_();
81 static inline void timeStepInitialize ( )
83 for (int n = DC_NUMBER_EXTRA_LIGHTS; n--; ) {
84 if (lights[n].enabled) {
85 glDisable((GLenum) (DC_EXTRA_LIGHT_BASE + n));
86 lights[n].enabled = false;
88 lights[n].association = -1;
89 if (lights[n].attenuated)
90 unattenuateLight(lights[n], n);
93 last_associated = 0;
96 private:
97 static void setupHeadLightPlay_inline_split_ ( );
98 static void resetHeadLight_inline_split_ ( );
100 static inline void associateLight ( Light &light, int a, Mote &mote, int m )
102 light.association = m;
103 mote.associated_light = a;
105 light.location[0] = mote.x;
106 light.location[1] = mote.y;
107 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_POSITION, light.location);
110 static inline void configureBlockBrightness ( Light &light, int a, Mote &mote,
111 float r )
113 assert(a >= 0);
114 assert(a < DC_NUMBER_EXTRA_LIGHTS);
116 float brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
117 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE))
118 * mote.brightness;
120 if (mote.light_color == 0) {
121 light.brightness[0] = brightness;
122 light.brightness[1] = brightness;
123 light.brightness[2] = brightness;
125 } else {
126 light.brightness[0] = brightness
127 * Displayer::mote_light_colors[mote.light_color][0];
128 light.brightness[1] = brightness
129 * Displayer::mote_light_colors[mote.light_color][1];
130 light.brightness[2] = brightness
131 * Displayer::mote_light_colors[mote.light_color][2];
134 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
135 light.brightness);
136 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
137 light.brightness);
140 static inline void configureGarbageBrightness ( Light &light, int a,
141 Mote &mote, float r)
143 assert(a >= 0);
144 assert(a < DC_NUMBER_EXTRA_LIGHTS);
146 float brightness;
147 if (r > 0.0f)
148 brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
149 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE)) * mote.brightness;
150 else
151 brightness = mote.brightness;
153 if (mote.light_color == 0) {
154 light.brightness[0] = brightness;
155 light.brightness[1] = brightness;
156 light.brightness[2] = brightness;
158 } else {
159 light.brightness[0] = brightness
160 * Displayer::mote_light_colors[mote.light_color][0];
161 light.brightness[1] = brightness
162 * Displayer::mote_light_colors[mote.light_color][1];
163 light.brightness[2] = brightness
164 * Displayer::mote_light_colors[mote.light_color][2];
167 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
168 light.brightness);
169 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
170 light.brightness);
173 static inline void attenuateLight ( Light &light, int a )
175 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
176 DC_MOTE_LIGHT_ATTENUATION);
177 light.attenuated = true;
180 static inline void unattenuateLight ( Light &light, int a )
182 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
183 0.0f);
184 light.attenuated = false;
187 static Light lights[DC_NUMBER_EXTRA_LIGHTS];
188 static int last_associated;
189 static bool headlight_normal;
192 #endif