1 | /**************************************************************************/ |
2 | /* scene_cache_interface.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 | #ifndef SCENE_CACHE_INTERFACE_H |
32 | #define SCENE_CACHE_INTERFACE_H |
33 | |
34 | #include "scene/main/multiplayer_api.h" |
35 | |
36 | class Node; |
37 | class SceneMultiplayer; |
38 | |
39 | class SceneCacheInterface : public RefCounted { |
40 | GDCLASS(SceneCacheInterface, RefCounted); |
41 | |
42 | private: |
43 | SceneMultiplayer *multiplayer = nullptr; |
44 | |
45 | //path sent caches |
46 | struct PathSentCache { |
47 | HashMap<int, bool> confirmed_peers; |
48 | int id; |
49 | }; |
50 | |
51 | //path get caches |
52 | struct PathGetCache { |
53 | struct NodeInfo { |
54 | NodePath path; |
55 | ObjectID instance; |
56 | }; |
57 | |
58 | HashMap<int, NodeInfo> nodes; |
59 | }; |
60 | |
61 | HashMap<NodePath, PathSentCache> path_send_cache; |
62 | HashMap<int, PathGetCache> path_get_cache; |
63 | int last_send_cache_id = 1; |
64 | |
65 | protected: |
66 | Error _send_confirm_path(Node *p_node, NodePath p_path, PathSentCache *psc, const List<int> &p_peers); |
67 | |
68 | public: |
69 | void clear(); |
70 | void on_peer_change(int p_id, bool p_connected); |
71 | void process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len); |
72 | void process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len); |
73 | |
74 | // Returns true if all peers have cached path. |
75 | bool send_object_cache(Object *p_obj, int p_target, int &p_id); |
76 | int make_object_cache(Object *p_obj); |
77 | Object *get_cached_object(int p_from, uint32_t p_cache_id); |
78 | bool is_cache_confirmed(NodePath p_path, int p_peer); |
79 | |
80 | SceneCacheInterface(SceneMultiplayer *p_multiplayer) { multiplayer = p_multiplayer; } |
81 | }; |
82 | |
83 | #endif // SCENE_CACHE_INTERFACE_H |
84 | |