nodeListManager.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _NODELISTMANAGER_H_
  23. #define _NODELISTMANAGER_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. #ifndef _MPOINT3_H_
  28. #include "math/mPoint3.h"
  29. #endif
  30. #ifndef _MQUAT_H_
  31. #include "math/mQuat.h"
  32. #endif
  33. #ifndef _NETCONNECTION_H_
  34. #include "sim/netConnection.h"
  35. #endif
  36. //-----------------------------------------------------------------------------
  37. class NodeListNotify;
  38. class NodeListManager
  39. {
  40. public:
  41. struct NodeList
  42. {
  43. U32 mId;
  44. U32 mTotalValidNodes;
  45. bool mListComplete;
  46. NodeList() { mId = 0; mTotalValidNodes = 0; mListComplete = false; }
  47. virtual ~NodeList() { }
  48. };
  49. static U32 smMaximumNodesPerEvent;
  50. protected:
  51. bool mIsServer;
  52. U32 mNextListId;
  53. Vector<NodeList*> mNodeLists;
  54. Vector<NodeListNotify*> mNotifyList;
  55. public:
  56. NodeListManager( const bool isServer );
  57. ~NodeListManager();
  58. void clearNodeLists();
  59. U32 nextListId();
  60. void addNodeList( NodeList* list );
  61. bool findListById( U32 id, NodeList** list, bool completeOnly=true );
  62. void clearNotification( U32 listId );
  63. void clearAllNotifications();
  64. void registerNotification( NodeListNotify* notify );
  65. bool dispatchNotification( U32 listId );
  66. bool dispatchNotification( NodeList* list );
  67. };
  68. extern NodeListManager* gClientNodeListManager;
  69. extern NodeListManager* gServerNodeListManager;
  70. //-----------------------------------------------------------------------------
  71. class NodeListNotify
  72. {
  73. protected:
  74. U32 mListId;
  75. public:
  76. NodeListNotify() { mListId = 0; }
  77. virtual ~NodeListNotify() { }
  78. U32 getListId() { return mListId; }
  79. virtual void sendNotification( NodeListManager::NodeList* list ) { }
  80. };
  81. //-----------------------------------------------------------------------------
  82. class NodeListEvent : public NetEvent
  83. {
  84. typedef NetEvent Parent;
  85. public:
  86. U32 mId;
  87. U32 mTotalNodes;
  88. U32 mLocalListStart;
  89. NodeListManager::NodeList* mNodeList;
  90. public:
  91. NodeListEvent() { mId = 0; mNodeList = NULL; mTotalNodes = mLocalListStart = 0; }
  92. virtual ~NodeListEvent();
  93. virtual void pack(NetConnection*, BitStream*);
  94. virtual void write(NetConnection*, BitStream*);
  95. virtual void unpack(NetConnection*, BitStream*);
  96. virtual void process(NetConnection*);
  97. virtual void mergeLists(NodeListManager::NodeList* oldList);
  98. virtual void copyIntoList(NodeListManager::NodeList* copyInto) { }
  99. virtual void padListToSize() { }
  100. DECLARE_CONOBJECT(NodeListEvent);
  101. };
  102. #endif // _NODELISTMANAGER_H_