/** * while (true) { // main game loop * // ... * * for (each gameObject) { * gameObject.PreAnimUpdate(dt); * } * * g_animationEngine.CalculateIntermediatePoses(dt); * * for (each gameObject) { * gameObject.PostAnimUpdate(dt); * } * * g_ragdollSystem.ApplySkeletonsToRagDolls(); * * g_physicsEngine.Simulate(dt); // runs ragdolls too * * g_collisionEngine.DetectAndResolveCollisions(dt); * * g_ragdollSystem.ApplyRagDollsToSkeletons(); * * g_animationEngine.FinalizePoseAndMatrixPalette(); * * for (each gameObject) { * gameObject.FinalUpdate(dt); * } * } */ void Application::run(Game& game) { createApplication(); double time = 1.0 / 60.0; clock.start(- time * 1000000.0); running = true; game.create(*this); while(running) { if(!processMessages()) break; clock.tick(); GameTime gameTime(clock.getElapsedTimeInMicroSec(), clock.getFps()); eventManager->updateEvents(); controllerManager->update(gameTime); game.update(gameTime); game.render(); swapBuffers(); } game.destroy(); destroyApplication(); }
SceneManager::SceneManager( DeviceManager* settings, DynamicUIManager* dynamicUImanager ) : m_devices(settings),m_gameIsRunning(true), m_nextScene(LOGIN), m_currentScene(NULL),m_needsRedraw(true),m_frameRate(60.0f), m_dynamicUI(dynamicUImanager), m_currentSceneType(NO_SCENE), m_needsResize(false),m_newScreenHeight(0),m_newScreenWidth(0), m_transitioning(false),m_transitionOpacity(1.0f),m_transitionRate(0.05f), m_needsTransition(false), m_canDraw(true),m_accelX(0.0f),m_accelY(0.0f),m_accelZ(0.0f), m_needFirstRender(true), m_callOnNextLogic(false), m_guiImageManager("res/gui/gui_image_mapping.conf","res/gui/"),m_nextLogicFrames(0),m_wasSignedIn(false), m_appResumed(false),m_bgexecWasHalted(false),m_bgExecing(false),m_bgTime(0.0f) { #ifdef CGE_IPHONE m_keyMan = new KeyboardMediator(); m_keyMan->showKeyboard(); m_keyMan->hideKeyboard(); #endif queue = al_create_event_queue(); m_gameTimer = al_create_timer(1.0 / m_frameRate); registerEventSources(); //Instance the first scene processMessages(); Log::write("Scene Manager","Scene Manager Started"); if(!Platf::isMobile()) m_g.setBuffering(settings->getDisplay()->getMaxTextureSize() >= 2048); else m_g.setBuffering(false); }
void Seq::process(unsigned n, short* p) { unsigned frames = n; processMessages(); if (state == TRANSPORT_PLAY) { unsigned framePos = 0; int endTime = playTime + frames; for (; playPos != events.constEnd(); ++playPos) { int f = cs->utick2utime(playPos.key()) * MScore::sampleRate; if (f >= endTime) break; int n = f - playTime; if (n) { synti->process(n, p); p += 2 * n; playTime += n; frames -= n; framePos += n; } playEvent(playPos.value()); } if (frames) { synti->process(frames, p); playTime += frames; } if (playPos == events.constEnd()) { driver->stopTransport(); seek(0); state = TRANSPORT_STOP; } } else { synti->process(frames, p); } }
int main(int argc, const char *argv[]) { text[0] = '\0'; if (argc == 2) { if (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0) { help(argv[0]); return EXIT_SUCCESS; } else if (strcmp("-t", argv[1]) == 0) { text[0] = '1'; } else { int sock = initClient(); sendMessage(sock, argv[1]); close(sock); return EXIT_SUCCESS; } } else if (argc > 2) { help(argv[0]); return EXIT_FAILURE; } int sock = initServer(); pid_t pid = fork(); if (pid == 0) processMessages(sock); close(sock); return pid >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
void Downloader::processFtpDirs() { if(ftpDirsProcessed()) return; openInternet(); if(!ftpDirs.empty()) { updateStatus(msg("Getting file information...")); processMessages(); for(list<FtpDir *>::iterator i = ftpDirs.begin(); i != ftpDirs.end(); i++) { FtpDir *f = *i; if(f->processed) continue; if(f->selected(components)) { if(scanFtpDir(f)) f->processed = true; } } } if(ftpDirsProcessed()) clearFtpDirs(); }
QJsonPipe::QJsonPipe(QObject *parent) : QObject(parent) , d_ptr(new QJsonPipePrivate()) { Q_D(QJsonPipe); d->mInBuffer = new QJsonBuffer(this); connect(d->mInBuffer, SIGNAL(readyReadMessage()), SLOT(processMessages())); }
void PosixIBClient::onProcessMessages() { while (isConnected()) { processMessages(); } }
void GameLoader::updateSystems(int counterdiff) { if (g_fp->_currentScene) { g_fp->_currentScene->update(counterdiff); _exCommand._messageKind = 17; _updateCounter++; _exCommand._messageNum = 33; _exCommand._excFlags = 0; _exCommand.postMessage(); } processMessages(); if (_preloadSceneId) { processMessages(); preloadScene(_preloadSceneId, _preloadEntranceId); } }
Receiver::Receiver(QHostAddress address, quint16 port, QObject * parent) : QObject(parent), socket(this) { if (!socket.bind(address, port)) { fprintf(stderr, "bind failed\n"); } connect(&socket, SIGNAL(readyRead()), this, SLOT(processMessages())); }
/*! Send a message to the Synchronization application which will cause a qcop message to be sent via the "qcop bridge". This code taken from sendMessage(...) in src/qtopiadesktop/server. */ void DeviceConnector::sendQcop( const QString &channel, const QString &message, const QByteArray &data ) { MessageRecord *msg = new MessageRecord(); msg->channel = channel; msg->message = message; msg->data = data; msg->state = NoMessage; messageQueue.append( msg ); QTimer::singleShot( 0, this, SLOT(processMessages()) ); }
// perform external and internal message processing, and post handling tasks for each handler void MessageQueue::tick () { // convert incoming messages to VAST or socket messages first _net->process (); // process incoming (external) messages first and flushing out the messages processMessages (); // perform post handleMessage tasks for each handler map<id_t, MessageHandler *>::iterator it; for (it = _handlers.begin (); it != _handlers.end (); it++) it->second->postHandling (); _net->flush (); // process once more for internal messages (targeted at self) // (e.g., to reflect proper neighbor list for Clients) processMessages (); }
void CurlStreamFile::fillCacheNonBlocking(){ if(!_running){ return ; } CURLMcode mcode; do{ mcode = curl_multi_perform(_mCurlHandle, &_running); }while(mcode == CURLM_CALL_MULTI_PERFORM); if(mcode != CURLM_OK){ throw SnailException(curl_multi_strerror(mcode)); } processMessages(); }
void Network::runTick() { if (state != Running) { return; } // TODO: consider the balance between scheduling and messaging (bounded-buffer problem) // Deliver messages processMessages(); // Schedule distributePacket(Packet(MsgTick), -1); }
void Network::runTick() { // TODO: consider the balance between scheduling and messaging (bounded-buffer problem) // Deliver messages processMessages(); // Schedule for (int i=0; i<MAX_NODES; i++) { Component *t = nodes[i]; if (t) { t->process(Packet(MsgTick), -1); } } }
void RosoutPanel::onProcessTimer(wxTimerEvent& evt) { callback_queue_.callAvailable(ros::WallDuration()); processMessages(); refilter_timer_ += 0.25f; if (needs_refilter_ && refilter_timer_ > 0.5f) { refilter_timer_ = 0.0f; needs_refilter_ = false; refilter(); } //PRINT_STUFF("onProcessTimer"); }
void StereoImageDisplayBase::incomingMessages( const sensor_msgs::Image::ConstPtr& left_msg, const sensor_msgs::Image::ConstPtr& right_msg) { if (!left_msg || !right_msg || context_->getFrameManager()->getPause() ) { return; } ++messages_received_; setStatus(StatusProperty::Ok, "Image", QString::number(messages_received_) + " images received"); emitTimeSignal( left_msg->header.stamp ); processMessages(left_msg, right_msg); }
bool Window::popMessage( InputMessage& message ) { // if there are no messages in the queue, check for new ones if ( _messages.empty( ) ) { processMessages( ); } // if there are messages, pop a next message if ( !_messages.empty( ) ) { message = _messages.front( ); _messages.pop( ); return true; } return false; }
// Processes the next frame interval's worth of media for the flow graph. // For now, this method always returns success. OsStatus MpFlowGraphBase::processNextFrame(void) { UtlBoolean boolRes; int i; OsStatus res; // Call processMessages() to handle any messages that have been posted // to either resources in the flow graph or to the flow graph itself. res = processMessages(); assert(res == OS_SUCCESS); // If resources or links have been added/removed from the flow graph, // then we need to recompute the execution order for resources in the // flow graph. This is done to ensure that resources producing output // buffers are executed before other resources in the flow graph that // expect to consume those buffers. if (mRecomputeOrder) { res = computeOrder(); assert(res == OS_SUCCESS); } // If the flow graph is "STOPPED" then there is no further processing // required for this frame interval. However, if the flow graph is // "STARTED", we invoke the processFrame() method for each of the // resources in the flow graph. if (getState() == STARTED) { for (i=0; i < mResourceCnt; i++) { mpResourceInProcess = mExecOrder[i]; boolRes = mExecOrder[i]->processFrame(); if (!boolRes) { osPrintf("MpMedia: called %s, which indicated failure\n", mpResourceInProcess->mName.data()); } } } mpResourceInProcess = NULL; mPeriodCnt++; return OS_SUCCESS; }
//------------------------------------------------------------------------ int TUIMainWindow::openServer() //------------------------------------------------------------------------ { delete sConn; sConn = new covise::ServerConnection(port, 0, (covise::sender_type)0); if (sConn->getSocket() == NULL) { fprintf(stderr, "Could not open server port %d\n", port); delete sConn; sConn = NULL; return (-1); } struct linger linger; linger.l_onoff = 0; linger.l_linger = 0; setsockopt(sConn->get_id(NULL), SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(linger)); sConn->listen(); if (!sConn->is_connected()) // could not open server port { fprintf(stderr, "Could not open server port %d\n", port); delete sConn; sConn = NULL; return (-1); } connections = new covise::ConnectionList(); connections->add(sConn); msg = new covise::Message; serverSN = new QSocketNotifier(sConn->get_id(NULL), QSocketNotifier::Read); //cerr << "listening on port " << port << endl; // weil unter windows manchmal Messages verloren gehen // der SocketNotifier wird nicht oft genug aufgerufen) #if defined(_WIN32) || defined(__APPLE__) m_periodictimer = new QTimer; QObject::connect(m_periodictimer, SIGNAL(timeout()), this, SLOT(processMessages())); m_periodictimer->start(1000); #endif QObject::connect(serverSN, SIGNAL(activated(int)), this, SLOT(processMessages())); return 0; }
bool Downloader::checkMirrors(tstring url, bool download/* or get size */) { TRACE(_T("Checking mirrors for %s (%s)..."), url.c_str(), download ? _T("download") : _T("get size")); pair<multimap<tstring, tstring>::iterator, multimap<tstring, tstring>::iterator> fileMirrors = mirrors.equal_range(url); for(multimap<tstring, tstring>::iterator i = fileMirrors.first; i != fileMirrors.second; ++i) { tstring mirror = i->second; TRACE(_T("Checking mirror %s:"), mirror.c_str()); NetFile f(mirror, files[url]->name, files[url]->size); if(download) { if(downloadFile(&f)) { files[url]->downloaded = true; return true; } } else // get size { try { DWORDLONG size = f.url.getSize(internet); if(size != FILE_SIZE_UNKNOWN) { files[url]->size = size; files[url]->mirrorUsed = mirror; return true; } } catch(HTTPError &e) { updateStatus(msg(e.what())); } } processMessages(); } return false; }
PerformanceDialog::PerformanceDialog(QWidget *parent) : QDialog(parent), ui(new Ui::PerformanceDialog), mFirstVSync(true), mCurrentRow(0) { ui->setupUi(this); mScene = new GridScene; mScene->setBackgroundBrush(QBrush(Qt::black)); mScene->setSceneRect(0,0,33.333,100); ui->graphicsView->setScene(mScene); ui->graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); // ui->graphicsView->viewport()->installEventFilter(this); ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->pauseButton->setEnabled(false); mUpdateValues = new CircularBuffer(60); mRenderValues = new CircularBuffer(60); mSwapValues = new CircularBuffer(60); QObject::connect(this,SIGNAL(messageAvailable()),this,SLOT(processMessages()), Qt::QueuedConnection); }
void Seq::process(unsigned n, float* p) { unsigned frames = n; processMessages(); if (state == TRANSPORT_PLAY) { unsigned framePos = 0; qreal endTime = playTime + qreal(frames)/qreal(MScore::sampleRate); for (; playPos != events.constEnd(); ++playPos) { qreal f = cs->utick2utime(playPos.key()); if (f >= endTime) break; int n = lrint((f - playTime) * MScore::sampleRate); synti->process(n, p); p += 2 * n; playTime += qreal(n)/qreal(MScore::sampleRate); frames -= n; framePos += n; playEvent(playPos.value()); playTick = playPos.key(); } if (frames) { synti->process(frames, p); playTime += qreal(frames)/qreal(MScore::sampleRate); } if (playPos == events.constEnd()) { driver->stopTransport(); seek(0); state = TRANSPORT_STOP; } } else { synti->process(frames, p); } }
void NetSpadesGame::sendMessageToGame( const SpadesGameMessage& msg ) { pushMessage(msg); processMessages(); }
void MessageChannel::threadChannelFunction( void *p_arg ) { processMessages(); }
void IComponent::tick(unsigned int msecs) { processMessages(); } // tick
void CurlStreamFile::fillCache(std::streampos size){ #if 1 assert(size >= 0); if(! _running || _cached >=size){ return ; } fd_set readfd, writefd, exceptfd; int maxfd; CURLMcode mcode; timeval tv; //hard-coded slect timeout //this number is kept low to give more thread switch //opportunities while waitting for a load const long maxSleepUsec = 10000; //1/100 of a second const unsigned int userTimeout = 60000; WallClockTimer lastProgress; while(_running){ fillCacheNonBlocking(); if(_cached>=size || !_running) break; FD_ZERO(&readfd); FD_ZERO(&writefd); FD_ZERO(&exceptfd); mcode = curl_multi_fdset(_mCurlHandle, &readfd, &writefd, &exceptfd, &maxfd); if(mcode != CURLM_OK){ throw SnailException(curl_multi_strerror(mcode)); } if(maxfd<0){ //as of libcurl 7.21.x, the DNS resolving appears to be //going on in the background, so curl_multi_fdset fails to //return anything useful, So we use the user timeout value //to give DNS enough time to resolve the lookup if(userTimeout && lastProgress.elapsed()>userTimeout){ return ; }else{ continue; } }//if(maxfd<0) tv.tv_sec = 0; tv.tv_usec = maxSleepUsec; //wait for data on the filedescriptors until a timeout set in rc file int ret = select(maxfd+1, &readfd, &writefd, &exceptfd, &tv); #if !defined(WIN32) if(ret == -1){ if(errno == EINTR){ cout<<"select() was interrupted by a singal"<<endl; ret = 0; }else{ std::ostringstream os; os<<"error polling data from connection to"<<_url<<":"<<strerror(errno); throw SnailException(os.str()); } } #endif if(!ret){ //timeout check the clock to see //if we expired the user timeout if(userTimeout && lastProgress.elapsed() > userTimeout){ cout<<"timeout ("<<userTimeout<<") while loading from URL"<<_url<<endl; return ; } }else{ lastProgress.restart(); } }//while(.... processMessages(); #endif }
bool Downloader::downloadFiles(bool useComponents) { if(ownMsgLoop) downloadCancelled = false; if(files.empty() && ftpDirs.empty()) return true; setMarquee(true); processFtpDirs(); if(getFileSizes() == OPERATION_STOPPED) { TRACE(_T("OPERATION_STOPPED")); setMarquee(false); return false; } TRACE(_T("filesSize: %d"), (DWORD)filesSize); if(!openInternet()) { storeError(); setMarquee(false); return false; } sizeTimeTimer.start(500); updateStatus(msg("Starting download...")); TRACE(_T("Starting file download cycle...")); if(!(filesSize == FILE_SIZE_UNKNOWN)) setMarquee(false); processMessages(); for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++) { NetFile *file = i->second; if(downloadCancelled) break; if(useComponents) if(!file->selected(components)) continue; if(!file->downloaded) { // If mirror was used in getFileSizes() function, check mirror first: if(file->mirrorUsed.length()) { NetFile newFile(file->mirrorUsed, file->name, file->size); if(downloadFile(&newFile)) { file->downloaded = newFile.downloaded; file->bytesDownloaded = newFile.bytesDownloaded; downloadedFilesSize += file->bytesDownloaded; continue; } } if(!downloadFile(file)) { TRACE(_T("File was not downloaded.")); if(checkMirrors(i->first, true)) downloadedFilesSize += file->bytesDownloaded; else { if(stopOnError) { closeInternet(); return false; } else { TRACE(_T("Ignoring file %s"), file->name.c_str()); } } } else downloadedFilesSize += file->bytesDownloaded; } processMessages(); } closeInternet(); return filesDownloaded(); }
bool Downloader::downloadFile(NetFile *netFile) { BYTE *buffer = new BYTE[readBufferSize]; DWORD bytesRead; File file; updateFileName(netFile); updateStatus(msg("Connecting...")); setMarquee(true, false); try { netFile->open(internet); } catch(exception &e) { setMarquee(false, stopOnError ? (netFile->size == FILE_SIZE_UNKNOWN) : false); updateStatus(msg(e.what())); storeError(msg(e.what())); delete[] buffer; return false; } if(!netFile->handle) { setMarquee(false, stopOnError ? (netFile->size == FILE_SIZE_UNKNOWN) : false); updateStatus(msg("Cannot connect")); storeError(); delete[] buffer; return false; } if(!file.open(netFile->name)) { setMarquee(false, stopOnError ? (netFile->size == FILE_SIZE_UNKNOWN) : false); tstring errstr = msg("Cannot create file") + _T(" ") + netFile->name; updateStatus(errstr); storeError(errstr); delete[] buffer; return false; } Timer progressTimer(100); Timer speedTimer(1000); updateStatus(msg("Downloading...")); if(!(netFile->size == FILE_SIZE_UNKNOWN)) setMarquee(false, false); processMessages(); while(true) { if(downloadCancelled) { file.close(); netFile->close(); delete[] buffer; return true; } if(!netFile->read(buffer, readBufferSize, &bytesRead)) { setMarquee(false, netFile->size == FILE_SIZE_UNKNOWN); updateStatus(msg("Download failed")); storeError(); file.close(); netFile->close(); delete[] buffer; return false; } if(bytesRead == 0) break; file.write(buffer, bytesRead); if(progressTimer.elapsed()) updateProgress(netFile); if(speedTimer.elapsed()) updateSpeed(netFile, &speedTimer); if(sizeTimeTimer.elapsed()) updateSizeTime(netFile, &sizeTimeTimer); processMessages(); } updateProgress(netFile); updateSpeed(netFile, &speedTimer); updateSizeTime(netFile, &sizeTimeTimer); updateStatus(msg("Download complete")); processMessages(); file.close(); netFile->close(); netFile->downloaded = true; delete[] buffer; return true; }
void ExCommand::sendMessage() { g_fullpipe->_exCommandList.push_back(this); processMessages(); }
DWORDLONG Downloader::getFileSizes(bool useComponents) { if(ownMsgLoop) downloadCancelled = false; if(files.empty()) return 0; updateStatus(msg("Initializing...")); processMessages(); if(!openInternet()) { storeError(); return FILE_SIZE_UNKNOWN; } filesSize = 0; bool sizeUnknown = false; for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++) { updateStatus(msg("Getting file information...")); processMessages(); NetFile *file = i->second; if(downloadCancelled) break; if(useComponents) if(!file->selected(components)) continue; if(file->size == FILE_SIZE_UNKNOWN) { try { try { updateFileName(file); processMessages(); file->size = file->url.getSize(internet); } catch(HTTPError &e) { updateStatus(msg(e.what())); //TODO: if allowContinue==0 & error code == file not found - stop. } if(file->size == FILE_SIZE_UNKNOWN) checkMirrors(i->first, false); } catch(FatalNetworkError &e) { updateStatus(msg(e.what())); storeError(msg(e.what())); closeInternet(); return OPERATION_STOPPED; } } if(!(file->size == FILE_SIZE_UNKNOWN)) filesSize += file->size; else sizeUnknown = true; } closeInternet(); if(sizeUnknown && !filesSize) filesSize = FILE_SIZE_UNKNOWN; //TODO: if only part of files has unknown size - ??? #ifdef _DEBUG TRACE(_T("getFileSizes result:")); for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++) { NetFile *file = i->second; TRACE(_T(" %s: %s"), file->getShortName().c_str(), (file->size == FILE_SIZE_UNKNOWN) ? _T("Unknown") : itotstr((DWORD)file->size).c_str()); } #endif return filesSize; }