MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Run

Method Run

Source/Engine/Utilities/Screenshot.cpp:78–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76};
77
78bool CaptureScreenshot::Run()
79{
80 const auto texture = _texture.Get();
81 if (texture == nullptr && _renderTask == nullptr)
82 {
83 LOG(Warning, "Missing target render task.");
84 return true;
85 }
86 PROFILE_MEM(Graphics);
87
88 // TODO: how about a case two or more screenshots at the same second? update counter and check files
89
90 // Ensure that path is valid and folder exists
91 String screenshotsDir;
92 if (_path.IsEmpty())
93 {
94#if USE_EDITOR
95 screenshotsDir = Globals::ProjectFolder / TEXT("Screenshots");
96#else
97 screenshotsDir = Globals::ProductLocalFolder / TEXT("Screenshots");
98#endif
99 _path = screenshotsDir / String::Format(TEXT("Screenshot_{0}.png"), DateTime::Now().ToFileNameString());
100 }
101 else
102 {
103 screenshotsDir = StringUtils::GetDirectoryName(_path);
104 }
105 if (!FileSystem::DirectoryExists(screenshotsDir))
106 FileSystem::CreateDirectory(screenshotsDir);
107
108#if COMPILE_WITH_TEXTURE_TOOL
109 // Export to file
110 if (TextureTool::ExportTexture(_path, _data))
111 {
112 LOG(Warning, "Cannot export screenshot to file.");
113 return true;
114 }
115#else
116 LOG(Warning, "Cannot export screenshot to file. No textures exporting support in build.");
117 return true;
118#endif
119
120 LOG(Info, "Saved screenshot '{1}' (time: {0} ms)", Math::RoundToInt((float)(DateTime::NowUTC() - _startTime).GetTotalMilliseconds()), _path);
121
122 _renderTask = nullptr;
123 return false;
124}
125
126void CaptureScreenshot::OnFail()
127{

Callers 2

CaptureMethod · 0.45
RequestMeshDataMethod · 0.45

Calls 5

ToFileNameStringMethod · 0.80
FormatFunction · 0.50
RoundToIntFunction · 0.50
GetMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected