2 Copyright (C) 1999-2006 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
22 #if !defined (INCLUDED_ECLASSLIB_H)
23 #define INCLUDED_ECLASSLIB_H
34 #include "math/vector.h"
35 #include "string/string.h"
37 typedef Vector3 Colour3;
39 class ListAttributeType
41 typedef std::pair<CopiedString, CopiedString> ListItem;
42 typedef std::vector<ListItem> ListItems;
46 typedef ListItems::const_iterator const_iterator;
47 const_iterator begin() const
49 return m_items.begin();
51 const_iterator end() const
56 const ListItem& operator[](std::size_t i) const
60 const_iterator findValue(const char* value) const
62 for(ListItems::const_iterator i = m_items.begin(); i != m_items.end(); ++i)
64 if(string_equal(value, (*i).second.c_str()))
72 void push_back(const char* name, const char* value)
74 m_items.push_back(ListItems::value_type(name, value));
78 class EntityClassAttribute
84 CopiedString m_description;
85 EntityClassAttribute()
88 EntityClassAttribute(const char* type, const char* name, const char* value = "", const char* description = "") : m_type(type), m_name(name), m_value(value), m_description(description)
93 typedef std::pair<CopiedString, EntityClassAttribute> EntityClassAttributePair;
94 typedef std::list<EntityClassAttributePair> EntityClassAttributes;
95 typedef std::list<CopiedString> StringList;
97 inline const char* EntityClassAttributePair_getName(const EntityClassAttributePair& attributePair)
99 if(!string_empty(attributePair.second.m_name.c_str()))
101 return attributePair.second.m_name.c_str();
103 return attributePair.first.c_str();
106 inline const char* EntityClassAttributePair_getDescription(const EntityClassAttributePair& attributePair)
108 if(!string_empty(attributePair.second.m_description.c_str()))
110 return attributePair.second.m_description.c_str();
112 return EntityClassAttributePair_getName(attributePair);
121 bool unknown; // wasn't found in source
126 Shader* m_state_fill;
127 Shader* m_state_wire;
128 Shader* m_state_blend;
130 CopiedString m_comments;
131 char flagnames[MAX_FLAGS][32];
133 CopiedString m_modelpath;
136 void (*free)(EntityClass*);
138 EntityClassAttributes m_attributes;
140 bool inheritanceResolved;
144 const char* name() const
146 return m_name.c_str();
148 const char* comments() const
150 return m_comments.c_str();
152 const char* modelpath() const
154 return m_modelpath.c_str();
156 const char* skin() const
158 return m_skin.c_str();
162 inline const char* EntityClass_valueForKey(const EntityClass& entityClass, const char* key)
164 for(EntityClassAttributes::const_iterator i = entityClass.m_attributes.begin(); i != entityClass.m_attributes.end(); ++i)
166 if(string_equal(key, (*i).first.c_str()))
168 return (*i).second.m_value.c_str();
174 inline EntityClassAttributePair& EntityClass_insertAttribute(EntityClass& entityClass, const char* key, const EntityClassAttribute& attribute = EntityClassAttribute())
176 entityClass.m_attributes.push_back(EntityClassAttributePair(key, attribute));
177 return entityClass.m_attributes.back();
181 inline void buffer_write_colour_fill(char buffer[128], const Colour3& colour)
183 sprintf(buffer, "(%g %g %g)", colour[0], colour[1], colour[2]);
186 inline void buffer_write_colour_wire(char buffer[128], const Colour3& colour)
188 sprintf(buffer, "<%g %g %g>", colour[0], colour[1], colour[2]);
191 inline void buffer_write_colour_blend(char buffer[128], const Colour3& colour)
193 sprintf(buffer, "[%g %g %g]", colour[0], colour[1], colour[2]);
196 inline Shader* colour_capture_state_fill(const Colour3& colour)
199 buffer_write_colour_fill(buffer, colour);
200 return GlobalShaderCache().capture(buffer);
203 inline void colour_release_state_fill(const Colour3& colour)
206 buffer_write_colour_fill(buffer, colour);
207 GlobalShaderCache().release(buffer);
210 inline Shader* colour_capture_state_wire(const Colour3& colour)
213 buffer_write_colour_wire(buffer, colour);
214 return GlobalShaderCache().capture(buffer);
217 inline void colour_release_state_wire(const Colour3& colour)
220 buffer_write_colour_wire(buffer, colour);
221 GlobalShaderCache().release(buffer);
224 inline Shader* colour_capture_state_blend(const Colour3& colour)
227 buffer_write_colour_blend(buffer, colour);
228 return GlobalShaderCache().capture(buffer);
231 inline void colour_release_state_blend(const Colour3& colour)
234 buffer_write_colour_blend(buffer, colour);
235 GlobalShaderCache().release(buffer);
238 inline void eclass_capture_state(EntityClass* eclass)
240 eclass->m_state_fill = colour_capture_state_fill(eclass->color);
241 eclass->m_state_wire = colour_capture_state_wire(eclass->color);
242 eclass->m_state_blend = colour_capture_state_blend(eclass->color);
245 inline void eclass_release_state(EntityClass* eclass)
247 colour_release_state_fill(eclass->color);
248 colour_release_state_wire(eclass->color);
249 colour_release_state_blend(eclass->color);
252 // eclass constructor
253 inline EntityClass* Eclass_Alloc()
255 EntityClass* e = new EntityClass;
257 e->fixedsize = false;
259 memset(e->flagnames, 0, MAX_FLAGS*32);
261 e->maxs = Vector3(-1,-1,-1);
262 e->mins = Vector3(1, 1, 1);
266 e->inheritanceResolved = true;
267 e->sizeSpecified = false;
268 e->colorSpecified = false;
274 inline void Eclass_Free(EntityClass* e)
276 eclass_release_state(e);
281 inline bool classname_equal(const char* classname, const char* other)
283 return string_equal(classname, other);
286 inline EntityClass* EClass_Create(const char* name, const Vector3& colour, const char* comments)
288 EntityClass *e = Eclass_Alloc();
289 e->free = &Eclass_Free;
294 eclass_capture_state(e);
297 e->m_comments = comments;
302 inline EntityClass* EClass_Create_FixedSize(const char* name, const Vector3& colour, const Vector3& mins, const Vector3& maxs, const char* comments)
304 EntityClass *e = Eclass_Alloc();
305 e->free = &Eclass_Free;
310 eclass_capture_state(e);
318 e->m_comments = comments;
323 const Vector3 smallbox[2] = {
328 inline EntityClass *EntityClass_Create_Default(const char *name, bool has_brushes)
330 // create a new class for it
333 return EClass_Create(name, Vector3(0.0f, 0.5f, 0.0f), "Not found in source.");
337 return EClass_Create_FixedSize(name, Vector3(0.0f, 0.5f, 0.0f), smallbox[0], smallbox[1], "Not found in source.");