Path: blob/master/modules/multiplayer/multiplayer_synchronizer.h
10277 views
/**************************************************************************/1/* multiplayer_synchronizer.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 "scene_replication_config.h"3334#include "scene/main/node.h"3536class MultiplayerSynchronizer : public Node {37GDCLASS(MultiplayerSynchronizer, Node);3839public:40enum VisibilityUpdateMode {41VISIBILITY_PROCESS_IDLE,42VISIBILITY_PROCESS_PHYSICS,43VISIBILITY_PROCESS_NONE,44};4546private:47struct Watcher {48NodePath prop;49uint64_t last_change_usec = 0;50Variant value;51};5253Ref<SceneReplicationConfig> replication_config;54NodePath root_path = NodePath(".."); // Start with parent, like with AnimationPlayer.55uint64_t sync_interval_usec = 0;56uint64_t delta_interval_usec = 0;57VisibilityUpdateMode visibility_update_mode = VISIBILITY_PROCESS_IDLE;58HashSet<Callable> visibility_filters;59HashSet<int> peer_visibility;60Vector<Watcher> watchers;61uint64_t last_watch_usec = 0;6263ObjectID root_node_cache;64uint64_t last_sync_usec = 0;65uint16_t last_inbound_sync = 0;66uint32_t net_id = 0;67bool sync_started = false;6869static Object *_get_prop_target(Object *p_obj, const NodePath &p_prop);70void _start();71void _stop();72void _update_process();73Error _watch_changes(uint64_t p_usec);7475protected:76static void _bind_methods();77void _notification(int p_what);7879public:80static Error get_state(const List<NodePath> &p_properties, Object *p_obj, Vector<Variant> &r_variant, Vector<const Variant *> &r_variant_ptrs);81static Error set_state(const List<NodePath> &p_properties, Object *p_obj, const Vector<Variant> &p_state);8283void reset();84Node *get_root_node();8586uint32_t get_net_id() const;87void set_net_id(uint32_t p_net_id);8889bool update_outbound_sync_time(uint64_t p_usec);90bool update_inbound_sync_time(uint16_t p_network_time);9192PackedStringArray get_configuration_warnings() const override;9394void set_replication_interval(double p_interval);95double get_replication_interval() const;9697void set_delta_interval(double p_interval);98double get_delta_interval() const;99100void set_replication_config(Ref<SceneReplicationConfig> p_config);101Ref<SceneReplicationConfig> get_replication_config();102103void set_root_path(const NodePath &p_path);104NodePath get_root_path() const;105virtual void set_multiplayer_authority(int p_peer_id, bool p_recursive = true) override;106107bool is_visibility_public() const;108void set_visibility_public(bool p_public);109bool is_visible_to(int p_peer);110void set_visibility_for(int p_peer, bool p_visible);111bool get_visibility_for(int p_peer) const;112void update_visibility(int p_for_peer);113void set_visibility_update_mode(VisibilityUpdateMode p_mode);114void add_visibility_filter(Callable p_callback);115void remove_visibility_filter(Callable p_callback);116VisibilityUpdateMode get_visibility_update_mode() const;117118List<Variant> get_delta_state(uint64_t p_cur_usec, uint64_t p_last_usec, uint64_t &r_indexes);119List<NodePath> get_delta_properties(uint64_t p_indexes);120SceneReplicationConfig *get_replication_config_ptr() const;121122MultiplayerSynchronizer();123};124125VARIANT_ENUM_CAST(MultiplayerSynchronizer::VisibilityUpdateMode);126127128