Path: blob/master/modules/objectdb_profiler/editor/snapshot_data.h
11323 views
/**************************************************************************/1/* snapshot_data.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/debugger/editor_debugger_inspector.h"3334class GameStateSnapshot;35class GameStateSnapshotRef;3637class SnapshotDataObject : public Object {38GDCLASS(SnapshotDataObject, Object);3940HashSet<ObjectID> _unique_references(const HashMap<String, ObjectID> &p_refs);41String _get_script_name(Ref<Script> p_script);4243public:44GameStateSnapshot *snapshot = nullptr;45Dictionary extra_debug_data;46HashMap<String, ObjectID> outbound_references;47HashMap<String, ObjectID> inbound_references;4849HashSet<ObjectID> get_unique_outbound_refernces();50HashSet<ObjectID> get_unique_inbound_references();5152uint64_t remote_object_id = 0;53String type_name;54LocalVector<PropertyInfo> prop_list;55HashMap<StringName, Variant> prop_values;56bool _get(const StringName &p_name, Variant &r_ret) const;57void _get_property_list(List<PropertyInfo> *p_list) const;5859struct ResourceCache {60HashMap<String, Ref<Resource>> cache;61int misses = 0;62int hits = 0;63};6465SnapshotDataObject(SceneDebuggerObject &p_obj, GameStateSnapshot *p_snapshot, ResourceCache &resource_cache);6667String get_name();68String get_node_path();69bool is_refcounted();70bool is_node();71bool is_class(const String &p_base_class);7273protected:74// Snapshots are inherently read-only. Can't edit the past.75bool _is_read_only() { return true; }76static void _bind_methods();77};7879class GameStateSnapshot : public Object {80GDCLASS(GameStateSnapshot, Object);8182void _get_outbound_references(Variant &p_var, HashMap<String, ObjectID> &r_ret_val, const String &p_current_path = "");83void _get_rc_cycles(SnapshotDataObject *p_obj, SnapshotDataObject *p_source_obj, HashSet<SnapshotDataObject *> p_traversed_objs, LocalVector<String> &r_ret_val, const String &p_current_path = "");8485public:86String name;87HashMap<ObjectID, SnapshotDataObject *> objects;88Dictionary snapshot_context;8990// Ideally, this would extend EditorDebuggerRemoteObject and be refcounted, but we can't have it both ways.91// So, instead we have this static 'constructor' that returns a RefCounted wrapper around a GameStateSnapshot.92static Ref<GameStateSnapshotRef> create_ref(const String &p_snapshot_name, const Vector<uint8_t> &p_snapshot_buffer);93~GameStateSnapshot();9495void recompute_references();96};9798// Thin RefCounted wrapper around a GameStateSnapshot.99class GameStateSnapshotRef : public RefCounted {100GDCLASS(GameStateSnapshotRef, RefCounted);101102GameStateSnapshot *gamestate_snapshot = nullptr;103104public:105GameStateSnapshotRef(GameStateSnapshot *p_gss) :106gamestate_snapshot(p_gss) {}107108bool unreference();109GameStateSnapshot *get_snapshot();110};111112113