Various style nitpicks

This commit is contained in:
Rémi Verschelde 2025-05-12 16:47:16 +02:00 committed by Mikael Hermansson
parent 78f1543e35
commit 0adf0898eb
18 changed files with 75 additions and 63 deletions

View file

@ -4,17 +4,17 @@ from misc.utility.scons_hints import *
Import("env")
Import("env_modules")
env_mp = env_modules.Clone()
env_objdb = env_modules.Clone()
module_obj = []
# Only include in editor and debug builds.
if env_mp.debug_features:
env_mp.add_source_files(module_obj, "*.cpp")
if env_objdb.debug_features:
env_objdb.add_source_files(module_obj, "*.cpp")
# Only the editor needs these files, don't include them in the game.
if env.editor_build:
env_mp.add_source_files(module_obj, "editor/*.cpp")
env_mp.add_source_files(module_obj, "editor/data_viewers/*.cpp")
env_objdb.add_source_files(module_obj, "editor/*.cpp")
env_objdb.add_source_files(module_obj, "editor/data_viewers/*.cpp")
env.modules_sources += module_obj

View file

@ -1,6 +1,3 @@
# config.py
def can_build(env, platform):
return env.debug_features

View file

@ -30,11 +30,11 @@
#include "class_view.h"
#include "shared_controls.h"
#include "editor/editor_node.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/split_container.h"
#include "shared_controls.h"
int ClassData::instance_count(GameStateSnapshot *p_snapshot) {
int count = 0;

View file

@ -30,11 +30,11 @@
#include "json_view.h"
#include "shared_controls.h"
#include "core/io/json.h"
#include "scene/gui/center_container.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/split_container.h"
#include "shared_controls.h"
SnapshotJsonView::SnapshotJsonView() {
set_name(TTR("JSON"));
@ -65,7 +65,7 @@ void SnapshotJsonView::show_snapshot(GameStateSnapshot *p_data, GameStateSnapsho
String hdr_a_text = diff_data ? TTR("Snapshot A JSON") : TTR("Snapshot JSON");
SpanningHeader *hdr_a = memnew(SpanningHeader(hdr_a_text));
if (diff_data) {
hdr_a->set_tooltip_text(TTR("Snapshot A: ") + snapshot_data->name);
hdr_a->set_tooltip_text(TTR("Snapshot A:") + " " + snapshot_data->name);
}
json_box->add_child(hdr_a);
@ -86,7 +86,7 @@ void SnapshotJsonView::show_snapshot(GameStateSnapshot *p_data, GameStateSnapsho
box->add_child(diff_json_box);
String hrd_b_text = TTR("Snapshot B JSON");
SpanningHeader *hdr_b = memnew(SpanningHeader(hrd_b_text));
hdr_b->set_tooltip_text(TTR("Snapshot B: ") + diff_data->name);
hdr_b->set_tooltip_text(TTR("Snapshot B:") + " " + diff_data->name);
diff_json_box->add_child(hdr_b);
diff_json_content = memnew(EditorJsonVisualizer);

View file

@ -31,9 +31,10 @@
#pragma once
#include "../snapshot_data.h"
#include "editor/editor_json_visualizer.h"
#include "snapshot_view.h"
#include "editor/editor_json_visualizer.h"
class SnapshotJsonView : public SnapshotView {
GDCLASS(SnapshotJsonView, SnapshotView);

View file

@ -130,7 +130,7 @@ void SnapshotNodeView::_node_selected(Tree *p_tree_selected_from) {
return;
}
if (objects.size() == 1) {
EditorNode::get_singleton()->push_item((Object *)(objects.get(0)));
EditorNode::get_singleton()->push_item((Object *)objects.get(0));
}
if (objects.size() == 2) {
// This happens if we're in the combined diff view and the node exists in both trees

View file

@ -106,7 +106,7 @@ void SnapshotRefCountedView::show_snapshot(GameStateSnapshot *p_data, GameStateS
refs_list->set_column_title(offset + 5, TTR("ObjectDB Cycles"));
refs_list->set_column_expand(offset + 5, false);
refs_list->set_column_title_tooltip_text(offset + 5, TTR("Cycles detected in the ObjectDB"));
refs_list->connect("item_selected", callable_mp(this, &SnapshotRefCountedView::_refcounted_selected));
refs_list->connect(SceneStringName(item_selected), callable_mp(this, &SnapshotRefCountedView::_refcounted_selected));
refs_list->set_h_size_flags(SizeFlags::SIZE_EXPAND_FILL);
refs_list->set_v_size_flags(SizeFlags::SIZE_EXPAND_FILL);

View file

@ -34,6 +34,7 @@
#include "editor/editor_string_names.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/menu_button.h"
#include "scene/resources/style_box_flat.h"

View file

@ -31,10 +31,10 @@
#pragma once
#include "scene/gui/box_container.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/tree.h"
class LineEdit;
class MenuButton;
class SpanningHeader : public PanelContainer {

View file

@ -30,8 +30,6 @@
#include "snapshot_view.h"
#include "scene/gui/label.h"
#include "scene/gui/rich_text_label.h"
#include "scene/gui/tree.h"
void SnapshotView::clear_snapshot() {

View file

@ -31,6 +31,7 @@
#pragma once
#include "../snapshot_data.h"
#include "scene/gui/control.h"
class Tree;

View file

@ -110,24 +110,24 @@ void SnapshotSummaryView::show_snapshot(GameStateSnapshot *p_data, GameStateSnap
String snapshot_a_name = diff_data == nullptr ? TTR("Snapshot") : TTR("Snapshot A");
String snapshot_b_name = TTR("Snapshot B");
_push_overview_blurb(snapshot_a_name + TTR(" Overview"), snapshot_data);
_push_overview_blurb(snapshot_a_name + " " + TTR("Overview"), snapshot_data);
if (diff_data) {
_push_overview_blurb(snapshot_b_name + TTR(" Overview"), diff_data);
_push_overview_blurb(snapshot_b_name + " " + TTR("Overview"), diff_data);
}
_push_node_blurb(snapshot_a_name + TTR(" Nodes"), snapshot_data);
_push_node_blurb(snapshot_a_name + " " + TTR("Nodes"), snapshot_data);
if (diff_data) {
_push_node_blurb(snapshot_b_name + TTR(" Nodes"), diff_data);
_push_node_blurb(snapshot_b_name + " " + TTR("Nodes"), diff_data);
}
_push_refcounted_blurb(snapshot_a_name + TTR(" RefCounteds"), snapshot_data);
_push_refcounted_blurb(snapshot_a_name + " " + TTR("RefCounteds"), snapshot_data);
if (diff_data) {
_push_refcounted_blurb(snapshot_b_name + TTR(" RefCounteds"), diff_data);
_push_refcounted_blurb(snapshot_b_name + " " + TTR("RefCounteds"), diff_data);
}
_push_object_blurb(snapshot_a_name + TTR(" Objects"), snapshot_data);
_push_object_blurb(snapshot_a_name + " " + TTR("Objects"), snapshot_data);
if (diff_data) {
_push_object_blurb(snapshot_b_name + TTR(" Objects"), diff_data);
_push_object_blurb(snapshot_b_name + " " + TTR("Objects"), diff_data);
}
}
@ -165,30 +165,30 @@ void SnapshotSummaryView::_push_overview_blurb(const String &p_title, GameStateS
String c = "";
c += "[ul]\n";
c += TTR(" [i]Name:[/i] ") + p_snapshot->name + "\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Name:"), p_snapshot->name);
if (p_snapshot->snapshot_context.has("timestamp")) {
c += TTR(" [i]Timestamp:[/i] ") + Time::get_singleton()->get_datetime_string_from_unix_time((double)p_snapshot->snapshot_context["timestamp"]) + "\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Timestamp:"), Time::get_singleton()->get_datetime_string_from_unix_time((double)p_snapshot->snapshot_context["timestamp"]));
}
if (p_snapshot->snapshot_context.has("game_version")) {
c += TTR(" [i]Game Version:[/i] ") + (String)p_snapshot->snapshot_context["game_version"] + "\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Game Version:"), (String)p_snapshot->snapshot_context["game_version"]);
}
if (p_snapshot->snapshot_context.has("editor_version")) {
c += TTR(" [i]Editor Version:[/i] ") + (String)p_snapshot->snapshot_context["editor_version"] + "\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Editor Version:"), (String)p_snapshot->snapshot_context["editor_version"]);
}
double bytes_to_mb = 0.000001;
if (p_snapshot->snapshot_context.has("mem_usage")) {
c += TTR(" [i]Memory Used:[/i] ") + String::num((double)((uint64_t)p_snapshot->snapshot_context["mem_usage"]) * bytes_to_mb, 3) + " MB\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Memory Used:"), String::num((double)((uint64_t)p_snapshot->snapshot_context["mem_usage"]) * bytes_to_mb, 3) + " MB");
}
if (p_snapshot->snapshot_context.has("mem_max_usage")) {
c += TTR(" [i]Max Memory Used:[/i] ") + String::num((double)((uint64_t)p_snapshot->snapshot_context["mem_max_usage"]) * bytes_to_mb, 3) + " MB\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Max Memory Used:"), String::num((double)((uint64_t)p_snapshot->snapshot_context["mem_max_usage"]) * bytes_to_mb, 3) + " MB");
}
if (p_snapshot->snapshot_context.has("mem_available")) {
// I'm guessing pretty hard about what this is supposed to be. It's hard coded to be -1 cast to a uint64_t in Memory.h,
// so it _could_ be checking if we're on a 64 bit system, I think...
c += TTR(" [i]Max uint64 value:[/i] ") + String::num_uint64((uint64_t)p_snapshot->snapshot_context["mem_available"]) + "\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Max uint64 Value:"), String::num_uint64((uint64_t)p_snapshot->snapshot_context["mem_available"]));
}
c += TTR(" [i]Total Objects:[/i] ") + itos(p_snapshot->objects.size()) + "\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Total Objects:"), itos(p_snapshot->objects.size()));
int node_count = 0;
for (const KeyValue<ObjectID, SnapshotDataObject *> &pair : p_snapshot->objects) {
@ -196,7 +196,7 @@ void SnapshotSummaryView::_push_overview_blurb(const String &p_title, GameStateS
node_count++;
}
}
c += TTR(" [i]Total Nodes:[/i] ") + itos(node_count) + "\n";
c += vformat(" [i]%s[/i] %s\n", TTR("Total Nodes:"), itos(node_count));
c += "[/ul]\n";
blurb_list->add_child(memnew(SummaryBlurb(p_title, c)));

View file

@ -31,9 +31,10 @@
#pragma once
#include "../snapshot_data.h"
#include "scene/gui/margin_container.h"
#include "snapshot_view.h"
#include "scene/gui/margin_container.h"
class CenterContainer;
class RichTextLabel;

View file

@ -31,15 +31,15 @@
#include "objectdb_profiler_panel.h"
#include "../snapshot_collector.h"
#include "core/config/project_settings.h"
#include "core/os/memory.h"
#include "core/os/time.h"
#include "data_viewers/class_view.h"
#include "data_viewers/json_view.h"
#include "data_viewers/node_view.h"
#include "data_viewers/object_view.h"
#include "data_viewers/refcounted_view.h"
#include "data_viewers/summary_view.h"
#include "core/config/project_settings.h"
#include "core/os/time.h"
#include "editor/debugger/editor_debugger_node.h"
#include "editor/debugger/script_editor_debugger.h"
#include "editor/editor_node.h"
@ -308,7 +308,7 @@ void ObjectDBProfilerPanel::_edit_snapshot_name() {
}
}
if (name_taken || new_snapshot_name.contains(":") || new_snapshot_name.contains("\\") || new_snapshot_name.contains("/") || new_snapshot_name.begins_with(".") || new_snapshot_name.is_empty()) {
if (name_taken || new_snapshot_name.contains_char(':') || new_snapshot_name.contains_char('\\') || new_snapshot_name.contains_char('/') || new_snapshot_name.begins_with(".") || new_snapshot_name.is_empty()) {
EditorNode::get_singleton()->show_warning(TTR("Invalid snapshot name."));
snapshot_list->get_selected()->set_text(0, old_snapshot_name);
return;

View file

@ -30,11 +30,12 @@
#pragma once
#include "core/io/dir_access.h"
#include "core/templates/lru.h"
#include "data_viewers/snapshot_view.h"
#include "snapshot_data.h"
#include "core/io/dir_access.h"
#include "core/templates/lru.h"
class TabContainer;
class Tree;

View file

@ -31,14 +31,14 @@
#include "snapshot_data.h"
#include "core/core_bind.h"
#include "core/version.h"
#include "core/object/script_language.h"
#include "scene/debugger/scene_debugger.h"
#if defined(MODULE_GDSCRIPT_ENABLED) && defined(DEBUG_ENABLED)
#include "modules/gdscript/gdscript.h"
#else
#include "core/object/script_language.h"
#endif
#include "scene/debugger/scene_debugger.h"
#include "zlib.h"
#include <zlib.h>
SnapshotDataObject::SnapshotDataObject(SceneDebuggerObject &p_obj, GameStateSnapshot *p_snapshot, ResourceCache &resource_cache) :
snapshot(p_snapshot) {
@ -365,7 +365,7 @@ Ref<GameStateSnapshotRef> GameStateSnapshot::create_ref(const String &p_snapshot
}
snapshot->recompute_references();
print_line("Resource cache hits: " + String::num(resource_cache.hits) + ". Resource cache misses: " + String::num(resource_cache.misses));
print_verbose("Resource cache hits: " + String::num(resource_cache.hits) + ". Resource cache misses: " + String::num(resource_cache.misses));
return sn;
}

View file

@ -30,25 +30,36 @@
#include "register_types.h"
#include "snapshot_collector.h"
#ifdef TOOLS_ENABLED
#include "editor/objectdb_profiler_plugin.h"
#endif // TOOLS_ENABLED
#include "snapshot_collector.h"
void initialize_objectdb_profiler_module(ModuleInitializationLevel p_level) {
switch (p_level) {
case MODULE_INITIALIZATION_LEVEL_SCENE: {
SnapshotCollector::initialize();
} break;
#ifdef TOOLS_ENABLED
if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
EditorPlugins::add_by_type<ObjectDBProfilerPlugin>();
}
case MODULE_INITIALIZATION_LEVEL_EDITOR: {
EditorPlugins::add_by_type<ObjectDBProfilerPlugin>();
} break;
#endif // TOOLS_ENABLED
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
SnapshotCollector::initialize();
default:
break;
}
}
void uninitialize_objectdb_profiler_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
SnapshotCollector::deinitialize();
switch (p_level) {
case MODULE_INITIALIZATION_LEVEL_SCENE: {
SnapshotCollector::deinitialize();
} break;
default:
break;
}
}

View file

@ -34,6 +34,7 @@
#include "core/debugger/engine_debugger.h"
#include "core/os/time.h"
#include "core/version.h"
#include "scene/main/node.h"
#include "scene/main/window.h"
HashMap<int, Vector<uint8_t>> SnapshotCollector::pending_snapshots;
@ -89,13 +90,13 @@ void SnapshotCollector::snapshot_objects(Array *p_arr, Dictionary &p_snapshot_co
SnapshotDataTransportObject debug_data(obj);
// If we're RefCounted, send over our RefCount too. Could add code here to add a few other interesting properties.
if (ClassDB::is_parent_class(obj->get_class_name(), RefCounted::get_class_static())) {
RefCounted *ref = (RefCounted *)obj;
RefCounted *ref = Object::cast_to<RefCounted>(obj);
if (ref) {
debug_data.extra_debug_data["ref_count"] = ref->get_reference_count();
}
if (ClassDB::is_parent_class(obj->get_class_name(), Node::get_class_static())) {
Node *node = (Node *)obj;
Node *node = Object::cast_to<Node>(obj);
if (node) {
debug_data.extra_debug_data["node_name"] = node->get_name();
if (node->get_parent() != nullptr) {
debug_data.extra_debug_data["node_parent"] = node->get_parent()->get_instance_id();
@ -125,7 +126,7 @@ void SnapshotCollector::snapshot_objects(Array *p_arr, Dictionary &p_snapshot_co
p_arr->push_back(debug_data.extra_debug_data);
}
print_verbose("snapshot size: " + String::num_uint64(p_arr->size()));
print_verbose("Snapshot size: " + String::num_uint64(p_arr->size()));
}
Error SnapshotCollector::parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured) {