get rid of os_GetSeconds()
replace it with std::chrono-based getTimeMs()
This commit is contained in:
parent
5541d34a9e
commit
06a6e26588
|
@ -28,10 +28,7 @@
|
|||
#include "network/picoppp.h"
|
||||
#include "serialize.h"
|
||||
#include "cfg/option.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#include "oslib/oslib.h"
|
||||
#endif
|
||||
#include "stdclass.h"
|
||||
#include <cassert>
|
||||
|
||||
#define MODEM_COUNTRY_RES 0
|
||||
|
@ -127,7 +124,7 @@ static u64 last_dial_time;
|
|||
static bool data_sent;
|
||||
|
||||
#ifndef NDEBUG
|
||||
static double last_comm_stats;
|
||||
static u64 last_comm_stats;
|
||||
static int sent_bytes;
|
||||
static int recvd_bytes;
|
||||
static FILE *recv_fp;
|
||||
|
@ -137,7 +134,7 @@ static FILE *sent_fp;
|
|||
static int modem_sched_func(int tag, int cycles, int jitter, void *arg)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (os_GetSeconds() - last_comm_stats >= 2)
|
||||
if (getTimeMs() - last_comm_stats >= 2000)
|
||||
{
|
||||
if (last_comm_stats != 0)
|
||||
{
|
||||
|
@ -147,7 +144,7 @@ static int modem_sched_func(int tag, int cycles, int jitter, void *arg)
|
|||
sent_bytes = 0;
|
||||
recvd_bytes = 0;
|
||||
}
|
||||
last_comm_stats = os_GetSeconds();
|
||||
last_comm_stats = getTimeMs();
|
||||
}
|
||||
#endif
|
||||
int callback_cycles = 0;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include <array>
|
||||
#include "spg.h"
|
||||
#include "hw/holly/holly_intc.h"
|
||||
#include "hw/holly/sb.h"
|
||||
#include "hw/sh4/sh4_sched.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "hw/maple/maple_if.h"
|
||||
#include "serialize.h"
|
||||
#include "network/ggpo.h"
|
||||
#include "hw/pvr/Renderer_if.h"
|
||||
#include "stdclass.h"
|
||||
#include <array>
|
||||
|
||||
#ifdef TEST_AUTOMATION
|
||||
#include "input/gamepad_device.h"
|
||||
|
@ -21,7 +21,7 @@ static u32 prv_cur_scanline = -1;
|
|||
|
||||
#if !defined(NDEBUG) || defined(DEBUGFAST)
|
||||
static u32 vblk_cnt;
|
||||
static float last_fps;
|
||||
static u64 last_fps;
|
||||
#endif
|
||||
|
||||
// 27 mhz pixel clock
|
||||
|
@ -156,17 +156,18 @@ static int spg_line_sched(int tag, int cycles, int jitter, void *arg)
|
|||
|
||||
rend_vblank();
|
||||
|
||||
double now = os_GetSeconds() * 1000000.0;
|
||||
u64 now = getTimeMs();
|
||||
cpu_time_idx = (cpu_time_idx + 1) % cpu_cycles.size();
|
||||
if (cpu_cycles[cpu_time_idx] != 0)
|
||||
{
|
||||
u32 cycle_span = (u32)(sh4_sched_now64() - cpu_cycles[cpu_time_idx]);
|
||||
double time_span = now - real_times[cpu_time_idx];
|
||||
double cpu_speed = ((double)cycle_span / time_span) / (SH4_MAIN_CLOCK / 100000000);
|
||||
SH4FastEnough = cpu_speed >= 85.0;
|
||||
u64 time_span = now - real_times[cpu_time_idx];
|
||||
float cpu_speed = ((float)cycle_span / time_span) / (SH4_MAIN_CLOCK / 100000);
|
||||
SH4FastEnough = cpu_speed >= 85.f;
|
||||
}
|
||||
else
|
||||
else {
|
||||
SH4FastEnough = false;
|
||||
}
|
||||
cpu_cycles[cpu_time_idx] = sh4_sched_now64();
|
||||
real_times[cpu_time_idx] = now;
|
||||
|
||||
|
@ -176,15 +177,15 @@ static int spg_line_sched(int tag, int cycles, int jitter, void *arg)
|
|||
|
||||
#if !defined(NDEBUG) || defined(DEBUGFAST)
|
||||
vblk_cnt++;
|
||||
if ((os_GetSeconds()-last_fps)>2)
|
||||
if (getTimeMs() - last_fps >= 2000)
|
||||
{
|
||||
static int Last_FC;
|
||||
double ts=os_GetSeconds()-last_fps;
|
||||
double spd_fps=(FrameCount-Last_FC)/ts;
|
||||
double spd_vbs=vblk_cnt/ts;
|
||||
double spd_cpu=spd_vbs*Frame_Cycles;
|
||||
spd_cpu/=1000000; //mrhz kthx
|
||||
double fullvbs=(spd_vbs/spd_cpu)*200;
|
||||
double ts = ((double)getTimeMs() - last_fps) / 1000.0;
|
||||
double spd_fps = (FrameCount - Last_FC) / ts;
|
||||
double spd_vbs = vblk_cnt / ts;
|
||||
double spd_cpu = spd_vbs * Frame_Cycles;
|
||||
spd_cpu /= 1000000.0; //mrhz kthx
|
||||
double fullvbs = (spd_vbs / spd_cpu) * 200.0;
|
||||
|
||||
Last_FC=FrameCount;
|
||||
|
||||
|
@ -210,13 +211,13 @@ static int spg_line_sched(int tag, int cycles, int jitter, void *arg)
|
|||
|
||||
double full_rps = spd_fps + fskip / ts;
|
||||
|
||||
INFO_LOG(COMMON, "%s/%c - %4.2f - %4.2f - V: %4.2f (%.2f, %s%s%4.2f) R: %4.2f+%4.2f",
|
||||
VER_SHORTNAME,'n',mspdf,spd_cpu*100/200,spd_vbs,
|
||||
spd_vbs/full_rps,mode,res,fullvbs,
|
||||
spd_fps,fskip/ts);
|
||||
INFO_LOG(COMMON, "SPG - %4.2f - %4.2f - V: %4.2f (%.2f, %s%s%4.2f) R: %4.2f+%4.2f",
|
||||
mspdf, spd_cpu * 100 / 200, spd_vbs,
|
||||
spd_vbs / full_rps, mode, res, fullvbs,
|
||||
spd_fps, fskip / ts);
|
||||
|
||||
fskip=0;
|
||||
last_fps=os_GetSeconds();
|
||||
fskip = 0;
|
||||
last_fps = getTimeMs();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "hw/sh4/sh4_if.h"
|
||||
#include "hw/sh4/sh4_core.h"
|
||||
#include "types.h"
|
||||
#include "stdclass.h"
|
||||
|
||||
#ifdef FAST_MMU
|
||||
|
||||
|
@ -156,7 +157,7 @@ int main(int argc, char *argv[])
|
|||
addrs.push_back(random());
|
||||
asids.push_back(666);
|
||||
}
|
||||
double start = os_GetSeconds();
|
||||
u64 start = getTimeMs();
|
||||
int success = 0;
|
||||
const int loops = 100000;
|
||||
for (int i = 0; i < loops; i++)
|
||||
|
@ -170,8 +171,8 @@ int main(int argc, char *argv[])
|
|||
success++;
|
||||
}
|
||||
}
|
||||
double end = os_GetSeconds();
|
||||
printf("Lookup time: %f ms. Success rate %f max_len %d\n", (end - start) * 1000.0 / addrs.size(), (double)success / addrs.size() / loops, 0/*max_length*/);
|
||||
u64 end = getTimeMs();
|
||||
printf("Lookup time: %f ms. Success rate %f max_len %d\n", ((double)end - start) / addrs.size(), (double)success / addrs.size() / loops, 0/*max_length*/);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "gamepad_device.h"
|
||||
#include "cfg/cfg.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "stdclass.h"
|
||||
#include "rend/gui.h"
|
||||
#include "emulator.h"
|
||||
#include "hw/maple/maple_devs.h"
|
||||
|
@ -152,7 +152,7 @@ bool GamepadDevice::handleButtonInput(int port, DreamcastKey key, bool pressed)
|
|||
bool GamepadDevice::gamepad_btn_input(u32 code, bool pressed)
|
||||
{
|
||||
if (_input_detected != nullptr && _detecting_button
|
||||
&& os_GetSeconds() >= _detection_start_time && pressed)
|
||||
&& getTimeMs() >= _detection_start_time && pressed)
|
||||
{
|
||||
_input_detected(code, false, false);
|
||||
_input_detected = nullptr;
|
||||
|
@ -207,7 +207,7 @@ bool GamepadDevice::gamepad_axis_input(u32 code, int value)
|
|||
{
|
||||
bool positive = value >= 0;
|
||||
if (_input_detected != NULL && _detecting_axis
|
||||
&& os_GetSeconds() >= _detection_start_time && std::abs(value) >= 16384)
|
||||
&& getTimeMs() >= _detection_start_time && std::abs(value) >= 16384)
|
||||
{
|
||||
_input_detected(code, true, positive);
|
||||
_input_detected = nullptr;
|
||||
|
@ -505,7 +505,7 @@ void GamepadDevice::detect_btn_input(input_detected_cb button_pressed)
|
|||
_input_detected = button_pressed;
|
||||
_detecting_button = true;
|
||||
_detecting_axis = false;
|
||||
_detection_start_time = os_GetSeconds() + 0.2;
|
||||
_detection_start_time = getTimeMs() + 200;
|
||||
}
|
||||
|
||||
void GamepadDevice::detect_axis_input(input_detected_cb axis_moved)
|
||||
|
@ -513,7 +513,7 @@ void GamepadDevice::detect_axis_input(input_detected_cb axis_moved)
|
|||
_input_detected = axis_moved;
|
||||
_detecting_button = false;
|
||||
_detecting_axis = true;
|
||||
_detection_start_time = os_GetSeconds() + 0.2;
|
||||
_detection_start_time = getTimeMs() + 200;
|
||||
}
|
||||
|
||||
void GamepadDevice::detectButtonOrAxisInput(input_detected_cb input_changed)
|
||||
|
@ -521,7 +521,7 @@ void GamepadDevice::detectButtonOrAxisInput(input_detected_cb input_changed)
|
|||
_input_detected = input_changed;
|
||||
_detecting_button = true;
|
||||
_detecting_axis = true;
|
||||
_detection_start_time = os_GetSeconds() + 0.2;
|
||||
_detection_start_time = getTimeMs() + 200;
|
||||
}
|
||||
|
||||
#ifdef TEST_AUTOMATION
|
||||
|
|
|
@ -177,7 +177,7 @@ private:
|
|||
int _maple_port;
|
||||
bool _detecting_button = false;
|
||||
bool _detecting_axis = false;
|
||||
double _detection_start_time = 0.0;
|
||||
u64 _detection_start_time = 0;
|
||||
input_detected_cb _input_detected;
|
||||
bool _remappable;
|
||||
u32 digitalToAnalogState[4];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "evdev.h"
|
||||
#include "input/gamepad_device.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "stdclass.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
void rumble(float power, float inclination, u32 duration_ms) override
|
||||
{
|
||||
vib_inclination = inclination * power;
|
||||
vib_stop_time = os_GetSeconds() + duration_ms / 1000.0;
|
||||
vib_stop_time = getTimeMs() + duration_ms;
|
||||
|
||||
do_rumble(power, duration_ms);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
{
|
||||
if (vib_inclination > 0)
|
||||
{
|
||||
int rem_time = (vib_stop_time - os_GetSeconds()) * 1000;
|
||||
int rem_time = vib_stop_time - getTimeMs();
|
||||
if (rem_time <= 0)
|
||||
vib_inclination = 0;
|
||||
else
|
||||
|
@ -308,7 +308,7 @@ private:
|
|||
std::string _devnode;
|
||||
int _rumble_effect_id = -1;
|
||||
float vib_inclination = 0;
|
||||
double vib_stop_time = 0;
|
||||
u64 vib_stop_time = 0;
|
||||
std::map<u32, int> axis_min_values;
|
||||
std::map<u32, unsigned int> axis_ranges;
|
||||
static std::map<std::string, std::shared_ptr<EvdevGamepadDevice>> evdev_gamepads;
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#include <sys/personality.h>
|
||||
#endif
|
||||
#if !defined(TARGET_BSD) && !defined(__ANDROID__) && defined(TARGET_VIDEOCORE)
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#ifdef __linux__
|
||||
#include <pthread.h>
|
||||
|
@ -123,14 +120,6 @@ void os_UninstallFaultHandler()
|
|||
}
|
||||
#endif // !defined(TARGET_NO_EXCEPTIONS)
|
||||
|
||||
double os_GetSeconds()
|
||||
{
|
||||
timeval a;
|
||||
gettimeofday (&a,0);
|
||||
static u64 tvs_base=a.tv_sec;
|
||||
return a.tv_sec-tvs_base+a.tv_usec/1000000.0;
|
||||
}
|
||||
|
||||
#if !defined(__unix__) && !defined(LIBRETRO) && !defined(__SWITCH__)
|
||||
[[noreturn]] void os_DebugBreak()
|
||||
{
|
||||
|
@ -138,11 +127,15 @@ double os_GetSeconds()
|
|||
}
|
||||
#endif
|
||||
|
||||
void enable_runfast()
|
||||
// RunFast mode is the combination of the following conditions:
|
||||
// * the VFP11 coprocessor is in flush-to-zero mode
|
||||
// * the VFP11 coprocessor is in default NaN mode
|
||||
// * all exception enable bits are cleared.
|
||||
static void enable_runfast()
|
||||
{
|
||||
#if HOST_CPU==CPU_ARM && !defined(ARMCC)
|
||||
static const unsigned int x = 0x04086060;
|
||||
static const unsigned int y = 0x03000000;
|
||||
#if HOST_CPU == CPU_ARM && !defined(ARMCC)
|
||||
static const unsigned int x = 0x04086060; // reset and disable FP exceptions, flush-to-zero, default NaN mode
|
||||
static const unsigned int y = 0x03000000; // round to zero
|
||||
int r;
|
||||
asm volatile (
|
||||
"fmrx %0, fpscr \n\t" //r0 = FPSCR
|
||||
|
@ -154,32 +147,18 @@ void enable_runfast()
|
|||
);
|
||||
|
||||
DEBUG_LOG(BOOT, "ARM VFP-Run Fast (NFP) enabled !");
|
||||
#endif
|
||||
}
|
||||
|
||||
void linux_fix_personality() {
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
DEBUG_LOG(BOOT, "Personality: %08X", personality(0xFFFFFFFF));
|
||||
personality(~READ_IMPLIES_EXEC & personality(0xFFFFFFFF));
|
||||
DEBUG_LOG(BOOT, "Updated personality: %08X", personality(0xFFFFFFFF));
|
||||
#endif
|
||||
}
|
||||
|
||||
void linux_rpi2_init() {
|
||||
#if !defined(TARGET_BSD) && !defined(__ANDROID__) && defined(TARGET_VIDEOCORE)
|
||||
void* handle;
|
||||
void (*rpi_bcm_init)(void);
|
||||
|
||||
handle = dlopen("libbcm_host.so", RTLD_LAZY);
|
||||
|
||||
if (handle) {
|
||||
DEBUG_LOG(BOOT, "found libbcm_host");
|
||||
*(void**) (&rpi_bcm_init) = dlsym(handle, "bcm_host_init");
|
||||
if (rpi_bcm_init) {
|
||||
DEBUG_LOG(BOOT, "rpi2: bcm_init");
|
||||
rpi_bcm_init();
|
||||
}
|
||||
}
|
||||
// Some old CPUs lack the NX (no exec) flag so READ_IMPLIES_EXEC is set by default on these platforms.
|
||||
// However resetting the flag isn't going to magically change the way the CPU works. So I wonder how useful this is.
|
||||
// It's not needed on modern 64-bit architectures anyway.
|
||||
static void linux_fix_personality()
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__) && (HOST_CPU == CPU_X86 || HOST_CPU == CPU_ARM)
|
||||
DEBUG_LOG(BOOT, "Personality: %08X", personality(0xFFFFFFFF));
|
||||
personality(~READ_IMPLIES_EXEC & personality(0xFFFFFFFF));
|
||||
DEBUG_LOG(BOOT, "Updated personality: %08X", personality(0xFFFFFFFF));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -193,7 +172,6 @@ static void sigintHandler(int)
|
|||
void common_linux_setup()
|
||||
{
|
||||
linux_fix_personality();
|
||||
linux_rpi2_init();
|
||||
|
||||
enable_runfast();
|
||||
os_InstallFaultHandler();
|
||||
|
|
|
@ -175,10 +175,12 @@ LogManager::~LogManager()
|
|||
// in the form 00:00:000.
|
||||
static std::string GetTimeFormatted()
|
||||
{
|
||||
double now = os_GetSeconds();
|
||||
u32 minutes = (u32)now / 60;
|
||||
u32 seconds = (u32)now % 60;
|
||||
u32 ms = (now - (u32)now) * 1000;
|
||||
u64 now = getTimeMs();
|
||||
u32 ms = (u32)(now % 1000);
|
||||
now /= 1000;
|
||||
u32 seconds = (u32)(now % 60);
|
||||
now /= 60;
|
||||
u32 minutes = (u32)now;
|
||||
return StringFromFormat("%02d:%02d:%03d", minutes, seconds, ms);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,6 @@
|
|||
#include "stdclass.h"
|
||||
|
||||
//#define BBA_PCAPNG_DUMP
|
||||
#ifdef BBA_PCAPNG_DUMP
|
||||
#include "oslib/oslib.h"
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#define _POSIX_SOURCE
|
||||
|
@ -883,7 +880,7 @@ static void dumpFrame(const u8 *frame, u32 size)
|
|||
fwrite(&roundedSize, sizeof(roundedSize), 1, pcapngDump);
|
||||
u32 ifId = 0;
|
||||
fwrite(&ifId, sizeof(ifId), 1, pcapngDump);
|
||||
u64 now = (u64)(os_GetSeconds() * 1000000.0);
|
||||
u64 now = getTimeMs() * 1000;
|
||||
fwrite((u32 *)&now + 1, 4, 1, pcapngDump);
|
||||
fwrite(&now, 4, 1, pcapngDump);
|
||||
fwrite(&size, sizeof(size), 1, pcapngDump);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#endif
|
||||
|
||||
void os_SetWindowText(const char* text);
|
||||
double os_GetSeconds();
|
||||
|
||||
void os_DoEvents();
|
||||
void os_CreateWindow();
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "gamesdb.h"
|
||||
#include "http_client.h"
|
||||
#include "stdclass.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "emulator.h"
|
||||
|
||||
#define APIKEY "3fcc5e726a129924972be97abfd577ac5311f8f12398a9d9bcb5a377d4656fa8"
|
||||
|
@ -74,9 +73,9 @@ void TheGamesDb::copyFile(const std::string& from, const std::string& to)
|
|||
|
||||
json TheGamesDb::httpGet(const std::string& url)
|
||||
{
|
||||
if (os_GetSeconds() < blackoutPeriod)
|
||||
if (getTimeMs() < blackoutPeriod)
|
||||
throw std::runtime_error("");
|
||||
blackoutPeriod = 0.0;
|
||||
blackoutPeriod = 0;
|
||||
|
||||
DEBUG_LOG(COMMON, "TheGameDb: GET %s", url.c_str());
|
||||
std::vector<u8> receivedData;
|
||||
|
@ -84,9 +83,9 @@ json TheGamesDb::httpGet(const std::string& url)
|
|||
bool success = http::success(status);
|
||||
if (status == 403)
|
||||
// hit rate-limit cap
|
||||
blackoutPeriod = os_GetSeconds() + 60.0;
|
||||
blackoutPeriod = getTimeMs() + 60 * 1000;
|
||||
else if (!success)
|
||||
blackoutPeriod = os_GetSeconds() + 1.0;
|
||||
blackoutPeriod = getTimeMs() + 1000;
|
||||
if (!success || receivedData.empty())
|
||||
throw std::runtime_error("http error");
|
||||
|
||||
|
@ -382,7 +381,7 @@ void TheGamesDb::fetchByUids(std::vector<GameBoxart>& items)
|
|||
|
||||
void TheGamesDb::scrape(std::vector<GameBoxart>& items)
|
||||
{
|
||||
if (os_GetSeconds() < blackoutPeriod)
|
||||
if (getTimeMs() < blackoutPeriod)
|
||||
throw std::runtime_error("");
|
||||
blackoutPeriod = 0.0;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ private:
|
|||
|
||||
int dreamcastPlatformId = 0;
|
||||
int arcadePlatformId = 0;
|
||||
double blackoutPeriod = 0.0;
|
||||
u64 blackoutPeriod = 0;
|
||||
|
||||
std::map<std::string, std::string> boxartCache; // key: url, value: local file path
|
||||
};
|
||||
|
|
|
@ -78,7 +78,7 @@ static float mouseWheel;
|
|||
static std::string error_msg;
|
||||
static bool error_msg_shown;
|
||||
static std::string osd_message;
|
||||
static double osd_message_end;
|
||||
static u64 osd_message_end;
|
||||
static std::mutex osd_message_mutex;
|
||||
static void (*showOnScreenKeyboard)(bool show);
|
||||
static bool keysUpNextFrame[512];
|
||||
|
@ -920,7 +920,7 @@ static std::shared_ptr<GamepadDevice> mapped_device;
|
|||
static u32 mapped_code;
|
||||
static bool analogAxis;
|
||||
static bool positiveDirection;
|
||||
static double map_start_time;
|
||||
static u64 map_start_time;
|
||||
static bool arcade_button_mode;
|
||||
static u32 gamepad_port;
|
||||
|
||||
|
@ -986,8 +986,8 @@ static void detect_input_popup(const Mapping *mapping)
|
|||
if (ImGui::BeginPopupModal("Map Control", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove))
|
||||
{
|
||||
ImGui::Text("Waiting for control '%s'...", mapping->name);
|
||||
double now = os_GetSeconds();
|
||||
ImGui::Text("Time out in %d s", (int)(5 - (now - map_start_time)));
|
||||
u64 now = getTimeMs();
|
||||
ImGui::Text("Time out in %d s", (int)(5 - (now - map_start_time) / 1000));
|
||||
if (mapped_code != (u32)-1)
|
||||
{
|
||||
std::shared_ptr<InputMapping> input_mapping = mapped_device->get_input_mapping();
|
||||
|
@ -1012,7 +1012,7 @@ static void detect_input_popup(const Mapping *mapping)
|
|||
mapped_device = NULL;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
else if (now - map_start_time >= 5)
|
||||
else if (now - map_start_time >= 5000)
|
||||
{
|
||||
mapped_device = NULL;
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
@ -1239,7 +1239,7 @@ static void controller_mapping_popup(const std::shared_ptr<GamepadDevice>& gamep
|
|||
ImGui::NextColumn();
|
||||
if (ImGui::Button("Map"))
|
||||
{
|
||||
map_start_time = os_GetSeconds();
|
||||
map_start_time = getTimeMs();
|
||||
ImGui::OpenPopup("Map Control");
|
||||
mapped_device = gamepad;
|
||||
mapped_code = -1;
|
||||
|
@ -2859,13 +2859,13 @@ void gui_display_notification(const char *msg, int duration)
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(osd_message_mutex);
|
||||
osd_message = msg;
|
||||
osd_message_end = os_GetSeconds() + (double)duration / 1000.0;
|
||||
osd_message_end = getTimeMs() + duration;
|
||||
}
|
||||
|
||||
static std::string get_notification()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(osd_message_mutex);
|
||||
if (!osd_message.empty() && os_GetSeconds() >= osd_message_end)
|
||||
if (!osd_message.empty() && getTimeMs() >= osd_message_end)
|
||||
osd_message.clear();
|
||||
return osd_message;
|
||||
}
|
||||
|
@ -3348,7 +3348,7 @@ void gui_display_ui()
|
|||
emu.start();
|
||||
}
|
||||
|
||||
static float LastFPSTime;
|
||||
static u64 LastFPSTime;
|
||||
static int lastFrameCount = 0;
|
||||
static float fps = -1;
|
||||
|
||||
|
@ -3356,9 +3356,9 @@ static std::string getFPSNotification()
|
|||
{
|
||||
if (config::ShowFPS)
|
||||
{
|
||||
double now = os_GetSeconds();
|
||||
if (now - LastFPSTime >= 1.0) {
|
||||
fps = (MainFrameCount - lastFrameCount) / (now - LastFPSTime);
|
||||
u64 now = getTimeMs();
|
||||
if (now - LastFPSTime >= 1000) {
|
||||
fps = ((float)MainFrameCount - lastFrameCount) * 1000.f / (now - LastFPSTime);
|
||||
LastFPSTime = now;
|
||||
lastFrameCount = MainFrameCount;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ static bool gameRunning;
|
|||
static bool mouseCaptured;
|
||||
static std::string clipboardText;
|
||||
static std::string barcode;
|
||||
static double lastBarcodeTime;
|
||||
static u64 lastBarcodeTime;
|
||||
|
||||
static KeyboardLayout detectKeyboardLayout();
|
||||
static bool handleBarcodeScanner(const SDL_Event& event);
|
||||
|
@ -1179,8 +1179,8 @@ static bool handleBarcodeScanner(const SDL_Event& event)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
double now = os_GetSeconds();
|
||||
if (!barcode.empty() && now - lastBarcodeTime >= 0.5)
|
||||
u64 now = getTimeMs();
|
||||
if (!barcode.empty() && now - lastBarcodeTime >= 500)
|
||||
{
|
||||
INFO_LOG(INPUT, "Barcode timeout");
|
||||
barcode.clear();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "input/gamepad_device.h"
|
||||
#include "input/mouse.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "stdclass.h"
|
||||
#include "sdl.h"
|
||||
|
||||
template<bool Arcade = false, bool Gamepad = false>
|
||||
|
@ -233,7 +233,7 @@ public:
|
|||
if (rumbleEnabled)
|
||||
{
|
||||
vib_inclination = inclination * power;
|
||||
vib_stop_time = os_GetSeconds() + duration_ms / 1000.0;
|
||||
vib_stop_time = getTimeMs() + duration_ms;
|
||||
|
||||
u16 intensity = getRumbleIntensity(power);
|
||||
SDL_JoystickRumble(sdl_joystick, intensity, intensity, duration_ms);
|
||||
|
@ -245,7 +245,7 @@ public:
|
|||
return;
|
||||
if (vib_inclination > 0)
|
||||
{
|
||||
int rem_time = (vib_stop_time - os_GetSeconds()) * 1000;
|
||||
int rem_time = vib_stop_time - getTimeMs();
|
||||
if (rem_time <= 0)
|
||||
vib_inclination = 0;
|
||||
else
|
||||
|
@ -418,7 +418,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
double vib_stop_time = 0;
|
||||
u64 vib_stop_time = 0;
|
||||
SDL_JoystickID sdl_joystick_instance;
|
||||
|
||||
private:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#pragma once
|
||||
#ifdef __APPLE__
|
||||
#include "sdl_keyboard.h"
|
||||
#include "stdclass.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <IOKit/IOTypes.h>
|
||||
#include <stack>
|
||||
|
@ -55,7 +56,7 @@ public:
|
|||
if (!rumbleEnabled)
|
||||
return;
|
||||
|
||||
vib_stop_time = os_GetSeconds() + duration_ms / 1000.0;
|
||||
vib_stop_time = getTimeMs() + duration_ms;
|
||||
|
||||
__block int pattern;
|
||||
if (power >= 0.75)
|
||||
|
@ -82,7 +83,7 @@ public:
|
|||
dispatch_source_set_timer(_timer, DISPATCH_TIME_NOW, 10 * NSEC_PER_MSEC * rumblePower / 100.f, 0);
|
||||
|
||||
dispatch_source_set_event_handler(_timer, ^{
|
||||
if ( vib_stop_time - os_GetSeconds() < 0 )
|
||||
if (vib_stop_time < getTimeMs())
|
||||
{
|
||||
dispatch_source_cancel(_timer);
|
||||
return;
|
||||
|
@ -105,7 +106,7 @@ public:
|
|||
private:
|
||||
std::stack<dispatch_source_t> vib_timer_stack;
|
||||
CFTypeRef vib_device = NULL;
|
||||
double vib_stop_time = 0;
|
||||
u64 vib_stop_time = 0;
|
||||
};
|
||||
|
||||
#endif // _APPLE_
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <algorithm>
|
||||
|
@ -211,3 +212,12 @@ void RamRegion::free()
|
|||
freeAligned(data);
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
u64 getTimeMs()
|
||||
{
|
||||
using the_clock = std::chrono::steady_clock;
|
||||
std::chrono::time_point<the_clock> now = the_clock::now();
|
||||
static std::chrono::time_point<the_clock> start = now;
|
||||
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count();
|
||||
}
|
||||
|
|
|
@ -197,3 +197,5 @@ public:
|
|||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
u64 getTimeMs();
|
||||
|
|
|
@ -80,9 +80,6 @@ inline static void JITWriteProtect(bool enabled) {
|
|||
|
||||
#include "log/Log.h"
|
||||
|
||||
#define VER_EMUNAME "Flycast"
|
||||
#define VER_SHORTNAME VER_EMUNAME
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define stricmp strcasecmp
|
||||
#endif
|
||||
|
|
|
@ -169,18 +169,3 @@ void os_UninstallFaultHandler()
|
|||
#endif
|
||||
SetUnhandledExceptionFilter(prevExceptionHandler);
|
||||
}
|
||||
|
||||
double os_GetSeconds()
|
||||
{
|
||||
static double qpfd = []() {
|
||||
LARGE_INTEGER qpf;
|
||||
QueryPerformanceFrequency(&qpf);
|
||||
return 1.0 / qpf.QuadPart; }();
|
||||
|
||||
LARGE_INTEGER time_now;
|
||||
|
||||
QueryPerformanceCounter(&time_now);
|
||||
static LARGE_INTEGER time_now_base = time_now;
|
||||
|
||||
return (time_now.QuadPart - time_now_base.QuadPart) * qpfd;
|
||||
}
|
||||
|
|
|
@ -688,8 +688,8 @@ private:
|
|||
return false;
|
||||
}
|
||||
|
||||
double now = os_GetSeconds();
|
||||
if (!barcode.empty() && now - lastBarcodeTime >= 0.5)
|
||||
u64 now = getTimeMs();
|
||||
if (!barcode.empty() && now - lastBarcodeTime >= 500)
|
||||
{
|
||||
INFO_LOG(INPUT, "Barcode timeout");
|
||||
barcode.clear();
|
||||
|
@ -721,5 +721,5 @@ private:
|
|||
|
||||
int modifiers = 0;
|
||||
std::string barcode;
|
||||
double lastBarcodeTime = 0.0;
|
||||
u64 lastBarcodeTime = 0;
|
||||
};
|
||||
|
|
|
@ -738,11 +738,11 @@ void pickIosFile()
|
|||
|
||||
const char *getIosJitStatus()
|
||||
{
|
||||
static double lastCheckTime;
|
||||
if (!iosJitAuthorized && os_GetSeconds() - lastCheckTime > 10.0)
|
||||
static u64 lastCheckTime;
|
||||
if (!iosJitAuthorized && getTimeMs() - lastCheckTime > 10000)
|
||||
{
|
||||
[flycastViewController altKitStart];
|
||||
lastCheckTime = os_GetSeconds();
|
||||
lastCheckTime = getTimeMs();
|
||||
}
|
||||
return iosJitStatus.c_str();
|
||||
}
|
||||
|
|
|
@ -2502,11 +2502,6 @@ void retro_rend_present()
|
|||
is_dupe = false;
|
||||
}
|
||||
|
||||
static uint32_t get_time_ms()
|
||||
{
|
||||
return (uint32_t)(os_GetSeconds() * 1000.0);
|
||||
}
|
||||
|
||||
static void get_analog_stick( retro_input_state_t input_state_cb,
|
||||
int player_index,
|
||||
int stick,
|
||||
|
@ -2963,14 +2958,14 @@ static void UpdateInputState(u32 port)
|
|||
}
|
||||
if (rumble.set_rumble_state != NULL && vib_stop_time[port] > 0)
|
||||
{
|
||||
if (get_time_ms() >= vib_stop_time[port])
|
||||
if (getTimeMs() >= vib_stop_time[port])
|
||||
{
|
||||
vib_stop_time[port] = 0;
|
||||
rumble.set_rumble_state(port, RETRO_RUMBLE_STRONG, 0);
|
||||
}
|
||||
else if (vib_delta[port] > 0.0)
|
||||
{
|
||||
u32 rem_time = vib_stop_time[port] - get_time_ms();
|
||||
u32 rem_time = vib_stop_time[port] - getTimeMs();
|
||||
rumble.set_rumble_state(port, RETRO_RUMBLE_STRONG, 65535 * vib_strength[port] * rem_time * vib_delta[port]);
|
||||
}
|
||||
}
|
||||
|
@ -3378,7 +3373,7 @@ static void updateVibration(u32 port, float power, float inclination, u32 durati
|
|||
vib_strength[port] = power;
|
||||
|
||||
rumble.set_rumble_state(port, RETRO_RUMBLE_STRONG, (u16)(65535 * power));
|
||||
vib_stop_time[port] = get_time_ms() + durationMs;
|
||||
vib_stop_time[port] = getTimeMs() + durationMs;
|
||||
vib_delta[port] = inclination;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,23 +59,23 @@ public:
|
|||
memcpy(&vibValues[1], &vibValues[0], sizeof(HidVibrationValue));
|
||||
hidSendVibrationValues(getDeviceHandle(), vibValues, 2);
|
||||
if (power != 0.f)
|
||||
vib_stop_time = os_GetSeconds() + duration_ms / 1000.0;
|
||||
vib_stop_time = getTimeMs() + duration_ms;
|
||||
else
|
||||
vib_stop_time = 0.0;
|
||||
vib_stop_time = 0;
|
||||
}
|
||||
|
||||
void update_rumble() override
|
||||
{
|
||||
if (!rumbleEnabled || vib_stop_time == 0.0)
|
||||
return;
|
||||
int rem_time = (vib_stop_time - os_GetSeconds()) * 1000;
|
||||
int rem_time = vib_stop_time - getTimeMs();
|
||||
if (rem_time <= 0)
|
||||
{
|
||||
HidVibrationValue vibValues[2]{};
|
||||
vibValues[0].freq_low = vibValues[1].freq_low = 160.f;
|
||||
vibValues[0].freq_high = vibValues[1].freq_high = 320.f;
|
||||
hidSendVibrationValues(getDeviceHandle(), vibValues, 2);
|
||||
vib_stop_time = 0.0;
|
||||
vib_stop_time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,20 +38,3 @@ void os_RunInstance(int argc, const char *argv[])
|
|||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
static LARGE_INTEGER qpf;
|
||||
static double qpfd;
|
||||
//Helper functions
|
||||
double os_GetSeconds()
|
||||
{
|
||||
static bool initme = (QueryPerformanceFrequency(&qpf), qpfd=1/(double)qpf.QuadPart);
|
||||
LARGE_INTEGER time_now;
|
||||
|
||||
QueryPerformanceCounter(&time_now);
|
||||
static LARGE_INTEGER time_now_base = time_now;
|
||||
return (time_now.QuadPart - time_now_base.QuadPart)*qpfd;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue