-
Notifications
You must be signed in to change notification settings - Fork 3
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
[REG-2168] Support a bot action to 'ResetForNextTest' .. and 'RestartGame' and 'QuitGame' #351
Conversation
@@ -0,0 +1,10 @@ | |||
namespace StateRecorder.BotSegments.Models | |||
{ | |||
public interface IRGRestartGameAction |
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.
New interface for custom restart implementations
namespace RegressionGames.StateRecorder.BotSegments.Models.BotActions | ||
{ | ||
[Serializable] | ||
public class RestartGameBotActionData : IBotActionData |
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.
New restart game bot action
namespace RegressionGames.StateRecorder.BotSegments.Models.BotActions | ||
{ | ||
[Serializable] | ||
public class QuitGameBotActionData : IBotActionData |
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.
New quit game bot action
/** | ||
* <summary> Add restart game bot action</summary> | ||
*/ | ||
public const int VERSION_25 = 25; |
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.
new sdk api version
@@ -47,6 +49,12 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist | |||
case BotActionType.Mouse_ObjectDetection: | |||
data = jObject["data"].ToObject<CVObjectDetectionMouseActionData>(serializer); | |||
break; | |||
case BotActionType.RestartGame: |
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.
handle the new actions when reading in bot segment json
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.
Looks good overall. Just 1 non-blocking Q
...bots/Runtime/Scripts/StateRecorder/BotSegments/Models/BotActions/RestartGameBotActionData.cs
Outdated
Show resolved
Hide resolved
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 looks good!
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.
Very nice!! I only had one question about default behavior in the editor for the restart mode, but looks good otherwise. Will resolve that quickly once I get an answer.
...bots/Runtime/Scripts/StateRecorder/BotSegments/Models/BotActions/RestartGameBotActionData.cs
Show resolved
Hide resolved
// un-register our listener | ||
EditorApplication.playModeStateChanged -= PlayGameInEditor; | ||
// just finished playing ... start it back up | ||
EditorApplication.isPlaying = true; |
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'm glad this actually works!
RGDebug.LogInfo($"Restarting the game in the editor..."); | ||
_error = null; | ||
error = _error; | ||
// register our hook so that the game will start right back up | ||
EditorApplication.playModeStateChanged += PlayGameInEditor; | ||
// stop the game in the editor | ||
EditorApplication.isPlaying = false; | ||
return true; |
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.
Does this mean in editor we only allow a restart that completely restarts the game? I might be misreading this but it seems like the _action is only considered outside of editor?
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.
correct.. as of right now..
- Editor - 'restart' actually restarts the game
- External Runtime -
- Default - 'restart' loads scene 0, which is as close as we can get to restarting the game without ending the process runtime; this restarts the game to the starting scene, but potentially without cleaning up many things as noted in the comments in the code... we could explore making this much harsher... like.. destroy all objects (event don't destroy on load) before loading scene 0 which would make it much closer to the editor behaviour... however, this still wouldn't kill background threads, or unity task running on entities/etc
- Custom - 'restart' runs whatever commands are in your custom impl
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 suppose that was fine for now, but I was thinking that even in editor it would run the custom impl, since my restart logic might just be "respawn at the respawn point and remove all enemies". But on second thought, it might be good to allow the custom action in the editor because this means the only way for you to test the custom logic is to keep rebuilding the game, which could take a long time.
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.
Apparently we weren't on the same page at all when initially discussing this task.
It seems you wanted an action to define 'reset for next test', but I got 'restart game' out of the initial discussion.
I guess I'll start over .
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.
Start over? I'm confused as I feel like all the code here aligns with exactly what I was thinking, including the default of loading the initial scene. From what I see here, this aligns almost exactly with my thinking but I had in my mind one small extension, but if that extension is not small I'd rather have this PR in.
@vontell I debated whether to start a new PR for this, but I re-opened the existing. There is now another new action You can now do what you intended with a partial reset for the next test without restarting the game, but I don't really agree with this function being different than restart game as there is generally no 1 single action you can take to safely reset the game's state other than fully restarting it. I feel that this is only going to add confusion for users on how to implement 'reset' safely for multiple test scenarios. |
@@ -11,6 +11,9 @@ public enum BotActionType | |||
Mouse_CVImage, | |||
Mouse_CVText, | |||
Mouse_ObjectDetection, | |||
RestartGame, | |||
QuitGame, | |||
ResetForNextTest |
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 would rather name this ResetGame
, but that is too close to RestartGame
to be completely clear.
Ultimately, I don't like Reset
existing separately from Restart
, but that was the only way to fufill @vontell 's ask that the custom impl be testable in the editor if desired.
Approving but happy to discuss this further at some point, I have a feeling what I'm about to write out via text is better explained over a quick huddle at some point. I think where the confusion came from is what we were assuming would go in this RestartGame custom impl, and I am fine going with whatever you were expecting inside of that... but anyhow, I was expecting the result of my message to not be an entirely new type, it was simply arguing that the custom impl would run in the editor - I guess I am missing some nuance around why we couldn't just delete that UNITY_EDITOR conditional in the ResetGame handler, that was what I thought would be the change (i.e. just making sure if I provide a custom impl, it uses that in editor so I can make sure that works before building). I suppose that means that the sentence "Ultimately, I don't like Reset existing separately from Restart, but that was the only way to fufill @vontell 's ask that the custom impl be testable in the editor if desired" is the part I don't understand, I'll dive a little deeper into the code though and see if I can figure that out for myself |
@vontell I fundamentally dis-agree with using the custom impl in the editor. The BEST and only truly clean option is to restart the game. In the editor, this is trivial to achieve and thus is what should happen. I don't like there being a reset and restart at all. I want just restart, as doing anything other than fully restarting the game is less than ideal. Unfortunately in a built runtime, the options for restarting the game are limited. That is why I had the initial discussion with you about possibly starting a new process for the game runtime as our preferred runtime option, but that didn't work well in docker. I would still prefer that to what is here now though. |
Hmmmm I think I see where the disconnect is, I suppose my question would be what exactly we imagine going into this custom impl for RestartGame. In terms of custom impl in the editor, I think we are actually in agreement there, I am pretty ok with taking a stance that we should be doing the best possible restart to ensure things are not getting messed up. The only reason I was pushing for the above (this reasoning slightly shifted as we conversed) is that I really don't like the idea of code that I can't test until after the build is made, it just makes iterating for the developer tough. But then again, maybe that goes back to what kind of code is going to be inside this custom impl, maybe the code you are imagining is very simple and therefore that wouldn't be as much of a concern Also just to demonstrate what I thought my comment was going to result in, here is the edit to the code that I thought would be made, I suppose I don't know why this change wouldn't work (this was a quick edit, small pieces of it may not be correct fully): 16e4823 |
Find the pull request instructions here
Every reviewer and the owner of the PR should consider these points in their request (feel free to copy this checklist so you can fill it out yourself in the overall PR comment)