Kiwano Engine v1.3.x
DebugActor.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/2d/Actor.h>
23#include <kiwano/render/TextLayout.h>
24
25namespace kiwano
26{
27
28template <typename T>
30{
31public:
32 SimpleRingBuffer(size_t capcity)
33 {
34 Reserve(capcity);
35 }
36
37 void PushBack(const T& val)
38 {
39 if (IsFull())
40 Reserve(Capacity() * 2);
41 buffer_[rear_] = val;
42 IncreaseRear();
43 }
44
45 void PopFront()
46 {
47 IncreaseFront();
48 }
49
50 const T& Front() const
51 {
52 return buffer_[front_];
53 }
54
55 T& Front()
56 {
57 return buffer_[front_];
58 }
59
60 const T& Back() const
61 {
62 return buffer_[ClampCursor(rear_, 1)];
63 }
64
65 T& Back()
66 {
67 return buffer_[ClampCursor(rear_, 1)];
68 }
69
70 bool IsEmpty() const noexcept
71 {
72 return front_ = rear_;
73 }
74
75 bool IsFull() const noexcept
76 {
77 return front_ == (rear_ + 1) % Capacity();
78 }
79
80 size_t Size() const
81 {
82 return ClampCursor(rear_, front_);
83 }
84
85 size_t Capacity() const
86 {
87 return buffer_.size();
88 }
89
90 void Reserve(size_t capacity)
91 {
92 buffer_.resize(capacity);
93 }
94
95private:
96 void IncreaseFront()
97 {
98 if (buffer_.empty())
99 return;
100 front_ = (front_ + 1) % Capacity();
101 }
102
103 void IncreaseRear()
104 {
105 rear_ = (rear_ + 1) % Capacity();
106 }
107
108 size_t ClampCursor(size_t cursor, size_t off) const
109 {
110 return (cursor + Capacity() - off) % Capacity();
111 }
112
113private:
114 Vector<T> buffer_;
115 size_t front_ = 0;
116 size_t rear_ = 0;
117};
118
128class KGE_API DebugActor : public Actor
129{
130public:
131 DebugActor();
132
133 virtual ~DebugActor();
134
135 void OnRender(RenderContext& ctx) override;
136
137 void OnUpdate(Duration dt) override;
138
139protected:
140 bool CheckVisibility(RenderContext& ctx) const override;
141
142private:
143 std::locale comma_locale_;
144 RefPtr<Brush> background_brush_;
145 RefPtr<Brush> debug_text_brush_;
146 TextStyle debug_text_style_;
147 TextLayout debug_text_;
148
149 SimpleRingBuffer<Time> frame_buffer_;
150};
151
153} // namespace kiwano
角色
Definition: Actor.h:63
调试节点
Definition: DebugActor.h:129
引用计数智能指针
Definition: RefBasePtr.hpp:35
渲染上下文
Definition: RenderContext.h:62
Definition: DebugActor.h:30
文本布局
Definition: TextLayout.h:37
文本样式
Definition: TextStyle.h:51
时间段
Definition: Duration.h:48