doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaterialDef.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 #include "../../idlib/precompiled.h"
29 #pragma hdrstop
30 
31 #include "MaterialDef.h"
32 
33 
38  type = 0;
39  quotes = false;
40 }
41 
46 }
47 
51 DWORD MaterialDef::GetViewData(const char* viewName) {
52  DWORD* value = NULL;
53  viewData.Get(viewName, &value);
54  return *value;
55 }
56 
60 void MaterialDef::SetViewData(const char* viewName, DWORD value) {
61  viewData.Set(viewName, value);
62 }
63 
64 #define MATERIAL_DEF_FILE "MaterialEditorDefs.med"
65 
67 
68 
74 
75  char *buffer;
76  int length = fileSystem->ReadFile( MATERIAL_DEF_FILE, (void **)&buffer);
77 
78  if ( length == -1 ) {
79  common->Error( "Couldn't load material editor definition: %s", MATERIAL_DEF_FILE );
80  return;
81  }
82 
83  idLexer src;
84  if ( !src.LoadMemory( buffer, length, MATERIAL_DEF_FILE ) ) {
85  common->Error( "Couldn't parse %s", MATERIAL_DEF_FILE );
86  fileSystem->FreeFile(buffer);
87  }
88 
89 
92  InitializeMaterialDefList(&src, "specialmapstageprops", &materialDefs[MATERIAL_DEF_SPECIAL_STAGE]);
93 
94  fileSystem->FreeFile(buffer);
95 }
96 
104 
105  idToken token;
106 
107  src->Reset();
108  src->SkipUntilString(typeName);
109  src->SkipUntilString("{");
110 
111  while(1) {
112  if ( !src->ExpectAnyToken( &token ) ) {
113  //Todo: Add some error checking here
114  return;
115  }
116 
117  if ( token == "}" ) {
118  break;
119  }
120 
121  MaterialDef* newProp = new MaterialDef();
122 
123  if(!token.Icmp("TYPE_GROUP")) {
125  } else if(!token.Icmp("TYPE_BOOL")) {
127  } else if(!token.Icmp("TYPE_STRING")) {
129  } else if(!token.Icmp("TYPE_FLOAT")) {
131  } else if(!token.Icmp("TYPE_INT")) {
133  }
134 
135  //Skip the ,
136  src->ReadToken(&token);
137 
138  //Read Dict Name
139  src->ReadToken(&token);
140  newProp->dictName = token;
141 
142  //Skip the ,
143  src->ReadToken(&token);
144 
145  //Read Display Name
146  src->ReadToken(&token);
147  newProp->displayName = token;
148 
149  //Skip the ,
150  src->ReadToken(&token);
151 
152  //Read Display Info
153  src->ReadToken(&token);
154  newProp->displayInfo = token;
155 
156  //Type Specific Data
158 
159  newProp->quotes = false;
160 
161  //Skip the ,
162  src->ReadToken(&token);
163 
164  //Read validate flag
165  src->ReadToken(&token);
166  if(token == "1") {
167  newProp->quotes = true;
168  }
169  }
170 
171  src->SkipRestOfLine();
172 
173  list->Append(newProp);
174  }
175 }
176 
181 
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];
185  }
186  materialDefs[i].Clear();
187  }
188 }
189 
195  if(type >= 0 && type < MATERIAL_DEF_NUM) {
196  return &materialDefs[type];
197  }
198  return NULL;
199 }
static void InitializeMaterialDefList(idLexer *src, const char *typeName, MaterialDefList *list)
Loads a single type of material attributes and adds them to the supplied MaterialDefList object...
GLsizei const GLfloat * value
Definition: glext.h:3614
void Reset(void)
Definition: Lexer.cpp:1550
MaterialDef(void)
Constructor.
Definition: MaterialDef.cpp:37
DWORD GetViewData(const char *viewName)
Returns view specific data associated with the material definition.
Definition: MaterialDef.cpp:51
idStr dictName
Definition: MaterialDef.h:51
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
#define MATERIAL_DEF_FILE
Definition: MaterialDef.cpp:64
DWORD
Definition: win_qgl.cpp:61
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
Definition: Token.h:71
idHashTable< DWORD > viewData
Definition: MaterialDef.h:55
GLuint src
Definition: glext.h:5390
int i
Definition: process.py:33
virtual void FreeFile(void *buffer)=0
int Icmp(const char *text) const
Definition: Str.h:667
static void DestroyMaterialDefLists()
Destroys all MaterialDef instances and clears the material attribute grouping lists.
int ExpectAnyToken(idToken *token)
Definition: Lexer.cpp:992
Represents a single attribute in a material.
Definition: MaterialDef.h:36
void Set(const char *key, Type &value)
Definition: HashTable.h:186
Definition: Lexer.h:137
idCommon * common
Definition: Common.cpp:206
#define NULL
Definition: Lib.h:88
GLuint buffer
Definition: glext.h:3108
int LoadMemory(const char *ptr, int length, const char *name, int startLine=1)
Definition: Lexer.cpp:1646
bool Get(const char *key, Type **value=NULL) const
Definition: HashTable.h:214
int Append(const type &obj)
Definition: List.h:646
void SetViewData(const char *viewName, DWORD value)
Sets view specific data for the material definition.
Definition: MaterialDef.cpp:60
static MaterialDefList materialDefs[MATERIAL_DEF_NUM]
Definition: MaterialDef.h:101
int Num(void) const
Definition: List.h:265
idStr displayName
Definition: MaterialDef.h:52
GLsizei const GLcharARB const GLint * length
Definition: glext.h:3599
static void InitializeMaterialDefLists()
Loads the material definition file instatiates MaterialDef objects for each definition and groups the...
Definition: MaterialDef.cpp:73
int SkipUntilString(const char *string)
Definition: Lexer.cpp:1097
GLint j
Definition: qgl.h:264
static MaterialDefList * GetMaterialDefs(int type)
Returns the MaterialDefList for the specified attribute grouping.
virtual ~MaterialDef(void)
Destructor.
Definition: MaterialDef.cpp:45
virtual void Error(const char *fmt,...) id_attribute((format(printf
Definition: List.h:84
int SkipRestOfLine(void)
Definition: Lexer.cpp:1113
int ReadToken(idToken *token)
Definition: Lexer.cpp:820
idStr displayInfo
Definition: MaterialDef.h:53
void Clear(void)
Definition: List.h:184