-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: cleanup objectIdManager overloading and classes (#1391)
* objectIdManager fixes * Remove debug log
- Loading branch information
Showing
25 changed files
with
166 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "ObjectIDManager.h" | ||
|
||
// Custom Classes | ||
#include "MasterPackets.h" | ||
#include "Database.h" | ||
#include "Logger.h" | ||
#include "Game.h" | ||
|
||
//! The persistent ID request | ||
struct PersistentIDRequest { | ||
PersistentIDRequest(const uint64_t& requestID, const std::function<void(uint32_t)>& callback) : requestID(requestID), callback(callback) {} | ||
uint64_t requestID; | ||
|
||
std::function<void(uint32_t)> callback; | ||
}; | ||
|
||
namespace { | ||
std::vector<PersistentIDRequest> Requests; //!< All outstanding persistent ID requests | ||
uint64_t CurrentRequestID = 0; //!< The current request ID | ||
uint32_t CurrentObjectID = uint32_t(1152921508165007067); //!< The current object ID | ||
std::uniform_int_distribution<int> Uni(10000000, INT32_MAX); | ||
}; | ||
|
||
//! Requests a persistent ID | ||
void ObjectIDManager::RequestPersistentID(const std::function<void(uint32_t)> callback) { | ||
const auto& request = Requests.emplace_back(++CurrentRequestID, callback); | ||
|
||
MasterPackets::SendPersistentIDRequest(Game::server, request.requestID); | ||
} | ||
|
||
//! Handles a persistent ID response | ||
void ObjectIDManager::HandleRequestPersistentIDResponse(const uint64_t requestID, const uint32_t persistentID) { | ||
auto it = std::find_if(Requests.begin(), Requests.end(), [requestID](const PersistentIDRequest& request) { | ||
return request.requestID == requestID; | ||
}); | ||
|
||
if (it == Requests.end()) return; | ||
|
||
it->callback(persistentID); | ||
Requests.erase(it); | ||
} | ||
|
||
//! Handles cases where we have to get a unique object ID synchronously | ||
uint32_t ObjectIDManager::GenerateRandomObjectID() { | ||
return Uni(Game::randomEngine); | ||
} | ||
|
||
//! Generates an object ID server-sided (used for regular entities like smashables) | ||
uint32_t ObjectIDManager::GenerateObjectID() { | ||
return ++CurrentObjectID; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
// C++ | ||
#include <functional> | ||
#include <vector> | ||
#include <stdint.h> | ||
|
||
/*! | ||
\file ObjectIDManager.h | ||
\brief A manager for handling object ID generation | ||
*/ | ||
|
||
//! The Object ID Manager | ||
namespace ObjectIDManager { | ||
//! Requests a persistent ID | ||
/*! | ||
\param callback The callback function | ||
*/ | ||
void RequestPersistentID(const std::function<void(uint32_t)> callback); | ||
|
||
|
||
//! Handles a persistent ID response | ||
/*! | ||
\param requestID The request ID | ||
\param persistentID The persistent ID | ||
*/ | ||
void HandleRequestPersistentIDResponse(const uint64_t requestID, const uint32_t persistentID); | ||
|
||
//! Generates an object ID server-sided | ||
/*! | ||
\return A generated object ID | ||
*/ | ||
uint32_t GenerateObjectID(); | ||
|
||
//! Generates a random object ID server-sided | ||
/*! | ||
\return A generated object ID | ||
*/ | ||
uint32_t GenerateRandomObjectID(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
set(DMASTERSERVER_SOURCES | ||
"InstanceManager.cpp" | ||
"ObjectIDManager.cpp" | ||
"PersistentIDManager.cpp" | ||
"Start.cpp" | ||
) | ||
|
||
|
Oops, something went wrong.