Polyphase Game Engine
Loading...
Searching...
No Matches
BuildCache.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <string>
6#include <vector>
7#include <unordered_map>
8#include <cstdint>
9#include "EngineTypes.h"
10
11struct FileEntry
12{
13 std::string mPath;
14 int64_t mModTime = 0;
15};
16
17struct BuildManifest
18{
19 static constexpr uint32_t kCurrentVersion = 1;
20
21 uint32_t mVersion = kCurrentVersion;
22 Platform mPlatform = Platform::Windows;
23 bool mEmbedded = false;
24 int64_t mBuildTime = 0;
25 std::string mProjectName;
26 std::string mOutputDirectory;
27
28 std::vector<FileEntry> mAssets;
29 std::vector<FileEntry> mScripts;
30 std::vector<FileEntry> mConfigFiles;
31};
32
33enum class BuildCacheResult
34{
35 UpToDate,
36 NeedsRebuild,
37 ManifestMissing,
38 ManifestCorrupt,
39 OutputMissing,
40 VersionMismatch
41};
42
43class BuildCache
44{
45public:
46 static BuildCache* Get();
47 static void Create();
48 static void Destroy();
49
50 BuildCacheResult CheckRebuildNeeded(Platform platform, bool embedded);
51 std::string GetRebuildReason() const { return mRebuildReason; }
52
53 void BuildCurrentManifest(Platform platform, bool embedded);
54 bool SaveManifest();
55 bool LoadManifest(Platform platform, bool embedded);
56
57 std::string GetManifestPath(Platform platform, bool embedded) const;
58
59private:
60 BuildCache();
61 ~BuildCache();
62
63 void GatherAssetFiles(std::vector<FileEntry>& outAssets);
64 void GatherScriptFiles(std::vector<FileEntry>& outScripts);
65 void GatherConfigFiles(std::vector<FileEntry>& outConfigs);
66
67 int64_t GetFileModTime(const std::string& path) const;
68 bool CompareManifests(const BuildManifest& current, const BuildManifest& saved);
69 bool VerifyOutputDirectory() const;
70
71 static BuildCache* sInstance;
72
73 BuildManifest mCurrentManifest;
74 BuildManifest mSavedManifest;
75 std::string mRebuildReason;
76};
77
78#endif
Platform
Definition EngineTypes.h:31