Started work on new undo system

This commit is contained in:
Yousef Khadadeh 2026-01-02 17:11:32 +03:00
parent da3a764ae9
commit be2ba1e285
8 changed files with 182 additions and 4 deletions

View file

@ -43,6 +43,12 @@ namespace NetworkingObjects {
bool NetObjManager::is_connected() const {
return (server && !server->is_disconnected()) || (client && !client->is_disconnected());
}
void NetObjManager::set_netid_reassign_callback(const std::function<void(const NetworkingObjects::NetObjID& oldID, const NetworkingObjects::NetObjID& newID)>& newNetIDReassignCallback) {
netIDReassignCallback = newNetIDReassignCallback;
}
void NetObjManager::set_netobj_destroy_callback(const std::function<void(const NetworkingObjects::NetObjID& netID)>& newDestroyCallback) {
destroyCallback = newDestroyCallback;
}
void NetObjManager::send_multi_update_messsage(std::function<void()> captureSendBlock, SendUpdateType updateType, const std::shared_ptr<NetServer::ClientData>& specificClient) {
if(is_connected()) {
std::shared_ptr<MultiUpdateData> d = std::make_shared<MultiUpdateData>();

View file

@ -27,6 +27,8 @@ namespace NetworkingObjects {
void disconnect();
bool is_server() const;
bool is_connected() const;
void set_netid_reassign_callback(const std::function<void(const NetworkingObjects::NetObjID& oldID, const NetworkingObjects::NetObjID& newID)>& newNetIDReassignCallback);
void set_netobj_destroy_callback(const std::function<void(const NetworkingObjects::NetObjID& netID)>& newDestroyCallback);
template <typename T> NetObjOwnerPtr<T> read_create_message(cereal::PortableBinaryInputArchive& a, const std::shared_ptr<NetServer::ClientData>& clientReceivedFrom) {
NetObjID id;
a(id);
@ -173,5 +175,7 @@ namespace NetworkingObjects {
std::unordered_map<NetObjID, SingleObjectData> objectData;
NetObjManagerTypeList typeList;
NetTypeIDType nextTypeID;
std::function<void(const NetworkingObjects::NetObjID& oldID, const NetworkingObjects::NetObjID& newID)> netIDReassignCallback;
std::function<void(const NetworkingObjects::NetObjID& netID)> destroyCallback;
};
}

View file

@ -34,6 +34,8 @@ namespace NetworkingObjects {
template <typename T> NetObjOwnerPtr<T>::~NetObjOwnerPtr() {
if(objMan && rawPtr) {
if(objMan->destroyCallback)
objMan->destroyCallback(id);
auto it = objMan->objectData.find(id);
delete static_cast<T*>(it->second.p);
objMan->objectData.erase(it);
@ -49,10 +51,13 @@ namespace NetworkingObjects {
NetObjManager::SingleObjectData objData = it->second;
objData.p = rawPtr;
objMan->objectData.erase(it);
NetworkingObjects::NetObjID oldID = id;
id = NetObjID::random_gen();
objMan->objectData.emplace(id, objData);
if constexpr(hasReassignNetObjIds)
rawPtr->reassign_netobj_ids_call();
if(objMan->netIDReassignCallback)
objMan->netIDReassignCallback(oldID, id);
}
}