MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / InitDynamicLighting

Function InitDynamicLighting

Descent3/lighting.cpp:118–172  ·  view source on GitHub ↗

Sets up our dynamic lighting maps and tables

Source from the content-addressed store, hash-verified

116// Sets up our dynamic lighting maps
117// and tables
118void InitDynamicLighting() {
119 int i, cl, size;
120
121 mprintf(0, "Initting dynamic lighting.\n");
122
123 memset(Lmi_spoken_for, 0, MAX_LIGHTMAP_INFOS / 8);
124
125 for (i = 0; i < 16; i++)
126 Light_component_scalar[i] = i / 15.0;
127 for (i = 16; i < 32; i++)
128 Light_component_scalar[i] = 1.0;
129
130 for (cl = 0, size = 128; size >= 2; size >>= 1, cl++) {
131 Specular_maps[cl] = lm_AllocLightmap(size, size);
132 ASSERT(Specular_maps[cl] != BAD_LM_INDEX);
133 }
134
135 // Init our dynamic memory
136 if (Mem_low_memory_mode) {
137 // Just use 1 meg if in low mem mode
138 DYNAMIC_LIGHTMAP_MEMORY = 500000;
139 }
140
141 Dynamic_lightmap_memory = (uint16_t *)mem_malloc(DYNAMIC_LIGHTMAP_MEMORY);
142
143 // Init our records list
144 Dynamic_lightmaps = (dynamic_lightmap *)mem_malloc(sizeof(dynamic_lightmap) * MAX_DYNAMIC_LIGHTMAPS);
145 ASSERT(Dynamic_lightmaps);
146
147 for (i = 0; i < MAX_DYNAMIC_LIGHTMAPS; i++) {
148 memset(&Dynamic_lightmaps[i], 0, sizeof(dynamic_lightmap));
149 }
150
151 // Setup uint8_t to float
152 for (i = 0; i < 256; i++)
153 Ubyte_to_float[i] = (float)i / 255.0;
154
155 // Setup specular tables
156 mprintf(0, "Building specular tables.\n");
157
158 for (i = 0; i < MAX_SPECULAR_INCREMENTS; i++) {
159 float val = (float)i / (float)(MAX_SPECULAR_INCREMENTS - 1);
160
161 // Metal
162 Specular_tables[0][i] = (val * val * val * val * val * val);
163
164 // Plastic
165 Specular_tables[1][i] = (val * val * val * val * val * val * val * val * val * val * val * val * val * val);
166
167 // Marble
168 Specular_tables[2][i] = (val * val * val * val);
169 }
170
171 atexit(FreeLighting);
172}
173
174// Given a float, returns the index into the Ubyte_float_table that this number
175// corresponds to

Callers 1

InitD3Systems1Function · 0.85

Calls 1

lm_AllocLightmapFunction · 0.85

Tested by

no test coverage detected