multiplayer_synchronizer.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************/
  2. /* multiplayer_synchronizer.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef MULTIPLAYER_SYNCHRONIZER_H
  31. #define MULTIPLAYER_SYNCHRONIZER_H
  32. #include "scene/main/node.h"
  33. #include "scene_replication_config.h"
  34. class MultiplayerSynchronizer : public Node {
  35. GDCLASS(MultiplayerSynchronizer, Node);
  36. public:
  37. enum VisibilityUpdateMode {
  38. VISIBILITY_PROCESS_IDLE,
  39. VISIBILITY_PROCESS_PHYSICS,
  40. VISIBILITY_PROCESS_NONE,
  41. };
  42. private:
  43. Ref<SceneReplicationConfig> replication_config;
  44. NodePath root_path = NodePath(".."); // Start with parent, like with AnimationPlayer.
  45. uint64_t interval_msec = 0;
  46. VisibilityUpdateMode visibility_update_mode = VISIBILITY_PROCESS_IDLE;
  47. HashSet<Callable> visibility_filters;
  48. HashSet<int> peer_visibility;
  49. static Object *_get_prop_target(Object *p_obj, const NodePath &p_prop);
  50. void _start();
  51. void _stop();
  52. void _update_process();
  53. protected:
  54. static void _bind_methods();
  55. void _notification(int p_what);
  56. public:
  57. static Error get_state(const List<NodePath> &p_properties, Object *p_obj, Vector<Variant> &r_variant, Vector<const Variant *> &r_variant_ptrs);
  58. static Error set_state(const List<NodePath> &p_properties, Object *p_obj, const Vector<Variant> &p_state);
  59. void set_replication_interval(double p_interval);
  60. double get_replication_interval() const;
  61. uint64_t get_replication_interval_msec() const;
  62. void set_replication_config(Ref<SceneReplicationConfig> p_config);
  63. Ref<SceneReplicationConfig> get_replication_config();
  64. void set_root_path(const NodePath &p_path);
  65. NodePath get_root_path() const;
  66. virtual void set_multiplayer_authority(int p_peer_id, bool p_recursive = true) override;
  67. bool is_visibility_public() const;
  68. void set_visibility_public(bool p_public);
  69. bool is_visible_to(int p_peer);
  70. void set_visibility_for(int p_peer, bool p_visible);
  71. bool get_visibility_for(int p_peer) const;
  72. void update_visibility(int p_for_peer);
  73. void set_visibility_update_mode(VisibilityUpdateMode p_mode);
  74. void add_visibility_filter(Callable p_callback);
  75. void remove_visibility_filter(Callable p_callback);
  76. VisibilityUpdateMode get_visibility_update_mode() const;
  77. MultiplayerSynchronizer();
  78. };
  79. VARIANT_ENUM_CAST(MultiplayerSynchronizer::VisibilityUpdateMode);
  80. #endif // MULTIPLAYER_SYNCHRONIZER_H