2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
28 char eclass_directory[1024];
32 the classname, color triple, and bounding box are parsed out of comments
33 A ? size means take the exact brush size.
35 /*QUAKED <classname> (0 0 0) ?
36 /*QUAKED <classname> (0 0 0) (-8 -8 -8) (8 8 8)
38 Flag names can follow the size description:
40 /*QUAKED func_door (0 .5 .8) ? START_OPEN STONE_SOUND DOOR_DONT_LINK GOLD_KEY SILVER_KEY
45 eclass_t *Eclass_InitFromText (char *text)
54 e = qmalloc(sizeof(*e));
55 memset (e, 0, sizeof(*e));
57 text += strlen("/*QUAKED ");
60 text = COM_Parse (text);
61 e->name = qmalloc (strlen(com_token)+1);
62 strcpy (e->name, com_token);
65 // grab the color, reformat as texture name
66 r = sscanf (text," (%f %f %f)", &e->color[0], &e->color[1], &e->color[2]);
69 sprintf (color, "(%f %f %f)", e->color[0], e->color[1], e->color[2]);
70 strcpy (e->texdef.name, color);
81 text = COM_Parse (text);
82 if (com_token[0] == '(')
83 { // parse the size as two vectors
85 r = sscanf (text,"%f %f %f) (%f %f %f)", &e->mins[0], &e->mins[1], &e->mins[2],
86 &e->maxs[0], &e->maxs[1], &e->maxs[2]);
108 // copy to the first /n
110 while (*text && *text != '\n')
115 // any remaining words are parm flags
117 for (i=0 ; i<8 ; i++)
122 strcpy (e->flagnames[i], com_token);
125 // find the length until close comment
126 for (t=text ; t[0] && !(t[0]=='*' && t[1]=='/') ; t++)
129 // copy the comment block out
131 e->comments = qmalloc (len+1);
132 memcpy (e->comments, text, len);
134 for (i=0 ; i<len ; i++)
136 e->comments[i] = '\r';
138 e->comments[i] = text[i];
140 e->comments[len] = 0;
148 Eclass_InsertAlphabetized
151 void Eclass_InsertAlphabetized (eclass_t *e)
163 if (stricmp (e->name, s->name) < 0)
172 if (!s->next || stricmp (e->name, s->next->name) < 0)
188 void Eclass_ScanFile (char *filename)
196 QE_ConvertDOSToUnixName( temp, filename );
198 Sys_Printf ("ScanFile: %s\n", temp);
200 size = LoadFile (filename, (void *)&data);
202 for (i=0 ; i<size ; i++)
203 if (!strncmp(data+i, "/*QUAKED",8))
205 e = Eclass_InitFromText (data+i);
207 Eclass_InsertAlphabetized (e);
209 printf ("Error parsing: %s in %s\n",debugname, filename);
217 void Eclass_InitForSourceDirectory (char *path)
219 struct _finddata_t fileinfo;
226 QE_ConvertDOSToUnixName( temp, path );
228 Sys_Printf ("Eclass_InitForSourceDirectory: %s\n", temp );
230 strcpy (filebase, path);
231 s = filebase + strlen(filebase)-1;
232 while (*s != '\\' && *s != '/' && s!=filebase)
238 handle = _findfirst (path, &fileinfo);
243 sprintf (filename, "%s\\%s", filebase, fileinfo.name);
244 Eclass_ScanFile (filename);
245 } while (_findnext( handle, &fileinfo ) != -1);
250 eclass_bad = Eclass_InitFromText ("/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?");
253 eclass_t *Eclass_ForName (char *name, qboolean has_brushes)
261 for (e=eclass ; e ; e=e->next)
262 if (!strcmp (name, e->name))
265 // create a new class for it
268 sprintf (init, "/*QUAKED %s (0 0.5 0) ?\nNot found in source.\n", name);
269 e = Eclass_InitFromText (init);
273 sprintf (init, "/*QUAKED %s (0 0.5 0) (-8 -8 -8) (8 8 8)\nNot found in source.\n", name);
274 e = Eclass_InitFromText (init);
277 Eclass_InsertAlphabetized (e);