Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. //Deadlock problem. So i am not sure where is the problem but I think it's that I am using pointer to access function and inside that function I change that pointer .
  2.  
  3. void Game::UpdateModel()
  4. {
  5.     FrameTimer.Mark();
  6.     if (wnd.kbd.KeyIsPressed(VK_ESCAPE))
  7.     {
  8.         exit(1);
  9.     }
  10.     GameClient.UserMsgHandler();// Client packet handler
  11.     // NOTE: (reductor) PacketSenderThread thead can block due to non-blocking call to send()
  12.     GameClient.PacketSenderThread();
  13.     pCurrentState->Update();
  14.     GUI.Update(wnd.mouse,wnd.kbd);
  15. }
  16.  
  17. void Client::UserMsgHandler()
  18. {
  19.     if (Connected) {
  20.         PacketType ptype;
  21.         if (!RecvPacketType(ptype))// recieving packettype
  22.         {
  23.             return;
  24.         }
  25.         std::lock_guard<std::mutex> lock(mtx);
  26.         if (!pGameState->PacketHandler(ptype))// pasing packet type to current gamestate virtual PacketHandler funtions
  27.         {
  28.             Log("Lost Connection to the server");
  29.             if (!CloseConnection())
  30.             {
  31.                 Log("Failed to close socket");
  32.             }
  33.             else
  34.             {
  35.                 Log("Socket was closed");
  36.             }
  37.             return;
  38.         }
  39.     }
  40. }
  41.  
  42. bool GameStateLogin::PacketHandler(PacketType type)
  43. {
  44.     switch (type)
  45.     {
  46.         case Login_NoSuchUser:
  47.         case Login_WrongPassword:
  48.             pGUI.GetElement("LoginError")->Enable();
  49.             break;
  50.         case Login_LoginSuccessful:
  51.         {
  52.             int id = 0;
  53.             int firsttime = 0;
  54.             if (!pClient.Recv32Bits(firsttime))
  55.                 return false;
  56.             if (!pClient.Recv32Bits(id))
  57.                 return false;
  58.  
  59.             pGUI.ClearGUI();
  60.             pGame.SetGameState(std::make_unique<GameStateGamePlay>(pGame, db, id, firsttime)); // changing state of game and poiner to state in client aswell
  61.             break;
  62.         }
  63.         case Mysql_Error:
  64.             pGUI.GetElement("FailedToConnect")->Enable();
  65.             break;
  66.     }
  67.     return true;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement