@ flare- engine/ 核心
核心运行时间 - GameLoop (固定时间步,与上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上下上上上上上上上上上上上上上上上上上上上上上下上上下上下上上下上下上下上上上上上上上上上下上上上下上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上上下上上上上上上上上上上下上上下上上上上上上上上下上上上上上上上上上上上上上上上上上上下上上上上上上上上上上上上上上上上上上上上上上上上上上上下上上下上上上上上上上上上上上上, Clock (德尔塔+缩放时间), AppLifecycle (背景/前钩), ScreenManager (FIT / FILL / STRETCH + 安全区域), CoroutineManager (基于基因的测序), Pool<T> (零分配重用).
安装
bun add @flare-engine/core
使用量
import { GameLoop, Pool } from '@flare-engine/core';
function updateGame(dt: number): void {
// advance game state by dt seconds
}
const loop = new GameLoop({ fixedDt: 1 / 60 });
loop.onUpdate.add((dt) => updateGame(dt));
loop.start();
const bullets = new Pool(() => ({ x: 0, y: 0, vx: 0, vy: 0 }));
const b = bullets.acquire();
bullets.release(b);
锦衣裙
yield 一个数字等待 这么多缩放秒, undefined 等待一个框架,或承诺
等着 一个胸围完全结束了 三种方式之一——完成, cancelled,或 failed - 和
handle.done 三者皆为真相. cancel() 财务报告和审定财务报表 clear() 两者都关闭生成器( 一个场景)
撕裂是coroutine认为的取消,所以 finally 块是
清理工作——在完成、取消、拆卸和失败时进行。 一个被拒绝的承诺是:
把它扔进发电机里 抓住它继续前进 或让它用 failed 设定 :
import { CoroutineManager } from '@flare-engine/core';
const coroutines = new CoroutineManager();
let bannerVisible = false;
const handle = coroutines.start(
(function* () {
try {
bannerVisible = true;
yield 2; // seconds, scaled time
yield fetch('/api/score'); // a rejection is thrown into the generator
yield undefined; // one frame
} finally {
bannerVisible = false; // runs on completion, cancel(), clear() and failure
}
})(),
);
// each frame
coroutines.update(1 / 60);
if (handle.failed) {
console.warn('score fetch failed', handle.error);
} else if (handle.cancelled) {
// ended early — cancel(), or the scene's clear() tore it down
}
handle.cancel(); // no-op once done; otherwise the finally block runs now
失败永远不会被重新评为无所顾忌的拒绝——手柄是唯一的通道,所以保留它
如果你需要知道的话。 测试 handle.failed 而不是说 handle.error: 一个赤裸的 reject() 拒绝
与 undefined。 。 。 .
见 API 规格。 。 。 .
许可证
阿帕奇 - 2.0