Adam's Lair Forum

game development and casual madness
It is currently 2017/11/19, 14:22

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 2017/08/13, 16:21 
Junior Member
Junior Member

Joined: 2017/07/20, 18:17
Posts: 27
Location: Germany
Role: Hobbyist
Hi,

I have a question regarding the Play, Pause, Stop workflow in the Dualitor. What I want to do is simple: I want to do cleanup when the Play mode in Dualitor is ended via Stop. I thought I found the solution with the "OnExecContextChange" of the CorePlugin. I wrote the following code:
Code:
protected override void OnExecContextChanged(DualityApp.ExecutionContext previousContext)
{
  this.logger.LogInformation($"Execution context changed from '{previousContext}' to '{DualityApp.ExecContext}'");

  // When Dualitor play mode is ended by user
  if (DualityApp.ExecContext == DualityApp.ExecutionContext.Editor && previousContext == DualityApp.ExecutionContext.Game)
  {
    this.CleanUp();
  }
}

Unfortunately it works only for Stop. This code will also be triggered when the Pause is used in Dualitor. But Pause should not trigger the cleanup. Is there a solution to the problem?

Some screenshots to show the behavior:
ImageImage Image


Top
 Profile  
 
PostPosted: 2017/08/13, 17:14 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2028
Location: Germany
Role: Professional
Hey there,

as you noticed, the execution context only distinguishes game mode (running in whatever environment) and editing mode (not running at all, but being hosted for editing purposes), but carries no information about why any of those modes is active - and as far as the game is concerned, being in a paused sandbox, or not being in sandbox mode at all is indistinguishable. This is by design - ideally, the game needs to know as little as possible about its environment to run properly.

If you're implementing editor-specific behavior, consider moving that code into an editor plugin. That way, you'll get the full editor API and can ask the sandbox about its state or register for its global events directly using the static Sandbox class.

Whether or not a paused sandbox should be considered game or editing mode is another question that we can debate when the need arises, but it's not a bug or tweak, that I'd just throw out there in a patch - if this were to change, it should be considered carefully.

Edit: Ah, just thought of another thing to mention: The sandbox reloads the scene on enter and exit, so your initializable components all get to init and cleanup properly. This does not happen when pausing, so the regular init / shutdown might be closer to what you want. Still, if this is about editor functionality, consider an editor plugin ^^

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2017/08/14, 08:13 
Junior Member
Junior Member

Joined: 2017/07/20, 18:17
Posts: 27
Location: Germany
Role: Hobbyist
Adam wrote:
If you're implementing editor-specific behavior, consider moving that code into an editor plugin. That way, you'll get the full editor API and can ask the sandbox about its state or register for its global events directly using the static Sandbox class.

I am uncertain about an editor plugin that can solve my issue. I really need the clean up in the core plugin, because it is related to game itself running in the editor. But let me describe my clean up with bit more detail:

On "New Game" the core plugin will connect to a server via TCP. All network handling including sending and receiving of messages together with alive pings and so on are done in background tasks independent of any rendering. On stopping the game in the editor I need to disconnect from the server and end the background running tasks to get a clean reset of the core plugin for next run in the editor. So I badly need some event where I can do this. Otherwise the game may not run stable in the editor.

The behaviour indeed is editor specific, but I need it done within the core plugin, because it does the network handling. I actually don't know how a separate editor plugin can solve my issue here, because core plugin and editor plugin are having no connection or am I wrong here?


Top
 Profile  
 
PostPosted: 2017/08/14, 22:18 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2028
Location: Germany
Role: Professional
Yep, that sounds like you need that behavior in the core ^^ It also sounds like it would be a good fit for a Component with an ICmpInitializable implementation that reacts to Activate and Deactivate signals. So as long as you are not absolutely required to keep that logic out of a scene, that might be one way to go.

Would that work in your case? Otherwise, that would be a good reason to schedule an extension of CorePlugin API to equip it with similar callbacks in a future update.

Faithless wrote:
I actually don't know how a separate editor plugin can solve my issue here, because core plugin and editor plugin are having no connection or am I wrong here?


Your editor plugin can depend on your core plugin and thus call any of your code whenever you want it to - so that at least wouldn't be a problem. In fact, it could be a way to achieve a workaround until the Duality API is extended, should the Component solution not be possible in your scenario.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2017/08/14, 23:18 
Junior Member
Junior Member

Joined: 2017/07/20, 18:17
Posts: 27
Location: Germany
Role: Hobbyist
Adam wrote:
Yep, that sounds like you need that behavior in the core ^^ It also sounds like it would be a good fit for a Component with an ICmpInitializable implementation that reacts to Activate and Deactivate signals. So as long as you are not absolutely required to keep that logic out of a scene, that might be one way to go.

Would that work in your case?

Hmm, a component may be workaround but not a good solution, because I had to put that indeed in every scene, because like you mentioned, I want to keep the logic across mutiple scenes. The main menu switches to the game setup scene after the connect and later to the game map scene. Even switiching the server connect to the game setup scene is no help, because there the connection to the server is required and still a scene change is needed.

Adam wrote:
Otherwise, that would be a good reason to schedule an extension of CorePlugin API to equip it with similar callbacks in a future update.

Therefore I would appreciate such an extension of the core plugin API most :) I will write an issue on github.

Adam wrote:
Your editor plugin can depend on your core plugin and thus call any of your code whenever you want it to - so that at least wouldn't be a problem. In fact, it could be a way to achieve a workaround until the Duality API is extended, should the Component solution not be possible in your scenario.

So for now I will use this approach. So far I didn't used the editor plugin, but so it is the first time. If an extension to the core plugin will be made, I change the implementation to the new API.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group