uint8_t ZIPPKCracker::initKeys(ZIPKeys* keys, const unsigned char* passwd, uint32_t len, uint8_t rndBuf[]){ keys->key0 = 0x12345678; keys->key1 = 0x23456789; keys->key2 = 0x34567890; for(uint32_t i = 0;i<len;i++){ updateKeys(keys,passwd[i]); } uint8_t C = 0; for(uint8_t i = 0;i<12;i++){ C = rndBuf[i] ^ decryptByte(keys); updateKeys(keys,C); } return C; }
void HexagonGame::update(float mFrameTime) { if(!hasDied) { manager.update(mFrameTime); updateLevelEvents(mFrameTime); if(timeStop <= 0) { currentTime += mFrameTime / 60.0f; incrementTime += mFrameTime / 60.0f; } else timeStop -= 1 * mFrameTime; updateIncrement(); updateLevel(mFrameTime); updateRadius(mFrameTime); if(!getBlackAndWhite()) styleData.update(mFrameTime); } else setRotationSpeed(getRotationSpeed() / 1.001f); updateKeys(); if(!getNoRotation()) updateRotation(mFrameTime); if(mustRestart) newGame(levelData.getId(), false); }
void CSecondaryScreen::remoteControl() { // assume primary has all clipboards for (ClipboardID id = 0; id < kClipboardEnd; ++id) { grabClipboard(id); } // update keyboard state updateKeys(); // now remote ready. fake being active for call to leave(). bool screenSaverSync; { CLock lock(&m_mutex); m_remoteReady = true; m_active = true; // copy screen saver synchronization state screenSaverSync = m_screenSaverSync; } // disable the screen saver if synchronization is enabled if (screenSaverSync) { getScreen()->openScreensaver(false); } // hide the cursor leave(); }
Options::Options(QWidget *parent) : QWidget(parent) , ui(new Ui::Options) { ui->setupUi(this); Model *model = new Model(this); ui->keys->setModel(model); updateKeys(); // Import key QAction *action; QMenu *menu = new QMenu(this); action = menu->addAction(trUtf8("from file")); connect(action, SIGNAL(triggered()), SLOT(importKeyFromFile())); action = menu->addAction(trUtf8("from clipboard")); connect(action, SIGNAL(triggered()), SLOT(importKeyFromClipboard())); ui->btnImport->setMenu(menu); // Export key menu = new QMenu(this); action = menu->addAction(trUtf8("to file")); connect(action, SIGNAL(triggered()), SLOT(exportKeyToFile())); ui->btnExport->addAction(action); action = menu->addAction(trUtf8("to clipboard")); connect(action, SIGNAL(triggered()), SLOT(exportKeyToClipboard())); ui->btnExport->setMenu(menu); }
static int updateUsbKeys (BrailleDisplay *brl) { while (1) { unsigned char packet[8]; { ssize_t result = gioReadData(brl->gioEndpoint, packet, sizeof(packet), 0); if (!result) return 1; if (result < 0) { if (errno == ENODEV) { /* Display was disconnected */ return 0; } logMessage(LOG_ERR, "USB read error: %s", strerror(errno)); keysInitialized = 0; return 1; } if (result < sizeof(packet)) { /* The display should only ever deliver packets of exactly 8 bytes */ logPartialPacket(packet, result); keysInitialized = 0; return 1; } logInputPacket(packet, result); } updateKeys(brl, packet); } }
void CSecondaryScreen::enter(SInt32 x, SInt32 y, KeyModifierMask mask) { CLock lock(&m_mutex); assert(m_active == false); LOG((CLOG_INFO "entering screen at %d,%d mask=%04x", x, y, mask)); getScreen()->syncDesktop(); // now active m_active = true; // subclass hook onPreEnter(); // update our keyboard state to reflect the local state updateKeys(); // remember toggle key state m_toggleKeys = getToggleState(); // toggle modifiers that don't match the desired state setToggleState(mask); // warp to requested location warpCursor(x, y); // show mouse hideWindow(); // subclass hook onPostEnter(); }
void QrSqlElement::clone(QrSqlElement * other) { if (! other) { return; } listColumns = other->listColumns; listValues = other->listValues; updateKeys(); }
void InputManager::update() { // Loop throug _keyMap using a for each loop, and copy it over to _previousKeyMap for (auto& it : _keyMap) { _previousKeyMap[it.first] = it.second; } updateMouse(); updateKeys(); }
static int updateSerialKeys (BrailleDisplay *brl) { const unsigned char code = 0X4B; unsigned char packet[9]; while (nextSerialPacket(brl, code, packet, sizeof(packet), 0)) { updateKeys(brl, &packet[1]); } return errno == EAGAIN; }
void handleMessages() { MSG msg; msg.message = NULL; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } updateKeys(); }
void MythUIVirtualKeyboard::lockClicked(void) { m_lock = !m_lock; m_shift = m_lock; if (m_shiftLButton) m_shiftLButton->SetLocked(m_shift); if (m_shiftRButton) m_shiftRButton->SetLocked(m_shift); updateKeys(); }
void app::start(){ //std::thread t(&app::updateKeys,this); //drawing updateKeys(); _GLSLstuffs["pics"]->use(); glActiveTexture(GL_TEXTURE0); GLint textlocate=_GLSLstuffs["pics"]->getUniformLocate("Text"); glUniform1i(textlocate,0); GLint camLocate=_GLSLstuffs["pics"]->getUniformLocate("orthiMat"); glm::mat4 abc = camera.getCamMatrix(); glUniformMatrix4fv(camLocate,1,GL_FALSE,&abc[0][0]); //t.join(); _spriteBatch.begin(); }
void MythUIVirtualKeyboard::shiftClicked(void) { m_shift = !m_shift; if (m_shiftLButton) m_shiftLButton->SetLocked(m_shift); if (m_shiftRButton) m_shiftRButton->SetLocked(m_shift); if (m_lockButton && m_lock) { m_lockButton->SetLocked(false); m_lock = false; } updateKeys(); }
TransferFunction TransferFunction::toNewRange(double oldX1, double oldX2, double newX1, double newX2) const { Q_ASSERT(!MathTools::isNaN(oldX1)); Q_ASSERT(!MathTools::isNaN(oldX2)); Q_ASSERT(oldX1 < oldX2); Q_ASSERT(!MathTools::isNaN(newX1)); Q_ASSERT(!MathTools::isNaN(newX2)); Q_ASSERT(newX1 < newX2); updateKeys(); double scale = (newX2 - newX1) / (oldX2 - oldX1); TransferFunction newRangetransferFunction; foreach (double x, m_keys) { newRangetransferFunction.set((x - oldX1) * scale + newX1, getColor(x), getScalarOpacity(x)); }
QList<double> TransferFunction::keys(double begin, double end) const { Q_ASSERT(!MathTools::isNaN(begin)); Q_ASSERT(!MathTools::isNaN(end)); Q_ASSERT(begin <= end); updateKeys(); QList<double>::const_iterator lowerBound = qLowerBound(m_keys, begin); QList<double>::const_iterator itEnd = m_keys.constEnd(); QList<double> keys; while (lowerBound != itEnd && *lowerBound <= end) { keys << *(lowerBound++); } return keys; }
/****************************************************************************** * Moves the keys in the given set by the given time shift. ******************************************************************************/ void KeyframeController::moveKeys(const QVector<AnimationKey*> keysToMove, TimePoint shift) { if(shift == 0) return; // First, remove the selected keys from the controller. QVector<OORef<AnimationKey>> removedKeys; for(AnimationKey* key : keysToMove) { int index = keys().indexOf(key); if(index >= 0) { removedKeys.push_back(key); _keys.remove(index); } } // Change times and re-insert keys into the controller. for(const OORef<AnimationKey>& key : removedKeys) { key->setTime(key->time() + shift); insertKey(key.get()); } updateKeys(); }
void main(int argc, char **argv) { char pwd[100] = "gustavo"; int pwdLen, i; FILE *ptr; int c; int count2 = 0; ptr = fopen("10k_most_common.txt","r"); pwdLen = strlen( pwd ); mkCrcTab( ); initkeys( ); initMulTab(); while(!feof(ptr)) { key0=KEY0INIT; key1=KEY1INIT; key2=KEY2INIT; //printf( "%08x %08x %08x\n", key0, key1, key2 ); i = 0; c = fgetc(ptr); do { pwd[i] = (char)c; i++; c = fgetc(ptr); } while(c!='\n'); pwd[i] = '\0'; pwdLen = i-1; if(count2%100==0) { printf("%s\n", pwd); printf("%d\n", count2); } for( i = 0; i < pwdLen; i++ ) updateKeys( pwd[i] ); //printf( "%08x %08x %08x\n", key0, key1, key2 ); findPwd( key0, key1, key2 ); count2++; } fclose(ptr); }
void AWKeyOperations::reinitKeys() { m_customKeys->initItems(); m_graphicalItems->initItems(); m_extNetRequest->initItems(); m_extQuotes->initItems(); m_extScripts->initItems(); m_extUpgrade->initItems(); m_extWeather->initItems(); // init QStringList allKeys = dictKeys(); // apply aw_* functions m_pattern = AWPatternFunctions::insertAllKeys(m_pattern, allKeys); m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys); m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys); m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys); m_pattern = AWPatternFunctions::insertMacros(m_pattern); // wrap templates m_pattern = AWPatternFunctions::expandTemplates(m_pattern); emit(updateKeys(allKeys)); }
/****************************************************************************** * Deletes the given set of keys from the controller. ******************************************************************************/ void KeyframeController::deleteKeys(const QVector<AnimationKey*> keysToDelete) { for(AnimationKey* key : keysToDelete) key->deleteReferenceObject(); updateKeys(); }
void MythUIVirtualKeyboard::altClicked(void) { m_alt = !m_alt; updateKeys(); }
void Options::addKey() { AddKeyDlg dlg(this); if (dlg.exec() == QDialog::Rejected) { return; } QString key; QString type, stype, length, name, comment, email, expiration, pass; switch (dlg.type()) { case 0: type = stype = "RSA"; break; case 1: type = "DSA"; stype = "ELG-E"; break; case 2: type = "DSA"; break; case 3: type = "RSA"; break; } length = QString::number(dlg.length()); name = dlg.name(); comment = dlg.comment(); email = dlg.email(); expiration = dlg.expiration().isValid() ? dlg.expiration().toString(Qt::ISODate) : "0"; pass = dlg.pass(); key += QString("Key-Type: %1\n").arg(type); key += QString("Key-Length: %2\n").arg(length); if (!stype.isEmpty()) { key += QString("Subkey-Type: %1\n").arg(stype); key += QString("Subkey-Length: %2\n").arg(length); } if (!name.isEmpty()) { key += QString("Name-Real: %1\n").arg(name); } if (!comment.isEmpty()) { key += QString("Name-Comment: %1\n").arg(comment); } if (!email.isEmpty()) { key += QString("Name-Email: %1\n").arg(email); } key += QString("Expire-Date: %1\n").arg(expiration); if (!pass.isEmpty()) { key += QString("Passphrase: %1\n").arg(pass); } key += "%commit\n"; QProgressDialog waitingDlg("", trUtf8("Cancel"), 0, 0, this); QLabel progressTextLabel(trUtf8( "<b>Please wait!</b><br/>" "We need to generate a lot of random bytes. It is a good idea to perform " "some other action (type on the keyboard, move the mouse, utilize the " "disks) during the prime generation; this gives the random number " "generator a better chance to gain enough entropy."), &waitingDlg); progressTextLabel.setAlignment(Qt::AlignHCenter); progressTextLabel.setWordWrap(true); waitingDlg.setLabel(&progressTextLabel); QProgressBar progressBar(&waitingDlg); progressBar.setAlignment(Qt::AlignHCenter); progressBar.setMinimum(0); progressBar.setMaximum(0); waitingDlg.setBar(&progressBar); waitingDlg.setWindowModality(Qt::WindowModal); waitingDlg.setWindowTitle(trUtf8("Key pair generating")); waitingDlg.show(); GpgProcess gpg; QStringList arguments; arguments << "--batch" << "--gen-key"; gpg.start(arguments); gpg.waitForStarted(); gpg.write(key.toUtf8()); gpg.closeWriteChannel(); while (gpg.state() == QProcess::Running) { gpg.waitForFinished(1); if (waitingDlg.wasCanceled()) { gpg.terminate(); break; } qApp->processEvents(); } updateKeys(); }
void QrSqlElement::setColumn(const QString & column) { listColumns.clear(); listColumns.append(column); updateKeys(); }
void QrSqlElement::setColumns(const QStringList & columns) { listColumns.clear(); listColumns = columns; updateKeys(); }
bool MythUIVirtualKeyboard::Create() { if (!LoadWindowFromXML("keyboard/keyboard.xml", "keyboard", this)) return false; BuildFocusList(); loadKeyDefinitions(gCoreContext->GetLanguageAndVariant()); updateKeys(true); int screenWidth, screenHeight; float xmult, ymult; GetMythUI()->GetScreenSettings(screenWidth, xmult, screenHeight, ymult); MythRect editArea = m_parentEdit->GetArea(); MythRect area = GetArea(); MythPoint newPos; //FIXME this assumes the edit is a direct child of the parent screen MythUIType *parentScreen = NULL; parentScreen = dynamic_cast<MythUIType *>(m_parentEdit->parent()); if (parentScreen) { editArea.moveTopLeft(QPoint(editArea.x() + parentScreen->GetArea().x(), editArea.y() + parentScreen->GetArea().y())); } switch (m_preferredPos) { case VK_POSABOVEEDIT: if (editArea.y() - area.height() - 5 > 0) { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() - area.height() - 5); } else { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() + editArea.height() + 5); } break; case VK_POSTOPDIALOG: newPos = QPoint(screenWidth / 2 - area.width() / 2, 5); break; case VK_POSBOTTOMDIALOG: newPos = QPoint(screenWidth / 2 - area.width() / 2, screenHeight - 5 - area.height()); break; case VK_POSCENTERDIALOG: newPos = QPoint(screenWidth / 2 - area.width() / 2, screenHeight / 2 - area.height() / 2); break; default: // VK_POSBELOWEDIT if (editArea.y() + editArea.height() + area.height() + 5 < screenHeight) { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() + editArea.height() + 5); } else { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() - area.height() - 5); } break; } // make sure the popup doesn't go off screen if (newPos.x() < 5) newPos.setX(5); if (newPos.x() + area.width() + 5 > screenWidth) newPos.setX(screenWidth - area.width() - 5); if (newPos.y() < 5) newPos.setY(5); if (newPos.y() + area.height() + 5 > screenHeight) newPos.setY(screenHeight - area.height() - 5); SetPosition(newPos); return true; }
void MythUIVirtualKeyboard::charClicked(void) { if (!GetFocusWidget()) return; KeyDefinition key = m_keyMap.value(GetFocusWidget()->objectName()); QString c = getKeyText(key); if (m_composing) { if (m_composeStr.isEmpty()) m_composeStr = c; else { // Produce the composed key. for (int i = 0; i < numcomps; i++) { if ((m_composeStr == comps[i][0]) && (c == comps[i][1])) { c = comps[i][2]; emit keyPressed(c); if (m_parentEdit) { QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, c); m_parentEdit->keyPressEvent(event); } break; } } m_composeStr.clear(); m_composing = false; if (m_compButton) m_compButton->SetLocked(false); } } else { emit keyPressed(c); if (m_parentEdit) { QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, c); m_parentEdit->keyPressEvent(event); } if (m_shift && !m_lock) { m_shift = false; if (m_shiftLButton) m_shiftLButton->SetLocked(false); if (m_shiftRButton) m_shiftRButton->SetLocked(false); updateKeys(); } } }
const QList<double>& TransferFunction::keys() const { updateKeys(); return m_keys; }
bool CXWindowsPrimaryScreen::onEvent(CEvent* event) { assert(event != NULL); XEvent& xevent = event->m_event; // let input methods try to handle event first if (m_ic != NULL) { // XFilterEvent() may eat the event and generate a new KeyPress // event with a keycode of 0 because there isn't an actual key // associated with the keysym. but the KeyRelease may pass // through XFilterEvent() and keep its keycode. this means // there's a mismatch between KeyPress and KeyRelease keycodes. // since we use the keycode on the client to detect when a key // is released this won't do. so we remember the keycode on // the most recent KeyPress (and clear it on a matching // KeyRelease) so we have a keycode for a synthesized KeyPress. if (xevent.type == KeyPress && xevent.xkey.keycode != 0) { m_lastKeycode = xevent.xkey.keycode; } else if (xevent.type == KeyRelease && xevent.xkey.keycode == m_lastKeycode) { m_lastKeycode = 0; } // now filter the event if (XFilterEvent(&xevent, None)) { return true; } } // handle event switch (xevent.type) { case CreateNotify: { // select events on new window CDisplayLock display(m_screen); selectEvents(display, xevent.xcreatewindow.window); } return true; case MappingNotify: // keyboard mapping changed updateKeys(); return true; case KeyPress: { LOG((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state)); const KeyModifierMask mask = mapModifier(xevent.xkey.state); KeyID key = mapKey(&xevent.xkey); if (key != kKeyNone) { // check for ctrl+alt+del emulation if ((key == kKeyPause || key == kKeyBreak) && (mask & (KeyModifierControl | KeyModifierAlt)) == (KeyModifierControl | KeyModifierAlt)) { // pretend it's ctrl+alt+del LOG((CLOG_DEBUG "emulate ctrl+alt+del")); key = kKeyDelete; } // get which button. see call to XFilterEvent() above // for more info. KeyCode keycode = xevent.xkey.keycode; if (keycode == 0) { keycode = m_lastKeycode; } // handle key m_receiver->onKeyDown(key, mask, static_cast<KeyButton>(keycode)); if (key == kKeyCapsLock && m_capsLockHalfDuplex) { m_receiver->onKeyUp(key, mask | KeyModifierCapsLock, static_cast<KeyButton>(keycode)); } else if (key == kKeyNumLock && m_numLockHalfDuplex) { m_receiver->onKeyUp(key, mask | KeyModifierNumLock, static_cast<KeyButton>(keycode)); } } } return true; case KeyRelease: { const KeyModifierMask mask = mapModifier(xevent.xkey.state); KeyID key = mapKey(&xevent.xkey); if (key != kKeyNone) { // check if this is a key repeat by getting the next // KeyPress event that has the same key and time as // this release event, if any. first prepare the // filter info. CKeyEventInfo filter; filter.m_event = KeyPress; filter.m_window = xevent.xkey.window; filter.m_time = xevent.xkey.time; filter.m_keycode = xevent.xkey.keycode; // now check for event bool hasPress; { XEvent xevent2; CDisplayLock display(m_screen); hasPress = (XCheckIfEvent(display, &xevent2, &CXWindowsPrimaryScreen::findKeyEvent, (XPointer)&filter) == True); } // check for ctrl+alt+del emulation if ((key == kKeyPause || key == kKeyBreak) && (mask & (KeyModifierControl | KeyModifierAlt)) == (KeyModifierControl | KeyModifierAlt)) { // pretend it's ctrl+alt+del and ignore autorepeat LOG((CLOG_DEBUG "emulate ctrl+alt+del")); key = kKeyDelete; hasPress = false; } if (!hasPress) { // no press event follows so it's a plain release LOG((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state)); if (key == kKeyCapsLock && m_capsLockHalfDuplex) { m_receiver->onKeyDown(key, mask, static_cast<KeyButton>(xevent.xkey.keycode)); } else if (key == kKeyNumLock && m_numLockHalfDuplex) { m_receiver->onKeyDown(key, mask, static_cast<KeyButton>(xevent.xkey.keycode)); } m_receiver->onKeyUp(key, mask, static_cast<KeyButton>(xevent.xkey.keycode)); } else { // found a press event following so it's a repeat. // we could attempt to count the already queued // repeats but we'll just send a repeat of 1. // note that we discard the press event. LOG((CLOG_DEBUG1 "event: repeat code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state)); m_receiver->onKeyRepeat(key, mask, 1, static_cast<KeyButton>(xevent.xkey.keycode)); } } } return true; case ButtonPress: { LOG((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button)); const ButtonID button = mapButton(xevent.xbutton.button); if (button != kButtonNone) { m_receiver->onMouseDown(button); } } return true; case ButtonRelease: { LOG((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button)); const ButtonID button = mapButton(xevent.xbutton.button); if (button != kButtonNone) { m_receiver->onMouseUp(button); } else if (xevent.xbutton.button == 4) { // wheel forward (away from user) m_receiver->onMouseWheel(120); } else if (xevent.xbutton.button == 5) { // wheel backward (toward user) m_receiver->onMouseWheel(-120); } } return true; case MotionNotify: { LOG((CLOG_DEBUG2 "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root)); // compute motion delta (relative to the last known // mouse position) SInt32 x = xevent.xmotion.x_root - m_x; SInt32 y = xevent.xmotion.y_root - m_y; // save position to compute delta of next motion m_x = xevent.xmotion.x_root; m_y = xevent.xmotion.y_root; if (xevent.xmotion.send_event) { // we warped the mouse. discard events until we // find the matching sent event. see // warpCursorNoFlush() for where the events are // sent. we discard the matching sent event and // can be sure we've skipped the warp event. CDisplayLock display(m_screen); do { XMaskEvent(display, PointerMotionMask, &xevent); } while (!xevent.xmotion.send_event); } else if (!isActive()) { // motion on primary screen m_receiver->onMouseMovePrimary(m_x, m_y); } else { // motion on secondary screen. warp mouse back to // center. // // my lombard (powerbook g3) running linux and // using the adbmouse driver has two problems: // first, the driver only sends motions of +/-2 // pixels and, second, it seems to discard some // physical input after a warp. the former isn't a // big deal (we're just limited to every other // pixel) but the latter is a PITA. to work around // it we only warp when the mouse has moved more // than s_size pixels from the center. static const SInt32 s_size = 32; if (xevent.xmotion.x_root - m_xCenter < -s_size || xevent.xmotion.x_root - m_xCenter > s_size || xevent.xmotion.y_root - m_yCenter < -s_size || xevent.xmotion.y_root - m_yCenter > s_size) { CDisplayLock display(m_screen); warpCursorNoFlush(display, m_xCenter, m_yCenter); } // send event if mouse moved. do this after warping // back to center in case the motion takes us onto // the primary screen. if we sent the event first // in that case then the warp would happen after // warping to the primary screen's enter position, // effectively overriding it. if (x != 0 || y != 0) { m_receiver->onMouseMoveSecondary(x, y); } } } return true; } return false; }
float UCBVHaarSingleStumpLearner::run() { if ( UCBVHaarSingleStumpLearner::_numOfCalling == 0 ) { init(); } UCBVHaarSingleStumpLearner::_numOfCalling++; //cout << "Num of iter:\t" << UCBVHaarSingleStumpLearner::_numOfCalling << " " << this->getTthSeriesElement( UCBVHaarSingleStumpLearner::_numOfCalling ) << flush << endl; const int numClasses = _pTrainingData->getNumClasses(); // set the smoothing value to avoid numerical problem // when theta=0. setSmoothingVal( 1.0 / (float)_pTrainingData->getNumExamples() * 0.01 ); vector<sRates> mu(numClasses); // The class-wise rates. See BaseLearner::sRates for more info. vector<float> tmpV(numClasses); // The class-wise votes/abstentions float tmpThreshold; float tmpAlpha; float bestEnergy = numeric_limits<float>::max(); float tmpEnergy; HaarData* pHaarData = static_cast<HaarData*>(_pTrainingData); // get the whole data matrix //const vector<int*>& intImages = pHaarData->getIntImageVector(); // The data matrix transformed into the feature's space vector< pair<int, float> > processedHaarData(_pTrainingData->getNumExamples()); // I need to prepare both type of sampling StumpAlgorithm<float> sAlgo(numClasses); sAlgo.initSearchLoop(_pTrainingData); float halfTheta; if ( _abstention == ABST_REAL || _abstention == ABST_CLASSWISE ) halfTheta = _theta/2.0; else halfTheta = 0; // The declared features types vector<HaarFeature*>& loadedFeatures = pHaarData->getLoadedFeatures(); // for every feature type vector<HaarFeature*>::iterator ftIt; //vector<HaarFeature*>::iterator maxftIt; vector<float> maxV( loadedFeatures.size() ); vector<int> maxKey( loadedFeatures.size() ); vector<int> maxNum( loadedFeatures.size() ); //claculate the Bk,s,t of the randomly chosen features int key = getKeyOfMaximalElement(); int featureIdx = (int) (key / 10); int featureType = (key % 10); //for (i = 0, ftIt = loadedFeatures.begin(); ftIt != loadedFeatures.end(); i++ ++ftIt) //*ftIt = loadedFeatures[ featureType ]; // just for readability //HaarFeature* pCurrFeature = *ftIt; HaarFeature* pCurrFeature = loadedFeatures[ featureType ]; if (_samplingType != ST_NO_SAMPLING) pCurrFeature->setAccessType(AT_RANDOM_SAMPLING); // Reset the iterator on the configurations. For random sampling // this clear the visited list pCurrFeature->loadConfigByNum( featureIdx ); if (_verbose > 1) cout << "Learning type " << pCurrFeature->getName() << ".." << flush; // transform the data from intImages to the feature's space pCurrFeature->fillHaarData( _pTrainingData->getExamples(), processedHaarData ); //pCurrFeature->fillHaarData(intImages, processedHaarData); // sort the examples in the new space by their coordinate sort( processedHaarData.begin(), processedHaarData.end(), nor_utils::comparePair<2, int, float, less<float> >() ); // find the optimal threshold tmpThreshold = sAlgo.findSingleThresholdWithInit(processedHaarData.begin(), processedHaarData.end(), _pTrainingData, halfTheta, &mu, &tmpV); tmpEnergy = getEnergy(mu, tmpAlpha, tmpV); // Store it in the current weak hypothesis. // note: I don't really like having so many temp variables // but the alternative would be a structure, which would need // to be inheritable to make things more consistent. But this would // make it less flexible. Therefore, I am still undecided. This // might change! _alpha = tmpAlpha; _v = tmpV; // I need to save the configuration because it changes within the object _selectedConfig = pCurrFeature->getCurrentConfig(); // I save the object because it contains the informations about the type, // the name, etc.. _pSelectedFeature = pCurrFeature; _threshold = tmpThreshold; bestEnergy = tmpEnergy; float edge = 0.0; for( vector<sRates>::iterator itR = mu.begin(); itR != mu.end(); itR++ ) edge += ( itR->rPls - itR->rMin ); //need to set the X value updateKeys( key, edge * edge ); if (!_pSelectedFeature) { cerr << "ERROR: No Haar Feature found. Something must be wrong!" << endl; exit(1); } else { if (_verbose > 1) cout << "Selected type: " << _pSelectedFeature->getName() << endl; } return bestEnergy; }
static void common_drive(int index, tCarElt* car, tSituation *s) { tdble slip; tdble ax0; tdble brake; tdble clutch; tdble throttle; tdble leftSteer; tdble rightSteer; int scrw, scrh, dummy; int idx = index - 1; tControlCmd *cmd = HCtx[idx]->CmdControl; const int BUFSIZE = 1024; char sstring[BUFSIZE]; static int firstTime = 1; if (firstTime) { if (HCtx[idx]->MouseControlUsed) { GfuiMouseShow(); GfctrlMouseInitCenter(); } GfuiKeyEventRegisterCurrent(onKeyAction); GfuiSKeyEventRegisterCurrent(onSKeyAction); firstTime = 0; } HCtx[idx]->distToStart = RtGetDistFromStart(car); HCtx[idx]->Gear = (tdble)car->_gear; /* telemetry */ GfScrGetSize(&scrw, &scrh, &dummy, &dummy); memset(&(car->ctrl), 0, sizeof(tCarCtrl)); car->_lightCmd = HCtx[idx]->lightCmd; if (car->_laps != HCtx[idx]->LastPitStopLap) { car->_raceCmd = RM_CMD_PIT_ASKED; } if (lastKeyUpdate != s->currentTime) { /* Update the controls only once for all the players */ updateKeys(); if (joyPresent) { GfctrlJoyGetCurrent(joyInfo); } GfctrlMouseGetCurrent(mouseInfo); lastKeyUpdate = s->currentTime; } if (((cmd[CMD_ABS].type == GFCTRL_TYPE_JOY_BUT) && joyInfo->edgeup[cmd[CMD_ABS].val]) || ((cmd[CMD_ABS].type == GFCTRL_TYPE_KEYBOARD) && keyInfo[cmd[CMD_ABS].val].edgeUp) || ((cmd[CMD_ABS].type == GFCTRL_TYPE_SKEYBOARD) && skeyInfo[cmd[CMD_ABS].val].edgeUp)) { HCtx[idx]->ParamAbs = 1 - HCtx[idx]->ParamAbs; snprintf(sstring, BUFSIZE, "%s/%s/%d", HM_SECT_PREF, HM_LIST_DRV, index); GfParmSetStr(PrefHdle, sstring, HM_ATT_ABS, Yn[1 - HCtx[idx]->ParamAbs]); GfParmWriteFile(NULL, PrefHdle, "Human"); } if (((cmd[CMD_ASR].type == GFCTRL_TYPE_JOY_BUT) && joyInfo->edgeup[cmd[CMD_ASR].val]) || ((cmd[CMD_ASR].type == GFCTRL_TYPE_KEYBOARD) && keyInfo[cmd[CMD_ASR].val].edgeUp) || ((cmd[CMD_ASR].type == GFCTRL_TYPE_SKEYBOARD) && skeyInfo[cmd[CMD_ASR].val].edgeUp)) { HCtx[idx]->ParamAsr = 1 - HCtx[idx]->ParamAsr; snprintf(sstring, BUFSIZE, "%s/%s/%d", HM_SECT_PREF, HM_LIST_DRV, index); GfParmSetStr(PrefHdle, sstring, HM_ATT_ASR, Yn[1 - HCtx[idx]->ParamAsr]); GfParmWriteFile(NULL, PrefHdle, "Human"); } const int bufsize = sizeof(car->_msgCmd[0]); snprintf(car->_msgCmd[0], bufsize, "%s %s", (HCtx[idx]->ParamAbs ? "ABS" : ""), (HCtx[idx]->ParamAsr ? "ASR" : "")); memcpy(car->_msgColorCmd, color, sizeof(car->_msgColorCmd)); if (((cmd[CMD_SPDLIM].type == GFCTRL_TYPE_JOY_BUT) && (joyInfo->levelup[cmd[CMD_SPDLIM].val] == 1)) || ((cmd[CMD_SPDLIM].type == GFCTRL_TYPE_KEYBOARD) && (keyInfo[cmd[CMD_SPDLIM].val].state == GFUI_KEY_DOWN)) || ((cmd[CMD_SPDLIM].type == GFCTRL_TYPE_SKEYBOARD) && (skeyInfo[cmd[CMD_SPDLIM].val].state == GFUI_KEY_DOWN))) { speedLimiter = 1; snprintf(car->_msgCmd[1], bufsize, "Speed Limiter On"); } else { speedLimiter = 0; snprintf(car->_msgCmd[1], bufsize, "Speed Limiter Off"); } if (((cmd[CMD_LIGHT1].type == GFCTRL_TYPE_JOY_BUT) && joyInfo->edgeup[cmd[CMD_LIGHT1].val]) || ((cmd[CMD_LIGHT1].type == GFCTRL_TYPE_KEYBOARD) && keyInfo[cmd[CMD_LIGHT1].val].edgeUp) || ((cmd[CMD_LIGHT1].type == GFCTRL_TYPE_SKEYBOARD) && skeyInfo[cmd[CMD_LIGHT1].val].edgeUp)) { if (HCtx[idx]->lightCmd & RM_LIGHT_HEAD1) { HCtx[idx]->lightCmd &= ~(RM_LIGHT_HEAD1 | RM_LIGHT_HEAD2); } else { HCtx[idx]->lightCmd |= RM_LIGHT_HEAD1 | RM_LIGHT_HEAD2; } } switch (cmd[CMD_LEFTSTEER].type) { case GFCTRL_TYPE_JOY_AXIS: ax0 = joyInfo->ax[cmd[CMD_LEFTSTEER].val] + cmd[CMD_LEFTSTEER].deadZone; if (ax0 > cmd[CMD_LEFTSTEER].max) { ax0 = cmd[CMD_LEFTSTEER].max; } else if (ax0 < cmd[CMD_LEFTSTEER].min) { ax0 = cmd[CMD_LEFTSTEER].min; } // normalize ax0 to -1..0 ax0 = (ax0 - cmd[CMD_LEFTSTEER].max) / (cmd[CMD_LEFTSTEER].max - cmd[CMD_LEFTSTEER].min); leftSteer = -SIGN(ax0) * cmd[CMD_LEFTSTEER].pow * pow(fabs(ax0), cmd[CMD_LEFTSTEER].sens) / (1.0 + cmd[CMD_LEFTSTEER].spdSens * car->pub.speed); break; case GFCTRL_TYPE_MOUSE_AXIS: ax0 = mouseInfo->ax[cmd[CMD_LEFTSTEER].val] - cmd[CMD_LEFTSTEER].deadZone; //FIXME: correct? if (ax0 > cmd[CMD_LEFTSTEER].max) { ax0 = cmd[CMD_LEFTSTEER].max; } else if (ax0 < cmd[CMD_LEFTSTEER].min) { ax0 = cmd[CMD_LEFTSTEER].min; } ax0 = ax0 * cmd[CMD_LEFTSTEER].pow; leftSteer = pow(fabs(ax0), cmd[CMD_LEFTSTEER].sens) / (1.0 + cmd[CMD_LEFTSTEER].spdSens * car->pub.speed / 10.0); break; case GFCTRL_TYPE_KEYBOARD: case GFCTRL_TYPE_SKEYBOARD: case GFCTRL_TYPE_JOY_BUT: if (cmd[CMD_LEFTSTEER].type == GFCTRL_TYPE_KEYBOARD) { ax0 = keyInfo[cmd[CMD_LEFTSTEER].val].state; } else if (cmd[CMD_LEFTSTEER].type == GFCTRL_TYPE_SKEYBOARD) { ax0 = skeyInfo[cmd[CMD_LEFTSTEER].val].state; } else { ax0 = joyInfo->levelup[cmd[CMD_LEFTSTEER].val]; } if (ax0 == 0) { HCtx[idx]->prevLeftSteer = leftSteer = 0; } else { ax0 = 2 * ax0 - 1; leftSteer = HCtx[idx]->prevLeftSteer + ax0 * cmd[CMD_LEFTSTEER].sens * s->deltaTime / (1.0 + cmd[CMD_LEFTSTEER].spdSens * car->pub.speed / 10.0); if (leftSteer > 1.0) leftSteer = 1.0; if (leftSteer < 0.0) leftSteer = 0.0; HCtx[idx]->prevLeftSteer = leftSteer; } break; default: leftSteer = 0; break; } switch (cmd[CMD_RIGHTSTEER].type) { case GFCTRL_TYPE_JOY_AXIS: ax0 = joyInfo->ax[cmd[CMD_RIGHTSTEER].val] - cmd[CMD_RIGHTSTEER].deadZone; if (ax0 > cmd[CMD_RIGHTSTEER].max) { ax0 = cmd[CMD_RIGHTSTEER].max; } else if (ax0 < cmd[CMD_RIGHTSTEER].min) { ax0 = cmd[CMD_RIGHTSTEER].min; } // normalize ax to 0..1 ax0 = (ax0 - cmd[CMD_RIGHTSTEER].min) / (cmd[CMD_RIGHTSTEER].max - cmd[CMD_RIGHTSTEER].min); rightSteer = -SIGN(ax0) * cmd[CMD_RIGHTSTEER].pow * pow(fabs(ax0), cmd[CMD_RIGHTSTEER].sens) / (1.0 + cmd[CMD_RIGHTSTEER].spdSens * car->pub.speed); break; case GFCTRL_TYPE_MOUSE_AXIS: ax0 = mouseInfo->ax[cmd[CMD_RIGHTSTEER].val] - cmd[CMD_RIGHTSTEER].deadZone; if (ax0 > cmd[CMD_RIGHTSTEER].max) { ax0 = cmd[CMD_RIGHTSTEER].max; } else if (ax0 < cmd[CMD_RIGHTSTEER].min) { ax0 = cmd[CMD_RIGHTSTEER].min; } ax0 = ax0 * cmd[CMD_RIGHTSTEER].pow; rightSteer = - pow(fabs(ax0), cmd[CMD_RIGHTSTEER].sens) / (1.0 + cmd[CMD_RIGHTSTEER].spdSens * car->pub.speed / 10.0); break; case GFCTRL_TYPE_KEYBOARD: case GFCTRL_TYPE_SKEYBOARD: case GFCTRL_TYPE_JOY_BUT: if (cmd[CMD_RIGHTSTEER].type == GFCTRL_TYPE_KEYBOARD) { ax0 = keyInfo[cmd[CMD_RIGHTSTEER].val].state; } else if (cmd[CMD_RIGHTSTEER].type == GFCTRL_TYPE_SKEYBOARD) { ax0 = skeyInfo[cmd[CMD_RIGHTSTEER].val].state; } else { ax0 = joyInfo->levelup[cmd[CMD_RIGHTSTEER].val]; } if (ax0 == 0) { HCtx[idx]->prevRightSteer = rightSteer = 0; } else { ax0 = 2 * ax0 - 1; rightSteer = HCtx[idx]->prevRightSteer - ax0 * cmd[CMD_RIGHTSTEER].sens * s->deltaTime/ (1.0 + cmd[CMD_RIGHTSTEER].spdSens * car->pub.speed / 10.0); if (rightSteer > 0.0) rightSteer = 0.0; if (rightSteer < -1.0) rightSteer = -1.0; HCtx[idx]->prevRightSteer = rightSteer; } break; default: rightSteer = 0; break; } car->_steerCmd = leftSteer + rightSteer; switch (cmd[CMD_BRAKE].type) { case GFCTRL_TYPE_JOY_AXIS: brake = joyInfo->ax[cmd[CMD_BRAKE].val]; if (brake > cmd[CMD_BRAKE].max) { brake = cmd[CMD_BRAKE].max; } else if (brake < cmd[CMD_BRAKE].min) { brake = cmd[CMD_BRAKE].min; } car->_brakeCmd = fabs(cmd[CMD_BRAKE].pow * pow(fabs((brake - cmd[CMD_BRAKE].minVal) / (cmd[CMD_BRAKE].max - cmd[CMD_BRAKE].min)), cmd[CMD_BRAKE].sens)); break; case GFCTRL_TYPE_MOUSE_AXIS: ax0 = mouseInfo->ax[cmd[CMD_BRAKE].val] - cmd[CMD_BRAKE].deadZone; if (ax0 > cmd[CMD_BRAKE].max) { ax0 = cmd[CMD_BRAKE].max; } else if (ax0 < cmd[CMD_BRAKE].min) { ax0 = cmd[CMD_BRAKE].min; } ax0 = ax0 * cmd[CMD_BRAKE].pow; car->_brakeCmd = pow(fabs(ax0), cmd[CMD_BRAKE].sens) / (1.0 + cmd[CMD_BRAKE].spdSens * car->_speed_x / 10.0); break; case GFCTRL_TYPE_JOY_BUT: car->_brakeCmd = joyInfo->levelup[cmd[CMD_BRAKE].val]; break; case GFCTRL_TYPE_MOUSE_BUT: car->_brakeCmd = mouseInfo->button[cmd[CMD_BRAKE].val]; break; case GFCTRL_TYPE_KEYBOARD: car->_brakeCmd = keyInfo[cmd[CMD_BRAKE].val].state; break; case GFCTRL_TYPE_SKEYBOARD: car->_brakeCmd = skeyInfo[cmd[CMD_BRAKE].val].state; break; default: car->_brakeCmd = 0; break; } switch (cmd[CMD_CLUTCH].type) { case GFCTRL_TYPE_JOY_AXIS: clutch = joyInfo->ax[cmd[CMD_CLUTCH].val]; if (clutch > cmd[CMD_CLUTCH].max) { clutch = cmd[CMD_CLUTCH].max; } else if (clutch < cmd[CMD_CLUTCH].min) { clutch = cmd[CMD_CLUTCH].min; } car->_clutchCmd = fabs(cmd[CMD_CLUTCH].pow * pow(fabs((clutch - cmd[CMD_CLUTCH].minVal) / (cmd[CMD_CLUTCH].max - cmd[CMD_CLUTCH].min)), cmd[CMD_CLUTCH].sens)); break; case GFCTRL_TYPE_MOUSE_AXIS: ax0 = mouseInfo->ax[cmd[CMD_CLUTCH].val] - cmd[CMD_CLUTCH].deadZone; if (ax0 > cmd[CMD_CLUTCH].max) { ax0 = cmd[CMD_CLUTCH].max; } else if (ax0 < cmd[CMD_CLUTCH].min) { ax0 = cmd[CMD_CLUTCH].min; } ax0 = ax0 * cmd[CMD_CLUTCH].pow; car->_clutchCmd = pow(fabs(ax0), cmd[CMD_CLUTCH].sens) / (1.0 + cmd[CMD_CLUTCH].spdSens * car->_speed_x / 10.0); break; case GFCTRL_TYPE_JOY_BUT: car->_clutchCmd = joyInfo->levelup[cmd[CMD_CLUTCH].val]; break; case GFCTRL_TYPE_MOUSE_BUT: car->_clutchCmd = mouseInfo->button[cmd[CMD_CLUTCH].val]; break; case GFCTRL_TYPE_KEYBOARD: car->_clutchCmd = keyInfo[cmd[CMD_CLUTCH].val].state; break; case GFCTRL_TYPE_SKEYBOARD: car->_clutchCmd = skeyInfo[cmd[CMD_CLUTCH].val].state; break; default: car->_clutchCmd = 0; break; } // if player's used the clutch manually then we dispense with autoClutch if (car->_clutchCmd != 0.0f) HCtx[idx]->autoClutch = 0; switch (cmd[CMD_THROTTLE].type) { case GFCTRL_TYPE_JOY_AXIS: throttle = joyInfo->ax[cmd[CMD_THROTTLE].val]; if (throttle > cmd[CMD_THROTTLE].max) { throttle = cmd[CMD_THROTTLE].max; } else if (throttle < cmd[CMD_THROTTLE].min) { throttle = cmd[CMD_THROTTLE].min; } car->_accelCmd = fabs(cmd[CMD_THROTTLE].pow * pow(fabs((throttle - cmd[CMD_THROTTLE].minVal) / (cmd[CMD_THROTTLE].max - cmd[CMD_THROTTLE].min)), cmd[CMD_THROTTLE].sens)); break; case GFCTRL_TYPE_MOUSE_AXIS: ax0 = mouseInfo->ax[cmd[CMD_THROTTLE].val] - cmd[CMD_THROTTLE].deadZone; if (ax0 > cmd[CMD_THROTTLE].max) { ax0 = cmd[CMD_THROTTLE].max; } else if (ax0 < cmd[CMD_THROTTLE].min) { ax0 = cmd[CMD_THROTTLE].min; } ax0 = ax0 * cmd[CMD_THROTTLE].pow; car->_accelCmd = pow(fabs(ax0), cmd[CMD_THROTTLE].sens) / (1.0 + cmd[CMD_THROTTLE].spdSens * car->_speed_x / 10.0); if (isnan (car->_accelCmd)) { car->_accelCmd = 0; } /* printf(" axO:%f accelCmd:%f\n", ax0, car->_accelCmd); */ break; case GFCTRL_TYPE_JOY_BUT: car->_accelCmd = joyInfo->levelup[cmd[CMD_THROTTLE].val]; break; case GFCTRL_TYPE_MOUSE_BUT: car->_accelCmd = mouseInfo->button[cmd[CMD_THROTTLE].val]; break; case GFCTRL_TYPE_KEYBOARD: car->_accelCmd = keyInfo[cmd[CMD_THROTTLE].val].state; break; case GFCTRL_TYPE_SKEYBOARD: car->_accelCmd = skeyInfo[cmd[CMD_THROTTLE].val].state; break; default: car->_accelCmd = 0; break; } if (s->currentTime > 1.0) { // thanks Christos for the following: gradual accel/brake changes for on/off controls. const tdble inc_rate = 0.2f; if (cmd[CMD_BRAKE].type == GFCTRL_TYPE_JOY_BUT || cmd[CMD_BRAKE].type == GFCTRL_TYPE_MOUSE_BUT || cmd[CMD_BRAKE].type == GFCTRL_TYPE_KEYBOARD || cmd[CMD_BRAKE].type == GFCTRL_TYPE_SKEYBOARD) { tdble d_brake = car->_brakeCmd - HCtx[idx]->pbrake; if (fabs(d_brake) > inc_rate && car->_brakeCmd > HCtx[idx]->pbrake) { car->_brakeCmd = MIN(car->_brakeCmd, HCtx[idx]->pbrake + inc_rate*d_brake/fabs(d_brake)); } HCtx[idx]->pbrake = car->_brakeCmd; } if (cmd[CMD_THROTTLE].type == GFCTRL_TYPE_JOY_BUT || cmd[CMD_THROTTLE].type == GFCTRL_TYPE_MOUSE_BUT || cmd[CMD_THROTTLE].type == GFCTRL_TYPE_KEYBOARD || cmd[CMD_THROTTLE].type == GFCTRL_TYPE_SKEYBOARD) { tdble d_accel = car->_accelCmd - HCtx[idx]->paccel; if (fabs(d_accel) > inc_rate && car->_accelCmd > HCtx[idx]->paccel) { car->_accelCmd = MIN(car->_accelCmd, HCtx[idx]->paccel + inc_rate*d_accel/fabs(d_accel)); } HCtx[idx]->paccel = car->_accelCmd; } } if (HCtx[idx]->AutoReverseEngaged) { /* swap brake and throttle */ brake = car->_brakeCmd; car->_brakeCmd = car->_accelCmd; car->_accelCmd = brake; } if (HCtx[idx]->ParamAbs) { if (fabs(car->_speed_x) > 10.0) { int i; tdble skidAng = atan2(car->_speed_Y, car->_speed_X) - car->_yaw; NORM_PI_PI(skidAng); if (car->_speed_x > 5 && fabs(skidAng) > 0.2) car->_brakeCmd = MIN(car->_brakeCmd, 0.10 + 0.70 * cos(skidAng)); if (fabs(car->_steerCmd) > 0.1) { tdble decel = ((fabs(car->_steerCmd)-0.1) * (1.0 + fabs(car->_steerCmd)) * 0.6); car->_brakeCmd = MIN(car->_brakeCmd, MAX(0.35, 1.0 - decel)); } const tdble abs_slip = 2.5; const tdble abs_range = 5.0; slip = 0; for (i = 0; i < 4; i++) { slip += car->_wheelSpinVel(i) * car->_wheelRadius(i); } slip = car->_speed_x - slip/4.0f; if (slip > abs_slip) car->_brakeCmd = car->_brakeCmd - MIN(car->_brakeCmd*0.8, (slip - abs_slip) / abs_range); } } if (HCtx[idx]->ParamAsr) { tdble trackangle = RtTrackSideTgAngleL(&(car->_trkPos)); tdble angle = trackangle - car->_yaw; NORM_PI_PI(angle); tdble maxaccel = 0.0; if (car->_trkPos.seg->type == TR_STR) maxaccel = MIN(car->_accelCmd, 0.2); else if (car->_trkPos.seg->type == TR_LFT && angle < 0.0) maxaccel = MIN(car->_accelCmd, MIN(0.6, -angle)); else if (car->_trkPos.seg->type == TR_RGT && angle > 0.0) maxaccel = MIN(car->_accelCmd, MIN(0.6, angle)); tdble origaccel = car->_accelCmd; tdble skidAng = atan2(car->_speed_Y, car->_speed_X) - car->_yaw; NORM_PI_PI(skidAng); if (car->_speed_x > 5 && fabs(skidAng) > 0.2) { car->_accelCmd = MIN(car->_accelCmd, 0.15 + 0.70 * cos(skidAng)); car->_accelCmd = MAX(car->_accelCmd, maxaccel); } if (fabs(car->_steerCmd) > 0.1) { tdble decel = ((fabs(car->_steerCmd)-0.1) * (1.0 + fabs(car->_steerCmd)) * 0.8); car->_accelCmd = MIN(car->_accelCmd, MAX(0.35, 1.0 - decel)); } tdble drivespeed = 0.0; switch (HCtx[idx]->drivetrain) { case D4WD: drivespeed = ((car->_wheelSpinVel(FRNT_RGT) + car->_wheelSpinVel(FRNT_LFT)) * car->_wheelRadius(FRNT_LFT) + (car->_wheelSpinVel(REAR_RGT) + car->_wheelSpinVel(REAR_LFT)) * car->_wheelRadius(REAR_LFT)) / 4.0; break; case DFWD: drivespeed = (car->_wheelSpinVel(FRNT_RGT) + car->_wheelSpinVel(FRNT_LFT)) * car->_wheelRadius(FRNT_LFT) / 2.0; break; default: drivespeed = (car->_wheelSpinVel(REAR_RGT) + car->_wheelSpinVel(REAR_LFT)) * car->_wheelRadius(REAR_LFT) / 2.0; break; } tdble slip = drivespeed - fabs(car->_speed_x); if (slip > 2.0) car->_accelCmd = MIN(car->_accelCmd, origaccel - MIN(origaccel-0.1, ((slip - 2.0)/10.0))); } if (speedLimiter) { tdble Dv; if (Vtarget != 0) { Dv = Vtarget - car->_speed_x; if (Dv > 0.0) { car->_accelCmd = MIN(car->_accelCmd, fabs(Dv/6.0)); } else { car->_brakeCmd = MAX(car->_brakeCmd, fabs(Dv/5.0)); car->_accelCmd = 0; } } } #ifndef WIN32 #ifdef TELEMETRY if ((car->_laps > 1) && (car->_laps < 5)) { if (HCtx[idx]->lap == 1) { RtTelemStartMonitoring("Player"); } RtTelemUpdate(car->_curLapTime); } if (car->_laps == 5) { if (HCtx[idx]->lap == 4) { RtTelemShutdown(); } } #endif #endif HCtx[idx]->lap = car->_laps; }
// update void DXInput::update() { updateMouse(); updateKeys(); GetKeyboardState(m_keys); }