void CDatabaseItem::setConnected(bool isconnected) { #ifdef DEBUG qDebug("CDatabaseItem::setConnected(%s)", debug_string(booltostr(isconnected))); #endif if (isBlocked()) return; setBlocked(true); if (isconnected) is_connected = isconnected && mysql()->mysql()->mysqlSelectDb(text(0)); else is_connected = false; setPixmap(0, is_connected ? databaseConnectedIcon : databaseDisconnectedIcon); if (is_connected) { new CTableGroupItem(this, text(0), mysql()); setOpen(true); } else deleteChilds(); createWindowMenu(consoleWindow()->itemToolBar()); setBlocked(false); }
void CDatabaseItem::refreshWidget(bool b) { #ifdef DEBUG qDebug("CDatabaseItem::refreshWidget(%s)", debug_string(booltostr(b))); #endif if (isBlocked()) return; setBlocked(true); if (widget_id == int_type()) { CShowDatabaseGroupProperties * w = (CShowDatabaseGroupProperties *) widgetStack()->widget(int_type()); w->setMySQL(mysql()); w->setTitle(mysql()->connectionName()); if (b || widgetData.isEmpty()) { w->refresh(); w->saveData(&widgetData); } else w->loadData(widgetData); } else ((CDatabaseListViewItem *) QListViewItem::parent())->refreshWidget(b); widgetStack()->raiseWidget(widget_id); setBlocked(false); }
void CQueryTable::refresh() { if (isBlocked()) return; reset(); m_cancel = false; if (!query()->isResultNull()) { setBlocked(true); query()->dataSeek(0); uint num_fields = query()->numFields(); ulong num_rows = query()->numRows(); setNumRows(num_rows); setNumCols(num_fields); QPixmap icon; bool columns_ok = (keepColumnWidth() && previous_columns_map.count() == num_fields); if (columns_ok) for (uint i = 0; i < num_fields; i++) columns_ok &= (previous_columns_map[i].label == query()->fields(i).name); if (!columns_ok && keepColumnWidth()) previous_columns_map.clear(); for (uint i = 0; i < num_fields; i++) { if (IS_PRI_KEY(query()->fields(i).flags)) icon = pkIcon; else if (IS_MUL_KEY(query()->fields(i).flags)) icon = mulIcon; else if (IS_UNI_KEY(query()->fields(i).flags)) icon = uniIcon; else icon = nothingIcon; if (columns_ok && previous_columns_map[i].label == query()->fields(i).name) horizontalHeader()->setLabel(i, icon, query()->fields(i).name, previous_columns_map[i].size); else horizontalHeader()->setLabel(i, icon, query()->fields(i).name); } if (hasProcessEvents()) qApp->processEvents(); else updateScrollBars(); ulong j = 0; while (query()->next(!hasProcessEvents())) { if (m_cancel) break; for (uint i = 0; i < num_fields; i++) setText(j, i, query()->row(i)); j++; } setBlocked(false); emit refreshed(); } else if (!previous_columns_map.empty()) previous_columns_map.clear(); }
void CAdministrationWindow::refresh() { if (isBlocked()) return; setBlocked(true); processList->refresh(); status->refresh(); if (has_innodb) innoDBStatus->refresh(); messagePanel()->information(tr("Refresh successful")); setBlocked(false); }
void CUserAdminItem::refresh() { #ifdef DEBUG qDebug("CUserAdminItem::refresh()"); #endif if (isBlocked() || !is_connected) return; setBlocked(true); if (!displayUsers()) printAccessError(); setBlocked(false); refreshWidget(true); }
LidSpaceCompactionJob::LidSpaceCompactionJob(const DocumentDBLidSpaceCompactionConfig &config, ILidSpaceCompactionHandler &handler, IOperationStorer &opStorer, IFrozenBucketHandler &frozenHandler, IDiskMemUsageNotifier &diskMemUsageNotifier, const BlockableMaintenanceJobConfig &blockableConfig, IClusterStateChangedNotifier &clusterStateChangedNotifier, bool nodeRetired) : BlockableMaintenanceJob("lid_space_compaction." + handler.getName(), config.getDelay(), config.getInterval(), blockableConfig), _cfg(config), _handler(handler), _opStorer(opStorer), _frozenHandler(frozenHandler), _scanItr(), _retryFrozenDocument(false), _shouldCompactLidSpace(false), _diskMemUsageNotifier(diskMemUsageNotifier), _clusterStateChangedNotifier(clusterStateChangedNotifier) { _diskMemUsageNotifier.addDiskMemUsageListener(this); _clusterStateChangedNotifier.addClusterStateChangedHandler(this); if (nodeRetired) { setBlocked(BlockedReason::CLUSTER_STATE); } }
bool LidSpaceCompactionJob::scanDocuments(const LidUsageStats &stats) { if (_scanItr->valid()) { DocumentMetaData document = getNextDocument(stats); if (document.valid()) { IFrozenBucketHandler::ExclusiveBucketGuard::UP bucketGuard = _frozenHandler.acquireExclusiveBucket(document.bucketId); if ( ! bucketGuard ) { // the job is blocked until the bucket for this document is thawed setBlocked(BlockedReason::FROZEN_BUCKET); _retryFrozenDocument = true; return true; } else { MoveOperation::UP op = _handler.createMoveOperation(document, stats.getLowestFreeLid()); search::IDestructorCallback::SP context = _moveOpsLimiter->beginOperation(); _opStorer.storeOperation(*op, context); _handler.handleMove(*op, std::move(context)); if (isBlocked(BlockedReason::OUTSTANDING_OPS)) { return true; } } } } if (!_scanItr->valid()){ if (shouldRestartScanDocuments(_handler.getLidStatus())) { _scanItr = _handler.getIterator(); } else { _scanItr = IDocumentScanIterator::UP(); _shouldCompactLidSpace = true; } } return false; // more work to do (scan documents or compact lid space) }
void CDatabaseItem::processMenu(int res) { #ifdef DEBUG qDebug("CDatabaseItem::processMenu(%d)", res); #endif if (isBlocked()) return; switch (res) { case MENU_CONNECT: setConnected(true); break; case MENU_DISCONNECT: setConnected(false); break; case MENU_DELETE: { if (myApp()->confirmCritical()) if ((QMessageBox::information(0, tr("Confirm Delete Database"), tr("Are you sure you want to Delete Database") + ":\'" + text(0) + "\' ?", tr("&Yes"), tr("&No")) != 0)) return; setBlocked(true); CMySQLQuery qry(mysql()->mysql()); qry.setEmitMessages(false); if (qry.execStaticQuery("DROP DATABASE IF EXISTS " + mysql()->mysql()->quote(text(0)))) { setVisible(false); setBlocked(false); delete this; } else setBlocked(false); } break; case MENU_NEW_WINDOW_FROM_HERE: databaseListView()->openInNewWindow(this); break; } }
void CAdministrationWindow::killProcesses() { if (isBlocked()) return; setBlocked(true); bool found = false; for (int i = 0; i < processList->numRows(); i++) { if (processList->item(i,0) != 0 && ((QCheckTableItem *) processList->item(i,0))->isChecked()) if (mysql()->mysql()->mysqlKill(processList->text(i,0).toLong())) { messagePanel()->information(tr("Process killed successfully") + " :" + processList->text(i,0)); if (!found) found = true; } } if (found) processList->refresh(); setBlocked(false); }
void CProjectile::init(float _x, float _y, int _parentID, bool _salve) { ci_projectile_data = new CProjectileData(); std::string sProjectileSound; sProjectileSound = ci_projectile_data->getSound(_parentID); if(!_salve) { sProjectileSound += ".wav"; PlaySound(glDataBox->GetSoundBuffer(sProjectileSound), _parentID + 4); // Make sure sounds get played on different layers } else { sProjectileSound += "_salve.wav"; PlaySound(glDataBox->GetSoundBuffer(sProjectileSound), _parentID + 4); } m_fStartX = _x; m_fStartY = _y; m_iParent = _parentID; m_bSalve = _salve; setBlocked(-1); setScale(-1.0f, 1.0f); setPosition(_x, _y); setOrigin(ci_projectile_data->getOrigin(m_iParent).x, ci_projectile_data->getOrigin(m_iParent).y); m_collision = new pwCollisionRect(); m_collision->SetSize((float)ci_projectile_data->getSize(m_iParent).width, (float)ci_projectile_data->getSize(m_iParent).height); AddCollisionObject(ID_CO_PROJECTILE, m_collision); SetGravityMultiplier(ci_projectile_data->getGravity(m_iParent) * (CBeatSystem::GetBPM() * 1.5f) / 80.0f); // Use BMP to modify gravity to a certain extent -> projectile needs to hit coloss m_visual.SetFramesPerSecond(ci_projectile_data->getAnimationSpeed(m_iParent)); velocity temp = calculateForce(m_iParent); SetStartVelocity(temp.xVel, temp.yVel); m_visual.setTexture(*glDataBox->GetTexture(ci_projectile_data->getTexture(m_iParent))); m_visual.SetFrameSize(ci_projectile_data->getSize(m_iParent).width, ci_projectile_data->getSize(m_iParent).height); m_visual.SetTotalFrames(ci_projectile_data->getFrames(m_iParent)); m_visual.AddAnimation(P_ANIM_NORMAL, ci_projectile_data->getAnimation(m_iParent).normalStart, ci_projectile_data->getAnimation(m_iParent).normalEnd); m_visual.AddAnimation(P_ANIM_DEATH, ci_projectile_data->getAnimation(m_iParent).deathStart, ci_projectile_data->getAnimation(m_iParent).deathEnd); m_visual.SetCurrentAnimation(P_ANIM_NORMAL); AddDrawableObject(ID_DO_PROJECTILE, &m_visual); m_vProjectiles.push_back(this); glLogics->RegisterGameObject(this, ID_GS_PLAY); }
//------------------------------------------------------------------------------ // listenForConnections() -- puts the socket into listen mode //------------------------------------------------------------------------------ bool TcpServerSingle::acceptConnection() { if (socketNum == INVALID_SOCKET) return 0; struct sockaddr_in clientAddr; socklen_t cAddrSize = sizeof(clientAddr); if (isMessageEnabled(MSG_INFO)) { std::cout << "Waiting to accept connection on " << getPort() << " ... " << std::flush; } LcSocket tcpSocket = ::accept(socketNum, reinterpret_cast<struct sockaddr*>(&clientAddr), &cAddrSize); if (tcpSocket == INVALID_SOCKET) { if (isMessageEnabled(MSG_INFO)) { std::cout << " failed!" << std::endl; } return false; } if (isMessageEnabled(MSG_INFO)) { std::cout << "Accepted"; char* ip = ::inet_ntoa(clientAddr.sin_addr); if (ip != nullptr) { std::cout << " connection from " << ip; } std::cout << std::endl; } // After accepting a connection we close the original opened socket and // we then assign socketNum to our local tcpSocket. #if defined(WIN32) if (::closesocket(socketNum) == SOCKET_ERROR) { #else if (::shutdown(socketNum, SHUT_RDWR) == SOCKET_ERROR) { #endif std::perror("TcpServerSingle::acceptConnection(): shutdown original error! \n"); } socketNum = tcpSocket; connected = true; connectionTerminated = false; // Set blocked or no-wait if (noWait) setNoWait(); else setBlocked(); if (isMessageEnabled(MSG_INFO)) { std::cout << "TcpServerSingle::acceptConnection: new socketNum = " << socketNum << std::endl; } return true; } }
void CUserAdminItem::setConnected(bool connected, bool refresh_toolbar) { #ifdef DEBUG qDebug("CUserAdminItem::setConnected(%s)", debug_string(booltostr(connected))); #endif if (isBlocked()) return; setBlocked(true); if (connected && !is_connected) { mysql()->mysql()->setEmitErrors(false); if (mysql()->mysql()->mysqlSelectDb("mysql")) is_connected = displayUsers(); else printAccessError(); mysql()->mysql()->setEmitErrors(true); } else is_connected = false; if (!is_connected && !connected) { while (this->childCount() > 0) deleteChilds(); } else if (is_connected) setOpen(true); setPixmap(0, getPixmapIcon(!is_connected ? "databaseUsersDisconnectedIcon" : "databaseUsersIcon")); if (refresh_toolbar) createWindowMenu(consoleWindow()->itemToolBar()); setBlocked(false); }
void LidSpaceCompactionJob::notifyClusterStateChanged(const IBucketStateCalculator::SP &newCalc) { // Called by master write thread bool nodeRetired = newCalc->nodeRetired(); if (!nodeRetired) { if (isBlocked(BlockedReason::CLUSTER_STATE)) { LOG(info, "notifyClusterStateChanged(): Node is no longer retired -> lid space compaction job re-enabled"); unBlock(BlockedReason::CLUSTER_STATE); } } else { LOG(info, "notifyClusterStateChanged(): Node is retired -> lid space compaction job disabled"); setBlocked(BlockedReason::CLUSTER_STATE); } }
/*! * \brief PositionSpread::ParseCommand * \param serverConnectionHandlerID * \param cmd * \param args * \return Return 0 if plugin handled the command, 1 if not handled. */ int PositionSpread::ParseCommand(uint64 serverConnectionHandlerID, QString cmd, QStringList args) { Q_UNUSED(serverConnectionHandlerID); if ((cmd.compare("SPS",Qt::CaseInsensitive)) != 0) return 1; cmd = args.at(0); if (cmd.compare("SET_BLOCKED",Qt::CaseInsensitive) == 0) { setBlocked((args.at(1).compare("true",Qt::CaseInsensitive) == 0)); return 0; } return 1; }
int main(void) { int size; printf("Enter board dimensions (n), n>=6 and n<=21: "); scanf("%d", &size); char board[21][21]; createBoard(size, board); char compPlayer[10]; bool humanUserWhite; printf("Computer playing B or W?: "); scanf("%s", &compPlayer); if (compPlayer[0] == 'B') humanUserWhite = true; else humanUserWhite = false; setBlocked(size, board); playGame(size, board, humanUserWhite); return (EXIT_SUCCESS); }
//------------------------------------------------------------------------------ // connectToServer() -- attempt to connect to the server //------------------------------------------------------------------------------ bool TcpClient::connectToServer() { connected = false; connectionTerminated = false; if (ipAddr == nullptr) return false; if (socketNum == INVALID_SOCKET) return false; struct sockaddr_in addr; // Working address structure bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = getNetAddr(); addr.sin_port = htons(getPort()); if (isMessageEnabled(MSG_INFO)) { std::cout << "Connecting to TCP server at " << ipAddr << ":" << getPort() << " ... " << std::flush; } if (::connect(socketNum, reinterpret_cast<const struct sockaddr*>(&addr), sizeof(addr)) == SOCKET_ERROR) { if (isMessageEnabled(MSG_INFO)) { std::cout << "Failed!" << std::endl; } } else { if (isMessageEnabled(MSG_INFO)) { std::cout << "Connected!" << std::endl; } connected = true; } if (isMessageEnabled(MSG_INFO)) { std::cout << "TcpClient::connectToServer: socketNum = " << socketNum << std::endl; } // Set blocked or no-wait if (noWait) setNoWait(); else setBlocked(); return connected; }
void CQueryTable::save() { if (isBlocked()) return; tmpFileName = getSaveFileName(tmpFileName, "txt", tr("Text Files (*.txt);;All Files(*.*)")); if (tmpFileName.isEmpty()) return; QFile file( tmpFileName ); if (file.exists() && myApp()->confirmCritical()) if ((QMessageBox::warning(0, tr("Replace File"), tr("The specified file name already exists.\nDo you want to replace it ?"), QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)) return; if ( !file.open( IO_WriteOnly ) ) { if (mysql()->messagePanel()) mysql()->messagePanel()->critical(tr("An error occurred while saving the file")); return; } setBlocked(true); QString line_terminator = mysql()->lineTerminator(true); QString title = caption() + line_terminator; title += tr("Connection") + ": " + mysql()->connectionName() + line_terminator; title += tr("Host") + ": " + mysql()->hostName() + line_terminator; title += tr("Saved") + ": " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") + line_terminator; title = CApplication::commentText(title, line_terminator) + line_terminator; QTextStream ts( &file ); ts << title; QString tmp = tr("Query") + ":" + line_terminator; tmp += query()->lastQuery().replace(QRegExp("\n"), line_terminator) + line_terminator; ts << CApplication::commentText(tmp, line_terminator) << line_terminator; query()->dataSeek(0); uint num_fields = query()->numFields(); QString encl = mysql()->fieldEncloser(true); QString sep = mysql()->fieldSeparator(true); uint j; bool add_sep = false; for (j = 0; j < num_fields; j++) { if (horizontalHeader()->sectionSize(j) != 0) { if (add_sep) ts << sep; ts << encl << query()->fields(j).name << encl; if (!add_sep) add_sep = true; } } ts << line_terminator; if (numRows() <= 0 || numCols() <= 0) return; QString repl_empty = mysql()->replaceEmpty(true); while (query()->next(!hasProcessEvents())) { add_sep = false; for (j = 0; j < num_fields; j++) if (horizontalHeader()->sectionSize(j) != 0) { const char* r = query()->row(j); if (!r) r = "[NULL]"; if (!*r) r = (const char*)repl_empty; if (add_sep) ts << sep; ts << encl << r << encl; if (!add_sep) add_sep = true; } ts << line_terminator; } file.close(); if (mysql()->messagePanel()) mysql()->messagePanel()->information(tr("Successfully saved") + ": " + tmpFileName); setBlocked(false); }
////////////////// /// Main method ///////////////// void Road::update() { //static QTime reloj = QTime::currentTime(); if(this->isEmpty()) return; /// Get robot's position in world and create robot's nose QVec robot3DPos = innerModel->transformS("world", robotname); auto &primero = this->first(); primero = robot3DPos; /// Robot nose QVec noseInRobot = innerModel->transformS("world", QVec::vec3(0, 0, 1000), robotname); //QLine2D nose = QLine2D(QVec::vec2(robot3DPos.x(), robot3DPos.z()), QVec::vec2(noseInRobot.x(), noseInRobot.z())); QLine2D nose = QLine2D(QVec::vec2(noseInRobot.x(), noseInRobot.z()),QVec::vec2(robot3DPos.x(), robot3DPos.z())); /// Compute closest point in road to robot. If closer than 1000mm it will use the virtual point (tip) instead of the center of the robot. Road::iterator closestPoint = computeClosestPointToRobot(robot3DPos); /// Compute roadTangent at closestPoint QLine2D tangent = computeTangentAt(closestPoint); setTangentAtClosestPoint(tangent); /// Compute signed perpenduicular distance from robot to tangent at closest point setRobotPerpendicularDistanceToRoad(tangent.perpendicularDistanceToPoint(robot3DPos)); /// Compute signed angle between nose and tangent at closest point float ang = nose.signedAngleWithLine2D(tangent); if (std::isnan(ang)) ang = 0; setAngleWithTangentAtClosestPoint(ang); /// Compute distance to target along trajectory setRobotDistanceToTarget(computeDistanceToTarget(closestPoint, robot3DPos)); //computes robotDistanceVariationToTarget setRobotDistanceVariationToTarget(robotDistanceVariationToTarget); /// Update estimated time of arrival setETA(); /// Compute curvature of trajectory at closest point to robot setRoadCurvatureAtClosestPoint(computeRoadCurvature(closestPoint, 3)); /// Compute distance to last road point visible with laser field setRobotDistanceToLastVisible(computeDistanceToLastVisible(closestPoint, robot3DPos)); /// Compute robot angle in each point for( Road::iterator it = this->begin(); it != this->end()-1; ++it ) { QLine2D l = computeTangentAt(it); QVec d = l.getDirectionVector(); float ang = atan2(d.x(), d.y()); if(ang>0) ang -= M_PI; else ang += M_PI; it->rot = QVec::vec3(0, ang, 0); } /// Check for arrival to target (translation) TOO SIMPLE // if (((((int) getIndexOfCurrentPoint()+1 == (int) this->size()) and (getRobotDistanceToTarget() < threshold))) or // (((int) getIndexOfCurrentPoint()+1 == (int) this->size()) and (getRobotDistanceVariationToTarget() > 0))) // { // qDebug() << "Road::" <<__FUNCTION__ << "ROAD: FINISHED"; // qDebug() << "Road::" <<__FUNCTION__ << " reason: " << ((int) getIndexOfCurrentPoint()+1 == (int)this->size()) << "index " << getIndexOfCurrentPoint(); // qDebug() << "Road::" <<__FUNCTION__ << " reason: " << (getRobotDistanceToTarget() < threshold) << " distance: "<<getRobotDistanceToTarget() << getRobotDistanceVariationToTarget(); // // clear(); // setFinished(true); // } // else { /////////////////////////////////////////// //Check for blocked road /////////////////////////////////////////// // qDebug() << "Road::" <<__FUNCTION__ << "ROAD: Robot distance to last visible" << getRobotDistanceToLastVisible() << (getIterToLastVisiblePoint() < this->end()); //print(); if( getRobotDistanceToLastVisible() < 250 and //PARAMS getIterToLastVisiblePoint() < this->end()) { qDebug() <<"Road::" <<__FUNCTION__ <<"BLOCKED" << "distanceToLastVisible" << getRobotDistanceToLastVisible(); setBlocked(true); } else setBlocked(false); } //printRobotState(innerModel); // print(); }
void CProcessListTable::refresh() { if (isBlocked()) return; setBlocked(true); bool max_scroll = false; int scroll = is_first ? 0 : verticalScrollBar()->value(); if (scroll >= verticalScrollBar()->maxValue() - 1 && scroll != 0) max_scroll = true; if (keepColumnWidth() && numCols() > 0) for (int i = 0; i < numCols(); i++) previous_columns_map.insert(i, CTable::OldColumn(horizontalHeader()->sectionSize(i), horizontalHeader()->label(i))); clearCellWidget(currentRow(), currentColumn()); if (is_first) ensureVisible(0, 0); query()->freeResult(); setNumRows(0); horizontalHeader()->setSortIndicator( -1 ); if (query()->exec(sql)) { uint num_rows = qry->numRows(); uint num_fields = qry->numFields(); bool columns_ok = (keepColumnWidth() && previous_columns_map.count() == num_fields); if (columns_ok) for (uint i = 0; i < num_fields; i++) columns_ok &= (previous_columns_map[i].label == query()->fields(i).name); if (!columns_ok && keepColumnWidth()) previous_columns_map.clear(); setNumRows(num_rows); setNumCols(num_fields); if (is_first) { for (uint i = 0; i < num_fields; i++) { if (columns_ok && previous_columns_map[i].label == query()->fields(i).name) horizontalHeader()->setLabel(i, qry->fields(i).name, previous_columns_map[i].size); else horizontalHeader()->setLabel(i, qry->fields(i).name); setColumnReadOnly (i, (i != 0)); } is_first = false; } if (hasProcessEvents()) qApp->processEvents(); else updateScrollBars(); uint j = 0; while (query()->next()) { for (uint i = 0; i < num_fields; i++) { const char *val = query()->row(i) ? query()->row(i) : NULL_TEXT; if (i == 0) setItem (j, i, new CCheckTableItem(this, val)); else setText(j, i, val); } j++; } if (!columns_ok) for (j = 0; j < num_fields; j++) adjustColumn(j); if (max_scroll) scroll = verticalScrollBar()->maxValue(); verticalScrollBar()->setValue(scroll); } setBlocked(false); applyLastSort(); }
bool CColossNormal::hasBlockStarted(int _layer) { bool blocked = false; float fDistance; int red; int green; int blue; int alpha; for(unsigned int i = 0; i < getProjectileVector().size(); i++) { switch(_layer) { case TOP_COLOSS: if((m_vLayerCollision[0].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[0])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) // Check if small object collides with big one and the other way round { // Play sound if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer0")), 0); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer0_future")), 0); } // Calculate animation speed so block will be at correct position startBlockAnimation(m_vBlockCollision[0].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 0); m_bTopBlock_active = true; // Distance to center fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[0].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[0].getPosition().y), 2)); // Button color red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[0].setColor(sf::Color(red, green, blue, alpha)); m_vButton[0].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[0].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 0); } else { if(m_vLayerCollision[0].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } // Projectile blocked getProjectileVector()[i]->setBlocked(0); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; case MIDDLE_HIGHER_COLOSS: if((m_vLayerCollision[1].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[1])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) { if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer1")), 1); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer1_future")), 1); } startBlockAnimation(m_vBlockCollision[1].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 1); m_bMiddleHigherBlock_active = true; fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[1].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[1].getPosition().y), 2)); red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[1].setColor(sf::Color(red, green, blue, alpha)); m_vButton[1].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[1].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 1); } else { if(m_vLayerCollision[1].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } getProjectileVector()[i]->setBlocked(1); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; case MIDDLE_LOWER_COLOSS: if((m_vLayerCollision[2].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[2])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) { if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer2")), 2); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer2_future")), 2); } startBlockAnimation(m_vBlockCollision[2].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 2); m_bMiddleLowerBlock_active = true; fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[2].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[2].getPosition().y), 2)); red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[2].setColor(sf::Color(red, green, blue, alpha)); m_vButton[2].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[2].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 2); } else { if(m_vLayerCollision[2].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } getProjectileVector()[i]->setBlocked(2); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; case BOTTOM_COLOSS: if((m_vLayerCollision[3].Collides(getProjectileVector()[i]->getCollisionObject()) || getProjectileVector()[i]->getCollisionObject()->Collides(&m_vLayerCollision[3])) && !getProjectileVector()[i]->getDead() && !getProjectileVector()[i]->getBounced() && getProjectileVector()[i]->getBlocked() == -1) { if(CLevelData::getCurrentLevelString() == "darkage") { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer3")), 3); } else { glAudio->PlaySound(glDataBox->GetSoundBuffer(data->GetString("layer3_future")), 3); } startBlockAnimation(m_vBlockCollision[3].getPosition().x, getProjectileVector()[i]->getPosition().x, getProjectileVector()[i]->GetStartVelocity().x, 3); m_bBottomBlock_active = true; fDistance = pwHelper::math::sqrt(pow((getProjectileVector()[i]->getPosition().x - m_vLayerCollision[3].getPosition().x), 2) + pow((getProjectileVector()[i]->getPosition().y - m_vLayerCollision[3].getPosition().y), 2)); red = (int)((fDistance/50 * 255) > 255 ? 255 : (fDistance/50 * 255)); green = (int)(200 + (55 - (fDistance/150 * 55))); blue = 0; alpha = 200; m_vButton[3].setColor(sf::Color(red, green, blue, alpha)); m_vButton[3].SetCurrentAnimation(C_ANIM_BUTTON_NORMAL); m_vButton[3].RestartAnimation(); if(!getBoss()) { calculateScore(fDistance, 3); } else { if(m_vLayerCollision[3].getPosition().x > getProjectileVector()[i]->getPosition().x) { getProjectileVector()[i]->setBlockDistance(-fDistance); } else { getProjectileVector()[i]->setBlockDistance(fDistance); } } getProjectileVector()[i]->setBlocked(3); blocked = true; if(!getBoss()) { modBlocked(1); modSteps(1); } } break; } // Blocked 15 projectiles in a row? Earn a modifier! if(getBlocked() >= m_iMultiplierDuration) { modModifier(1); setBlocked(0); } } return blocked; }
void CServerStatusTable::refresh() { if (isBlocked()) return; setBlocked(true); bool max_scroll = false; int scroll = is_first ? 0 : verticalScrollBar()->value(); if (scroll >= verticalScrollBar()->maxValue() - 1 && scroll != 0) max_scroll = true; if (is_traditional) { if (keepColumnWidth() && numCols() > 0) for (int i = 0; i < numCols(); i++) previous_columns_map.insert(i, CTable::OldColumn(horizontalHeader()->sectionSize(i), horizontalHeader()->label(i))); clearCellWidget(currentRow(), currentColumn()); if (is_first) ensureVisible(0, 0); setNumRows(0); if (sorting()) horizontalHeader()->setSortIndicator( -1 ); } if (query()->exec("SHOW STATUS")) { uint num_rows = query()->numRows(); uint num_fields = query()->numFields(); bool adjust = false; if (is_traditional) { bool columns_ok = (keepColumnWidth() && previous_columns_map.count() == num_fields); if (columns_ok) for (uint i = 0; i < num_fields; i++) columns_ok &= (previous_columns_map[i].label == query()->fields(i).name); if (!columns_ok) { adjust = true; if (keepColumnWidth()) previous_columns_map.clear(); } setNumRows(num_rows); setNumCols(num_fields); if (is_first) { for (uint i = 0; i < num_fields; i++) if (columns_ok && previous_columns_map[i].label == query()->fields(i).name) horizontalHeader()->setLabel(i, query()->fields(i).name, previous_columns_map[i].size); else horizontalHeader()->setLabel(i, query()->fields(i).name); if (columnsWindow->isVisible()) columnsWindow->refresh(); is_first = false; adjust = true; } uint j = 0; while (query()->next()) { for (uint i = 0; i < num_fields; i++) { const char * val = query()->row(i) ? query()->row(i) : NULL_TEXT; setText(j, i, val); } j++; } } else { if (is_first) { setNumRows(0); setNumCols(num_rows); int i = 0; while (query()->next()) horizontalHeader()->setLabel(i++, query()->row(0)); if (columnsWindow->isVisible()) columnsWindow->refresh(); is_first = false; adjust = true; query()->dataSeek(0); } setNumRows(numRows() + 1); ulong i = 0; while (query()->next()) { const char * val = query()->row(1) ? query()->row(1) : NULL_TEXT; setText(numRows() - 1, i++, val); } } if (adjust) for (int j = 0; j < numCols(); j++) adjustColumn(j); if (max_scroll) scroll = verticalScrollBar()->maxValue(); verticalScrollBar()->setValue(scroll); } setBlocked(false); applyLastSort(); }
QString CQueryTable::copy_data(int row, int col) { #ifdef DEBUG qDebug("CQueryTable::copy_data(int, int)"); #endif if (!query()) return QString::null; if (query()->isResultNull() || isBlocked()) return QString::null; if (currentSelection() == -1 && !forceCopyAll()) return copy_current_selection_func(row, col); else { QTableSelection sel; if (currentSelection() == -1 || forceCopyAll()) { sel.init(0, 0); sel.expandTo(numRows() -1, numCols() - 1); } else sel = selection(currentSelection()); if (sel.topRow() == sel.bottomRow() && sel.leftCol() == sel.rightCol() && !forceCopyAll()) return copy_current_selection_func(row, col); setBlocked(true); QString cpy; QString separator = "+"; int current_col; uint length; QMap<uint, ulong> max_length_map; QString tmp; for (current_col = sel.leftCol(); current_col <= sel.rightCol(); current_col++) { if (horizontalHeader()->sectionSize(current_col) <= 0) continue; length = strlen(query()->fields(current_col).name); length = max(length, query()->fields(current_col).max_length); if (length < strlen(NULL_TEXT) && !IS_NOT_NULL(query()->fields(current_col).flags)) length = strlen(NULL_TEXT); max_length_map.insert(current_col, length + 1); for (uint i = 0; i < min(max_length_map[current_col] - 1, MAX_COLUMN_LENGTH) + 2; i++) separator += "-"; separator += "+"; } separator += "\n"; cpy = separator + "|"; for (current_col = sel.leftCol(); current_col <= sel.rightCol(); current_col++) { if (horizontalHeader()->sectionSize(current_col) <= 0) continue; tmp.sprintf(" %-*s|",min((int) max_length_map[current_col], MAX_COLUMN_LENGTH), query()->fields(current_col).name); cpy += tmp; } cpy += "\n" + separator; copy_data_func(&cpy, query(), &sel, &max_length_map); setBlocked(false); return cpy + separator; } }