2002-09-19 18:51:19 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
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.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
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.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
See file, 'COPYING', for details.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
#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-09-19 16:58:48 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
2003-08-11 17:11:44 +00:00
|
|
|
#include <errno.h>
|
2003-08-11 20:43:26 +00:00
|
|
|
#include <ctype.h>
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
#include "QF/dstring.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
#include "QF/quakefs.h"
|
2004-11-02 05:05:00 +00:00
|
|
|
#include "QF/script.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
#include "QF/sys.h"
|
2003-09-02 20:20:54 +00:00
|
|
|
#include "QF/va.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#include "bsp5.h"
|
2010-08-05 03:39:26 +00:00
|
|
|
#include "compat.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
int nummapbrushfaces;
|
2002-09-19 17:14:23 +00:00
|
|
|
int nummapbrushes;
|
|
|
|
mbrush_t mapbrushes[MAX_MAP_BRUSHES];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int num_entities;
|
|
|
|
entity_t entities[MAX_MAP_ENTITIES];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int nummiptex;
|
|
|
|
char miptex[MAX_MAP_TEXINFO][16];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
int numdetailbrushes;
|
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
script_t *map_script;
|
2003-09-03 18:27:27 +00:00
|
|
|
|
|
|
|
static void __attribute__ ((format (printf, 1, 2), noreturn))
|
|
|
|
map_error (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
2010-08-05 03:30:13 +00:00
|
|
|
fprintf (stderr, "%s:%d: ", map_script->file, map_script->line);
|
2003-09-03 18:27:27 +00:00
|
|
|
vfprintf (stderr, fmt, args);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
va_end (args);
|
|
|
|
exit (1);
|
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
int
|
2003-01-06 18:28:13 +00:00
|
|
|
FindMiptex (const char *name)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
if (strcmp (name, "hint") == 0)
|
|
|
|
return TEX_HINT;
|
|
|
|
if (strcmp (name, "skip") == 0)
|
|
|
|
return TEX_SKIP;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < nummiptex; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!strcmp (name, miptex[i]))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
if (nummiptex == MAX_MAP_TEXINFO)
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("nummiptex == MAX_MAP_TEXINFO");
|
2002-09-19 16:58:48 +00:00
|
|
|
strcpy (miptex[i], name);
|
|
|
|
nummiptex++;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
FindTexinfo
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Returns a global texinfo number
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2002-09-19 17:14:23 +00:00
|
|
|
FindTexinfo (texinfo_t *t)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i, j;
|
|
|
|
texinfo_t *tex;
|
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
if (t->miptex < 0)
|
|
|
|
return t->miptex; // it's HINT or SKIP
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// set the special flag
|
2002-09-19 17:14:23 +00:00
|
|
|
if (miptex[t->miptex][0] == '*'
|
2002-09-19 18:51:19 +00:00
|
|
|
|| !strncasecmp (miptex[t->miptex], "sky", 3))
|
|
|
|
t->flags |= TEX_SPECIAL;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
tex = bsp->texinfo;
|
|
|
|
for (i = 0; i < bsp->numtexinfo; i++, tex++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (t->miptex != tex->miptex)
|
|
|
|
continue;
|
|
|
|
if (t->flags != tex->flags)
|
|
|
|
continue;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 8; j++)
|
2008-07-19 05:40:57 +00:00
|
|
|
if (t->vecs[j / 4][j % 4] != tex->vecs[j / 4][j % 4])
|
2002-09-19 16:58:48 +00:00
|
|
|
break;
|
|
|
|
if (j != 8)
|
|
|
|
continue;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
return i;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// allocate a new texture
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddTexinfo (bsp, t);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
entity_t *mapent;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
ParseEpair (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
epair_t *e;
|
|
|
|
|
|
|
|
e = malloc (sizeof (epair_t));
|
|
|
|
memset (e, 0, sizeof (epair_t));
|
2002-09-19 16:58:48 +00:00
|
|
|
e->next = mapent->epairs;
|
|
|
|
mapent->epairs = e;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
e->key = strdup (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
e->value = strdup (map_script->token->str);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
vec3_t baseaxis[18] = {
|
|
|
|
{0, 0, 1}, {1, 0, 0}, {0, -1, 0}, // floor
|
|
|
|
{0, 0, -1}, {1, 0, 0}, {0, -1, 0}, // ceiling
|
|
|
|
{1, 0, 0}, {0, 1, 0}, {0, 0, -1}, // west wall
|
|
|
|
{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}, // east wall
|
|
|
|
{0, 1, 0}, {1, 0, 0}, {0, 0, -1}, // south wall
|
|
|
|
{0, -1, 0}, {1, 0, 0}, {0, 0, -1} // north wall
|
2002-09-19 16:58:48 +00:00
|
|
|
};
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
TextureAxisFromPlane (plane_t *pln, vec3_t xv, vec3_t yv)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
float dot, best;
|
2002-09-19 18:51:19 +00:00
|
|
|
int bestaxis, i;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
best = 0;
|
|
|
|
bestaxis = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
dot = DotProduct (pln->normal, baseaxis[i * 3]);
|
|
|
|
if (dot > best) {
|
2002-09-19 16:58:48 +00:00
|
|
|
best = dot;
|
|
|
|
bestaxis = i;
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
VectorCopy (baseaxis[bestaxis * 3 + 1], xv);
|
|
|
|
VectorCopy (baseaxis[bestaxis * 3 + 2], yv);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-02-04 18:19:57 +00:00
|
|
|
static vec3_t *
|
|
|
|
ParseVerts (int *n_verts)
|
|
|
|
{
|
|
|
|
vec3_t *verts;
|
|
|
|
int i;
|
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
if (map_script->token->str[0] != ':')
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("parsing brush");
|
2010-08-05 03:30:13 +00:00
|
|
|
*n_verts = atoi (map_script->token->str + 1);
|
2003-02-04 18:19:57 +00:00
|
|
|
verts = malloc (sizeof (vec3_t) * *n_verts);
|
|
|
|
|
|
|
|
for (i = 0; i < *n_verts; i++) {
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, true);
|
|
|
|
verts[i][0] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, true);
|
|
|
|
verts[i][1] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, true);
|
|
|
|
verts[i][2] = atof (map_script->token->str);
|
2003-02-04 18:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return verts;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 17:14:23 +00:00
|
|
|
ParseBrush (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2003-09-03 22:00:08 +00:00
|
|
|
float rotate, scale[2];
|
|
|
|
float ang, sinv, cosv, ns, nt;
|
|
|
|
int sv, tv;
|
|
|
|
int i, j, n_verts = 0, hltexdef;
|
2002-09-19 17:14:23 +00:00
|
|
|
mbrush_t *b;
|
|
|
|
mface_t *f, *f2;
|
2003-09-03 22:00:08 +00:00
|
|
|
plane_t plane;
|
2002-09-19 18:51:19 +00:00
|
|
|
texinfo_t tx;
|
2002-09-19 17:14:23 +00:00
|
|
|
vec3_t planepts[3];
|
2003-09-03 22:00:08 +00:00
|
|
|
vec3_t t1, t2, *verts = 0;
|
|
|
|
vec_t d, vecs[2][4];
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
b = &mapbrushes[nummapbrushes];
|
|
|
|
nummapbrushes++;
|
|
|
|
b->next = mapent->brushes;
|
|
|
|
mapent->brushes = b;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, true);
|
|
|
|
if (strcmp (map_script->token->str, "(") != 0) {
|
2003-02-04 18:19:57 +00:00
|
|
|
verts = ParseVerts (&n_verts);
|
|
|
|
} else {
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_UngetToken (map_script);
|
2003-02-04 18:19:57 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
do {
|
2010-08-05 03:30:13 +00:00
|
|
|
if (!Script_GetToken (map_script, true))
|
2002-09-19 16:58:48 +00:00
|
|
|
break;
|
2010-08-05 03:30:13 +00:00
|
|
|
if (!strcmp (map_script->token->str, "}"))
|
2002-09-19 16:58:48 +00:00
|
|
|
break;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-02-04 18:19:57 +00:00
|
|
|
if (verts) {
|
|
|
|
int n_v, v;
|
2010-08-05 03:30:13 +00:00
|
|
|
n_v = atoi (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
2003-02-04 18:19:57 +00:00
|
|
|
for (i = 0; i < n_v; i++) {
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
v = atof (map_script->token->str);
|
2003-02-04 18:19:57 +00:00
|
|
|
if (i < 3)
|
|
|
|
VectorCopy (verts[v], planepts[i]);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
2003-02-04 18:19:57 +00:00
|
|
|
} else {
|
|
|
|
// read the three point plane definition
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
if (i != 0)
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, true);
|
|
|
|
if (strcmp (map_script->token->str, "("))
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("parsing brush");
|
2003-02-04 18:19:57 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 3; j++) {
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
planepts[i][j] = atof (map_script->token->str);
|
2003-02-04 18:19:57 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
if (strcmp (map_script->token->str, ")"))
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("parsing brush");
|
2003-02-04 18:19:57 +00:00
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
// convert points to a plane
|
|
|
|
VectorSubtract (planepts[0], planepts[1], t1);
|
|
|
|
VectorSubtract (planepts[2], planepts[1], t2);
|
|
|
|
CrossProduct(t1, t2, plane.normal);
|
|
|
|
VectorNormalize (plane.normal);
|
|
|
|
plane.dist = DotProduct(planepts[1], plane.normal);
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
// read the texturedef
|
|
|
|
memset (&tx, 0, sizeof (tx));
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
tx.miptex = FindMiptex (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
if ((hltexdef = !strcmp (map_script->token->str, "["))) {
|
2003-09-03 22:00:08 +00:00
|
|
|
// S vector
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[0][0] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[0][1] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[0][2] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[0][3] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
if (strcmp (map_script->token->str, "]"))
|
2003-09-03 22:32:40 +00:00
|
|
|
map_error ("missing ]");
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
if (strcmp (map_script->token->str, "["))
|
2003-09-03 22:32:40 +00:00
|
|
|
map_error ("missing [");
|
2003-09-03 22:00:08 +00:00
|
|
|
// T vector
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[1][0] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[1][1] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[1][2] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[1][3] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
if (strcmp (map_script->token->str, "]"))
|
2003-09-03 22:32:40 +00:00
|
|
|
map_error ("missing ]");
|
2003-09-03 22:00:08 +00:00
|
|
|
} else {
|
2010-08-05 03:30:13 +00:00
|
|
|
vecs[0][3] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
vecs[1][3] = atof (map_script->token->str);
|
2003-09-03 22:00:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
rotate = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
scale[0] = atof (map_script->token->str);
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
scale[1] = atof (map_script->token->str);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
while (Script_TokenAvailable (map_script, false)) {
|
|
|
|
Script_GetToken (map_script, false);
|
|
|
|
if (!strcmp (map_script->token->str, "detail"))
|
2003-02-04 23:26:26 +00:00
|
|
|
b->detail = 1;
|
|
|
|
else
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("parse error");
|
2003-02-04 18:19:57 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// if the three points are all on a previous plane, it is a duplicate
|
|
|
|
// plane
|
2002-09-19 17:14:23 +00:00
|
|
|
for (f2 = b->faces; f2; f2 = f2->next) {
|
|
|
|
for (i = 0; i < 3; i++) {
|
2002-09-19 18:51:19 +00:00
|
|
|
d = DotProduct (planepts[i], f2->plane.normal)
|
|
|
|
- f2->plane.dist;
|
2002-09-19 16:58:48 +00:00
|
|
|
if (d < -ON_EPSILON || d > ON_EPSILON)
|
|
|
|
break;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
if (i == 3)
|
2002-09-19 16:58:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
if (f2) {
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("WARNING: brush with duplicate plane\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
if (DotProduct (plane.normal, plane.normal) < 0.1) {
|
|
|
|
printf ("WARNING: brush plane with no normal on line %d\n",
|
2010-08-05 03:30:13 +00:00
|
|
|
map_script->line);
|
2003-09-03 22:00:08 +00:00
|
|
|
continue;
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
if (!hltexdef) {
|
|
|
|
// fake proper texture vectors from QuakeEd style
|
2003-09-03 22:54:14 +00:00
|
|
|
TextureAxisFromPlane (&plane, vecs[0], vecs[1]);
|
2003-09-03 22:00:08 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
if (!scale[0])
|
|
|
|
scale[0] = 1;
|
|
|
|
if (!scale[1])
|
|
|
|
scale[1] = 1;
|
|
|
|
|
|
|
|
// rotate axis
|
|
|
|
if (rotate == 0) {
|
|
|
|
sinv = 0;
|
|
|
|
cosv = 1;
|
|
|
|
} else if (rotate == 90) {
|
|
|
|
sinv = 1;
|
|
|
|
cosv = 0;
|
|
|
|
} else if (rotate == 180) {
|
|
|
|
sinv = 0;
|
|
|
|
cosv = -1;
|
|
|
|
} else if (rotate == 270) {
|
|
|
|
sinv = -1;
|
|
|
|
cosv = 0;
|
|
|
|
} else {
|
|
|
|
ang = rotate / 180 * M_PI;
|
|
|
|
sinv = sin (ang);
|
|
|
|
cosv = cos (ang);
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
if (vecs[0][0])
|
|
|
|
sv = 0;
|
|
|
|
else if (vecs[0][1])
|
|
|
|
sv = 1;
|
|
|
|
else
|
|
|
|
sv = 2;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
if (vecs[1][0])
|
|
|
|
tv = 0;
|
|
|
|
else if (vecs[1][1])
|
|
|
|
tv = 1;
|
|
|
|
else
|
|
|
|
tv = 2;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
// rotate
|
|
|
|
ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
|
|
|
|
nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
|
|
|
|
vecs[i][sv] = ns;
|
|
|
|
vecs[i][tv] = nt;
|
2006-12-24 03:13:29 +00:00
|
|
|
// scale and store into texinfo
|
2003-09-03 22:00:08 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
tx.vecs[i][j] = vecs[i][j] / scale[i];
|
|
|
|
tx.vecs[i][3] = vecs[i][3];
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-09-08 03:00:53 +00:00
|
|
|
f = calloc (1, sizeof (mface_t));
|
2003-09-03 22:00:08 +00:00
|
|
|
f->next = b->faces;
|
|
|
|
b->faces = f;
|
|
|
|
f->plane = plane;
|
2002-09-19 17:14:23 +00:00
|
|
|
// unique the texinfo
|
|
|
|
f->texinfo = FindTexinfo (&tx);
|
2003-09-03 22:00:08 +00:00
|
|
|
nummapbrushfaces++;
|
2002-09-19 16:58:48 +00:00
|
|
|
} while (1);
|
2003-02-04 18:19:57 +00:00
|
|
|
if (verts)
|
|
|
|
free (verts);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static qboolean
|
2002-09-19 17:14:23 +00:00
|
|
|
ParseEntity (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2010-08-05 03:30:13 +00:00
|
|
|
if (!Script_GetToken (map_script, true))
|
2002-09-19 16:58:48 +00:00
|
|
|
return false;
|
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
if (strcmp (map_script->token->str, "{"))
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("ParseEntity: { not found");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (num_entities == MAX_MAP_ENTITIES)
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("num_entities == MAX_MAP_ENTITIES");
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
mapent = &entities[num_entities];
|
|
|
|
num_entities++;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
do {
|
2010-08-05 03:30:13 +00:00
|
|
|
if (!Script_GetToken (map_script, true))
|
2003-09-03 18:27:27 +00:00
|
|
|
map_error ("ParseEntity: EOF without closing brace");
|
2010-08-05 03:30:13 +00:00
|
|
|
if (!strcmp (map_script->token->str, "}"))
|
2002-09-19 16:58:48 +00:00
|
|
|
break;
|
2010-08-05 03:30:13 +00:00
|
|
|
if (!strcmp (map_script->token->str, "{"))
|
2002-09-19 16:58:48 +00:00
|
|
|
ParseBrush ();
|
|
|
|
else
|
|
|
|
ParseEpair ();
|
|
|
|
} while (1);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
if (!strcmp ("am_detail", ValueForKey (mapent, "classname"))) {
|
|
|
|
mbrush_t *b, *lb;
|
|
|
|
// set detail flag
|
|
|
|
for (lb = b = mapent->brushes; b; lb = b, b = b->next) {
|
|
|
|
b->detail = 1;
|
|
|
|
numdetailbrushes++;
|
|
|
|
}
|
|
|
|
// add to worldspawn
|
|
|
|
lb->next = entities->brushes;
|
|
|
|
entities->brushes = mapent->brushes;
|
|
|
|
num_entities--;
|
|
|
|
memset (mapent, 0, sizeof (entity_t));
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
mbrush_t *b;
|
|
|
|
for (b = mapent->brushes; b; b = b->next)
|
|
|
|
if (b->detail)
|
|
|
|
numdetailbrushes++;
|
|
|
|
}
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
GetVectorForKey (mapent, "origin", mapent->origin);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2003-01-06 18:28:13 +00:00
|
|
|
LoadMapFile (const char *filename)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
char *buf;
|
2002-09-19 20:39:33 +00:00
|
|
|
QFile *file;
|
2004-02-05 00:13:42 +00:00
|
|
|
int bytes;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
file = Qopen (filename, "rt");
|
2003-08-11 17:11:44 +00:00
|
|
|
if (!file)
|
|
|
|
Sys_Error ("couldn't open %s. %s", filename, strerror(errno));
|
2004-02-05 00:13:42 +00:00
|
|
|
bytes = Qfilesize (file);
|
|
|
|
buf = malloc (bytes + 1);
|
|
|
|
bytes = Qread (file, buf, bytes);
|
|
|
|
buf[bytes] = 0;
|
2002-09-19 20:39:33 +00:00
|
|
|
Qclose (file);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
map_script = Script_New ();
|
|
|
|
Script_Start (map_script, filename, buf);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
num_entities = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-08-05 03:39:26 +00:00
|
|
|
if (Script_GetToken (map_script, 1)) {
|
|
|
|
if (strequal (map_script->token->str, "QuakeForge-map")) {
|
|
|
|
if (!Script_TokenAvailable (map_script, 1))
|
|
|
|
map_error ("Unexpected EOF reading %s\n", filename);
|
|
|
|
} else {
|
|
|
|
Script_UngetToken (map_script);
|
|
|
|
while (ParseEntity ())
|
|
|
|
;
|
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2010-08-05 03:30:13 +00:00
|
|
|
Script_Delete (map_script);
|
|
|
|
map_script = 0;
|
2002-09-19 16:58:48 +00:00
|
|
|
free (buf);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
qprintf ("--- LoadMapFile ---\n");
|
|
|
|
qprintf ("%s\n", filename);
|
2003-09-03 22:00:08 +00:00
|
|
|
qprintf ("%5i faces\n", nummapbrushfaces);
|
2003-02-04 23:26:26 +00:00
|
|
|
qprintf ("%5i brushes (%i detail)\n", nummapbrushes, numdetailbrushes);
|
2002-09-19 16:58:48 +00:00
|
|
|
qprintf ("%5i entities\n", num_entities);
|
2003-09-03 22:00:08 +00:00
|
|
|
qprintf ("%5i textures\n", nummiptex);
|
2002-09-19 16:58:48 +00:00
|
|
|
qprintf ("%5i texinfo\n", bsp->numtexinfo);
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
|
|
|
PrintEntity (entity_t *ent)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
epair_t *ep;
|
|
|
|
|
|
|
|
for (ep = ent->epairs; ep; ep = ep->next)
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("%20s : %s\n", ep->key, ep->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *
|
|
|
|
ValueForKey (entity_t *ent, const char *key)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
epair_t *ep;
|
|
|
|
|
|
|
|
for (ep = ent->epairs; ep; ep = ep->next)
|
|
|
|
if (!strcmp (ep->key, key))
|
2002-09-19 16:58:48 +00:00
|
|
|
return ep->value;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2003-01-06 18:28:13 +00:00
|
|
|
SetKeyValue (entity_t *ent, const char *key, const char *value)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
epair_t *ep;
|
|
|
|
|
|
|
|
for (ep = ent->epairs; ep; ep = ep->next)
|
|
|
|
if (!strcmp (ep->key, key)) {
|
2002-09-19 16:58:48 +00:00
|
|
|
free (ep->value);
|
|
|
|
ep->value = strdup (value);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
ep = malloc (sizeof (*ep));
|
2002-09-19 16:58:48 +00:00
|
|
|
ep->next = ent->epairs;
|
|
|
|
ent->epairs = ep;
|
|
|
|
ep->key = strdup (key);
|
|
|
|
ep->value = strdup (value);
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2003-01-06 18:28:13 +00:00
|
|
|
GetVectorForKey (entity_t *ent, const char *key, vec3_t vec)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *k;
|
2002-09-19 17:14:23 +00:00
|
|
|
double v1, v2, v3;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
k = ValueForKey (ent, key);
|
|
|
|
v1 = v2 = v3 = 0;
|
2002-09-23 16:27:17 +00:00
|
|
|
// scanf into doubles, then assign, so it is vec_t size independent
|
2002-09-19 16:58:48 +00:00
|
|
|
sscanf (k, "%lf %lf %lf", &v1, &v2, &v3);
|
|
|
|
vec[0] = v1;
|
|
|
|
vec[1] = v2;
|
|
|
|
vec[2] = v3;
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
|
|
|
WriteEntitiesToString (void)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 20:39:33 +00:00
|
|
|
dstring_t *buf;
|
2002-09-19 18:51:19 +00:00
|
|
|
epair_t *ep;
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
buf = dstring_newstr ();
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_entities; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
ep = entities[i].epairs;
|
|
|
|
if (!ep)
|
2002-09-19 17:14:23 +00:00
|
|
|
continue; // ent got removed
|
|
|
|
|
2002-09-19 20:39:33 +00:00
|
|
|
dstring_appendstr (buf, "{\n");
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (ep = entities[i].epairs; ep; ep = ep->next) {
|
2003-09-02 20:20:54 +00:00
|
|
|
dstring_appendstr (buf, va ("\"%s\" \"%s\"\n",
|
|
|
|
ep->key, ep->value));
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 20:39:33 +00:00
|
|
|
dstring_appendstr (buf, "}\n");
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 20:39:33 +00:00
|
|
|
BSP_AddEntities (bsp, buf->str, buf->size);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|