mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 15:19:53 -06:00
attempt at adding mirror instances and shito
This commit is contained in:
@ -36,6 +36,9 @@
|
|||||||
#include "IPC.h"
|
#include "IPC.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "ROMManager.h"
|
||||||
|
#include "Netplay.h"
|
||||||
|
#include "NDS.h"
|
||||||
|
|
||||||
|
|
||||||
extern EmuThread* emuThread;
|
extern EmuThread* emuThread;
|
||||||
@ -511,6 +514,29 @@ void ProcessCommands()
|
|||||||
case Cmd_Pause:
|
case Cmd_Pause:
|
||||||
emuThread->IPCPause(cmddata[0] != 0);
|
emuThread->IPCPause(cmddata[0] != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Cmd_LoadROM:
|
||||||
|
{
|
||||||
|
u16 len = *(u16*)&cmddata[0];
|
||||||
|
cmddata[2+len] = '\0';
|
||||||
|
|
||||||
|
char* cstr = (char*)&cmddata[2];
|
||||||
|
std::string str = cstr;
|
||||||
|
ROMManager::LoadROM(QString::fromStdString(str).split('|'), true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Cmd_SetupNetplayMirror:
|
||||||
|
{
|
||||||
|
Netplay::Player* player = (Netplay::Player*)&cmddata[0];
|
||||||
|
Netplay::StartMirror(player);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Cmd_Start:
|
||||||
|
NDS::Start();
|
||||||
|
emuThread->emuRun();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,6 +593,15 @@ bool SendCommandU8(u16 recipients, u16 command, u8 arg)
|
|||||||
return SendCommand(recipients, command, 1, &data);
|
return SendCommand(recipients, command, 1, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SendCommandStr(u16 recipients, u16 command, std::string str)
|
||||||
|
{
|
||||||
|
u8 data[kMaxCommandSize] = {0};
|
||||||
|
|
||||||
|
strncpy((char*)&data[2], str.c_str(), kMaxCommandSize-3);
|
||||||
|
*(u16*)&data[0] = strlen((const char*)&data[2]) + 1;
|
||||||
|
return SendCommand(recipients, command, 2+(*(u16*)&data[0]), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int SendMPPacketGeneric(u32 type, u8* packet, int len, u64 timestamp)
|
int SendMPPacketGeneric(u32 type, u8* packet, int len, u64 timestamp)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#ifndef IPC_H
|
#ifndef IPC_H
|
||||||
#define IPC_H
|
#define IPC_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
namespace IPC
|
namespace IPC
|
||||||
@ -28,7 +30,9 @@ enum
|
|||||||
{
|
{
|
||||||
Cmd_Pause = 1,
|
Cmd_Pause = 1,
|
||||||
|
|
||||||
|
Cmd_LoadROM,
|
||||||
Cmd_SetupNetplayMirror,
|
Cmd_SetupNetplayMirror,
|
||||||
|
Cmd_Start,
|
||||||
|
|
||||||
Cmd_MAX
|
Cmd_MAX
|
||||||
};
|
};
|
||||||
@ -51,6 +55,7 @@ u16 GetInstanceBitmask();
|
|||||||
void ProcessCommands();
|
void ProcessCommands();
|
||||||
bool SendCommand(u16 recipients, u16 command, u16 len, void* data);
|
bool SendCommand(u16 recipients, u16 command, u16 len, void* data);
|
||||||
bool SendCommandU8(u16 recipients, u16 command, u8 arg);
|
bool SendCommandU8(u16 recipients, u16 command, u8 arg);
|
||||||
|
bool SendCommandStr(u16 recipients, u16 command, std::string str);
|
||||||
|
|
||||||
int SendMPPacket(u8* data, int len, u64 timestamp);
|
int SendMPPacket(u8* data, int len, u64 timestamp);
|
||||||
int RecvMPPacket(u8* data, u64* timestamp);
|
int RecvMPPacket(u8* data, u64* timestamp);
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "IPC.h"
|
#include "IPC.h"
|
||||||
#include "Netplay.h"
|
#include "Netplay.h"
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
|
#include "ROMManager.h"
|
||||||
|
|
||||||
#include "ui_NetplayStartHostDialog.h"
|
#include "ui_NetplayStartHostDialog.h"
|
||||||
#include "ui_NetplayStartClientDialog.h"
|
#include "ui_NetplayStartClientDialog.h"
|
||||||
@ -272,7 +273,7 @@ void StartHost(const char* playername, int port)
|
|||||||
|
|
||||||
void StartClient(const char* playername, const char* host, int port)
|
void StartClient(const char* playername, const char* host, int port)
|
||||||
{
|
{
|
||||||
Host = enet_host_create(nullptr, 16, 1, 0, 0);
|
Host = enet_host_create(nullptr, 1, 1, 0, 0);
|
||||||
if (!Host)
|
if (!Host)
|
||||||
{
|
{
|
||||||
printf("client shat itself :(\n");
|
printf("client shat itself :(\n");
|
||||||
@ -322,6 +323,54 @@ void StartClient(const char* playername, const char* host, int port)
|
|||||||
IsMirror = false;
|
IsMirror = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StartMirror(const Player* player)
|
||||||
|
{
|
||||||
|
MirrorHost = enet_host_create(nullptr, 1, 1, 0, 0);
|
||||||
|
if (!MirrorHost)
|
||||||
|
{
|
||||||
|
printf("mirror shat itself :(\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("mirror created, connecting\n");
|
||||||
|
|
||||||
|
ENetAddress addr;
|
||||||
|
addr.host = player->Address;
|
||||||
|
addr.port = 8064+1 + player->ID; // FIXME!!!!!!!!!!
|
||||||
|
ENetPeer* peer = enet_host_connect(MirrorHost, &addr, 1, 0);
|
||||||
|
if (!peer)
|
||||||
|
{
|
||||||
|
printf("connect shat itself :(\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ENetEvent event;
|
||||||
|
bool conn = false;
|
||||||
|
if (enet_host_service(MirrorHost, &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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&MyPlayer, player, sizeof(Player));
|
||||||
|
|
||||||
|
HostAddress = addr.host;
|
||||||
|
|
||||||
|
Active = true;
|
||||||
|
IsHost = false;
|
||||||
|
IsMirror = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
u32 PlayerAddress(int id)
|
u32 PlayerAddress(int id)
|
||||||
{
|
{
|
||||||
@ -333,7 +382,7 @@ u32 PlayerAddress(int id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SpawnMirrorInstance(Player* player)
|
bool SpawnMirrorInstance(Player player)
|
||||||
{
|
{
|
||||||
u16 curmask = IPC::GetInstanceBitmask();
|
u16 curmask = IPC::GetInstanceBitmask();
|
||||||
|
|
||||||
@ -375,9 +424,13 @@ bool SpawnMirrorInstance(Player* player)
|
|||||||
if (newid == -1) return false;
|
if (newid == -1) return false;
|
||||||
|
|
||||||
// setup that instance
|
// setup that instance
|
||||||
printf("netplay: spawned mirror instance for player %d with ID %d, configuring\n", player->ID, newid);
|
printf("netplay: spawned mirror instance for player %d with ID %d, configuring\n", player.ID, newid);
|
||||||
|
|
||||||
IPC::SendCommand(1<<newid, IPC::Cmd_SetupNetplayMirror, sizeof(Player), player);
|
std::string rompath = ROMManager::FullROMPath.join('|').toStdString();
|
||||||
|
IPC::SendCommandStr(1<<newid, IPC::Cmd_LoadROM, rompath);
|
||||||
|
|
||||||
|
if (player.Address == 0x0100007F) player.Address = HostAddress;
|
||||||
|
IPC::SendCommand(1<<newid, IPC::Cmd_SetupNetplayMirror, sizeof(Player), &player);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -390,11 +443,20 @@ void StartGame()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// spawn mirror instances as needed
|
||||||
|
for (int i = 1; i < NumPlayers; i++)
|
||||||
|
{
|
||||||
|
SpawnMirrorInstance(Players[i]);
|
||||||
|
}
|
||||||
|
|
||||||
// tell remote peers to start game
|
// tell remote peers to start game
|
||||||
u8 cmd[1] = {0x01};
|
u8 cmd[1] = {0x04};
|
||||||
ENetPacket* pkt = enet_packet_create(cmd, sizeof(cmd), ENET_PACKET_FLAG_RELIABLE);
|
ENetPacket* pkt = enet_packet_create(cmd, sizeof(cmd), ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_host_broadcast(Host, 0, pkt);
|
enet_host_broadcast(Host, 0, pkt);
|
||||||
|
|
||||||
|
// tell other mirror instances to start the game
|
||||||
|
IPC::SendCommand(0xFFFF, IPC::Cmd_Start, 0, nullptr);
|
||||||
|
|
||||||
// start game locally
|
// start game locally
|
||||||
NDS::Start();
|
NDS::Start();
|
||||||
emuThread->emuRun();
|
emuThread->emuRun();
|
||||||
@ -542,6 +604,11 @@ void ProcessClient()
|
|||||||
netplayDlg->updatePlayerList(Players, NumPlayers);
|
netplayDlg->updatePlayerList(Players, NumPlayers);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x04: // start game
|
||||||
|
NDS::Start();
|
||||||
|
emuThread->emuRun();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -41,6 +41,8 @@ using namespace Platform;
|
|||||||
namespace ROMManager
|
namespace ROMManager
|
||||||
{
|
{
|
||||||
|
|
||||||
|
QStringList FullROMPath;
|
||||||
|
|
||||||
int CartType = -1;
|
int CartType = -1;
|
||||||
std::string BaseROMDir = "";
|
std::string BaseROMDir = "";
|
||||||
std::string BaseROMName = "";
|
std::string BaseROMName = "";
|
||||||
@ -729,6 +731,7 @@ bool LoadROM(QStringList filepath, bool reset)
|
|||||||
if (NDSSave) delete NDSSave;
|
if (NDSSave) delete NDSSave;
|
||||||
NDSSave = nullptr;
|
NDSSave = nullptr;
|
||||||
|
|
||||||
|
FullROMPath = filepath;
|
||||||
BaseROMDir = basepath;
|
BaseROMDir = basepath;
|
||||||
BaseROMName = romname;
|
BaseROMName = romname;
|
||||||
BaseAssetName = romname.substr(0, romname.rfind('.'));
|
BaseAssetName = romname.substr(0, romname.rfind('.'));
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
namespace ROMManager
|
namespace ROMManager
|
||||||
{
|
{
|
||||||
|
|
||||||
|
extern QStringList FullROMPath;
|
||||||
|
|
||||||
extern SaveManager* NDSSave;
|
extern SaveManager* NDSSave;
|
||||||
extern SaveManager* GBASave;
|
extern SaveManager* GBASave;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user