Skip to content

Commit

Permalink
Update: for p2p.
Browse files Browse the repository at this point in the history
  • Loading branch information
skeyll committed Oct 21, 2024
1 parent 2b14f86 commit aead9d2
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 80 deletions.
1 change: 0 additions & 1 deletion docs/content/SynicSugar.MatchMake/MatchMakeManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ If this is no longer needed, we call *[CancelCurrentMatchMake](../MatchMakeManag
| [CloseCurrentMatchMake](../MatchMakeManager/closecurrentmatchmake) | (Host) destroys lobby to stop the matchmaking |
| [KickTargetFromLobby](../MatchMakeManager/kicktargetfromlobby) | (Host) kicks target from Lobby |
| [CreateOfflineLobby](../MatchMakeManager/createofflinelobby) | Create fake-lobby as Host for tutorial |
| DestoryOfflineLobby | Destory offline-lobby and stop offline mode |
| [GetCurrentLobbyID](../MatchMakeManager/getcurrentlobbyid) | Get LobbyID that a user participating |
| [GetReconnectLobbyID](../MatchMakeManager/getreconnectlobbyid) | Get LobbyID by Playerprefs |
| [GetCurrentLobbyMemberCount](../MatchMakeManager/getcurrentlobbymembercount) | Get the current member count in Lobby |
Expand Down
6 changes: 3 additions & 3 deletions docs/content/SynicSugar.P2P/ConnectHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ Each assembly can have max 250 variables and functions with Network attribute (s
| API | description |
|---|---|
| [Instance](../ConnectHub/instance) | This scrip's instance |
| [CHANNELLIST](../ConnectHub/channellist) | List of all variable and functions having Network attribute |
| [Channels](../ConnectHub/channels) | List of all variable and functions having Network attribute |

### Function
| API | description |
|---|---|
| [StartSynicReceiver](../ConnectHub/startsynicreceiver) | Start the synic receiver to get only synic packet from buffer |
| [StartPacketReceiver](../ConnectHub/startpacketreceiver) | (Re)Start the packet receiver to get packet from buffer |
| [PausePacketReceiver](../ConnectHub/pausepacketreceiver) | Pause to get a packet from the buffer |
| [StopPacketReceiver](../ConnectHub/stoppacketreceiver) | Stop to get a packet from the buffer |
| [PauseConnections](../ConnectHub/pauseconnections) | Pause receiving a packet to the receive buffer |
| [RestartConnections](../ConnectHub/restartconnections) | Restart to receive packets receive buffer |
| [ExitSession](../ConnectHub/exitsession) | Leave connection |
| [CloseSession](../ConnectHub/closesession) | Close connection. (If Host, close the Lobby) |
| DestoryOfflineLobby | Destory offline-lobby and stop offline mode |
| [RegisterInstance](../ConnectHub/registerinstance) | Register instance to receive packets |
| [GetUserInstance](../ConnectHub/getuserinstance) | Get a NetworkPlayer instance of target user registered to ConnectHub |
| [GetInstance](../ConnectHub/getinstance) | Get a NetworkCommons instance registered to ConenctHub |
| [SyncSynic](../ConnectHub/syncsynic) | Synchronize all own Synic variables at once to TargetUser |
| ConvertFromPacket | SynicSugar uses internally |
| [ResendLastRPC](../ConnectHub/resendlastrpc) | Re-Send RPC with last recorded information |
| [ResendLastRPCToTarget](../ConnectHub/resendlastrpctotarget) | Re-Send RPC to the specific target with last recorded information |
| [ResendLastTargetRPC](../ConnectHub/resendlasttargetrpc) | Re-Send TargetRPC with last recorded information. |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
+++
title = "CHANNELLIST"
title = "Channels"
weight = 1
+++
## CHANNELLIST
## Channels
<small>*Namespace: SynicSugar.P2P* <br>
*Class: ConnectHub* </small>

public enum CHANNELLIST
intenal enum Channels


### Description
Expand All @@ -20,7 +20,7 @@ using MemoryPack;
[NetworkPlayer] //For [TargetRpc]
public class p2pSample {
void HandSend(){
EOSp2p.SendPacket((byte)ConnectHub.CHANNELLIST.TargetRPCFuction, MemoryPack.MemoryPackSerializer.Serialize("HELLO"), attackUserId).Forget();
EOSp2p.SendPacket((byte)ConnectHub.Channels.TargetRPCFuction, MemoryPack.MemoryPackSerializer.Serialize("HELLO"), attackUserId).Forget();
}

[TargetRpc] //Then, SourceGenerator add "RPCFuction" to enum ConnectHub.CHANNELLIST.
Expand Down
8 changes: 6 additions & 2 deletions docs/content/SynicSugar.P2P/ConnectHub/CloseSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ weight = 7
<small>*Namespace: SynicSugar.P2P* <br>
*Class: ConnectHub* </small>

public async UniTask&lt;bool&gt; CloseSession(bool destroyManager = true, CancellationTokenSource cancelToken = default(CancellationTokenSource))
public async UniTask&lt;bool&gt; CloseSession(bool destroyManager = true, bool cleanupMemberCountChanged = false, CancellationToken cancelToken = default(CancellationToken))


### Description
Stop the packet receiver, close all connections, remove the notify events and destroy ConnectManager object. Then, Host closees and Guest leaves the lobby. <br>
When Host closes Lobby, Guests are automatically kicked out from the Lobby.
When Host closes Lobby, Guests are automatically kicked out from the Lobby.<br>

destroyManager: If true, destroy NetworkManager after exit lobby.<br>
cleanupMemberCountChanged: Need to call MatchMakeManager.Instance.MatchMakingGUIEvents.LobbyMemberCountChanged(id, false) after exit lobby?<br>
cancelToken: ancel token for this task


```cs
Expand Down
8 changes: 6 additions & 2 deletions docs/content/SynicSugar.P2P/ConnectHub/ExitSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ weight = 6
<small>*Namespace: SynicSugar.P2P* <br>
*Class: ConnectHub* </small>

public async UniTask&lt;bool&gt; ExitSession(bool destroyManager = true, CancellationTokenSource cancelToken = default(CancellationTokenSource))
public async UniTask&lt;bool&gt; ExitSession(bool destroyManager = true, bool cleanupMemberCountChanged = false, CancellationToken cancelToken = default(CancellationToken))


### Description
Stop the packet receiver, close all connections, remove the notify events and destroy ConnectManager object. Then, the user leaves Lobby.<br>
The last user closes the lobby in Backend.
The last user closes the lobby in Backend.<br><br>

destroyManager: If true, destroy NetworkManager after exit lobby.<br>
cleanupMemberCountChanged: Need to call MatchMakeManager.Instance.MatchMakingGUIEvents.LobbyMemberCountChanged(id, false) after exit lobby?<br>
cancelToken: ancel token for this task


```cs
Expand Down
24 changes: 0 additions & 24 deletions docs/content/SynicSugar.P2P/ConnectHub/PausePacketReceiver.md

This file was deleted.

9 changes: 4 additions & 5 deletions docs/content/SynicSugar.P2P/ConnectHub/StartSynicReceiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ weight = 2
<small>*Namespace: SynicSugar.P2P* <br>
*Class: ConnectHub* </small>

public void StartSynicReceiver()

public void StartSynicReceiver(byte maxBatchSize = 1)

### Description
Start Packet Receiver (in burst FPS) to get only Synic packets from the receiving buffer.<br>
Start Packet Receiver to get only Synic packets (in Unity.Update) from the receiving buffer.<br>
This cannot be called with other Receiver at the same time. If start the other Receiver, ConenctHub stop this Receiver automatically before start the new one.<br>
Need the Instance of each Class to get the packet.<br>
So, genarete the components by *[SynicObject](../synicobject/)*, or set UserID in or after Unity.Start to Register the instanced to ConnectHub.<br>
Expand All @@ -26,12 +25,12 @@ public class p2pSample {
//This user is Reconnecter
if(p2pInfo.Instance.IsReconnecter){
//To get SynicPacket.
ConnectHub.Instance.StartSynicReceiver();
ConnectHub.Instance.StartSynicReceiver(8);
//This flag(HasReceivedAllSyncSynic) cannot be used at the same time. Once it returns True, it returns False again.
await UniTask.WaitUntil(() => p2pInfo.Instance.HasReceivedAllSyncSynic);
}
}
ConnectHub.Instance.StartSynicReceiver();
ConnectHub.Instance.StartPacketReceiver(maxBatchSize: 5);
}
}
```
24 changes: 24 additions & 0 deletions docs/content/SynicSugar.P2P/ConnectHub/StopPacketReceiver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
+++
title = "StopPacketReceiver"
weight = 3
+++
## StopPacketReceiver
<small>*Namespace: SynicSugar.P2P* <br>
*Class: ConnectHub* </small>

public void StopPacketReceiver()


### Description
Stop just getting a packet from the receiving buffer. **To get a packet again, call *[StartPacketReceiver](../ConnectHub/startpacketreceiver)***.<br>


```cs
using SynicSugar.P2P;

public class p2pSample {
void ConnectHubSample(){
ConnectHub.Instance.StopPacketReceiver();
}
}
```
3 changes: 2 additions & 1 deletion docs/content/SynicSugar.P2P/p2pConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ If this is no longer needed, we call *[CancelCurrentMatchMake](../../SynicSugar.
| [AutoRefreshPing](../p2pConfig/autorefreshping) | If true, update ping automatically |
| [SamplesPerPing](../p2pConfig/samplesperping) | Number of samples used for a ping |
| [PingAutoRefreshRateSec](../p2pConfig/pingautorefreshratesec) | Interval sec to update ping automatically |
| [RelayControl](../p2pConfig/relaycontrol) | The way to connection |
| [relayControl](../p2pConfig/relaycontrol) | The way to connection |


### Function
| API | description |
|---|---|
| [SetRelayControl](../MatchMakeManager/setrelaycontrol) | Change the way to connection |
| GetNetworkCore | Get instance to manage connection script |



Expand Down
35 changes: 0 additions & 35 deletions docs/content/SynicSugar.P2P/p2pConnectorForOtherAssembly.md

This file was deleted.

15 changes: 12 additions & 3 deletions docs/content/SynicSugar.P2P/p2pInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ If this is no longer needed, we call *[CancelCurrentMatchMake](../../SynicSugar.
| CurrentConnectedUserIds | Connected user ids include Local UserId |
| CurrentAllUserIds | AllUserIds - LeftUsers (not disconnected) |
| [AllUserIds](../p2pInfo/alluserids) | AllUserIds in the session |
| [CurrentSessionStartUTC](../p2pInfo/currentsessionstartutc) | Date time when this LOCAL user starts current session |
| [AcceptHostSynic](../p2pInfo/accepthostsynic) | If true, host overwrite this local user instnace |
| [ConnectionNotifier](../p2pInfo/connectionnotifier) | Notifers when a user connects or disconnects |
| LastDisconnectedUsersReason | The reason of last disconnected user |
| LastDisconnectedUsersId | UserID of last Disconnected user |
| LastConnectedUsersId | UserID of last Connected user |
| [SyncSnyicNotifier](../p2pInfo/syncsnyicnotifier) | Notifers when a user get SynicVariables |
| HasReceivedAllSyncSynic | Return True only once after local user receives all SyncSynics |
| SyncedSynicPhase | The SyncSynic phase of last received |
| LastSyncedUserId | The UserID of last synced SyncSynic |
Expand All @@ -44,12 +43,22 @@ If this is no longer needed, we call *[CancelCurrentMatchMake](../../SynicSugar.
| LastTargetRPCUserId | The last UserId sent with TargetRPC that record data |
| IsReconnecter | Return true until reconencter gets self Synic data. |

### Event
| API | description |
|---|---|
| [ConnectionNotifier](../p2pInfo/connectionnotifier) | Notifers when a user connects or disconnects |
| [SyncSnyicNotifier](../p2pInfo/syncsnyicnotifier) | Notifers when a user get SynicVariables |

### Function
| API | description |
|---|---|
| [IsLoaclUser](../p2pInfo/isloacluser) | If target is LocalUser, return true |
| [IsHost](../p2pInfo/ishost) | If local or target user is host, return true |
| [GetSessionTimestamp](../p2pInfo/currentsessionstartutc) | Sec since start current session |
| [GetSessionTimestampInMs](../p2pInfo/currentsessionstartutc) | Micro Sec since start current session |
| GetUserIndex | Get the user unique index in AllUserIds |
| [ConnectionIsValid](../p2pInfo/connectionisvalid) | Whether the connection is valid or not |
| [GetActiveReceiverType](../p2pInfo/getactivereceivertype) | Gets the currently valid packet receiver type |
| [QueryNATType](../p2pInfo/querynattype) | Update local user's NATType to the latest |
| [GetNATType](../p2pInfo/getnattype) | Get last-queried NAT-type |
| [GetPing](../p2pInfo/getping) | Get a ping with a peer from cache |
Expand All @@ -61,7 +70,7 @@ If this is no longer needed, we call *[CancelCurrentMatchMake](../../SynicSugar.
using SynicSugar.P2P;
using UnityEngine;
[NetworkPlayer]
public class p2pSample : MonoBehaviour {
public partial class p2pSample : MonoBehaviour {
void Start(){
if(!isLoacl){
return;
Expand Down
31 changes: 31 additions & 0 deletions docs/content/SynicSugar.P2P/p2pInfo/ConnectionIsValid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
+++
title = "ConnectionIsValid"
weight = 6
+++
## ConnectionIsValid
<small>*Namespace: SynicSugar.P2P* <br>
*Class: p2pInfo* </small>

public bool ConnectionIsValid ()


### Description
Checks if the connection has been enabled by the library or user.<br>
This does not necessarily mean that an actual connection has been established.<br>
The IsConnected flag becomes true after the user or library initiates the connection.<br>
After that, it will never become False unless we explicitly Pause connection.<br>

```cs
using SynicSugar.P2P;
using UnityEngine;
[NetworkCommons]
public partial class p2pSample : MonoBehaviour {

public void RestartConnection(){
if(p2pInfo.Instance.ConnectionIsValid()){
return;
}
ConnectHub.Instance.RestartConnections();
}
}
```
41 changes: 41 additions & 0 deletions docs/content/SynicSugar.P2P/p2pInfo/CurrentSessionStartUTC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
+++
title = "CurrentSessionStartUTC"
weight = 2
+++
## CurrentSessionStartUTC
<small>*Namespace: SynicSugar.P2P* <br>
*Class: p2pInfo* </small>

public DateTime CurrentSessionStartUTC { get; internal set; }


### Description
Date time when this LOCAL user starts current session.<br><br>

This time is the UTC just before the matchmaking results are returned. When matchmaking is decided and all preparations are complete, the LobbyID and UTC are saved in Application.persistentDataPath/ss_sessiondata.dat. The in-game timestamp is calculated based on the difference between this reference time and the current UTC.<br>
In P2P, there is no server, so server time cannot be used for the game. Additionally, Ping and RTC can be unreliable due to processing congestion, so SynicSugar saves the time when matchmaking finished on each device and uses it as a reference time.<br>
When reconnecting, if this value exists locally, it is used again. If it doesn't exist, an estimated start time is calculated from the elapsed time timestamp sent by the host and set to this value.<br><br>


```cs
using SynicSugar.P2P;
using UnityEngine;
[NetworkPlayer]
public partial class p2pSample : MonoBehaviour {
void Start(){
//For standard
Move(p2pInfo.Instance.GetSessionTimestamp());

//To need rigorous time
Fire(p2pInfo.Instance.GetSessionTimestampInMs());
}
[Rpc]
void Move(uint timestamp){
Debug.Log($"Lag is {p2pInfo.Instance.GetSessionTimestamp() - timestamp} sec");
}
[Rpc]
void Fire(double timestamp){
Debug.Log($"Lag is {p2pInfo.Instance.GetSessionTimestampInMs() - timestamp} ms");
}
}
```
34 changes: 34 additions & 0 deletions docs/content/SynicSugar.P2P/p2pInfo/GetActiveReceiverType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
+++
title = "GetActiveReceiverType"
weight = 6
+++
## GetActiveReceiverType
<small>*Namespace: SynicSugar.P2P* <br>
*Class: p2pInfo* </small>

public ReceiverType GetActiveReceiverType ()<br>

```cs
public enum ReceiverType {
None, FixedUpdate, Update, LateUpdate, Synic
}
```

### Description
Gets the currently valid (active) packet receiver type.<br>


```cs
using SynicSugar.P2P;
using UnityEngine;
[NetworkCommons]
public partial class p2pSample : MonoBehaviour {

public void Start(){
if(ReceiverType.None == p2pInfo.Instance.GetActiveReceiverType()){
ConnectHub.Instance.StartPacketReceiver(PacketReceiveTiming.FixedUpdate, 5);
//p2pInfo.Instance.GetActiveReceiverType() becomes ReceiverType.FixedUpdate
}
}
}
```

0 comments on commit aead9d2

Please sign in to comment.