Fixes for datatype size on amd64.
[crack-attack.git] / src / LightManager.h
blob24e34451d3d5dae577fb13ee4215e2256a844a60
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"
35 #include "Displayer.h"
36 #include "SparkleManager.h"
37 #include "CountDownManager.h"
38 #include "X.h"
40 #define LL_BELOW (1 << 0)
41 #define LL_ABOVE (1 << 1)
42 #define LL_LEFT (1 << 2)
43 #define LL_RIGHT (1 << 3)
45 class Light {
46 public:
47 int association;
48 GLfloat location[4];
49 GLfloat brightness[4];
50 bool enabled;
51 bool to_be_enabled;
52 bool attenuated;
55 /* static */ class LightManager {
56 public:
57 static void initialize ( );
58 static void setupBlockLights ( float x, float y );
59 static void setupGarbageLights ( float x, float y, int h, int w );
61 static inline void setupHeadLightPlay ( )
63 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
65 if (!(Game::state & GS_SYNC_WAIT) && CountDownManager::state == -1
66 && !X::crazyLights())
67 return;
68 setupHeadLightPlay_inline_split_();
72 static void setupHeadLightMeta ( );
74 static inline void resetHeadLight ( )
76 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
77 if (headlight_normal) return;
78 resetHeadLight_inline_split_();
82 static inline void timeStepInitialize ( )
84 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
85 for (int n = DC_NUMBER_EXTRA_LIGHTS; n--; ) {
86 if (lights[n].enabled) {
87 glDisable((GLenum) (DC_EXTRA_LIGHT_BASE + n));
88 lights[n].enabled = false;
90 lights[n].association = -1;
91 if (lights[n].attenuated)
92 unattenuateLight(lights[n], n);
95 last_associated = 0;
99 private:
100 static void setupHeadLightPlay_inline_split_ ( );
101 static void resetHeadLight_inline_split_ ( );
103 static inline void associateLight ( Light &light, int a, Mote &mote, int m )
105 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
106 light.association = m;
107 mote.associated_light = a;
109 light.location[0] = mote.x;
110 light.location[1] = mote.y;
111 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_POSITION, light.location);
115 static inline void configureBlockBrightness ( Light &light, int a, Mote &mote,
116 float r )
118 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
119 assert(a >= 0);
120 assert(a < DC_NUMBER_EXTRA_LIGHTS);
122 float brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
123 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE))
124 * mote.brightness;
126 if (mote.light_color == 0) {
127 light.brightness[0] = brightness;
128 light.brightness[1] = brightness;
129 light.brightness[2] = brightness;
131 } else {
132 light.brightness[0] = brightness
133 * Displayer::mote_light_colors[mote.light_color][0];
134 light.brightness[1] = brightness
135 * Displayer::mote_light_colors[mote.light_color][1];
136 light.brightness[2] = brightness
137 * Displayer::mote_light_colors[mote.light_color][2];
140 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
141 light.brightness);
142 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
143 light.brightness);
147 static inline void configureGarbageBrightness ( Light &light, int a,
148 Mote &mote, float r)
150 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
151 assert(a >= 0);
152 assert(a < DC_NUMBER_EXTRA_LIGHTS);
154 float brightness;
155 if (r > 0.0f)
156 brightness = (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE - r)
157 * (1.0f / (DC_MOTE_LIGHT_RANGE * DC_MOTE_LIGHT_RANGE)) * mote.brightness;
158 else
159 brightness = mote.brightness;
161 if (mote.light_color == 0) {
162 light.brightness[0] = brightness;
163 light.brightness[1] = brightness;
164 light.brightness[2] = brightness;
166 } else {
167 light.brightness[0] = brightness
168 * Displayer::mote_light_colors[mote.light_color][0];
169 light.brightness[1] = brightness
170 * Displayer::mote_light_colors[mote.light_color][1];
171 light.brightness[2] = brightness
172 * Displayer::mote_light_colors[mote.light_color][2];
175 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_DIFFUSE,
176 light.brightness);
177 glLightfv((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_SPECULAR,
178 light.brightness);
182 static inline void attenuateLight ( Light &light, int a )
184 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
185 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
186 DC_MOTE_LIGHT_ATTENUATION);
187 light.attenuated = true;
191 static inline void unattenuateLight ( Light &light, int a )
193 if (!(MetaState::mode & CM_REALLY_LOW_GRAPHICS)) {
194 glLightf((GLenum) (DC_EXTRA_LIGHT_BASE + a), GL_QUADRATIC_ATTENUATION,
195 0.0f);
196 light.attenuated = false;
200 static Light lights[DC_NUMBER_EXTRA_LIGHTS];
201 static int last_associated;
202 static bool headlight_normal;
205 #endif