forked from pjbroad/other-life
/
lights.h
227 lines (199 loc) · 5.5 KB
/
lights.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*!
* \file
* \ingroup lights
* \brief Light and sun handling.
*
* This file contains datatypes and functions to use lights and the sun with the client.
*/
#ifndef __LIGHTS_H__
#define __LIGHTS_H__
#include "platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/*!
* A light structure stores the position and color of a light
*/
typedef struct
{
/*!
* \name Light position
*/
/*! @{ */
float pos_x;
float pos_y;
float pos_z;
/*! @} */
/*!
* \name Light color
*/
/*! @{ */
float r;
float g;
float b;
/*! @} */
#ifdef MAP_EDITOR2
int locked;
#endif
#ifdef CLUSTER_INSIDES
short cluster;
#endif
}light;
/*! \name Lights limits */
/*! @{ */
#define GLOBAL_LIGHTS_NO 60 /*!< The maximum number of global lights to use */
#define MAX_LIGHTS 1000 /*!< The maximum amount of lights (global and local) */
/*! @} */
/*! \name Sky lights arrays */
/*! @{ */
extern GLfloat sky_lights_c1[GLOBAL_LIGHTS_NO*2][4];
extern GLfloat sky_lights_c2[GLOBAL_LIGHTS_NO*2][4];
extern GLfloat sky_lights_c3[GLOBAL_LIGHTS_NO*2][4];
extern GLfloat sky_lights_c4[GLOBAL_LIGHTS_NO*2][4];
/*! @} */
extern GLfloat ambient_light[]; /*!< An array for the ambient lights radiating from the sun */
extern GLfloat diffuse_light[]; /*!< An array for the diffuse light portion */
extern int show_lights; /*! the highest numbered light in the current GL display (0-6) */
extern int num_lights; /*! the number of lights currently loaded */
extern light *lights_list[MAX_LIGHTS]; /*!< global lights list */
extern unsigned char light_level; /*!< the light level */
extern short game_minute; /*!< the current game minute */
extern short game_second; /*!< the current game second */
extern unsigned char freeze_time; /*!< when this value is equal to 1, the game minute is freezed */
/*!
* \ingroup lights
* \brief Disables all local lightning.
*
* Disables all local lightning.
*
*/
void disable_local_lights();
/*!
* \ingroup lights
* \brief Draws the default local lights.
*
* Draws all default local lights. The lights must be enabled first.
*
* \sa draw_scene
* \sa enable_local_lights
*/
void draw_lights();
/*
* \ingroup lights
* \brief Destroys the light at position i in the lights_list
*
* Destroyes the light on position i in the lights_list - frees the memory and sets the lights_list[i]=NULL.
*
* \param i The position in the lights_list
*
* \callgraph
*/
void destroy_light(int i);
/*!
* \ingroup lights
* \brief Adds a new light using the given position and color.
*
* Adds a new light.using the given position (\a x, \a y, \a z) and the color (\a r, \a g, \a b, \a intensity) to the global \ref lights_list.
*
* \param x x coordinate of the lighs position
* \param y y coordinate of the lighs position
* \param z z coordinate of the lighs position
* \param r r (red) value of the lights color
* \param g g (green) value of the lights color
* \param b b (blue) value of the lights color
* \param intensity a (intensity) value of the lights color
* \retval int the index into the \ref lights_list array, where the light was added.
*/
#if defined (MAP_EDITOR2) || defined (MAP_EDITOR)
int add_light(GLfloat x, GLfloat y, GLfloat z, GLfloat r, GLfloat g, GLfloat b, GLfloat intensity, int locked, unsigned int dynamic);
#else
int add_light(GLfloat x, GLfloat y, GLfloat z, GLfloat r, GLfloat g, GLfloat b, GLfloat intensity, unsigned int dynamic);
#endif
/*!
* \ingroup lights
* \brief Gets the lights visible in the scene.
*
* Gets the lights visible in the scene.
*
* \sa draw_scene
*/
void update_scene_lights();
/*!
* \ingroup other
* \brief Initializes the default lights and enables lighting.
*
* Initializes the default lights and enables lighting.
*
* \sa init_stuff
* \sa set_new_video_mode
*/
void init_lights();
/*!
* \ingroup lights
* \brief Resets the material attributes to its default values.
*
* Resets the material attributes to the default values.
*
*/
void reset_material();
/*!
* \ingroup lights
* \brief Sets the material attributes to the given color.
*
* Sets the material attributes to the given color (\a r, \a g, \a b).
*
* \param r red component of the material color
* \param g green component of the material color
* \param b blue component of the material color
*/
void set_material(float r, float g, float b);
/*!
* \ingroup lights
* \brief Draws the global light.
*
* Draws the global light, i.e. the sun and the diffuse light.
*
* \sa draw_scene
*/
void draw_global_light();
/*!
* \ingroup lights
* \brief Draws the ambient light of dungeons.
*
* Draws the ambient light of dungeons.
*
* \sa draw_scene
*/
void draw_dungeon_light();
/*!
* \ingroup other
* \brief Initializies the global lights for the sun and lakes.
*
* Initializes the global lights for the sun and lakes using \ref make_gradient_light.
*
*/
void build_global_light_table();
/*!
* \ingroup other
* \brief Computes the table for the sun positions.
*
* Computes the global table of sun positions.
*
* \sa init_stuff
*/
void build_sun_pos_table();
/*!
* \ingroup event_handle
* \brief Sets the \ref light_level depending on the current \ref game_minute
*
* Sets the \ref light_level depending on the current \ref game_minute and adjusts the light.
*
* \callgraph
*/
void new_minute();
void new_second();
void cleanup_lights(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif