3 * Daniel Nelson - 8/24/0
5 * Copyright (C) 2000 Daniel Nelson
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
26 #ifndef LIGHTMANAGER_H
27 #define LIGHTMANAGER_H
36 #include "Displayer.h"
37 #include "SparkleManager.h"
38 #include "CountDownManager.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)
50 GLfloat brightness
[4];
56 /* static */ class LightManager
{
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
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
);
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
,
119 if (!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) {
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
))
127 if (mote
.light_color
== 0) {
128 light
.brightness
[0] = brightness
;
129 light
.brightness
[1] = brightness
;
130 light
.brightness
[2] = brightness
;
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
,
143 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
148 static inline void configureGarbageBrightness ( Light
&light
, int a
,
151 if (!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) {
153 assert(a
< DC_NUMBER_EXTRA_LIGHTS
);
157 brightness
= (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
- r
)
158 * (1.0f
/ (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
)) * mote
.brightness
;
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
;
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
,
178 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
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
,
197 light
.attenuated
= false;
201 static Light lights
[DC_NUMBER_EXTRA_LIGHTS
];
202 static int last_associated
;
203 static bool headlight_normal
;