Added more tests to ordered list, and fixed bug when inserting at end of list as client
This commit is contained in:
parent
06079f80cd
commit
df7ec9cb99
3 changed files with 63 additions and 27 deletions
|
|
@ -15,8 +15,10 @@
|
|||
|
||||
#ifdef ENABLE_NETOBJ_ORDERED_LIST_VERBOSE_DEBUG
|
||||
#define NETOBJ_ORDERED_LIST_VERBOSE_DEBUG(data, idMap) netobj_ordered_list_debug_check(data, idMap)
|
||||
#define NETOBJ_CHECK_INSERT_ORDERED(data, newObjs) netobj_check_insert_is_ordered(data, newObjs)
|
||||
#else
|
||||
#define NETOBJ_ORDERED_LIST_VERBOSE_DEBUG(data, idMap)
|
||||
#define NETOBJ_CHECK_INSERT_ORDERED(data, newObjs)
|
||||
#endif
|
||||
|
||||
namespace NetworkingObjects {
|
||||
|
|
@ -78,6 +80,28 @@ namespace NetworkingObjects {
|
|||
}
|
||||
std::cout << "[netobj_ordered_list_debug_check] Debug print end" << std::endl;
|
||||
}
|
||||
|
||||
template <typename T> void netobj_check_insert_is_ordered(const std::list<NetObjOrderedListObjectInfo<T>>& l, std::vector<std::pair<NetObjOrderedListIterator<T>, NetObjOwnerPtr<T>>>& newObjs) {
|
||||
std::cout << "[netobj_check_insert_is_ordered] Insert list order check" << std::endl;
|
||||
uint32_t lastPos = 0;
|
||||
bool isEnd = false;
|
||||
for(auto& [it, obj] : newObjs) {
|
||||
if(it == l.end()) {
|
||||
std::cout << "[netobj_check_insert_is_ordered] Insert at: " << l.size() << " (end)" << std::endl;
|
||||
isEnd = true;
|
||||
}
|
||||
else {
|
||||
std::cout << "[netobj_check_insert_is_ordered] Insert at: " << it->pos << std::endl;
|
||||
if(isEnd)
|
||||
throw std::runtime_error("[netobj_check_insert_is_ordered] Insert list not ordered! (Failure at end)");
|
||||
if(lastPos > it->pos)
|
||||
throw std::runtime_error("[netobj_check_insert_is_ordered] Insert list not ordered!");
|
||||
lastPos = it->pos;
|
||||
isEnd = false;
|
||||
}
|
||||
}
|
||||
std::cout << "[netobj_check_insert_is_ordered] Insert list is ordered" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T> void refresh_positions_complete(std::list<NetObjOrderedListObjectInfo<T>>& l) {
|
||||
|
|
@ -311,6 +335,8 @@ namespace NetworkingObjects {
|
|||
if(newObjs.empty())
|
||||
return {};
|
||||
|
||||
NETOBJ_CHECK_INSERT_ORDERED(data, newObjs);
|
||||
|
||||
std::vector<NetworkingObjects::NetObjID> idPositionList;
|
||||
for(auto& [itToInsertAt, newObj] : newObjs) {
|
||||
if(itToInsertAt == data.begin())
|
||||
|
|
@ -465,6 +491,8 @@ namespace NetworkingObjects {
|
|||
if(newObjs.empty())
|
||||
return {};
|
||||
|
||||
NETOBJ_CHECK_INSERT_ORDERED(clientData, newObjs);
|
||||
|
||||
std::vector<NetObjOrderedListIterator<T>> toRet;
|
||||
for(auto& [itToInsertAt, newObj] : newObjs) {
|
||||
auto newObjIt = clientData.emplace(itToInsertAt, std::move(newObj), itToInsertAt == clientData.end() ? clientData.size() : itToInsertAt->pos); // All position values will be wrong except the first one, which is all that matters
|
||||
|
|
@ -648,8 +676,11 @@ namespace NetworkingObjects {
|
|||
if(!elemData.foundInClient)
|
||||
continue;
|
||||
if(firstInsertedIt == clientData.end()) {
|
||||
firstInsertedActualPos = elemData.clientInsertPosIt->pos;
|
||||
firstInsertedIt = elemData.clientObjectIt;
|
||||
if(elemData.clientInsertPosIt != clientData.end())
|
||||
firstInsertedActualPos = elemData.clientInsertPosIt->pos;
|
||||
else
|
||||
firstInsertedActualPos = clientData.size();
|
||||
}
|
||||
clientData.splice(elemData.clientInsertPosIt, referredToObjectData, elemData.clientObjectIt);
|
||||
clientIdToDataMap.emplace(elemData.clientObjectIt->obj.get_net_id(), elemData.clientObjectIt);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue