50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import { initWorld, onWindowResize } from './world.js';
|
|
import { initAgents, updateAgents, getAgentCount } from './agents.js';
|
|
import { initEffects, updateEffects } from './effects.js';
|
|
import { initUI, updateUI } from './ui.js';
|
|
import { initInteraction } from './interaction.js';
|
|
import { initWebSocket, getConnectionState, getJobCount } from './websocket.js';
|
|
|
|
let frameCount = 0;
|
|
let lastFpsTime = performance.now();
|
|
let currentFps = 0;
|
|
|
|
function main() {
|
|
const { scene, camera, renderer } = initWorld();
|
|
|
|
initEffects(scene);
|
|
initAgents(scene);
|
|
initInteraction(camera, renderer);
|
|
initUI();
|
|
initWebSocket(scene);
|
|
|
|
window.addEventListener('resize', () => onWindowResize(camera, renderer));
|
|
|
|
function animate() {
|
|
requestAnimationFrame(animate);
|
|
|
|
const now = performance.now();
|
|
frameCount++;
|
|
if (now - lastFpsTime >= 1000) {
|
|
currentFps = Math.round(frameCount * 1000 / (now - lastFpsTime));
|
|
frameCount = 0;
|
|
lastFpsTime = now;
|
|
}
|
|
|
|
updateEffects(now);
|
|
updateAgents(now);
|
|
updateUI({
|
|
fps: currentFps,
|
|
agentCount: getAgentCount(),
|
|
jobCount: getJobCount(),
|
|
connectionState: getConnectionState(),
|
|
});
|
|
|
|
renderer.render(scene, camera);
|
|
}
|
|
|
|
animate();
|
|
}
|
|
|
|
main();
|