glegris / pulpcore

Automatically exported from code.google.com/p/pulpcore
0 stars 1 forks source link

Life cycle event management patch. #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've created a simple life cycle event management package and integrated it
with PulpCore.

Here's a patch.

Note, I did a diff on the directory after I imported it into Eclipse as a
project, so when applying the patch locally, be careful about the Eclipse
specific files and specific build.properties entries.

Also, the code needs to be cleaned up because my editor settings are
different than those of the files - is there a Jalopy file or something
similar somewhere so I can format them correctly?

I also included a screenshot of the Quick template running with it.

Original issue reported on code.google.com by elbe...@gmail.com on 26 Mar 2008 at 5:22

Attachments:

GoogleCodeExporter commented 9 years ago
Sorry, that patch was missing all the new classes. Sorry, here's a better patch.
Please delete the first one.

Original comment by elbe...@gmail.com on 26 Mar 2008 at 5:28

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the patch, it has a lot of good ideas, and can work as a starting 
point. I think there are a couple 
problems - it's complex, it duplicates some functionality, and the event 
notifications don't always happen in the 
same thread. Also performing certain code after init() but before start() might 
break some things.

So, at the moment it the main problem is it's not obvious how to get shutdown 
notifications for apps with 
multiple scenes. (Apps know when they are started from the load() method of the 
first scene, and single-scene 
apps know when they are shutdown from their unload() method). I might run with 
some of these ideas and 
simplify it, though.

Original comment by brack...@gmail.com on 31 Mar 2008 at 6:43

GoogleCodeExporter commented 9 years ago
David, thanks for the comments. This was meant as more of a proof of concept, I
certainly hoped and wanted more discussion about this before anything was 
actually
integrated in. 

I originally had the EventDispatcher with it's own thread for dispatching, but
thought it would be more acceptable to make use of the animation thread. I 
didn't
realize that there could be more than 1. You're right, this could definitely 
cause
issues - especially with timing - you wouldn't want the start event actually 
being
called before the init.

I'm not sure how it's complex, actually I feel it's too simplified. I'd like 
events
that mean more - eg. an AppletLifeCycleEvent and listener, or a 
StageLifeCycleEvent
and listener (and indeed I had done this, with the use of Generics, but after I
couldn't get it to compile, I opted for this route instead), but this would mean
exposing some things. I wanted to make the Stage LifeCycleAware and also make 
the
CoreApplet LifeCycleAware, but that would mean making it easier to get a hold of
those objects. Currently, I can get the Stage by getting the AppContext from the
CoreSystem, but there isn't a way to get the CoreApplet. Making these individual
classes LifeCycleAware, and allowing them to dispatch their own events means 
that
developers can listen only where they want to. 

My Example used the initial scene to attach the listeners, however I had 
envisioned
actually using the LoadingScene to do this. Perhaps adding a location in the
LoadingScene specifically for adding LifeCycleEventListeners would give 
developers a
nice convenient place for these things?

Also, I realize that Scene is already "Life Cycle Aware" in sorts because 
scenes are
notified on load and unload. So these events probably do not need to be 
listened for,
I merely added them for completeness sake.

In the very least, it would be nice to be able to add life-cycle call backs to 
the
applet or at least the Stage. Having a clear location to execute something when 
the
application is being unloaded is the ultimate desire, I think. Perhaps you can 
break
the unload method out into 2 methods, one for the scene unloading and one for 
the
application being unloaded?

Original comment by elbe...@gmail.com on 31 Mar 2008 at 10:18

GoogleCodeExporter commented 9 years ago
Added Stage.invokeOnShutdown(Runnable), in SVN. Startup code can happen in the 
first scene's constructor or 
load() method.

Original comment by brack...@gmail.com on 27 Apr 2008 at 1:43