Game.h 2.55 KB
Newer Older
1 2 3 4
#pragma once

// Game things go here!

NTAuthority's avatar
NTAuthority committed
5
#define GAME_NUM_STREAMING_CHANNELS 4
6

7 8
#include "vfs\Device.h"

NTAuthority's avatar
NTAuthority committed
9
#include "ModelInfo.h"
10
#include "Streaming.h"
11
#include "TexDict.h"
12
#include "CollisionStore.h"
13
#include "World.h"
14 15

#include "Console.Commands.h"
16
#include "GameUniverse.h"
17

18 19
#include "Console.VariableHelpers.h"

20 21
#include "Camera.h"

22 23 24 25 26
namespace krt
{

class Game
{
NTAuthority's avatar
NTAuthority committed
27
	friend struct Entity;
28

29
public:
30
	Game(const std::vector<std::pair<std::string, std::string>>& setList);
NTAuthority's avatar
NTAuthority committed
31
	~Game(void);
32

33 34
	void Run();

NTAuthority's avatar
NTAuthority committed
35
	std::string GetGamePath(std::string relPath);
36

NTAuthority's avatar
NTAuthority committed
37 38 39
	inline streaming::StreamMan& GetStreaming(void) { return this->streaming; }
	inline TextureManager& GetTextureManager(void) { return this->texManager; }
	inline ModelManager& GetModelManager(void) { return this->modelManager; }
40
	inline CollisionStore& GetCollisionStore(void) { return this->colStore; }
41

NTAuthority's avatar
NTAuthority committed
42 43
	inline World* GetWorld(void) { return &theWorld; }

44 45 46 47
	inline float GetDelta() { return dT; }

	inline uint32_t GetLastFrameTime() { return lastFrameTime; }

48 49
	inline uint64_t GetGameTime() { return lastGameTime; }

NTAuthority's avatar
NTAuthority committed
50
	std::string GetDevicePathPrefix(void) { return "gta3:/"; }
51

52
	GameUniversePtr AddUniverse(const GameConfiguration& configuration);
53

54
	GameUniversePtr GetUniverse(const std::string& name);
55

56 57
	Camera& GetWorldCamera(void) { return this->worldCam; }

58 59
	void SetActiveCamera(Camera* theCamera) { this->activeCam = theCamera; }
	Camera* GetActiveCamera(void) { return this->activeCam; }
60

61
private:
62 63
	void MountUserDirectory();

64
	void YieldThreadForShortTime();
65

66 67
	void LoadUniverseIfAvailable();

68
private:
69 70
	float dT;
	uint32_t lastFrameTime;
71
	uint64_t lastGameTime;
72

NTAuthority's avatar
NTAuthority committed
73
	std::string gameDir;
74

NTAuthority's avatar
NTAuthority committed
75
	streaming::StreamMan streaming;
76

NTAuthority's avatar
NTAuthority committed
77 78
	TextureManager texManager;
	ModelManager modelManager;
79
	CollisionStore colStore;
80

NTAuthority's avatar
NTAuthority committed
81
	World theWorld;
82

NTAuthority's avatar
NTAuthority committed
83
	NestedList<Entity> activeEntities;
84 85

	std::vector<GameUniversePtr> universes;
86 87 88 89 90

	int maxFPS;

	float timescale;

91 92
	Camera worldCam; // camera to render the main world in

93
	Camera* activeCam;
94

95
private:
96 97 98
	std::unique_ptr<ConVar<int>> maxFPSVariable;

	std::unique_ptr<ConVar<float>> timescaleVariable;
99 100 101 102

	std::unique_ptr<ConVar<std::string>> gameVariable;

	std::unique_ptr<ConVar<std::string>> gamePathVariable;
103 104
};

NTAuthority's avatar
NTAuthority committed
105
extern Game* theGame;
106

NTAuthority's avatar
NTAuthority committed
107
template <>
108 109 110 111 112
struct ConsoleArgumentType<GameUniversePtr>
{
	static bool Parse(const std::string& input, GameUniversePtr* out)
	{
		*out = theGame->GetUniverse(input);
113 114 115 116 117 118 119

		// fail to parse if there's no such universe
		if (!*out)
		{
			return false;
		}

120 121 122
		return true;
	}
};
123
};