/******************************************************************** Declaration: Call: Input: Returns: *********************************************************************/ void CommPort::SetByteSize(const DataBits nDataBits) { getState();// GetCommState(m_hCom, &m_dcb); m_dcb.ByteSize = nDataBits; setState();// SetCommState(m_hCom, &m_dcb); }
bool Creep::isDead() { return FlagUtil::isFlagSet(getState(), SET_TO_REMOVE) || FlagUtil::isFlagSet(getState(), DEAD) || FlagUtil::isFlagSet(getState(), DEPLOYING) || FlagUtil::isFlagSet(getState(), GOAL_REACHED); }
void Animation::logic(){ if (getState().position < frames.size()){ if (frames[getState().position]->time != -1){ getState().ticks += 1; if (getState().ticks >= frames[getState().position]->time){ getState().ticks = 0; getState().virtual_ticks = 0; if (getState().position < frames.size() - 1){ getState().position += 1; } else { if (!playOnce){ getState().position = loopPosition; getState().looped = true; } } } } else { getState().virtual_ticks += 1; } } }
int eDVBFrontendStatus::getBER() const { if (!frontend || getState() == iDVBFrontend_ENUMS::stateTuning) return 0; return frontend->readFrontendData(iFrontendInformation_ENUMS::bitErrorRate); }
Gen() { getState().copy(State); pure_init(); }
ompl::control::ProductGraph::State *ompl::control::ProductGraph::getState(const State *parent, const base::State *cs) const { return getState(parent, decomp_->locateRegion(cs)); }
_string CWebUser::getName() const { _string ret = getState(STATE_NAME); return ret.empty() ? guestName : ret; }
int ProxyConn::processResp() { HttpExtConnector *pHEC = getConnector(); if (!pHEC) { errno = ECONNRESET; return LS_FAIL; } int len = 0; int ret = 0; int &respState = pHEC->getRespState(); if (!(respState & 0xff)) { char *p = HttpResourceManager::getGlobalBuf(); const char *pBuf = p; if (m_iSsl) len = m_ssl.read(p, 1460); else len = ExtConn::read(p, 1460); if (len > 0) { int copy = len; if (m_iRespHeaderRecv + copy > 4095) copy = 4095 - m_iRespHeaderRecv; //memmove( &m_achRespBuf[ m_iRespHeaderRecv ], pBuf, copy ); m_iRespHeaderRecv += copy; m_iRespRecv += len; LS_DBG_L(this, "Read Response %d bytes", len); //debug code //::write( 1, pBuf, len ); ret = pHEC->parseHeader(pBuf, len, 1); switch (ret) { case -2: LS_WARN(this, "Invalid Http response header, retry!"); //debug code //::write( 1, pBuf, len ); errno = ECONNRESET; case -1: return LS_FAIL; } } else return len; if (respState & 0xff) { //debug code //::write(1, HttpResourceManager::getGlobalBuf(), // pBuf - HttpResourceManager::getGlobalBuf() ); HttpReq *pReq = pHEC->getHttpSession()->getReq(); if (pReq->noRespBody()) { incReqProcessed(); if (len > 0) abort(); else if (respState & HEC_RESP_CONN_CLOSE) setState(CLOSING); else if (getState() == ABORT) setState(PROCESSING); setInProcess(0); pHEC->endResponse(0, 0); return 0; } m_iRespBodySize = pHEC->getHttpSession()->getResp()->getContentLen(); LS_DBG_L(this, "Response body size of proxy reply is %d", m_iRespBodySize); if (m_iRespBodySize == LSI_RSP_BODY_SIZE_CHUNKED) setupChunkIS(); else if (!(respState & HEC_RESP_CONT_LEN)) m_iRespBodySize = INT_MAX; m_pBufBegin = pBuf; m_pBufEnd = pBuf + len; LS_DBG_M(this, "Process Response body %d bytes", len); return readRespBody(); } } else return readRespBody(); return 0; }
int ProxyConn::readRespBody() { HttpExtConnector *pHEC = getConnector(); int ret = 0; size_t bufLen; if (!pHEC) return LS_FAIL; if (m_pChunkIS) { while (getState() != ABORT && !m_pChunkIS->eos()) { char *pBuf = pHEC->getRespBuf(bufLen); if (!pBuf) return LS_FAIL; ret = m_pChunkIS->read(pBuf, bufLen); if (ret >= 0) { if (ret > 0) { m_lLastRespRecvTime = time(NULL); m_iRespBodyRecv += ret; int ret1 = pHEC->processRespBodyData(pBuf, ret); if (ret1 == -1) ret = LS_FAIL; if (ret > 1024 || (ret < (int)bufLen)) pHEC->flushResp(); } if (m_pChunkIS->eos()) { ret = 0; break; } pHEC->flushResp(); return ret; } else { if ((errno == ECONNRESET) && (getConnector())) break; return LS_FAIL; } } } else { while ((getState() != ABORT) && (m_iRespBodySize - m_iRespBodyRecv > 0)) { char *pBuf = pHEC->getRespBuf(bufLen); if (!pBuf) return LS_FAIL; int64_t toRead = m_iRespBodySize - m_iRespBodyRecv; if (toRead > (int64_t)bufLen) toRead = bufLen ; ret = read(pBuf, toRead); if (ret > 0) { m_iRespBodyRecv += ret; pHEC->processRespBodyData(pBuf, ret); if (ret > 1024) pHEC->flushResp(); //if ( ret1 ) // return ret1; if (m_iRespBodySize - m_iRespBodyRecv <= 0) break; if (ret < (int)toRead) { pHEC->flushResp(); return 0; } } else { if (ret) { if ((errno == ECONNRESET) && (getConnector())) break; } return ret; } } } incReqProcessed(); if (pHEC->getRespState() & HEC_RESP_CONN_CLOSE) setState(CLOSING); setInProcess(0); pHEC->endResponse(0, 0); return ret; }
c_WaitableWaitHandle* c_GenMapWaitHandle::getChild() { assert(getState() == STATE_BLOCKED); return static_cast<c_WaitableWaitHandle*>( m_deps->iter_value(m_iterPos)->m_data.pobj); }
void loop(){ api.getMyZRState(me); game.getItemLoc(target, 0); state = getState(target, me); switch (state) { case SPS: switch (game.getNumSPSHeld()) { case 3: game.dropSPS(); origin[0] = 0.5f; origin[1] = 0.0f; origin[2] = 0.0f; break; case 2: api.setPositionTarget(origin); if (distance(origin, me) <= .05) { game.dropSPS(); origin[0] = 0.0f; origin[1] = 0.68f; origin[2] = 0.0f; } break; case 1: api.setPositionTarget(origin); if (distance(origin, me) <= .05) game.dropSPS(); break; } break; case GET_ITEM: //Find vector between bot and item mathVecSubtract(holder, target, me, 3); //magnitude of previous vector mag = mathVecMagnitude(holder, 3); //Face towards the item api.setAttitudeTarget(holder); //DEBUG(("Dist: %f", distance(target, me))); DEBUG(("Dist: %f", mag)); //Scale down the vector so the endpoint is .170 units away from the item //scaleVect(holder, mag, 0.170f); //adjustGoal(holder, 0.170f); adjustGoal(target, 0.170f); //If in proximity /*if (mag <= .17 && mag >= .15) { DEBUG(("Stay")); api.setPositionTarget(me); game.dockItem(); }*/ if (distance(target, me) <= .17 && distance(target, me) >= .15) { DEBUG(("Stay")); DEBUG(("Close: %f", mag)); api.setPositionTarget(me); game.dockItem(); } //else if (mag <= .2 && mag > .17) { //api.setPositionTarget(target); //} else { //Full speed ahead //api.setVelocityTarget(holder); moveTo(holder); } break; case STAY: DEBUG(("Staying")); api.setPositionTarget(me); break; case FIND_ASSEMBLY: DEBUG(("Find Assembly")); //if (isFound) { if (game.getZone(myZone)) { DEBUG(("%f, %f, %f, %f", myZone[0], myZone[1], myZone[2], myZone[3])); } mathVecSubtract(holder, me, myZone, 3); //isFound = false; //} //move to and point to the estimated zone api.setPositionTarget(myZone); scaleVect(holder, 1.0f, -1.0f); api.setAttitudeTarget(holder); if (mathVecMagnitude(holder, 3) <= .17) { DEBUG(("Gottem")); api.setPositionTarget(me); game.dropItem(); } break; case GET_CENTER: break; } }
void BooleanPropertyComponent::buttonClicked (Button*) { setState (! getState()); }
void BooleanPropertyComponent::refresh() { button.setToggleState (getState(), false); button.setButtonText (button.getToggleState() ? onText : offText); }
void cube::shiftCube( char direction, bool orientation ) { /* * shifts the contents of the cube in the given direction. out-of-bound locations * will be ignored and set to 'off' */ cube *tmpCube = new cube; tmpCube->allOff(); signed short int modifier; if(orientation == 1) { modifier = 1; } else { modifier = -1; } byte t_x, t_y, t_z; for(byte i_x = 1; i_x <= 4; i_x++ ) { for(byte i_y = 1; i_y <= 4; i_y++ ) { for(byte i_z = 1; i_z <= 4; i_z++ ) { if( getState( i_x, i_y, i_z ) == 1 ) { switch(direction) { case 'x': t_x = i_x + modifier; if( t_x <= 0 || t_x > 4 ){ continue; } t_y = i_y; t_z = i_z; break; case 'y': t_x = i_x; t_y = i_y + modifier; if( t_y <= 0 || t_y > 4 ){ continue; } t_z = i_z; break; case 'z': t_x = i_x; t_y = i_y; t_z = i_z + modifier; if( t_z <= 0 || t_z > 4 ){ continue; } break; default: continue; break; } tmpCube->setState( t_x, t_y, t_z, 1 ); } } } } importData( tmpCube->_cube_state ); delete tmpCube; }
void ompl::control::ProductGraph::buildGraph(State *start, const std::function<void(State *)> &initialize) { graph_.clear(); solutionStates_.clear(); std::queue<State *> q; std::unordered_set<State *> processed; std::vector<int> regNeighbors; VertexIndexMap index = get(boost::vertex_index, graph_); GraphType::vertex_descriptor next = boost::add_vertex(graph_); startState_ = start; graph_[boost::vertex(next, graph_)] = startState_; stateToIndex_[startState_] = index[next]; q.push(startState_); processed.insert(startState_); OMPL_INFORM("Building graph from start state (%u,%u,%u) with index %d", startState_->decompRegion, startState_->cosafeState, startState_->safeState, stateToIndex_[startState_]); while (!q.empty()) { State *current = q.front(); // Initialize each state using the supplied state initializer function initialize(current); q.pop(); if (safety_->isAccepting(current->safeState) && cosafety_->isAccepting(current->cosafeState)) { solutionStates_.push_back(current); } GraphType::vertex_descriptor v = boost::vertex(stateToIndex_[current], graph_); // enqueue each neighbor of current decomp_->getNeighbors(current->decompRegion, regNeighbors); for (const auto &r : regNeighbors) { State *nextState = getState(current, r); if (!nextState->isValid()) continue; // if this state is newly discovered, // then we can dynamically allocate a copy of it // and add the new pointer to the graph. // either way, we need the pointer if (processed.find(nextState) == processed.end()) { const GraphType::vertex_descriptor next = boost::add_vertex(graph_); stateToIndex_[nextState] = index[next]; graph_[boost::vertex(next, graph_)] = nextState; q.push(nextState); processed.insert(nextState); } // whether or not the neighbor is newly discovered, // we still need to add the edge to the graph GraphType::edge_descriptor edge; bool ignore; boost::tie(edge, ignore) = boost::add_edge(v, boost::vertex(stateToIndex_[nextState], graph_), graph_); // graph_[edge].src = index[v]; // graph_[edge].dest = stateToIndex_[nextState]; } regNeighbors.clear(); } if (solutionStates_.empty()) { OMPL_ERROR("No solution path found in product graph."); } OMPL_INFORM("Number of decomposition regions: %u", decomp_->getNumRegions()); OMPL_INFORM("Number of cosafety automaton states: %u", cosafety_->numStates()); OMPL_INFORM("Number of safety automaton states: %u", safety_->numStates()); OMPL_INFORM("Number of high-level states in abstraction graph: %u", boost::num_vertices(graph_)); }
void EspNewIncomingConnectionStream::actOnReceive(IpcConnection *connection) { // check for OS errors if (getState() == ERROR_STATE) { ex_assert(FALSE,"Error while receiving first message from client"); } // check for protocol errors bool willPassTheAssertion = (getType() == IPC_MSG_SQLESP_DATA_REQUEST OR getType() == IPC_MSG_SQLESP_CANCEL_REQUEST) AND getVersion() == CurrEspRequestMessageVersion AND moreObjects(); if (!willPassTheAssertion) { char *doCatchBugCRx = getenv("ESP_BUGCATCHER_CR_NONUMBER"); if (!doCatchBugCRx || *doCatchBugCRx != '0') { connection->dumpAndStopOtherEnd(true, false); environment_->getControlConnection()-> castToGuaReceiveControlConnection()-> getConnection()->dumpAndStopOtherEnd(true, false); } } ex_assert((getType() == IPC_MSG_SQLESP_DATA_REQUEST OR getType() == IPC_MSG_SQLESP_CANCEL_REQUEST) AND getVersion() == CurrEspRequestMessageVersion AND moreObjects(), "Invalid first message from client"); // take a look at the type of the first object in the message IpcMessageObjType nextObjType = getNextObjType(); switch (nextObjType) { case ESP_OPEN_HDR: case ESP_LATE_CANCEL_HDR: { ExFragKey key; Lng32 remoteInstNum; NABoolean isParallelExtract = false; // peek at the message header to see for whom it is if (nextObjType == ESP_OPEN_HDR) { ExEspOpenReqHeader reqHdr((NAMemory *) NULL); *this >> reqHdr; key = reqHdr.key_; remoteInstNum = reqHdr.myInstanceNum_; if (reqHdr.getOpenType() == ExEspOpenReqHeader::PARALLEL_EXTRACT) { isParallelExtract = true; } } else { // note that the late cancel request may or may not // arrive as the first request (only in the former case // will we reach here) ExEspLateCancelReqHeader reqHdr((NAMemory *) NULL); *this >> reqHdr; key = reqHdr.key_; remoteInstNum = reqHdr.myInstanceNum_; } if (!isParallelExtract) { ExFragInstanceHandle handle = espFragInstanceDir_->findHandle(key); if (handle != NullFragInstanceHandle) { // the send bottom node # myInstanceNum of this downloaded fragment // is the true recipient of this open request ex_split_bottom_tcb * receivingTcb = espFragInstanceDir_->getTopTcb(handle); ex_send_bottom_tcb *receivingSendTcb = receivingTcb->getSendNode(remoteInstNum); // Check the connection for a co-located client, and if so, // tell the split bottom, because it may prefer this send // bottom when using skew buster uniform distribution. if (espFragInstanceDir_-> getEnvironment()-> getMyOwnProcessId(IPC_DOM_GUA_PHANDLE).match( connection->getOtherEnd().getNodeName(), connection->getOtherEnd().getCpuNum())) receivingTcb->setLocalSendBottom(remoteInstNum); // Portability note for the code above: we pass IPC_DOM_GUA_PHANDLE // for IpcEnvironment::getMyOwnProcessId, even though that method // can be called with the default param (IpcNetworkDomain // IPC_DOM_INVALID). In fact it would probably be better // to call the object without specifying the IpcNetworkDomain so // that it can decide for itself what domain it is using. // But there is a problem with the Windows implementation // of IpcEnvironment::getMyOwnProcessId, it seems to assume // that its domain is IPC_DOM_INTERNET and so this will // cause the botch of an assertion that its control connection // (which is type EspGuaControlConnection) can be cast to a // SockControlConnection. When this problem is fixed, the // IPC_DOM_GUA_PHANDLE param above can be removed. Also, // when this code is ported to run it a domain other than // "guardian", it will be necessary to fix this and to // fix IpcEnvironment::getMyOwnProcessId to work properly on // windows. receivingSendTcb->setClient(connection); receivingSendTcb->routeMsg(*this); } else { connection->dumpAndStopOtherEnd(true, false); ex_assert(FALSE,"entry not found, set diagnostics area and reply"); } } // normal case, not parallel extract else { // The OPEN request is from a parallel extract consumer. The // incoming request contains a user ID which we will compare // against the current user ID for this ESP. // NOTE: The user ID for the extract security check is // currently sent and compared as a C string. On Linux it is // possible to send and compare integers which would lead to // simpler code. The code to send/compare strings is still // used because it works on all platforms. char errorStr[150]; // check if next msg is of securityInfo type. ex_assert(moreObjects(), "expected object not received"); ex_assert(getNextObjType() == ESP_SECURITY_INFO, "received message for unknown message type"); // unpack security info ExMsgSecurityInfo secInfo(environment_->getHeap()); *this >> secInfo; // Get the auth ID of this ESP in text form and compare it // to the auth ID that arrived in the message. Skip this // step in the debug build if an environment variable is // set. NABoolean doAuthIdCheck = TRUE; Int32 status = 0; #ifdef NA_DEBUG_C_RUNTIME const char *envvar = getenv("NO_EXTRACT_AUTHID_CHECK"); if (envvar && envvar[0]) doAuthIdCheck = FALSE; #endif if (doAuthIdCheck) { // Get user ID from ExMsgSecurityInfo -> (secUserID) // the user ID is the integer value made into a string // Convert it back into its integer value short userIDLen = (short) str_len(secInfo.getAuthID()); Int32 secUserID = str_atoi(secInfo.getAuthID(), userIDLen); // Get the current user ID Int32 curUserID = ComUser::getSessionUser(); // Report an error if the user ID is not valid if (curUserID == NA_UserIdDefault || secUserID == NA_UserIdDefault) { str_cpy_c(errorStr, "Producer ESP could not authenticate the consumer, " "no valid current user."); status = -1; } // Make sure user id passed in ExMsgSecurityInfo matches // the user id associated with the current session #if defined(NA_DEBUG_C_RUNTIME) NABoolean doDebug = (getenv("DBUSER_DEBUG") ? TRUE : FALSE); if (doDebug) printf("[DBUSER:%d] ESP extract user ID: " "local [%d], msg [%d]\n", (int) getpid(), curUserID, secUserID); #endif // Compare user ID, Report an error, if comparison fails if (curUserID != secUserID) { str_cpy_c(errorStr, "Producer ESP could not authenticate the consumer, " "user named passed in ExMsgSecurityInfo is not the " "current user"); status = -1; } } // if (doAuthIdCheck) // get the split bottom TCB that matches the securityKey ex_split_bottom_tcb *receivingTcb = NULL; if (status == 0) { receivingTcb = espFragInstanceDir_->getExtractTop(secInfo.getSecurityKey()); if (receivingTcb == NULL) { str_cpy_c(errorStr, "Producer ESP could not locate extract node"); status = -1; } } // get the sendBottom TCB if not already connected to a client ex_send_bottom_tcb *receivingSendTcb = NULL; if (status == 0) { receivingSendTcb = receivingTcb->getConsumerSendBottom(); if (receivingSendTcb == NULL) { str_cpy_c(errorStr, "Producer ESP already connected to a client"); status = -1; } } // send the error message to the consumer if (status != 0) { clearAllObjects(); setType(IPC_MSG_SQLESP_DATA_REPLY); NAMemory *heap = environment_->getHeap(); IpcMessageObj* baseObj = new(heap)IpcMessageObj(IPC_SQL_DIAG_AREA, CurrEspReplyMessageVersion); *this << *baseObj; // prepare proper error message char phandle[100]; MyGuaProcessHandle myHandle; myHandle.toAscii(phandle, 100); ComDiagsArea *diags = ComDiagsArea::allocate(heap); *diags << DgSqlCode(-EXE_PARALLEL_EXTRACT_OPEN_ERROR) << DgString0(phandle) << DgString1(errorStr); *this << *diags; diags->decrRefCount(); send(TRUE /* TRUE indicates waited */); } // if everything okay, then make the connection if (status == 0) { receivingSendTcb->setClient(connection); receivingSendTcb->routeMsg(*this); } } // parallel extract case } // open or cancel header
ompl::control::ProductGraph::State *ompl::control::ProductGraph::getState(const base::State *cs) const { return getState(cs, cosafety_->getStartState(), safety_->getStartState()); }
void Client::manage(Boolean mapped) { Boolean shouldHide, reshape; XWMHints *hints; Display *d = display(); long mSize; int state; XSelectInput(d, m_window, ColormapChangeMask | EnterWindowMask | PropertyChangeMask | FocusChangeMask); m_iconName = getProperty(XA_WM_ICON_NAME); m_name = getProperty(XA_WM_NAME); setLabel(); getColormaps(); getProtocols(); getTransient(); hints = XGetWMHints(d, m_window); if (!getState(&state)) { state = hints ? hints->initial_state : NormalState; } shouldHide = (state == IconicState); if (hints) XFree(hints); if (XGetWMNormalHints(d, m_window, &m_sizeHints, &mSize) == 0 || m_sizeHints.flags == 0) { m_sizeHints.flags = PSize; } m_fixedSize = False; // if ((m_sizeHints.flags & (USSize | PSize))) m_fixedSize = True; if ((m_sizeHints.flags & (PMinSize | PMaxSize)) == (PMinSize | PMaxSize) && (m_sizeHints.min_width == m_sizeHints.max_width && m_sizeHints.min_height == m_sizeHints.max_height)) m_fixedSize = True; reshape = !mapped; if (m_fixedSize) { if ((m_sizeHints.flags & USPosition)) reshape = False; if ((m_sizeHints.flags & PPosition) && shouldHide) reshape = False; if ((m_transient != None)) reshape = False; } if ((m_sizeHints.flags & PBaseSize)) { m_minWidth = m_sizeHints.base_width; m_minHeight = m_sizeHints.base_height; } else if ((m_sizeHints.flags & PMinSize)) { m_minWidth = m_sizeHints.min_width; m_minHeight = m_sizeHints.min_height; } else { m_minWidth = m_minHeight = 50; } // act gravitate(False); // zeros are iffy, should be calling some Manager method int dw = DisplayWidth(display(), 0), dh = DisplayHeight(display(), 0); if (m_w < m_minWidth) { m_w = m_minWidth; m_fixedSize = False; reshape = True; } if (m_h < m_minHeight) { m_h = m_minHeight; m_fixedSize = False; reshape = True; } if (m_w > dw - 8) m_w = dw - 8; if (m_h > dh - 8) m_h = dh - 8; if (m_x > dw - m_border->xIndent()) { m_x = dw - m_border->xIndent(); } if (m_y > dh - m_border->yIndent()) { m_y = dh - m_border->yIndent(); } if (m_x < m_border->xIndent()) m_x = m_border->xIndent(); if (m_y < m_border->yIndent()) m_y = m_border->yIndent(); m_border->configure(m_x, m_y, m_w, m_h, 0L, Above); if (mapped) m_reparenting = True; if (reshape && !m_fixedSize) XResizeWindow(d, m_window, m_w, m_h); XSetWindowBorderWidth(d, m_window, 0); m_border->reparent(); // (support for shaped windows absent) XAddToSaveSet(d, m_window); m_managed = True; if (shouldHide) hide(); else { XMapWindow(d, m_window); m_border->map(); setState(NormalState); if (CONFIG_CLICK_TO_FOCUS || (m_transient != None && activeClient() && activeClient()->m_window == m_transient)) { activate(); mapRaised(); } else { deactivate(); } } if (activeClient() && !isActive()) { activeClient()->installColormap(); } if (CONFIG_AUTO_RAISE) { m_windowManager->stopConsideringFocus(); focusIfAppropriate(False); } }
string CWebUser::getUserId() const { return _to_utf8(getState(STATE_ID)); }
// Save current info to BusinessInfo.txt void BusinessInfo::saveBusinessInfo() { string delimiter = ","; fstream outfile; outfile.open("BusinessInfo.txt", ios::out); outfile << getName() << delimiter << getAddress() << delimiter << getCity() << delimiter << getState() << delimiter << getZipCode() << delimiter << getSalesTax() << delimiter; outfile.close(); }
bool CWebUser::getIsGuest() const { return getState(STATE_ID).empty(); }
/******************************************************* 设置当前状态 ********************************************************/ void CAutoDownload::setState(AUTODOWN_STATE state) { CAutoDownload::AUTODOWN_IMPL* pImpl = getImpl(); if(pImpl->m_hCallbackWnd && pImpl->m_state != state) { pImpl->m_state = state; ::SendMessage(pImpl->m_hCallbackWnd, CAutoDownload::AM_STATUSUPDATE, pImpl->m_nOwnerID, getState()); } else { pImpl->m_state = state; } }
int eDVBFrontendStatus::getSignalPower() const { if (!frontend || getState() == iDVBFrontend_ENUMS::stateTuning) return 0; return frontend->readFrontendData(iFrontendInformation_ENUMS::signalPower); }
void Updatable::loop() { struct timeval last; struct timeval start; struct timeval profile; // last time a profile update happened Usec sleep_time; Usec offset; // This call determines the time it takes for a gettimeofday call // This makes the calls more accurate gettimeofday(&last, NULL); gettimeofday(&start, NULL); offset = timeval_diff(&start, &last); // Get time of day for profiling gettimeofday(&profile, NULL); m_profileCount = 0; // Zero last so we can check last.tv_usec = 0; while (1) { // Grab current time gettimeofday(&start, NULL); // Grab our running state bool in_background = false; int interval = 10; getState(in_background, interval); // Change thread state if needed { boost::mutex::scoped_lock lock(m_upStateMutex); if (m_settingChange & PRIORITY) setThreadPriority(); if (m_settingChange & AFFINITY) setThreadAffinity(); m_settingChange = 0; } if (in_background) { // On the first loop through, set the step to ideal double diff = (double)(interval *(double)1000); if (0 != last.tv_usec) diff = (double)(timeval_diff(&start, &last) + offset); // Record time for next run last = start; // Call our update function update(diff / (double)1000000); m_profileCount += 1; Usec profile_time = timeval_diff(&last, &profile); // If 1 second has passed since the last profile, publish and reset if (profile_time > 1000000) { if (m_publisher) { IntEventPtr event(new IntEvent()); event->data = m_profileCount; m_publisher->publish(IUpdatable::PROFILE, event); } profile = last; m_profileCount = 0; } // Only sleep if we aren't running all out if (interval > 0) { // Determine next time to awake struct timeval next = start; timeval_add(&next, (Usec)interval * USEC_PER_MILLISEC); // Sleep for the rest for the remainder of our time sleep_time = -age(&next); // Handle overrun if (sleep_time < 0) sleep_time = interval * USEC_PER_MILLISEC; // If the wait ends early keep waiting while(sleep_time > SLEEP_THRESHOLD) { waitForUpdate((long)sleep_time); sleep_time = -age(&next); } } } // Time to quit else { break; } } // Release an threads waiting on m_threadStopped.countDown(); }
c_WaitableWaitHandle* c_AwaitAllWaitHandle::getChild() { assert(getState() == STATE_BLOCKED); assert(m_unfinished < m_cap); return m_children[m_unfinished].m_child; }
void ScummEngine_v4::o4_ifNotState() { int a = getVarOrDirectWord(PARAM_1); int b = getVarOrDirectByte(PARAM_2); jumpRelative(getState(a) != b); }
void Animation::virtualTick(){ getState().virtual_ticks += 1; }
void MWWorld::ContainerStore::readState (const ESM::InventoryState& inventory) { clear(); int index = 0; for (std::vector<ESM::ObjectState>::const_iterator iter (inventory.mItems.begin()); iter!=inventory.mItems.end(); ++iter) { const ESM::ObjectState& state = *iter; int type = MWBase::Environment::get().getWorld()->getStore().find(state.mRef.mRefID); int thisIndex = index++; switch (type) { case ESM::REC_ALCH: getState (potions, state); break; case ESM::REC_APPA: getState (appas, state); break; case ESM::REC_ARMO: readEquipmentState (getState (armors, state), thisIndex, inventory); break; case ESM::REC_BOOK: readEquipmentState (getState (books, state), thisIndex, inventory); break; // not equipable as such, but for selectedEnchantItem case ESM::REC_CLOT: readEquipmentState (getState (clothes, state), thisIndex, inventory); break; case ESM::REC_INGR: getState (ingreds, state); break; case ESM::REC_LOCK: readEquipmentState (getState (lockpicks, state), thisIndex, inventory); break; case ESM::REC_MISC: getState (miscItems, state); break; case ESM::REC_PROB: readEquipmentState (getState (probes, state), thisIndex, inventory); break; case ESM::REC_REPA: getState (repairs, state); break; case ESM::REC_WEAP: readEquipmentState (getState (weapons, state), thisIndex, inventory); break; case ESM::REC_LIGH: readEquipmentState (getState (lights, state), thisIndex, inventory); break; case 0: std::cerr << "Dropping reference to '" << state.mRef.mRefID << "' (object no longer exists)" << std::endl; break; default: std::cerr << "Invalid item type in inventory state, refid " << state.mRef.mRefID << std::endl; break; } } mLevelledItemMap = inventory.mLevelledItemMap; }
c_WaitableWaitHandle* c_ConditionWaitHandle::getChild() { assert(getState() == STATE_BLOCKED); return m_child; }
void ScummEngine_v2::o2_clearState08() { int obj = getActiveObject(); putState(obj, getState(obj) & ~kObjectState_08); markObjectRectAsDirty(obj); clearDrawObjectQueue(); }