static void updateChangedSubEntriesCount( std::unordered_map<AccountID, SubEntriesChange>& subEntriesChange, std::shared_ptr<LedgerEntry const> const& current, std::shared_ptr<LedgerEntry const> const& previous) { auto valid = current ? current : previous; assert(valid); switch (valid->data.type()) { case ACCOUNT: { auto accountID = valid->data.account().accountID; auto& change = subEntriesChange[accountID]; change.numSubEntries = (current ? int32_t(current->data.account().numSubEntries) : 0) - (previous ? int32_t(previous->data.account().numSubEntries) : 0); change.signers = (current ? int32_t(current->data.account().signers.size()) : 0) - (previous ? int32_t(previous->data.account().signers.size()) : 0); change.calculatedSubEntries += change.signers; break; } case TRUSTLINE: { auto accountID = valid->data.trustLine().accountID; subEntriesChange[accountID].calculatedSubEntries += calculateDelta(current, previous); break; } case OFFER: { auto accountID = valid->data.offer().sellerID; subEntriesChange[accountID].calculatedSubEntries += calculateDelta(current, previous); break; } case DATA: { auto accountID = valid->data.data().accountID; subEntriesChange[accountID].calculatedSubEntries += calculateDelta(current, previous); break; } default: abort(); } }
//------------------------------------------------------------------------ CMouseEventResult CSlider::onMouseDown (CPoint& where, const CButtonState& buttons) { if (!(buttons & kLButton)) return kMouseEventNotHandled; CRect handleRect; delta = calculateDelta (where, getMode () != kFreeClickMode ? &handleRect : 0); if (getMode () == kTouchMode && !handleRect.pointInside (where)) return kMouseEventNotHandled; oldVal = getMin () - 1; oldButton = buttons; if ((getMode () == kRelativeTouchMode && handleRect.pointInside (where)) || getMode () != kRelativeTouchMode) { if (checkDefaultValue (buttons)) { return kMouseDownEventHandledButDontNeedMovedOrUpEvents; } } startVal = getValue (); beginEdit (); mouseStartPoint = where; if (buttons & kZoomModifier) return kMouseEventHandled; return onMouseMoved (where, buttons); }
// GameLoop void GameCore::startGameLoop() { try { while(running) { calculateDelta(); checkKeyPress(); // Show environment environment->update(camera->getPosition()); environment->draw(camera->getViewMatrix(),delta); // Camera position glm::vec3 pos = glm::vec3(camera->getPosition().x, 0.0f, camera->getPosition().z); camera->setPosition(pos); pos = this->environment->checkCollision(camera->getPosition()); camera->setPosition(pos); // Update window windowOpengl->update(); } } catch(const char* s) { throw s; } }
void display() { int delta = calculateDelta(); update(delta); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT); game.display(); glutSwapBuffers(); }
bool ConflictOnlyNE::commitMove(Move* mv) { firstMove = true; lastSuggested = suggested; Variable* var = mv->getVar(); std::vector<int>& evaluation = state->getEvaluation(); // Skal genberegne!!!!! bool legal = calculateDelta(mv); if (!legal) { return false; } var->setCurrentValue(1 - var->getCurrentValue()); propagation_queue queue = model->getPropagationQueue(var); for (updateType invar : queue) { invar->updateValue(); if (invar->representConstraint()) { if (invar->getCurrentValue() == 0) { if (invar->getInvariantPointers().back()->inViolatedConstraints()) { // std::unordered_map<unsigned, invariant>& vioCons = model->getViolatedConstraints(); model->removeViolatedConstraint(invar->getInvariantPointers().back()); } } else { if (!invar->getInvariantPointers().back()->inViolatedConstraints()) { // std::unordered_map<unsigned, invariant>& vioCons = model->getViolatedConstraints(); model->addViolatedConstraint(invar->getInvariantPointers().back()); // vioCons[invar->getInvariantPointers().back()->getID()] = invar->getInvariantPointers().back(); // invar->getInvariantPointers().back()->setInViolatedConstraints(true); } } } } for (unsigned i = 0; i < model->getEvaluationInvariants().size(); i++) { evaluation[i] = model->getEvaluationInvariantNr(i)->getCurrentValue(); } return true; }
//------------------------------------------------------------------------ CMouseEventResult CSlider::onMouseMoved (CPoint& where, const CButtonState& _buttons) { if (isEditing ()) { CButtonState buttons (_buttons); if (kAlwaysUseZoomFactor) buttons |= kZoomModifier; if (buttons & kLButton) { if (kAlwaysUseZoomFactor) { CCoord distance = fabs ((style & kHorizontal) ? where.y - mouseStartPoint.y : where.x - mouseStartPoint.x); float newZoomFactor = 1.f; if (distance > ((style & kHorizontal) ? getHeight () : getWidth ())) { newZoomFactor = (float)(distance / ((style & kHorizontal) ? getHeight () : getWidth ())); newZoomFactor = static_cast<int32_t>(newZoomFactor * 10.f) / 10.f; } if (zoomFactor != newZoomFactor) { zoomFactor = newZoomFactor; oldVal = (value - getMin ()) / getRange (); delta = calculateDelta (where); } } if (oldVal == getMin () - 1) oldVal = (value - getMin ()) / getRange (); if ((oldButton != buttons) && (buttons & kZoomModifier)) { oldVal = (value - getMin ()) / getRange (); oldButton = buttons; } else if (!(buttons & kZoomModifier)) oldVal = (value - getMin ()) / getRange (); float normValue; if (style & kHorizontal) normValue = (float)(where.x - delta) / (float)rangeHandle; else normValue = (float)(where.y - delta) / (float)rangeHandle; if (style & kRight || style & kBottom) normValue = 1.f - normValue; if (buttons & kZoomModifier) normValue = oldVal + ((normValue - oldVal) / zoomFactor); setValueNormalized (normValue); if (isDirty ()) { valueChanged (); invalid (); } } return kMouseEventHandled; } return kMouseEventNotHandled; }
bool IntSwapNeighborhood::commitMove(Move* mv) { moveCounter = 0; moveCounter2 = 0; Variable* var1 = mv->getVars().at(0); Variable* var2 = mv->getVars().at(1); std::vector<int>& evaluation = state->getEvaluation(); // Skal genberegne!!!!! bool legal = calculateDelta(mv); if (!legal) { return false; } var1->setCurrentValue(1 - var1->getCurrentValue()); var2->setCurrentValue(1 - var2->getCurrentValue()); propagation_queue& queue1 = model->getPropagationQueue(var1); propagation_queue& queue2 = model->getPropagationQueue(var2); // ######################################################### // Create queue by comparison // ######################################################### std::vector<updateType> queue; propagation_queue::iterator iter1 = queue1.begin(); propagation_queue::iterator iter2 = queue2.begin(); while (iter1 != queue1.end() || iter2 != queue2.end()) { if ((*iter1)->getTimestamp()> (*iter2)->getTimestamp()) { queue.push_back((*iter1)); iter1++; } else if ((*iter1)->getTimestamp() == (*iter2)->getTimestamp()) { queue.push_back((*iter1)); iter1++; iter2++; } else { queue.push_back(*iter2); iter2++; } } while (iter1 != queue1.end()) { queue.push_back(*iter1); iter1++; } while (iter2 != queue2.end()) { queue.push_back(*iter2); iter2++; } for (updateType invar : queue) { invar->updateValue(); if (invar->isUsedByConstraint()) { if (invar->getPriority() > 0) { std::shared_ptr<Constraint> cons = invar->getConstraint(); // model->getConstraintsWithPriority(invar->getPriority())->at(invar->getConstraintNumber()); evaluation.at(cons->getPriority()) += cons->updateViolation(); } else { evaluation.at(0) += invar->getDeltaValue(); } } } // testCounter++; return true; }
void FITSHistogramCommand::redo() { FITSView *image = tab->getView(); FITSData *image_data = image->getImageData(); uint8_t *image_buffer = image_data->getImageBuffer(); unsigned int size = image_data->getSize(); int channels = image_data->getNumOfChannels(); int BBP = image_data->getBytesPerPixel(); QApplication::setOverrideCursor(Qt::WaitCursor); if (delta != NULL) { double min,max,stddev,average,median,snr; min = image_data->getMin(); max = image_data->getMax(); stddev = image_data->getStdDev(); average = image_data->getMean(); median = image_data->getMedian(); snr = image_data->getSNR(); reverseDelta(); restoreStats(); saveStats(min, max, stddev, average, median, snr); } else { saveStats(image_data->getMin(), image_data->getMax(), image_data->getStdDev(), image_data->getMean(), image_data->getMedian(), image_data->getSNR()); // If it's rotation of flip, no need to calculate delta if (type >= FITS_ROTATE_CW && type <= FITS_FLIP_V) { image_data->applyFilter(type, image_buffer); } else { uint8_t *buffer = new uint8_t[size * channels * BBP]; if (buffer == NULL) { qWarning() << "Error! not enough memory to create image buffer in redo()" << endl; QApplication::restoreOverrideCursor(); return; } memcpy(buffer, image_buffer, size * channels * BBP); float dataMin = min, dataMax = max; switch (type) { case FITS_AUTO: case FITS_LINEAR: image_data->applyFilter(FITS_LINEAR, NULL, &dataMin, &dataMax); break; case FITS_LOG: image_data->applyFilter(FITS_LOG, NULL, &dataMin, &dataMax); break; case FITS_SQRT: image_data->applyFilter(FITS_SQRT, NULL, &dataMin, &dataMax); break; default: image_data->applyFilter(type); break; } calculateDelta(buffer); delete [] buffer; } } if (histogram != NULL) { histogram->constructHistogram(); if (tab->getViewer()->isStarsMarked()) image_data->findStars(); } image->pushFilter(type); image->rescale(ZOOM_KEEP_LEVEL); image->updateFrame(); QApplication::restoreOverrideCursor(); }