DYTSrouce/src/workspace/Timestep.h
2025-11-11 07:16:13 +08:00

81 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <vector>
#include <QObject>
#include <QString>
class WorkSpace;
class Timestep : public QObject {
Q_OBJECT
public:
enum class PlayStatus : uint8_t {
PS_Started,
PS_Stoped,
PS_Suspended,
};
public:
explicit Timestep(WorkSpace* parent = nullptr) noexcept;
~Timestep() override = default;
void GetRange(double& minTime, double& maxTime, double& step);
void Update(double dt);
double GetCurrent() const {
return current_;
}
bool IsPause();
bool IsStoped();
void Start();
void Resume();
void Pause();
void Stop();
void Up();
void Down();
// 设置播放速度(倍率),会选取最接近的预设倍率并触发 StepChanged
void SetSpeed(double speed);
// 设置数据驱动的默认最大时间(非手动区间),用于没有文件步长时的播放边界
void SetDataMaxTime(double end);
WorkSpace* GetWorkSpace() const {
return workSpace_;
}
// 手动时间区间(可选):允许用户指定起止时间,替代或重映射步骤
void SetManualRange(double start, double end);
void ClearManualRange();
bool HasManualRange() const { return hasManualRange_; }
double GetManualStart() const { return manualStart_; }
double GetManualEnd() const { return manualEnd_; }
Q_SIGNALS:
void StatusChanged(int);
void StepChanged(double);
void TimeChanged(double);
// 当时间范围或步进倍率更新时通知 UI例如设置手动区间或清除
void RangeChanged(double minTime, double maxTime, double step);
private:
double current_{ 0.0 };
double maxTime_{ 0.0 };
// 播放速度(倍率),与 UI 显示一致,比如 0.5x、1x、2x
double currentStep_{ 1.0 };
// 有限倍率列表,防止无限放大/缩小导致无法恢复
std::vector<double> speedLevels_{ 0.25, 0.5, 1.0, 2.0, 4.0, 8.0 };
int speedIndex_{ 2 }; // 默认指向 1.0x
PlayStatus playStatus_{ PlayStatus::PS_Stoped };
WorkSpace* workSpace_{ nullptr };
bool hasManualRange_{ false };
double manualStart_{ 0.0 };
double manualEnd_{ 0.0 };
};