浏览代码

Merge pull request #49915 from Calinou/bakedlightmap-print-time-request-attention-3.x

Print time taken and request attention when lightmaps are done baking
Rémi Verschelde 4 年之前
父节点
当前提交
5601d86a27
共有 2 个文件被更改,包括 11 次插入3 次删除
  1. 10 2
      editor/plugins/baked_lightmap_editor_plugin.cpp
  2. 1 1
      editor/plugins/baked_lightmap_editor_plugin.h

+ 10 - 2
editor/plugins/baked_lightmap_editor_plugin.cpp

@@ -33,13 +33,14 @@
 void BakedLightmapEditorPlugin::_bake_select_file(const String &p_file) {
 	if (lightmap) {
 		BakedLightmap::BakeError err;
+		uint32_t time_started = OS::get_singleton()->get_ticks_msec();
 		if (get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root() == lightmap) {
 			err = lightmap->bake(lightmap, p_file);
 		} else {
 			err = lightmap->bake(lightmap->get_parent(), p_file);
 		}
 
-		bake_func_end();
+		bake_func_end(time_started);
 
 		switch (err) {
 			case BakedLightmap::BAKE_ERROR_NO_SAVE_PATH: {
@@ -122,7 +123,7 @@ bool BakedLightmapEditorPlugin::bake_func_substep(float p_progress, const String
 	return tmp_subprogress->step(p_description, p_progress * 1000, p_force_refresh);
 }
 
-void BakedLightmapEditorPlugin::bake_func_end() {
+void BakedLightmapEditorPlugin::bake_func_end(uint32_t p_time_started) {
 	if (tmp_progress != nullptr) {
 		memdelete(tmp_progress);
 		tmp_progress = nullptr;
@@ -132,6 +133,13 @@ void BakedLightmapEditorPlugin::bake_func_end() {
 		memdelete(tmp_subprogress);
 		tmp_subprogress = nullptr;
 	}
+
+	const int time_taken = (OS::get_singleton()->get_ticks_msec() - p_time_started) * 0.001;
+	print_line(vformat("Done baking lightmaps in %02d:%02d:%02d.", time_taken / 3600, (time_taken % 3600) / 60, time_taken % 60));
+	// Request attention in case the user was doing something else.
+	// Baking lightmaps is likely the editor task that can take the most time,
+	// so only request the attention for baking lightmaps.
+	OS::get_singleton()->request_attention();
 }
 
 void BakedLightmapEditorPlugin::_bind_methods() {

+ 1 - 1
editor/plugins/baked_lightmap_editor_plugin.h

@@ -50,7 +50,7 @@ class BakedLightmapEditorPlugin : public EditorPlugin {
 
 	static bool bake_func_step(float p_progress, const String &p_description, void *, bool p_force_refresh);
 	static bool bake_func_substep(float p_progress, const String &p_description, void *, bool p_force_refresh);
-	static void bake_func_end();
+	static void bake_func_end(uint32_t p_time_started);
 
 	void _bake_select_file(const String &p_file);
 	void _bake();