-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of GameServer() for Unity #1169
Implementation of GameServer() for Unity #1169
Conversation
Build Failed 😱 Build Id: ac3ac819-075e-4233-bed6-926555391acd To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
/assign @pooneh-m (since you have a lot more c# experience than I do) |
/assign @dzlier-gcp Also Dane... |
Weird this flaked - looking at the logs, it completed:
Restarting the e2e test. |
Build Succeeded 👏 Build Id: fe276dcb-f870-49d5-88f5-71ddb76b75ed The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
@@ -40,6 +40,15 @@ async void SomeMethod() | |||
} | |||
``` | |||
|
|||
To get the details on the [backing `GameServer`]({{< relref "_index.md#gameserver" >}}) call `GameServer()`. | |||
|
|||
Will return `null` if something there is an error in retrieving the `GameServer` record. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"something" -> remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️ thank you!
@@ -73,6 +73,14 @@ async void Update() | |||
|
|||
echoBytes = Encoding.UTF8.GetBytes($"Allocate {ok}"); | |||
break; | |||
|
|||
case "GameServer": | |||
var gameserver = await agones.GameServer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[future nit.] the C# style guide recommends suffixing async methods with Async. e.g. GameServerAsync.
You should add "Async" as the suffix of every async method name you write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be a good thing. But we already have the rest of the SDK being async, and it wasn't written that way in the first place 😞 we probably should at least be consistent?
@@ -78,7 +81,23 @@ private void OnApplicationQuit() | |||
/// </returns> | |||
public async Task<bool> Ready() | |||
{ | |||
return await SendRequestAsync("/ready", "{}"); | |||
return await SendRequestAsync("/ready", "{}").ContinueWith(task => task.Result.ok); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this? -> .ContinueWith(task => task.Result.ok)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are now no longer returning a Task<bool>
but a Task<AsyncResult>
from SendRequestAsync
, since we needed more information from it.
/// <summary> | ||
/// Initializes a new instance of the <see cref="GameServer" /> class. | ||
/// </summary> | ||
public GameServer(IReadOnlyDictionary<string, object> data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null check for data?
sdks/unity/model/GameServer.cs
Outdated
public GameServer(IReadOnlyDictionary<string, object> data) | ||
{ | ||
this.ObjectMeta = new GameServerObjectMeta((Dictionary<string,object>) data["object_meta"]); | ||
this.Spec = new GameServerSpec((Dictionary<string,object>) data["spec"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this requires force conversion (throw exception if not converted) while status requires soft conversion with as
(null value if not converted)? If intended can you add a comment to document?
public SpecHealth(IReadOnlyDictionary<string, object> data) | ||
{ | ||
this.Disabled = data.TryGetValue("disabled", out var disabled) && bool.Parse((string) disabled); | ||
this.PeriodSeconds = (Int64) data["period_seconds"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use Int64.Parse for these as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an actual Int64
stored in the map, so there is no string to parse.
return null; | ||
} | ||
|
||
var data = Json.Deserialize(result.json) as Dictionary<string, object>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a JSON deserializer, such as newtonsoft that accepts the predefined objects here with json names, instead of converting them to a dictionary and find the values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish. We can't use NuGet, so we can't pull in newtonsoft. There is a Unity specific version of it, but it's huge, and seems like a massive dependency. And we can't force Users to pull things down from the asset store.
MiniJSON is lightweight, and does what we need, even though we have to do more work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use NuGet
Why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not something Unity supports. Also they have older / kinda hacked version of Mono running in there. It's a whole thing.
Build Succeeded 👏 Build Id: a4e5fff8-1d52-4b4f-bedc-6f02d58a862f The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
f842952
to
ad78040
Compare
Should be ready for re-review now. |
Build Succeeded 👏 Build Id: 69612b1f-f353-4d71-8485-cf7bb280710d The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
- Refactored `SendRequestAsync` to return a `AsyncResult` which contains both a success bool, and the returned body text from the http call. - Used the swagger.json to generate the basic structure of the `GameServer` object, and then hand modified as needed. - Had to include third_party/MiniJSON because Unity doesn't natively support `Dictionary`, which means we can't get Label or Annotation data. Then had to manually import the MiniJSON data into GameServer and related model objects. - Used a set of symlinks to share the Agones Unity SDK code with the unity-simple example. Couldn't think of a better way. - Minor version update on the example project as that is the earliest version I could get in 2018.4.x - Added `GameServer` command to the simple-unity example as well. Work on googleforgames#927
ad78040
to
529c33f
Compare
Build Succeeded 👏 Build Id: dabbb04f-25b5-46c7-b9cd-caf6876c4b10 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
Thanks for the approval @pooneh-m - would love to get @dzlier-gcp to also look, just because of their Unity experience as well. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dzlier-gcp, markmandel, pooneh-m The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
- Refactored `SendRequestAsync` to return a `AsyncResult` which contains both a success bool, and the returned body text from the http call. - Used the swagger.json to generate the basic structure of the `GameServer` object, and then hand modified as needed. - Had to include third_party/MiniJSON because Unity doesn't natively support `Dictionary`, which means we can't get Label or Annotation data. Then had to manually import the MiniJSON data into GameServer and related model objects. - Used a set of symlinks to share the Agones Unity SDK code with the unity-simple example. Couldn't think of a better way. - Minor version update on the example project as that is the earliest version I could get in 2018.4.x - Added `GameServer` command to the simple-unity example as well. Work on googleforgames#927
SendRequestAsync
to return aAsyncResult
which contains both a success bool, and the returned body text from the http call.GameServer
object, and then hand modified as needed.Dictionary
, which means we can't get Label or Annotation data. Then had to manually import the MiniJSON data into GameServer and related model objects.GameServer
command to the simple-unity example as well.Work on #927