2002-08-25 23:06:23 +00:00
|
|
|
/*
|
|
|
|
trace.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
2002-09-25 01:51:58 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-08-25 23:06:23 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/bspfile.h"
|
|
|
|
#include "QF/dstring.h"
|
|
|
|
#include "QF/mathlib.h"
|
2004-01-27 08:31:34 +00:00
|
|
|
#include "QF/qfplist.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
#include "QF/qtypes.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2004-11-12 02:54:00 +00:00
|
|
|
#include "QF/script.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "light.h"
|
|
|
|
#include "threads.h"
|
|
|
|
#include "entities.h"
|
|
|
|
#include "options.h"
|
2004-01-27 08:31:34 +00:00
|
|
|
#include "properties.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-09-08 03:39:44 +00:00
|
|
|
entity_t *entities;
|
2002-08-25 23:06:23 +00:00
|
|
|
int num_entities;
|
2003-09-08 03:39:44 +00:00
|
|
|
static int max_entities;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
ENTITY FILE PARSING
|
|
|
|
|
|
|
|
If a light has a targetname, generate a unique style in the 32-63 range
|
|
|
|
*/
|
|
|
|
|
|
|
|
int numlighttargets;
|
2003-09-08 03:46:56 +00:00
|
|
|
const char *lighttargets[32];
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2003-09-08 03:39:44 +00:00
|
|
|
LightStyleForTargetname (const char *targetname, qboolean alloc)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2002-09-19 02:37:52 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numlighttargets; i++)
|
2002-08-25 23:06:23 +00:00
|
|
|
if (!strcmp (lighttargets[i], targetname))
|
|
|
|
return 32 + i;
|
2002-09-19 02:37:52 +00:00
|
|
|
|
|
|
|
if (!alloc)
|
2002-08-25 23:06:23 +00:00
|
|
|
return -1;
|
2002-09-19 02:37:52 +00:00
|
|
|
|
2003-09-08 03:46:56 +00:00
|
|
|
lighttargets[i] = targetname;
|
2002-09-19 02:37:52 +00:00
|
|
|
numlighttargets++;
|
|
|
|
return numlighttargets - 1 + 32;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-08-25 23:06:23 +00:00
|
|
|
MatchTargets (void)
|
|
|
|
{
|
2002-09-19 02:37:52 +00:00
|
|
|
int i, j;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2002-09-19 02:37:52 +00:00
|
|
|
for (i = 0; i < num_entities; i++) {
|
2003-09-08 03:46:56 +00:00
|
|
|
if (!entities[i].target || !entities[i].target[0])
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < num_entities; j++)
|
2003-09-08 03:46:56 +00:00
|
|
|
if (entities[j].targetname
|
|
|
|
&& !strcmp (entities[j].targetname, entities[i].target)) {
|
2002-08-25 23:06:23 +00:00
|
|
|
entities[i].targetent = &entities[j];
|
2003-09-09 08:13:33 +00:00
|
|
|
// set up spotlight values for lighting code to use
|
|
|
|
VectorSubtract (entities[i].targetent->origin,
|
|
|
|
entities[i].origin, entities[i].spotdir);
|
|
|
|
VectorNormalize (entities[i].spotdir);
|
|
|
|
if (!entities[i].angle)
|
|
|
|
entities[i].spotcone = -cos(20 * M_PI / 180);
|
|
|
|
else
|
|
|
|
entities[i].spotcone = -cos(entities[i].angle * M_PI / 360);
|
2002-08-25 23:06:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j == num_entities) {
|
|
|
|
printf ("WARNING: entity at (%i,%i,%i) (%s) has unmatched "
|
|
|
|
"target\n",
|
|
|
|
(int) entities[i].origin[0], (int) entities[i].origin[1],
|
|
|
|
(int) entities[i].origin[2], entities[i].classname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// set the style on the source ent for switchable lights
|
|
|
|
if (entities[j].style) {
|
|
|
|
char s[16];
|
|
|
|
|
|
|
|
entities[i].style = entities[j].style;
|
|
|
|
sprintf (s, "%i", entities[i].style);
|
|
|
|
SetKeyValue (&entities[i], "style", s);
|
|
|
|
}
|
2003-09-09 08:13:33 +00:00
|
|
|
|
2004-03-25 05:41:33 +00:00
|
|
|
if (entities[i].spotcone >= 0) {
|
2003-09-09 08:13:33 +00:00
|
|
|
VectorZero (entities[i].spotdir);
|
|
|
|
entities[i].spotcone = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
WriteLights (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FILE *f;
|
|
|
|
entity_t *e;
|
|
|
|
|
|
|
|
if (!options.lightsfilename)
|
|
|
|
return;
|
|
|
|
printf ("building .lights file\n");
|
|
|
|
f = fopen (options.lightsfilename, "wb");
|
|
|
|
for (i = 0; i < num_entities; i++) {
|
|
|
|
e = entities + i;
|
|
|
|
if (e->light)
|
|
|
|
fprintf(f, "%f %f %f %f %f %f %f %f %f %f %f %f %f %d\n",
|
|
|
|
e->origin[0], e->origin[1], e->origin[2],
|
|
|
|
e->falloff,
|
|
|
|
e->color[0], e->color[1], e->color[2],
|
|
|
|
e->subbrightness,
|
|
|
|
e->spotdir[0], e->spotdir[1], e->spotdir[2],
|
|
|
|
e->spotcone, e->lightoffset, e->style);
|
2002-09-19 02:37:52 +00:00
|
|
|
}
|
2003-09-09 08:13:33 +00:00
|
|
|
fclose (f);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LoadEntities (void)
|
|
|
|
{
|
2003-09-08 03:39:44 +00:00
|
|
|
const char *key;
|
2003-09-09 08:13:33 +00:00
|
|
|
double vec[4];
|
2003-09-08 03:39:44 +00:00
|
|
|
entity_t *entity;
|
|
|
|
epair_t *epair;
|
2004-01-26 07:39:29 +00:00
|
|
|
float cutoff_range;
|
|
|
|
float intensity;
|
2004-01-27 08:31:34 +00:00
|
|
|
plitem_t *dict;
|
2004-11-12 02:54:00 +00:00
|
|
|
script_t *script;
|
2002-09-19 02:37:52 +00:00
|
|
|
|
2004-11-12 02:54:00 +00:00
|
|
|
script = Script_New ();
|
|
|
|
Script_Start (script, "ent data", bsp->entdata);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
// start parsing
|
2003-09-08 03:39:44 +00:00
|
|
|
max_entities = num_entities = 0;
|
|
|
|
entities = 0;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
// go through all the entities
|
2004-11-12 02:54:00 +00:00
|
|
|
while (Script_GetToken (script, 1)) {
|
2002-08-25 23:06:23 +00:00
|
|
|
// parse the opening brace
|
2010-09-25 13:30:40 +00:00
|
|
|
if (strcmp (script->token->str, "{"))
|
|
|
|
fprintf (stderr, "LoadEntities: found %s when expecting {\n",
|
2004-11-12 02:54:00 +00:00
|
|
|
script->token->str);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-09-08 03:39:44 +00:00
|
|
|
if (num_entities == max_entities) {
|
|
|
|
max_entities += 128;
|
|
|
|
entities = realloc (entities, max_entities * sizeof (entity_t));
|
|
|
|
}
|
2002-08-25 23:06:23 +00:00
|
|
|
entity = &entities[num_entities];
|
|
|
|
num_entities++;
|
|
|
|
|
2003-09-09 08:13:33 +00:00
|
|
|
memset (entity, 0, sizeof (*entity));
|
|
|
|
entity->color[0] = entity->color[1] = entity->color[2] = 1.0f;
|
2004-01-27 08:31:34 +00:00
|
|
|
VectorCopy (entity->color, entity->color2);
|
2003-09-09 08:13:33 +00:00
|
|
|
entity->falloff = DEFAULTFALLOFF * DEFAULTFALLOFF;
|
|
|
|
entity->lightradius = 0;
|
|
|
|
entity->lightoffset = LIGHTDISTBIAS;
|
2004-01-26 07:39:29 +00:00
|
|
|
entity->attenuation = options.attenuation;
|
2003-09-09 08:13:33 +00:00
|
|
|
|
2004-01-27 08:31:34 +00:00
|
|
|
dict = PL_NewDictionary ();
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
// go through all the keys in this entity
|
|
|
|
while (1) {
|
|
|
|
// parse key
|
2004-11-12 02:54:00 +00:00
|
|
|
if (!Script_GetToken (script, 1))
|
2002-08-25 23:06:23 +00:00
|
|
|
fprintf (stderr, "LoadEntities: EOF without closing brace");
|
2004-11-12 02:54:00 +00:00
|
|
|
if (!strcmp (script->token->str, "}"))
|
2002-08-25 23:06:23 +00:00
|
|
|
break;
|
2004-11-12 02:54:00 +00:00
|
|
|
key = strdup (script->token->str);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
// parse value
|
2004-11-12 02:54:00 +00:00
|
|
|
// FIXME shouldn't cross line
|
|
|
|
if (!Script_GetToken (script, 1))
|
2002-08-25 23:06:23 +00:00
|
|
|
fprintf (stderr, "LoadEntities: EOF without closing brace");
|
2010-09-05 06:35:22 +00:00
|
|
|
if (!strcmp (script->token->str, "}"))
|
2002-08-25 23:06:23 +00:00
|
|
|
fprintf (stderr, "LoadEntities: closing brace without data");
|
|
|
|
|
2003-09-08 03:39:44 +00:00
|
|
|
epair = calloc (1, sizeof (epair_t));
|
|
|
|
epair->key = key;
|
2004-11-12 02:54:00 +00:00
|
|
|
epair->value = strdup (script->token->str);
|
2002-08-25 23:06:23 +00:00
|
|
|
epair->next = entity->epairs;
|
|
|
|
entity->epairs = epair;
|
|
|
|
|
2006-12-09 06:00:36 +00:00
|
|
|
PL_D_AddObject (dict, key, PL_NewString (script->token->str));
|
2004-01-27 08:31:34 +00:00
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
if (!strcmp (key, "classname"))
|
2003-09-08 03:39:44 +00:00
|
|
|
entity->classname = epair->value;
|
2002-08-25 23:06:23 +00:00
|
|
|
else if (!strcmp (key, "target"))
|
2003-09-08 03:39:44 +00:00
|
|
|
entity->target = epair->value;
|
2002-08-25 23:06:23 +00:00
|
|
|
else if (!strcmp (key, "targetname"))
|
2003-09-08 03:39:44 +00:00
|
|
|
entity->targetname = epair->value;
|
2002-08-25 23:06:23 +00:00
|
|
|
else if (!strcmp (key, "origin")) {
|
|
|
|
// scan into doubles, then assign
|
|
|
|
// which makes it vec_t size independent
|
2004-11-12 02:54:00 +00:00
|
|
|
if (sscanf (script->token->str, "%lf %lf %lf",
|
2002-09-19 02:37:52 +00:00
|
|
|
&vec[0], &vec[1], &vec[2]) != 3)
|
2002-08-25 23:06:23 +00:00
|
|
|
fprintf (stderr, "LoadEntities: not 3 values for origin");
|
2004-01-26 07:39:29 +00:00
|
|
|
else
|
2004-01-27 08:31:34 +00:00
|
|
|
VectorCopy (vec, entity->origin);
|
|
|
|
}
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-25 13:30:40 +00:00
|
|
|
if (options.verbosity > 1 && entity->targetname)
|
|
|
|
printf ("%s %d %d\n", entity->targetname, entity->light,
|
|
|
|
entity->style);
|
2003-09-10 15:48:46 +00:00
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
// all fields have been parsed
|
2004-01-26 07:39:29 +00:00
|
|
|
if (entity->classname && !strncmp (entity->classname, "light", 5)) {
|
2004-01-27 08:31:34 +00:00
|
|
|
set_properties (entity, dict);
|
2003-09-09 08:13:33 +00:00
|
|
|
if (!entity->light)
|
|
|
|
entity->light = DEFAULTLIGHTLEVEL;
|
2004-01-26 07:39:29 +00:00
|
|
|
if (!entity->noise)
|
|
|
|
entity->noise = options.noise;
|
|
|
|
if (!entity->persistence)
|
|
|
|
entity->persistence = 1;
|
|
|
|
}
|
2004-01-27 08:31:34 +00:00
|
|
|
PL_Free (dict);
|
2003-09-09 08:13:33 +00:00
|
|
|
|
|
|
|
if (entity->light) {
|
|
|
|
// convert to subtraction to the brightness for the whole light,
|
|
|
|
// so it will fade nicely, rather than being clipped off
|
2004-01-27 08:31:34 +00:00
|
|
|
VectorScale (entity->color2,
|
2003-09-09 08:13:33 +00:00
|
|
|
entity->light * 16384.0 * options.globallightscale,
|
2004-01-27 08:31:34 +00:00
|
|
|
entity->color2);
|
|
|
|
entity->color[0] *= entity->color2[0];
|
|
|
|
entity->color[1] *= entity->color2[1];
|
|
|
|
entity->color[2] *= entity->color2[2];
|
2003-09-09 08:13:33 +00:00
|
|
|
|
|
|
|
if (entity->lightradius)
|
|
|
|
entity->subbrightness = 1.0 / (entity->lightradius
|
|
|
|
* entity->lightradius
|
|
|
|
* entity->falloff
|
|
|
|
+ LIGHTDISTBIAS);
|
|
|
|
if (entity->subbrightness < (1.0 / 1048576.0))
|
|
|
|
entity->subbrightness = (1.0 / 1048576.0);
|
2004-01-26 07:39:29 +00:00
|
|
|
|
|
|
|
intensity = entity->light;
|
|
|
|
if (intensity < 0)
|
|
|
|
intensity = -intensity;
|
|
|
|
switch (entity->attenuation) {
|
|
|
|
case LIGHT_RADIUS:
|
|
|
|
// default radius is intensity (same as LIGHT_LINEAR)
|
|
|
|
if (!entity->radius)
|
|
|
|
entity->radius = intensity;
|
|
|
|
break;
|
|
|
|
case LIGHT_LINEAR:
|
|
|
|
// don't allow radius to be greater than intensity
|
|
|
|
if (entity->radius > intensity || entity->radius == 0)
|
|
|
|
entity->radius = intensity;
|
|
|
|
break;
|
|
|
|
case LIGHT_REALISTIC:
|
|
|
|
if (options.cutoff) {
|
|
|
|
// approximate limit for faster lighting
|
|
|
|
cutoff_range = sqrt (intensity / options.cutoff);
|
|
|
|
if (!entity->radius || cutoff_range < entity->radius)
|
|
|
|
entity->radius = cutoff_range;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIGHT_INVERSE:
|
|
|
|
if (options.cutoff) {
|
|
|
|
// approximate limit for faster lighting
|
|
|
|
cutoff_range = intensity / options.cutoff;
|
|
|
|
if (!entity->radius || cutoff_range < entity->radius)
|
|
|
|
entity->radius = cutoff_range;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-09-09 08:13:33 +00:00
|
|
|
}
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-09-08 03:46:56 +00:00
|
|
|
if (entity->classname && !strcmp (entity->classname, "light")) {
|
|
|
|
if (entity->targetname && entity->targetname[0]
|
|
|
|
&& !entity->style) {
|
2002-08-25 23:06:23 +00:00
|
|
|
char s[16];
|
|
|
|
|
|
|
|
entity->style = LightStyleForTargetname (entity->targetname,
|
|
|
|
true);
|
|
|
|
sprintf (s, "%i", entity->style);
|
|
|
|
SetKeyValue (entity, "style", s);
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 02:37:52 +00:00
|
|
|
}
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
if (options.verbosity >= 0)
|
|
|
|
printf ("%d entities read\n", num_entities);
|
|
|
|
|
2002-09-19 02:37:52 +00:00
|
|
|
MatchTargets ();
|
2003-09-09 08:13:33 +00:00
|
|
|
|
|
|
|
WriteLights();
|
|
|
|
|
|
|
|
novislights = (entity_t **)calloc (num_entities, sizeof (entity_t *));
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *
|
|
|
|
ValueForKey (entity_t *ent, const char *key)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2002-09-19 02:37:52 +00:00
|
|
|
epair_t *ep;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2002-09-19 02:37:52 +00:00
|
|
|
for (ep = ent->epairs; ep; ep = ep->next)
|
2002-08-25 23:06:23 +00:00
|
|
|
if (!strcmp (ep->key, key))
|
|
|
|
return ep->value;
|
2002-09-19 02:37:52 +00:00
|
|
|
return "";
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-01-06 18:28:13 +00:00
|
|
|
SetKeyValue (entity_t *ent, const char *key, const char *value)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
|
|
|
epair_t *ep;
|
|
|
|
|
2002-09-19 02:37:52 +00:00
|
|
|
for (ep = ent->epairs; ep; ep = ep->next)
|
2002-08-25 23:06:23 +00:00
|
|
|
if (!strcmp (ep->key, key)) {
|
2003-09-08 03:39:44 +00:00
|
|
|
ep->value = strdup (value);
|
2002-08-25 23:06:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-09-19 02:37:52 +00:00
|
|
|
ep = malloc (sizeof (*ep));
|
|
|
|
ep->next = ent->epairs;
|
|
|
|
ent->epairs = ep;
|
2003-09-08 03:39:44 +00:00
|
|
|
ep->key = strdup (key);
|
|
|
|
ep->value = strdup (value);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2003-01-06 18:28:13 +00:00
|
|
|
FloatForKey (entity_t *ent, const char *key)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2003-01-06 18:28:13 +00:00
|
|
|
const char*k;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
k = ValueForKey (ent, key);
|
2002-09-19 02:37:52 +00:00
|
|
|
return atof (k);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2003-09-09 08:13:33 +00:00
|
|
|
entity_t *
|
2003-09-10 15:48:46 +00:00
|
|
|
FindEntityWithKeyPair (const char *key, const char *value)
|
2003-09-09 08:13:33 +00:00
|
|
|
{
|
|
|
|
entity_t *ent;
|
|
|
|
epair_t *ep;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_entities; i++) {
|
|
|
|
ent = &entities[i];
|
|
|
|
for (ep = ent->epairs; ep; ep = ep->next) {
|
|
|
|
if (!strcmp (ep->key, key)) {
|
|
|
|
if (!strcmp (ep->value, value))
|
|
|
|
return ent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
void
|
2003-01-06 18:28:13 +00:00
|
|
|
GetVectorForKey (entity_t *ent, const char *key, vec3_t vec)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *k;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2002-09-19 02:37:52 +00:00
|
|
|
k = ValueForKey (ent, key);
|
|
|
|
sscanf (k, "%f %f %f", &vec[0], &vec[1], &vec[2]);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WriteEntitiesToString (void)
|
|
|
|
{
|
2002-09-20 22:31:44 +00:00
|
|
|
dstring_t *buf;
|
2002-09-19 02:37:52 +00:00
|
|
|
epair_t *ep;
|
|
|
|
int i;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2002-09-20 22:31:44 +00:00
|
|
|
buf = dstring_newstr ();
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
if (options.verbosity >= 0)
|
|
|
|
printf ("%i switchable light styles\n", numlighttargets);
|
|
|
|
|
2002-09-19 02:37:52 +00:00
|
|
|
for (i = 0; i < num_entities; i++) {
|
2002-08-25 23:06:23 +00:00
|
|
|
ep = entities[i].epairs;
|
|
|
|
if (!ep)
|
|
|
|
continue; // ent got removed
|
|
|
|
|
2002-09-20 22:31:44 +00:00
|
|
|
dstring_appendstr (buf, "{\n");
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
for (ep = entities[i].epairs; ep; ep = ep->next) {
|
2003-09-09 08:13:33 +00:00
|
|
|
dasprintf (buf, "\"%s\" \"%s\"\n", ep->key, ep->value);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
2002-09-20 22:31:44 +00:00
|
|
|
dstring_appendstr (buf, "}\n");
|
2002-09-19 02:37:52 +00:00
|
|
|
}
|
2002-09-20 22:31:44 +00:00
|
|
|
BSP_AddEntities (bsp, buf->str, buf->size);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|