File: PreGame.h

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (81 lines) | stat: -rw-r--r-- 1,954 bytes parent folder | download
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef PREGAME_H
#define PREGAME_H

#include <string>
#include <boost/shared_ptr.hpp>

#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(boost::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();
	int KeyPressed(int k, bool isRepeat);
	bool Update();

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(boost::shared_ptr<const netcode::RawPacket> packet);

	/**
	@brief GameData we received from server

	We won't start until we received this (NULL until GameDataReceived)
	*/
	boost::shared_ptr<GameData> gameData;
	boost::shared_ptr<ClientSetup> clientSetup;

	std::string modArchive;
	ILoadSaveHandler* savefile;

	spring_time timer;
	bool wantDemo;
};

extern CPreGame* pregame;

#endif /* PREGAME_H */