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 (!(Game::state
& GS_SYNC_WAIT
) && CountDownManager::state
== -1
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
);
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
,
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
))
120 if (mote
.light_color
== 0) {
121 light
.brightness
[0] = brightness
;
122 light
.brightness
[1] = brightness
;
123 light
.brightness
[2] = brightness
;
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
,
136 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
140 static inline void configureGarbageBrightness ( Light
&light
, int a
,
144 assert(a
< DC_NUMBER_EXTRA_LIGHTS
);
148 brightness
= (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
- r
)
149 * (1.0f
/ (DC_MOTE_LIGHT_RANGE
* DC_MOTE_LIGHT_RANGE
)) * mote
.brightness
;
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
;
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
,
169 glLightfv((GLenum
) (DC_EXTRA_LIGHT_BASE
+ a
), GL_SPECULAR
,
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
,
184 light
.attenuated
= false;
187 static Light lights
[DC_NUMBER_EXTRA_LIGHTS
];
188 static int last_associated
;
189 static bool headlight_normal
;