get enet going, I guess

still very experimental
This commit is contained in:
Arisotura
2023-03-23 14:29:16 +01:00
parent db887cc509
commit de8a768b79
4 changed files with 127 additions and 0 deletions

View File

@ -28,8 +28,19 @@
namespace Netplay
{
bool Active;
bool IsHost;
ENetHost* Host;
ENetPeer* Peer;
bool Init()
{
Active = false;
IsHost = false;
Host = nullptr;
if (enet_initialize() != 0)
{
printf("enet shat itself :(\n");
@ -45,4 +56,89 @@ void DeInit()
enet_deinitialize();
}
void StartHost()
{
ENetAddress addr;
addr.host = ENET_HOST_ANY;
addr.port = 8064;
// TODO determine proper number of clients/channels
Host = enet_host_create(&addr, 16, 16, 0, 0);
if (!Host)
{
printf("host shat itself :(\n");
return;
}
Active = true;
IsHost = true;
}
void StartClient()
{
// TODO determine proper number of clients/channels
Host = enet_host_create(nullptr, 16, 16, 0, 0);
if (!Host)
{
printf("client shat itself :(\n");
return;
}
printf("client created, connecting\n");
ENetAddress addr;
enet_address_set_host(&addr, "127.0.0.1"); // TODO!!!!
addr.port = 8064;
Peer = enet_host_connect(Host, &addr, 2, 0);
if (!Peer)
{
printf("connect shat itself :(\n");
return;
}
ENetEvent event;
bool conn = false;
if (enet_host_service(Host, &event, 5000) > 0)
{
if (event.type == ENET_EVENT_TYPE_CONNECT)
{
printf("connected!\n");
conn = true;
}
}
if (!conn)
{
printf("connection failed\n");
enet_peer_reset(Peer);
}
Active = true;
IsHost = false;
}
void ProcessFrame()
{
ENetEvent event;
while (enet_host_service(Host, &event, 0) > 0)
{
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
printf("client connected %08X %d\n", event.peer->address.host, event.peer->address.port);
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf("client disconnected %08X %d\n", event.peer->address.host, event.peer->address.port);
break;
case ENET_EVENT_TYPE_RECEIVE:
printf("received shit\n");
break;
}
}
}
}

View File

@ -24,9 +24,16 @@
namespace Netplay
{
extern bool Active;
bool Init();
void DeInit();
void StartHost();
void StartClient();
void ProcessFrame();
}
#endif // NETPLAY_H

View File

@ -363,6 +363,8 @@ void EmuThread::run()
while (EmuRunning != emuStatus_Exit)
{
if (Netplay::Active) Netplay::ProcessFrame();
IPC::ProcessCommands();
Input::Process();
@ -1566,6 +1568,14 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
actMPNewInstance = submenu->addAction("Launch new instance");
connect(actMPNewInstance, &QAction::triggered, this, &MainWindow::onMPNewInstance);
submenu->addSeparator();
actMPStartHost = submenu->addAction("NETPLAY HOST");
connect(actMPStartHost, &QAction::triggered, this, &MainWindow::onMPStartHost);
actMPStartClient = submenu->addAction("NETPLAY CLIENT");
connect(actMPStartClient, &QAction::triggered, this, &MainWindow::onMPStartClient);
}
}
{
@ -2824,6 +2834,16 @@ void MainWindow::onMPNewInstance()
newinst.startDetached();
}
void MainWindow::onMPStartHost()
{
Netplay::StartHost();
}
void MainWindow::onMPStartClient()
{
Netplay::StartClient();
}
void MainWindow::onOpenEmuSettings()
{
emuThread->emuPause();

View File

@ -311,6 +311,8 @@ private slots:
void onRAMInfo();
void onOpenTitleManager();
void onMPNewInstance();
void onMPStartHost();
void onMPStartClient();
void onOpenEmuSettings();
void onEmuSettingsDialogFinished(int res);
@ -408,6 +410,8 @@ public:
QAction* actRAMInfo;
QAction* actTitleManager;
QAction* actMPNewInstance;
QAction* actMPStartHost;
QAction* actMPStartClient;
QAction* actEmuSettings;
#ifdef __APPLE__