deduplicate entity connecting code
This commit is contained in:
parent
0b43b1744f
commit
129d54e33f
|
|
@ -128,11 +128,11 @@ class ConnectEntities
|
||||||
Entity* m_e1;
|
Entity* m_e1;
|
||||||
Entity* m_e2;
|
Entity* m_e2;
|
||||||
public:
|
public:
|
||||||
const char* m_keyname;
|
const char* m_targetkey;
|
||||||
ConnectEntities( Entity* e1, Entity* e2, int index ) : m_e1( e1 ), m_e2( e2 ), m_keyname( index == 1? "killtarget" : "target" ){
|
ConnectEntities( Entity* e1, Entity* e2, int index ) : m_e1( e1 ), m_e2( e2 ), m_targetkey( index == 1? "killtarget" : "target" ){
|
||||||
}
|
}
|
||||||
void connect( const char* name ){
|
void connect( const char* name ){
|
||||||
m_e1->setKeyValue( m_keyname, name );
|
m_e1->setKeyValue( m_targetkey, name );
|
||||||
m_e2->setKeyValue( "targetname", name );
|
m_e2->setKeyValue( "targetname", name );
|
||||||
}
|
}
|
||||||
typedef MemberCaller1<ConnectEntities, const char*, &ConnectEntities::connect> ConnectCaller;
|
typedef MemberCaller1<ConnectEntities, const char*, &ConnectEntities::connect> ConnectCaller;
|
||||||
|
|
@ -202,44 +202,22 @@ public:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConnectEntities connector( e1, e2, index );
|
ConnectEntities connector( e1, e2, index );
|
||||||
//killconnect
|
// prioritize existing target key: intent is to most probably not break existing connections
|
||||||
if( index == 1 ){
|
// checking, if ent has actual connections, could be better solution
|
||||||
const char* value = e2->getKeyValue( "targetname" );
|
const char* value = e1->getKeyValue( connector.m_targetkey );
|
||||||
if ( !string_empty( value ) ) {
|
if ( string_empty( value ) ) {
|
||||||
connector.connect( value );
|
value = e2->getKeyValue( "targetname" );
|
||||||
}
|
}
|
||||||
else
|
if ( !string_empty( value ) ) {
|
||||||
{
|
connector.connect( value );
|
||||||
const char* type = e2->getClassName();
|
|
||||||
if ( string_empty( type ) ) {
|
|
||||||
type = "t";
|
|
||||||
}
|
|
||||||
const auto key = StringStream<64>( type, '1' );
|
|
||||||
GlobalNamespace().makeUnique( key, ConnectEntities::ConnectCaller( connector ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//normal connect
|
|
||||||
else{
|
else{
|
||||||
//prioritize existing target key
|
const char* type = e2->getClassName();
|
||||||
//checking, if ent got other connected ones already, could be better solution
|
if ( string_empty( type ) ) {
|
||||||
const char* value = e1->getKeyValue( "target" );
|
type = "t";
|
||||||
if ( !string_empty( value ) ) {
|
|
||||||
connector.connect( value );
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
value = e2->getKeyValue( "targetname" );
|
|
||||||
if ( !string_empty( value ) ) {
|
|
||||||
connector.connect( value );
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
const char* type = e2->getClassName();
|
|
||||||
if ( string_empty( type ) ) {
|
|
||||||
type = "t";
|
|
||||||
}
|
|
||||||
const auto key = StringStream<64>( type, '1' );
|
|
||||||
GlobalNamespace().makeUnique( key, ConnectEntities::ConnectCaller( connector ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const auto key = StringStream<64>( type, '1' );
|
||||||
|
GlobalNamespace().makeUnique( key, ConnectEntities::ConnectCaller( connector ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SceneChangeNotify();
|
SceneChangeNotify();
|
||||||
|
|
@ -443,7 +421,9 @@ void Entity_Construct( EGameType gameType ){
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity_InitFilters();
|
Entity_InitFilters();
|
||||||
const LightType lightType = g_gameType == eGameTypeRTCW? LIGHTTYPE_RTCW : g_gameType == eGameTypeDoom3? LIGHTTYPE_DOOM3 : LIGHTTYPE_DEFAULT;
|
const LightType lightType = g_gameType == eGameTypeRTCW? LIGHTTYPE_RTCW
|
||||||
|
: g_gameType == eGameTypeDoom3? LIGHTTYPE_DOOM3
|
||||||
|
: LIGHTTYPE_DEFAULT;
|
||||||
Light_Construct( lightType );
|
Light_Construct( lightType );
|
||||||
MiscModel_construct();
|
MiscModel_construct();
|
||||||
Doom3Group_construct();
|
Doom3Group_construct();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user