this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

libretro: Replace clock() with frame time callback (#2589)

authored by

Rob Loach and committed by
GitHub
1c8eb84c 41fa7e18

+35 -6
+35 -6
src/system/libretro/tic80_libretro.c
··· 35 35 #define RETRO_BASE_POINTER_SPEED_DPAD 1.6f 36 36 #define RETRO_SLOW_MOUSE_FACTOR_ANALOG 0.3f 37 37 #define RETRO_SLOW_MOUSE_FACTOR_DPAD 0.4f 38 + #ifndef TIC80_FREQUENCY 39 + #define TIC80_FREQUENCY 1000000 40 + #endif 38 41 39 42 enum pointer_device_type 40 43 { ··· 74 77 int mouseHideTimer; 75 78 int mouseHideTimerStart; 76 79 tic80* tic; 80 + retro_usec_t frameTime; 77 81 }; 78 82 static struct tic80_state* state; 79 83 80 84 /** 81 - * TIC-80 callback; Request counter 85 + * TIC-80 callback; Request counter. 82 86 */ 83 87 static u64 tic80_libretro_counter() 84 88 { 85 - return clock(); 89 + if (state == NULL) { 90 + return 0; 91 + } 92 + 93 + return (u64)state->frameTime; 86 94 } 87 95 88 96 /** 89 - * TIC-80 callback; Request freq 97 + * TIC-80 callback; Request frequency. 90 98 */ 91 - static u64 tic80_libretro_freq() 99 + static u64 tic80_libretro_frequency() 92 100 { 93 - return CLOCKS_PER_SEC; 101 + return TIC80_FREQUENCY; 94 102 } 95 103 96 104 /** ··· 143 151 va_start(va, fmt); 144 152 vfprintf(stderr, fmt, va); 145 153 va_end(va); 154 + } 155 + 156 + /** 157 + * libretro callback; Called to indicate how much time has passed since last retro_run(). 158 + */ 159 + void tic80_libretro_frame_time(retro_usec_t usec) { 160 + if (state == NULL) { 161 + return; 162 + } 163 + 164 + state->frameTime = usec; 146 165 } 147 166 148 167 /** ··· 838 857 tic80_libretro_update_keyboard(&state->input.keyboard); 839 858 840 859 // Update the game state. 841 - tic80_tick(game, state->input, tic80_libretro_counter, tic80_libretro_freq); 860 + tic80_tick(game, state->input, tic80_libretro_counter, tic80_libretro_frequency); 842 861 tic80_sound(game); 843 862 } 844 863 ··· 1035 1054 // Ensure content data is available. 1036 1055 if (info->data == NULL) { 1037 1056 log_cb(RETRO_LOG_ERROR, "[TIC-80] No content data provided.\n"); 1057 + return false; 1058 + } 1059 + 1060 + // Set up the frame time callback. 1061 + struct retro_frame_time_callback frame_time = { 1062 + .callback = tic80_libretro_frame_time, 1063 + .reference = TIC80_FREQUENCY / TIC80_FRAMERATE, 1064 + }; 1065 + if (!environ_cb(RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK, &frame_time)) { 1066 + log_cb(RETRO_LOG_ERROR, "[TIC-80] Failed to set frame time callback.\n"); 1038 1067 return false; 1039 1068 } 1040 1069