portal_gameplay_monitor.h 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**************************************************************************/
  2. /* portal_gameplay_monitor.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 PORTAL_GAMEPLAY_MONITOR_H
  31. #define PORTAL_GAMEPLAY_MONITOR_H
  32. #include "core/local_vector.h"
  33. #include "servers/visual_server_callbacks.h"
  34. #include <stdint.h>
  35. class PortalRenderer;
  36. struct VSRoom;
  37. class PortalGameplayMonitor {
  38. public:
  39. PortalGameplayMonitor();
  40. void unload(PortalRenderer &p_portal_renderer);
  41. // entering and exiting gameplay notifications (requires PVS)
  42. void update_gameplay(PortalRenderer &p_portal_renderer, const int *p_source_room_ids, int p_num_source_rooms);
  43. void set_params(bool p_use_secondary_pvs, bool p_use_signals);
  44. private:
  45. void _update_gameplay_room(PortalRenderer &p_portal_renderer, int p_room_id, bool p_source_rooms_changed);
  46. bool _source_rooms_changed(const int *p_source_room_ids, int p_num_source_rooms);
  47. void _swap(bool p_source_rooms_changed);
  48. // gameplay ticks happen every physics tick
  49. uint32_t _gameplay_tick = 1;
  50. // Room ticks only happen when the rooms the cameras are within change.
  51. // This is an optimization. This tick needs to be maintained separately from _gameplay_tick
  52. // because testing against the previous tick is used to determine whether to send enter or exit
  53. // gameplay notifications, and this must be synchronized differently for rooms, roomgroups and static ghosts.
  54. uint32_t _room_tick = 1;
  55. // we need two version, current and previous
  56. LocalVector<uint32_t, int32_t> _active_moving_pool_ids[2];
  57. LocalVector<uint32_t, int32_t> *_active_moving_pool_ids_curr;
  58. LocalVector<uint32_t, int32_t> *_active_moving_pool_ids_prev;
  59. LocalVector<uint32_t, int32_t> _active_rghost_pool_ids[2];
  60. LocalVector<uint32_t, int32_t> *_active_rghost_pool_ids_curr;
  61. LocalVector<uint32_t, int32_t> *_active_rghost_pool_ids_prev;
  62. LocalVector<uint32_t, int32_t> _active_room_ids[2];
  63. LocalVector<uint32_t, int32_t> *_active_room_ids_curr;
  64. LocalVector<uint32_t, int32_t> *_active_room_ids_prev;
  65. LocalVector<uint32_t, int32_t> _active_roomgroup_ids[2];
  66. LocalVector<uint32_t, int32_t> *_active_roomgroup_ids_curr;
  67. LocalVector<uint32_t, int32_t> *_active_roomgroup_ids_prev;
  68. LocalVector<uint32_t, int32_t> _active_sghost_ids[2];
  69. LocalVector<uint32_t, int32_t> *_active_sghost_ids_curr;
  70. LocalVector<uint32_t, int32_t> *_active_sghost_ids_prev;
  71. LocalVector<uint32_t, int32_t> _source_rooms_prev;
  72. VisualServerCallbacks::CallbackType _enter_callback_type = VisualServerCallbacks::CALLBACK_NOTIFICATION_ENTER_GAMEPLAY;
  73. VisualServerCallbacks::CallbackType _exit_callback_type = VisualServerCallbacks::CALLBACK_NOTIFICATION_EXIT_GAMEPLAY;
  74. bool _use_secondary_pvs = false;
  75. bool _use_signals = false;
  76. };
  77. #endif // PORTAL_GAMEPLAY_MONITOR_H