feat: Implement Event Deck, Monster Spawning, and AI Movement

This commit is contained in:
2026-01-05 00:40:12 +01:00
parent 056217437c
commit b619e4cee4
7 changed files with 421 additions and 35 deletions

View File

@@ -467,33 +467,52 @@ export class GameRenderer {
}
}
// Optimized getTexture with pending request queue
getTexture(path, onLoad) {
if (!this.textureCache.has(path)) {
const tex = this.textureLoader.load(
path,
(texture) => {
texture.needsUpdate = true;
if (onLoad) onLoad(texture);
},
undefined,
(err) => {
console.error(`[TextureLoader] [Checked] ✗ Failed to load: ${path}`, err);
}
);
tex.magFilter = THREE.NearestFilter;
tex.minFilter = THREE.NearestFilter;
tex.colorSpace = THREE.SRGBColorSpace;
this.textureCache.set(path, tex);
} else {
// Already cached, call onLoad immediately if texture is ready
const cachedTex = this.textureCache.get(path);
if (onLoad && cachedTex.image) {
onLoad(cachedTex);
}
// 1. Check Cache
if (this.textureCache.has(path)) {
const tex = this.textureCache.get(path);
if (onLoad) onLoad(tex);
return;
}
return this.textureCache.get(path);
// 2. Check Pending Requests (Deduplication)
if (!this._pendingTextureRequests) this._pendingTextureRequests = new Map();
if (this._pendingTextureRequests.has(path)) {
this._pendingTextureRequests.get(path).push(onLoad);
return;
}
// 3. Start Load
this._pendingTextureRequests.set(path, [onLoad]);
this.textureLoader.load(
path,
(texture) => {
// Success
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
texture.colorSpace = THREE.SRGBColorSpace;
this.textureCache.set(path, texture);
// Execute all waiting callbacks
const callbacks = this._pendingTextureRequests.get(path);
if (callbacks) {
callbacks.forEach(cb => { if (cb) cb(texture); });
this._pendingTextureRequests.delete(path);
}
},
undefined, // onProgress
(err) => {
console.error(`[GameRenderer] Failed to load texture: ${path}`, err);
const callbacks = this._pendingTextureRequests.get(path);
if (callbacks) {
this._pendingTextureRequests.delete(path);
}
}
);
}
addTile(cells, type, tileDef, tileInstance) {