Stabilized and optimized library

This commit is contained in:
Albin Corén 2018-03-08 19:58:15 +01:00
parent 5426f4a421
commit 34031beee0
4 changed files with 25 additions and 16 deletions

View File

@ -266,12 +266,12 @@ namespace MLAPI
using (BinaryWriter writer = new BinaryWriter(stream))
{
//Write all indexes
writer.Write(dirtyFields.Length);
writer.Write((byte)dirtyFields.Length);
writer.Write(networkId); //NetId
writer.Write(networkedObject.GetOrderIndex(this)); //Behaviour OrderIndex
for (byte i = 0; i < dirtyFields.Length; i++)
{
writer.Write(networkId);
writer.Write(networkedObject.GetOrderIndex(this));
writer.Write(i); //Index
writer.Write(i); //FieldIndex
switch (syncedFieldTypes[i])
{
case FieldType.Bool:
@ -332,8 +332,8 @@ namespace MLAPI
break;
}
}
NetworkingManager.singleton.Send(clientId, "MLAPI_SYNC_VAR_UPDATE", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.ToArray());
}
NetworkingManager.singleton.Send(clientId, "MLAPI_SYNC_VAR_UPDATE", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.ToArray());
}
}
@ -353,14 +353,14 @@ namespace MLAPI
{
//Write all indexes
writer.Write(dirtyCount);
writer.Write(networkId); //NetId
writer.Write(networkedObject.GetOrderIndex(this)); //Behaviour OrderIndex
for (byte i = 0; i < dirtyFields.Length; i++)
{
//Writes all the indexes of the dirty syncvars.
if (dirtyFields[i] == true)
{
writer.Write(networkId);
writer.Write(networkedObject.GetOrderIndex(this));
writer.Write(i); //Index
writer.Write(i); //FieldIndex
switch (syncedFieldTypes[i])
{
case FieldType.Bool:
@ -425,8 +425,8 @@ namespace MLAPI
dirtyFields[i] = false;
}
}
NetworkingManager.singleton.Send("MLAPI_SYNC_VAR_UPDATE", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.ToArray(), ownerClientId);
}
NetworkingManager.singleton.Send("MLAPI_SYNC_VAR_UPDATE", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.ToArray());
}
lastSyncTime = Time.time;
}

View File

@ -86,8 +86,7 @@ namespace MLAPI
if(!childNetworkedBehaviours[i].networkedStartInvoked)
{
childNetworkedBehaviours[i].NetworkStart();
if (NetworkingManager.singleton.isServer)
childNetworkedBehaviours[i].SyncVarInit();
childNetworkedBehaviours[i].SyncVarInit();
}
}
}

View File

@ -451,6 +451,16 @@ namespace MLAPI
//Custom message, invoke all message handlers
if(targeted)
{
if(!MessageManager.targetedMessages.ContainsKey(messageType))
{
Debug.LogWarning("MLAPI: No handlers for the given messagetype");
return;
}
else if(!MessageManager.targetedMessages[messageType].ContainsKey(targetNetworkId))
{
Debug.LogWarning("MLAPI: No handlers for the given networkId");
return;
}
List<int> handlerIds = MessageManager.targetedMessages[messageType][targetNetworkId];
for (int i = 0; i < handlerIds.Count; i++)
{
@ -688,7 +698,7 @@ namespace MLAPI
}
}
break;
case 9:
case 9: //Syncvar
if (isClient)
{
using (MemoryStream messageReadStream = new MemoryStream(incommingData))
@ -696,12 +706,12 @@ namespace MLAPI
using (BinaryReader messageReader = new BinaryReader(messageReadStream))
{
byte dirtyCount = messageReader.ReadByte();
if(dirtyCount > 0)
uint netId = messageReader.ReadUInt32();
ushort orderIndex = messageReader.ReadUInt16();
if (dirtyCount > 0)
{
for (int i = 0; i < dirtyCount; i++)
{
uint netId = messageReader.ReadUInt32(); //NetId the syncvar is from
ushort orderIndex = messageReader.ReadUInt16();
byte fieldIndex = messageReader.ReadByte();
if(!SpawnManager.spawnedObjects.ContainsKey(netId))
{

View File

@ -81,7 +81,7 @@ namespace MLAPI.MonoBehaviours.Prototyping
writer.Write(transform.rotation.eulerAngles.z);
}
if (isServer)
SendToNonLocalClientsTarget("MLAPI_OnRecieveTransformFromClient", "MLAPI_POSITION_UPDATE", writeStream.GetBuffer());
SendToClientsTarget("MLAPI_OnRecieveTransformFromServer", "MLAPI_POSITION_UPDATE", writeStream.GetBuffer());
else
SendToServerTarget("MLAPI_OnRecieveTransformFromClient", "MLAPI_POSITION_UPDATE", writeStream.GetBuffer());
}