void NetworkConstantModel::updateActionsState(double /*now*/, double delta) { NetworkConstantAction *action = nullptr; ActionList *actionSet = getRunningActionSet(); for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end()) ; it != itend ; it=itNext) { ++itNext; action = static_cast<NetworkConstantAction*>(&*it); if (action->latency_ > 0) { if (action->latency_ > delta) { double_update(&(action->latency_), delta, sg_surf_precision); } else { action->latency_ = 0.0; } } action->updateRemains(action->getCost() * delta / action->initialLatency_); if (action->getMaxDuration() != NO_MAX_DURATION) action->updateMaxDuration(delta); if (action->getRemainsNoUpdate() <= 0) { action->finish(); action->setState(Action::State::done); } else if ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)) { action->finish(); action->setState(Action::State::done); } } }
RobotInterface::ActionList RobotInterface::XMLReader::Private::readActionsTag(TiXmlElement *actionsElem) { const std::string &valueStr = actionsElem->ValueStr(); if (valueStr.compare("actions") != 0) { SYNTAX_ERROR(actionsElem->Row()) << "Expected \"actions\". Found" << valueStr; } std::string filename; if (actionsElem->QueryStringAttribute("file", &filename) == TIXML_SUCCESS) { // yDebug() << "Found actions file [" << filename << "]"; #ifdef WIN32 std::replace(filename.begin(), filename.end(), '/', '\\'); filename = path + "\\" + filename; #else // WIN32 filename = path + "/" + filename; #endif //WIN32 return readActionsFile(filename); } std::string robotName; if (actionsElem->QueryStringAttribute("robot", &robotName) != TIXML_SUCCESS) { SYNTAX_WARNING(actionsElem->Row()) << "\"actions\" element should contain the \"robot\" attribute"; } if (robotName != robot.name()) { SYNTAX_WARNING(actionsElem->Row()) << "Trying to import a file for the wrong robot. Found" << robotName << "instead of" << robot.name(); } unsigned int build; #if TINYXML_UNSIGNED_INT_BUG if (actionsElem->QueryUnsignedAttribute("build", &build()) != TIXML_SUCCESS) { // No build attribute. Assuming build="0" SYNTAX_WARNING(actionsElem->Row()) << "\"actions\" element should contain the \"build\" attribute [unsigned int]. Assuming 0"; } #else int tmp; if (actionsElem->QueryIntAttribute("build", &tmp) != TIXML_SUCCESS || tmp < 0) { // No build attribute. Assuming build="0" SYNTAX_WARNING(actionsElem->Row()) << "\"actions\" element should contain the \"build\" attribute [unsigned int]. Assuming 0"; tmp = 0; } build = (unsigned)tmp; #endif if (build != robot.build()) { SYNTAX_WARNING(actionsElem->Row()) << "Import a file for a different robot build. Found" << build << "instead of" << robot.build(); } ActionList actions; for (TiXmlElement* childElem = actionsElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { ActionList childActions = readActions(childElem); for (ActionList::const_iterator it = childActions.begin(); it != childActions.end(); ++it) { actions.push_back(*it); } } return actions; }
void apply_actions(File const & f, ActionList & actions) { auto it = actions.begin(); auto end = actions.end(); for (;it != end; ++it) { (*it)(f); } }
void StorageN11Model::updateActionsState(double /*now*/, double delta) { StorageAction *action = nullptr; ActionList *actionSet = getRunningActionSet(); for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end()) ; it != itend ; it=itNext) { ++itNext; action = static_cast<StorageAction*>(&*it); if(action->m_type == WRITE){ // Update the disk usage // Update the file size // For each action of type write double current_progress = delta * lmm_variable_getvalue(action->getVariable()); long int incr = current_progress; XBT_DEBUG("%s:\n\t progress = %.2f, current_progress = %.2f, incr = %ld, lrint(1) = %ld, lrint(2) = %ld", action->p_file->name, action->progress, current_progress, incr, lrint(action->progress + current_progress), lrint(action->progress)+ incr); /* take care of rounding error accumulation */ if (lrint(action->progress + current_progress) > lrint(action->progress)+ incr) incr++; action->progress +=current_progress; action->p_storage->usedSize_ += incr; // disk usage action->p_file->current_position+= incr; // current_position // which becomes the new file size action->p_file->size = action->p_file->current_position ; sg_size_t *psize = xbt_new(sg_size_t,1); *psize = action->p_file->size; xbt_dict_t content_dict = action->p_storage->content_; xbt_dict_set(content_dict, action->p_file->name, psize, nullptr); } action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta); if (action->getMaxDuration() > NO_MAX_DURATION) action->updateMaxDuration(delta); if(action->getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action->getVariable()) > 0 && action->p_storage->usedSize_ == action->p_storage->size_) { action->finish(); action->setState(Action::State::failed); } else if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) || ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { action->finish(); action->setState(Action::State::done); } } return; }
//ActionCallback World::pushActionCallback(){ void World::pushActionCallback(){ BoundingBox *box = character->getBoundingBox(); EntityList *elist = new EntityList(); int nEntities = currScene->getEntitiesInBox(box, elist); for(EntityList::iterator i=elist->begin(); i!=elist->end(); i++){ ActionList actionList = (*i)->getActionList(); for(ActionList::iterator j = actionList.begin(); j!=actionList.end(); j++){ if((*j)->type == ACTION_PUSH){ (*j)->react(); } } } }
void World::pickupActionCallback(){ EntityList *elist = new EntityList(); BoundingBox *box = character->getFeetBoundingBox(); int nEntities = currScene->getEntitiesInBox(box, elist); for(EntityList::iterator i=elist->begin(); i!=elist->end(); i++){ ActionList actionList = (*i)->getActionList(); for(ActionList::iterator j = actionList.begin(); j!=actionList.end(); j++){ if((*j)->type == ACTION_PICKUP && (*i)->getAttribute(ENTITY_PICKUPABLE)){ (*j)->react(); } } } }
bool CKeyBindings::RemoveCommandFromList(ActionList& al, const std::string& command) { bool success = false; ActionList::iterator it = al.begin(); while (it != al.end()) { if (it->command == command) { it = al.erase(it); success = true; } else { ++it; } } return success; }
double NetworkConstantModel::next_occuring_event(double /*now*/) { NetworkConstantAction *action = nullptr; double min = -1.0; ActionList *actionSet = getRunningActionSet(); for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end()) ; it != itend ; ++it) { action = static_cast<NetworkConstantAction*>(&*it); if (action->latency_ > 0 && (min < 0 || action->latency_ < min)) min = action->latency_; } return min; }
const CKeyBindings::ActionList& CKeyBindings::GetActionList(const CKeySet& ks) const { static const ActionList empty; const ActionList* alPtr = ∅ if (ks.AnyMod()) { KeyMap::const_iterator it = bindings.find(ks); if (it != bindings.end()) { alPtr = &(it->second); } } else { // have to check for an AnyMod keyset as well as the normal one CKeySet anyMod = ks; anyMod.SetAnyBit(); KeyMap::const_iterator nit = bindings.find(ks); KeyMap::const_iterator ait = bindings.find(anyMod); const bool haveNormal = (nit != bindings.end()); const bool haveAnyMod = (ait != bindings.end()); if (haveNormal && !haveAnyMod) { alPtr = &(nit->second); } else if (!haveNormal && haveAnyMod) { alPtr = &(ait->second); } else if (haveNormal && haveAnyMod) { // combine the two lists (normal first) static ActionList merged; //FIXME switch to thread_local when all buildbots are using >=gcc4.7 merged = nit->second; merged.insert(merged.end(), ait->second.begin(), ait->second.end()); alPtr = &merged; } } if (debugEnabled) { LOG("GetActions: hex=0x%02X acii=\"%s\":", ks.Key(), ks.GetString(false).c_str()); if (alPtr != &empty) { int i = 1; for (const auto& a: *alPtr) { LOG(" %i. action=\"%s\" rawline=\"%s\" shortcut=\"%s\"", i++, a.command.c_str(), a.rawline.c_str(), a.boundWith.c_str()); } } else { LOG(" EMPTY"); } } return *alPtr; }
/********* * Model * *********/ void CpuModel::updateActionsStateLazy(double now, double /*delta*/) { CpuAction *action; while ((xbt_heap_size(getActionHeap()) > 0) && (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) { action = static_cast<CpuAction*>(xbt_heap_pop(getActionHeap())); XBT_CDEBUG(surf_kernel, "Something happened to action %p", action); if (TRACE_is_enabled()) { Cpu *cpu = static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0))); TRACE_surf_host_set_utilization(cpu->getName(), action->getCategory(), lmm_variable_getvalue(action->getVariable()), action->getLastUpdate(), now - action->getLastUpdate()); } action->finish(); XBT_CDEBUG(surf_kernel, "Action %p finished", action); /* set the remains to 0 due to precision problems when updating the remaining amount */ action->setRemains(0); action->setState(SURF_ACTION_DONE); action->heapRemove(getActionHeap()); //FIXME: strange call since action was already popped } if (TRACE_is_enabled()) { //defining the last timestamp that we can safely dump to trace file //without losing the event ascending order (considering all CPU's) double smaller = -1; ActionList *actionSet = getRunningActionSet(); for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end()) ; it != itend ; ++it) { action = static_cast<CpuAction*>(&*it); if (smaller < 0) { smaller = action->getLastUpdate(); continue; } if (action->getLastUpdate() < smaller) { smaller = action->getLastUpdate(); } } if (smaller > 0) { TRACE_last_timestamp_to_dump = smaller; } } return; }
double NetworkModel::next_occuring_event_full(double now) { NetworkAction *action = NULL; ActionList *runningActions = surf_network_model->getRunningActionSet(); double minRes; minRes = shareResourcesMaxMin(runningActions, surf_network_model->maxminSystem_, surf_network_model->f_networkSolve); for(ActionList::iterator it(runningActions->begin()), itend(runningActions->end()) ; it != itend ; ++it) { action = static_cast<NetworkAction*>(&*it); if (action->latency_ > 0) { minRes = (minRes < 0) ? action->latency_ : std::min(minRes, action->latency_); } } XBT_DEBUG("Min of share resources %f", minRes); return minRes; }
RobotInterface::Device RobotInterface::XMLReader::Private::readDeviceTag(TiXmlElement *deviceElem) { const std::string &valueStr = deviceElem->ValueStr(); if (valueStr.compare("device") != 0) { SYNTAX_ERROR(deviceElem->Row()) << "Expected \"device\". Found" << valueStr; } Device device; if (deviceElem->QueryStringAttribute("name", &device.name()) != TIXML_SUCCESS) { SYNTAX_ERROR(deviceElem->Row()) << "\"device\" element should contain the \"name\" attribute"; } // yDebug() << "Found device [" << device.name() << "]"; if (deviceElem->QueryStringAttribute("type", &device.type()) != TIXML_SUCCESS) { SYNTAX_ERROR(deviceElem->Row()) << "\"device\" element should contain the \"type\" attribute"; } device.params().push_back(Param("robotName", robot.portprefix().c_str())); for (TiXmlElement* childElem = deviceElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { if (childElem->ValueStr().compare("action") == 0 || childElem->ValueStr().compare("actions") == 0) { ActionList childActions = readActions(childElem); for (ActionList::const_iterator it = childActions.begin(); it != childActions.end(); ++it) { device.actions().push_back(*it); } } else { ParamList childParams = readParams(childElem); for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) { device.params().push_back(*it); } } } // yDebug() << device; return device; }
void LabEngine::doActions(const ActionList &actionList) { ActionList::const_iterator action; for (action = actionList.begin(); action != actionList.end(); ++action) { updateEvents(); if (_quitLab || shouldQuit()) return; switch (action->_actionType) { case kActionPlaySound: _music->loadSoundEffect(action->_messages[0], false, true); break; case kActionPlaySoundNoWait: // only used in scene 7 (street, when teleporting to the surreal maze) _music->loadSoundEffect(action->_messages[0], false, false); break; case kActionPlaySoundLooping: _music->loadSoundEffect(action->_messages[0], true, false); break; case kActionShowDiff: _graphics->readPict(action->_messages[0], true); break; case kActionShowDiffLooping: // used in scene 44 (heart of the labyrinth, minotaur) _graphics->readPict(action->_messages[0], false); break; case kActionLoadDiff: if (!action->_messages[0].empty()) // Puts a file into memory _graphics->loadPict(action->_messages[0]); break; case kActionLoadBitmap: error("Unused opcode kActionLoadBitmap has been called"); case kActionShowBitmap: error("Unused opcode kActionShowBitmap has been called"); case kActionTransition: _graphics->doTransition((TransitionType)action->_param1, action->_messages[0].c_str()); break; case kActionNoUpdate: _noUpdateDiff = true; _anim->_doBlack = false; break; case kActionForceUpdate: _curFileName = " "; break; case kActionShowCurPict: { Common::String test = getPictName(true); if (test != _curFileName) { _curFileName = test; _graphics->readPict(_curFileName); } } break; case kActionSetElement: _conditions->inclElement(action->_param1); break; case kActionUnsetElement: _conditions->exclElement(action->_param1); break; case kActionShowMessage: if (_graphics->_longWinInFront) _graphics->longDrawMessage(action->_messages[0], true); else _graphics->drawMessage(action->_messages[0], true); break; case kActionCShowMessage: if (!_closeDataPtr) _graphics->drawMessage(action->_messages[0], true); break; case kActionShowMessages: _graphics->drawMessage(action->_messages[_utils->getRandom(action->_param1)], true); break; case kActionChangeRoom: if (action->_param1 & 0x8000) { // This is a Wyrmkeep Windows trial version, thus stop at this // point, since we can't check for game payment status _graphics->readPict(getPictName(true)); GUI::MessageDialog trialMessage("This is the end of the trial version. You can play the full game using the original interpreter from Wyrmkeep"); trialMessage.runModal(); break; } _music->checkRoomMusic(_roomNum, action->_param1); _roomNum = action->_param1; _direction = action->_param2 - 1; _closeDataPtr = nullptr; _anim->_doBlack = true; break; case kActionSetCloseup: { Common::Point curPos = Common::Point(_utils->scaleX(action->_param1), _utils->scaleY(action->_param2)); const CloseData *tmpClosePtr = getObject(curPos, _closeDataPtr); if (tmpClosePtr) _closeDataPtr = tmpClosePtr; } break; case kActionMainView: _closeDataPtr = nullptr; break; case kActionSubInv: if (_inventory[action->_param1]._quantity) (_inventory[action->_param1]._quantity)--; if (_inventory[action->_param1]._quantity == 0) _conditions->exclElement(action->_param1); break; case kActionAddInv: (_inventory[action->_param1]._quantity) += action->_param2; _conditions->inclElement(action->_param1); break; case kActionShowDir: _graphics->setActionMessage(false); break; case kActionWaitSecs: { uint32 targetMillis = _system->getMillis() + action->_param1 * 1000; _graphics->screenUpdate(); while (_system->getMillis() < targetMillis) { updateEvents(); if (_quitLab || shouldQuit()) return; _anim->diffNextFrame(); } } break; case kActionStopMusic: // used in scene 44 (heart of the labyrinth, minotaur) _music->freeMusic(); break; case kActionStartMusic: // unused error("Unused opcode kActionStartMusic has been called"); break; case kActionChangeMusic: // used in scene 46 (museum exhibit, for the alarm) _music->changeMusic(action->_messages[0], true, false); break; case kActionResetMusic: // used in scene 45 (sheriff's office, after museum) _music->resetMusic(true); break; case kActionFillMusic: error("Unused opcode kActionFillMusic has been called"); break; case kActionWaitSound: // used in scene 44 (heart of the labyrinth / ending) while (_music->isSoundEffectActive()) { updateEvents(); if (_quitLab || shouldQuit()) return; _anim->diffNextFrame(); waitTOF(); } break; case kActionClearSound: _music->stopSoundEffect(); break; case kActionWinMusic: // used in scene 44 (heart of the labyrinth / ending) _music->freeMusic(); _music->changeMusic("Music:WinGame", false, false); break; case kActionWinGame: // used in scene 44 (heart of the labyrinth / ending) _quitLab = true; showLab2Teaser(); break; case kActionLostGame: error("Unused opcode kActionLostGame has been called"); case kActionResetBuffer: _graphics->freePict(); break; case kActionSpecialCmd: if (action->_param1 == 0) _anim->_doBlack = true; else if (action->_param1 == 1) _anim->_doBlack = (_closeDataPtr == nullptr); else if (action->_param1 == 2) _anim->_doBlack = (_closeDataPtr != nullptr); else if (action->_param1 == 5) { // inverse the palette for (int idx = (8 * 3); idx < (255 * 3); idx++) _anim->_diffPalette[idx] = 255 - _anim->_diffPalette[idx]; waitTOF(); _graphics->setPalette(_anim->_diffPalette, 256); waitTOF(); waitTOF(); } else if (action->_param1 == 4) { // white the palette _graphics->whiteScreen(); waitTOF(); waitTOF(); } else if (action->_param1 == 6) { // Restore the palette waitTOF(); _graphics->setPalette(_anim->_diffPalette, 256); waitTOF(); waitTOF(); } else if (action->_param1 == 7) { // Quick pause waitTOF(); waitTOF(); waitTOF(); } break; } } _music->stopSoundEffect(); }
void Driver::BuildUniversalActions(const ArgList &Args, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building actions for universal build"); // Collect the list of architectures. Duplicates are allowed, but // should only be handled once (in the order seen). llvm::StringSet<> ArchNames; llvm::SmallVector<const char *, 4> Archs; for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { Arg *A = *it; if (A->getOption().getId() == options::OPT_arch) { const char *Name = A->getValue(Args); // FIXME: We need to handle canonicalization of the specified // arch? A->claim(); if (ArchNames.insert(Name)) Archs.push_back(Name); } } // When there is no explicit arch for this platform, make sure we // still bind the architecture (to the default) so that -Xarch_ is // handled correctly. if (!Archs.size()) Archs.push_back(0); // FIXME: We killed off some others but these aren't yet detected in // a functional manner. If we added information to jobs about which // "auxiliary" files they wrote then we could detect the conflict // these cause downstream. if (Archs.size() > 1) { // No recovery needed, the point of this is just to prevent // overwriting the same files. if (const Arg *A = Args.getLastArg(options::OPT_save_temps)) Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) << A->getAsString(Args); } ActionList SingleActions; BuildActions(Args, SingleActions); // Add in arch binding and lipo (if necessary) for every top level // action. for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) { Action *Act = SingleActions[i]; // Make sure we can lipo this kind of output. If not (and it is an // actual output) then we disallow, since we can't create an // output file with the right name without overwriting it. We // could remove this oddity by just changing the output names to // include the arch, which would also fix // -save-temps. Compatibility wins for now. if (Archs.size() > 1 && !types::canLipoType(Act->getType())) Diag(clang::diag::err_drv_invalid_output_with_multiple_archs) << types::getTypeName(Act->getType()); ActionList Inputs; for (unsigned i = 0, e = Archs.size(); i != e; ++i) Inputs.push_back(new BindArchAction(Act, Archs[i])); // Lipo if necessary, We do it this way because we need to set the // arch flag so that -Xarch_ gets overwritten. if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing) Actions.append(Inputs.begin(), Inputs.end()); else Actions.push_back(new LipoJobAction(Inputs, Act->getType())); } }
void add(const ActionList& other) { insert(end(), other.begin(), other.end()); }