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 ){
}
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" ) ) {
world.LoadFromEntity( instance.path().top(), false );

View File

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

View File

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

View File

@ -43,7 +43,7 @@ public:
bool pre( const scene::Path& path, scene::Instance& instance ) const {
if ( m_entity == 0 ) {
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;
}
}
@ -73,13 +73,9 @@ public:
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 {
const char *str;
Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 && string_equal( m_classname, entity->getKeyValue( "classname" ) ) ) {
str = entity->getKeyValue( m_flag );
if ( string_empty( str ) ) {
( *m_count )++;
}
if ( entity != 0 && string_equal( m_classname, entity->getClassName() ) && !entity->hasKeyValue( m_flag ) ) {
( *m_count )++;
}
return true;
}
@ -99,15 +95,14 @@ public:
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 {
const char *str;
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 ) {
( *m_count )++;
}
// now get the highest teamnum
if ( m_team ) {
str = entity->getKeyValue( "team" );
const char *str = entity->getKeyValue( "team" );
if ( !string_empty( str ) ) {
if ( atoi( str ) > *m_team ) {
( *m_team ) = atoi( str );
@ -147,18 +142,18 @@ void assign_default_values_to_worldspawn( bool override, const char **returnMsg
*message = '\0';
*str = '\0';
if ( override || string_empty( worldspawn->getKeyValue( "maxlevel" ) ) ) {
if ( override || !worldspawn->hasKeyValue( "maxlevel" ) ) {
// TODO: Get highest brush - a level has 64 units
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 );
if ( teams ) {
snprintf( str, sizeof( str ) - 1, "%i", teams );
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 ) {
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
if ( string_empty( worldspawn->getKeyValue( "maxlevel" ) ) ) {
if ( !worldspawn->hasKeyValue( "maxlevel" ) ) {
strncat( message, "Worldspawn: No maxlevel defined\n", sizeof( message ) - 1 );
}
else if ( atoi( worldspawn->getKeyValue( "maxlevel" ) ) > 8 ) {

View File

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

View File

@ -543,7 +543,7 @@ public:
}
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" );
m_observers.insert( &observer );
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 );
}
}
void detach( Observer& observer ){
void detach( Observer& observer ) override {
ASSERT_MESSAGE( !m_observerMutex, "observer cannot be detached during iteration" );
m_observers.erase( &observer );
for ( KeyValues::const_iterator i = m_keyValues.begin(); i != m_keyValues.end(); ++i )
@ -593,17 +593,20 @@ public:
}
// entity
EntityClass& getEntityClass() const {
EntityClass& getEntityClass() const override {
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 )
{
visitor.visit( ( *i ).first.c_str(), ( *i ).second->c_str() );
}
}
void setKeyValue( const char* key, const char* value ){
if ( value[0] == '\0'
void setKeyValue( const char* key, const char* value ) override {
if ( string_empty( value )
/*|| string_equal(EntityClass_valueForKey(*m_eclass, key), value)*/ ) { // don't delete values equal to default
erase( key );
}
@ -613,16 +616,20 @@ public:
}
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 );
if ( i != m_keyValues.end() ) {
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;
}
};

View File

@ -204,8 +204,7 @@ public:
if ( i != 0 ) {
key << i;
}
const char* value = e1->getKeyValue( key.c_str() );
if ( string_empty( value ) ) {
if ( !e1->hasKeyValue( key.c_str() ) ) {
e1->setKeyValue( key.c_str(), e2->getKeyValue( "name" ) );
break;
}
@ -224,7 +223,7 @@ public:
}
else
{
const char* type = e2->getKeyValue( "classname" );
const char* type = e2->getClassName();
if ( string_empty( type ) ) {
type = "t";
}
@ -247,7 +246,7 @@ public:
connector.connect( value );
}
else{
const char* type = e2->getKeyValue( "classname" );
const char* type = e2->getClassName();
if ( string_empty( type ) ) {
type = "t";
}
@ -329,7 +328,7 @@ public:
filter_entity_classname( const char* classname ) : m_classname( classname ){
}
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 ) ){
}
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:
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" ) );
}
};
@ -377,7 +376,7 @@ class filter_entity_not_func_detail : public EntityFilter
public:
bool filter( const Entity& entity ) const {
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:
bool filter( const Entity& entity ) const {
const char* value = entity.getKeyValue( "classname" );
const char* value = entity.getClassName();
return string_equal( value, "worldspawn" )
|| string_equal( value, "func_group" )
|| string_equal_n( value, "func_detail", 11 );
@ -402,7 +401,7 @@ public:
bool filter( const Entity& entity ) const {
return !entity.isContainer()
&& !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;
bool m_anglesDraw;
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();
}
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 ){
char value[64];
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 );
else //secondaryIntensity
entity->setKeyValue( "light", value ); //otherwise default to "light", which is understood by both q3 and q1
@ -1443,7 +1443,7 @@ public:
if( selected ){
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 ) {
renderer.SetState( m_colour.state_additive(), Renderer::eFullMaterials );
renderer.Highlight( Renderer::ePrimitive, false );

View File

@ -251,7 +251,7 @@ public:
const EntityClass& eclass = m_entity.getEntityClass();
const char *key = eclass.miscmodel_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 );
}
}

View File

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

View File

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

View File

@ -159,7 +159,7 @@ public:
}
void popElement( const char* name ){
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 ) );

View File

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

View File

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

View File

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

View File

@ -112,10 +112,8 @@ public:
// ignore worldspawn
Entity* entity = Node_getEntity( path.top() );
if ( entity ) {
if ( string_equal( entity->getKeyValue( "classname" ), "worldspawn" ) ) {
return true;
}
if ( entity != nullptr && string_equal( entity->getClassName(), "worldspawn" ) ) {
return true;
}
if ( path.size() > 1
@ -873,7 +871,7 @@ void Select_EntitiesByKeyValue( const char* key, const char* value ){
else if( key != nullptr ){
if( !string_empty( key ) ){
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 */
char value[64];
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 );
else //secondaryIntensity
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
{
SelectionTest& m_test;
@ -1700,7 +1700,7 @@ public:
return true;
}
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.getTexture = makeCallback2( LightGetTexture(), *entity );
}