Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
command.h
Go to the documentation of this file.
1// command.h — CPU → GPU のコマンド(06 §3 の 64 バイトの形。T-0086)。
2//
3// CPU(View と Controller。D-107)が世界に何かを頼むときの唯一の形。窓の入力・魔法・会話の選択・エディタの変更がこれになる。
4// - CPU は「適用する刻み」(targetTick)と、同じ刻みの中の順番(sequence。CPU が通しで増やす)を付けて GPU のコマンドキューへ足す。
5// - GPU は刻み targetTick の適用の単位で (targetTick, sequence) の順に適用する(sim/probe_sim・shaders/sim/probe_tick.hlsl)。
6// - 再生ファイル(save/replay_file)は初期状態とこの列を持つ。これだけで世界が再現できる(D-205・D-110)。
7// payload の中身の意味は type ごと(種類の一覧はシミュごとの .hlsli。今は common/probe_sim.hlsli の PROBE_COMMAND_TYPE_*)。
8// ここは GPU を知らない(save からも使う)。
9#pragma once
10
11#include <array>
12#include <cstdint>
13
14namespace bicameral::sim {
15
16 inline constexpr uint32_t COMMAND_BYTES = 64;
17 inline constexpr uint32_t COMMAND_PAYLOAD_WORDS = 12; // 48 バイト
18
19 struct Command {
20 uint64_t targetTick = 0; // 適用する刻み
21 uint32_t sequence = 0; // 同じ刻みの中の順番(CPU が通しで増やす)
22 uint16_t type = 0;
23 uint16_t size = 0; // payload の使っているバイト数
24 std::array<uint32_t, COMMAND_PAYLOAD_WORDS> payload{};
25
26 friend bool operator==(const Command&, const Command&) = default;
27 };
28
29 static_assert(sizeof(Command) == COMMAND_BYTES);
30
31 // キューと再生ファイルの並び: (targetTick, sequence) の昇順。a が b より前なら true
32 [[nodiscard]] constexpr bool CommandPrecedes(const Command& a, const Command& b) {
33 return a.targetTick != b.targetTick ? a.targetTick < b.targetTick : a.sequence < b.sequence;
34 }
35
36} // namespace bicameral::sim
constexpr bool CommandPrecedes(const Command &a, const Command &b)
Definition command.h:32
constexpr uint32_t COMMAND_PAYLOAD_WORDS
Definition command.h:17
constexpr uint32_t COMMAND_BYTES
Definition command.h:16
std::array< uint32_t, COMMAND_PAYLOAD_WORDS > payload
Definition command.h:24
friend bool operator==(const Command &, const Command &)=default