17 #if _RAKNET_SUPPORT_ReplicaManager3==1
25 using namespace SLNet;
95 for (
unsigned int i=0; i < 255; i++)
144 for (
unsigned int index=0; index < participantListIn.
Size(); index++)
162 if (newConnection==0)
173 if (index==(
unsigned int)-1)
183 unsigned int pushIdx;
184 for (pushIdx=0; pushIdx < world->userReplicaList.Size(); pushIdx++)
214 connection=world->connectionList[index];
226 for (index2=0; index2 < replicaList.
Size(); index2++)
228 action = replicaList[index2]->QueryActionOnPopConnection(connection);
229 replicaList[index2]->OnPoppedConnection(connection);
258 for (index2=0; index2 < destructionList.
Size(); index2++)
262 if (replicaToDestroy)
269 world->connectionList.RemoveAtIndex(index);
282 for (index=0; index < world->connectionList.Size(); index++)
284 if (world->connectionList[index]->GetRakNetGUID()==guid)
301 if (index!=(
unsigned int)-1)
303 unsigned int pushIdx;
304 for (pushIdx=0; pushIdx < world->connectionList.Size(); pushIdx++)
309 world->connectionList[pushIdx]->OnLocalReference(replica3,
this);
324 if (index==(
unsigned int)-1)
337 return world->userReplicaList.Size()-1;
339 return (
unsigned int) -1;
349 unsigned int index, index2;
350 for (index=0; index < world->userReplicaList.Size(); index++)
352 if (world->userReplicaList[index]==replica3)
360 for (index2=0; index2 < world->connectionList.Size(); index2++)
362 world->connectionList[index2]->OnDereference(replica3,
this);
371 for (index=0; index < replicaListIn.
Size(); index++)
391 replicaListOut=world->userReplicaList;
402 for (index=0; index < world->userReplicaList.Size(); index++)
404 if (world->userReplicaList[index]->creatingSystemGUID==guid)
458 for (index=0; index < world->connectionList.Size(); index++)
460 if (world->connectionList[index]->GetSystemAddress()==sa)
476 for (index=0; index < world->connectionList.Size(); index++)
478 if (world->connectionList[index]->GetRakNetGUID()==guid)
523 for (index=0; index < world->connectionList.Size(); index++)
525 if (world->connectionList[index]->HasReplicaConstructed(replica))
526 connectionsThatHaveConstructedThisReplica.
Push(world->connectionList[index],
_FILE_AND_LINE_);
538 for (index=0; index < world->connectionList.Size(); index++)
540 if (world->connectionList[index]->GetDownloadWasCompleted()==
false)
576 for (
unsigned int i=0; i < connectionList.Size(); i++)
582 for (
unsigned int i=0; i < connectionList.Size(); i++)
586 for (
unsigned int i=0; i < userReplicaList.Size(); i++)
588 userReplicaList[i]->replicaManager=0;
589 userReplicaList[i]->SetNetworkIDManager(0);
609 newWorld->worldId=worldId;
662 unsigned char packetIdentifier, packetDataOffset;
667 packetIdentifier = (
unsigned char ) packet->
data[
sizeof(
unsigned char ) +
sizeof(
SLNet::Time ) ];
670 tsBs.Read(timestamp);
673 incomingWorldId=packet->
data[
sizeof(
unsigned char )*2 +
sizeof(
SLNet::Time )];
674 packetDataOffset=
sizeof(
unsigned char )*3 +
sizeof(
SLNet::Time );
681 packetIdentifier = (
unsigned char ) packet->
data[ 0 ];
684 incomingWorldId=packet->
data[
sizeof(
unsigned char )];
685 packetDataOffset=
sizeof(
unsigned char )*2;
691 switch (packetIdentifier)
731 ValidateLists(replicaManager3);
733 ConstructionMode curConstructionMode = QueryConstructionMode();
743 if (curConstructionMode==QUERY_REPLICA_FOR_CONSTRUCTION || curConstructionMode==QUERY_REPLICA_FOR_CONSTRUCTION_AND_DESTRUCTION)
745 while (index < queryToConstructReplicaList.Size())
747 lsr=queryToConstructReplicaList[index];
751 OnReplicaAlreadyExists(index, replicaManager3);
805 OnConstructToThisConnection(index, replicaManager3);
811 OnNeverConstruct(index, replicaManager3);
820 if (curConstructionMode==QUERY_REPLICA_FOR_CONSTRUCTION_AND_DESTRUCTION)
824 while (index < queryToDestructReplicaList.Size())
826 lsr=queryToDestructReplicaList[index];
830 OnSendDestructionFromQuery(index, replicaManager3);
835 OnDoNotQueryDestruction(index, replicaManager3);
845 else if (curConstructionMode==QUERY_CONNECTION_FOR_REPLICA_LIST)
847 QueryReplicaList(constructedReplicasCulled,destroyedReplicasCulled);
849 unsigned int idx1, idx2;
852 for (idx2=0; idx2 < constructedReplicasCulled.Size(); idx2++)
853 OnConstructToThisConnection(constructedReplicasCulled[idx2], replicaManager3);
856 for (idx2=0; idx2 < destroyedReplicasCulled.Size(); idx2++)
860 idx1=constructedReplicaList.GetIndexFromKey(destroyedReplicasCulled[idx2], &objectExists);
863 constructedReplicaList.RemoveAtIndex(idx1);
866 for (j=0; j < queryToSerializeReplicaList.Size(); j++)
868 if (queryToSerializeReplicaList[j]->replica==destroyedReplicasCulled[idx2] )
870 queryToSerializeReplicaList.RemoveAtIndex(j);
882 unsigned int index,index2,index3;
891 worldId = world->worldId;
893 for (index=0; index < world->connectionList.Size(); index++)
895 if (world->connectionList[index]->isValidated==
false)
897 world->connectionList[index]->AutoConstructByQuery(
this, worldId);
906 worldId = world->worldId;
908 for (index=0; index < world->userReplicaList.Size(); index++)
910 world->userReplicaList[index]->forceSendUntilNextUpdate=
false;
911 world->userReplicaList[index]->OnUserReplicaPreSerializeTick();
924 for (index=0; index < world->connectionList.Size(); index++)
926 connection = world->connectionList[index];
937 while (index2 < connection->queryToSerializeReplicaList.Size())
946 while (index2 < replicasToSerialize.
Size())
948 lsr=replicasToSerialize[index2]->lsr;
960 while (index2 < connection->queryToSerializeReplicaList.Size())
991 (void) lostConnectionReason;
992 (void) systemAddress;
1021 unsigned int index3;
1026 while (world->connectionList.Size())
1056 RakAssert(
"Got OnConstruction but no connection yet" && 0);
1066 bsIn.IgnoreBytes(packetDataOffset);
1067 uint16_t constructionObjectListSize, destructionObjectListSize, index, index2;
1068 BitSize_t streamEnd, writeAllocationIDEnd;
1072 bool actuallyCreateObject=
false;
1079 bsIn.Read(constructionObjectListSize);
1080 for (index=0; index < constructionObjectListSize; index++)
1082 bsIn.Read(streamEnd);
1083 bsIn.Read(networkId);
1085 bsIn.Read(actuallyCreateObject);
1087 bsIn.AlignReadToByteBoundary();
1089 if (actuallyCreateObject)
1091 bsIn.Read(creatingSystemGuid);
1092 bsIn.Read(writeAllocationIDEnd);
1095 if (existingReplica)
1103 bsIn.SetReadOffset(streamEnd);
1107 bsIn.AlignReadToByteBoundary();
1112 bsIn.SetReadOffset(streamEnd);
1118 bsIn.SetReadOffset(writeAllocationIDEnd);
1130 bsIn.SetReadOffset(streamEnd);
1142 if (existingReplica)
1154 bsIn.SetReadOffset(streamEnd);
1155 bsIn.AlignReadToByteBoundary();
1158 RakAssert(constructionTickStack.
Size()==constructionObjectListSize);
1159 RakAssert(actuallyCreateObjectList.
Size()==constructionObjectListSize);
1162 for (index=0; index < constructionObjectListSize; index++)
1164 bool pdcWritten=
false;
1165 bsIn.
Read(pdcWritten);
1168 bsIn.AlignReadToByteBoundary();
1169 bsIn.Read(streamEnd);
1170 bsIn.Read(networkId);
1171 if (constructionTickStack[index]!=0)
1173 bsIn.AlignReadToByteBoundary();
1174 if (actuallyCreateObjectList[index])
1175 constructionTickStack[index]->PostDeserializeConstruction(&bsIn, connection);
1177 constructionTickStack[index]->PostDeserializeConstructionExisting(&bsIn, connection);
1179 bsIn.SetReadOffset(streamEnd);
1183 if (constructionTickStack[index]!=0)
1185 if (actuallyCreateObjectList[index])
1186 constructionTickStack[index]->PostDeserializeConstruction(&empty, connection);
1188 constructionTickStack[index]->PostDeserializeConstructionExisting(&empty, connection);
1192 bsIn.AlignReadToByteBoundary();
1194 for (index=0; index < constructionObjectListSize; index++)
1196 if (constructionTickStack[index]!=0)
1198 if (actuallyCreateObjectList[index])
1203 for (index2=0; index2 < world->connectionList.Size(); index2++)
1205 if (world->connectionList[index2]!=connection)
1206 world->connectionList[index2]->OnDownloadFromOtherSystem(constructionTickStack[index],
this);
1213 bool b = bsIn.Read(destructionObjectListSize);
1216 for (index=0; index < destructionObjectListSize; index++)
1218 bsIn.Read(networkId);
1219 bsIn.Read(streamEnd);
1224 bsIn.SetReadOffset(streamEnd);
1231 if (world->networkIDManager->GET_OBJECT_FROM_ID<
Replica3*>(networkId))
1248 bsIn.AlignReadToByteBoundary();
1269 bsIn.IgnoreBytes(packetDataOffset);
1273 ds.sourceConnection=connection;
1278 bsIn.Read(networkId);
1285 bsIn.Read(ds.bitstreamWrittenTo[z]);
1286 if (ds.bitstreamWrittenTo[z])
1288 bsIn.ReadCompressed(bitsUsed);
1289 bsIn.AlignReadToByteBoundary();
1290 bsIn.Read(ds.serializationBitstream[z], bitsUsed);
1319 bsIn.IgnoreBytes(packetDataOffset);
1348 bsIn.IgnoreBytes(packetDataOffset);
1361 for (i=0; i < world->userReplicaList.Size(); i++)
1363 if (world->userReplicaList[i]->GetNetworkID()==networkId)
1383 for (i=0; i < replicaListSource.
Size(); i++)
1387 replicaList.
Push(replicaListSource[i], __FILE__, __LINE__);
1390 if (replicaList.
Size()==0)
1393 for (i=0; i < replicaList.
Size(); i++)
1399 for (j=0; j < world->connectionList.Size(); j++)
1401 if (world->connectionList[j]->GetSystemAddress()==exclusionAddress)
1406 bsOut.
Write(worldId);
1414 for (i=0; i < replicaList.
Size(); i++)
1416 if (world->connectionList[j]->HasReplicaConstructed(replicaList[i])==
false)
1421 networkId=replicaList[i]->GetNetworkID();
1422 bsOut.
Write(networkId);
1425 bsOut.
Write(offsetStart);
1426 bsOut.
Write(replicaList[i]->deletingSystemGUID);
1427 replicaList[i]->SerializeDestruction(&bsOut, world->connectionList[j]);
1431 bsOut.
Write(offsetEnd);
1462 : systemAddress(_systemAddress), guid(_guid)
1465 isFirstConstruction=
true;
1466 groupConstructionAndSerialize=
false;
1467 gotDownloadComplete=
false;
1498 return objectExists;
1509 bs->
Write(timestamp);
1526 bool channelHasData;
1530 if (indicesToSend[z])
1531 sum+=serializationData[z].GetNumberOfBitsUsed();
1539 memset(bitsPerChannel, 0,
sizeof(bitsPerChannel));
1549 PRO lastPro=sendParameters[0];
1553 if (channelIndex==0)
1557 else if (lastPro!=sendParameters[channelIndex])
1562 bitsPerChannel[channelIndex2]=0;
1574 if (serializationData[channelIndex2].GetNumberOfBitsUsed()>0)
1586 for (
int channelIndex2=0; channelIndex2 < channelIndex; channelIndex2++)
1588 bitsPerChannel[channelIndex2]=0;
1591 lastPro=sendParameters[channelIndex];
1594 bitsUsed=serializationData[channelIndex].GetNumberOfBitsUsed();
1595 channelHasData = indicesToSend[channelIndex]==
true && bitsUsed>0;
1596 out.
Write(channelHasData);
1599 bitsPerChannel[channelIndex] = bitsUsed;
1602 out.
Write(serializationData[channelIndex]);
1604 serializationData[channelIndex].ResetReadPointer();
1608 bitsPerChannel[channelIndex] = 0;
1725 indicesToSend[z]=
true;
1735 indicesToSend[z]=
false;
1752 indicesToSend[z]=
true;
1760 indicesToSend[z]=
false;
1779 (void) replicaManager;
1780 (void) curConstructionMode;
1787 RakAssert(
"replica added twice to queryToConstructReplicaList" && 0);
1793 RakAssert(
"replica added to queryToConstructReplicaList when already in constructedReplicaList" && 0);
1921 (void) curConstructionMode;
1936 (void) curConstructionMode;
1956 (void) replicaManager;
1989 (void) curConstructionMode;
2033 (void) curConstructionMode;
2073 (void) replicaManager;
2195 if (newObjects.
Size()==0 && deletedObjects.
Size()==0)
2201 BitSize_t offsetStart, offsetStart2, offsetEnd;
2202 unsigned int newListIndex, oldListIndex;
2208 bsOut.
Write(worldId);
2216 bsOut.
Write(worldId);
2218 bsOut.
Write(objectSize);
2221 for (newListIndex=0; newListIndex < newObjects.
Size(); newListIndex++)
2224 bsOut.
Write(offsetStart);
2225 networkId=newObjects[newListIndex]->GetNetworkID();
2226 bsOut.
Write(networkId);
2230 bsOut.
Write(actuallyCreateObject);
2233 if (actuallyCreateObject)
2236 bsOut.
Write(newObjects[newListIndex]->creatingSystemGUID);
2238 bsOut.
Write(offsetStart2);
2240 newObjects[newListIndex]->WriteAllocationID(
this, &bsOut);
2244 bsOut.
Write(offsetEnd);
2246 newObjects[newListIndex]->SerializeConstruction(&bsOut,
this);
2250 newObjects[newListIndex]->SerializeConstructionExisting(&bsOut,
this);
2256 bsOut.
Write(offsetEnd);
2261 for (newListIndex=0; newListIndex < newObjects.
Size(); newListIndex++)
2267 newObjects[newListIndex]->PostSerializeConstruction(&bsOut2,
this);
2272 newObjects[newListIndex]->PostSerializeConstructionExisting(&bsOut2,
this);
2279 bsOut.
Write(offsetStart);
2280 networkId=newObjects[newListIndex]->GetNetworkID();
2281 bsOut.
Write(networkId);
2283 bsOut.
Write(&bsOut2);
2287 bsOut.
Write(offsetEnd);
2297 bsOut.
Write(objectSize);
2298 for (oldListIndex=0; oldListIndex < deletedObjects.
Size(); oldListIndex++)
2300 networkId=deletedObjects[oldListIndex]->GetNetworkID();
2301 bsOut.
Write(networkId);
2303 bsOut.
Write(offsetStart);
2305 bsOut.
Write(deletedObjects[oldListIndex]->deletingSystemGUID);
2306 deletedObjects[oldListIndex]->SerializeDestruction(&bsOut,
this);
2310 bsOut.
Write(offsetEnd);
2326 sp.
pro[index]=sendParameters;
2332 for (newListIndex=0; newListIndex < newObjects.
Size(); newListIndex++)
2365 bsOut.
Write(worldId);
2381 bsOut.
Write(worldId);
2425 (void) destinationConnection;
2429 if (isThisTheServer)
2438 (void) sourceConnection;
2439 (void) isThisTheServer;
2449 (void) destinationConnection;
2451 if (isThisTheServer)
2460 (void) sourceConnection;
2461 if (isThisTheServer)
2470 (void) destinationConnection;
2506 (void) sourceConnection;
2529 (void) destinationConnection;
2531 if (isThisTheServer)
2542 (void) destinationConnection;
2576 (void) droppedConnection;
2584 (void) droppedConnection;
2592 (void) droppedConnection;
2598 #endif // _RAKNET_SUPPORT_*