Debian Codegraph @

modules/multiplayer/scene_replication_config.h

raw symbols SCIP
1 /**************************************************************************/
2 /* scene_replication_config.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 "core/io/resource.h"
34 #include "core/variant/typed_array.h"
35
36 class SceneReplicationConfig : public Resource {
37 GDCLASS(SceneReplicationConfig, Resource);
38 OBJ_SAVE_TYPE(SceneReplicationConfig);
39 RES_BASE_EXTENSION("repl");
40
41 public:
42 enum ReplicationMode {
43 REPLICATION_MODE_NEVER,
44 REPLICATION_MODE_ALWAYS,
45 REPLICATION_MODE_ON_CHANGE,
46 };
47
48 private:
49 struct ReplicationProperty {
50 NodePath name;
51 bool spawn = true;
52 ReplicationMode mode = REPLICATION_MODE_ALWAYS;
53
54 bool operator==(const ReplicationProperty &p_to) {
55 return name == p_to.name;
56 }
57
58 ReplicationProperty() {}
59
60 ReplicationProperty(const NodePath &p_name) {
61 name = p_name;
62 }
63 };
64
65 List<ReplicationProperty> properties;
66 List<NodePath> spawn_props;
67 List<NodePath> sync_props;
68 List<NodePath> watch_props;
69 bool dirty = false;
70
71 void _update();
72
73 protected:
74 static void _bind_methods();
75
76 bool _set(const StringName &p_name, const Variant &p_value);
77 bool _get(const StringName &p_name, Variant &r_ret) const;
78 void _get_property_list(List<PropertyInfo> *p_list) const;
79
80 public:
81 virtual void reset_state() override; // Required since we use variable amount of properties.
82
83 TypedArray<NodePath> get_properties() const;
84
85 void add_property(const NodePath &p_path, int p_index = -1);
86 void remove_property(const NodePath &p_path);
87 bool has_property(const NodePath &p_path) const;
88
89 int property_get_index(const NodePath &p_path) const;
90 bool property_get_spawn(const NodePath &p_path);
91 void property_set_spawn(const NodePath &p_path, bool p_enabled);
92
93 bool property_get_sync(const NodePath &p_path);
94 void property_set_sync(const NodePath &p_path, bool p_enabled);
95
96 bool property_get_watch(const NodePath &p_path);
97 void property_set_watch(const NodePath &p_path, bool p_enabled);
98
99 ReplicationMode property_get_replication_mode(const NodePath &p_path);
100 void property_set_replication_mode(const NodePath &p_path, ReplicationMode p_mode);
101
102 const List<NodePath> &get_spawn_properties();
103 const List<NodePath> &get_sync_properties();
104 const List<NodePath> &get_watch_properties();
105
106 SceneReplicationConfig() {}
107 };
108
109 VARIANT_ENUM_CAST(SceneReplicationConfig::ReplicationMode);