Polyphase Game Engine
Loading...
Searching...
No Matches
MemorySnapshotProfiler.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 "MemorySnapshot.h"
9
10class Asset;
11
12// Walks the game world(s) and returns the set of assets the game actually
13// references -- direct node/script property refs plus transitive children
14// (mesh -> material -> texture, incl. MaterialLite texture slots; font -> atlas).
15// Editor-only assets (gizmos, grid, thumbnails, engine editor fonts) are excluded
16// because game nodes never reference them. This is the accurate, game-scoped
17// resource set shared by the Memory Snapshot tool and the Profiling window.
18// outRefs maps each referenced Asset* to how many times it was referenced.
19// Optional out-params report the Lua scripts referenced and the node/world counts.
20void GatherGameReferencedAssets(std::unordered_map<Asset*, uint32_t>& outRefs,
21 std::unordered_map<std::string, uint32_t>* outScriptFiles = nullptr,
22 uint32_t* outNodeCount = nullptr,
23 int32_t* outWorldCount = nullptr);
24
25// Builds the full game-scoped memory report: one entry per referenced asset
26// (sized by actual pixel format, streaming-aware audio), plus Lua script source
27// entries and a Frame Buffers entry (color x2 + depth for the render surface).
28// This is the single source of truth shared by the Memory Snapshot tool and the
29// Profiling window, so both report identical numbers. Appends to outEntries.
30void BuildGameMemoryEntries(std::vector<SnapshotEntry>& outEntries,
31 uint32_t* outNodeCount = nullptr,
32 int32_t* outWorldCount = nullptr);
33
34// Builds a MemorySnapshot of the running game (the Game/3DS preview surface, or
35// live Play-In-Editor) -- never the editor viewport. Memory is attributed to the
36// assets referenced by the game world's nodes, so editor-only resources (gizmo
37// icons, editor fonts, asset-browser thumbnails, grid) are naturally excluded.
38// Safe to call whether or not PIE is active; the result records which mode it was
39// captured in (MemorySnapshot::mWasPlayingInEditor). Must run on the main thread
40// (reads the render target for the thumbnail).
41MemorySnapshot CaptureSnapshot();
42
43// The <project>/Debug/ folder snapshots are written to (with a trailing slash).
44// Deliberately a sibling of Assets/ so the AssetManager never indexes snapshots.
45// Returns "" when no project is open.
46std::string GetDebugSnapshotDir();
47
48// Auto-named path in the Debug/ folder: DebugSnapshot_YYYY-MM-DD_HH-MM-SS.oct.
49// Returns "" when no project is open.
50std::string MakeDefaultSnapshotPath();
51
52// Loose-file (bare Stream) serialization. path is any writable location; the
53// primary caller passes MakeDefaultSnapshotPath(). Creates Debug/ if needed.
54bool SaveSnapshot(const MemorySnapshot& snapshot, const std::string& path);
55bool LoadSnapshot(MemorySnapshot& outSnapshot, const std::string& path);
56
57#endif
Definition Asset.h:120