Skip to content

Commit

Permalink
Fixed previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Squaresweets authored Jul 14, 2021
1 parent 27ed35f commit ef7f35e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
32 changes: 22 additions & 10 deletions BubbleTransport/BubbleTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public MessageBuffer(ArraySegment<byte> data, int channelId, int connId)
bool connected = false;

bool needToDisconnectFlag = false;
//Check if it was the transport that started the game
static bool startFlag = false;

/* Structure of the transport
Expand Down Expand Up @@ -159,8 +161,20 @@ public override bool Available()

//~~~~~~~~~~ These two functions are all sorted out by game center, and these should not be called by anything other than the transport, if you want to start a game use FindMatch(); ~~~~~~~~~~

public override void ServerStart() { }
public override void ClientConnect(string address) { }
public override void ServerStart()
{
if (startFlag)
startFlag = false;
else
Debug.LogError("BubbleTransport | Don't call ServerStart() as matchmaking is random, call FindMatch() instead :D");
}
public override void ClientConnect(string address)
{
if (startFlag)
startFlag = false;
else
Debug.LogError("BubbleTransport | Don't call ClientConnect() as matchmaking is random, call FindMatch() instead :D");
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -256,8 +270,8 @@ We get a pointer back from the plugin containing the location of the array of by
| 1 Byte | 1 Byte | Rest of the array |
| | | |
---------------------------------------------------------------
Objective C code splits this up into offset and count and sends it here
Objective C code splits this up into offset and channel and sends it here
*/
byte[] _data = new byte[count];
Marshal.Copy(data, _data, 0, count);
Expand All @@ -272,6 +286,7 @@ static void OnClientStartCallback()
instance.connected = true;
activeTransport = instance;
instance.matchFound.Invoke();
startFlag = true;
NetworkManager.singleton.StartClient();
instance.OnClientConnected?.Invoke();
}
Expand Down Expand Up @@ -327,12 +342,12 @@ We get a pointer back from the plugin containing the location of the array of by
| | | |
---------------------------------------------------------------
Objective C code splits this up into offset and count and sends it here
Objective C code splits this up into offset and channel and sends it here
*/
byte[] _data = new byte[count];
Marshal.Copy(data, _data, 0, count);

clientMessageBuffer.Add(new MessageBuffer(new ArraySegment<byte>(_data, offset, count), channelId, connId));
serverMessageBuffer.Add(new MessageBuffer(new ArraySegment<byte>(_data, offset, count), channelId, connId));
}

/// <summary>
Expand All @@ -352,6 +367,7 @@ static void OnServerStartCallback()
instance.connected = true;
activeTransport = instance;
instance.matchFound?.Invoke();
startFlag = true;
Mirror.NetworkManager.singleton.StartHost();
}

Expand Down Expand Up @@ -382,8 +398,6 @@ public override void ClientLateUpdate()
//This executes any messages that were recieved in the last frame
for (int i = 0; i < clientMessageBuffer.Count && i < MaxReceivesPerTick; i++)
{
//Channel set as 0 because I can't work out the channel from the message
//I may want to add something that sends the channel as well later
OnClientDataReceived?.Invoke(clientMessageBuffer[0].data, clientMessageBuffer[0].channelId);
clientMessageBuffer.RemoveAt(0);
}
Expand All @@ -395,8 +409,6 @@ public override void ServerLateUpdate()
//This executes any messages that were recieved in the last frame
for (int i = 0; i < serverMessageBuffer.Count && i < MaxReceivesPerTick; i++)
{
//Channel set as 0 because I can't work out the channel from the message
//I may want to add something that sends the channel as well later
OnServerDataReceived?.Invoke(serverMessageBuffer[0].connId, serverMessageBuffer[0].data, serverMessageBuffer[0].channelId);
serverMessageBuffer.RemoveAt(0);
}
Expand Down
8 changes: 4 additions & 4 deletions BubbleTransport/Plugins/GCController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

extern UIViewController *UnityGetGLViewController();

typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
OnClientDidDataRecievedDelegate ClientRecievedData = NULL;
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
OnServerDidDataRecievedDelegate ServerRecievedData = NULL;
typedef void (*OnServerConnectedDelegate)(int connId);
OnServerConnectedDelegate ServerConnected = NULL;
Expand Down Expand Up @@ -178,7 +178,7 @@ void SendMessageToClient(int clientId, Byte data[], int offset, int count, int c

[GCController sendDataToPlayer:dataToSend toPlayer:clientId datamode:channel];
}
typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
void RegisterClientDataRecieveCallback(OnClientDidDataRecievedDelegate callback)
{
if(ClientRecievedData == NULL)
Expand Down Expand Up @@ -234,7 +234,7 @@ void RegisterOnClientDisconnectedCallback(OnClientDisconnectedDelegate callback)
ClientDisconnected = callback;
}
}
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
void RegisterServerDataRecieveCallback(OnServerDidDataRecievedDelegate callback)
{
if(ServerRecievedData == NULL)
Expand Down

1 comment on commit ef7f35e

@Squaresweets
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah and added some debug log stuff ¯_(ツ)_/¯

Please sign in to comment.