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 bool mStaticContent = false;
25 bool mContentPak = false;
26 int64_t mBuildTime = 0;
27 std::string mProjectName;
28 std::string mOutputDirectory;
29 std::string mTargetVariant; // discriminates targets sharing a basePlatform; "" for the canonical built-in
30
31 std::vector<FileEntry> mAssets;
32 std::vector<FileEntry> mScripts;
33 std::vector<FileEntry> mConfigFiles;
34};
35
36enum class BuildCacheResult
37{
38 UpToDate,
39 NeedsRebuild,
40 ManifestMissing,
41 ManifestCorrupt,
42 OutputMissing,
43 VersionMismatch
44};
45
46class BuildCache
47{
48public:
49 static BuildCache* Get();
50 static void Create();
51 static void Destroy();
52
53 // staticContent participates in the manifest identity: a Moddable package and
54 // a Static package of the same content are different outputs, so they must not
55 // share a manifest or flipping the checkbox reports "up to date" and ships the
56 // previous, unobfuscated build.
57 //
58 // targetVariant extends that identity to the build target. Platform alone is
59 // not unique — RPM, AppImage, PSP, Dreamcast and PS2 all declare Linux as
60 // their basePlatform — so without it they share one manifest and switching
61 // between them falsely reports "up to date". Empty for the canonical built-in
62 // of each platform, which keeps legacy manifest filenames unchanged. Callers
63 // fold the target's profile options into the string so option edits invalidate.
64 // outputDirectory is the absolute Packaged/<subdir>/ path this build writes
65 // to; empty derives the legacy Packaged/<PlatformName>/. It has to be told
66 // rather than derived because only ActionManager knows which target owns a
67 // platform outright, and VerifyOutputDirectory checks it to decide whether a
68 // cached build's output still exists.
69 BuildCacheResult CheckRebuildNeeded(Platform platform, bool embedded, bool staticContent, bool contentPak,
70 const std::string& targetVariant = "",
71 const std::string& outputDirectory = "");
72 std::string GetRebuildReason() const { return mRebuildReason; }
73
74 void BuildCurrentManifest(Platform platform, bool embedded, bool staticContent, bool contentPak,
75 const std::string& targetVariant = "",
76 const std::string& outputDirectory = "");
77 bool SaveManifest();
78 bool LoadManifest(Platform platform, bool embedded, bool staticContent, bool contentPak,
79 const std::string& targetVariant = "");
80
81 std::string GetManifestPath(Platform platform, bool embedded, bool staticContent, bool contentPak,
82 const std::string& targetVariant = "") const;
83
84private:
85 BuildCache();
86 ~BuildCache();
87
88 void GatherAssetFiles(std::vector<FileEntry>& outAssets);
89 void GatherScriptFiles(std::vector<FileEntry>& outScripts);
90 void GatherConfigFiles(std::vector<FileEntry>& outConfigs);
91
92 int64_t GetFileModTime(const std::string& path) const;
93 bool CompareManifests(const BuildManifest& current, const BuildManifest& saved);
94 bool VerifyOutputDirectory() const;
95
96 static BuildCache* sInstance;
97
98 BuildManifest mCurrentManifest;
99 BuildManifest mSavedManifest;
100 std::string mRebuildReason;
101};
102
103#endif
Platform
Definition EngineTypes.h:32