NetworkIDManager.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. ///
  12. #ifndef __NETWORK_ID_MANAGER_H
  13. #define __NETWORK_ID_MANAGER_H
  14. #include "RakNetTypes.h"
  15. #include "Export.h"
  16. #include "RakMemoryOverride.h"
  17. #include "NetworkIDObject.h"
  18. #include "Rand.h"
  19. namespace RakNet
  20. {
  21. /// Increase this value if you plan to have many persistent objects
  22. /// This value must match on all systems
  23. #define NETWORK_ID_MANAGER_HASH_LENGTH 1024
  24. /// This class is simply used to generate a unique number for a group of instances of NetworkIDObject
  25. /// An instance of this class is required to use the ObjectID to pointer lookup system
  26. /// You should have one instance of this class per game instance.
  27. /// Call SetIsNetworkIDAuthority before using any functions of this class, or of NetworkIDObject
  28. class RAK_DLL_EXPORT NetworkIDManager
  29. {
  30. public:
  31. // GetInstance() and DestroyInstance(instance*)
  32. STATIC_FACTORY_DECLARATIONS(NetworkIDManager)
  33. NetworkIDManager();
  34. virtual ~NetworkIDManager(void);
  35. /// Returns the parent object, or this instance if you don't use a parent.
  36. /// Supports NetworkIDObject anywhere in the inheritance hierarchy
  37. /// \pre You must first call SetNetworkIDManager before using this function
  38. template <class returnType>
  39. returnType GET_OBJECT_FROM_ID(NetworkID x) {
  40. NetworkIDObject *nio = GET_BASE_OBJECT_FROM_ID(x);
  41. if (nio==0)
  42. return 0;
  43. if (nio->GetParent())
  44. return (returnType) nio->GetParent();
  45. return (returnType) nio;
  46. }
  47. // Stop tracking all NetworkID objects
  48. void Clear(void);
  49. /// \internal
  50. NetworkIDObject *GET_BASE_OBJECT_FROM_ID(NetworkID x);
  51. protected:
  52. /// \internal
  53. void TrackNetworkIDObject(NetworkIDObject *networkIdObject);
  54. void StopTrackingNetworkIDObject(NetworkIDObject *networkIdObject);
  55. friend class NetworkIDObject;
  56. NetworkIDObject *networkIdHash[NETWORK_ID_MANAGER_HASH_LENGTH];
  57. unsigned int NetworkIDToHashIndex(NetworkID networkId);
  58. uint64_t startingOffset;
  59. /// \internal
  60. NetworkID GetNewNetworkID(void);
  61. };
  62. } // namespace RakNet
  63. #endif
粤ICP备19079148号