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 idDeclSkin::Size( void ) const {
39 return sizeof( idDeclSkin );
47 void idDeclSkin::FreeData( void ) {
56 bool idDeclSkin::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( "{" );
64 associatedModels.Clear();
67 if ( !src.ReadToken( &token ) ) {
71 if ( !token.Icmp( "}" ) ) {
74 if ( !src.ReadToken( &token2 ) ) {
75 src.Warning( "Unexpected end of file" );
80 if ( !token.Icmp( "model" ) ) {
81 associatedModels.Append( token2 );
87 if ( !token.Icmp( "*" ) ) {
91 map.from = declManager->FindMaterial( token );
94 map.to = declManager->FindMaterial( token2 );
96 mappings.Append( map );
104 idDeclSkin::SetDefaultText
107 bool idDeclSkin::SetDefaultText( void ) {
108 // if there exists a material with the same name
109 if ( declManager->FindType( DECL_MATERIAL, GetName(), false ) ) {
110 char generated[2048];
112 idStr::snPrintf( generated, sizeof( generated ),
113 "skin %s // IMPLICITLY GENERATED\n"
116 "}\n", GetName(), GetName() );
117 SetText( generated );
126 idDeclSkin::DefaultDefinition
129 const char *idDeclSkin::DefaultDefinition( void ) const {
132 "\t" "\"*\"\t\"_default\"\n"
138 idDeclSkin::GetNumModelAssociations
141 const int idDeclSkin::GetNumModelAssociations(void ) const {
142 return associatedModels.Num();
147 idDeclSkin::GetAssociatedModel
150 const char *idDeclSkin::GetAssociatedModel( int index ) const {
151 if ( index >= 0 && index < associatedModels.Num() ) {
152 return associatedModels[ index ];
162 const idMaterial *idDeclSkin::RemapShaderBySkin( const idMaterial *shader ) const {
169 // never remap surfaces that were originally nodraw, like collision hulls
170 if ( !shader->IsDrawn() ) {
174 for ( i = 0; i < mappings.Num() ; i++ ) {
175 const skinMapping_t *map = &mappings[i];
177 // NULL = wildcard match
178 if ( !map->from || map->from == shader ) {
183 // didn't find a match or wildcard, so stay the same