Added support for LMSTYLES16 bspx lump, allowing up to 16 lightstyles per face and a lot more switchable light styles.

This commit is contained in:
Shpoike 2019-09-10 15:41:11 +01:00
parent ebd361db63
commit ee2ab9a593
11 changed files with 104 additions and 51 deletions

View file

@ -256,7 +256,7 @@ typedef struct
short texinfo; short texinfo;
// lighting info // lighting info
byte styles[MAXLIGHTMAPS]; byte styles[4];
int lightofs; // start of [numstyles*surfsize] samples int lightofs; // start of [numstyles*surfsize] samples
} dsface_t; } dsface_t;
@ -270,7 +270,7 @@ typedef struct
int texinfo; int texinfo;
// lighting info // lighting info
byte styles[MAXLIGHTMAPS]; byte styles[4];
int lightofs; // start of [numstyles*surfsize] samples int lightofs; // start of [numstyles*surfsize] samples
} dlface_t; } dlface_t;

View file

@ -2274,7 +2274,7 @@ void CL_ParseServerMessage (void)
int cmd; int cmd;
int i; int i;
const char *str; //johnfitz const char *str; //johnfitz
int total, j, lastcmd; //johnfitz int lastcmd; //johnfitz
// //
// if recording demos, copy the message out // if recording demos, copy the message out
@ -2404,26 +2404,7 @@ void CL_ParseServerMessage (void)
case svc_lightstyle: case svc_lightstyle:
i = MSG_ReadByte (); i = MSG_ReadByte ();
str = MSG_ReadString(); str = MSG_ReadString();
if ((unsigned)i < MAX_LIGHTSTYLES) CL_UpdateLightstyle(i, str);
{
q_strlcpy (cl_lightstyle[i].map, str, MAX_STYLESTRING);
cl_lightstyle[i].length = Q_strlen(cl_lightstyle[i].map);
//johnfitz -- save extra info
if (cl_lightstyle[i].length)
{
total = 0;
cl_lightstyle[i].peak = 'a';
for (j=0; j<cl_lightstyle[i].length; j++)
{
total += cl_lightstyle[i].map[j] - 'a';
cl_lightstyle[i].peak = q_max(cl_lightstyle[i].peak, cl_lightstyle[i].map[j]);
}
cl_lightstyle[i].average = total / cl_lightstyle[i].length + 'a';
}
else
cl_lightstyle[i].average = cl_lightstyle[i].peak = 'm';
}
//johnfitz
break; break;
case svc_sound: case svc_sound:

View file

@ -927,9 +927,13 @@ void Mod_LoadLighting (lump_t *l)
// LordHavoc: no .lit found, expand the white lighting data to color // LordHavoc: no .lit found, expand the white lighting data to color
if (!l->filelen) if (!l->filelen)
return; return;
loadmodel->lightdata = Q1BSPX_FindLump("RGBLIGHTING", &bspxsize); in = Q1BSPX_FindLump("RGBLIGHTING", &bspxsize);
if (loadmodel->lightdata && bspxsize == l->filelen*3) if (loadmodel->lightdata && bspxsize == l->filelen*3)
{
loadmodel->lightdata = out = (byte *) Hunk_AllocName ( l->filelen*3, litfilename);
memcpy(out, in, l->filelen*3);
Con_DPrintf("bspx lighting loaded\n"); Con_DPrintf("bspx lighting loaded\n");
}
else else
{ {
in = Q1BSPX_FindLump("LIGHTING_E5BGR9", &bspxsize); in = Q1BSPX_FindLump("LIGHTING_E5BGR9", &bspxsize);
@ -1407,7 +1411,8 @@ void Mod_LoadFaces (lump_t *l, qboolean bsp2)
unsigned char *lmshift = NULL, defaultshift = 4; unsigned char *lmshift = NULL, defaultshift = 4;
unsigned int *lmoffset = NULL; unsigned int *lmoffset = NULL;
unsigned char *lmstyle = NULL; unsigned char *lmstyle8 = NULL, stylesperface = 4;
unsigned short *lmstyle16 = NULL;
int lumpsize; int lumpsize;
char scalebuf[16]; char scalebuf[16];
@ -1442,9 +1447,17 @@ void Mod_LoadFaces (lump_t *l, qboolean bsp2)
lmoffset = Q1BSPX_FindLump("LMOFFSET", &lumpsize); lmoffset = Q1BSPX_FindLump("LMOFFSET", &lumpsize);
if (lumpsize != sizeof(*lmoffset)*count) if (lumpsize != sizeof(*lmoffset)*count)
lmoffset = NULL; lmoffset = NULL;
lmstyle = Q1BSPX_FindLump("LMSTYLE", &lumpsize); lmstyle16 = Q1BSPX_FindLump("LMSTYLE16", &lumpsize);
if (lumpsize != sizeof(*lmstyle)*MAXLIGHTMAPS*count) stylesperface = lumpsize/(sizeof(*lmstyle16)*count);
lmstyle = NULL; if (lumpsize != sizeof(*lmstyle16)*stylesperface*count)
lmstyle16 = NULL;
if (!lmstyle16)
{
lmstyle8 = Q1BSPX_FindLump("LMSTYLE", &lumpsize);
stylesperface = lumpsize/(sizeof(*lmstyle8)*count);
if (lumpsize != sizeof(*lmstyle8)*stylesperface*count)
lmstyle8 = NULL;
}
if (Mod_ParseWorldspawnKey(loadmodel, "lightmap_scale", scalebuf, sizeof(scalebuf))) if (Mod_ParseWorldspawnKey(loadmodel, "lightmap_scale", scalebuf, sizeof(scalebuf)))
{ {
@ -1466,8 +1479,8 @@ void Mod_LoadFaces (lump_t *l, qboolean bsp2)
planenum = LittleLong(inl->planenum); planenum = LittleLong(inl->planenum);
side = LittleLong(inl->side); side = LittleLong(inl->side);
texinfon = LittleLong (inl->texinfo); texinfon = LittleLong (inl->texinfo);
for (i=0 ; i<MAXLIGHTMAPS ; i++) for (i=0 ; i<4 ; i++)
out->styles[i] = inl->styles[i]; out->styles[i] = ((inl->styles[i]==INVALID_LIGHTSTYLE_OLD)?INVALID_LIGHTSTYLE:inl->styles[i]);
lofs = LittleLong(inl->lightofs); lofs = LittleLong(inl->lightofs);
inl++; inl++;
} }
@ -1478,20 +1491,29 @@ void Mod_LoadFaces (lump_t *l, qboolean bsp2)
planenum = LittleShort(ins->planenum); planenum = LittleShort(ins->planenum);
side = LittleShort(ins->side); side = LittleShort(ins->side);
texinfon = LittleShort (ins->texinfo); texinfon = LittleShort (ins->texinfo);
for (i=0 ; i<MAXLIGHTMAPS ; i++) for (i=0 ; i<4 ; i++)
out->styles[i] = ins->styles[i]; out->styles[i] = ((ins->styles[i]==INVALID_LIGHTSTYLE_OLD)?INVALID_LIGHTSTYLE:ins->styles[i]);
lofs = LittleLong(ins->lightofs); lofs = LittleLong(ins->lightofs);
ins++; ins++;
} }
shift = defaultshift; shift = defaultshift;
//bspx overrides (for lmscale) //bspx overrides (for lmscale)
if (lmstyle) if (lmshift)
shift = lmshift[surfnum]; shift = lmshift[surfnum];
if (lmoffset) if (lmoffset)
lofs = LittleLong(lmoffset[surfnum]); lofs = LittleLong(lmoffset[surfnum]);
if (lmstyle) if (lmstyle16)
for (i=0 ; i<MAXLIGHTMAPS ; i++) for (i=0 ; i<stylesperface ; i++)
out->styles[i] = lmstyle[surfnum*MAXLIGHTMAPS+i]; out->styles[i] = lmstyle16[surfnum*stylesperface+i];
else if (lmstyle8)
for (i=0 ; i<stylesperface ; i++)
{
out->styles[i] = lmstyle8[surfnum*stylesperface+i];
if (out->styles[i] == INVALID_LIGHTSTYLE_OLD)
out->styles[i] = INVALID_LIGHTSTYLE;
}
for ( ; i<MAXLIGHTMAPS ; i++)
out->styles[i] = INVALID_LIGHTSTYLE;
out->flags = 0; out->flags = 0;

View file

@ -162,7 +162,7 @@ typedef struct msurface_s
// int is 32 bits, need an array for MAX_DLIGHTS > 32 // int is 32 bits, need an array for MAX_DLIGHTS > 32
int lightmaptexturenum; int lightmaptexturenum;
byte styles[MAXLIGHTMAPS]; unsigned short styles[MAXLIGHTMAPS];
int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap
qboolean cached_dlight; // true if dynamic light in cache qboolean cached_dlight; // true if dynamic light in cache
byte *samples; // [numstyles*surfsize] byte *samples; // [numstyles*surfsize]

View file

@ -27,6 +27,33 @@ int r_dlightframecount;
extern cvar_t r_flatlightstyles; //johnfitz extern cvar_t r_flatlightstyles; //johnfitz
//Spike - made this a general function
void CL_UpdateLightstyle(unsigned int idx, const char *str)
{
int total;
int j;
if (idx < MAX_LIGHTSTYLES)
{
q_strlcpy (cl_lightstyle[idx].map, str, MAX_STYLESTRING);
cl_lightstyle[idx].length = Q_strlen(cl_lightstyle[idx].map);
//johnfitz -- save extra info
if (cl_lightstyle[idx].length)
{
total = 0;
cl_lightstyle[idx].peak = 'a';
for (j=0; j<cl_lightstyle[idx].length; j++)
{
total += cl_lightstyle[idx].map[j] - 'a';
cl_lightstyle[idx].peak = q_max(cl_lightstyle[idx].peak, cl_lightstyle[idx].map[j]);
}
cl_lightstyle[idx].average = total / cl_lightstyle[idx].length + 'a';
}
else
cl_lightstyle[idx].average = cl_lightstyle[idx].peak = 'm';
//johnfitz
}
}
/* /*
================== ==================
R_AnimateLight R_AnimateLight
@ -350,7 +377,7 @@ loc0:
lightmap = surf->samples + ((dt>>surf->lmshift) * ((surf->extents[0]>>surf->lmshift)+1) + (ds>>surf->lmshift))*3; // LordHavoc: *3 for color lightmap = surf->samples + ((dt>>surf->lmshift) * ((surf->extents[0]>>surf->lmshift)+1) + (ds>>surf->lmshift))*3; // LordHavoc: *3 for color
for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++) for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != INVALID_LIGHTSTYLE;maps++)
{ {
scale = (float) d_lightstylevalue[surf->styles[maps]] * 1.0 / 256.0; scale = (float) d_lightstylevalue[surf->styles[maps]] * 1.0 / 256.0;
r00 += (float) lightmap[ 0] * scale;g00 += (float) lightmap[ 1] * scale;b00 += (float) lightmap[2] * scale; r00 += (float) lightmap[ 0] * scale;g00 += (float) lightmap[ 1] * scale;b00 += (float) lightmap[2] * scale;

View file

@ -55,7 +55,7 @@ refdef_t r_refdef;
mleaf_t *r_viewleaf, *r_oldviewleaf; mleaf_t *r_viewleaf, *r_oldviewleaf;
int d_lightstylevalue[256]; // 8.8 fraction of base light value int d_lightstylevalue[MAX_LIGHTSTYLES]; // 8.8 fraction of base light value
cvar_t r_norefresh = {"r_norefresh","0",CVAR_NONE}; cvar_t r_norefresh = {"r_norefresh","0",CVAR_NONE};

View file

@ -151,7 +151,7 @@ extern vec3_t r_origin;
// //
extern refdef_t r_refdef; extern refdef_t r_refdef;
extern mleaf_t *r_viewleaf, *r_oldviewleaf; extern mleaf_t *r_viewleaf, *r_oldviewleaf;
extern int d_lightstylevalue[256]; // 8.8 fraction of base light value extern int d_lightstylevalue[MAX_LIGHTSTYLES]; // 8.8 fraction of base light value
extern cvar_t r_norefresh; extern cvar_t r_norefresh;
extern cvar_t r_drawentities; extern cvar_t r_drawentities;
@ -369,6 +369,7 @@ const char *Fog_GetFogCommand(void); //for demo recording
void R_NewGame (void); void R_NewGame (void);
void CL_UpdateLightstyle(unsigned int idx, const char *stylestring);
void R_AnimateLight (void); void R_AnimateLight (void);
void R_MarkSurfaces (void); void R_MarkSurfaces (void);
void R_CullSurfaces (void); void R_CullSurfaces (void);

View file

@ -1009,6 +1009,11 @@ void Host_Reconnect_Sv_f (void)
cls.signon = 0; // need new connection messages cls.signon = 0; // need new connection messages
} }
void Host_Lightstyle_f (void)
{
CL_UpdateLightstyle(atoi(Cmd_Argv(1)), Cmd_Argv(2));
}
/* /*
===================== =====================
Host_Connect_f Host_Connect_f
@ -1172,8 +1177,6 @@ void Host_Savegame_f (void)
{ {
if (sv.lightstyles[i]) if (sv.lightstyles[i])
fprintf (f, "sv.lightstyles %i \"%s\"\n", i, sv.lightstyles[i]); fprintf (f, "sv.lightstyles %i \"%s\"\n", i, sv.lightstyles[i]);
else
fprintf (f, "sv.lightstyles %i \"\"\n", i);
} }
for (i = 1; i < MAX_MODELS; i++) for (i = 1; i < MAX_MODELS; i++)
{ {
@ -1308,6 +1311,8 @@ void Host_Loadgame_f (void)
data = COM_ParseStringNewline (data); data = COM_ParseStringNewline (data);
sv.lightstyles[i] = (const char *)Hunk_Strdup (com_token, "lightstyles"); sv.lightstyles[i] = (const char *)Hunk_Strdup (com_token, "lightstyles");
} }
for (; i < MAX_LIGHTSTYLES; i++)
sv.lightstyles[i] = NULL;
// load the edicts out of the savegame file // load the edicts out of the savegame file
entnum = -1; // -1 is the globals entnum = -1; // -1 is the globals
@ -1873,12 +1878,20 @@ void Host_Spawn_f (void)
{ {
//CL_ClearState should have cleared all lightstyles, so don't send irrelevant ones //CL_ClearState should have cleared all lightstyles, so don't send irrelevant ones
if (sv.lightstyles[i]) if (sv.lightstyles[i])
{
if (i > 0xff)
{
MSG_WriteByte (&host_client->message, svc_stufftext);
MSG_WriteString (&host_client->message, va("//ls %i \"%s\"\n", i, sv.lightstyles[i]));
}
else
{ {
MSG_WriteByte (&host_client->message, svc_lightstyle); MSG_WriteByte (&host_client->message, svc_lightstyle);
MSG_WriteByte (&host_client->message, (char)i); MSG_WriteByte (&host_client->message, i);
MSG_WriteString (&host_client->message, sv.lightstyles[i]); MSG_WriteString (&host_client->message, sv.lightstyles[i]);
} }
} }
}
// //
// send some stats // send some stats
@ -2644,6 +2657,7 @@ void Host_InitCommands (void)
Cmd_AddCommand ("connect", Host_Connect_f); Cmd_AddCommand ("connect", Host_Connect_f);
Cmd_AddCommand_Console ("reconnect", Host_Reconnect_Con_f); Cmd_AddCommand_Console ("reconnect", Host_Reconnect_Con_f);
Cmd_AddCommand_ServerCommand ("reconnect", Host_Reconnect_Sv_f); Cmd_AddCommand_ServerCommand ("reconnect", Host_Reconnect_Sv_f);
Cmd_AddCommand_ServerCommand ("ls", Host_Lightstyle_f);
Cmd_AddCommand_ClientCommand ("name", Host_Name_f); Cmd_AddCommand_ClientCommand ("name", Host_Name_f);
Cmd_AddCommand_ClientCommand ("noclip", Host_Noclip_f); Cmd_AddCommand_ClientCommand ("noclip", Host_Noclip_f);
Cmd_AddCommand_ClientCommand ("setpos", Host_SetPos_f); //QuakeSpasm Cmd_AddCommand_ClientCommand ("setpos", Host_SetPos_f); //QuakeSpasm

View file

@ -1340,12 +1340,20 @@ static void PF_sv_lightstyle (void)
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
{ {
if (client->active || client->spawned) if (client->active || client->spawned)
{
if (style > 0xff)
{
MSG_WriteByte (&client->message, svc_stufftext);
MSG_WriteString (&client->message, va("//ls %i \"%s\"\n", style, val));
}
else
{ {
MSG_WriteChar (&client->message, svc_lightstyle); MSG_WriteChar (&client->message, svc_lightstyle);
MSG_WriteChar (&client->message, style); MSG_WriteChar (&client->message, style);
MSG_WriteString (&client->message, val); MSG_WriteString (&client->message, val);
} }
} }
}
} }
static void PF_rint (void) static void PF_rint (void)

View file

@ -97,7 +97,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MIN_EDICTS 256 // johnfitz -- lowest allowed value for max_edicts cvar #define MIN_EDICTS 256 // johnfitz -- lowest allowed value for max_edicts cvar
#define MAX_EDICTS 32000 // johnfitz -- highest allowed value for max_edicts cvar #define MAX_EDICTS 32000 // johnfitz -- highest allowed value for max_edicts cvar
// ents past 8192 can't play sounds in the standard protocol // ents past 8192 can't play sounds in the standard protocol
#define MAX_LIGHTSTYLES 255 //spike -- file format max of 255, increasing will break saved games. #define MAX_LIGHTSTYLES 1024 //spike -- file format max of 255, increasing will break saved games.
#define MAX_MODELS 4096 // johnfitz -- was 256 #define MAX_MODELS 4096 // johnfitz -- was 256
#define MAX_SOUNDS 2048 // johnfitz -- was 256 #define MAX_SOUNDS 2048 // johnfitz -- was 256
#define MAX_PARTICLETYPES 2048 #define MAX_PARTICLETYPES 2048

View file

@ -669,7 +669,7 @@ void R_RenderDynamicLightmaps (qmodel_t *model, msurface_t *fa)
lightmap[fa->lightmaptexturenum].polys = fa->polys; lightmap[fa->lightmaptexturenum].polys = fa->polys;
// check for lightmap modification // check for lightmap modification
for (maps=0; maps < MAXLIGHTMAPS && fa->styles[maps] != 255; maps++) for (maps=0; maps < MAXLIGHTMAPS && fa->styles[maps] != INVALID_LIGHTSTYLE; maps++)
if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps]) if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps])
goto dynamic; goto dynamic;
@ -1161,7 +1161,7 @@ void R_BuildLightMap (qmodel_t *model, msurface_t *surf, byte *dest, int stride)
// add all the lightmaps // add all the lightmaps
if (lightmap) if (lightmap)
{ {
for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != INVALID_LIGHTSTYLE ;
maps++) maps++)
{ {
scale = d_lightstylevalue[surf->styles[maps]]; scale = d_lightstylevalue[surf->styles[maps]];