Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
time_control.h
Go to the documentation of this file.
1
// time_control.h — エディタの時間の操作: 止める・1 刻み進める・速さ(T-0023、docs/design/14 §2「時間の操作」・ADR-0035)。
2
//
3
// データの流れ: エディタのパネル(editor/editor_overlay)とキー → TimeRequest → TimeControl → frame::SimScheduler
4
// (「現実の時間からいくつ刻みを始めてよいか」)。フレームのループは毎フレーム AdvanceRealTime で経過時間を渡す。
5
// 時間の操作は「いつ刻みを投げるか」だけを変える Controller の仕事で、世界のコマンドには入らない(D-107・ADR-0035)。
6
// 世界の結果は刻みの番号と、刻みに付いたコマンドだけで決まる(06 §1・§3)ので、止めても速くしても再生ファイルのハッシュ列は同じになる。
7
// ここは GPU を知らない(CPU だけのテスト tests/time_control_test.cpp)。
8
#pragma once
9
10
#include <array>
11
#include <cstdint>
12
13
#include "
frame/sim_scheduler.h
"
14
15
namespace
bicameral::editor
{
16
17
// 速さの段(等速 = 1 を真ん中に 1/8〜8 倍)。速くしても 1 フレームの予算(ADR-0011)は変わらないので、
18
// 重い世界では上の段にしても追いつかない(追いつけない分は捨てる。D-202)
19
inline
constexpr
std::array<double, 7>
TIME_SPEEDS
= {0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0};
20
inline
constexpr
uint32_t
NORMAL_SPEED_INDEX
= 3;
21
22
// 1 フレームぶんの時間の操作の依頼(パネルのボタンとキーから)
23
struct
TimeRequest
{
24
bool
togglePause
=
false
;
// 止める / 動かす
25
uint32_t
stepTicks
= 0;
// 止めている間に進める刻みの数(動いている間は無視)
26
int32_t
speedSteps
= 0;
// 速さの段を上げる(+)/ 下げる(−)
27
bool
resetSpeed
=
false
;
// 等速に戻す(speedSteps より先に効く)
28
// この刻みの保存点へ巻き戻す(UINT64_MAX = しない。T-0143)。TimeControl は見ない(フレームのループが保存点から戻す)
29
uint64_t
rewindTick
= UINT64_MAX;
30
31
[[nodiscard]]
bool
Any
()
const
{
32
return
togglePause
||
stepTicks
> 0 ||
speedSteps
!= 0 ||
resetSpeed
||
rewindTick
!= UINT64_MAX;
33
}
34
};
35
36
class
TimeControl
{
37
public
:
38
// 依頼を受ける。止めたら未処理の刻みを捨てる(始めた刻みは最後まで進む)
39
void
Apply
(
const
TimeRequest
& request,
frame::SimScheduler
& scheduler);
40
41
// 現実の経過時間を渡す。止めている間は進めない。gameSpeed はゲーム側の速さ(D-409。1 = 等速)
42
void
AdvanceRealTime
(
double
seconds,
frame::SimScheduler
& scheduler,
double
gameSpeed = 1.0)
const
;
43
44
[[nodiscard]]
bool
Paused
()
const
{
return
m_paused
; }
45
[[nodiscard]] uint32_t
SpeedIndex
()
const
{
return
m_speedIndex
; }
46
[[nodiscard]]
double
Speed
()
const
{
return
TIME_SPEEDS
[
m_speedIndex
]; }
47
[[nodiscard]] uint64_t
SteppedTicks
()
const
{
return
m_steppedTicks
; }
// 1 刻みずつ進めた数の合計(表示用)
48
49
private
:
50
bool
m_paused
=
false
;
51
uint32_t
m_speedIndex
=
NORMAL_SPEED_INDEX
;
52
uint64_t
m_steppedTicks
= 0;
53
};
54
55
}
// namespace bicameral::editor
bicameral::editor::TimeControl
Definition
time_control.h:36
bicameral::editor::TimeControl::SteppedTicks
uint64_t SteppedTicks() const
Definition
time_control.h:47
bicameral::editor::TimeControl::Apply
void Apply(const TimeRequest &request, frame::SimScheduler &scheduler)
Definition
time_control.cpp:8
bicameral::editor::TimeControl::m_paused
bool m_paused
Definition
time_control.h:50
bicameral::editor::TimeControl::AdvanceRealTime
void AdvanceRealTime(double seconds, frame::SimScheduler &scheduler, double gameSpeed=1.0) const
Definition
time_control.cpp:32
bicameral::editor::TimeControl::Speed
double Speed() const
Definition
time_control.h:46
bicameral::editor::TimeControl::m_speedIndex
uint32_t m_speedIndex
Definition
time_control.h:51
bicameral::editor::TimeControl::Paused
bool Paused() const
Definition
time_control.h:44
bicameral::editor::TimeControl::SpeedIndex
uint32_t SpeedIndex() const
Definition
time_control.h:45
bicameral::editor::TimeControl::m_steppedTicks
uint64_t m_steppedTicks
Definition
time_control.h:52
bicameral::frame::SimScheduler
Definition
sim_scheduler.h:42
bicameral::editor
Definition
editor_overlay.cpp:25
bicameral::editor::TIME_SPEEDS
constexpr std::array< double, 7 > TIME_SPEEDS
Definition
time_control.h:19
bicameral::editor::NORMAL_SPEED_INDEX
constexpr uint32_t NORMAL_SPEED_INDEX
Definition
time_control.h:20
sim_scheduler.h
bicameral::editor::TimeRequest
Definition
time_control.h:23
bicameral::editor::TimeRequest::Any
bool Any() const
Definition
time_control.h:31
bicameral::editor::TimeRequest::togglePause
bool togglePause
Definition
time_control.h:24
bicameral::editor::TimeRequest::stepTicks
uint32_t stepTicks
Definition
time_control.h:25
bicameral::editor::TimeRequest::resetSpeed
bool resetSpeed
Definition
time_control.h:27
bicameral::editor::TimeRequest::rewindTick
uint64_t rewindTick
Definition
time_control.h:29
bicameral::editor::TimeRequest::speedSteps
int32_t speedSteps
Definition
time_control.h:26
engine
src
editor
time_control.h
Generated by
1.15.0