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 ===========================================================================
28 #include "../../idlib/precompiled.h"
31 #include "MaterialDef.h"
37 MaterialDef::MaterialDef(void) {
45 MaterialDef::~MaterialDef(void) {
49 * Returns view specific data associated with the material definition.
51 DWORD MaterialDef::GetViewData(const char* viewName) {
53 viewData.Get(viewName, &value);
58 * Sets view specific data for the material definition.
60 void MaterialDef::SetViewData(const char* viewName, DWORD value) {
61 viewData.Set(viewName, value);
64 #define MATERIAL_DEF_FILE "MaterialEditorDefs.med"
66 MaterialDefList MaterialDefManager::materialDefs[MaterialDefManager::MATERIAL_DEF_NUM];
70 * Loads the material definition file instatiates MaterialDef objects for each definition
71 * and groups the definitions.
73 void MaterialDefManager::InitializeMaterialDefLists() {
76 int length = fileSystem->ReadFile( MATERIAL_DEF_FILE, (void **)&buffer);
79 common->Error( "Couldn't load material editor definition: %s", MATERIAL_DEF_FILE );
84 if ( !src.LoadMemory( buffer, length, MATERIAL_DEF_FILE ) ) {
85 common->Error( "Couldn't parse %s", MATERIAL_DEF_FILE );
86 fileSystem->FreeFile(buffer);
90 InitializeMaterialDefList(&src, "materialprops", &materialDefs[MATERIAL_DEF_MATERIAL]);
91 InitializeMaterialDefList(&src, "stageprops", &materialDefs[MATERIAL_DEF_STAGE]);
92 InitializeMaterialDefList(&src, "specialmapstageprops", &materialDefs[MATERIAL_DEF_SPECIAL_STAGE]);
94 fileSystem->FreeFile(buffer);
98 * Loads a single type of material attributes and adds them to the supplied MaterialDefList object.
99 * @param src The idLexer object that contains the file.
100 * @param typeName The name of the attribute grouping to search for in the file.
101 * @param list The MaterialDefList object to append the MaterialDef instances to.
103 void MaterialDefManager::InitializeMaterialDefList(idLexer* src, const char* typeName, MaterialDefList* list) {
108 src->SkipUntilString(typeName);
109 src->SkipUntilString("{");
112 if ( !src->ExpectAnyToken( &token ) ) {
113 //Todo: Add some error checking here
117 if ( token == "}" ) {
121 MaterialDef* newProp = new MaterialDef();
123 if(!token.Icmp("TYPE_GROUP")) {
124 newProp->type = MaterialDef::MATERIAL_DEF_TYPE_GROUP;
125 } else if(!token.Icmp("TYPE_BOOL")) {
126 newProp->type = MaterialDef::MATERIAL_DEF_TYPE_BOOL;
127 } else if(!token.Icmp("TYPE_STRING")) {
128 newProp->type = MaterialDef::MATERIAL_DEF_TYPE_STRING;
129 } else if(!token.Icmp("TYPE_FLOAT")) {
130 newProp->type = MaterialDef::MATERIAL_DEF_TYPE_FLOAT;
131 } else if(!token.Icmp("TYPE_INT")) {
132 newProp->type = MaterialDef::MATERIAL_DEF_TYPE_INT;
136 src->ReadToken(&token);
139 src->ReadToken(&token);
140 newProp->dictName = token;
143 src->ReadToken(&token);
146 src->ReadToken(&token);
147 newProp->displayName = token;
150 src->ReadToken(&token);
153 src->ReadToken(&token);
154 newProp->displayInfo = token;
157 if(newProp->type == MaterialDef::MATERIAL_DEF_TYPE_STRING) {
159 newProp->quotes = false;
162 src->ReadToken(&token);
165 src->ReadToken(&token);
167 newProp->quotes = true;
171 src->SkipRestOfLine();
173 list->Append(newProp);
178 * Destroys all MaterialDef instances and clears the material attribute grouping lists.
180 void MaterialDefManager::DestroyMaterialDefLists() {
182 for(int i = 0; i < MATERIAL_DEF_NUM; i++) {
183 for(int j = 0; j < materialDefs[i].Num(); j++) {
184 delete materialDefs[i][j];
186 materialDefs[i].Clear();
191 * Returns the MaterialDefList for the specified attribute grouping.
192 * @param type The attribute grouping for which to retreive the attribute list.
194 MaterialDefList* MaterialDefManager::GetMaterialDefs(int type) {
195 if(type >= 0 && type < MATERIAL_DEF_NUM) {
196 return &materialDefs[type];