2026-06-18 18:59:56 +09:00
|
|
|
"use strict";
|
|
|
|
|
let last = nowSec();
|
|
|
|
|
let statsTimer = 0;
|
|
|
|
|
let fpsTimer = 0;
|
|
|
|
|
let fpsFrames = 0;
|
2026-06-19 14:00:48 +09:00
|
|
|
let perfResizeTimer = 0;
|
|
|
|
|
let lastPerfLevel = 0;
|
2026-06-18 18:59:56 +09:00
|
|
|
window.__tarinaiFps = 0;
|
2026-06-20 23:27:39 +09:00
|
|
|
|
|
|
|
|
function setLoadingProgress(text = "", ratio = 0) {
|
|
|
|
|
const screen = document.getElementById("loadingScreen");
|
|
|
|
|
if (!screen) return;
|
|
|
|
|
const pct = clamp(Number(ratio) || 0, 0, 1);
|
|
|
|
|
const label = document.getElementById("loadingText");
|
|
|
|
|
const bar = document.getElementById("loadingBar");
|
|
|
|
|
const percent = document.getElementById("loadingPercent");
|
|
|
|
|
if (label && text) label.textContent = text;
|
|
|
|
|
if (bar) bar.style.width = `${Math.round(pct * 100)}%`;
|
|
|
|
|
if (percent) percent.textContent = `${Math.round(pct * 100)}%`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideLoadingScreen() {
|
|
|
|
|
setLoadingProgress("\u8d77\u52d5\u5b8c\u4e86", 1);
|
|
|
|
|
const screen = document.getElementById("loadingScreen");
|
|
|
|
|
if (!screen) return;
|
|
|
|
|
window.setTimeout(() => screen.classList.add("hidden"), 120);
|
|
|
|
|
}
|
2026-06-18 18:59:56 +09:00
|
|
|
function loop() {
|
|
|
|
|
const t = nowSec();
|
|
|
|
|
const rawDt = t - last;
|
|
|
|
|
const dt = clamp(rawDt, 0, 0.05);
|
|
|
|
|
last = t;
|
|
|
|
|
fpsTimer += rawDt;
|
|
|
|
|
fpsFrames += 1;
|
|
|
|
|
if (fpsTimer >= 0.5) {
|
|
|
|
|
window.__tarinaiFps = Math.round(fpsFrames / Math.max(fpsTimer, 0.001));
|
|
|
|
|
fpsTimer = 0;
|
|
|
|
|
fpsFrames = 0;
|
|
|
|
|
}
|
|
|
|
|
world.update(dt);
|
|
|
|
|
render();
|
|
|
|
|
statsTimer += dt;
|
2026-06-19 02:27:19 +09:00
|
|
|
const perf = world.performanceLevel ? world.performanceLevel() : 0;
|
2026-06-19 14:00:48 +09:00
|
|
|
perfResizeTimer += rawDt;
|
|
|
|
|
if (perfResizeTimer > 1.5) {
|
|
|
|
|
if (perf !== lastPerfLevel) {
|
|
|
|
|
lastPerfLevel = perf;
|
|
|
|
|
resizeCanvas();
|
|
|
|
|
}
|
|
|
|
|
perfResizeTimer = 0;
|
|
|
|
|
}
|
2026-06-19 02:27:19 +09:00
|
|
|
const statsInterval = perf >= 3 ? 1.20 : perf === 2 ? 0.92 : perf === 1 ? 0.68 : 0.48;
|
|
|
|
|
if (statsTimer > statsInterval) {
|
2026-06-18 18:59:56 +09:00
|
|
|
renderStats();
|
|
|
|
|
statsTimer = 0;
|
|
|
|
|
}
|
|
|
|
|
requestAnimationFrame(loop);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-20 23:27:39 +09:00
|
|
|
setLoadingProgress("\u521d\u671f\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u4e2d", 0.08);
|
|
|
|
|
loadImages(null, (done, total) => {
|
|
|
|
|
const p = total > 0 ? done / total : 1;
|
|
|
|
|
setLoadingProgress(`\u521d\u671f\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u4e2d ${done}/${total}`, 0.08 + p * 0.46);
|
|
|
|
|
}).then(() => {
|
|
|
|
|
setLoadingProgress("UI\u3092\u6e96\u5099\u4e2d", 0.62);
|
2026-06-18 18:59:56 +09:00
|
|
|
bindUI();
|
2026-06-20 23:27:39 +09:00
|
|
|
setLoadingProgress("\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u69cb\u7bc9\u4e2d", 0.72);
|
2026-06-19 14:00:48 +09:00
|
|
|
applyFieldLayout("garden");
|
|
|
|
|
world.reset(null, "garden");
|
2026-06-18 18:59:56 +09:00
|
|
|
selectTool("observe");
|
2026-06-20 23:27:39 +09:00
|
|
|
setLoadingProgress("\u8868\u793a\u3092\u521d\u671f\u5316\u4e2d", 0.84);
|
2026-06-18 18:59:56 +09:00
|
|
|
renderLog(world.logs);
|
|
|
|
|
renderArchive();
|
|
|
|
|
render();
|
|
|
|
|
renderStats();
|
|
|
|
|
syncTopButtons();
|
2026-06-19 23:22:15 +09:00
|
|
|
if (typeof startBackgroundImageLoading === "function") startBackgroundImageLoading();
|
2026-06-20 23:27:39 +09:00
|
|
|
setLoadingProgress("\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u59cb\u4e2d", 0.94);
|
2026-06-18 18:59:56 +09:00
|
|
|
loop();
|
2026-06-20 23:27:39 +09:00
|
|
|
requestAnimationFrame(hideLoadingScreen);
|
2026-06-18 18:59:56 +09:00
|
|
|
});
|