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
39 #include "Displayer.h"
40 #include "SparkleManager.h"
41 #include "CountDownManager.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)
53 GLfloat brightness
[4];
59 /* static */ class LightManager
{
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
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
);
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
,
122 if (!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) {
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
))
130 if (mote
.light_color
== 0) {
131 light
.brightness
[0] = brightness
;
132 light
.brightness
[1] = brightness
;
133 light
.brightness
[2] = brightness
;
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
,
146 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
151 static inline void configureGarbageBrightness ( Light
&light
, int a
,
154 if (!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) {
156 assert(a
< DC_NUMBER_EXTRA_LIGHTS
);
160 brightness
= (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
- r
)
161 * (1.0f
/ (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
)) * mote
.brightness
;
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
;
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
,
181 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
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
,
200 light
.attenuated
= false;
204 static Light lights
[DC_NUMBER_EXTRA_LIGHTS
];
205 static int last_associated
;
206 static bool headlight_normal
;