Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/objectdb_profiler/editor/snapshot_data.h
11323 views
1
/**************************************************************************/
2
/* snapshot_data.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "editor/debugger/editor_debugger_inspector.h"
34
35
class GameStateSnapshot;
36
class GameStateSnapshotRef;
37
38
class SnapshotDataObject : public Object {
39
GDCLASS(SnapshotDataObject, Object);
40
41
HashSet<ObjectID> _unique_references(const HashMap<String, ObjectID> &p_refs);
42
String _get_script_name(Ref<Script> p_script);
43
44
public:
45
GameStateSnapshot *snapshot = nullptr;
46
Dictionary extra_debug_data;
47
HashMap<String, ObjectID> outbound_references;
48
HashMap<String, ObjectID> inbound_references;
49
50
HashSet<ObjectID> get_unique_outbound_refernces();
51
HashSet<ObjectID> get_unique_inbound_references();
52
53
uint64_t remote_object_id = 0;
54
String type_name;
55
LocalVector<PropertyInfo> prop_list;
56
HashMap<StringName, Variant> prop_values;
57
bool _get(const StringName &p_name, Variant &r_ret) const;
58
void _get_property_list(List<PropertyInfo> *p_list) const;
59
60
struct ResourceCache {
61
HashMap<String, Ref<Resource>> cache;
62
int misses = 0;
63
int hits = 0;
64
};
65
66
SnapshotDataObject(SceneDebuggerObject &p_obj, GameStateSnapshot *p_snapshot, ResourceCache &resource_cache);
67
68
String get_name();
69
String get_node_path();
70
bool is_refcounted();
71
bool is_node();
72
bool is_class(const String &p_base_class);
73
74
protected:
75
// Snapshots are inherently read-only. Can't edit the past.
76
bool _is_read_only() { return true; }
77
static void _bind_methods();
78
};
79
80
class GameStateSnapshot : public Object {
81
GDCLASS(GameStateSnapshot, Object);
82
83
void _get_outbound_references(Variant &p_var, HashMap<String, ObjectID> &r_ret_val, const String &p_current_path = "");
84
void _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 = "");
85
86
public:
87
String name;
88
HashMap<ObjectID, SnapshotDataObject *> objects;
89
Dictionary snapshot_context;
90
91
// Ideally, this would extend EditorDebuggerRemoteObject and be refcounted, but we can't have it both ways.
92
// So, instead we have this static 'constructor' that returns a RefCounted wrapper around a GameStateSnapshot.
93
static Ref<GameStateSnapshotRef> create_ref(const String &p_snapshot_name, const Vector<uint8_t> &p_snapshot_buffer);
94
~GameStateSnapshot();
95
96
void recompute_references();
97
};
98
99
// Thin RefCounted wrapper around a GameStateSnapshot.
100
class GameStateSnapshotRef : public RefCounted {
101
GDCLASS(GameStateSnapshotRef, RefCounted);
102
103
GameStateSnapshot *gamestate_snapshot = nullptr;
104
105
public:
106
GameStateSnapshotRef(GameStateSnapshot *p_gss) :
107
gamestate_snapshot(p_gss) {}
108
109
bool unreference();
110
GameStateSnapshot *get_snapshot();
111
};
112
113