Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////H File ////////////
- #pragma once
- #include "GameState.h"
- #include <future>
- #include "GameStateGamePlay.h"
- class GameStateLoadGame :public GameState
- {
- public:
- GameStateLoadGame(Game& game, std::string db, unsigned int userid);
- void Draw(Graphics& gfx)override;
- void Update()override;
- private:
- std::shared_ptr<GameStateGamePlay> SetupNextState();
- private:
- Surface background;
- std::future<std::shared_ptr<GameStateGamePlay>> next;
- };
- ////////////////////CPP file //////////////
- #include "GameStateLoadGame.h"
- #include "..\Game.h"
- GameStateLoadGame::GameStateLoadGame(Game & game, std::string db, unsigned int userid)
- :
- GameState(game),
- background(Surface::FromFile("..\\data\\textures\\bg.png")),
- //ERROR: no instande of constructors matches argument list , types are std::future<void>
- next(std::async(std::launch::async, [this,db,userid] { SetupNextState(); }))
- {
- }
- void GameStateLoadGame::Draw(Graphics & gfx)
- {
- background.Draw(0, 0, gfx);
- //also draw loading bar based on process white fill with yellow
- }
- void GameStateLoadGame::Update()
- {
- if (next.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready)
- {
- // error because currently i am using unique_ptr not shared
- pGame.SetGameState(next.get());
- }
- }
- std::shared_ptr<GameStateGamePlay> GameStateLoadGame::SetupNextState()
- {
- return std::make_shared<GameStateGamePlay>(pGame,db, userid); // error undefined db and userid (doing something stupid)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement