dl
dl_action_def.h
浏览该文件的文档.
1
11#pragma once
12
13#include <functional>
14
15#include "dl_type.h"
16#include "dl_range.h"
17#include "misc/dl_timer.h"
18#include "io/dl_log.h"
19#include "math/dl_algorithm.h"
20#include "base/dl_color.h"
21
22namespace dl
23{
25class Action
26{
27 friend class ActionManager;
28public:
29 bool IsFinish()
30 {
31 return _count == 0;
32 }
33
35protected:
36 virtual void Update() = 0;
37
39 _cur{ 0 },
40 _max{ t },
41 _count{ 1 }
42 {}
43 virtual ~Action() {}
44private:
45 FloatTime _cur;
46 FloatTime _max;
47 size_t _count; // 剩余次数
48 // 完成状态
49 // _cur ~= 0 && _cur < _max
50 // _count = 0
51
52 // 返回真表示完成
53 bool _update(FloatTime dt)
54 {
55 if (_count == 0)
56 return true;
57 _cur += dt;
58 while (_cur >= _max)
59 {
60 _cur -= _max;
61 --_count;
62 }
63 return false;
64 }
65};
66
67class ActionColor : public Action
68{
69public:
70 using Func = std::function<void(ActionColor*)>;
72 Action{ t },
73 _func{ func },
74 _col{ ColorDef::RED, ColorDef::GREEN }
75 {}
76 virtual void Update() override
77 {
78 _func(this);
79 }
80
81 void SetColor(const std::array<Color, 2>& col)
82 {
83 _col = col;
84 }
85
87 {
88 return Each::Lerp(_col[0], _col[1], GetK());
89 }
90private:
91 std::array<Color, 2> _col;
92 Func _func;
93};
94
95}
virtual void Update() override
std::function< void(ActionColor *)> Func
Color GetColor()
返回当前插值颜色
ActionColor(FloatTime t, Func func)
void SetColor(const std::array< Color, 2 > &col)
设置颜色插值
virtual void Update()=0
FloatTime GetK()
返回进度0-1
Action(FloatTime t)
friend class ActionManager
日志系统
范围操作
计时器
通用类型
颜色预定义
Array< T, N > Lerp(const Array< T, N > &a, const Array< T, N > &b, T t)
线性插值
float FloatTime
Array< float, 4 > Color