bool OSystem_IPHONE::handleEvent_mouseUp(Common::Event &event, int x, int y) { //printf("Mouse up at (%u, %u)\n", x, y); if (_secondaryTapped) { _secondaryTapped = false; if (!handleEvent_secondMouseUp(event, x, y)) return false; } else if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONUP; event.mouse.x = _videoContext->mouseX; event.mouse.y = _videoContext->mouseY; } else { if (getMillis() - _lastMouseDown < 250) { event.type = Common::EVENT_LBUTTONDOWN; event.mouse.x = _videoContext->mouseX; event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_LBUTTONUP; _queuedInputEvent.mouse.x = _videoContext->mouseX; _queuedInputEvent.mouse.y = _videoContext->mouseY; _lastMouseTap = getMillis(); _queuedEventTime = _lastMouseTap + kQueuedInputEventDelay; } else return false; } return true; }
void OSystem_Dreamcast::delayMillis(uint msecs) { getMillis(); unsigned int t, start = Timer(); int time = (((unsigned int)msecs)*3125U)>>6; while (((int)((t = Timer())-start))<time) { if (_timerManager != NULL) ((DefaultTimerManager *)_timerManager)->handler(); checkSound(); } getMillis(); }
bool retroCheckThread(uint32 offset = 0) { if(_threadExitTime <= (getMillis() + offset)) { extern void retro_leave_thread(); retro_leave_thread(); _threadExitTime = getMillis() + 10; return true; } return false; }
/** * Handles mouse button release. * * @param ev The SDL event * @param event The ScummVM event. * @return True if event was processed, false if not. */ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { if (motionPtrIndex == ev.button.which) { motionPtrIndex = -1; // When drag mode was active then simply send a mouse up event if (dragging) { event.type = Common::EVENT_LBUTTONUP; fillMouseEvent(event, curX, curY); dragging = false; return true; } // When mouse was moved 5 pixels or less then emulate a mouse button // click. if (ABS(dragDiffX) < 6 && ABS(dragDiffY) < 6) { int duration = getMillis() - screenDownTime; // When screen was pressed for less than 500ms then emulate a // left mouse click. if (duration < 500) { event.type = Common::EVENT_LBUTTONUP; fillMouseEvent(event, curX, curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_LBUTTONDOWN; dragStartTime = getMillis(); } // When screen was pressed for less than 1000ms then emulate a // right mouse click. else if (duration < 1000) { event.type = Common::EVENT_RBUTTONUP; fillMouseEvent(event, curX, curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_RBUTTONDOWN; } // When screen was pressed for more than 1000ms then emulate a // middle mouse click. else { event.type = Common::EVENT_MBUTTONUP; fillMouseEvent(event, curX, curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_MBUTTONDOWN; } } } return true; }
Period *Period::normalizedStandard(const PeriodType *type) { type = DateTimeUtils::getPeriodType(type); int64_t millis = getMillis(); // no overflow can happen, even with Integer.MAX_VALUEs millis += (((int64_t) getSeconds()) * ((int64_t) DateTimeConstants::MILLIS_PER_SECOND)); millis += (((int64_t) getMinutes()) * ((int64_t) DateTimeConstants::MILLIS_PER_MINUTE)); millis += (((int64_t) getHours()) * ((int64_t) DateTimeConstants::MILLIS_PER_HOUR)); millis += (((int64_t) getDays()) * ((int64_t) DateTimeConstants::MILLIS_PER_DAY)); millis += (((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::MILLIS_PER_WEEK)); Period *result = new Period(millis, type, ISOChronology::getInstanceUTC()); int years = getYears(); int months = getMonths(); if (years != 0 || months != 0) { int64_t totalMonths = years * 12L + months; if (type->isSupported(DurationFieldType::YEARS_TYPE)) { int normalizedYears = FieldUtils::safeToInt(totalMonths / 12); result = result->withYears(normalizedYears); totalMonths = totalMonths - (normalizedYears * 12); } if (type->isSupported(DurationFieldType::MONTHS_TYPE)) { int normalizedMonths = FieldUtils::safeToInt(totalMonths); result = result->withMonths(normalizedMonths); totalMonths = totalMonths - normalizedMonths; } if (totalMonths != 0) { string err("Unable to normalize as PeriodType is missing either years or months but period has a month/year amount: "); err.append(toString()); throw UnsupportedOperationException(err); } } return result; }
/** * Validate authentication key */ bool DaemonCore::authKeyValid( const std::string& key ) { CRASH_REPORT_BEGIN; // If we are empty, forget about it if (authKeys.empty()) { return false; } // Expire past keys bool found = false; unsigned long ts = getMillis(); for (std::list< AuthKey >::iterator it = authKeys.begin(); it != authKeys.end(); ++it) { AuthKey k = *it; if (ts >= k.expireTime) { it = authKeys.erase(it); if (authKeys.empty()) break; } else if (k.key == key) { found = true; } } // Check if we found it return found; CRASH_REPORT_END; }
void OSystem_IPHONE::handleEvent_keyPressed(Common::Event &event, int keyPressed) { int ascii = keyPressed; //printf("key: %i\n", keyPressed); // We remap some of the iPhone keyboard keys. // The first ten here are the row of symbols below the numeric keys. switch (keyPressed) { case 45: keyPressed = Common::KEYCODE_F1; ascii = Common::ASCII_F1; break; case 47: keyPressed = Common::KEYCODE_F2; ascii = Common::ASCII_F2; break; case 58: keyPressed = Common::KEYCODE_F3; ascii = Common::ASCII_F3; break; case 59: keyPressed = Common::KEYCODE_F4; ascii = Common::ASCII_F4; break; case 40: keyPressed = Common::KEYCODE_F5; ascii = Common::ASCII_F5; break; case 41: keyPressed = Common::KEYCODE_F6; ascii = Common::ASCII_F6; break; case 36: keyPressed = Common::KEYCODE_F7; ascii = Common::ASCII_F7; break; case 38: keyPressed = Common::KEYCODE_F8; ascii = Common::ASCII_F8; break; case 64: keyPressed = Common::KEYCODE_F9; ascii = Common::ASCII_F9; break; case 34: keyPressed = Common::KEYCODE_F10; ascii = Common::ASCII_F10; break; case 10: keyPressed = Common::KEYCODE_RETURN; ascii = Common::ASCII_RETURN; break; } event.type = Common::EVENT_KEYDOWN; _queuedInputEvent.type = Common::EVENT_KEYUP; event.kbd.flags = _queuedInputEvent.kbd.flags = 0; event.kbd.keycode = _queuedInputEvent.kbd.keycode = (Common::KeyCode)keyPressed; event.kbd.ascii = _queuedInputEvent.kbd.ascii = ascii; _queuedEventTime = getMillis() + kQueuedInputEventDelay; }
/** * Handles mouse button press. * * @param ev The SDL event * @param event The ScummVM event. * @return True if event was processed, false if not. */ bool WebOSSdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) { if (motionPtrIndex == -1) { motionPtrIndex = ev.button.which; dragDiffX = 0; dragDiffY = 0; screenDownTime = getMillis(); // Start dragging when pressing the screen shortly after a tap. if (getMillis() - dragStartTime < 250) { dragging = true; event.type = Common::EVENT_LBUTTONDOWN; fillMouseEvent(event, curX, curY); } } return true; }
Duration *Duration::withDurationAdded(int64_t durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } int64_t add = FieldUtils::safeMultiply(durationToAdd, scalar); int64_t duration = FieldUtils::safeAdd(getMillis(), add); return new Duration(duration); }
void OSystem_PalmBase::timer_handler() { UInt32 msecs = getMillis(); if (_timer.active && (msecs >= _timer.nextExpiry)) { _timer.duration = _timer.callback(_timer.duration); _timer.nextExpiry = msecs + _timer.duration; } }
void OSystem_IPHONE::suspendLoop() { bool done = false; uint32 startTime = getMillis(); stopSoundsystem(); InternalEvent event; while (!done) { if (iPhone_fetchEvent(&event)) if (event.type == kInputApplicationResumed) done = true; usleep(100000); } startSoundsystem(); _timeSuspended += getMillis() - startTime; }
void Sword2Engine::sleepUntil(uint32 time) { while (getMillis() < time) { // Make sure menu animations and fades don't suffer, but don't // redraw the entire scene. _mouse->processMenu(); _screen->updateDisplay(false); _system->delayMillis(10); } }
Weeks *Period::toStandardWeeks() { checkYearsAndMonths("Weeks"); int64_t millis = getMillis(); // assign to a int64_t millis += ((int64_t) getSeconds()) * DateTimeConstants::MILLIS_PER_SECOND; millis += ((int64_t) getMinutes()) * DateTimeConstants::MILLIS_PER_MINUTE; millis += ((int64_t) getHours()) * DateTimeConstants::MILLIS_PER_HOUR; millis += ((int64_t) getDays()) * DateTimeConstants::MILLIS_PER_DAY; int64_t weeks = ((int64_t) getWeeks()) + millis / DateTimeConstants::MILLIS_PER_WEEK; return Weeks::weeks(FieldUtils::safeToInt(weeks)); }
void OSystem_IPHONE::setTimerCallback(TimerProc callback, int interval) { //printf("setTimerCallback()\n"); if (callback != NULL) { _timerCallbackTimer = interval; _timerCallbackNext = getMillis() + interval; _timerCallback = callback; } else _timerCallback = NULL; }
void OSystem_PalmBase::setTimerCallback(TimerProc callback, int timer) { if (callback != NULL) { _timer.duration = timer; _timer.nextExpiry = getMillis() + timer; _timer.callback = callback; _timer.active = true; } else { _timer.active = false; } }
Duration *Period::toStandardDuration() { checkYearsAndMonths("Duration"); int64_t millis = getMillis(); // no overflow can happen, even with Integer.MAX_VALUEs millis += (((int64_t) getSeconds()) * ((int64_t) DateTimeConstants::MILLIS_PER_SECOND)); millis += (((int64_t) getMinutes()) * ((int64_t) DateTimeConstants::MILLIS_PER_MINUTE)); millis += (((int64_t) getHours()) * ((int64_t) DateTimeConstants::MILLIS_PER_HOUR)); millis += (((int64_t) getDays()) * ((int64_t) DateTimeConstants::MILLIS_PER_DAY)); millis += (((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::MILLIS_PER_WEEK)); return new Duration(millis); }
Seconds *Period::toStandardSeconds() { checkYearsAndMonths("Seconds"); int64_t seconds = getMillis() / DateTimeConstants::MILLIS_PER_SECOND; seconds = FieldUtils::safeAdd(seconds, (int64_t) getSeconds()); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getMinutes()) * ((int64_t) DateTimeConstants::SECONDS_PER_MINUTE)); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getHours()) * ((int64_t) DateTimeConstants::SECONDS_PER_HOUR)); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getDays()) * ((int64_t) DateTimeConstants::SECONDS_PER_DAY)); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::SECONDS_PER_WEEK)); return Seconds::seconds(FieldUtils::safeToInt(seconds)); }
Days *Period::toStandardDays() { checkYearsAndMonths("Days"); int64_t millis = getMillis(); // assign to a int64_t millis += ((int64_t) getSeconds()) * DateTimeConstants::MILLIS_PER_SECOND; millis += ((int64_t) getMinutes()) * DateTimeConstants::MILLIS_PER_MINUTE; millis += ((int64_t) getHours()) * DateTimeConstants::MILLIS_PER_HOUR; int64_t days = millis / DateTimeConstants::MILLIS_PER_DAY; days = FieldUtils::safeAdd(days, (int64_t) getDays()); days = FieldUtils::safeAdd(days, ((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::DAYS_PER_WEEK)); return Days::days(FieldUtils::safeToInt(days)); }
/** * Before calling the original SDL implementation this method checks if the * gesture area is pressed down. * * @param ev The SDL event * @param event The ScummVM event. * @return True if event was processed, false if not. */ bool WebOSSdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) { // Handle gesture area tap. if (ev.key.keysym.sym == SDLK_WORLD_71) { gestureDown = true; gestureDownTime = getMillis(); return true; } // Call original SDL key handler. return SdlEventSource::handleKeyDown(ev, event); }
Minutes *Period::toStandardMinutes() { checkYearsAndMonths("Minutes"); int64_t millis = getMillis(); // assign to a int64_t millis += ((int64_t) getSeconds()) * DateTimeConstants::MILLIS_PER_SECOND; int64_t minutes = millis / DateTimeConstants::MILLIS_PER_MINUTE; minutes = FieldUtils::safeAdd(minutes, (int64_t) getMinutes()); minutes = FieldUtils::safeAdd(minutes, ((int64_t) getHours()) * ((int64_t) DateTimeConstants::MINUTES_PER_HOUR)); minutes = FieldUtils::safeAdd(minutes, ((int64_t) getDays()) * ((int64_t) DateTimeConstants::MINUTES_PER_DAY)); minutes = FieldUtils::safeAdd(minutes, ((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::MINUTES_PER_WEEK)); return Minutes::minutes(FieldUtils::safeToInt(minutes)); }
OSystem_RETRO() : _mousePaletteEnabled(false), _mouseVisible(false), _mouseX(0), _mouseY(0), _mouseHotspotX(0), _mouseHotspotY(0), _mouseKeyColor(0), _mouseDontScale(false), _mixer(0), _threadExitTime(getMillis()) { _fsFactory = new POSIXFilesystemFactory(); memset(_mouseButtons, 0, sizeof(_mouseButtons)); if(s_systemDir.empty()) { s_systemDir = "."; } }
void PopUpDialog::handleMouseUp(int x, int y, int button, int clickCount) { // Mouse was released. If it wasn't moved much since the original mouse down, // let the popup stay open. If it did move, assume the user made his selection. int dist = (_clickX - x) * (_clickX - x) + (_clickY - y) * (_clickY - y); if (dist > 3 * 3 || getMillis() - _openTime > 300) { setResult(_selection); close(); } _clickX = -1; _clickY = -1; _openTime = (uint32)-1; }
bool OSystem_Wii::needsScreenUpdate() { if (getMillis() - _lastScreenUpdate < 1000 / MAX_FPS) return false; if (_gameRunning && _gameDirty) return true; if (_overlayVisible && _overlayDirty) return true; if (_mouseVisible && _texMouse.palette && _cursorPaletteDirty) return true; return false; }
/** * Allocate new authenticatino key */ std::string DaemonCore::newAuthKey() { CRASH_REPORT_BEGIN; AuthKey key; // The key lasts 5 minutes key.expireTime = getMillis() + 300000; // Allocate new UUID key.key = newGUID(); // Store on list authKeys.push_back( key ); // Return the key return key.key; CRASH_REPORT_END; }
OSystem_RETRO() : _mousePaletteEnabled(false), _mouseVisible(false), _mouseX(0), _mouseY(0), _mouseHotspotX(0), _mouseHotspotY(0), _mouseKeyColor(0), _mouseDontScale(false), _mixer(0), _startTime(0), _threadExitTime(10) { _fsFactory = new FS_SYSTEM_FACTORY(); memset(_mouseButtons, 0, sizeof(_mouseButtons)); memset(_joypadmouseButtons, 0, sizeof(_joypadmouseButtons)); _joypadstartButton = false; _startTime = getMillis(); if(s_systemDir.empty()) s_systemDir = "."; if(s_saveDir.empty()) s_saveDir = "."; }
bool OSystem_IPHONE::handleEvent_secondMouseDown(Common::Event &event, int x, int y) { _lastSecondaryDown = getMillis(); _gestureStartX = x; _gestureStartY = y; if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONUP; event.mouse.x = _videoContext->mouseX; event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_RBUTTONDOWN; _queuedInputEvent.mouse.x = _videoContext->mouseX; _queuedInputEvent.mouse.y = _videoContext->mouseY; } else return false; return true; }
bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int y) { int curTime = getMillis(); if (curTime - _lastSecondaryDown < 400) { //printf("Right tap!\n"); if (curTime - _lastSecondaryTap < 400 && !_videoContext->overlayVisible) { //printf("Right escape!\n"); event.type = Common::EVENT_KEYDOWN; _queuedInputEvent.type = Common::EVENT_KEYUP; event.kbd.flags = _queuedInputEvent.kbd.flags = 0; event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_ESCAPE; event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_ESCAPE; _queuedEventTime = curTime + kQueuedInputEventDelay; _lastSecondaryTap = 0; } else if (!_mouseClickAndDragEnabled) { //printf("Rightclick!\n"); event.type = Common::EVENT_RBUTTONDOWN; event.mouse.x = _videoContext->mouseX; event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_RBUTTONUP; _queuedInputEvent.mouse.x = _videoContext->mouseX; _queuedInputEvent.mouse.y = _videoContext->mouseY; _lastSecondaryTap = curTime; _queuedEventTime = curTime + kQueuedInputEventDelay; } else { //printf("Right nothing!\n"); return false; } } if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_RBUTTONUP; event.mouse.x = _videoContext->mouseX; event.mouse.y = _videoContext->mouseY; } return true; }
bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) { //printf("Mouse down at (%u, %u)\n", x, y); // Workaround: kInputMouseSecondToggled isn't always sent when the // secondary finger is lifted. Need to make sure we get out of that mode. _secondaryTapped = false; if (_touchpadModeEnabled) { _lastPadX = x; _lastPadY = y; } else warpMouse(x, y); if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONDOWN; event.mouse.x = _videoContext->mouseX; event.mouse.y = _videoContext->mouseY; return true; } else { _lastMouseDown = getMillis(); } return false; }
void OSystem_PS2::readRtcTime(void) { struct CdClock cdClock; readRTC(&cdClock); g_lastTimeCheck = getMillis(); if (cdClock.stat) { msgPrintf(5000, "Unable to read RTC time, EC: %d\n", cdClock.stat); g_day = g_month = 1; g_year = 0; g_timeSecs = 0; } else { int gmtOfs = configGetTimezone(); if (configIsDaylightSavingEnabled()) gmtOfs += 60; int timeSecs = (FROM_BCD(cdClock.hour) * 60 + FROM_BCD(cdClock.minute)) * 60 + FROM_BCD(cdClock.second); timeSecs -= 9 * 60 * 60; // minus 9 hours, JST -> GMT conversion timeSecs += gmtOfs * 60; // GMT -> timezone the user selected g_day = FROM_BCD(cdClock.day); g_month = FROM_BCD(cdClock.month); g_year = FROM_BCD(cdClock.year); if (timeSecs < 0) { buildNewDate(-1); timeSecs += SECONDS_PER_DAY; } else if (timeSecs >= SECONDS_PER_DAY) { buildNewDate(+1); timeSecs -= SECONDS_PER_DAY; } g_timeSecs = (uint32)timeSecs; } sioprintf("Time: %d:%02d:%02d - %d.%d.%4d\n", g_timeSecs / (60 * 60), (g_timeSecs / 60) % 60, g_timeSecs % 60, g_day, g_month, g_year + 2000); }
int main(int argc, char **argv) { srand(time(NULL)); setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); if(!checkArgs(argc, argv, &args)) { fprintf(stderr,"Invalid Arguments\n"); exit(1); } log_fd = fopen(args.fname, "w"); printf("Emulator Launched"); q1_index = q2_index = q3_index = 0; q1 = (queued_packet*) malloc(args.queue_size * sizeof(queued_packet)); q2 = (queued_packet*) malloc(args.queue_size * sizeof(queued_packet)); q3 = (queued_packet*) malloc(args.queue_size * sizeof(queued_packet)); //sock = openUDPSocket(); Testing only sock = openRawSocket(); if(bind(sock,(struct sockaddr*) &(args.sin), sizeof(args.sin)) < 0) { perror("Failed to bind to UDP socket"); exit(errno); } m1 = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(m1,NULL); m2 = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(m2,NULL); m3 = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(m3,NULL); pthread_t mThread; if(pthread_create(&mThread, NULL, tMain, (void*) NULL)) { perror("Unable to create thread"); exit(errno); } while(1) { unsigned long time = getMillis(); while(q1_index > 0 && q1[0].timestamp < time) { if(q1[0].timestamp == 0) { unsigned long delay = (10 * (rand() % 110)) + 100; q1[0].timestamp = time + delay; }else if(q1[0].timestamp <= time) { dequeuePacket(q1, m1, &q1_index); } } while(q2_index > 0 && q2[0].timestamp < time) { if(q2[0].timestamp == 0) { unsigned long delay = (10 * (rand() % 110)) + 100; q2[0].timestamp = time + delay; }else if(q2[0].timestamp <= time) { dequeuePacket(q2, m1, &q2_index); } } while(q3_index > 0 && q3[0].timestamp < time) { if(q3[0].timestamp == 0) { unsigned long delay = (10 * (rand() % 110)) + 100; q3[0].timestamp = time + delay; }else if(q3[0].timestamp <= time) { dequeuePacket(q3, m1, &q3_index); } } } pthread_cancel(mThread); fclose(log_fd); return 0; }