quakeforge/tools/qflight/source/qflight.c

169 lines
2.9 KiB
C
Raw Normal View History

2002-08-25 23:06:23 +00:00
/*
trace.c
(description)
Copyright (C) 2002 Colin Thompson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
2002-08-26 15:12:05 +00:00
static const char rcsid[] =
"$Id$";
2002-08-25 23:06:23 +00:00
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_IO_H
# include <io.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <getopt.h>
#include <errno.h>
#include <stdlib.h>
#include "QF/bspfile.h"
#include "QF/dstring.h"
2002-08-25 23:06:23 +00:00
#include "QF/mathlib.h"
#include "QF/qtypes.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
2002-08-25 23:06:23 +00:00
#include "light.h"
#include "threads.h"
#include "entities.h"
#include "options.h"
options_t options;
bsp_t *bsp;
2002-08-25 23:06:23 +00:00
char *bspfile;
float scalecos = 0.5;
byte *filebase, *file_p, *file_end;
dmodel_t *bspmodel;
int bspfileface; // next surface to dispatch
vec3_t bsp_origin;
qboolean extrasamples;
float minlights[MAX_MAP_FACES];
byte *
GetFileSpace (int size)
{
2002-09-19 02:37:52 +00:00
byte *buf;
LOCK;
file_p = (byte *) (((long) file_p + 3) & ~3);
buf = file_p;
file_p += size;
UNLOCK;
if (file_p > file_end)
2002-08-25 23:06:23 +00:00
fprintf (stderr, "GetFileSpace: overrun");
2002-09-19 02:37:52 +00:00
return buf;
2002-08-25 23:06:23 +00:00
}
void
LightThread (void *junk)
{
2002-09-19 02:37:52 +00:00
int i;
2002-08-25 23:06:23 +00:00
2002-09-19 02:37:52 +00:00
while (1) {
2002-08-25 23:06:23 +00:00
LOCK;
i = bspfileface++;
UNLOCK;
if (i >= bsp->numfaces)
2002-08-25 23:06:23 +00:00
return;
LightFace (i);
2002-09-19 02:37:52 +00:00
}
2002-08-25 23:06:23 +00:00
}
void
LightWorld (void)
{
filebase = file_p = bsp->lightdata;
file_end = filebase + MAX_MAP_LIGHTING;
2002-08-25 23:06:23 +00:00
2002-09-19 02:37:52 +00:00
RunThreadsOn (LightThread);
2002-08-25 23:06:23 +00:00
bsp->lightdatasize = file_p - filebase;
2002-08-25 23:06:23 +00:00
if (options.verbosity >= 0)
printf ("lightdatasize: %i\n", bsp->lightdatasize);
2002-08-25 23:06:23 +00:00
}
int
main (int argc, char **argv)
{
2002-09-19 02:37:52 +00:00
double start, stop;
QFile *f;
2002-09-19 02:37:52 +00:00
2002-08-25 23:06:23 +00:00
start = Sys_DoubleTime ();
2002-09-19 02:37:52 +00:00
2002-08-25 23:06:23 +00:00
this_program = argv[0];
2002-09-19 02:37:52 +00:00
2002-08-25 23:06:23 +00:00
DecodeArgs (argc, argv);
if (!bspfile) {
fprintf (stderr, "%s: no bsp file specified.\n", this_program);
usage (1);
}
2002-09-19 02:37:52 +00:00
2002-08-25 23:06:23 +00:00
InitThreads ();
COM_StripExtension (bspfile, bspfile);
COM_DefaultExtension (bspfile, ".bsp");
f = Qopen (bspfile, "rb");
bsp = LoadBSPFile (f, Qfilesize (f));
Qclose (f);
2002-09-19 02:37:52 +00:00
LoadEntities ();
MakeTnodes (&bsp->models[0]);
2002-08-25 23:06:23 +00:00
2002-09-19 02:37:52 +00:00
LightWorld ();
2002-08-25 23:06:23 +00:00
2002-09-19 02:37:52 +00:00
WriteEntitiesToString ();
f = Qopen (bspfile, "wb");
WriteBSPFile (bsp, f);
Qclose (f);
2002-08-25 23:06:23 +00:00
stop = Sys_DoubleTime ();
if (options.verbosity >= 0)
printf ("%5.1f seconds elapsed\n", stop - start);
2002-09-19 02:37:52 +00:00
return 0;
2002-08-25 23:06:23 +00:00
}