-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dmouton
committed
Oct 19, 2017
1 parent
5ec612c
commit b4857b1
Showing
9 changed files
with
165 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,57 @@ | ||
package org.tamina.net; | ||
|
||
import js.Promise; | ||
import org.tamina.log.QuickLogger; | ||
import js.Error; | ||
|
||
class AssetCompositeLoader { | ||
|
||
private var _pool:Array<GroupURL>; | ||
private var _resolve:Bool->Void; | ||
private var _reject:Array<Error>->Void; | ||
private var _errors:Array<Error>; | ||
|
||
public function new() { | ||
_pool = new Array<GroupURL>(); | ||
_errors = new Array<Error>(); | ||
} | ||
|
||
public function add(group:GroupURL):Void{ | ||
_pool.push(group); | ||
} | ||
|
||
public function start():Void{ | ||
loadNextGroup(); | ||
public function start():Promise<Bool>{ | ||
return new Promise(loadNextGroup); | ||
} | ||
|
||
private function loadNextGroup():Void { | ||
private function loadNextGroup(resolve:Bool->Void,reject:Array<Error>->Void):Void { | ||
_resolve = resolve; | ||
_reject = reject; | ||
if (_pool.length > 0) { | ||
var g = _pool.shift(); | ||
if(g.loadingType == AssetLoadingType.SEQUENCE){ | ||
var loader = new AssetListLoader(); | ||
loader.completeSignal.add(assetCompleteHandler); | ||
loader.errorSignal.add(assetErrorHandler); | ||
loader.load(g.toArray()); | ||
var loader = new AssetsSequenceLoader(); | ||
loader.load(g.toArray()).then(assetCompleteHandler).catchError(assetErrorHandler); | ||
} else { | ||
var loader = new AssetParallelLoader(); | ||
loader.completeSignal.add(assetCompleteHandler); | ||
loader.errorSignal.add(assetErrorHandler); | ||
loader.load(g.toArray()); | ||
loader.load(g.toArray()).then(assetCompleteHandler).catchError(assetErrorHandler); | ||
} | ||
} else { | ||
QuickLogger.info("ALL ASSETS LOADED"); | ||
//completeSignal.dispatch(); | ||
if(_errors.length == 0){ | ||
L.info("ALL ASSETS LOADED"); | ||
_resolve(true); | ||
} else { | ||
_reject(_errors); | ||
} | ||
} | ||
} | ||
|
||
private function assetCompleteHandler():Void { | ||
loadNextGroup(); | ||
private function assetCompleteHandler(value:Bool):Void { | ||
loadNextGroup(_resolve,_reject); | ||
} | ||
|
||
private function assetErrorHandler():Void { | ||
loadNextGroup(); | ||
private function assetErrorHandler(errors:Array<Error>):Void { | ||
_errors = _errors.concat(errors); | ||
loadNextGroup(_resolve,_reject); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,45 @@ | ||
package org.tamina.net; | ||
|
||
import js.Promise; | ||
import js.Error; | ||
import org.tamina.log.QuickLogger; | ||
|
||
class AssetParallelLoader { | ||
class AssetParallelLoader extends BaseAssetsLoader{ | ||
|
||
private var _pool:Array<AssetURL>; | ||
private var _remainingAssetNumber:Int=0; | ||
|
||
public function new() { | ||
_pool = new Array<AssetURL>(); | ||
super(); | ||
} | ||
|
||
public function load(assets:Array<AssetURL>):Void { | ||
override public function load(assets:Array<AssetURL>):Promise<Bool> { | ||
_pool = assets; | ||
_remainingAssetNumber = _pool.length; | ||
start(); | ||
return new Promise(start); | ||
} | ||
|
||
private function start():Void{ | ||
private function start(resolve:Bool->Void,reject:Array<Error>->Void):Void{ | ||
_resolve = resolve; | ||
_reject = reject; | ||
for(i in 0..._pool.length){ | ||
var l = new AssetLoader(); | ||
l.completeSignal.add(assetCompleteHandler); | ||
l.errorSignal.add(assetErrorHandler); | ||
l.load(_pool[i]); | ||
l.load(_pool[i]).then(assetCompleteHandler).catchError(assetErrorHandler); | ||
} | ||
} | ||
|
||
private function assetCompleteHandler():Void { | ||
private function assetCompleteHandler(value:Bool):Void { | ||
_remainingAssetNumber--; | ||
if(_remainingAssetNumber == 0){ | ||
//completeSignal.dispatch(); | ||
end(); | ||
} | ||
} | ||
|
||
private function assetErrorHandler():Void { | ||
QuickLogger.error('error while loading asset'); | ||
private function assetErrorHandler(error:Error):Void { | ||
L.error('error while loading asset'); | ||
_remainingAssetNumber--; | ||
_errors.push(error); | ||
if(_remainingAssetNumber == 0){ | ||
//completeSignal.dispatch(); | ||
end(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.tamina.net; | ||
|
||
import js.Promise; | ||
import js.Error; | ||
|
||
class AssetsSequenceLoader extends BaseAssetsLoader { | ||
|
||
public function new() { | ||
super(); | ||
} | ||
|
||
override public function load(assets:Array<AssetURL>):Promise<Bool> { | ||
_pool = assets; | ||
return new Promise(loadNextAsset); | ||
} | ||
|
||
private function assetCompleteHandler(value:Bool):Void { | ||
loadNextAsset(_resolve,_reject); | ||
} | ||
|
||
private function assetErrorHandler(error:Error):Void { | ||
_errors.push(error); | ||
loadNextAsset(_resolve,_reject); | ||
} | ||
|
||
private function loadNextAsset(resolve:Bool->Void,reject:Array<Error>->Void):Void { | ||
_resolve = resolve; | ||
_reject = reject; | ||
if (_pool.length > 0) { | ||
_loader.load(_pool.shift()).then(assetCompleteHandler).catchError(assetErrorHandler); | ||
} else { | ||
end(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.tamina.net; | ||
|
||
import js.Promise; | ||
import js.Error; | ||
|
||
class BaseAssetsLoader { | ||
|
||
private var _pool:Array<AssetURL>; | ||
private var _loader:AssetLoader; | ||
private var _resolve:Bool->Void; | ||
private var _reject:Array<Error>->Void; | ||
private var _errors:Array<Error>; | ||
|
||
public function new() { | ||
_pool = new Array<AssetURL>(); | ||
_loader = new AssetLoader(); | ||
_errors = new Array<Error>(); | ||
} | ||
|
||
public function load(assets:Array<AssetURL>):Promise<Bool> { | ||
_pool = assets; | ||
return null; | ||
} | ||
|
||
private function end():Void{ | ||
if(_errors.length == 0){ | ||
_resolve(true); | ||
} else { | ||
_reject(_errors); | ||
} | ||
} | ||
} |
Oops, something went wrong.