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
35 #include "Displayer.h"
36 #include "SparkleManager.h"
37 #include "CountDownManager.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)
49 GLfloat brightness
[4];
55 /* static */ class LightManager
{
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
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
);
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
,
118 if (!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) {
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
))
126 if (mote
.light_color
== 0) {
127 light
.brightness
[0] = brightness
;
128 light
.brightness
[1] = brightness
;
129 light
.brightness
[2] = brightness
;
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
,
142 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
147 static inline void configureGarbageBrightness ( Light
&light
, int a
,
150 if (!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) {
152 assert(a
< DC_NUMBER_EXTRA_LIGHTS
);
156 brightness
= (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
- r
)
157 * (1.0f
/ (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
)) * mote
.brightness
;
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
;
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
,
177 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
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
,
196 light
.attenuated
= false;
200 static Light lights
[DC_NUMBER_EXTRA_LIGHTS
];
201 static int last_associated
;
202 static bool headlight_normal
;