123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import { Asset, Component } from "cc";
- import { FrameworkConf } from "../config/FrameworkConf";
- import { Framework } from "../Framework";
- import { resLoader } from "./ResLoader";
- class ResQueue {
- private _load_timer_uuid = 0;
- private _load_task_quene: { priority: number, bundle: string, url: string, type: typeof Asset, completed: (error: Error, res: Asset) => void, target: Component }[] = [];
- private _preload_timer_uuid = 0;
- private _preload_task_quene: { priority: number, bundle: string, url: string, type: typeof Asset }[] = [];
- constructor() {
- this._load_timer_uuid = 0;
- this._load_task_quene = [];
- this._preload_timer_uuid = 0;
- this._preload_task_quene = [];
- }
-
- pushLoad(priority: number, bundle: string, url: string, type: typeof Asset, completed: (error: Error, res: Asset) => void, target: Component) {
- this._load_task_quene.push({ priority: priority, bundle: bundle, url: url, type: type, completed: completed, target: target });
- this._load_task_quene.sort((a, b) => {
- return b.priority - a.priority;
- });
- if (this._load_timer_uuid <= 0) {
- this._load_timer_uuid = Framework.time.schedule(() => {
- for (let i = 0; i < FrameworkConf.frame_load_count; ++i) {
- let task = this._load_task_quene.shift();
- if (task) {
- resLoader.load(task.bundle, task.url, task.type, task.completed.bind(task.target));
- } else {
- (this._load_timer_uuid > 0) && Framework.time.unschedule(this._load_timer_uuid);
- this._load_timer_uuid = -1;
- break;
- }
- }
- });
- }
- }
-
- pushPreload(priority: number, bundle: string, url: string, type: typeof Asset) {
- this._preload_task_quene.push({ priority: priority, bundle: bundle, url: url, type: type });
- this._preload_task_quene.sort((a, b) => {
- return b.priority - a.priority;
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- private totalAb: number = 0;
-
- private nowAb: number = 0;
-
- private now: number = 0;
-
- private total: number = 0;
-
- loadPreload(progress: Function, endFunc: Function) {
- this.total = this._preload_task_quene.length - 1
- if (this._preload_timer_uuid <= 0) {
- this._preload_timer_uuid = Framework.time.schedule(() => {
- for (let i = 0; i < FrameworkConf.frame_preload_count; ++i) {
- let task = this._preload_task_quene.shift();
- this.now++
- if (task) {
- resLoader.preload(task.bundle, task.url, task.type);
- progress(this.now, this.total)
- } else {
- (this._preload_timer_uuid > 0) && Framework.time.unschedule(this._preload_timer_uuid);
- this._preload_timer_uuid = -1;
- endFunc()
- break;
- }
- }
- });
- }
- }
- }
- export let LoadQueue = new ResQueue();
|