1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef PREGAME_H
#define PREGAME_H
#include <string>
#include <memory>
#include "GameController.h"
#include "System/Misc/SpringTime.h"
class ILoadSaveHandler;
class GameData;
class CGameSetup;
class ClientSetup;
namespace netcode {
class RawPacket;
}
/**
* @brief This controls the game start
*
* Before a game starts, this class does everything that needs to be done before.
* It basically goes like this:
* For servers:
* 1. Find out which map, script and mod to use
* 2. Start the server with this settings
* 3. continue with "For clients"
*
* For Clients:
* 1. Connect to the server
* 2. Receive GameData from server
* 3. Start the CGame with the information provided by server
* */
class CPreGame : public CGameController
{
public:
CPreGame(std::shared_ptr<ClientSetup> setup);
virtual ~CPreGame();
void LoadSetupscript(const std::string& script);
void LoadDemo(const std::string& demo);
void LoadSavefile(const std::string& save, bool usecreg);
bool Draw() override;
bool Update() override;
int KeyPressed(int k, bool isRepeat) override;
private:
void AddGameSetupArchivesToVFS(const CGameSetup* setup, bool mapOnly);
void StartServer(const std::string& setupscript);
void StartServerForDemo(const std::string& demoName);
/// reads out map, mod and script from demos (with or without a gameSetupScript)
void ReadDataFromDemo(const std::string& demoName);
/// receive network traffic
void UpdateClientNet();
void GameDataReceived(std::shared_ptr<const netcode::RawPacket> packet);
/**
@brief GameData we received from server
We won't start until we received this (NULL until GameDataReceived)
*/
std::shared_ptr<GameData> gameData;
std::shared_ptr<ClientSetup> clientSetup;
std::string modArchive;
ILoadSaveHandler* savefile;
spring_time connectTimer;
bool wantDemo;
};
extern CPreGame* pregame;
#endif /* PREGAME_H */
|