Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. ///////////////H File ////////////
  2. #pragma once
  3. #include "GameState.h"
  4. #include <future>
  5. #include "GameStateGamePlay.h"
  6.  
  7. class GameStateLoadGame :public GameState
  8. {
  9. public:
  10.     GameStateLoadGame(Game& game, std::string db, unsigned int userid);
  11.     void Draw(Graphics& gfx)override;
  12.     void Update()override;
  13. private:
  14.     std::shared_ptr<GameStateGamePlay> SetupNextState();
  15. private:
  16.     Surface background;
  17.     std::future<std::shared_ptr<GameStateGamePlay>> next;
  18. };
  19. ////////////////////CPP file //////////////
  20. #include "GameStateLoadGame.h"
  21. #include "..\Game.h"
  22.  
  23. GameStateLoadGame::GameStateLoadGame(Game & game, std::string db, unsigned int userid)
  24.     :
  25.     GameState(game),
  26.     background(Surface::FromFile("..\\data\\textures\\bg.png")),
  27.     //ERROR: no instande of constructors matches argument list , types are std::future<void>
  28.     next(std::async(std::launch::async, [this,db,userid] { SetupNextState(); }))
  29. {
  30. }
  31.  
  32. void GameStateLoadGame::Draw(Graphics & gfx)
  33. {
  34.     background.Draw(0, 0, gfx);
  35.     //also draw loading bar based on process white fill with yellow
  36. }
  37.  
  38. void GameStateLoadGame::Update()
  39. {
  40.     if (next.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)
  41.     {
  42.         // error because currently i am using unique_ptr not shared
  43.         pGame.SetGameState(next.get());
  44.     }
  45. }
  46.  
  47. std::shared_ptr<GameStateGamePlay> GameStateLoadGame::SetupNextState()
  48. {
  49.     return std::make_shared<GameStateGamePlay>(pGame,db, userid); // error undefined db and userid (doing something stupid)
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement