perf: 전투 시뮬레이터 시작 payload를 줄인다
권위 실행 context를 화면 진입 때 한 번 전달하고 준비 응답은 seed base만 반환한다. 반복별 seed 배열은 결정적 파생값으로 대체하되 구형 queue seed 우선순위와 고정 seed 동작을 보존한다.
This commit is contained in:
@@ -90,6 +90,9 @@ export interface BattleSimEnvironment {
|
||||
scenarioEffect: ScenarioEffectKey | null;
|
||||
}
|
||||
|
||||
export const buildBattleSimSeedBase = (request: Pick<BattleSimRequestPayload, 'seed'>): string | null =>
|
||||
request.seed ? null : randomUUID();
|
||||
|
||||
export const buildBattleSimEnvironment = async (
|
||||
worldState: WorldStateRow,
|
||||
profileFallback: string
|
||||
@@ -138,10 +141,11 @@ export const buildBattleSimJobPayload = async (
|
||||
profileFallback: string
|
||||
): Promise<BattleSimJobPayload> => {
|
||||
const environment = await buildBattleSimEnvironment(worldState, profileFallback);
|
||||
const seedBase = buildBattleSimSeedBase(request);
|
||||
|
||||
return {
|
||||
...request,
|
||||
seeds: request.seed ? [] : Array.from({ length: request.repeatCnt }, () => randomUUID()),
|
||||
...(seedBase ? { seedBase } : {}),
|
||||
unitSet: environment.unitSet,
|
||||
config: environment.config,
|
||||
time: {
|
||||
|
||||
@@ -11,7 +11,11 @@ import {
|
||||
readOnlyAuthedProcedure,
|
||||
router,
|
||||
} from '../../trpc.js';
|
||||
import { buildBattleSimEnvironment, buildBattleSimJobPayload } from '../../battleSim/environment.js';
|
||||
import {
|
||||
buildBattleSimEnvironment,
|
||||
buildBattleSimJobPayload,
|
||||
buildBattleSimSeedBase,
|
||||
} from '../../battleSim/environment.js';
|
||||
import { zBattleSimJobId, zBattleSimRequest } from '../../battleSim/schema.js';
|
||||
import {
|
||||
BATTLE_SIM_CITY_LEVELS,
|
||||
@@ -62,17 +66,9 @@ const resolveDexValue = (meta: Record<string, unknown>, key: string): number =>
|
||||
};
|
||||
|
||||
export const battleRouter = router({
|
||||
prepareSimulation: accessReadOnlyAuthedInputProcedure(zBattleSimRequest).mutation(async ({ ctx, input }) => {
|
||||
const worldState = await ctx.db.worldState.findFirst();
|
||||
if (!worldState) {
|
||||
throw new TRPCError({
|
||||
code: 'PRECONDITION_FAILED',
|
||||
message: 'World state is not initialized.',
|
||||
});
|
||||
}
|
||||
|
||||
return buildBattleSimJobPayload(worldState, input, ctx.profile.id);
|
||||
}),
|
||||
prepareSimulation: accessReadOnlyAuthedInputProcedure(zBattleSimRequest).mutation(({ input }) => ({
|
||||
seedBase: buildBattleSimSeedBase(input),
|
||||
})),
|
||||
simulate: accessReadOnlyAuthedInputProcedure(zBattleSimRequest).mutation(async ({ ctx, input }) => {
|
||||
const worldState = await ctx.db.worldState.findFirst();
|
||||
if (!worldState) {
|
||||
@@ -104,30 +100,15 @@ export const battleRouter = router({
|
||||
const environment = await buildBattleSimEnvironment(worldState, ctx.profile.id);
|
||||
const [traits, items] = await Promise.all([loadBattleSimTraitOptions(), loadBattleSimItemOptions()]);
|
||||
|
||||
const crewTypes = (environment.unitSet.crewTypes ?? [])
|
||||
.filter((crewType) => crewType.armType !== environment.config.armTypes.castle)
|
||||
.map((crewType) => ({
|
||||
id: crewType.id,
|
||||
name: crewType.name,
|
||||
armType: crewType.armType,
|
||||
}));
|
||||
|
||||
return {
|
||||
world: {
|
||||
startYear: environment.startYear,
|
||||
currentYear: worldState.currentYear,
|
||||
currentMonth: worldState.currentMonth,
|
||||
},
|
||||
config: {
|
||||
maxTrainByWar: environment.config.maxTrainByWar,
|
||||
maxAtmosByWar: environment.config.maxAtmosByWar,
|
||||
maxTrainByCommand: environment.config.maxTrainByCommand,
|
||||
maxAtmosByCommand: environment.config.maxAtmosByCommand,
|
||||
},
|
||||
unitSet: {
|
||||
defaultCrewTypeId: environment.unitSet.defaultCrewTypeId ?? crewTypes[0]?.id ?? 0,
|
||||
crewTypes,
|
||||
},
|
||||
config: environment.config,
|
||||
unitSet: environment.unitSet,
|
||||
scenarioEffect: environment.scenarioEffect,
|
||||
nationTypes: traits.nationTypes,
|
||||
eventDomesticTraits: traits.eventDomesticTraits,
|
||||
warTraits: traits.warTraits,
|
||||
|
||||
Reference in New Issue
Block a user