-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurtleNode.cpp
136 lines (123 loc) · 2.31 KB
/
TurtleNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "TurtleNode.h"
#include <iostream>
TurtleNode::TurtleNode():
speed(100.f),
lineColor(sf::Color::Black),
body(&this->arrow),
isPenUp(false),
isHide(false),
fastUpdateFlag(false)
{
this->lines.push_back(sf::VertexArray(sf::Lines, 0));
this->start_fill_iter = lines.end();
}
void TurtleNode::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const
{
sf::RenderStates parentTransformState;
parentTransformState.transform *= this->getParentTransform();
if (this->lines.size())
{
//parentTransformState.transform.;
for (const sf::VertexArray& line : this->lines)
{
target.draw(line,parentTransformState);
}
}
if (this->fillZones.size())
{
for (const sf::VertexArray& zone : this->fillZones)
{
target.draw(zone,parentTransformState);
}
}
if (this->dots.size())
{
for (const TurtleDot& dot : this->dots)
{
target.draw(dot,parentTransformState);
}
}
if (!this->isHide)
{
target.draw(*this->body, states);
}
}
void TurtleNode::updateCurrent(const sf::Time& dt)
{
if (this->fastUpdateFlag)
{
this->fastUpdate(dt);
}
if (this->commands.empty())
{
return;
}
if (this->commands.front().done)
{
this->commands.pop_front();
return;
}
this->commands.front()(*this, dt);
}
void TurtleNode::fastUpdate(const sf::Time& dt)
{
if (this->commands.empty())
{
return;
}
TurtleCommand& top = this->commands.front();
while (true)
{
this->commands.front()(*this, dt);
if(!this->commands.front().done)
{
return;
}
this->commands.pop_front();
if (this->commands.empty())
{
return;
}
}
}
float TurtleNode::getSpeed() const
{
return this->speed;
}
void TurtleNode::setSpeed(const float& speed)
{
this->speed = speed;
}
void TurtleNode::pushCommand(const TurtleCommand& command)
{
//this->commands.pu
this->commands.push_back(command);
}
TurtleNode::TurtleCommand& TurtleNode::lastPushed()
{
return this->commands.back();
}
void TurtleNode::setBody(sf::Drawable* body)
{
this->body = body;
}
sf::Drawable* TurtleNode::getBody()
{
return this->body;
}
void TurtleNode::setLineColor(const sf::Color& color)
{
this->lineColor = color;
}
sf::Color TurtleNode::getLineColor()
{
return this->lineColor;
}
void TurtleNode::setPenUp(const bool& flag)
{
this->isPenUp = flag;
}
void TurtleNode::attachCanvas(Canvas* canvas)
{
this->canvas = canvas;
}