GameUniverse.h 2.1 KB
Newer Older
1 2 3 4 5 6
#pragma once

#include <Streaming.h>

#include <vfs/Device.h>

7 8
#include <Console.CommandHelpers.h>

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
namespace krt
{
struct GameConfiguration
{
	// the internal name of the game ('gta3', for instance)
	std::string gameName;

	// the path (in the existing VFS tree) to the game root
	std::string rootPath;

	// a list of game configuration files (world DAT files) to load, relative to the game root
	std::vector<std::string> configurationFiles;

	// a list of CD images to preload (say, 'models/gta3.img')
	std::vector<std::string> imageFiles;
};

26 27
class Game;

28 29 30
// a game universe represents a single game's asset configuration
class GameUniverse
{
NTAuthority committed
31
  public:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	GameUniverse(const GameConfiguration& configuration);

	~GameUniverse();

	inline const GameConfiguration& GetConfiguration() const
	{
		return m_configuration;
	}

	void Load();

	std::string GetMountPoint() const;

	std::string GetImageMountPoint() const;

	inline void RegisterOwnedStreamingIndex(streaming::ident_t id)
	{
		m_streamingIndices.push_back(id);
	}

	inline void RegisterModelIndexMapping(streaming::ident_t from, streaming::ident_t to)
	{
NTAuthority committed
54
		m_modelIndexMapping.insert({from, to});
55 56 57 58 59 60
	}

	inline streaming::ident_t GetModelIndexMapping(streaming::ident_t localId)
	{
		auto it = m_modelIndexMapping.find(localId);

61 62 63
#if _DEBUG
		// We kind of do not want this to happen in our testing.
		// But if it does, then handle it appropriately.
64
		assert(it != m_modelIndexMapping.end());
65
#endif
66

67 68
		if (it == m_modelIndexMapping.end())
			return -1;
69

70 71 72
		return it->second;
	}

NTAuthority committed
73
  private:
74 75
	void AddImage(const std::string& relativePath);

76
	ConsoleCommand cmdAddImage;
77

78 79
	void LoadConfiguration(const std::string& relativePath);

NTAuthority committed
80
  private:
81 82 83 84 85 86 87 88 89
	struct ImageFile
	{
		vfs::DevicePtr cdimage;
		vfs::DevicePtr relativeMount;

		// the path the CD image is primarily mounted at
		std::string primaryMount;
	};

NTAuthority committed
90
  private:
91 92 93 94 95 96 97
	GameConfiguration m_configuration;

	std::vector<ImageFile> m_imageFiles;

	std::vector<streaming::ident_t> m_streamingIndices;

	std::map<streaming::ident_t, streaming::ident_t> m_modelIndexMapping;
NTAuthority committed
98 99

	Game* m_game;
100 101 102 103
};

using GameUniversePtr = std::shared_ptr<GameUniverse>;
}