light: remove bsp30 support and automatically generate .lit when needed

Check whether any of the entities have colored fields set and if so,
enable colored light output. Can still be overridden from the command line
if needed.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-03-01 09:52:27 +10:30
parent 65b38c4952
commit 8ce739fe3f
5 changed files with 37 additions and 62 deletions

View File

@ -242,8 +242,8 @@ LoadBSPFile(const char *filename)
bsp_version = (int)header->version; bsp_version = (int)header->version;
logprint("BSP is version %i\n", bsp_version); logprint("BSP is version %i\n", bsp_version);
if (bsp_version != 29 && bsp_version != 30) if (bsp_version != 29)
Error("Sorry, only bsp versions 29 & 30 supported."); Error("Sorry, only bsp version 29 supported.");
nummodels = CopyLump(LUMP_MODELS, &dmodels, sizeof(dmodel_t)); nummodels = CopyLump(LUMP_MODELS, &dmodels, sizeof(dmodel_t));
numvertexes = CopyLump(LUMP_VERTEXES, &dvertexes, sizeof(dvertex_t)); numvertexes = CopyLump(LUMP_VERTEXES, &dvertexes, sizeof(dvertex_t));

View File

@ -46,6 +46,7 @@ void MakeTnodes(void);
extern float scaledist; extern float scaledist;
extern float rangescale; extern float rangescale;
extern int worldminlight; extern int worldminlight;
extern const vec3_t vec3_white;
extern vec3_t minlight_color; extern vec3_t minlight_color;
extern int sunlight; extern int sunlight;
extern vec3_t sunlight_color; extern vec3_t sunlight_color;

View File

@ -154,11 +154,14 @@ CheckEntityFields(entity_t *entity)
} }
entity->formula = LF_LINEAR; entity->formula = LF_LINEAR;
} }
if (!entity->lightcolor[0] && !entity->lightcolor[1] if (!VectorCompare(entity->lightcolor, vec3_origin)) {
&& !entity->lightcolor[2]) { if (!colored) {
entity->lightcolor[0] = 255; colored = true;
entity->lightcolor[1] = 255; logprint("Colored light entities detected: "
entity->lightcolor[2] = 255; ".lit output enabled.\n");
}
} else {
VectorCopy(vec3_white, entity->lightcolor);
} }
} }
@ -181,6 +184,7 @@ LoadEntities(void)
data = dentdata; data = dentdata;
/* start parsing */ /* start parsing */
memset(entities, 0, sizeof(entity_t) * MAX_MAP_ENTITIES);
num_entities = 0; num_entities = 0;
num_lights = 0; num_lights = 0;
@ -295,6 +299,16 @@ LoadEntities(void)
} }
} }
} }
if (!VectorCompare(sunlight_color, vec3_white) ||
!VectorCompare(minlight_color, vec3_white)) {
if (!colored) {
colored = true;
logprint("Colored light entities detected: "
".lit output enabled.\n");
}
}
logprint("%d entities read, %d are lights.\n", num_entities, num_lights); logprint("%d entities read, %d are lights.\n", num_entities, num_lights);
MatchTargets(); MatchTargets();
} }

View File

@ -22,8 +22,9 @@
float scaledist = 1.0; float scaledist = 1.0;
float rangescale = 0.5; float rangescale = 0.5;
int worldminlight = 0; int worldminlight = 0;
vec3_t minlight_color = { 255, 255, 255 }; /* defaults to white light */
int sunlight = 0; int sunlight = 0;
const vec3_t vec3_white = { 255, 255, 255 };
vec3_t minlight_color = { 255, 255, 255 }; /* defaults to white light */
vec3_t sunlight_color = { 255, 255, 255 }; /* defaults to white light */ vec3_t sunlight_color = { 255, 255, 255 }; /* defaults to white light */
vec3_t sunmangle = { 0, 0, 16384 }; /* defaults to straight down */ vec3_t sunmangle = { 0, 0, 16384 }; /* defaults to straight down */
@ -38,8 +39,6 @@ static byte *lit_file_end; // end of space for litfile data
qboolean extrasamples; qboolean extrasamples;
qboolean compress_ents; qboolean compress_ents;
qboolean colored; qboolean colored;
qboolean bsp30;
qboolean litfile;
qboolean nominlimit; qboolean nominlimit;
qboolean nolightface[MAX_MAP_FACES]; qboolean nolightface[MAX_MAP_FACES];
@ -159,14 +158,14 @@ LightWorld(void)
Error("%s: allocation of %i bytes failed.", __func__, lightdatasize); Error("%s: allocation of %i bytes failed.", __func__, lightdatasize);
memset(dlightdata, 0, lightdatasize + 16); memset(dlightdata, 0, lightdatasize + 16);
if (litfile) if (colored)
lightdatasize /= 4; lightdatasize /= 4;
/* align filebase to a 4 byte boundary */ /* align filebase to a 4 byte boundary */
filebase = file_p = (byte *)(((unsigned long)dlightdata + 3) & ~3); filebase = file_p = (byte *)(((unsigned long)dlightdata + 3) & ~3);
file_end = filebase + lightdatasize; file_end = filebase + lightdatasize;
if (colored && litfile) { if (colored) {
/* litfile data stored in dlightdata, after the white light */ /* litfile data stored in dlightdata, after the white light */
lit_filebase = file_end + 12 - ((unsigned long)file_end % 12); lit_filebase = file_end + 12 - ((unsigned long)file_end % 12);
lit_file_p = lit_filebase; lit_file_p = lit_filebase;
@ -223,13 +222,8 @@ main(int argc, const char **argv)
} else if (!strcmp(argv[i], "-compress")) { } else if (!strcmp(argv[i], "-compress")) {
compress_ents = true; compress_ents = true;
logprint("light entity compression enabled\n"); logprint("light entity compression enabled\n");
} else if (!strcmp(argv[i], "-colored") ||
!strcmp(argv[i], "-coloured")) {
colored = true;
} else if (!strcmp(argv[i], "-bsp30")) {
bsp30 = true;
} else if (!strcmp(argv[i], "-lit")) { } else if (!strcmp(argv[i], "-lit")) {
litfile = true; colored = true;
} else if (!strcmp(argv[i], "-nominlimit")) { } else if (!strcmp(argv[i], "-nominlimit")) {
nominlimit = true; nominlimit = true;
} else if (argv[i][0] == '-') } else if (argv[i][0] == '-')
@ -240,29 +234,13 @@ main(int argc, const char **argv)
if (numthreads > 1) if (numthreads > 1)
logprint("running with %d threads\n", numthreads); logprint("running with %d threads\n", numthreads);
if (colored)
// Switch on colored flag if specifying -lit or -bsp30 logprint(".lit colored light output requested on command line.\n");
if (bsp30 || litfile)
colored = true;
// Check the colored options
if (colored) {
if (!bsp30 && !litfile) {
logprint("colored output format not specified -> using bsp 30\n");
bsp30 = true;
} else if (bsp30 && litfile) {
Error("Two colored output formats specified");
} else if (litfile) {
logprint("colored output format: lit\n");
} else if (bsp30) {
logprint("colored output format: bsp30\n");
}
}
if (i != argc - 1) if (i != argc - 1)
Error("usage: light [-threads num] [-light num] [-extra]\n" Error("usage: light [-threads num] [-light num] [-extra]\n"
" [-colored] [-bsp30] [-lit]\n" " [-dist n] [-range n] [-lit] [-compress]\n"
" [-nocount] [-compress] [-nominlimit] bspfile\n"); " [-nominlimit] bspfile\n");
start = I_FloatTime(); start = I_FloatTime();
@ -277,13 +255,8 @@ main(int argc, const char **argv)
LightWorld(); LightWorld();
WriteEntitiesToString(); WriteEntitiesToString();
WriteBSPFile(source, bsp_version);
if (colored && bsp30) if (colored)
WriteBSPFile(source, 30);
else
WriteBSPFile(source, bsp_version);
if (colored && litfile)
WriteLitFile(source, LIT_VERSION); WriteLitFile(source, LIT_VERSION);
end = I_FloatTime(); end = I_FloatTime();

View File

@ -886,7 +886,7 @@ LightFace(int surfnum, qboolean nolight, const vec3_t faceoffset)
int lightmapwidth; int lightmapwidth;
int lightmapsize; int lightmapsize;
byte *out; byte *out;
byte *lit_out; byte *lit_out = NULL;
vec_t *light; vec_t *light;
vec3_t *lightcolor; vec3_t *lightcolor;
@ -1037,18 +1037,10 @@ LightFace(int surfnum, qboolean nolight, const vec3_t faceoffset)
for (i = 0; i < MAXLIGHTMAPS; i++) for (i = 0; i < MAXLIGHTMAPS; i++)
face->styles[i] = l.lightstyles[i]; face->styles[i] = l.lightstyles[i];
/* Extra room for BSP30 lightmaps */ lightmapsize = size * l.numlightstyles;
if (colored && bsp30)
lightmapsize = size * l.numlightstyles * 4;
else
lightmapsize = size * l.numlightstyles;
out = GetFileSpace(lightmapsize); out = GetFileSpace(lightmapsize);
if (colored)
if (litfile)
lit_out = GetLitFileSpace(lightmapsize * 3); lit_out = GetLitFileSpace(lightmapsize * 3);
else
lit_out = NULL; /* Fix compiler warning... */
face->lightofs = out - filebase; face->lightofs = out - filebase;
@ -1121,12 +1113,7 @@ LightFace(int surfnum, qboolean nolight, const vec3_t faceoffset)
} }
/* Write out the lightmap in the appropriate format */ /* Write out the lightmap in the appropriate format */
if (colored && bsp30) { if (colored) {
*out++ = colors[0];
*out++ = colors[1];
*out++ = colors[2];
}
if (colored && litfile) {
*lit_out++ = colors[0]; *lit_out++ = colors[0];
*lit_out++ = colors[1]; *lit_out++ = colors[1];
*lit_out++ = colors[2]; *lit_out++ = colors[2];