void DiBone::SetBindingPose() { SetInitialState(); mBindDerivedInversePosition = -GetDerivedPosition(); mBindDerivedInverseScale = DiVec3::UNIT_SCALE / GetDerivedScale(); mBindDerivedInverseOrientation = GetDerivedOrientation().Inverse(); }
XnStatus XnFileDevice::Rewind() { XnStatus nRetVal = XN_STATUS_OK; // go back to start of stream nRetVal = m_pInputStream->Seek(XN_DEVICE_FILE_MAGIC_LEN); XN_IS_STATUS_OK(nRetVal); // read initial state XN_PROPERTY_SET_CREATE_ON_STACK(state); nRetVal = ReadInitialState(&state); XN_IS_STATUS_OK(nRetVal); // first handle current streams. remove or reset them for (XnNodeInfoMap::Iterator it = m_nodeInfoMap.Begin(); it != m_nodeInfoMap.End(); ++it) { const XnChar* strName = it->Key(); if (m_bNodeCollectionChanged) { // we need to destroy all streams, and recreate them later nRetVal = m_pNotifications->OnNodeRemoved(m_pNotificationsCookie, strName); XN_IS_STATUS_OK(nRetVal); } else { // just reset frame ID it->Value().nCurrFrameID = 0; // and mark not to recreate it nRetVal = m_ignoreNewNodes.Set(strName, it->Value()); XN_IS_STATUS_OK(nRetVal); } } // if we need, recreate nodes if (m_bNodeCollectionChanged) { nRetVal = SetInitialState(&state); XN_IS_STATUS_OK(nRetVal); } // ResetLastTimestampAndFrame(); // m_nReferenceTimestamp = 0; // m_nReferenceTime = 0; m_bNodeCollectionChanged = FALSE; m_nCurrTimestamp = 0; return (XN_STATUS_OK); }
void idSliderWindow::InitWithDefaults(const char *_name, const idRectangle &_rect, const idVec4 &_foreColor, const idVec4 &_matColor, const char *_background, const char *thumbShader, bool _vertical, bool _scrollbar) { SetInitialState(_name); rect = _rect; foreColor = _foreColor; matColor = _matColor; thumbMat = declManager->FindMaterial(thumbShader); thumbMat->SetSort( SS_GUI ); thumbWidth = thumbMat->GetImageWidth(); thumbHeight = thumbMat->GetImageHeight(); background = declManager->FindMaterial(_background); background->SetSort( SS_GUI ); vertical = _vertical; scrollbar = _scrollbar; flags |= WIN_HOLDCAPTURE; }
XnStatus XnFileDevice::SetInputStream(void *pStreamCookie, XnPlayerInputStreamInterface *pStream) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_NEW(m_pInputStream, XnInputStream, pStream, pStreamCookie); nRetVal = m_pInputStream->Init(); if (nRetVal != XN_STATUS_OK) { XN_DELETE(m_pInputStream); m_pInputStream = NULL; return (nRetVal); } // read format version nRetVal = ReadFileVersion(); XN_IS_STATUS_OK(nRetVal); m_pDataPacker = XN_NEW(XnDataPacker, m_pInputStream, XN_DEVICE_FILE_MAX_INTERNAL_BUFFER); if (m_pDataPacker == NULL) { XN_DELETE(m_pInputStream); return (XN_STATUS_ALLOC_FAILED); } nRetVal = m_pDataPacker->Init(); if (nRetVal != XN_STATUS_OK) { XN_DELETE(m_pDataPacker); XN_DELETE(m_pInputStream); return (nRetVal); } // read initial state XN_PROPERTY_SET_CREATE_ON_STACK(props); nRetVal = ReadInitialState(&props); XN_IS_STATUS_OK(nRetVal); nRetVal = SetInitialState(&props); XN_IS_STATUS_OK(nRetVal); // now read till first data XnBool bWrap; nRetVal = ReadTillNextData(&bWrap); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
//============================================================== // SupplicantStateTracker //============================================================== SupplicantStateTracker::SupplicantStateTracker( /* [in] */ IContext* c, /* [in] */ WifiStateMachine* wsm, /* [in] */ WifiConfigStore* wcs, /* [in] */ ILooper* l) : StateMachine(TAG, l) , mWifiStateMachine(wsm) , mWifiConfigStore(wcs) , mAuthenticationFailuresCount(0) , mAssociationRejectCount(0) , mAuthFailureInSupplicantBroadcast(FALSE) , mNetworksDisabledDuringConnect(FALSE) , mContext(c) , mUninitializedState(new UninitializedState(this)) , mDefaultState(new DefaultState(this)) , mInactiveState(new InactiveState(this)) , mDisconnectState(new DisconnectedState(this)) , mScanState(new ScanState(this)) , mHandshakeState(new HandshakeState(this)) , mCompletedState(new CompletedState(this)) , mDormantState(new DormantState(this)) { AutoPtr<IInterface> service; AutoPtr<IServiceManager> serviceManager; CServiceManager::AcquireSingleton((IServiceManager**)&serviceManager); serviceManager->GetService(IBatteryStats::SERVICE_NAME, (IInterface**)&service); mBatteryStats = IIBatteryStats::Probe(service); AddState(mDefaultState); AddState(mUninitializedState, mDefaultState); AddState(mInactiveState, mDefaultState); AddState(mDisconnectState, mDefaultState); AddState(mScanState, mDefaultState); AddState(mHandshakeState, mDefaultState); AddState(mCompletedState, mDefaultState); AddState(mDormantState, mDefaultState); SetInitialState(mUninitializedState); SetLogRecSize(50); SetLogOnlyTransitions(TRUE); //start the state machine Start(); }
//============================================================== // DhcpStateMachine::WaitBeforeRenewalState //============================================================== DhcpStateMachine::DhcpStateMachine( /* [in] */ IContext* context, /* [in] */ StateMachine* controller, /* [in] */ const String& intf) : StateMachine(TAG) , mController(controller) , mContext(context) , mInterfaceName(intf) , mRegisteredForPreDhcpNotification(FALSE) { mDefaultState = new DefaultState(this); mStoppedState = new StoppedState(this); mWaitBeforeStartState = new WaitBeforeStartState(this); mRunningState = new RunningState(this); mWaitBeforeRenewalState = new WaitBeforeRenewalState(this); mContext->GetSystemService(IContext::ALARM_SERVICE, (IInterface**)&mAlarmManager); AutoPtr<IIntent> dhcpRenewalIntent; CIntent::New(ACTION_DHCP_RENEW, NULL, (IIntent**)&dhcpRenewalIntent); AutoPtr<IPendingIntentHelper> intentHelper; CPendingIntentHelper::AcquireSingleton((IPendingIntentHelper**)&intentHelper); intentHelper->GetBroadcast(mContext, DHCP_RENEW, dhcpRenewalIntent, 0, (IPendingIntent**)&mDhcpRenewalIntent); AutoPtr<IPowerManager> powerManager; mContext->GetSystemService(IContext::POWER_SERVICE, (IInterface**)&powerManager); powerManager->NewWakeLock(IPowerManager::PARTIAL_WAKE_LOCK, WAKELOCK_TAG, (IPowerManagerWakeLock**)&mDhcpRenewWakeLock); mDhcpRenewWakeLock->SetReferenceCounted(FALSE); mBroadcastReceiver = new MyBroadcastReceiver(this); AutoPtr<IIntentFilter> intentFilter; CIntentFilter::New(ACTION_DHCP_RENEW, (IIntentFilter**)&intentFilter); AutoPtr<IIntent> intent; mContext->RegisterReceiver(mBroadcastReceiver, intentFilter, (IIntent**)&intent); AddState(mDefaultState); AddState(mStoppedState, mDefaultState); AddState(mWaitBeforeStartState, mDefaultState); AddState(mRunningState, mDefaultState); AddState(mWaitBeforeRenewalState, mDefaultState); SetInitialState(mStoppedState); }
XnStatus XnStreamReaderDevice::InitImpl(const XnDeviceConfig* pDeviceConfig) { XnStatus nRetVal = XN_STATUS_OK; // we will init the device using state from the stream, instead of the one from user. // the one from user will be used to set properties afterwards. // first open the stream nRetVal = InitPacker(pDeviceConfig->cpConnectionString); XN_IS_STATUS_OK(nRetVal); // create a property set XnPropertySet* pSet; nRetVal = XnPropertySetCreate(&pSet); XN_IS_STATUS_OK(nRetVal); // read initial state (we assume first object in the stream is the initial state) nRetVal = ReadInitialState(pSet); if (nRetVal != XN_STATUS_OK) { XnPropertySetDestroy(&pSet); return (nRetVal); } nRetVal = SetInitialState(pDeviceConfig, pSet); if (nRetVal != XN_STATUS_OK) { XnPropertySetDestroy(&pSet); return (nRetVal); } // destroy the property set (we don't need it anymore) nRetVal = XnPropertySetDestroy(&pSet); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
int main(int argc, char* argv[]) { clock_t begin_main = GetTime(); clock_t end_main; bool is_verbose = false; #ifdef OUTPUT is_verbose = true; #endif float discount_factor = 0.0; /* gamma */ float max_reward = 0.0; float weight = 0.0; char algorithm = 0; char opt = 0; unsigned int NUM_ACTIONS = 4; unsigned int NUM_AGENTS = 2; GridWorld *environment = NULL; VariablesInfo* stateDescription = NULL; int next_option = 0; int num_options = 0; /* A string listing valid short options letters: h = help a = number of actions t = number of agents m = algorithm (C=CoLF, K = CKCoLF) g = gamma p = number of steps for each trial e = environment (G = grid for now) */ const char* const short_options = "h:a:o:w:g:e:"; /* An array describing valid long options (see above). */ const struct option long_options[] = { {"help", 0, NULL, 'h'}, {"algorithm", 1, NULL, 'a'}, {"option", 1, NULL, 'o'}, {"weight", 1, NULL, 'w'}, {"gamma", 1, NULL, 'g'}, {"environment", 1, NULL, 'e'}, {NULL, 0, NULL, 0} /* Required at end of array. */ }; srand(time(NULL)); vector<VI*> agents; vector<string> agent_names; do { next_option = getopt_long (argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': { /* -h or --help */ PrintUsage("Help message",EXIT_OK); } case 'a': { /* -m or --algorithm --> learning algorithm for self play (C, K) */ if (*optarg == 'C' || *optarg == 'F'||*optarg == 'M'||*optarg == 'T') algorithm = *optarg; else PrintUsage("Invalid algorithm, only \'C\' or \'F\' or \'M\' or \'T\' are allowed!",BAD_USAGE); //cout << "Algorithm: " << algorithm << endl; num_options++; break; } case 'o': { if (*optarg == 'u' || *optarg == 'e'||*optarg == 'r') opt = *optarg; else PrintUsage("Invalid algorithm option, only \'u\' or \'e\' or \'r\' are allowed!",BAD_USAGE); //cout << "Algorithm: " << algorithm << endl; num_options++; break; } case 'w': weight = atof(optarg); if (weight < 0 || weight > 1) PrintUsage("Invalid weight, it must be between 0 and 1", BAD_USAGE); //cout << "Gamma: " << discount_factor <<endl;; num_options++; break; case 'g': { /* -g or --gamma --> discount factor */ discount_factor = atof(optarg); if (discount_factor < 0 || discount_factor > 1) PrintUsage("Invalid discount_factor, it must be between 0 and 1", BAD_USAGE); //cout << "Gamma: " << discount_factor <<endl;; num_options++; break; } case 'e': { /* -e or --environment --> environment choosen (G) */ if ( *optarg == 'T') { if (NUM_AGENTS >= 8) PrintUsage("Too many agents for the grid environment; maximum allowed = 7\n", BAD_USAGE); environment = new GridWorld(*optarg); } else if(*optarg == 'C'||*optarg == 'P'||*optarg == 'X'||*optarg == 'G'||*optarg == 'A') environment = new GridWorldWall(*optarg); else PrintUsage("Invalid environment", BAD_USAGE); //cout << "Environment: " << *optarg << endl; num_options++; break; } case '?': { /* The user specified an invalid option. */ PrintUsage (string("Unknown option \'").append(optarg).append("\'"), BAD_USAGE); } case -1: { /* Done with options. */ if (num_options != 5) PrintUsage("Mandatory options not present", BAD_USAGE); break; } default: /* Something else unexpected. */ abort(); } } while (next_option != -1); VariablesInfo* admissible_actions = new VariablesInfo(); CE_VI* agent = NULL; AddAgentNames(&agent_names); AddAgentActions(NUM_ACTIONS, admissible_actions); // Set the intial state of grid environment with random position for all agents // Obviously is passed as argument to each agent... stateDescription = SetInitialState(NUM_AGENTS); environment->Init(stateDescription); //stateDescription = environment->GetStateDescription(); //environment->AppendInit(AppendToInitialState(stateDescription,NUM_AGENTS)); cout << "****" << endl; if (algorithm == 'C' || algorithm == 'F'|| algorithm == 'M'|| algorithm == 'T') { cout << "Creating VI..." <<endl << "algorithm: "<<algorithm<< " option:" << opt<<endl; agent = new CE_VI(agent_names[0], 0, NUM_AGENTS, admissible_actions, discount_factor, max_reward, is_verbose, algorithm, opt, weight, environment); if (agent == NULL) { cerr << "main: VI creation NULL!" << endl; exit(NO_MEM_AVAILABLE); } } else { cout << "The specified algorithm is not available" << endl; cout << "The only algorithms available are:" << endl; cout << "'C': CE-VI" << endl; cout << "'F': Friend-VI" << endl; cout << "'M': MiniMax-VI" << endl; cout << "'T': TB-VI" << endl; exit(1); } agent->SetTransitionModel(environment->GetTransitionModel()); //FOR DEBUG /*vector <unsigned> vState; for (unsigned i= 0; i<81;i++) { cout << "State " << i; vState = environment->GetFromIndex(i,4,3); cout <<": " << vState[0] << "," <<vState[1] << "," <<vState[2] << "," <<vState[3] <<endl; cout << "<-state:" << environment->ComputeJointIndex(vState, 3) << endl; }*/ agent->Execute(); // select and execute action //agent->BuildConvexHull(); delete stateDescription; stateDescription = NULL; //test_environment(environment); //cout << "TOTAL PAYOFF --> G = " << endl << endl; /*for (i = 0; i < agents.size(); i++) { cout << agents[i]->PrintQTable(); }*/ delete admissible_actions; delete environment; // perché diavolo segmenta?!? /*for (i = 0; i < agents.size(); i++) { cout << "main: delete agent " << i << endl; flush(cout); delete agents[i]; }*/ end_main = GetTime(); cout << ">>> main.cpp: elapsed time = " << (double)(end_main-begin_main)/CLOCKS_PER_SEC << " seconds" <<endl; return 0; }