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 using ListItem = std::pair<CopiedString, CopiedString>;
42 using ListItems = std::vector<ListItem>;
46 typedef ListItems::const_iterator const_iterator;
47 const_iterator begin() const {
48 return m_items.begin();
50 const_iterator end() const {
54 const ListItem& operator[]( std::size_t i ) const {
57 const_iterator findValue( const char* value ) const {
58 for ( ListItems::const_iterator i = m_items.begin(); i != m_items.end(); ++i )
60 if ( string_equal( value, ( *i ).second.c_str() ) ) {
67 void push_back( const char* name, const char* value ){
68 m_items.push_back( ListItems::value_type( name, value ) );
72 class EntityClassAttribute
78 CopiedString m_description;
79 EntityClassAttribute(){
81 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 ){
85 typedef std::pair<CopiedString, EntityClassAttribute> EntityClassAttributePair;
86 typedef std::list<EntityClassAttributePair> EntityClassAttributes;
87 typedef std::list<CopiedString> StringList;
89 inline const char* EntityClassAttributePair_getName( const EntityClassAttributePair& attributePair ){
90 if ( !string_empty( attributePair.second.m_name.c_str() ) ) {
91 return attributePair.second.m_name.c_str();
93 return attributePair.first.c_str();
96 inline const char* EntityClassAttributePair_getDescription( const EntityClassAttributePair& attributePair ){
97 if ( !string_empty( attributePair.second.m_description.c_str() ) ) {
98 return attributePair.second.m_description.c_str();
100 return EntityClassAttributePair_getName( attributePair );
109 bool unknown; // wasn't found in source
114 Shader* m_state_fill;
115 Shader* m_state_wire;
116 Shader* m_state_blend;
118 CopiedString m_comments;
119 char flagnames[MAX_FLAGS][32];
121 CopiedString m_modelpath;
124 void ( *free )( EntityClass* );
126 EntityClassAttributes m_attributes;
128 bool inheritanceResolved;
132 const char* name() const {
133 return m_name.c_str();
135 const char* comments() const {
136 return m_comments.c_str();
138 const char* modelpath() const {
139 return m_modelpath.c_str();
141 const char* skin() const {
142 return m_skin.c_str();
146 inline const char* EntityClass_valueForKey( const EntityClass& entityClass, const char* key ){
147 for ( EntityClassAttributes::const_iterator i = entityClass.m_attributes.begin(); i != entityClass.m_attributes.end(); ++i )
149 if ( string_equal( key, ( *i ).first.c_str() ) ) {
150 return ( *i ).second.m_value.c_str();
156 inline EntityClassAttributePair& EntityClass_insertAttribute( EntityClass& entityClass, const char* key, const EntityClassAttribute& attribute = EntityClassAttribute() ){
157 entityClass.m_attributes.push_back( EntityClassAttributePair( key, attribute ) );
158 return entityClass.m_attributes.back();
162 inline void buffer_write_colour_fill( char buffer[128], const Colour3& colour ){
163 sprintf( buffer, "(%g %g %g)", colour[0], colour[1], colour[2] );
166 inline void buffer_write_colour_wire( char buffer[128], const Colour3& colour ){
167 sprintf( buffer, "<%g %g %g>", colour[0], colour[1], colour[2] );
170 inline void buffer_write_colour_blend( char buffer[128], const Colour3& colour ){
171 sprintf( buffer, "[%g %g %g]", colour[0], colour[1], colour[2] );
174 inline Shader* colour_capture_state_fill( const Colour3& colour ){
176 buffer_write_colour_fill( buffer, colour );
177 return GlobalShaderCache().capture( buffer );
180 inline void colour_release_state_fill( const Colour3& colour ){
182 buffer_write_colour_fill( buffer, colour );
183 GlobalShaderCache().release( buffer );
186 inline Shader* colour_capture_state_wire( const Colour3& colour ){
188 buffer_write_colour_wire( buffer, colour );
189 return GlobalShaderCache().capture( buffer );
192 inline void colour_release_state_wire( const Colour3& colour ){
194 buffer_write_colour_wire( buffer, colour );
195 GlobalShaderCache().release( buffer );
198 inline Shader* colour_capture_state_blend( const Colour3& colour ){
200 buffer_write_colour_blend( buffer, colour );
201 return GlobalShaderCache().capture( buffer );
204 inline void colour_release_state_blend( const Colour3& colour ){
206 buffer_write_colour_blend( buffer, colour );
207 GlobalShaderCache().release( buffer );
210 inline void eclass_capture_state( EntityClass* eclass ){
211 eclass->m_state_fill = colour_capture_state_fill( eclass->color );
212 eclass->m_state_wire = colour_capture_state_wire( eclass->color );
213 eclass->m_state_blend = colour_capture_state_blend( eclass->color );
216 inline void eclass_release_state( EntityClass* eclass ){
217 colour_release_state_fill( eclass->color );
218 colour_release_state_wire( eclass->color );
219 colour_release_state_blend( eclass->color );
222 // eclass constructor
223 inline EntityClass* Eclass_Alloc(){
224 EntityClass* e = new EntityClass;
226 e->fixedsize = false;
228 memset( e->flagnames, 0, MAX_FLAGS * 32 );
230 e->maxs = Vector3( -1,-1,-1 );
231 e->mins = Vector3( 1, 1, 1 );
235 e->inheritanceResolved = true;
236 e->sizeSpecified = false;
237 e->colorSpecified = false;
243 inline void Eclass_Free( EntityClass* e ){
244 eclass_release_state( e );
249 inline bool classname_equal( const char* classname, const char* other ){
250 return string_equal( classname, other );
253 inline EntityClass* EClass_Create( const char* name, const Vector3& colour, const char* comments ){
254 EntityClass *e = Eclass_Alloc();
255 e->free = &Eclass_Free;
260 eclass_capture_state( e );
263 e->m_comments = comments;
269 inline EntityClass* EClass_Create_FixedSize( const char* name, const Vector3& colour, const Vector3& mins, const Vector3& maxs, const char* comments ){
270 EntityClass *e = Eclass_Alloc();
271 e->free = &Eclass_Free;
276 eclass_capture_state( e );
284 e->m_comments = comments;
290 const Vector3 smallbox[2] = {
295 inline EntityClass *EntityClass_Create_Default( const char *name, bool has_brushes ){
296 // create a new class for it
298 return EClass_Create( name, Vector3( 0.0f, 0.5f, 0.0f ), "Not found in source." );
302 return EClass_Create_FixedSize( name, Vector3( 0.0f, 0.5f, 0.0f ), smallbox[0], smallbox[1], "Not found in source." );