Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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 .
- void Game::UpdateModel()
- {
- FrameTimer.Mark();
- if (wnd.kbd.KeyIsPressed(VK_ESCAPE))
- {
- exit(1);
- }
- GameClient.UserMsgHandler();// Client packet handler
- // NOTE: (reductor) PacketSenderThread thead can block due to non-blocking call to send()
- GameClient.PacketSenderThread();
- pCurrentState->Update();
- GUI.Update(wnd.mouse,wnd.kbd);
- }
- void Client::UserMsgHandler()
- {
- if (Connected) {
- PacketType ptype;
- if (!RecvPacketType(ptype))// recieving packettype
- {
- return;
- }
- std::lock_guard<std::mutex> lock(mtx);
- if (!pGameState->PacketHandler(ptype))// pasing packet type to current gamestate virtual PacketHandler funtions
- {
- Log("Lost Connection to the server");
- if (!CloseConnection())
- {
- Log("Failed to close socket");
- }
- else
- {
- Log("Socket was closed");
- }
- return;
- }
- }
- }
- bool GameStateLogin::PacketHandler(PacketType type)
- {
- switch (type)
- {
- case Login_NoSuchUser:
- case Login_WrongPassword:
- pGUI.GetElement("LoginError")->Enable();
- break;
- case Login_LoginSuccessful:
- {
- int id = 0;
- int firsttime = 0;
- if (!pClient.Recv32Bits(firsttime))
- return false;
- if (!pClient.Recv32Bits(id))
- return false;
- pGUI.ClearGUI();
- pGame.SetGameState(std::make_unique<GameStateGamePlay>(pGame, db, id, firsttime)); // changing state of game and poiner to state in client aswell
- break;
- }
- case Mysql_Error:
- pGUI.GetElement("FailedToConnect")->Enable();
- break;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement