2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../idlib/precompiled.h"
38 size_t idDeclEntityDef::Size( void ) const {
39 return sizeof( idDeclEntityDef ) + dict.Allocated();
44 idDeclEntityDef::FreeData
47 void idDeclEntityDef::FreeData( void ) {
53 idDeclEntityDef::Parse
56 bool idDeclEntityDef::Parse( const char *text, const int textLength ) {
58 idToken token, token2;
60 src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
61 src.SetFlags( DECL_LEXER_FLAGS );
62 src.SkipUntilString( "{" );
65 if ( !src.ReadToken( &token ) ) {
69 if ( !token.Icmp( "}" ) ) {
72 if ( token.type != TT_STRING ) {
73 src.Warning( "Expected quoted string, but found '%s'", token.c_str() );
78 if ( !src.ReadToken( &token2 ) ) {
79 src.Warning( "Unexpected end of file" );
84 if ( dict.FindKey( token ) ) {
85 src.Warning( "'%s' already defined", token.c_str() );
87 dict.Set( token, token2 );
90 // we always automatically set a "classname" key to our name
91 dict.Set( "classname", GetName() );
93 // "inherit" keys will cause all values from another entityDef to be copied into this one
94 // if they don't conflict. We can't have circular recursions, because each entityDef will
95 // never be parsed mroe than once
97 // find all of the dicts first, because copying inherited values will modify the dict
98 idList<const idDeclEntityDef *> defList;
101 const idKeyValue *kv;
102 kv = dict.MatchPrefix( "inherit", NULL );
107 const idDeclEntityDef *copy = static_cast<const idDeclEntityDef *>( declManager->FindType( DECL_ENTITYDEF, kv->GetValue(), false ) );
109 src.Warning( "Unknown entityDef '%s' inherited by '%s'", kv->GetValue().c_str(), GetName() );
111 defList.Append( copy );
114 // delete this key/value pair
115 dict.Delete( kv->GetKey() );
118 // now copy over the inherited key / value pairs
119 for ( int i = 0 ; i < defList.Num() ; i++ ) {
120 dict.SetDefaults( &defList[ i ]->dict );
123 // precache all referenced media
124 // do this as long as we arent in modview
125 if ( !( com_editors & (EDITOR_RADIANT|EDITOR_AAS) ) ) {
126 game->CacheDictionaryMedia( &dict );
134 idDeclEntityDef::DefaultDefinition
137 const char *idDeclEntityDef::DefaultDefinition( void ) const {
140 "\t" "\"DEFAULTED\"\t\"1\"\n"
146 idDeclEntityDef::Print
148 Dumps all key/value pairs, including inherited ones
151 void idDeclEntityDef::Print( void ) {