MassBattle Docsv1.19.20

Statistics.h

USTRUCT ×1

Source/MassBattle/Public/Fragments/Statistics.h

概述 Overview

玩家统计 fragment FStatistics——记录玩家身份(玩家 ID / 名称 / 头像)与战绩累计(总伤害、总击杀、总分值、总存活时长、自身价值)。带自旋锁(std::atomic<bool> 互斥)支持并行段安全累加;支持把统计记入另一实体(CreditToEntity)。拷贝构造 / 赋值逐字段复制。

Player statistics fragment FStatistics — records player identity (player ID / name / avatar) and accumulated performance (total damage, kills, score, survival time, self score). Carries a spin lock (std::atomic<bool> mutex) for safe accumulation from parallel sections; supports crediting stats to another entity (CreditToEntity). Copy constructor / assignment copy every field.

FStatistics USTRUCT

玩家统计 fragment(FA_MassBattleBaseFragment 派生)。含 FString / UTexture2DDynamic 成员,经 MASS_FRAGMENT_ACCEPT_NOT_TRIVIALLY_COPYABLE 声明为不可平凡拷贝;含 TArray 的 fragment 处理相同。

Player statistics fragment (derived from FA_MassBattleBaseFragment). Contains FString / UTexture2DDynamic members; declared via MASS_FRAGMENT_ACCEPT_NOT_TRIVIALLY_COPYABLE as not-trivially-copyable.

成员变量 Members

名称 Name类型 Type默认值说明 Description
LockFlagstd::atomic<bool> (private)false私有自旋锁标志。Private spin-lock flag.
bEnablebooltrue是否启用统计记录。Whether statistics recording is enabled.
CreditToEntityFEntityHandle—若设置且有效,所有分数 / 伤害 / 击杀将记入该实体而非自身。If set and valid, all score/damage/kills are credited to this entity instead of self.
PlayerIDFString"null"玩家 ID。Player ID.
PlayerNameFString"null"玩家名称。Player name.
PlayerProfileImageTObjectPtr<UTexture2DDynamic>nullptr玩家头像(动态纹理)。Player profile image (dynamic texture).
SelfScoreint321自身价值(被击杀时对手获得的分数)。Self score value (score granted to the killer).
TotalDamagefloat0总伤害。Total damage dealt.
TotalKillsint320总击杀。Total kills.
TotalScoreint320总分值。Total score.
TotalTimefloat0总存活时长。Total survival time.

方法 Methods

Lock void (const)

自旋获取锁:对 LockFlag 做 acquire 语义的 exchange,占用中则忙等。

Spins to acquire the lock: exchange on LockFlag with acquire semantics, busy-waiting while held.

Input

无参数。

No parameters.

Output

无返回值。副作用:锁被当前线程占用。

No return value. Side effect: the lock is held by the calling thread.

Unlock void (const)

释放锁:以 release 语义把 LockFlag 存回 false。

Releases the lock: stores false into LockFlag with release semantics.

Input

无参数。

No parameters.

Output

无返回值。副作用:锁释放,其它线程可获取。

No return value. Side effect: the lock is released for other threads.

管线角色 Pipeline Role

FStatistics 在 MassBattle 管线中的位置:伤害 / 击杀累计由多个处理器在并行段写入(加锁保护),读取方包括 MassBattleAgentBehaviorProcessor / MassBattleAgentMoveProcessor / MassBattleAgentMoveProcessorFP / MassBattleAgentReactionProcessor / MassBattleAgentRenderProcessor / MassBattleAgentTraceProcessor / MassBattleLootMonoProcessor(分数结算)。

Position of FStatistics in the MassBattle pipeline: damage/kill accumulation is written from parallel sections by multiple processors (lock-protected); readers include MassBattleAgentBehaviorProcessor, MassBattleAgentMoveProcessor / MassBattleAgentMoveProcessorFP, MassBattleAgentReactionProcessor, MassBattleAgentRenderProcessor, MassBattleAgentTraceProcessor and MassBattleLootMonoProcessor (score settlement).