mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2024-11-14 13:27:41 -07:00
add GetMSCount/GetUSCount to Platform. remove SDL dependency from LAN.
This commit is contained in:
parent
fc5628bbc2
commit
e0f40cd2d1
@ -270,6 +270,9 @@ bool Mutex_TryLock(Mutex* mutex);
|
|||||||
|
|
||||||
void Sleep(u64 usecs);
|
void Sleep(u64 usecs);
|
||||||
|
|
||||||
|
u64 GetMSCount();
|
||||||
|
u64 GetUSCount();
|
||||||
|
|
||||||
|
|
||||||
// functions called when the NDS or GBA save files need to be written back to storage
|
// functions called when the NDS or GBA save files need to be written back to storage
|
||||||
// savedata and savelen are always the entire save memory buffer and its full length
|
// savedata and savelen are always the entire save memory buffer and its full length
|
||||||
|
@ -395,6 +395,16 @@ void Sleep(u64 usecs)
|
|||||||
QThread::usleep(usecs);
|
QThread::usleep(usecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 GetMSCount()
|
||||||
|
{
|
||||||
|
return sysTimer.elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 GetUSCount()
|
||||||
|
{
|
||||||
|
return sysTimer.nsecsElapsed() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WriteNDSSave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen, void* userdata)
|
void WriteNDSSave(const u8* savedata, u32 savelen, u32 writeoffset, u32 writelen, void* userdata)
|
||||||
{
|
{
|
||||||
|
@ -73,7 +73,6 @@ using namespace melonDS;
|
|||||||
QString* systemThemeName;
|
QString* systemThemeName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString emuDirectory;
|
QString emuDirectory;
|
||||||
|
|
||||||
const int kMaxEmuInstances = 16;
|
const int kMaxEmuInstances = 16;
|
||||||
@ -86,6 +85,9 @@ std::optional<LibPCap> pcap;
|
|||||||
Net net;
|
Net net;
|
||||||
|
|
||||||
|
|
||||||
|
QElapsedTimer sysTimer;
|
||||||
|
|
||||||
|
|
||||||
void NetInit()
|
void NetInit()
|
||||||
{
|
{
|
||||||
Config::Table cfg = Config::GetGlobalTable();
|
Config::Table cfg = Config::GetGlobalTable();
|
||||||
@ -237,6 +239,7 @@ bool MelonApplication::event(QEvent *event)
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
sysTimer.start();
|
||||||
srand(time(nullptr));
|
srand(time(nullptr));
|
||||||
|
|
||||||
for (int i = 0; i < kMaxEmuInstances; i++)
|
for (int i = 0; i < kMaxEmuInstances; i++)
|
||||||
|
@ -22,14 +22,8 @@
|
|||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QWidget>
|
#include <QEvent>
|
||||||
#include <QWindow>
|
#include <QElapsedTimer>
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QImage>
|
|
||||||
#include <QActionGroup>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QScreen>
|
|
||||||
#include <QCloseEvent>
|
|
||||||
|
|
||||||
#include "EmuInstance.h"
|
#include "EmuInstance.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
@ -48,6 +42,8 @@ public:
|
|||||||
extern QString* systemThemeName;
|
extern QString* systemThemeName;
|
||||||
extern QString emuDirectory;
|
extern QString emuDirectory;
|
||||||
|
|
||||||
|
extern QElapsedTimer sysTimer;
|
||||||
|
|
||||||
bool createEmuInstance();
|
bool createEmuInstance();
|
||||||
void deleteEmuInstance(int id);
|
void deleteEmuInstance(int id);
|
||||||
void deleteAllEmuInstances(int first = 0);
|
void deleteAllEmuInstances(int first = 0);
|
||||||
|
@ -45,9 +45,6 @@
|
|||||||
#define INVALID_SOCKET (socket_t)-1
|
#define INVALID_SOCKET (socket_t)-1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// REMOVEME REMOVEME REMOVEME
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
#include "LAN.h"
|
#include "LAN.h"
|
||||||
|
|
||||||
|
|
||||||
@ -227,7 +224,7 @@ bool LAN::StartDiscovery()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscoveryLastTick = SDL_GetTicks();
|
DiscoveryLastTick = (u32)Platform::GetMSCount();
|
||||||
DiscoveryList.clear();
|
DiscoveryList.clear();
|
||||||
|
|
||||||
Active = true;
|
Active = true;
|
||||||
@ -324,11 +321,11 @@ bool LAN::StartClient(const char* playername, const char* host)
|
|||||||
|
|
||||||
ENetEvent event;
|
ENetEvent event;
|
||||||
int conn = 0;
|
int conn = 0;
|
||||||
u32 starttick = SDL_GetTicks();
|
u32 starttick = (u32)Platform::GetMSCount();
|
||||||
const int conntimeout = 5000;
|
const int conntimeout = 5000;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
u32 curtick = SDL_GetTicks();
|
u32 curtick = (u32)Platform::GetMSCount();
|
||||||
if (curtick < starttick) break;
|
if (curtick < starttick) break;
|
||||||
int timeout = conntimeout - (int)(curtick - starttick);
|
int timeout = conntimeout - (int)(curtick - starttick);
|
||||||
if (timeout < 0) break;
|
if (timeout < 0) break;
|
||||||
@ -407,7 +404,7 @@ void LAN::ProcessDiscovery()
|
|||||||
if (DiscoverySocket == INVALID_SOCKET)
|
if (DiscoverySocket == INVALID_SOCKET)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u32 tick = SDL_GetTicks();
|
u32 tick = (u32)Platform::GetMSCount();
|
||||||
if ((tick - DiscoveryLastTick) < 1000)
|
if ((tick - DiscoveryLastTick) < 1000)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -801,7 +798,7 @@ void LAN::ProcessLAN(int type)
|
|||||||
if (!Host) return;
|
if (!Host) return;
|
||||||
//printf("Process(%d): %d %d\n", type, RXQueue.empty(), RXQueue.size());
|
//printf("Process(%d): %d %d\n", type, RXQueue.empty(), RXQueue.size());
|
||||||
|
|
||||||
u32 time_last = SDL_GetTicks();
|
u32 time_last = (u32)Platform::GetMSCount();
|
||||||
|
|
||||||
// see if we have queued packets already, get rid of the stale ones
|
// see if we have queued packets already, get rid of the stale ones
|
||||||
// any incoming packet should be consumed by the core quickly, so if
|
// any incoming packet should be consumed by the core quickly, so if
|
||||||
@ -837,7 +834,7 @@ void LAN::ProcessLAN(int type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int timeout = (type == 2) ? MPRecvTimeout : 0;
|
int timeout = (type == 2) ? MPRecvTimeout : 0;
|
||||||
time_last = SDL_GetTicks();
|
time_last = (u32)Platform::GetMSCount();
|
||||||
|
|
||||||
ENetEvent event;
|
ENetEvent event;
|
||||||
while (enet_host_service(Host, &event, timeout) > 0)
|
while (enet_host_service(Host, &event, timeout) > 0)
|
||||||
@ -861,7 +858,7 @@ void LAN::ProcessLAN(int type)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// mark this packet with the time it was received
|
// mark this packet with the time it was received
|
||||||
header->Magic = SDL_GetTicks();
|
header->Magic = (u32)Platform::GetMSCount();
|
||||||
|
|
||||||
event.packet->userData = event.peer;
|
event.packet->userData = event.peer;
|
||||||
RXQueue.push(event.packet);
|
RXQueue.push(event.packet);
|
||||||
@ -879,7 +876,7 @@ void LAN::ProcessLAN(int type)
|
|||||||
|
|
||||||
if (type == 2)
|
if (type == 2)
|
||||||
{
|
{
|
||||||
u32 time = SDL_GetTicks();
|
u32 time = (u32)Platform::GetMSCount();
|
||||||
if (time < time_last) return;
|
if (time < time_last) return;
|
||||||
timeout -= (int)(time - time_last);
|
timeout -= (int)(time - time_last);
|
||||||
if (timeout <= 0) return;
|
if (timeout <= 0) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user