snapshot_data.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #pragma once
  31. #include "editor/debugger/editor_debugger_inspector.h"
  32. class GameStateSnapshot;
  33. class SnapshotDataObject : public Object {
  34. GDCLASS(SnapshotDataObject, Object);
  35. HashSet<ObjectID> _unique_references(const HashMap<String, ObjectID> &p_refs);
  36. String _get_script_name(Ref<Script> p_script);
  37. public:
  38. GameStateSnapshot *snapshot = nullptr;
  39. Dictionary extra_debug_data;
  40. HashMap<String, ObjectID> outbound_references;
  41. HashMap<String, ObjectID> inbound_references;
  42. HashSet<ObjectID> get_unique_outbound_refernces();
  43. HashSet<ObjectID> get_unique_inbound_references();
  44. uint64_t remote_object_id = 0;
  45. String type_name;
  46. LocalVector<PropertyInfo> prop_list;
  47. HashMap<StringName, Variant> prop_values;
  48. bool _get(const StringName &p_name, Variant &r_ret) const;
  49. void _get_property_list(List<PropertyInfo> *p_list) const;
  50. struct ResourceCache {
  51. HashMap<String, Ref<Resource>> cache;
  52. int misses = 0;
  53. int hits = 0;
  54. };
  55. SnapshotDataObject(SceneDebuggerObject &p_obj, GameStateSnapshot *p_snapshot, ResourceCache &resource_cache);
  56. String get_name();
  57. String get_node_path();
  58. bool is_refcounted();
  59. bool is_node();
  60. bool is_class(const String &p_base_class);
  61. protected:
  62. // Snapshots are inherently read-only. Can't edit the past.
  63. bool _is_read_only() { return true; }
  64. static void _bind_methods();
  65. };
  66. class GameStateSnapshot : public RefCounted {
  67. GDCLASS(GameStateSnapshot, RefCounted);
  68. void _get_outbound_references(Variant &p_var, HashMap<String, ObjectID> &r_ret_val, const String &p_current_path = "");
  69. 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 = "");
  70. public:
  71. String name;
  72. HashMap<ObjectID, SnapshotDataObject *> objects;
  73. Dictionary snapshot_context;
  74. static Ref<GameStateSnapshot> create_ref(const String &p_snapshot_name, const Vector<uint8_t> &p_snapshot_buffer);
  75. ~GameStateSnapshot();
  76. void recompute_references();
  77. };