gboolean S9xIdleFunc (gpointer data) { if (needs_fullscreening) { top_level->enter_fullscreen_mode(); needs_fullscreening = FALSE; } if (Settings.Paused) { S9xSetSoundMute (gui_config->mute_sound); S9xSoundStop (); #ifdef USE_JOYSTICK gui_config->flush_joysticks (); #endif #ifdef NETPLAY_SUPPORT if (Settings.NetPlay && NetPlay.Connected) { S9xNPSendPause (TRUE); } #endif /* Move to a timer-based function to use less CPU */ g_timeout_add (100, S9xPauseFunc, NULL); top_level->update_statusbar (); return FALSE; } if (syncing) S9xSyncSpeedFinish (); S9xCheckPointerTimer (); S9xProcessEvents (TRUE); #ifdef NETPLAY_SUPPORT if (!S9xNetplayPush ()) { #endif if(top_level->user_rewind) top_level->user_rewind = stateMan.pop(); else if(IPPU.TotalEmulatedFrames % gui_config->rewindGranularity == 0) stateMan.push(); S9xMainLoop (); S9xMixSound (); #ifdef NETPLAY_SUPPORT S9xNetplayPop (); } #endif return TRUE; }
gboolean S9xPauseFunc (gpointer data) { S9xProcessEvents (TRUE); if (!gui_config->rom_loaded) return TRUE; #ifdef NETPLAY_SUPPORT if (!S9xNetplayPush ()) { S9xNetplayPop (); } #endif if (!Settings.Paused) /* Coming out of pause */ { #ifdef USE_JOYSTICK /* Clear joystick queues */ gui_config->flush_joysticks (); #endif S9xSetSoundMute (FALSE); S9xSoundStart (); #ifdef NETPLAY_SUPPORT if (Settings.NetPlay && NetPlay.Connected) { S9xNPSendPause (FALSE); } #endif /* Resume high-performance callback */ idle_func_id = g_idle_add_full (IDLE_FUNC_PRIORITY, S9xIdleFunc, NULL, NULL); top_level->update_statusbar (); return FALSE; } return TRUE; }
int S9xNetplaySyncSpeed (void) { if (!Settings.NetPlay || !NetPlay.Connected) return 0; // Send 1st joypad's position update to server S9xNPSendJoypadUpdate (local_joypads[0]); // set input from network for (int i = 0; i < NP_MAX_CLIENTS; i++) joypads[i] = S9xNPGetJoypad (i); if (!S9xNPCheckForHeartBeat ()) { // No heartbeats already arrived, have to wait for one. NetPlay.PendingWait4Sync = !S9xNPWaitForHeartBeatDelay (100); IPPU.RenderThisFrame = TRUE; IPPU.SkippedFrames = 0; } else { int difference = (int) (NetPlay.MySequenceNum) - (int) (NetPlay.ServerSequenceNum); if (difference < 0) difference += 256; if (NetPlay.Waiting4EmulationThread) { if ((unsigned int) difference <= (NetPlay.MaxBehindFrameCount / 2)) { NetPlay.Waiting4EmulationThread = FALSE; S9xNPSendPause (FALSE); } } else { if ((unsigned int) difference >= (NetPlay.MaxBehindFrameCount)) { NetPlay.Waiting4EmulationThread = TRUE; S9xNPSendPause (TRUE); } } NetPlay.PendingWait4Sync = !S9xNPWaitForHeartBeatDelay (200); if (IPPU.SkippedFrames < NetPlay.MaxFrameSkip) { IPPU.SkippedFrames++; IPPU.RenderThisFrame = FALSE; } else { IPPU.RenderThisFrame = TRUE; IPPU.SkippedFrames = 0; } } if (!NetPlay.PendingWait4Sync) { NetPlay.FrameCount++; S9xNPStepJoypadHistory (); } return 1; }
void S9xSyncSpeed( void) { #ifdef NETPLAY_SUPPORT if (Settings.NetPlay) { #if defined (NP_DEBUG) && NP_DEBUG == 2 printf ("CLIENT: SyncSpeed @%d\n", timeGetTime () - START); #endif S9xWinScanJoypads (); LONG prev; BOOL success; // Wait for heart beat from server if ((success = ReleaseSemaphore (GUI.ClientSemaphore, 1, &prev)) && prev == 0) { // No heartbeats already arrived, have to wait for one. // Mop up the ReleaseSemaphore test above... WaitForSingleObject (GUI.ClientSemaphore, 0); // ... and then wait for the real sync-signal from the // client loop thread. NetPlay.PendingWait4Sync = WaitForSingleObject (GUI.ClientSemaphore, 100) != WAIT_OBJECT_0; #if defined (NP_DEBUG) && NP_DEBUG == 2 if (NetPlay.PendingWait4Sync) printf ("CLIENT: PendingWait4Sync1 @%d\n", timeGetTime () - START); #endif IPPU.RenderThisFrame = TRUE; IPPU.SkippedFrames = 0; } else { if (success) { // Once for the ReleaseSemaphore above... WaitForSingleObject (GUI.ClientSemaphore, 0); if (prev == 4 && NetPlay.Waiting4EmulationThread) { // Reached the lower behind count threshold - tell the // server its safe to start sending sync pulses again. NetPlay.Waiting4EmulationThread = FALSE; S9xNPSendPause (FALSE); } #if defined (NP_DEBUG) && NP_DEBUG == 2 if (prev > 1) { printf ("CLIENT: SyncSpeed prev: %d @%d\n", prev, timeGetTime () - START); } #endif } else { #ifdef NP_DEBUG printf ("*** CLIENT: SyncSpeed: Release failed @ %d\n", timeGetTime () - START); #endif } // ... and again to mop up the already-waiting sync-signal NetPlay.PendingWait4Sync = WaitForSingleObject (GUI.ClientSemaphore, 200) != WAIT_OBJECT_0; #if defined (NP_DEBUG) && NP_DEBUG == 2 if (NetPlay.PendingWait4Sync) printf ("CLIENT: PendingWait4Sync2 @%d\n", timeGetTime () - START); #endif if (IPPU.SkippedFrames < NetPlay.MaxFrameSkip) { IPPU.SkippedFrames++; IPPU.RenderThisFrame = FALSE; } else { IPPU.RenderThisFrame = TRUE; IPPU.SkippedFrames = 0; } } // Give up remainder of time-slice to any other waiting threads, // if they need any time, that is. Sleep (0); if (!NetPlay.PendingWait4Sync) { NetPlay.FrameCount++; S9xNPStepJoypadHistory (); } } else #endif if (!Settings.TurboMode && Settings.SkipFrames == AUTO_FRAMERATE && !GUI.AVIOut) { if (!do_frame_adjust) { IPPU.RenderThisFrame = TRUE; IPPU.SkippedFrames = 0; } else { if (IPPU.SkippedFrames < Settings.AutoMaxSkipFrames) { IPPU.SkippedFrames++; IPPU.RenderThisFrame = FALSE; } else { IPPU.RenderThisFrame = TRUE; IPPU.SkippedFrames = 0; } } } else { uint32 SkipFrames; if(Settings.TurboMode && !GUI.AVIOut) SkipFrames = Settings.TurboSkipFrames; else SkipFrames = (Settings.SkipFrames == AUTO_FRAMERATE) ? 0 : Settings.SkipFrames; if (IPPU.FrameSkip++ >= SkipFrames) { IPPU.FrameSkip = 0; IPPU.SkippedFrames = 0; IPPU.RenderThisFrame = TRUE; } else { IPPU.SkippedFrames++; IPPU.RenderThisFrame = GUI.AVIOut!=0; } } }
gboolean S9xIdleFunc (gpointer data) { if (needs_fullscreening) { top_level->enter_fullscreen_mode(); needs_fullscreening = FALSE; } if (Settings.Paused) { S9xSetSoundMute (gui_config->mute_sound); S9xSoundStop (); #ifdef USE_JOYSTICK gui_config->flush_joysticks (); #endif #ifdef NETPLAY_SUPPORT if (Settings.NetPlay && NetPlay.Connected) { S9xNPSendPause (TRUE); } #endif /* Move to a timer-based function to use less CPU */ g_timeout_add (100, S9xPauseFunc, NULL); top_level->update_statusbar (); return FALSE; } if (syncing) S9xSyncSpeedFinish (); S9xCheckPointerTimer (); S9xProcessEvents (TRUE); #ifdef NETPLAY_SUPPORT if (!S9xNetplayPush ()) { #endif if(Settings.Rewinding) { uint16 joypads[8]; for (int i = 0; i < 8; i++) joypads[i] = MovieGetJoypad(i); Settings.Rewinding = stateMan.pop(); for (int i = 0; i < 8; i++) MovieSetJoypad (i, joypads[i]); } else if(IPPU.TotalEmulatedFrames % gui_config->rewind_granularity == 0) stateMan.push(); static int muted_from_turbo = FALSE; static int mute_saved_state = FALSE; if (Settings.TurboMode && !muted_from_turbo && gui_config->mute_sound_turbo) { muted_from_turbo = TRUE; mute_saved_state = Settings.Mute; S9xSetSoundMute (TRUE); } if (!Settings.TurboMode && muted_from_turbo) { muted_from_turbo = FALSE; Settings.Mute = mute_saved_state; } S9xMainLoop (); #ifdef NETPLAY_SUPPORT S9xNetplayPop (); } #endif return TRUE; }