scene_cache_interface.h 3.5 KB

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