DarkflameServer/dWorldServer/ObjectIDManager.h

76 lines
1.6 KiB
C
Raw Permalink Normal View History

#pragma once
// C++
#include <functional>
#include <vector>
#include <stdint.h>
/*!
\file ObjectIDManager.hpp
\brief A manager for handling object ID generation
*/
2022-07-28 13:39:57 +00:00
//! The persistent ID request
struct PersistentIDRequest {
2022-07-28 13:39:57 +00:00
uint64_t requestID;
2022-07-28 13:39:57 +00:00
std::function<void(uint32_t)> callback;
};
//! The Object ID Manager
class ObjectIDManager {
private:
2022-07-28 13:39:57 +00:00
static ObjectIDManager* m_Address; //!< The singleton instance
2022-07-28 13:39:57 +00:00
std::vector<PersistentIDRequest*> requests; //!< All outstanding persistent ID requests
uint64_t currentRequestID; //!< The current request ID
2022-07-28 13:39:57 +00:00
uint32_t currentObjectID; //!< The current object ID
public:
2022-07-28 13:39:57 +00:00
//! The singleton instance
static ObjectIDManager* Instance() {
if (m_Address == 0) {
m_Address = new ObjectIDManager;
}
2022-07-28 13:39:57 +00:00
return m_Address;
}
2022-07-28 13:39:57 +00:00
//! Initializes the manager
void Initialize(void);
2022-07-28 13:39:57 +00:00
//! Requests a persistent ID
/*!
\param callback The callback function
*/
void RequestPersistentID(std::function<void(uint32_t)> callback);
2022-07-28 13:39:57 +00:00
//! Handles a persistent ID response
/*!
\param requestID The request ID
\param persistentID The persistent ID
*/
void HandleRequestPersistentIDResponse(uint64_t requestID, uint32_t persistentID);
2022-07-28 13:39:57 +00:00
//! Generates an object ID server-sided
/*!
\return A generated object ID
*/
uint32_t GenerateObjectID(void);
//! Generates a random object ID server-sided
/*!
\return A generated object ID
*/
2022-07-28 13:39:57 +00:00
static uint32_t GenerateRandomObjectID();
2022-07-28 13:39:57 +00:00
//! Generates a persistent object ID server-sided
/*!
\return A generated object ID
*/
uint32_t GeneratePersistentObjectID(void);
};