feat: Introduce robust diagnostic setup with fixed-size renderer, enhanced logging, system checks, and improved error handling for initial game components.

This commit is contained in:
2026-01-03 07:16:53 +00:00
parent ad5b025a8b
commit 31a4a5ee9b
7 changed files with 155 additions and 44 deletions

View File

@@ -1,52 +1,71 @@
import { Graphics } from './Graphics.js';
import { World } from './World.js';
import { Player } from './Player.js';
import * as THREE from 'three';
export class Game {
constructor() {
this.graphics = new Graphics();
this.world = new World(this.graphics.scene);
this.player = new Player(this.graphics.camera, this.world.colliders);
window.log('Game constructor start');
try {
this.graphics = new Graphics();
this.world = new World(this.graphics.scene);
this.player = new Player(this.graphics.camera, this.world.colliders);
window.log('All components created successfully');
} catch (e) {
window.log('CRITICAL ERROR during setup: ' + e.message);
}
this.isRunning = false;
this.lastTime = 0;
this.setupUI();
}
setupUI() {
const startScreen = document.getElementById('start-screen');
const hud = document.getElementById('hud');
if (!startScreen) {
window.log('ERROR: start-screen not found');
return;
}
startScreen.addEventListener('click', () => {
this.player.lockControls();
window.log('Start screen clicked');
if (this.player) {
this.player.lockControls();
}
startScreen.style.display = 'none';
hud.style.display = 'block';
if (hud) hud.style.display = 'block';
this.isRunning = true;
window.log('Game isRunning = true');
});
}
start() {
this.graphics.init();
this.world.load();
// Add player to scene if needed, but usually player moves camera
this.graphics.scene.add(this.player.getObject());
window.log('Game.start() begin');
try {
if (this.world) this.world.load();
if (this.player) {
const playerObj = this.player.getObject();
this.graphics.scene.add(playerObj);
}
window.log('World/Player loading complete');
} catch (e) {
window.log('ERROR in Game.start(): ' + e.message);
}
requestAnimationFrame(this.loop.bind(this));
window.log('Animation loop requested');
}
loop(time) {
requestAnimationFrame(this.loop.bind(this));
const dt = this.lastTime === 0 ? 0 : Math.min((time - this.lastTime) / 1000, 0.1); // Cap dt
const dt = this.lastTime === 0 ? 0 : Math.min((time - this.lastTime) / 1000, 0.1);
this.lastTime = time;
if (this.isRunning) {
this.player.update(dt);
// this.world.update(dt);
}
this.graphics.render();
requestAnimationFrame(this.loop.bind(this));
}
}