From b515f7195f986edb64b3ec15b101e7d90cb434db Mon Sep 17 00:00:00 2001 From: root Date: Sun, 8 Mar 2026 21:10:00 +0000 Subject: [PATCH] feat(thought): integrate ThoughtSystem into game loop and socket broadcast Co-Authored-By: Claude Opus 4.6 --- server/src/game/GameLoop.ts | 4 ++++ server/src/network/SocketServer.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/server/src/game/GameLoop.ts b/server/src/game/GameLoop.ts index 0ffd0b3..d45801e 100644 --- a/server/src/game/GameLoop.ts +++ b/server/src/game/GameLoop.ts @@ -15,12 +15,14 @@ import { generateBackstory } from '../llm/backstoryGenerator.js'; import { createNarrationService, type NarrationService } from '../llm/narrationService.js'; import { narrationEmitter } from '../systems/narrationEmitter.js'; import type { EntityId } from '@dflike/shared'; +import { createThoughtSystem, type ThoughtSystem } from '../systems/thoughtSystem.js'; export class GameLoop { readonly world: World; readonly map: GameMap; readonly llmService: LlmService; readonly narrationService: NarrationService; + readonly thoughtSystem: ThoughtSystem; public followedEntityIds: Set = new Set(); private tick = 0; private interval: ReturnType | null = null; @@ -32,6 +34,7 @@ export class GameLoop { this.map = new GameMap(); this.llmService = createLlmService(); this.narrationService = createNarrationService(this.llmService); + this.thoughtSystem = createThoughtSystem(this.llmService, this.narrationService); this.setupMap(); this.spawnInitialNPCs(8); } @@ -93,6 +96,7 @@ export class GameLoop { narrationEmitter(this.world, this.narrationService, this.followedEntityIds); relationshipSystem(this.world); movementSystem(this.world); + this.thoughtSystem.update(this.world, this.followedEntityIds, this.tick); // Broadcast state periodically if (this.tick % BROADCAST_EVERY_N_TICKS === 0 && this.onBroadcast) { diff --git a/server/src/network/SocketServer.ts b/server/src/network/SocketServer.ts index e074f99..c1e8ab4 100644 --- a/server/src/network/SocketServer.ts +++ b/server/src/network/SocketServer.ts @@ -41,6 +41,10 @@ export class SocketServer { narrationService.onEventUpdated = (event) => { this.io.emit('narration-update', { id: event.id, narration: event.narration }); }; + + this.gameLoop.thoughtSystem.onThought = (data) => { + this.io.emit('npc-thought', data); + }; } private setupConnections(): void {