Пример #1
0
// called from ---GUI--- thread
bool NetPlayServer::ChangeGame(const std::string &game)
{
	std::lock_guard<std::recursive_mutex> lkg(m_crit.game);

	m_selected_game = game;

	// send changed game to clients
	sf::Packet spac;
	spac << (MessageId)NP_MSG_CHANGE_GAME;
	spac << game;

	std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
	std::lock_guard<std::recursive_mutex> lks(m_crit.send);
	SendToClients(spac);

	return true;
}
Пример #2
0
void NetPlayServer::SetHostInputAuthority(const bool enable)
{
  std::lock_guard<std::recursive_mutex> lkg(m_crit.game);

  m_host_input_authority = enable;

  // tell clients about the new value
  sf::Packet spac;
  spac << static_cast<MessageId>(NP_MSG_HOST_INPUT_AUTHORITY);
  spac << m_host_input_authority;

  SendAsyncToClients(std::move(spac));

  // resend pad buffer to clients when disabled
  if (!m_host_input_authority)
    AdjustPadBufferSize(m_target_buffer_size);
}
Пример #3
0
// called from ---GUI--- thread and ---NETPLAY--- thread (client side)
bool NetPlay::StopGame()
{
	std::lock_guard<std::recursive_mutex> lkg(m_crit.game);

	if (false == m_is_running)
	{
		PanicAlertT("Game isn't running!");
		return false;
	}

	m_dialog->AppendChat(" -- STOPPING GAME -- ");

	m_is_running = false;
	NetPlay_Disable();

	// stop game
	m_dialog->StopGame();

	return true;
}
Пример #4
0
// called from ---NETPLAY--- thread
unsigned int NetPlayServer::OnDisconnect(sf::SocketTCP& socket)
{
	if (m_is_running)
	{
		PanicAlertT("Client disconnect while game is running!! NetPlay is disabled. You must manually stop the game.");
		std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
		m_is_running = false;

		sf::Packet spac;
		spac << (MessageId)NP_MSG_DISABLE_GAME;
		// this thread doesn't need players lock
		std::lock_guard<std::recursive_mutex> lks(m_crit.send);
		SendToClients(spac);
	}

	int pid = m_players[socket].pid;

	sf::Packet spac;
	spac << (MessageId)NP_MSG_PLAYER_LEAVE;
	spac << pid;

	m_selector.Remove(socket);
	
	std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
	m_players.erase(m_players.find(socket));

	// alert other players of disconnect
	std::lock_guard<std::recursive_mutex> lks(m_crit.send);
	SendToClients(spac);

	for (int i = 0; i < 4; i++)
		if (m_pad_map[i] == pid)
			m_pad_map[i] = -1;
	UpdatePadMapping();

	return 0;
}
Пример #5
0
// called from ---NETPLAY--- thread
void NetPlayServer::ThreadFunc()
{
	while (m_do_loop)
	{
		// update pings every so many seconds
		if ((m_ping_timer.GetTimeElapsed() > (10 * 1000)) || m_update_pings)
		{
			//PanicAlertT("Sending pings");

			m_ping_key = Common::Timer::GetTimeMs();

			sf::Packet spac;
			spac << (MessageId)NP_MSG_PING;
			spac << m_ping_key;

			std::lock_guard<std::recursive_mutex> lks(m_crit.send);
			m_ping_timer.Start();
			SendToClients(spac);

			m_update_pings = false;
		}

		// check which sockets need attention
		const unsigned int num = m_selector.Wait(0.01f);
		for (unsigned int i=0; i<num; ++i)
		{
			sf::SocketTCP ready_socket = m_selector.GetSocketReady(i);

			// listening socket
			if (ready_socket == m_socket)
			{
				sf::SocketTCP accept_socket;
				m_socket.Accept(accept_socket);

				unsigned int error;
				{
				std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
				error = OnConnect(accept_socket);
				}

				if (error)
				{
					sf::Packet spac;
					spac << (MessageId)error;
					// don't need to lock, this client isn't in the client map
					accept_socket.Send(spac);

					// TODO: not sure if client gets the message if i close right away
					accept_socket.Close();
				}
			}
			// client socket
			else
			{
				sf::Packet rpac;
				switch (ready_socket.Receive(rpac))
				{
				case sf::Socket::Done :
					// if a bad packet is received, disconnect the client
					if (0 == OnData(rpac, ready_socket))
						break;

				//case sf::Socket::Disconnected :
				default :
					{
					std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
					OnDisconnect(ready_socket);
					break;
					}
				}
			}
		}
	}

	// close listening socket and client sockets
	{
	std::map<sf::SocketTCP, Client>::reverse_iterator
		i = m_players.rbegin(),
		e = m_players.rend();
	for ( ; i!=e; ++i)
		i->second.socket.Close();
	}

	return;
}
Пример #6
0
// called from ---NETPLAY--- thread
unsigned int NetPlayClient::OnData(sf::Packet& packet)
{
  MessageId mid;
  packet >> mid;

  switch (mid)
  {
  case NP_MSG_PLAYER_JOIN:
  {
    Player player;
    packet >> player.pid;
    packet >> player.name;
    packet >> player.revision;

    {
      std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
      m_players[player.pid] = player;
    }

    m_dialog->Update();
  }
  break;

  case NP_MSG_PLAYER_LEAVE:
  {
    PlayerId pid;
    packet >> pid;

    {
      std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
      m_players.erase(m_players.find(pid));
    }

    m_dialog->Update();
  }
  break;

  case NP_MSG_CHAT_MESSAGE:
  {
    PlayerId pid;
    packet >> pid;
    std::string msg;
    packet >> msg;

    // don't need lock to read in this thread
    const Player& player = m_players[pid];

    // add to gui
    std::ostringstream ss;
    ss << player.name << '[' << (char)(pid + '0') << "]: " << msg;

    m_dialog->AppendChat(ss.str());
  }
  break;

  case NP_MSG_PAD_MAPPING:
  {
    for (PadMapping& mapping : m_pad_map)
    {
      packet >> mapping;
    }

    UpdateDevices();

    m_dialog->Update();
  }
  break;

  case NP_MSG_WIIMOTE_MAPPING:
  {
    for (PadMapping& mapping : m_wiimote_map)
    {
      packet >> mapping;
    }

    m_dialog->Update();
  }
  break;

  case NP_MSG_PAD_DATA:
  {
    PadMapping map = 0;
    GCPadStatus pad;
    packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
        pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;

    // Trusting server for good map value (>=0 && <4)
    // add to pad buffer
    m_pad_buffer.at(map).Push(pad);
    m_gc_pad_event.Set();
  }
  break;

  case NP_MSG_WIIMOTE_DATA:
  {
    PadMapping map = 0;
    NetWiimote nw;
    u8 size;
    packet >> map >> size;

    nw.resize(size);

    for (unsigned int i = 0; i < size; ++i)
      packet >> nw[i];

    // Trusting server for good map value (>=0 && <4)
    // add to Wiimote buffer
    m_wiimote_buffer.at(map).Push(nw);
    m_wii_pad_event.Set();
  }
  break;

  case NP_MSG_PAD_BUFFER:
  {
    u32 size = 0;
    packet >> size;

    m_target_buffer_size = size;
    m_dialog->OnPadBufferChanged(size);
  }
  break;

  case NP_MSG_CHANGE_GAME:
  {
    {
      std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
      packet >> m_selected_game;
    }

    // update gui
    m_dialog->OnMsgChangeGame(m_selected_game);

    sf::Packet spac;
    spac << static_cast<MessageId>(NP_MSG_GAME_STATUS);

    PlayerGameStatus status = m_dialog->FindGame(m_selected_game).empty() ?
                                  PlayerGameStatus::NotFound :
                                  PlayerGameStatus::Ok;

    spac << static_cast<u32>(status);
    Send(spac);
  }
  break;

  case NP_MSG_GAME_STATUS:
  {
    PlayerId pid;
    packet >> pid;

    {
      std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
      Player& player = m_players[pid];
      u32 status;
      packet >> status;
      player.game_status = static_cast<PlayerGameStatus>(status);
    }

    m_dialog->Update();
  }
  break;

  case NP_MSG_START_GAME:
  {
    {
      std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
      packet >> m_current_game;
      packet >> g_NetPlaySettings.m_CPUthread;
      packet >> g_NetPlaySettings.m_CPUcore;
      packet >> g_NetPlaySettings.m_EnableCheats;
      packet >> g_NetPlaySettings.m_SelectedLanguage;
      packet >> g_NetPlaySettings.m_OverrideGCLanguage;
      packet >> g_NetPlaySettings.m_ProgressiveScan;
      packet >> g_NetPlaySettings.m_PAL60;
      packet >> g_NetPlaySettings.m_DSPEnableJIT;
      packet >> g_NetPlaySettings.m_DSPHLE;
      packet >> g_NetPlaySettings.m_WriteToMemcard;
      packet >> g_NetPlaySettings.m_OCEnable;
      packet >> g_NetPlaySettings.m_OCFactor;

      int tmp;
      packet >> tmp;
      g_NetPlaySettings.m_EXIDevice[0] = (TEXIDevices)tmp;
      packet >> tmp;
      g_NetPlaySettings.m_EXIDevice[1] = (TEXIDevices)tmp;

      u32 time_low, time_high;
      packet >> time_low;
      packet >> time_high;
      g_netplay_initial_rtc = time_low | ((u64)time_high << 32);
    }

    m_dialog->OnMsgStartGame();
  }
  break;

  case NP_MSG_STOP_GAME:
  case NP_MSG_DISABLE_GAME:
  {
    StopGame();
    m_dialog->OnMsgStopGame();
  }
  break;

  case NP_MSG_PING:
  {
    u32 ping_key = 0;
    packet >> ping_key;

    sf::Packet spac;
    spac << (MessageId)NP_MSG_PONG;
    spac << ping_key;

    Send(spac);
  }
  break;

  case NP_MSG_PLAYER_PING_DATA:
  {
    PlayerId pid;
    packet >> pid;

    {
      std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
      Player& player = m_players[pid];
      packet >> player.ping;
    }

    DisplayPlayersPing();
    m_dialog->Update();
  }
  break;

  case NP_MSG_DESYNC_DETECTED:
  {
    int pid_to_blame;
    u32 frame;
    packet >> pid_to_blame;
    packet >> frame;

    std::string player = "??";
    std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
    {
      auto it = m_players.find(pid_to_blame);
      if (it != m_players.end())
        player = it->second.name;
    }
    m_dialog->OnDesync(frame, player);
  }
  break;

  case NP_MSG_SYNC_GC_SRAM:
  {
    u8 sram[sizeof(g_SRAM.p_SRAM)];
    for (size_t i = 0; i < sizeof(g_SRAM.p_SRAM); ++i)
    {
      packet >> sram[i];
    }

    {
      std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
      memcpy(g_SRAM.p_SRAM, sram, sizeof(g_SRAM.p_SRAM));
      g_SRAM_netplay_initialized = true;
    }
  }
  break;

  case NP_MSG_COMPUTE_MD5:
  {
    std::string file_identifier;
    packet >> file_identifier;

    ComputeMD5(file_identifier);
  }
  break;

  case NP_MSG_MD5_PROGRESS:
  {
    PlayerId pid;
    int progress;
    packet >> pid;
    packet >> progress;

    m_dialog->SetMD5Progress(pid, progress);
  }
  break;

  case NP_MSG_MD5_RESULT:
  {
    PlayerId pid;
    std::string result;
    packet >> pid;
    packet >> result;

    m_dialog->SetMD5Result(pid, result);
  }
  break;

  case NP_MSG_MD5_ERROR:
  {
    PlayerId pid;
    std::string error;
    packet >> pid;
    packet >> error;

    m_dialog->SetMD5Result(pid, error);
  }
  break;

  case NP_MSG_MD5_ABORT:
  {
    m_should_compute_MD5 = false;
    m_dialog->AbortMD5();
  }
  break;

  default:
    PanicAlertT("Unknown message received with id : %d", mid);
    break;
  }

  return 0;
}
Пример #7
0
void ShaderManager::ClearSourceCodes() {
	std::unique_lock<std::shared_mutex> lkg(m_sourceMutex);

	m_codes.clear();
}
	~mi_tls() {
		// deallocate our slot
		std::lock_guard<std::mutex> lkg(indexAllocatorLock);

		indexAllocator.Deallocate(myIndex);
	}
Пример #9
0
void ShaderManager::AddSourceCode(std::string name, std::string sourceCode) {
	std::unique_lock<std::shared_mutex> lkg(m_sourceMutex);

	m_codes.insert({ name, sourceCode });
}
Пример #10
0
void ShaderManager::ClearSourceDirectories() {
	std::unique_lock<std::shared_mutex> lkg(m_sourceMutex);

	m_directories.clear();
}
Пример #11
0
void ShaderManager::RemoveSourceDirectory(std::experimental::filesystem::path directory) {
	std::unique_lock<std::shared_mutex> lkg(m_sourceMutex);

	m_directories.erase(directory);
}
Пример #12
0
// called from multiple threads
bool NetPlayServer::StartGame()
{
  m_timebase_by_frame.clear();
  m_desync_detected = false;
  std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
  m_current_game = Common::Timer::GetTimeMs();

  // no change, just update with clients
  if (!m_host_input_authority)
    AdjustPadBufferSize(m_target_buffer_size);

  m_first_pad_status_received.fill(false);

  const sf::Uint64 initial_rtc = GetInitialNetPlayRTC();

  const std::string region = SConfig::GetDirectoryForRegion(
      SConfig::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game)->GetRegion()));

  // tell clients to start game
  sf::Packet spac;
  spac << static_cast<MessageId>(NP_MSG_START_GAME);
  spac << m_current_game;
  spac << m_settings.m_CPUthread;
  spac << static_cast<std::underlying_type_t<PowerPC::CPUCore>>(m_settings.m_CPUcore);
  spac << m_settings.m_EnableCheats;
  spac << m_settings.m_SelectedLanguage;
  spac << m_settings.m_OverrideGCLanguage;
  spac << m_settings.m_ProgressiveScan;
  spac << m_settings.m_PAL60;
  spac << m_settings.m_DSPEnableJIT;
  spac << m_settings.m_DSPHLE;
  spac << m_settings.m_WriteToMemcard;
  spac << m_settings.m_CopyWiiSave;
  spac << m_settings.m_OCEnable;
  spac << m_settings.m_OCFactor;
  spac << m_settings.m_ReducePollingRate;
  spac << m_settings.m_EXIDevice[0];
  spac << m_settings.m_EXIDevice[1];
  spac << m_settings.m_EFBAccessEnable;
  spac << m_settings.m_BBoxEnable;
  spac << m_settings.m_ForceProgressive;
  spac << m_settings.m_EFBToTextureEnable;
  spac << m_settings.m_XFBToTextureEnable;
  spac << m_settings.m_DisableCopyToVRAM;
  spac << m_settings.m_ImmediateXFBEnable;
  spac << m_settings.m_EFBEmulateFormatChanges;
  spac << m_settings.m_SafeTextureCacheColorSamples;
  spac << m_settings.m_PerfQueriesEnable;
  spac << m_settings.m_FPRF;
  spac << m_settings.m_AccurateNaNs;
  spac << m_settings.m_SyncOnSkipIdle;
  spac << m_settings.m_SyncGPU;
  spac << m_settings.m_SyncGpuMaxDistance;
  spac << m_settings.m_SyncGpuMinDistance;
  spac << m_settings.m_SyncGpuOverclock;
  spac << m_settings.m_JITFollowBranch;
  spac << m_settings.m_FastDiscSpeed;
  spac << m_settings.m_MMU;
  spac << m_settings.m_Fastmem;
  spac << m_settings.m_SkipIPL;
  spac << m_settings.m_LoadIPLDump;
  spac << m_settings.m_VertexRounding;
  spac << m_settings.m_InternalResolution;
  spac << m_settings.m_EFBScaledCopy;
  spac << m_settings.m_FastDepthCalc;
  spac << m_settings.m_EnablePixelLighting;
  spac << m_settings.m_WidescreenHack;
  spac << m_settings.m_ForceFiltering;
  spac << m_settings.m_MaxAnisotropy;
  spac << m_settings.m_ForceTrueColor;
  spac << m_settings.m_DisableCopyFilter;
  spac << m_settings.m_DisableFog;
  spac << m_settings.m_ArbitraryMipmapDetection;
  spac << m_settings.m_ArbitraryMipmapDetectionThreshold;
  spac << m_settings.m_EnableGPUTextureDecoding;
  spac << m_settings.m_StrictSettingsSync;
  spac << initial_rtc;
  spac << m_settings.m_SyncSaveData;
  spac << region;

  SendAsyncToClients(std::move(spac));

  m_start_pending = false;
  m_is_running = true;

  return true;
}
Пример #13
0
// called from ---NETPLAY--- thread
void NetPlayServer::ThreadFunc()
{
  while (m_do_loop)
  {
    // update pings every so many seconds
    if ((m_ping_timer.GetTimeElapsed() > 1000) || m_update_pings)
    {
      m_ping_key = Common::Timer::GetTimeMs();

      sf::Packet spac;
      spac << (MessageId)NP_MSG_PING;
      spac << m_ping_key;

      m_ping_timer.Start();
      SendToClients(spac);
      m_update_pings = false;
    }

    ENetEvent netEvent;
    int net;
    if (m_traversal_client)
      m_traversal_client->HandleResends();
    net = enet_host_service(m_server, &netEvent, 1000);
    while (!m_async_queue.Empty())
    {
      {
        std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
        SendToClients(m_async_queue.Front());
      }
      m_async_queue.Pop();
    }
    if (net > 0)
    {
      switch (netEvent.type)
      {
      case ENET_EVENT_TYPE_CONNECT:
      {
        ENetPeer* accept_peer = netEvent.peer;
        unsigned int error;
        {
          std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
          error = OnConnect(accept_peer);
        }

        if (error)
        {
          sf::Packet spac;
          spac << (MessageId)error;
          // don't need to lock, this client isn't in the client map
          Send(accept_peer, spac);
          if (netEvent.peer->data)
          {
            delete (PlayerId*)netEvent.peer->data;
            netEvent.peer->data = nullptr;
          }
          enet_peer_disconnect_later(accept_peer, 0);
        }
      }
      break;
      case ENET_EVENT_TYPE_RECEIVE:
      {
        sf::Packet rpac;
        rpac.append(netEvent.packet->data, netEvent.packet->dataLength);

        auto it = m_players.find(*(PlayerId*)netEvent.peer->data);
        Client& client = it->second;
        if (OnData(rpac, client) != 0)
        {
          // if a bad packet is received, disconnect the client
          std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
          OnDisconnect(client);

          if (netEvent.peer->data)
          {
            delete (PlayerId*)netEvent.peer->data;
            netEvent.peer->data = nullptr;
          }
        }
        enet_packet_destroy(netEvent.packet);
      }
      break;
      case ENET_EVENT_TYPE_DISCONNECT:
      {
        std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
        if (!netEvent.peer->data)
          break;
        auto it = m_players.find(*(PlayerId*)netEvent.peer->data);
        if (it != m_players.end())
        {
          Client& client = it->second;
          OnDisconnect(client);

          if (netEvent.peer->data)
          {
            delete (PlayerId*)netEvent.peer->data;
            netEvent.peer->data = nullptr;
          }
        }
      }
      break;
      default:
        break;
      }
    }
  }

  // close listening socket and client sockets
  for (auto& player_entry : m_players)
  {
    delete (PlayerId*)player_entry.second.socket->data;
    player_entry.second.socket->data = nullptr;
    enet_peer_disconnect(player_entry.second.socket, 0);
  }
}
Пример #14
0
void NetPlay::SetMemcardWriteEnabled(bool enabled)
{
	std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
	g_NetPlaySettings.m_WriteToMemcard = enabled;
}
Пример #15
0
// called from ---NETPLAY--- thread
unsigned int NetPlayClient::OnData(sf::Packet& packet)
{
	MessageId mid;
	packet >> mid;

	switch (mid)
	{
	case NP_MSG_PLAYER_JOIN:
	{
		Player player;
		packet >> player.pid;
		packet >> player.name;
		packet >> player.revision;

		{
			std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
			m_players[player.pid] = player;
		}

		m_dialog->Update();
	}
	break;

	case NP_MSG_PLAYER_LEAVE:
	{
		PlayerId pid;
		packet >> pid;

		{
			std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
			m_players.erase(m_players.find(pid));
		}

		m_dialog->Update();
	}
	break;

	case NP_MSG_CHAT_MESSAGE:
	{
		PlayerId pid;
		packet >> pid;
		std::string msg;
		packet >> msg;

		// don't need lock to read in this thread
		const Player& player = m_players[pid];

		// add to gui
		std::ostringstream ss;
		ss << player.name << '[' << (char)(pid + '0') << "]: " << msg;

		m_dialog->AppendChat(ss.str());
	}
	break;

	case NP_MSG_PAD_MAPPING:
	{
		for (PadMapping& mapping : m_pad_map)
		{
			packet >> mapping;
		}

		UpdateDevices();

		m_dialog->Update();
	}
	break;

	case NP_MSG_WIIMOTE_MAPPING:
	{
		for (PadMapping& mapping : m_wiimote_map)
		{
			packet >> mapping;
		}

		m_dialog->Update();
	}
	break;

	case NP_MSG_PAD_DATA:
	{
		PadMapping map = 0;
		GCPadStatus pad;
		packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;

		// trusting server for good map value (>=0 && <4)
		// add to pad buffer
		m_pad_buffer[map].Push(pad);
	}
	break;

	case NP_MSG_WIIMOTE_DATA:
	{
		PadMapping map = 0;
		NetWiimote nw;
		u8 size;
		packet >> map >> size;

		nw.resize(size);

		for (unsigned int i = 0; i < size; ++i)
			packet >> nw[i];

		// trusting server for good map value (>=0 && <4)
		// add to Wiimote buffer
		m_wiimote_buffer[(unsigned)map].Push(nw);
	}
	break;


	case NP_MSG_PAD_BUFFER:
	{
		u32 size = 0;
		packet >> size;

		m_target_buffer_size = size;
	}
	break;

	case NP_MSG_CHANGE_GAME:
	{
		{
			std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
			packet >> m_selected_game;
		}

		// update gui
		m_dialog->OnMsgChangeGame(m_selected_game);
	}
	break;

	case NP_MSG_START_GAME:
	{
		{
			std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
			packet >> m_current_game;
			packet >> g_NetPlaySettings.m_CPUthread;
			packet >> g_NetPlaySettings.m_CPUcore;
			packet >> g_NetPlaySettings.m_SelectedLanguage;
			packet >> g_NetPlaySettings.m_OverrideGCLanguage;
			packet >> g_NetPlaySettings.m_ProgressiveScan;
			packet >> g_NetPlaySettings.m_PAL60;
			packet >> g_NetPlaySettings.m_DSPEnableJIT;
			packet >> g_NetPlaySettings.m_DSPHLE;
			packet >> g_NetPlaySettings.m_WriteToMemcard;
			packet >> g_NetPlaySettings.m_OCEnable;
			packet >> g_NetPlaySettings.m_OCFactor;

			int tmp;
			packet >> tmp;
			g_NetPlaySettings.m_EXIDevice[0] = (TEXIDevices)tmp;
			packet >> tmp;
			g_NetPlaySettings.m_EXIDevice[1] = (TEXIDevices)tmp;

			u32 time_low, time_high;
			packet >> time_low;
			packet >> time_high;
			g_netplay_initial_gctime = time_low | ((u64)time_high << 32);
		}

		m_dialog->OnMsgStartGame();
	}
	break;

	case NP_MSG_STOP_GAME:
	{
		m_dialog->OnMsgStopGame();
	}
	break;

	case NP_MSG_DISABLE_GAME:
	{
		PanicAlertT("Other client disconnected while game is running!! NetPlay is disabled. You must manually stop the game.");
		m_is_running.store(false);
		NetPlay_Disable();
	}
	break;

	case NP_MSG_PING:
	{
		u32 ping_key = 0;
		packet >> ping_key;

		sf::Packet spac;
		spac << (MessageId)NP_MSG_PONG;
		spac << ping_key;

		Send(spac);
	}
	break;

	case NP_MSG_PLAYER_PING_DATA:
	{
		PlayerId pid;
		packet >> pid;

		{
			std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
			Player& player = m_players[pid];
			packet >> player.ping;
		}

		m_dialog->Update();
	}
	break;

	case NP_MSG_DESYNC_DETECTED:
	{
		int pid_to_blame;
		u32 frame;
		packet >> pid_to_blame;
		packet >> frame;
		const char* blame_str = "";
		const char* blame_name = "";
		std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
		if (pid_to_blame != -1)
		{
			auto it = m_players.find(pid_to_blame);
			blame_str = " from player ";
			blame_name = it != m_players.end() ? it->second.name.c_str() : "??";
		}

		m_dialog->AppendChat(StringFromFormat("/!\\ Possible desync detected%s%s on frame %u", blame_str, blame_name, frame));
	}
	break;

	case NP_MSG_SYNC_GC_SRAM:
	{
		u8 sram[sizeof(g_SRAM.p_SRAM)];
		for (size_t i = 0; i < sizeof(g_SRAM.p_SRAM); ++i)
		{
			packet >> sram[i];
		}

		{
			std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
			memcpy(g_SRAM.p_SRAM, sram, sizeof(g_SRAM.p_SRAM));
			g_SRAM_netplay_initialized = true;
		}
	}
	break;

	default:
		PanicAlertT("Unknown message received with id : %d", mid);
		break;

	}

	return 0;
}
Пример #16
0
void ShaderManager::RemoveSourceCode(const std::string& name) {
	std::unique_lock<std::shared_mutex> lkg(m_sourceMutex);

	m_codes.erase(name);
}
Пример #17
0
// called from ---GUI--- thread
bool NetPlayClient::StartGame(const std::string &path)
{
	std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
	// tell server i started the game
	sf::Packet* spac = new sf::Packet;
	*spac << (MessageId)NP_MSG_START_GAME;
	*spac << m_current_game;
	*spac << (char *)&g_NetPlaySettings;
	SendAsync(spac);

	if (m_is_running.load())
	{
		PanicAlertT("Game is already running!");
		return false;
	}

	m_dialog->AppendChat(" -- STARTING GAME -- ");

	m_timebase_frame = 0;

	m_is_running.store(true);
	NetPlay_Enable(this);

	ClearBuffers();

	if (m_dialog->IsRecording())
	{

		if (Movie::IsReadOnly())
			Movie::SetReadOnly(false);

		u8 controllers_mask = 0;
		for (unsigned int i = 0; i < 4; ++i)
		{
			if (m_pad_map[i] > 0)
				controllers_mask |= (1 << i);
			if (m_wiimote_map[i] > 0)
				controllers_mask |= (1 << (i + 4));
		}
		Movie::BeginRecordingInput(controllers_mask);
	}

	// boot game

	m_dialog->BootGame(path);

	UpdateDevices();

	if (SConfig::GetInstance().bWii)
	{
		for (unsigned int i = 0; i < 4; ++i)
			WiimoteReal::ChangeWiimoteSource(i, m_wiimote_map[i] > 0 ? WIIMOTE_SRC_EMU : WIIMOTE_SRC_NONE);

		// Needed to prevent locking up at boot if (when) the wiimotes connect out of order.
		NetWiimote nw;
		nw.resize(4, 0);

		for (unsigned int w = 0; w < 4; ++w)
		{
			if (m_wiimote_map[w] != -1)
				// probably overkill, but whatever
				for (unsigned int i = 0; i < 7; ++i)
					m_wiimote_buffer[w].Push(nw);
		}
	}

	return true;
}
Пример #18
0
	void Register() {
		std::lock_guard<std::mutex> lkg(registryLock);
		myThreadObjects.insert(&threadObjects);
		myThreadInstances.insert(&threadInstances);
		threadInstances.insert(this);
	}