+ model_brush_lightstyleinfo_t *style;
+
+ // For each lightstyle, check if its value changed and mark the lightmaps as dirty if so
+ for (i = 0, style = model->brushq1.data_lightstyleinfo; i < model->brushq1.num_lightstyles; i++, style++)
+ {
+ if (style->value != r_refdef.scene.lightstylevalue[style->style])
+ {
+ int* list = style->surfacelist;
+ style->value = r_refdef.scene.lightstylevalue[style->style];
+ // Value changed - mark the surfaces belonging to this style chain as dirty
+ for (j = 0; j < style->numsurfaces; j++)
+ update[list[j]] = true;
+ }
+ }
+ // Now check if update flags are set on any surfaces that are visible
+ if (r_q1bsp_lightmap_updates_hidden_surfaces.integer)
+ {
+ /*
+ * We can do less frequent texture uploads (approximately 10hz for animated
+ * lightstyles) by rebuilding lightmaps on surfaces that are not currently visible.
+ * For optimal efficiency, this includes the submodels of the worldmodel, so we
+ * use model->num_surfaces, not nummodelsurfaces.
+ */
+ for (i = 0; i < model->num_surfaces;i++)
+ if (update[i])
+ R_BuildLightMap(ent, surfaces + i, r_q1bsp_lightmap_updates_combine.integer);
+ }
+ else