新增 CoroutineManager 协同程序

This commit is contained in:
yhh
2020-08-28 19:12:21 +08:00
parent 7a308f76b6
commit 358e899e8b
17 changed files with 760 additions and 35 deletions

View File

@@ -198,6 +198,7 @@ declare module es {
_nextScene: Scene;
_sceneTransition: SceneTransition;
_globalManagers: GlobalManager[];
_coroutineManager: CoroutineManager;
_timerManager: TimerManager;
constructor();
static readonly Instance: Core;
@@ -207,6 +208,7 @@ declare module es {
static registerGlobalManager(manager: es.GlobalManager): void;
static unregisterGlobalManager(manager: es.GlobalManager): void;
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
static startCoroutine(enumerator: IEnumerator): CoroutineImpl;
static schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
onOrientationChanged(): void;
draw(): Promise<void>;
@@ -2064,6 +2066,19 @@ declare module es {
equals(other: Pair<T>): boolean;
}
}
declare module es {
class Pool<T> {
private static _objectQueue;
static warmCache(type: any, cacheCount: number): void;
static trimCache(cacheCount: number): void;
static clearCache(): void;
static obtain<T>(type: any): T;
static free<T>(obj: T): void;
}
interface IPoolable {
reset(): any;
}
}
declare class RandomUtils {
static randrange(start: number, stop: number, step?: number): number;
static randint(a: number, b: number): number;
@@ -2264,6 +2279,46 @@ declare module es {
initialized: boolean;
}
}
declare module es {
interface ICoroutine {
stop(): any;
setUseUnscaledDeltaTime(useUnscaledDeltaTime: any): ICoroutine;
}
class Coroutine {
static waitForSeconds(seconds: number): WaitForSeconds;
}
class WaitForSeconds {
static waiter: WaitForSeconds;
waitTime: number;
wait(seconds: number): WaitForSeconds;
}
}
declare module es {
class CoroutineImpl implements ICoroutine, IPoolable {
enumerator: IEnumerator;
waitTimer: number;
isDone: boolean;
waitForCoroutine: CoroutineImpl;
useUnscaledDeltaTime: boolean;
stop(): void;
setUseUnscaledDeltaTime(useUnscaledDeltaTime: any): es.ICoroutine;
prepareForuse(): void;
reset(): void;
}
interface IEnumerator {
current: any;
moveNext(): boolean;
reset(): any;
}
class CoroutineManager extends GlobalManager {
_isInUpdate: boolean;
_unblockedCoroutines: CoroutineImpl[];
_shouldRunNextFrame: CoroutineImpl[];
startCoroutine(enumerator: IEnumerator): CoroutineImpl;
update(): void;
tickCoroutine(coroutine: CoroutineImpl): boolean;
}
}
declare module es {
class TouchState {
x: number;