void bbSystemPoll(){ MSG msg; while( PeekMessage( &msg,0,0,0,PM_REMOVE ) ){ switch( msg.message ){ case WM_KEYDOWN:case WM_KEYUP: case WM_SYSKEYDOWN:case WM_SYSKEYUP: switch( msg.wParam ){ case VK_SHIFT: case VK_CONTROL: case VK_MENU: case VK_LWIN:case VK_RWIN: updateMods(); break; } break; } if( isControl( msg.hwnd ) ){ HWND hwnd=GetParent( msg.hwnd ); while( hwnd && isControl( hwnd ) ) hwnd=GetParent( hwnd ); if( hwnd && IsDialogMessage( hwnd,&msg ) ) continue; } TranslateMessage( &msg ); DispatchMessage( &msg ); } }
void doPlayerSelect(void) { if (isControl(CONTROL_PREV_FIGHTER)) { selectNewPlayer(-1); clearControl(CONTROL_PREV_FIGHTER); } if (isControl(CONTROL_NEXT_FIGHTER)) { selectNewPlayer(1); clearControl(CONTROL_NEXT_FIGHTER); } if (player->health > 0 && isAcceptControl()) { battle.playerSelect = 0; initPlayer(); resetAcceptControls(); } }
static void handleMouse(void) { faceMouse(); if (battle.status == MS_IN_PROGRESS) { if (isControl(CONTROL_FIRE) && !player->reload && player->guns[0].type) { if (player->selectedGunType != BT_ROCKET) { fireGuns(player); } else { fireRocket(player); } if (battle.hasSuspicionLevel && !battle.numEnemies && !battle.suspicionCoolOff) { battle.suspicionLevel += (MAX_SUSPICION_LEVEL * 0.05); } } if (isControl(CONTROL_ACCELERATE)) { if (battle.boostTimer > BOOST_FINISHED_TIME || game.currentMission->challengeData.noBoost) { applyFighterThrust(); } } if (isControl(CONTROL_MISSILE)) { preFireMissile(); app.mouse.button[SDL_BUTTON_MIDDLE] = 0; } if (isControl(CONTROL_GUNS)) { switchGuns(); app.mouse.button[SDL_BUTTON_X1] = 0; } if (isControl(CONTROL_RADAR)) { cycleRadarZoom(); app.mouse.button[SDL_BUTTON_X2] = 0; } } }
void print() const { if (not isControl()) return; std::cerr << "Reordered: " << reordered << std::endl; std::cerr << "Checks: " << checks << std::endl; std::cerr << "Wait cycles: " << waitCycles << std::endl; }
void check() { if (not isControl()) return; if (ret[x] == 0 and ret[y] == 0) ++reordered; ++checks; }
void genericAction(char *tmpBuffer, int size, char c) { if(isControl()) { toggleControl(); setPressedChar(c); // control character switch(c) { case 'x':// cut // make sure highlight bounds are correct if(beginHighlight == -1 || endHighlight == -1) { return; } if(beginHighlight > endHighlight) { quickSwap(&beginHighlight, &endHighlight); } // perform cut setClipboardRange(tmpBuffer, beginHighlight, endHighlight); removeText(tmpBuffer, size); moveKBCursorAbsolute(beginHighlight); // reset the edit mode clearFakeHighlight(); select = 0; break; case 'c':// copy // make sure highlight bounds are correct if(beginHighlight == -1 || endHighlight == -1) { return; } if(beginHighlight > endHighlight) { quickSwap(&beginHighlight, &endHighlight); } // perform copy setClipboardRange(tmpBuffer, beginHighlight, endHighlight); // reset the edit mode clearFakeHighlight(); select = 0; break; case 'v':// paste if(beginHighlight != -1 && endHighlight != -1) { if(beginHighlight > endHighlight) { quickSwap(&beginHighlight, &endHighlight); } // we need to overwrite, but first check to make sure we don't overdo it if(strlen(tmpBuffer) - (endHighlight - beginHighlight) + strlen(getClipboard()) > size) { // after removing the current text and adding the new text, we are going over the size return; } // remove the current text removeText(tmpBuffer, size); moveKBCursorAbsolute(beginHighlight); clearFakeHighlight(); select = 0; // cursor is now where we want to add the new text // we know also that there is enough room, so just insert the text // ensure we are inserting, even if overwrite uint16 tInsert = insert; insert = 1; char *tAdd = getClipboard(); // loop and add chars while(*tAdd != 0) { insertChar(tmpBuffer, size, *tAdd); tAdd++; } // reset insert insert = tInsert; } else { if(strlen(tmpBuffer) + strlen(getClipboard()) > size) { // after adding the new text, we are going over the size return; } clearFakeHighlight(); select = 0; // add the text char *tAdd = getClipboard(); // loop and add chars while(*tAdd != 0) { insertChar(tmpBuffer, size, *tAdd); tAdd++; } } break; } } else { if(getKBCursor() < 0) { moveKBCursorAbsolute(0); } else if(getKBCursor() >= size) { moveKBCursorAbsolute(size - 1); } if(beginHighlight != -1 && endHighlight != -1) { if(beginHighlight > endHighlight) { quickSwap(&beginHighlight, &endHighlight); } // we have to clear out the data before performing the action removeText(tmpBuffer, size); // move the cursor moveKBCursorAbsolute(beginHighlight); // reset the edit mode clearFakeHighlight(); select = 0; if(c == BSP || c == DEL) { // we've done the work required, exit return; } } if(c == BSP) { // backspace if(getKBCursor() == 0) // handle backspacing nothing { return; } int z; for(z=getKBCursor()-1;z<=size;z++) { tmpBuffer[z] = tmpBuffer[z+1]; } moveKBCursorRelative(CURSOR_BACKWARD); } else if(c == DEL) { // del if(tmpBuffer[getKBCursor()] == 0) // handle deleting nothing { return; } moveKBCursorRelative(CURSOR_FORWARD); int z; for(z=getKBCursor()-1;z<=size;z++) { tmpBuffer[z] = tmpBuffer[z+1]; } moveKBCursorRelative(CURSOR_BACKWARD); } else { // normal add insertChar(tmpBuffer, size, c); } tmpBuffer[size] = 0; } }
static void handleKeyboard(void) { if (battle.status == MS_IN_PROGRESS) { if (isControl(CONTROL_BOOST) && player->speed > 0) { if (battle.boostTimer == BOOST_RECHARGE_TIME) { playSound(SND_BOOST); activateBoost(); } else { playSound(SND_GUI_DENIED); } clearControl(CONTROL_BOOST); } if (isControl(CONTROL_TARGET)) { selectTarget(); clearControl(CONTROL_TARGET); } if (isControl(CONTROL_ECM)) { if (battle.ecmTimer == ECM_RECHARGE_TIME) { playSound(SND_ECM); activateECM(); } else { playSound(SND_GUI_DENIED); } clearControl(CONTROL_ECM); } if (isControl(CONTROL_BRAKE)) { applyFighterBrakes(); } if (isControl(CONTROL_GUNS)) { switchGuns(); clearControl(CONTROL_GUNS); } if (isControl(CONTROL_RADAR)) { cycleRadarZoom(); clearControl(CONTROL_RADAR); } if (isControl(CONTROL_MISSILE)) { preFireMissile(); clearControl(CONTROL_MISSILE); } } else { applyFighterBrakes(); } }
std::pair<size_t, RedisParser::ParseResult> RedisParser::parseChunk(const char *ptr, size_t size) { size_t i = 0; for(; i < size; ++i) { char c = ptr[i]; switch(state) { case Start: buf.clear(); switch(c) { case stringReply: state = String; break; case errorReply: state = ErrorString; break; case integerReply: state = Integer; break; case bulkReply: state = BulkSize; bulkSize = 0; break; case arrayReply: state = ArraySize; break; default: state = Start; return std::make_pair(i + 1, Error); } break; case String: if( c == '\r' ) { state = StringLF; } else if( isChar(c) && !isControl(c) ) { buf.push_back(c); } else { state = Start; return std::make_pair(i + 1, Error); } break; case ErrorString: if( c == '\r' ) { state = ErrorLF; } else if( isChar(c) && !isControl(c) ) { buf.push_back(c); } else { state = Start; return std::make_pair(i + 1, Error); } break; case BulkSize: if( c == '\r' ) { if( buf.empty() ) { state = Start; return std::make_pair(i + 1, Error); } else { state = BulkSizeLF; } } else if( isdigit(c) || c == '-' ) { buf.push_back(c); } else { state = Start; return std::make_pair(i + 1, Error); } break; case StringLF: if( c == '\n') { state = Start; valueStack.push(buf); return std::make_pair(i + 1, Completed); } else { state = Start; return std::make_pair(i + 1, Error); } break; case ErrorLF: if( c == '\n') { state = Start; RedisValue::ErrorTag tag; valueStack.push(RedisValue(buf, tag)); return std::make_pair(i + 1, Completed); } else { state = Start; return std::make_pair(i + 1, Error); } break; case BulkSizeLF: if( c == '\n' ) { // TODO optimize me std::string tmp(buf.begin(), buf.end()); bulkSize = strtol(tmp.c_str(), 0, 10); buf.clear(); if( bulkSize == -1 ) { state = Start; valueStack.push(RedisValue()); // Nil return std::make_pair(i + 1, Completed); } else if( bulkSize == 0 ) { state = BulkCR; } else if( bulkSize < 0 ) { state = Start; return std::make_pair(i + 1, Error); } else { buf.reserve(bulkSize); long int available = size - i - 1; long int canRead = std::min(bulkSize, available); if( canRead > 0 ) { buf.assign(ptr + i + 1, ptr + i + canRead + 1); } i += canRead; if( bulkSize > available ) { bulkSize -= canRead; state = Bulk; return std::make_pair(i + 1, Incompleted); } else { state = BulkCR; } } } else { state = Start; return std::make_pair(i + 1, Error); } break; case Bulk: { assert( bulkSize > 0 ); long int available = size - i; long int canRead = std::min(available, bulkSize); buf.insert(buf.end(), ptr + i, ptr + canRead); bulkSize -= canRead; i += canRead - 1; if( bulkSize > 0 ) { return std::make_pair(i + 1, Incompleted); } else { state = BulkCR; if( size == i + 1 ) { return std::make_pair(i + 1, Incompleted); } } break; } case BulkCR: if( c == '\r') { state = BulkLF; } else { state = Start; return std::make_pair(i + 1, Error); } break; case BulkLF: if( c == '\n') { state = Start; valueStack.push(buf); return std::make_pair(i + 1, Completed); } else { state = Start; return std::make_pair(i + 1, Error); } break; case ArraySize: if( c == '\r' ) { if( buf.empty() ) { state = Start; return std::make_pair(i + 1, Error); } else { state = ArraySizeLF; } } else if( isdigit(c) || c == '-' ) { buf.push_back(c); } else { state = Start; return std::make_pair(i + 1, Error); } break; case ArraySizeLF: if( c == '\n' ) { // TODO optimize me std::string tmp(buf.begin(), buf.end()); long int arraySize = strtol(tmp.c_str(), 0, 10); buf.clear(); std::vector<RedisValue> array; if( arraySize == -1 || arraySize == 0) { state = Start; valueStack.push(array); // Empty array return std::make_pair(i + 1, Completed); } else if( arraySize < 0 ) { state = Start; return std::make_pair(i + 1, Error); } else { array.reserve(arraySize); arrayStack.push(arraySize); valueStack.push(array); state = Start; if( i + 1 != size ) { std::pair<size_t, ParseResult> parseResult = parseArray(ptr + i + 1, size - i - 1); parseResult.first += i + 1; return parseResult; } else { return std::make_pair(i + 1, Incompleted); } } } else { state = Start; return std::make_pair(i + 1, Error); } break; case Integer: if( c == '\r' ) { if( buf.empty() ) { state = Start; return std::make_pair(i + 1, Error); } else { state = IntegerLF; } } else if( isdigit(c) || c == '-' ) { buf.push_back(c); } else { state = Start; return std::make_pair(i + 1, Error); } break; case IntegerLF: if( c == '\n' ) { // TODO optimize me std::string tmp(buf.begin(), buf.end()); int64_t value = strtoll(tmp.c_str(), 0, 10); buf.clear(); valueStack.push(value); state = Start; return std::make_pair(i + 1, Completed); } else { state = Start; return std::make_pair(i + 1, Error); } break; default: state = Start; return std::make_pair(i + 1, Error); } } return std::make_pair(i, Incompleted); }
inline bool HttpMessageProcessor::isToken(char value) { return isChar(value) && !(isControl(value) || isSeparator(value)); }
inline bool HttpMessageProcessor::isText(char value) { // TEXT = <any OCTET except CTLs but including LWS> return !isControl(value) || value == SP || value == HT; }
void reset() { if (not isControl()) return; std::fill(mem.begin(), mem.end(), 0); }
void loop( void ) { // Serial.write( '\n' ) ; // send a char // Serial.write( '\r' ) ; // send a char // Serial5.write( '-' ) ; // send a char // adding a constant integer to a string: stringThree = stringOne + 123; Serial.println(stringThree); // prints "stringThree = 123" // adding a constant long interger to a string: stringThree = stringOne + 123456789; Serial.println(stringThree); // prints " You added 123456789" // adding a constant character to a string: stringThree = stringOne + 'A'; Serial.println(stringThree); // prints "You added A" // adding a constant string to a string: stringThree = stringOne + "abc"; Serial.println(stringThree); // prints "You added abc" stringThree = stringOne + stringTwo; Serial.println(stringThree); // prints "You added this string" // adding a variable integer to a string: int sensorValue = analogRead(A0); stringOne = "Sensor value: "; stringThree = stringOne + sensorValue; Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has // adding a variable long integer to a string: long currentTime = millis(); stringOne = "millis() value: "; stringThree = stringOne + millis(); Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has // do nothing while true: while (true); #if 0 // get any incoming bytes: if (Serial.available() > 0) { int thisChar = Serial.read(); //////// int thisChar = 'a'; // say what was sent: Serial.print("You sent me: \'"); Serial.write(thisChar); Serial.print("\' ASCII Value: "); Serial.println(thisChar); // analyze what was sent: if (isAlphaNumeric(thisChar)) { Serial.println("it's alphanumeric"); } if (isAlpha(thisChar)) { Serial.println("it's alphabetic"); } if (isAscii(thisChar)) { Serial.println("it's ASCII"); } if (isWhitespace(thisChar)) { Serial.println("it's whitespace"); } if (isControl(thisChar)) { Serial.println("it's a control character"); } if (isDigit(thisChar)) { Serial.println("it's a numeric digit"); } if (isGraph(thisChar)) { Serial.println("it's a printable character that's not whitespace"); } if (isLowerCase(thisChar)) { Serial.println("it's lower case"); } if (isPrintable(thisChar)) { Serial.println("it's printable"); } if (isPunct(thisChar)) { Serial.println("it's punctuation"); } if (isSpace(thisChar)) { Serial.println("it's a space character"); } if (isUpperCase(thisChar)) { Serial.println("it's upper case"); } if (isHexadecimalDigit(thisChar)) { Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)"); } // add some space and ask for another byte: Serial.println(); Serial.println("Give me another byte:"); Serial.println(); } #endif #if 0 sensorValue = analogRead(A0); // apply the calibration to the sensor reading sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); Serial.print("sensor = " ); Serial.print(sensorValue); // in case the sensor value is outside the range seen during calibration outputValue = constrain(sensorValue, 0, 255); // print the results to the serial monitor: Serial.print("\t output = "); Serial.println(outputValue); // fade the LED using the calibrated value: analogWrite(9/*ledPin*/, sensorValue); delay(1); #endif #if 0 // read the analog in value: sensorValue = analogRead(A0); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(9/*analogOutPin*/, outputValue); // print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); // delay(1000); #endif #if 0 digitalWrite( 0, HIGH ) ; // set the red LED on digitalWrite( 0, LOW ) ; // set the red LED on digitalWrite( 1, HIGH ) ; // set the red LED on digitalWrite( 1, LOW ) ; // set the red LED on digitalWrite( 4, HIGH ) ; // set the red LED on digitalWrite( 4, LOW ) ; // set the red LED on digitalWrite( 5, HIGH ) ; // set the red LED on digitalWrite( 5, LOW ) ; // set the red LED on digitalWrite( 6, HIGH ) ; // set the red LED on digitalWrite( 6, LOW ) ; // set the red LED on digitalWrite( 7, HIGH ) ; // set the red LED on digitalWrite( 7, LOW ) ; // set the red LED on digitalWrite( 8, HIGH ) ; // set the red LED on digitalWrite( 8, LOW ) ; // set the red LED on digitalWrite( 9, HIGH ) ; // set the red LED on digitalWrite( 9, LOW ) ; // set the red LED on digitalWrite( 10, HIGH ) ; // set the red LED on digitalWrite( 10, LOW ) ; // set the red LED on digitalWrite( 11, HIGH ) ; // set the red LED on digitalWrite( 11, LOW ) ; // set the red LED on digitalWrite( 12, HIGH ) ; // set the red LED on digitalWrite( 12, LOW ) ; // set the red LED on digitalWrite( 13, HIGH ) ; // set the red LED on digitalWrite( 13, LOW ) ; // set the red LED on #endif #if 0 // int a = 123; // Serial.print(a, DEC); // for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ ) for ( uint32_t i = 0 ; i <= NUM_ANALOG_INPUTS ; i++ ) { int a = analogRead(i); // int a = 123; Serial.print(a, DEC); Serial.print(" "); // Serial.write( ' ' ) ; // send a char // Serial.write( 0x30 + i ) ; // send a char // Serial.write( 0x30 + ((a/1000)%10) ) ; // send a char // Serial.write( 0x30 + ((a/100)%10) ) ; // send a char // Serial.write( 0x30 + ((a/10)%10) ) ; // send a char // Serial.write( 0x30 + (a%10) ) ; // send a char // Serial.write( ' ' ) ; // send a char } Serial.println(); #endif #if 0 volatile int pin_value=0 ; static volatile uint8_t duty_cycle=0 ; static volatile uint16_t dac_value=0 ; // Test digitalWrite led_step1() ; delay( 500 ) ; // wait for a second led_step2() ; delay( 500 ) ; // wait for a second // Test Serial output Serial5.write( '-' ) ; // send a char Serial5.write( "test1\n" ) ; // send a string Serial5.write( "test2" ) ; // send another string // Test digitalRead: connect pin 2 to either GND or 3.3V. !!!! NOT on 5V pin !!!! pin_value=digitalRead( 2 ) ; Serial5.write( "pin 2 value is " ) ; Serial5.write( (pin_value == LOW)?"LOW\n":"HIGH\n" ) ; duty_cycle+=8 ;//=(uint8_t)(millis() & 0xff) ; analogWrite( 13, duty_cycle ) ; analogWrite( 12, duty_cycle ) ; analogWrite( 11, duty_cycle ) ; analogWrite( 10 ,duty_cycle ) ; analogWrite( 9, duty_cycle ) ; analogWrite( 8, duty_cycle ) ; dac_value += 64; analogWrite(A0, dac_value); Serial5.print("\r\nAnalog pins: "); for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ ) { int a = analogRead(i); Serial5.print(a, DEC); Serial5.print(" "); } Serial5.println(); Serial5.println("External interrupt pins:"); if ( ul_Interrupt_Pin3 == 1 ) { Serial5.println( "Pin 3 triggered (LOW)" ) ; ul_Interrupt_Pin3 = 0 ; } if ( ul_Interrupt_Pin4 == 1 ) { Serial5.println( "Pin 4 triggered (HIGH)" ) ; ul_Interrupt_Pin4 = 0 ; } if ( ul_Interrupt_Pin5 == 1 ) { Serial5.println( "Pin 5 triggered (FALLING)" ) ; ul_Interrupt_Pin5 = 0 ; } if ( ul_Interrupt_Pin6 == 1 ) { Serial5.println( "Pin 6 triggered (RISING)" ) ; ul_Interrupt_Pin6 = 0 ; } if ( ul_Interrupt_Pin7 == 1 ) { Serial5.println( "Pin 7 triggered (CHANGE)" ) ; ul_Interrupt_Pin7 = 0 ; } #endif }
int isAcceptControl(void) { return (app.keyboard[SDL_SCANCODE_SPACE] ||app.keyboard[SDL_SCANCODE_RETURN] || isControl(CONTROL_FIRE)); }
int main(int argc, char *argv[]) { float td; long then, lastFrameTime, frames; long expireTextTimer; SDL_Event event; memset(&app, 0, sizeof(App)); memset(&dev, 0, sizeof(Dev)); handleLoggingArgs(argc, argv); atexit(cleanup); srand(time(NULL)); init18N(argc, argv); initLookups(); initSDL(); initGameSystem(); createScreenshotFolder(); if (fileExists(getSaveFilePath(SAVE_FILENAME))) { loadGame(); } handleMissionArgs(argc, argv); dev.fps = frames = td = 0; then = SDL_GetTicks(); lastFrameTime = SDL_GetTicks() + 1000; expireTextTimer = SDL_GetTicks() + (1000 * 10); while (1) { td += (SDL_GetTicks() - then); then = SDL_GetTicks(); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEMOTION: doMouseMotion(&event.motion); break; case SDL_MOUSEWHEEL: doMouseWheel(&event.wheel); break; case SDL_MOUSEBUTTONDOWN: doMouseDown(&event.button); break; case SDL_MOUSEBUTTONUP: doMouseUp(&event.button); break; case SDL_KEYDOWN: doKeyDown(&event.key); break; case SDL_KEYUP: doKeyUp(&event.key); break; case SDL_QUIT: exit(0); break; } } if (app.modalDialog.type != MD_NONE) { doModalDialog(); } while (td >= LOGIC_RATE) { /* let the delegate decide during logic() */ app.doTrophyAlerts = 0; app.delegate.logic(); td -= LOGIC_RATE; if (app.doTrophyAlerts) { doTrophyAlerts(); } if (app.resetTimeDelta) { td = 0; then = SDL_GetTicks(); app.resetTimeDelta = 0; } game.stats[STAT_TIME]++; } prepareScene(); app.delegate.draw(); if (app.doTrophyAlerts) { drawTrophyAlert(); } if (app.modalDialog.type != MD_NONE) { drawModalDialog(); } presentScene(); doDevKeys(); frames++; if (SDL_GetTicks() > lastFrameTime) { dev.fps = frames; frames = 0; lastFrameTime = SDL_GetTicks() + 1000; if (dev.takeScreenshots) { saveScreenshot(); } } if (isControl(CONTROL_SCREENSHOT)) { saveScreenshot(); clearControl(CONTROL_SCREENSHOT); } if (SDL_GetTicks() > expireTextTimer) { expireTexts(0); expireTextTimer = SDL_GetTicks() + (1000 * 10); } /* don't save more than once per request, and not in the middle of battle */ if (app.saveGame && battle.status != MS_IN_PROGRESS) { saveGame(); app.saveGame = 0; } /* always zero the mouse motion */ app.mouse.dx = app.mouse.dy = 0; SDL_Delay(1); } return 0; }