diff --git "a/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" "b/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" index 6bcbec5..c190a5a 100644 --- "a/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" +++ "b/docs/01_Env/ENV_01_\347\222\260\345\242\203\346\247\213\347\257\211\343\203\273\346\212\200\350\241\223\343\202\271\343\202\277\343\203\203\343\202\257.txt" @@ -107,7 +107,7 @@ │ ├── index.ts # 共有エクスポート │ ├── config/ │ │ ├── index.ts # 設定エクスポート - │ │ └── gameConfig.ts # 共通定数 + │ │ ├── gameConfig.ts # 共通定数 │ │ └── networkConfig.ts # 通信設定 │ ├── domains/ │ │ ├── gridMap/ @@ -120,6 +120,12 @@ │ │ └── room.type.ts # ルーム型 │ └── protocol/ │ └── events.ts # 通信イベント定義 + ├── test/ # テスト用スクリプト群 + │ ├── load-bot.constants.ts # 負荷テスト定数 + │ ├── load-bot.ts # 負荷テスト実行 + │ ├── node_modules/ # テスト依存 + │ ├── package.json # テスト依存・スクリプト + │ └── tsconfig.json # テストTS設定 ├── .gitignore # Git除外設定 ├── .npmrc # pnpm設定 ├── docker-compose.prod.yml # 本番Compose定義 diff --git a/packages/shared/src/config/gameConfig.ts b/packages/shared/src/config/gameConfig.ts index 7d0ef50..681f9dd 100644 --- a/packages/shared/src/config/gameConfig.ts +++ b/packages/shared/src/config/gameConfig.ts @@ -23,7 +23,7 @@ // プレイヤー挙動設定 PLAYER_RADIUS: 10, // プレイヤー半径 - PLAYER_SPEED: 5, // 移動速度(ピクセル/秒) + PLAYER_SPEED: 5, // 60fps基準の1フレーム当たりの移動量(px) // チームカラー設定 // teamId インデックス順カラー配列 diff --git a/test/load-bot.constants.ts b/test/load-bot.constants.ts index 6383cfb..6331e98 100644 --- a/test/load-bot.constants.ts +++ b/test/load-bot.constants.ts @@ -6,7 +6,9 @@ export const BOTS = 20; export const DURATION_MS = 60_000; export const JOIN_DELAY_MS = 25; -export const MOVE_INTERVAL_MS = 200; +export const MOVE_TICK_MS = GAME_CONFIG.PLAYER_POSITION_UPDATE_MS; +export const BOT_SPEED = GAME_CONFIG.PLAYER_SPEED; +export const BOT_RADIUS = GAME_CONFIG.PLAYER_RADIUS; export const START_DELAY_MS = 800; export const MAX_X = GAME_CONFIG.MAP_WIDTH; export const MAX_Y = GAME_CONFIG.MAP_HEIGHT; diff --git a/test/load-bot.ts b/test/load-bot.ts index abe3946..c458ed9 100644 --- a/test/load-bot.ts +++ b/test/load-bot.ts @@ -5,7 +5,9 @@ JOIN_DELAY_MS, MAX_X, MAX_Y, - MOVE_INTERVAL_MS, + MOVE_TICK_MS, + BOT_SPEED, + BOT_RADIUS, ROOM_ID, SOCKET_PATH, SOCKET_TRANSPORTS, @@ -50,7 +52,9 @@ joinDelayMs: JOIN_DELAY_MS, startGame: START_GAME, startDelayMs: START_DELAY_MS, - moveIntervalMs: MOVE_INTERVAL_MS, + moveTickMs: MOVE_TICK_MS, + botSpeed: BOT_SPEED, + botRadius: BOT_RADIUS, maxX: MAX_X, maxY: MAX_Y, }); @@ -90,6 +94,41 @@ }); let moveTimer: NodeJS.Timeout | null = null; + let posX = BOT_RADIUS + Math.random() * (MAX_X - BOT_RADIUS * 2); + let posY = BOT_RADIUS + Math.random() * (MAX_Y - BOT_RADIUS * 2); + let dirX = 1; + let dirY = 0; + + const updateDirection = () => { + const angle = Math.random() * Math.PI * 2; + dirX = Math.cos(angle); + dirY = Math.sin(angle); + }; + + const tickMove = () => { + const frameDelta = MOVE_TICK_MS / (1000 / 60); + posX += dirX * BOT_SPEED * frameDelta; + posY += dirY * BOT_SPEED * frameDelta; + + if (posX < BOT_RADIUS) { + posX = BOT_RADIUS; + updateDirection(); + } else if (posX > MAX_X - BOT_RADIUS) { + posX = MAX_X - BOT_RADIUS; + updateDirection(); + } + + if (posY < BOT_RADIUS) { + posY = BOT_RADIUS; + updateDirection(); + } else if (posY > MAX_Y - BOT_RADIUS) { + posY = MAX_Y - BOT_RADIUS; + updateDirection(); + } + + socket.emit("move", { x: posX, y: posY }); + counters.moveSent += 1; + }; socket.on("connect", () => { counters.connected += 1; @@ -109,13 +148,9 @@ socket.on("game-start", () => { counters.gameStarts += 1; // ゲーム開始後に定期的な移動イベントを送信。 - if (!moveTimer && MOVE_INTERVAL_MS > 0) { - moveTimer = setInterval(() => { - const x = Math.random() * MAX_X; - const y = Math.random() * MAX_Y; - socket.emit("move", { x, y }); - counters.moveSent += 1; - }, MOVE_INTERVAL_MS); + if (!moveTimer && MOVE_TICK_MS > 0) { + updateDirection(); + moveTimer = setInterval(tickMove, MOVE_TICK_MS); } });