Closed nettlep closed 10 years ago
If you want progress on the vectorization we need the loading to report how far it is
To implement this, I had to re-work some of the initialization for scenes, moving some of the code from the didMoveToView(...) into its own function that's called on a separate thread. With this, the guy moves along the progress bar correctly now.
The first time you load a level, the progress bar moves along rather slowly to start with but then picks up speed. This is because those are the portions of the progress that are performing the vectorization. Subsequent runs will used the cached data and the progress bar zooms along nicely.
Important -- The progress bar no longer monitors progress of the workers like it used to. It was simpler to use just the vectorization code for progress and not have to also take those workers into account. The only real worker that was being "progressed" was the one that deserializes the level, which happens almost in no time. Therefore, if there is any code in the book that discusses this, it will likely need to be modified.
I need to modify my part then. Can you shed some more light on how the vectorization reports progress?
Sure (and sorry to change that up on you.)
When we create the scene (during the loading of a new level), we're creating a GameScene. This class is a subclass of PaperScene, which represents a sketched scene. The progress node is handed to that newly created scene so it can access the progress node to update its position. This shows up in loadLevel() as a new worker:
// Prepare the level
work.append {
if scene != nil {
// Give the scene access to the progress loader so it can update progress while it loads
scene!.progressNode = self.progressLoader
// Prepare the level, which takes time
scene!.prepareLevel()
}
return scene
}
The process that does the vectorization is PaperScene.convertToSketch(), which is really just a wrapper around SketchRender.attachSketchNodes() that does the real work. The progress node is passed along to that method.
So the real work is done in attachSketchNodes(), which locates any node that should be converted to sketch and replaces the single node with 4 children that represent the animated sketches. It is during this process that the total nodes are counted and then converted. During this conversion process, it uses the total and the current progress through that count to determine the progress.
I hope that's clear...