Skip to content

Commit

Permalink
Updated to 12194
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Andreasen committed Mar 14, 2019
1 parent ca17c58 commit 147f471
Show file tree
Hide file tree
Showing 33 changed files with 207 additions and 100 deletions.
13 changes: 3 additions & 10 deletions Assets/Scripts/Game/Entity/GameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public GameWorld(string name = "world")
m_sceneRoot = new GameObject(name);
GameObject.DontDestroyOnLoad(m_sceneRoot);
}

m_ECSWorld = World.Active != null ? World.Active : new World(name);
World.Active = m_ECSWorld;
GameDebug.Assert(World.Active != null,"There is no active world");
m_ECSWorld = World.Active;

m_EntityManager = m_ECSWorld.GetOrCreateManager<EntityManager>();

Expand Down Expand Up @@ -114,13 +114,6 @@ public void Shutdown()

s_Worlds.Remove(this);

if (m_ECSWorld.IsCreated)
{
m_ECSWorld.Dispose();
m_ECSWorld = null;
World.Active = null;
}

GameObject.Destroy(m_sceneRoot);
}

Expand Down
30 changes: 19 additions & 11 deletions Assets/Scripts/Game/Main/ClientGameLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ public bool Init(string[] args)

#if UNITY_EDITOR
Game.game.levelManager.UnloadLevel();
World.DisposeAllWorlds();
#endif
m_GameWorld = new GameWorld("ClientWorld");

Expand Down Expand Up @@ -988,7 +987,7 @@ void CmdMatchmake(string[] args)

if (string.IsNullOrEmpty(endpoint))
{
GameDebug.LogError("matchmake: command requires an endpoint <hostname[:port]/{projectid}>");
GameDebug.LogError("matchmake: command requires an endpoint <ex: cloud.connected.unity3d.com/{projectid}>");
return;
}

Expand All @@ -1004,27 +1003,36 @@ void CmdMatchmake(string[] args)
return;
}

GameDebug.Log($"matchmake: Starting the matchmaker. Requesting match from {endpoint} for player {clientPlayerName.Value}.");
GameDebug.Log($"matchmake: Starting the matchmaker. Requesting match from {endpoint} for request ID {clientPlayerName.Value}.");
m_useMatchmaking = true;
m_matchmaker = new Matchmaker(endpoint);
m_matchmaker = new Matchmaker(endpoint, OnMatchmakingSuccess, OnMatchmakingError);

MatchmakingPlayerProperties playerProps = new MatchmakingPlayerProperties() {hats = 5};
MatchmakingGroupProperties groupProps = new MatchmakingGroupProperties() {mode = 0};
MatchmakingRequest request = Matchmaker.CreateMatchmakingRequest(clientPlayerName.Value, playerProps, groupProps);
m_matchmaker.RequestMatch(request, OnMatchmakingSuccess, OnMatchmakingError);

m_matchmaker.RequestMatch(clientPlayerName.Value, playerProps, groupProps);
}
void OnMatchmakingSuccess(string connectionInfo)

void OnMatchmakingSuccess(Assignment assignment)
{
GameDebug.Log($"Matchmaking has found a game! The server is at: {connectionInfo}");
// TODO: Uncomment following line when matchmaking service returns an endpoint instead of the roster
//Console.EnqueueCommand($"connect {connectionInfo}");
if (string.IsNullOrEmpty(assignment.ConnectionString))
{
GameDebug.Log("Matchmaking finished, but did not return a game server. Ensure your server has been allocated and is running then try again.");
GameDebug.Log($"MM Error: {assignment.AssignmentError ?? "None"}");
}
else
{
GameDebug.Log($"Matchmaking has found a game! The server is at {assignment.ConnectionString}. Attempting to connect...");
Console.EnqueueCommand($"connect {assignment.ConnectionString}");
}
m_useMatchmaking = false;
m_matchmaker = null;
}

void OnMatchmakingError(string errorInfo)
{
GameDebug.LogError($"Matchmaking failed! Error is: {errorInfo}");
m_useMatchmaking = false;
m_matchmaker = null;
}

Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/Game/Main/ServerGameLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ public bool Init(string[] args)

#if UNITY_EDITOR
Game.game.levelManager.UnloadLevel();
World.DisposeAllWorlds();
#endif
m_GameWorld = new GameWorld("ServerWorld");

Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/Game/Main/ThinClientGameLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ public bool Init(string[] args)

#if UNITY_EDITOR
Game.game.levelManager.UnloadLevel();
World.DisposeAllWorlds();
#endif
Console.AddCommand("disconnect", CmdDisconnect, "Disconnect from server if connected", this.GetHashCode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,5 @@ public override string ToString()
}
}

public class CharacterInterpolated : ComponentDataWrapper<CharacterInterpolatedData>
public class CharacterInterpolated : ComponentDataProxy<CharacterInterpolatedData>
{}
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ public override string ToString()
#endif
}

public class CharacterPredicted : ComponentDataWrapper<CharacterPredictedData>
public class CharacterPredicted : ComponentDataProxy<CharacterPredictedData>
{}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public Entity FindAbilityWithComponent(EntityManager entityManager, Type ability
}
}

public class CharacterReplicated : ComponentDataWrapper<CharacterReplicatedData>
public class CharacterReplicated : ComponentDataProxy<CharacterReplicatedData>
{
}
1 change: 1 addition & 0 deletions Assets/Scripts/Game/Modules/Effect/VFXSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEngine;
using UnityEngine.Experimental.VFX;

[DisableAutoCreation]
public class VFXSystem : ComponentSystem
{
static readonly int positionID = Shader.PropertyToID("position");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct HitCollisionOwnerData : IComponentData


[DisallowMultipleComponent]
public class HitCollisionOwner : ComponentDataWrapper<HitCollisionOwnerData>
public class HitCollisionOwner : ComponentDataProxy<HitCollisionOwnerData>
{
private void OnEnable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ public void Deserialize(ref SerializeContext context, ref NetworkReader reader)
}
}

public class UserCommandComponent : ComponentDataWrapper<UserCommandComponentData>
public class UserCommandComponent : ComponentDataProxy<UserCommandComponentData>
{}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public PresentationOwnerData(int variation)
}
}

public class PresentationOwner : ComponentDataWrapper<PresentationOwnerData>
public class PresentationOwner : ComponentDataProxy<PresentationOwnerData>
{}


Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Game/Modules/Ragdoll/RagdollState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Deserialize(ref SerializeContext context, ref NetworkReader reader)
}
}

public class RagdollState : ComponentDataWrapper<RagdollStateData>
public class RagdollState : ComponentDataProxy<RagdollStateData>
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Deserialize(ref SerializeContext context, ref NetworkReader reader)

[ExecuteAlways, DisallowMultipleComponent]
[RequireComponent(typeof(GameObjectEntity))]
public class ReplicatedEntity : ComponentDataWrapper<ReplicatedEntityData>
public class ReplicatedEntity : ComponentDataProxy<ReplicatedEntityData>
{
public byte[] netID; // guid of instance. Used for identifying replicated entities from the scene

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Game/Modules/SpectatorCam/SpectatorCam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Deserialize(ref SerializeContext context, ref NetworkReader reader)



public class SpectatorCam : ComponentDataWrapper<SpectatorCamData>
public class SpectatorCam : ComponentDataProxy<SpectatorCamData>
{

}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Game/Systems/Damage/DamageHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Deserialize(ref SerializeContext context, ref NetworkReader reader)
}
}

public class DamageHistory : ComponentDataWrapper<DamageHistoryData>
public class DamageHistory : ComponentDataProxy<DamageHistoryData>
{
}

2 changes: 1 addition & 1 deletion Assets/Scripts/Game/Systems/Damage/HealthState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void ApplyDamage(ref DamageEvent damageEvent, int tick)
}


public class HealthState : ComponentDataWrapper<HealthStateData>
public class HealthState : ComponentDataProxy<HealthStateData>
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public void Deserialize(ref SerializeContext context, ref NetworkReader reader)
}
}

public class DestructablePropReplicatedState : ComponentDataWrapper<DestructablePropReplicatedData>
public class DestructablePropReplicatedState : ComponentDataProxy<DestructablePropReplicatedData>
{
}
2 changes: 1 addition & 1 deletion Assets/Scripts/Game/Systems/Movable/Movable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Interpolate(ref SerializeContext context, ref MovableData first, ref
}

[RequireComponent(typeof(Rigidbody))]
public class Movable : ComponentDataWrapper<MovableData>
public class Movable : ComponentDataProxy<MovableData>
{
public void Start()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Deserialize(ref SerializeContext context, ref NetworkReader reader)
}

[DisallowMultipleComponent]
public class TeleporterPresentation : ComponentDataWrapper<TeleporterPresentationData>
public class TeleporterPresentation : ComponentDataProxy<TeleporterPresentationData>
{

}
91 changes: 52 additions & 39 deletions Assets/Scripts/Networking/Matchmaking/Matchmaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@

namespace UnityEngine.Ucg.Matchmaking
{
public class Matchmaker
public class Matchmaker
{
/// <summary>
/// The hostname[:port]/{projectid} for the running matchmaker assigned to this project
/// The hostname[:port]/{projectid} of your matchmaking server
/// </summary>
public string Endpoint;

MatchmakingRequest MatchmakingRequest;

MatchmakingController matchmakingController;
private MatchmakingRequest request;

public delegate void SuccessCallback(string connectionInfo);

public delegate void SuccessCallback(Assignment assignment);
public delegate void ErrorCallback(string error);

SuccessCallback m_Success;
ErrorCallback m_Error;
public SuccessCallback successCallback;
public ErrorCallback errorCallback;

public enum MatchmakingState
{
Expand All @@ -35,9 +33,34 @@ public enum MatchmakingState
/// </summary>
public MatchmakingState State = MatchmakingState.None;

public Matchmaker(string endpoint)
/// <summary>
/// Matchmaker
/// </summary>
/// <param name="endpoint"></param>
/// <param name="onSuccessCallback">If a match is found, this callback will provide the connection information</param>
/// <param name="onErrorCallback">If matchmaking fails, this callback will provided some failure information</param>
public Matchmaker(string endpoint, SuccessCallback onSuccessCallback = null, ErrorCallback onErrorCallback = null)
{
Endpoint = endpoint;
this.successCallback = onSuccessCallback;
this.errorCallback = onErrorCallback;
}

/// <summary>
/// Start Matchmaking
/// </summary>
/// <param name="playerId">The id of the player</param>
/// <param name="playerProps">Custom player properties relevant to the matchmaking function</param>
/// <param name="groupProps">Custom group properties relevant to the matchmaking function</param>
public void RequestMatch(string playerId, MatchmakingPlayerProperties playerProps, MatchmakingGroupProperties groupProps)
{
request = CreateMatchmakingRequest(playerId, playerProps, groupProps);

matchmakingController = new MatchmakingController(Endpoint);

matchmakingController.StartRequestMatch(request, GetAssignment, OnError);
State = MatchmakingState.Requesting;
Debug.Log(State);
}

/// <summary>
Expand All @@ -56,8 +79,7 @@ public void Update()
break;
case MatchmakingState.Found:
case MatchmakingState.Error:
Debug.Log("Update() is still being called after matchmaking finished.");
break;
break; // User hasn't stopped the state machine yet.
default:
throw new ArgumentOutOfRangeException();
}
Expand All @@ -70,58 +92,49 @@ public void Update()
/// <param name="playerProps">Custom player properties relevant to the matchmaking function</param>
/// <param name="groupProps">Custom group properties relevant to the matchmaking function</param>
/// <returns></returns>
public static MatchmakingRequest CreateMatchmakingRequest(string playerId, MatchmakingPlayerProperties playerProps, MatchmakingGroupProperties groupProps)
private static MatchmakingRequest CreateMatchmakingRequest(string playerId, MatchmakingPlayerProperties playerProps, MatchmakingGroupProperties groupProps)
{
MatchmakingRequest request = new MatchmakingRequest();
MatchmakingPlayer thisPlayer = new MatchmakingPlayer(playerId);
// TODO: WORKAROUND: Currently matchmaker handles IDs as UUIDs, not player names, and will only ever generate 1 match assignment for each UUID
// Therefore, we'll append the current time in Ticks as an attempt at creating a UUID
playerId = playerId + DateTime.UtcNow.Ticks.ToString();

MatchmakingPlayer thisPlayer = new MatchmakingPlayer(playerId)
{
Properties = JsonUtility.ToJson(playerProps)
};

MatchmakingRequest request = new MatchmakingRequest()
{
Properties = JsonUtility.ToJson(groupProps)
};

thisPlayer.Properties = JsonUtility.ToJson(playerProps);

request.Players.Add(thisPlayer);
request.Properties = JsonUtility.ToJson(groupProps);

return request;
}

/// <summary>
/// Start matchmaking
/// </summary>
/// <param name="request">The matchmaking request</param>
/// <param name="successCallback">If a match is found, this callback will provide the connection information</param>
/// <param name="errorCallback">If matchmaking fails, this callback will provided some failure information</param>
public void RequestMatch(MatchmakingRequest request, SuccessCallback successCallback,
ErrorCallback errorCallback)
{
m_Success = successCallback;
m_Error = errorCallback;
MatchmakingRequest = request;

matchmakingController = new MatchmakingController(Endpoint);

matchmakingController.StartRequestMatch(request, GetAssignment, OnError);
State = MatchmakingState.Requesting;
Debug.Log(State);
}

void GetAssignment()
{
matchmakingController.StartGetAssignment(MatchmakingRequest.Players[0].Id, OnSuccess, OnError);
matchmakingController.StartGetAssignment(request.Players[0].Id, OnSuccess, OnError);
State = MatchmakingState.Searching;
Debug.Log(State);
}

void OnSuccess(string connectionInfo)
void OnSuccess(Assignment assignment)
{
State = MatchmakingState.Found;
Debug.Log(State);
m_Success.Invoke(connectionInfo);
successCallback?.Invoke(assignment);
}

void OnError(string error)
{
State = MatchmakingState.Error;
Debug.Log(State);
m_Error.Invoke(error);
errorCallback?.Invoke(error ?? "Undefined Error");
}
}
}
}
Loading

0 comments on commit 147f471

Please sign in to comment.