void IpPool::OnDisConnect(const boost::asio::ip::udp::endpoint& end_point, bool is_active) { if (is_running_ == false) return; LOG4CPLUS_INFO_LOG(logger_ippool, "IpPool::OnDisConnect Endpoint=" << end_point); protocol::SocketAddr socket_addr(end_point.address().to_v4().to_ulong(), end_point.port()); std::map<protocol::SocketAddr, CandidatePeer::p>::iterator iter = candidate_peers_.find(socket_addr); if (iter == candidate_peers_.end()) return; CandidatePeer::p peer = iter->second; assert(peer); IPPoolIndexUpdating updating(peer, shared_from_this()); peer->last_active_time_ = framework::timer::TickCounter::tick_count(); // reset last_connect_time_ to avoid re-connecting the peer immediately peer->last_connect_time_ = peer->last_active_time_; peer->is_connecting_ = false; peer->is_connected_ = false; if (is_active) { protocol::CloseSessionPacket packet(protocol::Packet::NewTransactionID(), protocol::PEER_VERSION, end_point); AppModule::Inst()->DoSendPacket(packet, protocol::PEER_VERSION); } }
/** * This is the main paint routine. It must be called by the viewer holding the reference to this canvas (e.g. when a * window must be redrawn). * * @param content The elements to render. */ void CGenericCanvas::render(TGCRenderContent content) { // No display if the canvas is currently being updated. if (!updating()) { beginUpdate(); try { if ((FStates & GC_STATE_PENDING_ACTIVATION) != 0) { // A pending activation state always means there is a valid current view. FStates &= ~GC_STATE_PENDING_ACTIVATION; FCurrentView->activate(); }; if (FCurrentView != NULL) { FCurrentView->validate(); clearBuffers(); FCurrentView->render(content); }; endUpdate(); } catch(...) { endUpdate(); throw; }; checkError(); }; }
// Voy tomando de a vectores x, que representa el patron de activacion que se // esta aplicando a la red. void SOM::sampling(const vector<vector<float> > &samples, float it, float maxit) { // En cada iteracion, ingresamos una sola muestra for (unsigned int muestra = 0, cnt = samples.size(); muestra < cnt; muestra++) { // Obtenemos el primer valor como minimo float min = neuronas[0].get_distancia(samples[muestra]); unsigned int idx = 0; /// SIMILARITY MATCHING (Haykin p454) // Recorro cada neurona, y voy buscando la minima distancia for (unsigned int j = 1; j < cant; j++) { float distancia = neuronas[j].get_distancia(samples[muestra]); // El idx me indica cual neurona tiene el minimo if (min > distancia) { min = distancia; idx = j; } } // Acto seguido, actualizo los pesos updating(samples[muestra], idx, muestra, it, maxit); } }
void CollisionManager::checkEnemyPlayerBulletCollision( const std::vector<GameObject *> &objects) { for(unsigned int i = 0; i < objects.size(); i++) { auto pObject = objects[i]; for(unsigned int j = 0; j < TheBulletHandler::Instance()->getPlayerBullets().size(); j++) { if(pObject->type() != std::string("Enemy") || !pObject->updating()) { continue; } auto pRect1 = std::make_shared<SDL_Rect>(); pRect1->x = pObject->getPosition().getX(); pRect1->y = pObject->getPosition().getY(); pRect1->w = pObject->getWidth(); pRect1->h = pObject->getHeight(); auto pPlayerBullet = TheBulletHandler::Instance()-> getPlayerBullets()[j]; auto pRect2 = std::make_shared<SDL_Rect>(); pRect2->x = pPlayerBullet->getPosition().getX(); pRect2->y = pPlayerBullet->getPosition().getY(); pRect2->w = pPlayerBullet->getWidth(); pRect2->h = pPlayerBullet->getHeight(); if(RectRect(pRect1, pRect2)) { if(!pObject->dying() && !pPlayerBullet->dying()) { pPlayerBullet->collision(); pObject->collision(); } } } } }
LibraryPage::LibraryPage(QWidget *p) : QWidget(p) { setupUi(this); addToPlayQueue->setDefaultAction(StdActions::self()->addToPlayQueueAction); replacePlayQueue->setDefaultAction(StdActions::self()->replacePlayQueueAction); view->addAction(StdActions::self()->addToPlayQueueAction); view->addAction(StdActions::self()->replacePlayQueueAction); view->addAction(StdActions::self()->addWithPriorityAction); view->addAction(StdActions::self()->addToStoredPlaylistAction); #ifdef TAGLIB_FOUND #ifdef ENABLE_DEVICES_SUPPORT view->addAction(StdActions::self()->copyToDeviceAction); #endif view->addAction(StdActions::self()->organiseFilesAction); view->addAction(StdActions::self()->editTagsAction); #ifdef ENABLE_REPLAYGAIN_SUPPORT view->addAction(StdActions::self()->replaygainAction); #endif view->addAction(StdActions::self()->setCoverAction); #ifdef ENABLE_DEVICES_SUPPORT view->addSeparator(); view->addAction(StdActions::self()->deleteSongsAction); #endif #endif // TAGLIB_FOUND connect(this, SIGNAL(add(const QStringList &, bool, quint8)), MPDConnection::self(), SLOT(add(const QStringList &, bool, quint8))); connect(this, SIGNAL(addSongsToPlaylist(const QString &, const QStringList &)), MPDConnection::self(), SLOT(addToPlaylist(const QString &, const QStringList &))); connect(genreCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(searchItems())); connect(MPDConnection::self(), SIGNAL(updatingLibrary()), view, SLOT(updating())); connect(MPDConnection::self(), SIGNAL(updatedLibrary()), view, SLOT(updated())); connect(MPDConnection::self(), SIGNAL(updatingDatabase()), view, SLOT(updating())); connect(MPDConnection::self(), SIGNAL(updatedDatabase()), view, SLOT(updated())); connect(MusicLibraryModel::self(), SIGNAL(updateGenres(const QSet<QString> &)), genreCombo, SLOT(update(const QSet<QString> &))); connect(this, SIGNAL(loadLibrary()), MPDConnection::self(), SLOT(loadLibrary())); connect(view, SIGNAL(itemsSelected(bool)), this, SLOT(controlActions())); connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(itemDoubleClicked(const QModelIndex &))); connect(view, SIGNAL(searchItems()), this, SLOT(searchItems())); connect(view, SIGNAL(rootIndexSet(QModelIndex)), this, SLOT(updateGenres(QModelIndex))); proxy.setSourceModel(MusicLibraryModel::self()); view->setModel(&proxy); view->load(metaObject()->className()); }
StripChart::StripChart(QWidget *parent):QFrame(parent) { QGridLayout *gl = new QGridLayout(this); title_=new QLabel("Title",this); gl->addWidget(title_,0,1); int frameWidth=3; QFrame *chartFrame= new QFrame(this); chartFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken); chartFrame->setLineWidth(frameWidth); gl->addWidget(chartFrame,2,1); QVBoxLayout *vb = new QVBoxLayout(chartFrame); vb->setContentsMargins(0,0,0,0); plotter_ = new Plotter(this); plotter_->setScrollingWindow(true); vb->addWidget(plotter_); xAxis_ = new AxisWidget(frameWidth,plotter_->xAxis(),this); xAxis_->setOrientation(Qt::Horizontal); xAxis_->setTitle("time (s)"); gl->addWidget(xAxis_,3,1); yAxis_ = new AxisWidget(frameWidth,plotter_->yAxis(),this); yAxis_->setOrientation(Qt::Vertical); yAxis_->setTitle("data (arb.)"); gl->addWidget(yAxis_,2,0); gl->setSpacing(0); gl->setRowStretch(0,0); gl->setRowStretch(1,0); gl->setRowStretch(2,1); gl->setRowStretch(3,0); gl->setColumnStretch(0,0); gl->setColumnStretch(1,1); connect(plotter_,SIGNAL(updating()),this,SLOT(setUpdating())); connect(plotter_,SIGNAL(inspecting()),this,SLOT(setInspecting())); connect(xAxis_,SIGNAL(rangeChanged(double,double)),this,SLOT(updateXAxisRange(double,double))); connect(yAxis_,SIGNAL(rangeChanged(double,double)),this,SLOT(updateYAxisRange(double,double))); }
void IpPool::OnConnectSucced(const boost::asio::ip::udp::endpoint& end_point) { if (is_running_ == false) return; LOG4CPLUS_INFO_LOG(logger_ippool, "IpPool::OnConnectSucced Endpoint=" << end_point); protocol::SocketAddr socket_addr(end_point.address().to_v4().to_ulong(), end_point.port()); std::map<protocol::SocketAddr, CandidatePeer::p>::iterator iter = candidate_peers_.find(socket_addr); if (iter == candidate_peers_.end()) return; CandidatePeer::p peer = iter->second; assert(peer); IPPoolIndexUpdating updating(peer, shared_from_this()); peer->last_active_time_ = framework::timer::TickCounter::tick_count(); peer->is_connecting_ = false; peer->is_connected_ = true; }
/** * Renders the current scene to a file in the format given. * * @param filename The name of the target file. It must already contain the correct extension and must be encoded in UTF-8. * @param format The format of the file to render. Supported are PNG, PDF, PS (postscript) and EPS (encapsulated postscript). * @param title The titel for the document. Must be ANSI encoded for now. * @param software A string describing the producer of the document. Must be ANSI encoded for now. * @param content A set of flags indicating what additional info to render. * @param zoom The zoom at which render the file. * @param bounds Position and size of the area to store in the file (currently only for PNG). * @return True if successful otherwise false. */ bool CGenericCanvas::renderToFile(const char* filename, TGCFileFormat format, const char* title, const char* software, TGCRenderContent content, float zoom, TGCViewport& bounds) { bool result = false; if (!updating()) { beginUpdate(); try { if ((FStates & GC_STATE_PENDING_ACTIVATION) != 0) { // A pending activation state always means there is a valid current view. FStates &= ~GC_STATE_PENDING_ACTIVATION; FCurrentView->activate(); }; switch (format) { case GC_FILE_FORMAT_PDF: case GC_FILE_FORMAT_PS: case GC_FILE_FORMAT_EPS: { if (FCurrentView != NULL) { const int fileTypeMapper[4] = {GL2PS_PDF, GL2PS_PS, GL2PS_EPS, GL2PS_TEX}; FILE *file = openFile(filename, "wb"); GLint bufferSize = 0; GLint state = GL2PS_OVERFLOW; char *oldlocale = setlocale(LC_NUMERIC, "C"); while (state == GL2PS_OVERFLOW) { bufferSize += 1024 * 1024; gl2psBeginPage(title, software, NULL, fileTypeMapper[format], GL2PS_NO_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT | GL2PS_COMPRESS, GL_RGBA, 0, NULL, 0, 0, 0, bufferSize, file, filename); gl2psEnable(GL2PS_BLEND); gl2psBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); clearBuffers(); FCurrentView->render(content); state = gl2psEndPage(); }; setlocale(LC_NUMERIC, oldlocale); fclose(file); result = true; }; break; }; case GC_FILE_FORMAT_PNG: { if (FCurrentView != NULL) { TImage image; float workspaceWidth; float workspaceHeight; FCurrentView->getWorkspace(&workspaceWidth, &workspaceHeight); image.width = bounds.width; if (image.width < 0) image.width = (int) workspaceWidth; image.height = bounds.height; if (image.height < 0) image.height = (int) workspaceHeight; // If the frame buffer extension is not supported then there is no sense // to allocate a buffer larger than the current viewport, // because we cannot render more than this area in this case. if (!supportsExtension(GC_OE_FRAME_BUFFER_OBJECTS)) { if (image.height > FCurrentView->viewportGet().height) image.height = FCurrentView->viewportGet().height; if (image.width > FCurrentView->viewportGet().width) image.width = FCurrentView->viewportGet().width; }; image.colorType = COLOR_TYPE_RGB_ALPHA; image.data = (unsigned char*) malloc(image.width * image.height * 4); if (image.data != NULL) { FCurrentView->renderToMemory(GC_COLOR_FORMAT_RGBA, content, zoom, bounds, image.data); image.width = bounds.width; image.height = bounds.height; result = savePNG(utf8ToUtf16(filename), &image, true, title, software); free(image.data); }; }; break; }; }; endUpdate(); } catch(...) { endUpdate(); throw; }; checkError(); }; return result; }
void SHistogram::starting() { updating(); }
void KPlayerActionList::unplug (void) { #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << "KPlayerActionList::unplug\n"; kdDebugTime() << " Name " << objectName() << "\n"; #endif if ( ! isEmpty() ) { #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << "Removing separators\n"; #endif QAction* action = actions().first(); int i, count = action -> associatedWidgets().count(); #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << " Containers " << count << "\n"; #endif for ( i = 0; i < count; i ++ ) { QWidget* container = action -> associatedWidgets().value (i); #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << " Container " << container -> metaObject() -> className() << " " << container -> objectName() << "\n"; #endif if ( container -> inherits ("QMenu") ) { int index = container -> actions().indexOf (action); #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << " Index " << index << "\n"; #endif if ( index > 0 ) { QAction* action = container -> actions().value (index - 1); if ( action -> isSeparator() ) container -> removeAction (action); } } } action = actions().last(); count = action -> associatedWidgets().count(); #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << " Containers " << count << "\n"; #endif for ( i = 0; i < count; i ++ ) { QWidget* container = action -> associatedWidgets().value (i); #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << " Container " << container -> metaObject() -> className() << " " << container -> objectName() << "\n"; #endif if ( container -> inherits ("QMenu") ) { int index = container -> actions().indexOf (action) + 1; #ifdef DEBUG_KPLAYER_ACTIONLIST kdDebugTime() << " Index " << index << "\n"; #endif if ( index > 0 && index < container -> actions().count() ) { QAction* action = container -> actions().value (index); if ( action -> isSeparator() ) container -> removeAction (action); } } } } emit updating (this); for ( QList<QAction*>::ConstIterator iterator (actions().begin()); iterator != actions().end(); ++ iterator ) delete *iterator; m_actions.clear(); }