add and use Entity::getClassName(), Entity::hasKeyValue()

do not return default value from getKeyValue()
This commit is contained in:
Garux 2021-05-16 10:13:42 +03:00
parent ed04f90497
commit da98f5f9d9
18 changed files with 73 additions and 78 deletions

View File

@ -212,7 +212,7 @@ public:
: pFile( pFile ), exclusionList( exclusionList ){ : pFile( pFile ), exclusionList( exclusionList ){
} }
void operator()( scene::Instance& instance ) const { void operator()( scene::Instance& instance ) const {
const char* classname = Node_getEntity( instance.path().top() )->getKeyValue( "classname" ); const char* classname = Node_getEntity( instance.path().top() )->getClassName();
if ( !strcmp( classname, "worldspawn" ) ) { if ( !strcmp( classname, "worldspawn" ) ) {
world.LoadFromEntity( instance.path().top(), false ); world.LoadFromEntity( instance.path().top(), false );

View File

@ -95,7 +95,7 @@ public:
if ( m_entity == 0 ) { if ( m_entity == 0 ) {
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 if ( entity != 0
&& string_equal( m_name, entity->getKeyValue( "classname" ) ) ) { && string_equal( m_name, entity->getClassName() ) ) {
m_entity = entity; m_entity = entity;
} }
} }

View File

@ -65,7 +65,7 @@ public:
int spawnflagsInt; int spawnflagsInt;
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 ) { if ( entity != 0 ) {
if ( string_equal( m_name, entity->getKeyValue( "classname" ) ) ) { if ( string_equal( m_name, entity->getClassName() ) ) {
const char *spawnflags = entity->getKeyValue( "spawnflags" ); const char *spawnflags = entity->getKeyValue( "spawnflags" );
globalOutputStream() << "spawnflags for " << m_name << ": " << spawnflags << ".\n"; globalOutputStream() << "spawnflags for " << m_name << ": " << spawnflags << ".\n";

View File

@ -43,7 +43,7 @@ public:
bool pre( const scene::Path& path, scene::Instance& instance ) const { bool pre( const scene::Path& path, scene::Instance& instance ) const {
if ( m_entity == 0 ) { if ( m_entity == 0 ) {
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 && string_equal( m_name, entity->getKeyValue( "classname" ) ) ) { if ( entity != 0 && string_equal( m_name, entity->getClassName() ) ) {
m_entity = entity; m_entity = entity;
} }
} }
@ -73,13 +73,9 @@ public:
EntityFindFlags( const char *classname, const char *flag, int *count ) : m_classname( classname ), m_flag( flag ), m_count( count ){ EntityFindFlags( const char *classname, const char *flag, int *count ) : m_classname( classname ), m_flag( flag ), m_count( count ){
} }
bool pre( const scene::Path& path, scene::Instance& instance ) const { bool pre( const scene::Path& path, scene::Instance& instance ) const {
const char *str;
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 && string_equal( m_classname, entity->getKeyValue( "classname" ) ) ) { if ( entity != 0 && string_equal( m_classname, entity->getClassName() ) && !entity->hasKeyValue( m_flag ) ) {
str = entity->getKeyValue( m_flag ); ( *m_count )++;
if ( string_empty( str ) ) {
( *m_count )++;
}
} }
return true; return true;
} }
@ -99,15 +95,14 @@ public:
EntityFindTeams( const char *classname, int *count, int *team ) : m_classname( classname ), m_count( count ), m_team( team ){ EntityFindTeams( const char *classname, int *count, int *team ) : m_classname( classname ), m_count( count ), m_team( team ){
} }
bool pre( const scene::Path& path, scene::Instance& instance ) const { bool pre( const scene::Path& path, scene::Instance& instance ) const {
const char *str;
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 && string_equal( m_classname, entity->getKeyValue( "classname" ) ) ) { if ( entity != 0 && string_equal( m_classname, entity->getClassName() ) ) {
if ( m_count ) { if ( m_count ) {
( *m_count )++; ( *m_count )++;
} }
// now get the highest teamnum // now get the highest teamnum
if ( m_team ) { if ( m_team ) {
str = entity->getKeyValue( "team" ); const char *str = entity->getKeyValue( "team" );
if ( !string_empty( str ) ) { if ( !string_empty( str ) ) {
if ( atoi( str ) > *m_team ) { if ( atoi( str ) > *m_team ) {
( *m_team ) = atoi( str ); ( *m_team ) = atoi( str );
@ -147,18 +142,18 @@ void assign_default_values_to_worldspawn( bool override, const char **returnMsg
*message = '\0'; *message = '\0';
*str = '\0'; *str = '\0';
if ( override || string_empty( worldspawn->getKeyValue( "maxlevel" ) ) ) { if ( override || !worldspawn->hasKeyValue( "maxlevel" ) ) {
// TODO: Get highest brush - a level has 64 units // TODO: Get highest brush - a level has 64 units
worldspawn->setKeyValue( "maxlevel", "5" ); worldspawn->setKeyValue( "maxlevel", "5" );
snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Set maxlevel to: %s", worldspawn->getKeyValue( "maxlevel" ) ); snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Set maxlevel to: %s", "5" );
} }
if ( override || string_empty( worldspawn->getKeyValue( "maxteams" ) ) ) { if ( override || !worldspawn->hasKeyValue( "maxteams" ) ) {
get_team_count( "info_player_start", &count, &teams ); get_team_count( "info_player_start", &count, &teams );
if ( teams ) { if ( teams ) {
snprintf( str, sizeof( str ) - 1, "%i", teams ); snprintf( str, sizeof( str ) - 1, "%i", teams );
worldspawn->setKeyValue( "maxteams", str ); worldspawn->setKeyValue( "maxteams", str );
snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Set maxteams to: %s", worldspawn->getKeyValue( "maxteams" ) ); snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Set maxteams to: %s", str );
} }
if ( count < 16 ) { if ( count < 16 ) {
snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "You should at least place 16 info_player_start" ); snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "You should at least place 16 info_player_start" );
@ -236,7 +231,7 @@ void check_map_values( const char **returnMsg ){
} }
// check maxlevel // check maxlevel
if ( string_empty( worldspawn->getKeyValue( "maxlevel" ) ) ) { if ( !worldspawn->hasKeyValue( "maxlevel" ) ) {
strncat( message, "Worldspawn: No maxlevel defined\n", sizeof( message ) - 1 ); strncat( message, "Worldspawn: No maxlevel defined\n", sizeof( message ) - 1 );
} }
else if ( atoi( worldspawn->getKeyValue( "maxlevel" ) ) > 8 ) { else if ( atoi( worldspawn->getKeyValue( "maxlevel" ) ) > 8 ) {

View File

@ -60,9 +60,11 @@ public:
}; };
virtual const EntityClass& getEntityClass() const = 0; virtual const EntityClass& getEntityClass() const = 0;
virtual const char* getClassName() const = 0;
virtual void forEachKeyValue( Visitor& visitor ) const = 0; virtual void forEachKeyValue( Visitor& visitor ) const = 0;
virtual void setKeyValue( const char* key, const char* value ) = 0; virtual void setKeyValue( const char* key, const char* value ) = 0;
virtual const char* getKeyValue( const char* key ) const = 0; virtual const char* getKeyValue( const char* key ) const = 0;
virtual bool hasKeyValue( const char* key ) const = 0;
virtual bool isContainer() const = 0; virtual bool isContainer() const = 0;
virtual void attach( Observer& observer ) = 0; virtual void attach( Observer& observer ) = 0;
virtual void detach( Observer& observer ) = 0; virtual void detach( Observer& observer ) = 0;

View File

@ -543,7 +543,7 @@ public:
} }
typedef MemberCaller1<EntityKeyValues, const KeyValues&, &EntityKeyValues::importState> UndoImportCaller; typedef MemberCaller1<EntityKeyValues, const KeyValues&, &EntityKeyValues::importState> UndoImportCaller;
void attach( Observer& observer ){ void attach( Observer& observer ) override {
ASSERT_MESSAGE( !m_observerMutex, "observer cannot be attached during iteration" ); ASSERT_MESSAGE( !m_observerMutex, "observer cannot be attached during iteration" );
m_observers.insert( &observer ); m_observers.insert( &observer );
for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i ) for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
@ -551,7 +551,7 @@ public:
observer.insert( ( *i ).first.c_str(), *( *i ).second ); observer.insert( ( *i ).first.c_str(), *( *i ).second );
} }
} }
void detach( Observer& observer ){ void detach( Observer& observer ) override {
ASSERT_MESSAGE( !m_observerMutex, "observer cannot be detached during iteration" ); ASSERT_MESSAGE( !m_observerMutex, "observer cannot be detached during iteration" );
m_observers.erase( &observer ); m_observers.erase( &observer );
for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i ) for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
@ -593,17 +593,20 @@ public:
} }
// entity // entity
EntityClass& getEntityClass() const { EntityClass& getEntityClass() const override {
return *m_eclass; return *m_eclass;
} }
void forEachKeyValue( Visitor& visitor ) const { const char* getClassName() const override {
return m_eclass->name();
}
void forEachKeyValue( Visitor& visitor ) const override {
for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i ) for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
{ {
visitor.visit( ( *i ).first.c_str(), ( *i ).second->c_str() ); visitor.visit( ( *i ).first.c_str(), ( *i ).second->c_str() );
} }
} }
void setKeyValue( const char* key, const char* value ){ void setKeyValue( const char* key, const char* value ) override {
if ( value[0] == '\0' if ( string_empty( value )
/*|| string_equal(EntityClass_valueForKey(*m_eclass, key), value)*/ ) { // don't delete values equal to default /*|| string_equal(EntityClass_valueForKey(*m_eclass, key), value)*/ ) { // don't delete values equal to default
erase( key ); erase( key );
} }
@ -613,16 +616,20 @@ public:
} }
m_entityKeyValueChanged(); m_entityKeyValueChanged();
} }
const char* getKeyValue( const char* key ) const { const char* getKeyValue( const char* key ) const override {
KeyValues::const_iterator i = m_keyValues.find( key ); KeyValues::const_iterator i = m_keyValues.find( key );
if ( i != m_keyValues.end() ) { if ( i != m_keyValues.end() ) {
return ( *i ).second->c_str(); return ( *i ).second->c_str();
} }
return EntityClass_valueForKey( *m_eclass, key ); // return EntityClass_valueForKey( *m_eclass, key );
return "";
}
bool hasKeyValue( const char* key ) const override {
return m_keyValues.find( key ) != m_keyValues.end();
} }
bool isContainer() const { bool isContainer() const override {
return m_isContainer; return m_isContainer;
} }
}; };

View File

@ -204,8 +204,7 @@ public:
if ( i != 0 ) { if ( i != 0 ) {
key << i; key << i;
} }
const char* value = e1->getKeyValue( key.c_str() ); if ( !e1->hasKeyValue( key.c_str() ) ) {
if ( string_empty( value ) ) {
e1->setKeyValue( key.c_str(), e2->getKeyValue( "name" ) ); e1->setKeyValue( key.c_str(), e2->getKeyValue( "name" ) );
break; break;
} }
@ -224,7 +223,7 @@ public:
} }
else else
{ {
const char* type = e2->getKeyValue( "classname" ); const char* type = e2->getClassName();
if ( string_empty( type ) ) { if ( string_empty( type ) ) {
type = "t"; type = "t";
} }
@ -247,7 +246,7 @@ public:
connector.connect( value ); connector.connect( value );
} }
else{ else{
const char* type = e2->getKeyValue( "classname" ); const char* type = e2->getClassName();
if ( string_empty( type ) ) { if ( string_empty( type ) ) {
type = "t"; type = "t";
} }
@ -329,7 +328,7 @@ public:
filter_entity_classname( const char* classname ) : m_classname( classname ){ filter_entity_classname( const char* classname ) : m_classname( classname ){
} }
bool filter( const Entity& entity ) const { bool filter( const Entity& entity ) const {
return string_equal( entity.getKeyValue( "classname" ), m_classname ); return string_equal( entity.getClassName(), m_classname );
} }
}; };
@ -341,7 +340,7 @@ public:
filter_entity_classgroup( const char* classgroup ) : m_classgroup( classgroup ), m_length( string_length( m_classgroup ) ){ filter_entity_classgroup( const char* classgroup ) : m_classgroup( classgroup ), m_length( string_length( m_classgroup ) ){
} }
bool filter( const Entity& entity ) const { bool filter( const Entity& entity ) const {
return string_equal_n( entity.getKeyValue( "classname" ), m_classgroup, m_length ); return string_equal_n( entity.getClassName(), m_classgroup, m_length );
} }
}; };
@ -364,7 +363,7 @@ class filter_entity_doom3model : public EntityFilter
{ {
public: public:
bool filter( const Entity& entity ) const { bool filter( const Entity& entity ) const {
return string_equal( entity.getKeyValue( "classname" ), "func_static" ) return string_equal( entity.getClassName(), "func_static" )
&& !string_equal( entity.getKeyValue( "model" ), entity.getKeyValue( "name" ) ); && !string_equal( entity.getKeyValue( "model" ), entity.getKeyValue( "name" ) );
} }
}; };
@ -377,7 +376,7 @@ class filter_entity_not_func_detail : public EntityFilter
public: public:
bool filter( const Entity& entity ) const { bool filter( const Entity& entity ) const {
return entity.isContainer() return entity.isContainer()
&& !string_equal_n( entity.getKeyValue( "classname" ), "func_detail", 11 ); && !string_equal_n( entity.getClassName(), "func_detail", 11 );
} }
}; };
@ -387,7 +386,7 @@ class filter_entity_world : public EntityFilter
{ {
public: public:
bool filter( const Entity& entity ) const { bool filter( const Entity& entity ) const {
const char* value = entity.getKeyValue( "classname" ); const char* value = entity.getClassName();
return string_equal( value, "worldspawn" ) return string_equal( value, "worldspawn" )
|| string_equal( value, "func_group" ) || string_equal( value, "func_group" )
|| string_equal_n( value, "func_detail", 11 ); || string_equal_n( value, "func_detail", 11 );
@ -402,7 +401,7 @@ public:
bool filter( const Entity& entity ) const { bool filter( const Entity& entity ) const {
return !entity.isContainer() return !entity.isContainer()
&& !entity.getEntityClass().miscmodel_is && !entity.getEntityClass().miscmodel_is
&& !string_equal_prefix( entity.getEntityClass().name(), "light" ); && !string_equal_prefix( entity.getClassName(), "light" );
} }
}; };

View File

@ -72,7 +72,7 @@ class Group
RenderableArrow m_arrow; RenderableArrow m_arrow;
bool m_anglesDraw; bool m_anglesDraw;
void updateAnglesDraw(){ void updateAnglesDraw(){
m_anglesDraw = m_entity.getEntityClass().has_angles || !string_empty( m_entity.getKeyValue( "angle" ) ) || !string_empty( m_entity.getKeyValue( "angles" ) ); m_anglesDraw = m_entity.getEntityClass().has_angles || m_entity.hasKeyValue( "angle" ) || m_entity.hasKeyValue( "angles" );
SceneChangeNotify(); SceneChangeNotify();
} }
typedef MemberCaller<Group, &Group::updateAnglesDraw> UpdateAnglesDrawCaller; typedef MemberCaller<Group, &Group::updateAnglesDraw> UpdateAnglesDrawCaller;

View File

@ -689,7 +689,7 @@ void light_draw( const AABB& aabb_light, RenderStateFlags state ){
inline void write_intensity( const float intensity, Entity* entity ){ inline void write_intensity( const float intensity, Entity* entity ){
char value[64]; char value[64];
sprintf( value, "%g", intensity ); sprintf( value, "%g", intensity );
if( !string_empty( entity->getKeyValue( "_light" ) ) ) //primaryIntensity //if set or default is set in .ent if( entity->hasKeyValue( "_light" ) ) //primaryIntensity //if set
entity->setKeyValue( "_light", value ); entity->setKeyValue( "_light", value );
else //secondaryIntensity else //secondaryIntensity
entity->setKeyValue( "light", value ); //otherwise default to "light", which is understood by both q3 and q1 entity->setKeyValue( "light", value ); //otherwise default to "light", which is understood by both q3 and q1
@ -1443,7 +1443,7 @@ public:
if( selected ){ if( selected ){
if ( g_lightType != LIGHTTYPE_DOOM3 ) { if ( g_lightType != LIGHTTYPE_DOOM3 ) {
if ( g_lightRadii && string_empty( m_entity.getKeyValue( "target" ) ) ) { if ( g_lightRadii && !m_entity.hasKeyValue( "target" ) ) {
if ( renderer.getStyle() == Renderer::eFullMaterials ) { if ( renderer.getStyle() == Renderer::eFullMaterials ) {
renderer.SetState( m_colour.state_additive(), Renderer::eFullMaterials ); renderer.SetState( m_colour.state_additive(), Renderer::eFullMaterials );
renderer.Highlight( Renderer::ePrimitive, false ); renderer.Highlight( Renderer::ePrimitive, false );

View File

@ -251,7 +251,7 @@ public:
const EntityClass& eclass = m_entity.getEntityClass(); const EntityClass& eclass = m_entity.getEntityClass();
const char *key = eclass.miscmodel_key(); const char *key = eclass.miscmodel_key();
const char *model = EntityClass_valueForKey( eclass, key ); const char *model = EntityClass_valueForKey( eclass, key );
if( !string_empty( model ) && model == m_entity.getKeyValue( key ) ) // default found = no key set if( !string_empty( model ) && !m_entity.hasKeyValue( key ) )
m_model.modelChanged( model ); m_model.modelChanged( model );
} }
} }

View File

@ -59,12 +59,12 @@ public:
} }
const char* name() const { const char* name() const {
if ( string_empty( m_name.c_str() ) ) { if ( string_empty( m_name.c_str() ) ) {
return m_entity.getEntityClass().name(); return m_entity.getClassName();
} }
return m_name.c_str(); return m_name.c_str();
} }
const char* classname() const { const char* classname() const {
return m_entity.getEntityClass().name(); return m_entity.getClassName();
} }
const Colour3& color() const { const Colour3& color() const {
return m_entity.getEntityClass().color; return m_entity.getEntityClass().color;
@ -78,7 +78,7 @@ public:
void identifierChanged( const char* value ){ void identifierChanged( const char* value ){
if ( string_empty( value ) ) { if ( string_empty( value ) ) {
m_changed.changed( m_entity.getEntityClass().name() ); m_changed.changed( m_entity.getClassName() );
} }
else else
{ {

View File

@ -70,9 +70,9 @@ public:
Entity* entity = Node_getEntity( node ); Entity* entity = Node_getEntity( node );
if ( entity != 0 ) { if ( entity != 0 ) {
if( entity->isContainer() && Node_getTraversable( node )->empty() && !string_equal( entity->getKeyValue( "classname" ), "worldspawn" ) if( entity->isContainer() && Node_getTraversable( node )->empty() && !string_equal( entity->getClassName(), "worldspawn" )
&& string_empty( entity->getKeyValue( "origin" ) ) ){ && !entity->hasKeyValue( "origin" ) ){
globalErrorStream() << "discarding empty group entity: # = " << g_count_entities << "; classname = " << entity->getKeyValue( "classname" ) << "\n"; globalErrorStream() << "discarding empty group entity: # = " << g_count_entities << "; classname = " << entity->getClassName() << "\n";
return false; return false;
} }
m_writer.writeToken( "//" ); m_writer.writeToken( "//" );

View File

@ -159,7 +159,7 @@ public:
} }
void popElement( const char* name ){ void popElement( const char* name ){
ASSERT_MESSAGE( string_equal( name, "entity" ), PARSE_ERROR ); ASSERT_MESSAGE( string_equal( name, "entity" ), PARSE_ERROR );
NodeSmartReference entity( m_entityTable.createEntity( GlobalEntityClassManager().findOrInsert( Node_getEntity( node() )->getKeyValue( "classname" ), node_is_group( node() ) ) ) ); NodeSmartReference entity( m_entityTable.createEntity( GlobalEntityClassManager().findOrInsert( Node_getEntity( node() )->getClassName(), node_is_group( node() ) ) ) );
{ {
EntityCopyingVisitor visitor( *Node_getEntity( entity ) ); EntityCopyingVisitor visitor( *Node_getEntity( entity ) );

View File

@ -311,7 +311,7 @@ void Entity_moveSelectedPrimitives( bool toLast ){
if ( Node_isEntity( node ) && node_is_group( node ) ) { if ( Node_isEntity( node ) && node_is_group( node ) ) {
StringOutputStream command; StringOutputStream command;
command << "movePrimitivesToEntity " << makeQuoted( Node_getEntity( node )->getEntityClass().name() ); command << "movePrimitivesToEntity " << makeQuoted( Node_getEntity( node )->getClassName() );
UndoableCommand undo( command.c_str() ); UndoableCommand undo( command.c_str() );
Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node ); Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node );
} }

View File

@ -1062,7 +1062,7 @@ void EntityClassList_selectEntityClass( EntityClass* eclass ){
{ {
char* text; char* text;
gtk_tree_model_get( model, &iter, 0, &text, -1 ); gtk_tree_model_get( model, &iter, 0, &text, -1 );
if ( strcmp( text, eclass->name() ) == 0 ) { if ( string_equal( text, eclass->name() ) ) {
GtkTreeView* view = g_entityClassList; GtkTreeView* view = g_entityClassList;
GtkTreePath* path = gtk_tree_model_get_path( model, &iter ); GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path ); gtk_tree_selection_select_path( gtk_tree_view_get_selection( view ), path );
@ -1295,7 +1295,7 @@ void EntityInspector_applyKeyValue(){
return; return;
} }
if ( strcmp( key.c_str(), "classname" ) == 0 ) { if ( string_equal( key.c_str(), "classname" ) ) {
Scene_EntitySetClassname_Selected( value.c_str() ); Scene_EntitySetClassname_Selected( value.c_str() );
} }
else else
@ -1309,7 +1309,7 @@ void EntityInspector_clearKeyValue(){
StringOutputStream key( 64 ); StringOutputStream key( 64 );
key << gtk_entry_get_text( g_entityKeyEntry ); key << gtk_entry_get_text( g_entityKeyEntry );
if ( strcmp( key.c_str(), "classname" ) != 0 ) { if ( !string_equal( key.c_str(), "classname" ) ) {
StringOutputStream command; StringOutputStream command;
command << "entityDeleteKey -key " << key.c_str(); command << "entityDeleteKey -key " << key.c_str();
UndoableCommand undo( command.c_str() ); UndoableCommand undo( command.c_str() );

View File

@ -431,7 +431,7 @@ public:
if ( m_entity == 0 ) { if ( m_entity == 0 ) {
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 if ( entity != 0
&& string_equal( m_name, entity->getKeyValue( "classname" ) ) ) { && string_equal( m_name, entity->getClassName() ) ) {
m_entity = entity; m_entity = entity;
} }
} }
@ -489,9 +489,8 @@ void FocusViews( const Vector3& point, float angle ){
void Map_StartPosition(){ void Map_StartPosition(){
Entity* entity = Scene_FindPlayerStart(); Entity* entity = Scene_FindPlayerStart();
if ( entity ) { Vector3 origin;
Vector3 origin; if ( entity != nullptr && string_parse_vector3( entity->getKeyValue( "origin" ), origin ) ) {
string_parse_vector3( entity->getKeyValue( "origin" ), origin );
FocusViews( origin, string_read_float( entity->getKeyValue( "angle" ) ) ); FocusViews( origin, string_read_float( entity->getKeyValue( "angle" ) ) );
} }
else else
@ -503,7 +502,7 @@ void Map_StartPosition(){
inline bool node_is_worldspawn( scene::Node& node ){ inline bool node_is_worldspawn( scene::Node& node ){
Entity* entity = Node_getEntity( node ); Entity* entity = Node_getEntity( node );
return entity != 0 && string_equal( entity->getKeyValue( "classname" ), "worldspawn" ); return entity != 0 && string_equal( entity->getClassName(), "worldspawn" );
} }
@ -825,13 +824,7 @@ public:
bool pre( const scene::Path& path, scene::Instance& instance ) const { bool pre( const scene::Path& path, scene::Instance& instance ) const {
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 ) { if ( entity != 0 ) {
const EntityClass& eclass = entity->getEntityClass(); ++m_entitymap[entity->getClassName()];
if ( m_entitymap.find( eclass.name() ) == m_entitymap.end() ) {
m_entitymap[eclass.name()] = 1;
}
else{
++m_entitymap[eclass.name()];
}
} }
return true; return true;
} }
@ -853,18 +846,19 @@ public:
bool pre( const scene::Path& path, scene::Instance& instance ) const { bool pre( const scene::Path& path, scene::Instance& instance ) const {
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 ){ if ( entity != 0 ){
const char* classname = entity->getClassName();
if( entity->isContainer() ){ if( entity->isContainer() ){
++m_groupents; ++m_groupents;
if( !string_equal_nocase( "func_group", entity->getKeyValue( "classname" ) ) && if( !string_equal_nocase( "func_group", classname ) &&
!string_equal_nocase( "_decal", entity->getKeyValue( "classname" ) ) && !string_equal_nocase( "_decal", classname ) &&
!string_equal_nocase_n( "func_detail", entity->getKeyValue( "classname" ), 11 ) ){ !string_equal_nocase_n( "func_detail", classname, 11 ) ){
++m_groupents_ingame; ++m_groupents_ingame;
++m_ents_ingame; ++m_ents_ingame;
} }
return true; return true;
} }
if( !string_equal_nocase_n( "light", entity->getKeyValue( "classname" ), 5 ) && if( !string_equal_nocase_n( "light", classname, 5 ) &&
!string_equal_nocase( "misc_model", entity->getKeyValue( "classname" ) ) ){ !string_equal_nocase( "misc_model", classname ) ){
++m_ents_ingame; ++m_ents_ingame;
} }
} }
@ -2326,7 +2320,7 @@ void map_autocaulk_selected(){
bool pre( const scene::Path& path, scene::Instance& instance ) const { bool pre( const scene::Path& path, scene::Instance& instance ) const {
if( path.size() == 2 ){ if( path.size() == 2 ){
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if( entity != 0 && entity->isContainer() && string_equal_nocase_n( entity->getEntityClass().name(), "trigger_", 8 ) if( entity != 0 && entity->isContainer() && string_equal_nocase_n( entity->getClassName(), "trigger_", 8 )
&& ( instance.childSelected() || instance.isSelected() ) ) && ( instance.childSelected() || instance.isSelected() ) )
m_trigger = &instance; m_trigger = &instance;
else else

View File

@ -112,10 +112,8 @@ public:
// ignore worldspawn // ignore worldspawn
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity ) { if ( entity != nullptr && string_equal( entity->getClassName(), "worldspawn" ) ) {
if ( string_equal( entity->getKeyValue( "classname" ), "worldspawn" ) ) { return true;
return true;
}
} }
if ( path.size() > 1 if ( path.size() > 1
@ -873,7 +871,7 @@ void Select_EntitiesByKeyValue( const char* key, const char* value ){
else if( key != nullptr ){ else if( key != nullptr ){
if( !string_empty( key ) ){ if( !string_empty( key ) ){
Scene_EntitySelectByPropertyValues( GlobalSceneGraph(), [key]( const Entity* entity )->bool{ Scene_EntitySelectByPropertyValues( GlobalSceneGraph(), [key]( const Entity* entity )->bool{
return !string_empty( entity->getKeyValue( key ) ); return entity->hasKeyValue( key );
} ); } );
} }
} }

View File

@ -1611,7 +1611,7 @@ void Light_setTexture( Entity& entity, const char* shader, const FaceTexture& cl
/* copypaste of write_intensity() from entity plugin */ /* copypaste of write_intensity() from entity plugin */
char value[64]; char value[64];
sprintf( value, "%g", clipboard.m_light ); sprintf( value, "%g", clipboard.m_light );
if( !string_empty( entity.getKeyValue( "_light" ) ) ) //primaryIntensity //if set or default is set in .ent if( entity.hasKeyValue( "_light" ) ) //primaryIntensity //if set
entity.setKeyValue( "_light", value ); entity.setKeyValue( "_light", value );
else //secondaryIntensity else //secondaryIntensity
entity.setKeyValue( "light", value ); //otherwise default to "light", which is understood by both q3 and q1 entity.setKeyValue( "light", value ); //otherwise default to "light", which is understood by both q3 and q1
@ -1664,7 +1664,7 @@ public:
} }
} }
}; };
#include "eclasslib.h"
class BrushGetClosestFaceVisibleWalker : public scene::Graph::Walker class BrushGetClosestFaceVisibleWalker : public scene::Graph::Walker
{ {
SelectionTest& m_test; SelectionTest& m_test;
@ -1700,7 +1700,7 @@ public:
return true; return true;
} }
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if( entity != 0 && string_equal_n( entity->getEntityClass().name(), "light", 5 ) ){ if( entity != 0 && string_equal_n( entity->getClassName(), "light", 5 ) ){
m_texturable.setTexture = makeCallback4( LightSetTexture(), *entity ); m_texturable.setTexture = makeCallback4( LightSetTexture(), *entity );
m_texturable.getTexture = makeCallback2( LightGetTexture(), *entity ); m_texturable.getTexture = makeCallback2( LightGetTexture(), *entity );
} }