<commit_before>import Engine from "./engine";
import InputMgr from "./inputmgr";
import SceneMgr from "./scenemgr";
import {IScene} from "./scene";
import Scene from "./scene";
import State from "./state";
import Loop from "./loop";
import ResStack from "./resstack";
import {RequestAnimationFrame} from "./utilfuncs";
import * as G from "./global";
import GLResourceSet from "./gl_resource_set";

class St extends State<LoadingScene> {}
export class LoadingScene extends Scene<LoadingScene> {
	constructor(res: string[], nextScene: IScene) {
		super(0, new St());
		G.resource.loadFrame(
			res,
			()=> {
				try {
					G.scene.push(nextScene, true);
				} catch (e) {
					alert(e);
				}
			},
			()=> {
				alert("ERROR");
			}
		);
	}
}
type Alias_t = {[key: string]: string;};
function _MainLoop<T>(alias: Alias_t, base: string, cbMakeScene: ()=>IScene) {
	G.SetResource(new ResStack(base));
	G.resource.addAlias(alias);
	G.SetEngine(new Engine());
	G.SetInput(new InputMgr());
	G.SetScene(new SceneMgr(cbMakeScene()));
	G.SetGLRes(new GLResourceSet());
	G.glres.onContextRestored();
}
export function MainLoop<T>(alias: Alias_t, base: string, cbMakeScene: ()=>IScene) {
	_MainLoop(alias, base, cbMakeScene);

	RequestAnimationFrame(function Loop() {
		RequestAnimationFrame(Loop);
		G.scene.onDraw();
	});
	const loop = new Loop();
	loop.start(60, (tick) => {
		G.input.update();
		if(!G.scene.onUpdate(tick)) {
			loop.stop();
		}
	});
}
export function MainLoop_RF<T>(alias: Alias_t, base: string, cbMakeScene: ()=>IScene) {
	_MainLoop(alias, base, cbMakeScene);

	RequestAnimationFrame(function Loop() {
		RequestAnimationFrame(Loop);
		G.input.update();
		G.scene.onUpdate(1/60);
		G.scene.onDraw();
	});
}
<commit_msg>デバイスロスト時は描画ループを回さない<commit_after>import Engine from "./engine";
import InputMgr from "./inputmgr";
import SceneMgr from "./scenemgr";
import {IScene} from "./scene";
import Scene from "./scene";
import State from "./state";
import Loop from "./loop";
import ResStack from "./resstack";
import {RequestAnimationFrame} from "./utilfuncs";
import * as G from "./global";
import GLResourceSet from "./gl_resource_set";
import {gl} from "./global";

class St extends State<LoadingScene> {}
export class LoadingScene extends Scene<LoadingScene> {
	constructor(res: string[], nextScene: IScene) {
		super(0, new St());
		G.resource.loadFrame(
			res,
			()=> {
				try {
					G.scene.push(nextScene, true);
				} catch (e) {
					alert(e);
				}
			},
			()=> {
				alert("ERROR");
			}
		);
	}
}
type Alias_t = {[key: string]: string;};
function _MainLoop<T>(alias: Alias_t, base: string, cbMakeScene: ()=>IScene) {
	G.SetResource(new ResStack(base));
	G.resource.addAlias(alias);
	G.SetEngine(new Engine());
	G.SetInput(new InputMgr());
	G.SetScene(new SceneMgr(cbMakeScene()));
	G.SetGLRes(new GLResourceSet());
	G.glres.onContextRestored();
}
export function MainLoop<T>(alias: Alias_t, base: string, cbMakeScene: ()=>IScene) {
	_MainLoop(alias, base, cbMakeScene);

	RequestAnimationFrame(function Loop() {
		RequestAnimationFrame(Loop);
		if(gl.isContextLost())
			return;
		G.scene.onDraw();
	});
	const loop = new Loop();
	loop.start(60, (tick) => {
		G.input.update();
		if(!G.scene.onUpdate(tick)) {
			loop.stop();
		}
	});
}
export function MainLoop_RF<T>(alias: Alias_t, base: string, cbMakeScene: ()=>IScene) {
	_MainLoop(alias, base, cbMakeScene);

	RequestAnimationFrame(function Loop() {
		RequestAnimationFrame(Loop);
		G.input.update();
		G.scene.onUpdate(1/60);
		if(gl.isContextLost())
			return;
		G.scene.onDraw();
	});
}

{'fraction_non_alphanumeric': 0.17623984309330346, 'fraction_numerical': 0.0033622863547212102, 'mean_word_length': 4.586854460093897, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2706490', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1268, 'n_words': 278}