commit unfinished shit. see you later or smth
This commit is contained in:
parent
b496bb4856
commit
d6d76c824c
|
@ -1719,7 +1719,9 @@ void MainWindow::onNPStartClient()
|
||||||
void MainWindow::onNPTest()
|
void MainWindow::onNPTest()
|
||||||
{
|
{
|
||||||
// HAX
|
// HAX
|
||||||
//Netplay::StartGame();
|
// TODO: this should be integrated into the netplay dialog, and this menu item removed
|
||||||
|
if (MPInterface::GetType() != MPInterface_Netplay) return;
|
||||||
|
((Netplay&)MPInterface::Get()).StartGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateMPInterface(MPInterfaceType type)
|
void MainWindow::updateMPInterface(MPInterfaceType type)
|
||||||
|
|
|
@ -118,7 +118,7 @@ void NetInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool createEmuInstance()
|
int createEmuInstance()
|
||||||
{
|
{
|
||||||
int id = -1;
|
int id = -1;
|
||||||
for (int i = 0; i < kMaxEmuInstances; i++)
|
for (int i = 0; i < kMaxEmuInstances; i++)
|
||||||
|
@ -131,12 +131,12 @@ bool createEmuInstance()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
return false;
|
return -1;
|
||||||
|
|
||||||
auto inst = new EmuInstance(id);
|
auto inst = new EmuInstance(id);
|
||||||
emuInstances[id] = inst;
|
emuInstances[id] = inst;
|
||||||
|
|
||||||
return true;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteEmuInstance(int id)
|
void deleteEmuInstance(int id)
|
||||||
|
|
|
@ -45,7 +45,7 @@ extern QString emuDirectory;
|
||||||
|
|
||||||
extern QElapsedTimer sysTimer;
|
extern QElapsedTimer sysTimer;
|
||||||
|
|
||||||
bool createEmuInstance();
|
int createEmuInstance();
|
||||||
void deleteEmuInstance(int id);
|
void deleteEmuInstance(int id);
|
||||||
void deleteAllEmuInstances(int first = 0);
|
void deleteAllEmuInstances(int first = 0);
|
||||||
int numEmuInstances();
|
int numEmuInstances();
|
||||||
|
|
|
@ -54,8 +54,7 @@ enum
|
||||||
Cmd_ClientInit = 1, // 01 -- host->client -- init new client and assign ID
|
Cmd_ClientInit = 1, // 01 -- host->client -- init new client and assign ID
|
||||||
Cmd_PlayerInfo, // 02 -- client->host -- send client player info to host
|
Cmd_PlayerInfo, // 02 -- client->host -- send client player info to host
|
||||||
Cmd_PlayerList, // 03 -- host->client -- broadcast updated player list
|
Cmd_PlayerList, // 03 -- host->client -- broadcast updated player list
|
||||||
//Cmd_PlayerConnect, // 04 -- both -- signal connected state (ready to receive MP frames)
|
Cmd_StartGame, // 04 -- host->client -- start the game on all players
|
||||||
//Cmd_PlayerDisconnect, // 05 -- both -- signal disconnected state (not receiving MP frames)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +72,9 @@ Netplay::Netplay() noexcept : LocalMP(), Inited(false)
|
||||||
NumPlayers = 0;
|
NumPlayers = 0;
|
||||||
MaxPlayers = 0;
|
MaxPlayers = 0;
|
||||||
|
|
||||||
|
memset(PlayerToInstance, 0, sizeof(PlayerToInstance));
|
||||||
|
memset(InstanceToPlayer, 0, sizeof(InstanceToPlayer));
|
||||||
|
|
||||||
// TODO make this somewhat nicer
|
// TODO make this somewhat nicer
|
||||||
if (enet_initialize() != 0)
|
if (enet_initialize() != 0)
|
||||||
{
|
{
|
||||||
|
@ -682,34 +684,36 @@ void Netplay::StartGame()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// spawn mirror instances as needed
|
|
||||||
for (int i = 1; i < NumPlayers; i++)
|
|
||||||
{
|
|
||||||
//SpawnMirrorInstance(Players[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//SyncMirrorClients();
|
|
||||||
|
|
||||||
// tell remote peers to start game
|
// tell remote peers to start game
|
||||||
u8 cmd[1] = {0x04};
|
u8 cmd[1] = {Cmd_StartGame};
|
||||||
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, Chan_Cmd, pkt);
|
||||||
|
|
||||||
// tell other mirror instances to start the game
|
|
||||||
//IPC::SendCommand(0xFFFF, IPC::Cmd_Start, 0, nullptr);
|
|
||||||
|
|
||||||
// TO START MIRROR CLIENT SHITO
|
|
||||||
//
|
|
||||||
// 1. NDS::Reset()
|
|
||||||
// 2. load ROM
|
|
||||||
// 3. load state
|
|
||||||
|
|
||||||
// start game locally
|
// start game locally
|
||||||
//StartLocal();
|
StartLocal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Netplay::StartLocal()
|
void Netplay::StartLocal()
|
||||||
{
|
{
|
||||||
|
// assign local instances to players
|
||||||
|
|
||||||
|
PlayerToInstance[MyPlayer.ID] = 0;
|
||||||
|
InstanceToPlayer[0] = MyPlayer.ID;
|
||||||
|
|
||||||
|
for (int p = 0, i = 1; p < 16; p++)
|
||||||
|
{
|
||||||
|
if (p == MyPlayer.ID) continue;
|
||||||
|
|
||||||
|
Player* player = &Players[p];
|
||||||
|
if (player->Status == Player_None) continue;
|
||||||
|
|
||||||
|
PlayerToInstance[p] = i;
|
||||||
|
InstanceToPlayer[i] = p;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prefill input queue
|
||||||
|
// TODO: make input lag not hardcoded
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
InputFrame frame;
|
InputFrame frame;
|
||||||
|
@ -806,7 +810,7 @@ void Netplay::ProcessHost()
|
||||||
u8* data = (u8*)event.packet->data;
|
u8* data = (u8*)event.packet->data;
|
||||||
switch (data[0])
|
switch (data[0])
|
||||||
{
|
{
|
||||||
case 0x02: // client sending player info
|
case Cmd_PlayerInfo: // client sending player info
|
||||||
{
|
{
|
||||||
if (event.packet->dataLength != (1+sizeof(Player))) break;
|
if (event.packet->dataLength != (1+sizeof(Player))) break;
|
||||||
|
|
||||||
|
@ -828,11 +832,11 @@ void Netplay::ProcessHost()
|
||||||
|
|
||||||
// broadcast updated player list
|
// broadcast updated player list
|
||||||
u8 cmd[2+sizeof(Players)];
|
u8 cmd[2+sizeof(Players)];
|
||||||
cmd[0] = 0x03;
|
cmd[0] = Cmd_PlayerList;
|
||||||
cmd[1] = (u8)NumPlayers;
|
cmd[1] = (u8)NumPlayers;
|
||||||
memcpy(&cmd[2], Players, sizeof(Players));
|
memcpy(&cmd[2], Players, sizeof(Players));
|
||||||
ENetPacket* pkt = enet_packet_create(cmd, 2+sizeof(Players), ENET_PACKET_FLAG_RELIABLE);
|
ENetPacket* pkt = enet_packet_create(cmd, 2+sizeof(Players), ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_host_broadcast(Host, 0, pkt);
|
enet_host_broadcast(Host, Chan_Cmd, pkt);
|
||||||
|
|
||||||
//netplayDlg->updatePlayerList(Players, NumPlayers);
|
//netplayDlg->updatePlayerList(Players, NumPlayers);
|
||||||
}
|
}
|
||||||
|
@ -896,34 +900,6 @@ void Netplay::ProcessClient()
|
||||||
u8* data = (u8*)event.packet->data;
|
u8* data = (u8*)event.packet->data;
|
||||||
switch (data[0])
|
switch (data[0])
|
||||||
{
|
{
|
||||||
case Cmd_ClientInit: // host sending player ID
|
|
||||||
{
|
|
||||||
if (event.packet->dataLength != 2) break;
|
|
||||||
|
|
||||||
NumMirrorClients = 0;
|
|
||||||
|
|
||||||
// create mirror host
|
|
||||||
/*ENetAddress mirroraddr;
|
|
||||||
mirroraddr.host = ENET_HOST_ANY;
|
|
||||||
mirroraddr.port = 8064+1 + data[1]; // FIXME!!!!
|
|
||||||
printf("client mirror host connecting to %08X:%d\n", mirroraddr.host, mirroraddr.port);
|
|
||||||
MirrorHost = enet_host_create(&mirroraddr, 16, 2, 0, 0);
|
|
||||||
if (!MirrorHost)
|
|
||||||
{
|
|
||||||
printf("mirror host shat itself :(\n");
|
|
||||||
break;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// send player information
|
|
||||||
MyPlayer.ID = data[1];
|
|
||||||
u8 cmd[1+sizeof(Player)];
|
|
||||||
cmd[0] = 0x02;
|
|
||||||
memcpy(&cmd[1], &MyPlayer, sizeof(Player));
|
|
||||||
ENetPacket* pkt = enet_packet_create(cmd, 1+sizeof(Player), ENET_PACKET_FLAG_RELIABLE);
|
|
||||||
enet_peer_send(event.peer, 0, pkt);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Cmd_PlayerList: // host sending player list
|
case Cmd_PlayerList: // host sending player list
|
||||||
{
|
{
|
||||||
if (event.packet->dataLength != (2+sizeof(Players))) break;
|
if (event.packet->dataLength != (2+sizeof(Players))) break;
|
||||||
|
@ -963,22 +939,9 @@ printf("client: receive player list, %08X %d\n", event.peer->address.host, event
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x04: // start game
|
case Cmd_StartGame: // start game
|
||||||
{
|
{
|
||||||
// spawn mirror instances as needed
|
StartLocal();
|
||||||
/*for (int i = 0; i < NumPlayers; i++)
|
|
||||||
{
|
|
||||||
if (i != MyPlayer.ID)
|
|
||||||
SpawnMirrorInstance(Players[i]);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//SyncMirrorClients();
|
|
||||||
printf("bourf\n");
|
|
||||||
// tell other mirror instances to start the game
|
|
||||||
//IPC::SendCommand(0xFFFF, IPC::Cmd_Start, 0, nullptr);
|
|
||||||
printf("birf\n");
|
|
||||||
// start game locally
|
|
||||||
//StartLocal();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,8 @@ public:
|
||||||
bool StartClient(const char* player, const char* host, int port);
|
bool StartClient(const char* player, const char* host, int port);
|
||||||
void EndSession();
|
void EndSession();
|
||||||
|
|
||||||
|
void StartGame();
|
||||||
|
|
||||||
std::vector<Player> GetPlayerList();
|
std::vector<Player> GetPlayerList();
|
||||||
int GetNumPlayers() { return NumPlayers; }
|
int GetNumPlayers() { return NumPlayers; }
|
||||||
int GetMaxPlayers() { return MaxPlayers; }
|
int GetMaxPlayers() { return MaxPlayers; }
|
||||||
|
@ -89,6 +91,10 @@ private:
|
||||||
|
|
||||||
int NumMirrorClients;
|
int NumMirrorClients;
|
||||||
|
|
||||||
|
// maps to convert between player IDs and local instance IDs
|
||||||
|
int PlayerToInstance[16];
|
||||||
|
int InstanceToPlayer[16];
|
||||||
|
|
||||||
struct InputFrame
|
struct InputFrame
|
||||||
{
|
{
|
||||||
u32 FrameNum;
|
u32 FrameNum;
|
||||||
|
@ -99,7 +105,6 @@ private:
|
||||||
|
|
||||||
std::queue<InputFrame> InputQueue;
|
std::queue<InputFrame> InputQueue;
|
||||||
|
|
||||||
void StartGame();
|
|
||||||
void StartLocal();
|
void StartLocal();
|
||||||
void ProcessHost();
|
void ProcessHost();
|
||||||
void ProcessClient();
|
void ProcessClient();
|
||||||
|
|
Loading…
Reference in New Issue