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