bool CBasicGUILayer::updateGL(CEventMouseClick *e) { if (m_root) { static CBasic2dEntity *entityDown = nullptr, *entityUp = nullptr; EMouseState state = e->getMouseState(); m_root->onClicked(*e); if (!CEntity2dFactory::getInstance()->getEntities4Event().empty()) { if (state == EMouseState::down) { entityDown = CEntity2dFactory::getInstance()->getEntities4Event().back(); entityUp = nullptr; executeAction(&CGUIManager::onPressed); } else { entityUp = CEntity2dFactory::getInstance()->getEntities4Event().back(); executeAction(&CGUIManager::onReleased); } if (entityUp && entityDown && entityDown->getId() == entityUp->getId()) { entityUp = entityDown = nullptr; executeAction(&CGUIManager::onClick); } } } return true; }
void Scheduler::doWork() { QDateTime time = QDateTime::currentDateTime(); foreach(const ScheduledAction& a, m_actions) { if(a.repeated) { const QTime& atime = a.whenRepeated; if(a.daysRepeated[time.date().dayOfWeek()-1] && time.time().hour() == atime.hour() && time.time().minute() == atime.minute()) { executeAction(a); } } else { QTime atime = a.whenOneTime.time(); if(time.date() == a.whenOneTime.date() && time.time().hour() == atime.hour() && time.time().minute() == atime.minute()) { executeAction(a); } } } }
void PropertyInt2ListControl::notifyEndDialog(Dialog* _sender, bool _result) { mTextFieldControl->endModal(); if (_result) { if (mTextFieldControl->getTextField() != "") { mList->setItemNameAt(mList->getItemCount() - 1, mTextFieldControl->getTextField()); executeAction(getValue()); return; } } mList->removeItemAt(mList->getItemCount() - 1); }
void BaseInstance::tick(float deltaTime, float interpolation) { pthread_mutex_lock(&m_canTickMutex); // Update event input state and get pending actions updateEvents(m_actions); // Execute callbacks bound to actions bool isValid = false; uint64 action = m_actions.pop(isValid); while(isValid) { executeAction(action); action = m_actions.pop(isValid); } m_activeScene->tick(deltaTime, interpolation); tickInternal(deltaTime, interpolation); m_uiManager->tick(deltaTime); if(m_debugUI) { m_debugUI->tick(getKeyCodesCount(), getKeyCodes()); if(m_debugUI->isInputReady()) { executeConsoleCommand(m_debugUI->consumeInput()); } } // Reset keyboard input cache. Make sure to do this after last tick operation. resetKeyCodes(); // Find visible actors only if draw thread is awaiting sync operation. Otherwise it would be a waste of time if(pthread_mutex_trylock(&m_canDrawMutex) > 0) { m_renderQueue.clear(); m_activeScene->findVisibleActors(m_renderQueue); pthread_mutex_unlock(&m_canSyncMutex); } else { pthread_mutex_unlock(&m_canDrawMutex); pthread_mutex_unlock(&m_canTickMutex); } }
bool itemData::saveDword(char* data) { if(_type == DWORD || _type == FLOAT || _type == RGB || _type == RGBW || _type == HSB) { _data[0] = data[0]; _data[1] = data[1]; _data[2] = data[2]; _data[3] = data[3]; //setNewData(); executeAction(); return true; } else return false; }
bool itemData::saveArray(char *pData, int len) { if(_type == ARRAY) { if(_datalen < len) return false; for(int i=0;i<len;i++) { _data[i] = pData[i]; } //setNewData(); executeAction(); return true; } else return false; }
List<Event> Keymapper::mapNonKey(const HardwareInputCode code) { if (!_enabled || _activeMaps.empty()) return List<Event>(); Action *action = 0; // Search for nonkey in active keymap stack for (int i = _activeMaps.size() - 1; i >= 0; --i) { MapRecord mr = _activeMaps[i]; debug(5, "Keymapper::mapKey keymap: %s", mr.keymap->getName().c_str()); action = mr.keymap->getMappedAction(code); if (action || !mr.transparent) break; } if (!action) return List<Event>(); return executeAction(action); }
int JSONTokenizer::parse() try { push__(0); // initial state clearin(); // clear the tokens. while (true) { try { if (s_state[d_state__]->d_type & REQ_TOKEN) nextToken(); // obtain next token int action = lookup(false); // lookup d_token__ in d_state__ if (action > 0) // SHIFT: push a new state { push__(action); popToken__(); // token processed } else if (action < 0) // REDUCE: execute and pop. { executeAction(-action); // next token is the rule's LHS reduce__(s_productionInfo[-action]); } else ACCEPT(); } catch (ErrorRecovery__) { errorRecovery(); } } } catch (Return__ retValue) { return retValue; }
/********************************************************* * Communication with agent *********************************************************/ bool agentenvironmentcb(lilee_rl_discrete::AgentEnvironment::Request& req, lilee_rl_discrete::AgentEnvironment::Response& res) { // perform action executeAction(req.action); ros::Duration(actions::ACTION_DURATION_).sleep(); // read next state goaldepthFlag = odomFlag = false; while (!(goaldepthFlag && odomFlag)) { ros::Duration(0.1).sleep(); } // Send next state and reward if (((int)state_.distance_to_goal < 1) && (state_.theta_to_goal <= 1)) { // Check if goal state ROS_ERROR("envir: GOAL!!"); respawn_goal(); respawn_agent(); res.reward = 100.0; res.state = TERMINAL_STATE_; res.state.success = 1; } else if (stepCnt > MAX_STEP_CNT_) { // If agent took MAX_STEP_CNT steps, restart episode. ROS_ERROR("envir: Agent failed to find goal after %d steps.", MAX_STEP_CNT_); respawn_goal(); respawn_agent(); res.reward = -1.0; res.state = state_; res.state.isTerminal = true; res.state.success = 0; } else { res.reward = -1.0; res.state = state_; } return true; }
MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // setup ActionBox 1 ui->ActionBox1->setIcon(QPixmap(":/res/fileopen.png")); ui->ActionBox1->header()->setText("Header of the group"); connect(ui->ActionBox1->header(), SIGNAL(clicked()), this, SLOT(executeAction())); QSint::ActionLabel *a1 = ui->ActionBox1->createItem("This action has no icon"); connect(a1, SIGNAL(clicked()), this, SLOT(executeAction())); QSint::ActionLabel *a2 = ui->ActionBox1->createItem(QPixmap(":/res/fileprint.png"), "This action has icon"); connect(a2, SIGNAL(clicked()), this, SLOT(executeAction())); QLayout *hbl1 = ui->ActionBox1->createHBoxLayout(); QSint::ActionLabel *a3 = ui->ActionBox1->createItem("1st action in row", hbl1); connect(a3, SIGNAL(clicked()), this, SLOT(executeAction())); QSint::ActionLabel *a4 = ui->ActionBox1->createItem("2nd action in row", hbl1); connect(a4, SIGNAL(clicked()), this, SLOT(executeAction())); // setup ActionBox 2 ui->ActionBox2->setIcon(QPixmap(":/res/filesave.png")); ui->ActionBox2->header()->setText("Checkable actions allowed"); connect(ui->ActionBox2->header(), SIGNAL(clicked()), this, SLOT(executeAction())); QSint::ActionLabel *b1 = ui->ActionBox2->createItem("Action 1 (Exclusive)"); b1->setCheckable(true); b1->setAutoExclusive(true); b1->setChecked(true); QSint::ActionLabel *b2 = ui->ActionBox2->createItem("Action 2 (Exclusive)"); b2->setCheckable(true); b2->setAutoExclusive(true); QSint::ActionLabel *b3 = ui->ActionBox2->createItem("Action 3 (Exclusive)"); b3->setCheckable(true); b3->setAutoExclusive(true); QSint::ActionLabel *b4 = ui->ActionBox2->createItem("Non-exclusive but still checkable"); b4->setCheckable(true); // setup ActionBox 3 ui->ActionBox3->setIcon(QPixmap(":/res/fileprint.png")); ui->ActionBox3->header()->setText("Also, widgets allowed as well"); ui->ActionBox3->addWidget(new QPushButton("PushButton", this)); ui->ActionBox3->addWidget(new QCheckBox("CheckBox", this)); QLayout *hbl3 = ui->ActionBox3->createHBoxLayout(); ui->ActionBox3->addWidget(new QRadioButton("RadioButton 1", this), hbl3); ui->ActionBox3->addWidget(new QRadioButton("RadioButton 2", this), hbl3); // setup ActionBox 4 ui->ActionBox4->setIcon(QPixmap(":/res/fileopen.png")); ui->ActionBox4->header()->setText("ActionBox with different scheme"); ui->ActionBox4->createItem("This action has no icon"); ui->ActionBox4->createItem(QPixmap(":/res/fileprint.png"), "This action has icon"); QLayout *hbl4 = ui->ActionBox4->createHBoxLayout(); ui->ActionBox4->createItem("1st action in row", hbl4); ui->ActionBox4->createItem("2nd action in row", hbl4); ui->ActionBox4->createItem("3rd action in row", hbl4); const char* ActionBoxNewStyle = "QSint--ActionBox {" "background-color: #333333;" "border: 1px solid #000000;" "text-align: left;" "}" "QSint--ActionBox:hover {" "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #666666, stop: 1 #333333);" "border: 1px solid #222222;" "}" "QSint--ActionBox QSint--ActionLabel[class='header'] {" "text-align: center;" "font: 14px bold;" "color: #999999;" "background-color: transparent;" "border: 1px solid transparent;" "}" "QSint--ActionBox QSint--ActionLabel[class='header']:hover {" "color: #aaaaaa;" "text-decoration: underline;" "border: 1px dotted #aaaaaa;" "}" "QSint--ActionBox QSint--ActionLabel[class='action'] {" "background-color: transparent;" "border: none;" "color: #777777;" "text-align: left;" "font: 11px;" "}" "QSint--ActionBox QSint--ActionLabel[class='action']:hover {" "color: #888888;" "text-decoration: underline;" "}" "QSint--ActionBox QSint--ActionLabel[class='action']:on {" "background-color: #ddeeff;" "color: #006600;" "}" ; ui->ActionBox4->setStyleSheet(ActionBoxNewStyle); }
/** * Perform the one-time action to "wave" (e.g., when approaching a fellow pedestrian) */ void PedestrianGeometry::executeWave(double factor) { executeAction(anim.waveIdx, factor); }
/** * Perform the one-time action to "look both ways before crossing the street" (i.e., turn head left and right) */ void PedestrianGeometry::executeLook(double factor) { executeAction(anim.lookIdx, factor); }
CMath::StateChange CMathEventQueue::process(const bool & priorToOutput) { if (mpTime == NULL || getProcessQueueExecutionTime() > *mpTime) return CMath::NoChange; mEquality = priorToOutput; mExecutionCounter = 0; mCascadingLevel = 0; bool success = true; CMath::StateChange StateChange = CMath::NoChange; *mpRootValuesBefore = mpContainer->getRoots(); mpContainer->updatePriorityValues(); iterator itAction = getAction(); #ifdef DEBUG_OUTPUT std::cout << "State: " << mpContainer->getState(false) << std::endl; std::cout << "Roots: " << mpContainer->getRoots() << std::endl; #endif //DEBUG_OUTPUT // The algorithm below will work properly for user ordered events // as the queue enforces the proper ordering. while (success && itAction != mActions.end() && mCascadingLevel != std::numeric_limits<size_t>::max()) { CMath::StateChange ActionStateChange = executeAction(itAction); StateChange |= ActionStateChange; if (ActionStateChange != CMath::NoChange) { mpContainer->updatePriorityValues(); } // State change does not indicate whether we have any root changes. We need to // explicitly check for it. #ifdef DEBUG_OUTPUT std::cout << "State: " << mpContainer->getState(false) << std::endl; std::cout << "Roots: " << mpContainer->getRoots() << std::endl; #endif // DEBUG_OUTPUT // We switch to the next cascading level so that events triggered by the // execution of assignments are properly scheduled. mCascadingLevel++; // We need to compare the roots before the execution and after // to determine which roots need to be charged. if (rootsFound()) { // We have to deal with both types of found roots. mpContainer->processRoots(mRootsFound); } // Note, applying the events may have added new events to the queue. // The setting of the equality flag for these events may be either true // or false. // First we handle equalities. mEquality = true; // Retrieve the pending calculations. itAction = getAction(); while (itAction == mActions.end() && mCascadingLevel > 0) { // If we are here we have no more actions for this level. mCascadingLevel--; if (mCascadingLevel == 0) { mEquality = priorToOutput; } itAction = getAction(); } } return StateChange; }
bool CGUIManager::onReleased(AbstractEntity *entity) { return executeAction(entity, "onReleased"); }
bool CGUIManager::onClick(AbstractEntity *entity) { return executeAction(entity, "onClick"); }
// time to think about something new to do void CHLDMBot :: getTasks (unsigned int iIgnore) { static CBotUtilities utils; static CBotUtility *next; static CBotWeapon *gravgun; static CBotWeapon *crossbow; static CWeapon *pWeapon; static bool bCheckCurrent; if ( !hasSomeConditions(CONDITION_CHANGED) && !m_pSchedules->isEmpty() ) return; removeCondition(CONDITION_CHANGED); bCheckCurrent = true; // important for checking current schedule gravgun = m_pWeapons->getWeapon(CWeapons::getWeapon(HL2DM_WEAPON_PHYSCANNON)); // If I have the grav gun, think about picking something up if ( gravgun ) { edict_t *pent = INDEXENT(gravgun->getWeaponIndex()); if ( CBotGlobals::entityIsValid(pent) ) { ADD_UTILITY(BOT_UTIL_HL2DM_GRAVIGUN_PICKUP,(!m_pEnemy||(m_pCurrentWeapon&&(strcmp("weapon_physcannon",m_pCurrentWeapon->GetClassName())))) && gravgun && gravgun->hasWeapon() && (m_NearestPhysObj.get()!=NULL) && (gravgun->getWeaponIndex() > 0) && (CClassInterface::gravityGunObject(INDEXENT(gravgun->getWeaponIndex()))==NULL),0.9f); } } if ( (crossbow = m_pWeapons->getWeapon(CWeapons::getWeapon(HL2DM_WEAPON_CROSSBOW))) != NULL ) { if ( crossbow->hasWeapon() && !crossbow->outOfAmmo(this) ) ADD_UTILITY(BOT_UTIL_SNIPE,true,0.91f); } // low on health? Pick some up if there's any near by ADD_UTILITY(BOT_UTIL_HL2DM_USE_HEALTH_CHARGER,(m_pHealthCharger.get() != NULL) && (CClassInterface::getAnimCycle(m_pHealthCharger)<1.0f) && (getHealthPercent()<1.0f),(1.0f-getHealthPercent())); ADD_UTILITY(BOT_UTIL_FIND_NEAREST_HEALTH,(m_pHealthKit.get()!=NULL) && (getHealthPercent()<1.0f),1.0f-getHealthPercent()); // low on armor? ADD_UTILITY(BOT_UTIL_HL2DM_FIND_ARMOR,(m_pBattery.get() !=NULL) && (getArmorPercent()<1.0f),(1.0f-getArmorPercent())*0.75f); ADD_UTILITY(BOT_UTIL_HL2DM_USE_CHARGER,(m_pCharger.get() !=NULL) && (CClassInterface::getAnimCycle(m_pCharger)<1.0f) && (getArmorPercent()<1.0f),(1.0f-getArmorPercent())*0.75f); ADD_UTILITY(BOT_UTIL_HL2DM_USE_CRATE,(m_pAmmoCrate.get()!=NULL) && (m_fUseCrateTime < engine->Time()),1.0f); // low on ammo? ammo nearby? ADD_UTILITY(BOT_UTIL_FIND_NEAREST_AMMO,(m_pAmmoKit.get() !=NULL) && (getAmmo(0)<5),0.01f*(100-getAmmo(0))); // always able to roam around ADD_UTILITY(BOT_UTIL_ROAM,true,0.01f); // I have an enemy ADD_UTILITY(BOT_UTIL_FIND_LAST_ENEMY,wantToFollowEnemy() && !m_bLookedForEnemyLast && m_pLastEnemy && CBotGlobals::entityIsValid(m_pLastEnemy) && CBotGlobals::entityIsAlive(m_pLastEnemy),getHealthPercent()*(getArmorPercent()+0.1)); if ( !hasSomeConditions(CONDITION_SEE_CUR_ENEMY) && hasSomeConditions(CONDITION_SEE_LAST_ENEMY_POS) && m_pLastEnemy && m_fLastSeeEnemy && ((m_fLastSeeEnemy + 10.0) > engine->Time()) && m_pWeapons->hasWeapon(HL2DM_WEAPON_FRAG) ) { float fDistance = distanceFrom(m_vLastSeeEnemyBlastWaypoint); if ( ( fDistance > BLAST_RADIUS ) && ( fDistance < 1500 ) ) { CWeapon *pWeapon = CWeapons::getWeapon(HL2DM_WEAPON_FRAG); CBotWeapon *pBotWeapon = m_pWeapons->getWeapon(pWeapon); ADD_UTILITY(BOT_UTIL_THROW_GRENADE, pBotWeapon && (pBotWeapon->getAmmo(this) > 0) ,1.0f-(getHealthPercent()*0.2)); } } if ( m_pNearbyWeapon.get() ) { pWeapon = CWeapons::getWeapon(m_pNearbyWeapon.get()->GetClassName()); if ( pWeapon && !m_pWeapons->hasWeapon(pWeapon->getID()) ) { ADD_UTILITY(BOT_UTIL_PICKUP_WEAPON, true , 0.6f + pWeapon->getPreference()*0.1f); } } utils.execute(); while ( (next = utils.nextBest()) != NULL ) { if ( !m_pSchedules->isEmpty() && bCheckCurrent ) { if ( m_CurrentUtil != next->getId() ) m_pSchedules->freeMemory(); else break; } bCheckCurrent = false; if ( executeAction(next->getId()) ) { m_CurrentUtil = next->getId(); if ( m_fUtilTimes[next->getId()] < engine->Time() ) m_fUtilTimes[next->getId()] = engine->Time() + randomFloat(0.1f,2.0f); // saves problems with consistent failing if ( CClients::clientsDebugging(BOT_DEBUG_UTIL) ) { CClients::clientDebugMsg(BOT_DEBUG_UTIL,g_szUtils[next->getId()],this); } break; } } utils.freeMemory(); }