2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 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 GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #define USE_QERTABLE_DEFINE
26 #include "qerplugin.h"
27 #define USE_ECLASSMANAGER_DEFINE
29 #define USE_SCRIPLIBTABLE_DEFINE
30 #include "iscriplib.h"
32 #define __VFSTABLENAME g_FileSystemTable_def
33 #define USE_VFSTABLE_DEFINE
34 #include "ifilesystem.h"
37 #include "eclass_def.h"
39 /*! \file eclass_def.cpp
40 \brief .def entity description format
41 implements parsing for .def entity format
42 this is statically linked into the radiant core as we always need it, but really considered
43 as an idependant module by the rest of the core. "ECLASS_MAJOR" "def"
46 _QERScripLibTable g_ScripLibTable;
47 _EClassManagerTable g_EClassManagerTable;
48 _QERFuncTable_1 g_FuncTable;
49 _QERFileSystemTable g_FileSystemTable_def;
51 CSynapseBuiltinClientDef eclass_def;
53 // forward declare, I'm cheap
54 void Eclass_ScanFile (char *filename);
56 const char* EClass_GetExtension()
61 void CSynapseBuiltinClientDef::EnumerateInterfaces(CSynapseServer *server)
63 AddAPI(SCRIPLIB_MAJOR, NULL, sizeof(g_ScripLibTable), SYN_REQUIRE, &g_ScripLibTable);
64 AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);
65 AddAPI(ECLASSMANAGER_MAJOR, NULL, sizeof(g_EClassManagerTable), SYN_REQUIRE, &g_EClassManagerTable);
66 // hardcode the minor for now, we can still add it to the synapse.config at some point
67 AddAPI(VFS_MAJOR, "pk3", sizeof(g_FileSystemTable_def), SYN_REQUIRE, &g_FileSystemTable_def);
69 AddAPI(ECLASS_MAJOR, "def", sizeof(_EClassTable));
72 bool CSynapseBuiltinClientDef::RequestAPI(APIDescriptor_t *pAPI)
74 if (!strcmp(pAPI->major_name, ECLASS_MAJOR))
76 _EClassTable* pTable= static_cast<_EClassTable*>(pAPI->mpTable);
77 pTable->m_pfnScanFile = &Eclass_ScanFile;
78 pTable->m_pfnGetExtension = &EClass_GetExtension;
83 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
89 const char* CSynapseBuiltinClientDef::GetInfo()
91 return "Builtin .def module built " __DATE__ " " RADIANT_VERSION;
94 // ------------------------------------------------------------------------------------------------
96 qboolean eclass_found;
99 void setSpecialLoad(eclass_t *e, const char* pWhat, char*& p)
101 // Hydra: removed some amazingly bad cstring usage, whoever wrote that
102 // needs to be taken out and shot.
107 p = NULL; // incase we don't find what we're looking for.
108 where = strstr(e->comments,pWhat);
112 pText = where + strlen(pWhat);
116 where = strchr(pText,'\"');
119 int len = (where-pText);
120 p = new char[len + 1];
121 strncpy(p,pText,len);
122 p[len]=0; // just to make sure, as most implementations of strncpy don't null terminate
128 eclass_t *Eclass_InitFromText (char *text)
137 e = (eclass_t*)malloc(sizeof(*e));
138 memset (e, 0, sizeof(*e));
140 text += strlen("/*QUAKED ");
143 text = COM_Parse (text);
144 e->name = (char*)malloc (strlen(Get_COM_Token())+1);
145 strcpy (e->name, Get_COM_Token());
148 // grab the color, reformat as texture name
149 r = sscanf (text," (%f %f %f)", &e->color[0], &e->color[1], &e->color[2]);
153 sprintf (color, "(%f %f %f)", e->color[0], e->color[1], e->color[2]);
154 //strcpy (e->texdef.name, color);
155 e->texdef.SetName(color);
167 text = COM_Parse (text);
168 if (Get_COM_Token()[0] == '(')
169 { // parse the size as two vectors
171 r = sscanf (text,"%f %f %f) (%f %f %f)", &e->mins[0], &e->mins[1], &e->mins[2],
172 &e->maxs[0], &e->maxs[1], &e->maxs[2]);
177 for (i=0 ; i<2 ; i++)
192 // copy to the first /n
194 while (*text && *text != '\n')
199 // any remaining words are parm flags
201 for (i=0 ; i<MAX_FLAGS ; i++)
206 strcpy (e->flagnames[i], Get_COM_Token());
209 // find the length until close comment
210 for (t=text ; t[0] && !(t[0]=='*' && t[1]=='/') ; t++)
213 // copy the comment block out
215 e->comments = (char*)malloc (len+1);
216 memcpy (e->comments, text, len);
218 // the win32 Gtk widgets are expecting text stuff to be in unix format (that is CR only instead of DOS's CR/LF)
219 // we convert on the fly by replacing the LF with a ' ' (yeah I'm cheap)
220 for (i=0 ; i<len ; i++)
222 e->comments[i] = ' ';
224 e->comments[i] = text[i];
226 e->comments[len] = 0;
228 setSpecialLoad(e, "model=", e->modelpath);
229 setSpecialLoad(e, "skin=", e->skinpath);
231 setSpecialLoad(e, "frame=", pFrame);
234 e->nFrame = atoi(pFrame);
235 delete pFrame; //Hydra - Fixed memory leak!
239 setSpecialLoad(e, "texture=", e->skinpath);
243 if (strcmpi(e->name, "light") == 0 || strcmpi(e->name, "dlight") == 0 || strcmpi(e->name, "lightjunior") == 0)
245 e->nShowFlags |= ECLASS_LIGHT;
248 if ( (strnicmp(e->name, "info_player", strlen("info_player")) == 0)
249 ||(strnicmp(e->name, "path_corner", strlen("path_corner")) == 0)
250 ||(strnicmp(e->name, "team_ctf", strlen("team_ctf")) == 0)
251 ||(strnicmp(e->name, "misc_teleporter_dest", strlen("misc_teleporter_dest")) == 0)
254 e->nShowFlags |= ECLASS_ANGLE;
256 if (strcmpi(e->name, "path") == 0)
258 e->nShowFlags |= ECLASS_PATH;
260 if (strcmpi(e->name, "misc_model") == 0)
262 e->nShowFlags |= ECLASS_MISCMODEL;
269 void Eclass_ScanFile (char *filename)
277 QE_ConvertDOSToUnixName( temp, filename );
279 size = vfsLoadFullPathFile(filename, (void**)&data);
282 Sys_FPrintf (SYS_ERR, "Eclass_ScanFile: %s not found\n", filename);
285 Sys_Printf ("ScanFile: %s\n", temp);
286 eclass_found = false;
287 for (i=0 ; i<size ; i++)
289 if (!strncmp(data+i, "/*QUAKED",8))
291 e = Eclass_InitFromText (data+i);
293 Eclass_InsertAlphabetized (e);
295 Sys_FPrintf (SYS_ERR, "Error parsing: %s in %s\n",debugname, filename);
299 Set_Eclass_Found(true);
300 if ( Get_Parsing_Single() )