Protocol : Tick-Tac -Distributed Jitter Decoupler-
[EN]
Tick-Tac - Distributed Jitter Decoupler
[b]A lightweight performance framework that eliminates CPU spike loads caused by synchronized periodic Tick processing across both vanilla systems and multiple mods.[/b]
Overview
Tick-Tac distributes execution timing across components and pawns, preventing large numbers of periodic processes from running simultaneously.
It preserves vanilla behavior while smoothing CPU usage over time.
Architecture
Tick-Tac consists of two independent layers that can be used together:
V1 – Mod Framework Layer
Opt-in system for modded components
V2 – Vanilla Distribution Engine
Automatic distribution of core game systems
V1 handles what mods add
V2 handles what vanilla does
Both layers are implemented as separate class libraries and operate independently without conflict.
V1 – Mod Framework Layer
How it works
Assigns each component a deterministic execution slot based on type hash and instance ID.
For MOD Developers
HediffComp: Automatically distributed if CompPostTick is overridden
ThingComp / MapComponent / WorldComponent / GameComponent:
Add the following field to opt in:
public bool EnableTickTac = true;
Technical Details
Uses Harmony Prefix/Postfix to temporarily offset ticksGameInt per execution context
Stack-based nesting protection prevents double application
DynamicMethod delegates eliminate reflection overhead
Slot formula: (typeHash ^ assemblyHash) % 60
V2 – Vanilla Distribution Engine
Tick-Tac V2 extends the system into a vanilla-level scheduler, distributing core interval-based tick workloads without requiring mod-side integration.
Scope (Interval-Based Only)
Distribution is applied strictly to existing interval tick methods:
[b]Needs → NeedsTrackerTickInterval (150 ticks)
Interactions → InteractionsTrackerTickInterval (60 / 91 ticks)
JobTracker → JobTrackerTickInterval (60 ticks)[/b]
Vanilla execution frequency is preserved; only per-pawn timing is shifted.
Features
[b]Deterministic Per-Pawn Scheduling
Session seed + Pawn ID ensures stable distribution within a session
Responsiveness Preservation
Distribution is bypassed when immediate response is required:
Drafted pawns
Recently undrafted pawns (~30 ticks)
Mental states
Selective Scope Control
Optional animal support (experimental)
Technical Details
Harmony Prefix is used to gate execution of interval tick methods
Does not modify global tick flow or ticksGameInt
Offset generation via Gen.HashCombineInt(PawnID, SessionSeed)
Draft state tracked via lightweight dictionary
Cached FieldInfo eliminates reflection overhead
Save Compatibility & Safe Removal[/b]
[b]Tick-Tac is designed to be safe for mid-save installation and removal.[/b]
Can be added to an existing save
[b]Does not persist irreversible state into save data
Safe Uninstallation Procedure
Draft all pawns
Save the game
Disable / uninstall Tick-Tac[/b]
This ensures no delayed or gated execution remains active at removal.
Important Notes
Operates only on interval-based tick entry points
Does not interfere with per-tick logic
V1 and V2 can be used together for maximum effectiveness
HediffComps benefit automatically; other components require opt-in (V1)
This MOD has no visible effect on its own
[JP]
Tick-Tac - 分散ジッター・デカップラー
[b]バニラおよび複数MODにおける周期的Tick処理の同時実行によって発生するCPUスパイク負荷を解消する、軽量パフォーマンスフレームワークです。[/b]
概要
Tick-Tacは、各処理の実行タイミングを分散させることで、特定タイミングへの負荷集中を防ぎます。
ゲームの挙動を変えることなく、CPU負荷を時間的に平滑化します。
アーキテクチャ
Tick-Tacは、独立した2つのレイヤーで構成されており、併用可能です:
V1 – MODフレームワーク層
カスタムコンポーネント向けのオプトイン型分散
V2 – バニラ分散エンジン
コアシステムへの自動分散
V1は「MODが追加する処理」を扱い
V2は「バニラが持つ処理」を扱います
両者は別クラスライブラリとして実装されており、干渉せず独立して動作します。
V1 – MODフレームワーク層
動作原理
型ハッシュと個体IDに基づき、各コンポーネントに決定論的な実行スロットを割り当てます。
MOD開発者向け
HediffComp: CompPostTick をオーバーライドしている場合は自動適用
ThingComp / MapComponent / WorldComponent / GameComponent:
以下のフィールドを追加で有効化
public bool EnableTickTac = true;
技術的詳細
- Harmony Prefix/Postfix により ticksGameInt を一時的にオフセット
- スタック構造によるネスト保護で二重適用を防止
- DynamicMethod によりリフレクションを排除
- スロット式: (型ハッシュ ^ アセンブリハッシュ) % 60
V2 – バニラ分散エンジン
Tick-Tac V2は、バニラの周期Tick処理に直接介入し、MOD側の対応なしで負荷分散を実現します。
適用範囲(インターバル限定)
分散は既存のインターバルTickメソッドにのみ適用されます:
[b]
Needs → NeedsTrackerTickInterval(150周期)
Interactions → InteractionsTrackerTickInterval(60 / 91周期)
JobTracker → JobTrackerTickInterval(60周期)[/b]
バニラの処理頻度は維持され、Pawnごとに実行タイミングのみが分散されます。
特徴
[b]決定論的なPawn単位スケジューリング[/b]
セッションシード + Pawn ID により安定した分散を実現
[b]即応性の維持[/b]
分散は以下の状態では無効化されます:
- 徴兵中
- 徴兵解除直後(約30Tick以内)
- メンタル状態中
[b]適用範囲の制御[/b]
動物への適用は設定で切り替え可能(実験的)
技術的詳細
- Harmony Prefix による Intervalメソッドの実行可否制御(ゲーティング)
- ticksGameInt やグローバルTickは変更しない
- Gen.HashCombineInt(PawnID, SessionSeed) によるオフセット生成
- 徴兵状態をDictionaryで管理
- FieldInfoキャッシュにより低オーバーヘッド化
セーブ互換性と安全なアンインストール
[b]Tick-Tacは、途中導入および途中削除に対応しています。[/b]
- 既存セーブへの途中導入が可能
- セーブデータに不可逆な状態を残しません
安全なアンインストール手順
- すべてのPawnを徴兵状態にする
- セーブを行う
- MODを無効化 / アンインストールする
分散によって遅延している処理が残らない状態で、安全に削除できます。
注意事項
- インターバル型Tickエントリポイントのみに作用します
- 毎Tick処理には干渉しません
- V1とV2は併用可能で最大の効果を発揮します
- HediffCompは自動適用、それ以外はV1で明示的オプトインが必要
- このMOD単体では目に見える効果はありません