codemp/cgame/cg_light.c

Go to the documentation of this file.
00001 #include "cg_local.h"
00002 
00003 #if !defined(CG_LIGHTS_H_INC)
00004         #include "cg_lights.h"
00005 #endif
00006 
00007 static  clightstyle_t   cl_lightstyle[MAX_LIGHT_STYLES];
00008 static  int                             lastofs;
00009 
00010 /*
00011 ================
00012 FX_ClearLightStyles
00013 ================
00014 */
00015 void CG_ClearLightStyles (void)
00016 {
00017         int     i;
00018 
00019         memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
00020         lastofs = -1;
00021 
00022         for(i=0;i<MAX_LIGHT_STYLES*3;i++)
00023         {
00024                 CG_SetLightstyle (i);
00025         }
00026 }
00027 
00028 /*
00029 ================
00030 FX_RunLightStyles
00031 ================
00032 */
00033 void CG_RunLightStyles (void)
00034 {
00035         int             ofs;
00036         int             i;
00037         clightstyle_t   *ls;
00038 
00039         ofs = cg.time / 50;
00040 //      if (ofs == lastofs)
00041 //              return;
00042         lastofs = ofs;
00043 
00044         for (i=0,ls=cl_lightstyle ; i<MAX_LIGHT_STYLES ; i++, ls++)
00045         {
00046                 if (!ls->length)
00047                 {
00048                         ls->value[0] = ls->value[1] = ls->value[2] = ls->value[3] = 255;
00049                 }
00050                 else if (ls->length == 1)
00051                 {
00052                         ls->value[0] = ls->map[0][0];
00053                         ls->value[1] = ls->map[0][1];
00054                         ls->value[2] = ls->map[0][2];
00055                         ls->value[3] = 255; //ls->map[0][3];
00056                 }
00057                 else
00058                 {
00059                         ls->value[0] = ls->map[ofs%ls->length][0];
00060                         ls->value[1] = ls->map[ofs%ls->length][1];
00061                         ls->value[2] = ls->map[ofs%ls->length][2];
00062                         ls->value[3] = 255; //ls->map[ofs%ls->length][3];
00063                 }
00064                 trap_R_SetLightStyle(i, *(int*)ls->value);
00065         }
00066 }
00067 
00068 void CG_SetLightstyle (int i)
00069 {
00070         const char      *s;
00071         int                     j, k;
00072 
00073         s = CG_ConfigString( i+CS_LIGHT_STYLES );
00074         j = strlen (s);
00075         if (j >= MAX_QPATH)
00076         {
00077                 Com_Error (ERR_DROP, "svc_lightstyle length=%i", j);
00078         }
00079 
00080         cl_lightstyle[(i/3)].length = j;
00081         for (k=0 ; k<j ; k++)
00082         {
00083                 cl_lightstyle[(i/3)].map[k][(i%3)] = (float)(s[k]-'a')/(float)('z'-'a') * 255.0;
00084         }
00085 }