const char *DynamicConsoleMethodComponent::callOnBehaviors( U32 argc, const char *argv[] ) { // Set Owner SimObject *pThis; pThis = dynamic_cast<SimObject *>( this ); AssertFatal( pThis, "DynamicConsoleMethodComponent::callOnBehaviors : this should always exist!" ); const char* result = ""; bool handled = false; if( getComponentCount() > 0 ) { VectorPtr<SimComponent *>&componentList = lockComponentList(); for( SimComponentIterator nItr = (componentList.end()-1); nItr >= componentList.begin(); nItr-- ) { argv[0] = StringTable->insert(argv[0]); SimComponent *pComponent = (*nItr); AssertFatal( pComponent, "DynamicConsoleMethodComponent::callOnBehaviors - NULL component in list!" ); handled = pComponent->callMethodOnComponents(argc, argv, &result); if (handled) break; } unlockComponentList(); } if (!handled) { result = "ERR_CALL_NOT_HANDLED"; } return result; }
bool SimComponent::callMethodOnComponents( U32 argc, const char* argv[], const char** result ) { const char *cbName = StringTable->insert(argv[0]); if (isEnabled()) { if(isMethod(cbName)) { // This component can handle the given method *result = Con::execute( this, argc, argv, true ); return true; } else if( getComponentCount() > 0 ) { // Need to try the component's children bool handled = false; VectorPtr<SimComponent *>&componentList = lockComponentList(); for( SimComponentIterator nItr = (componentList.end()-1); nItr >= componentList.begin(); nItr-- ) { argv[0] = cbName; SimComponent *pComponent = (*nItr); AssertFatal( pComponent, "SimComponent::callMethodOnComponents - NULL component in list!" ); // Call on children handled = pComponent->callMethodOnComponents( argc, argv, result ); if (handled) break; } unlockComponentList(); if (handled) return true; } } return false; }