Skip to content

Commit 2be68fe

Browse files
committed
Remove unused AnimatedToken
1 parent 628d972 commit 2be68fe

4 files changed

Lines changed: 122 additions & 123 deletions

File tree

data/imgui.ini

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ Size=400,400
99
Collapsed=0
1010

1111
[Window][Console]
12-
Pos=0,842
13-
Size=1920,164
12+
Pos=0,604
13+
Size=1100,164
1414
Collapsed=0
1515
DockId=0x00000006,0
1616

1717
[Window][Message]
18-
Pos=0,842
19-
Size=1920,164
18+
Pos=0,604
19+
Size=1100,164
2020
Collapsed=0
2121
DockId=0x00000006,1
2222

2323
[Window][Places]
24-
Pos=1527,19
25-
Size=393,821
24+
Pos=707,19
25+
Size=393,583
2626
Collapsed=0
2727
DockId=0x00000003,1
2828

2929
[Window][Arcs]
30-
Pos=1527,19
31-
Size=393,821
30+
Pos=707,19
31+
Size=393,583
3232
Collapsed=0
3333
DockId=0x00000003,2
3434

@@ -39,8 +39,8 @@ Collapsed=0
3939
DockId=0x00000072,0
4040

4141
[Window][Transitions]
42-
Pos=1527,19
43-
Size=393,821
42+
Pos=707,19
43+
Size=393,583
4444
Collapsed=0
4545
DockId=0x00000003,0
4646

@@ -81,8 +81,8 @@ Size=565,338
8181
Collapsed=0
8282

8383
[Window][Steps]
84-
Pos=1492,19
85-
Size=428,468
84+
Pos=707,19
85+
Size=393,314
8686
Collapsed=0
8787
DockId=0x00000003,1
8888

@@ -98,7 +98,7 @@ Collapsed=0
9898

9999
[Window][WindowOverViewport_11111111]
100100
Pos=0,19
101-
Size=1920,987
101+
Size=1100,749
102102
Collapsed=0
103103

104104
[Window][Critical Cycle]
@@ -117,26 +117,26 @@ Size=224,71
117117
Collapsed=0
118118

119119
[Window][Actions]
120-
Pos=1492,19
121-
Size=428,468
120+
Pos=707,19
121+
Size=393,314
122122
Collapsed=0
123123
DockId=0x00000003,2
124124

125125
[Window][Outputs]
126-
Pos=1734,489
127-
Size=186,397
126+
Pos=929,335
127+
Size=171,267
128128
Collapsed=0
129129
DockId=0x00000008,0
130130

131131
[Window][Inputs]
132-
Pos=1492,489
133-
Size=240,397
132+
Pos=707,335
133+
Size=220,267
134134
Collapsed=0
135135
DockId=0x00000007,0
136136

137137
[Window][Net0]
138138
Pos=0,19
139-
Size=1525,821
139+
Size=705,583
140140
Collapsed=0
141141
DockId=0x00000072,0
142142

@@ -198,6 +198,16 @@ Pos=110,116
198198
Size=634,371
199199
Collapsed=0
200200

201+
[Window][Choose the PNG file to save the screenshot##ScreenshotDlgKey]
202+
Pos=628,111
203+
Size=469,372
204+
Collapsed=0
205+
206+
[Window][The selected file already exists!##Choose the PNG file to save the screenshotScreenshotDlgKeyOverWriteDialog]
207+
Pos=750,271
208+
Size=224,71
209+
Collapsed=0
210+
201211
[Table][0x90C2C115,4]
202212
RefScale=13
203213
Column 0 Sort=0v
@@ -622,8 +632,56 @@ Column 0 Sort=0v
622632
RefScale=13
623633
Column 0 Sort=0v
624634

635+
[Table][0x876E92F9,4]
636+
RefScale=13
637+
Column 0 Sort=0v
638+
639+
[Table][0xB79264FF,4]
640+
RefScale=13
641+
Column 0 Sort=0v
642+
643+
[Table][0xB9CB7C38,4]
644+
RefScale=13
645+
Column 0 Sort=0v
646+
647+
[Table][0xEE8B84E4,4]
648+
RefScale=13
649+
Column 0 Sort=0v
650+
651+
[Table][0xDE7772E2,4]
652+
RefScale=13
653+
Column 0 Sort=0v
654+
655+
[Table][0x0420D902,4]
656+
RefScale=13
657+
Column 0 Sort=0v
658+
659+
[Table][0x34DC2F04,4]
660+
RefScale=13
661+
Column 0 Sort=0v
662+
663+
[Table][0xE22B6D94,4]
664+
RefScale=13
665+
Column 0 Sort=0v
666+
667+
[Table][0xD2D79B92,4]
668+
RefScale=13
669+
Column 0 Sort=0v
670+
671+
[Table][0xA4E45FD5,4]
672+
RefScale=13
673+
Column 0 Sort=0v
674+
675+
[Table][0xC79FD6C3,4]
676+
RefScale=13
677+
Column 0 Sort=0v
678+
679+
[Table][0xD9E2CAEE,4]
680+
RefScale=13
681+
Column 0 Sort=0v
682+
625683
[Docking][Data]
626-
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,19 Size=1920,987 Split=Y
684+
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,19 Size=1100,749 Split=Y
627685
DockNode ID=0x00000005 Parent=0x08BD597D SizeRef=1100,867 Split=X
628686
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1525,749 Split=X Selected=0xACD08B34
629687
DockNode ID=0x0000000B Parent=0x00000002 SizeRef=651,768 Selected=0x68006E5B
@@ -731,7 +789,7 @@ DockSpace
731789
DockNode ID=0x00000071 Parent=0x0000006E SizeRef=623,768 Selected=0x68006E5B
732790
DockNode ID=0x00000072 Parent=0x0000006E SizeRef=497,768 CentralNode=1 Selected=0x501101F7
733791
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=393,749 Split=Y Selected=0x142E3D6D
734-
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=302,468 Selected=0xCB595B90
792+
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=302,468 Selected=0x50EA5CCF
735793
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=302,397 Split=X Selected=0x0E1F77DA
736794
DockNode ID=0x00000007 Parent=0x00000004 SizeRef=240,322 Selected=0xA48EA2F1
737795
DockNode ID=0x00000008 Parent=0x00000004 SizeRef=186,322 Selected=0x0E1F77DA

src/PetriNet/Simulation.cpp

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,6 @@ namespace tpne {
3434
// Static member initialization
3535
Simulation::ActionState Simulation::s_dummy_action_state;
3636

37-
//------------------------------------------------------------------------------
38-
// Helper function to compute Euclidean distance
39-
//------------------------------------------------------------------------------
40-
static inline float norm(Node const& A, Node const& B)
41-
{
42-
return std::sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
43-
}
44-
45-
//------------------------------------------------------------------------------
46-
Simulation::AnimatedToken::AnimatedToken(Node& origin_, Node& destination_,
47-
Place& target_place_, size_t tokens_,
48-
float duration, float default_duration)
49-
: origin(&origin_), destination(&destination_), targetPlace(&target_place_),
50-
x(origin_.x), y(origin_.y), tokens(tokens_)
51-
{
52-
magnitude = norm(*origin, *destination);
53-
speed = magnitude / std::max(0.000001f, duration > 0.0f ? duration : default_duration);
54-
}
55-
56-
//------------------------------------------------------------------------------
57-
bool Simulation::AnimatedToken::update(float const dt)
58-
{
59-
offset += dt * speed / magnitude;
60-
x = origin->x + (destination->x - origin->x) * offset;
61-
y = origin->y + (destination->y - origin->y) * offset;
62-
return offset >= 1.0f;
63-
}
64-
6537
//------------------------------------------------------------------------------
6638
static const char* current_time()
6739
{
@@ -75,7 +47,7 @@ static const char* current_time()
7547
Simulation::Simulation(Net& net)
7648
: m_net(net)
7749
{
78-
m_animated_tokens.reserve(128u);
50+
m_timed_tokens.reserve(128u);
7951
}
8052

8153
//------------------------------------------------------------------------------
@@ -113,7 +85,7 @@ void Simulation::initializeRuntimeState()
11385
shuffleTransitions(true);
11486

11587
// Clear animated tokens
116-
m_animated_tokens.clear();
88+
m_timed_tokens.clear();
11789

11890
// Initialize place activation states
11991
m_place_was_active.clear();
@@ -232,7 +204,7 @@ void Simulation::handleHaltingState()
232204
restoreInitialMarking();
233205
m_net.resetReceptivies();
234206
m_receptivities.clear();
235-
m_animated_tokens.clear();
207+
m_timed_tokens.clear();
236208
m_action_states.clear();
237209
Sensors::instance().clear();
238210

@@ -463,32 +435,7 @@ void Simulation::fireTransitions()
463435
<< count << " token" << (count == 1u ? "" : "s")
464436
<< std::endl;
465437

466-
// Determine visual destination and default duration based on net type
467-
Node& origin = arc->from;
468-
Place& target_place = *reinterpret_cast<Place*>(&arc->to);
469-
Node* destination = &arc->to;
470-
float default_duration = 0.2f; // Default for Petri net
471-
472-
if (m_net.type() == TypeOfNet::TimedEventGraph)
473-
{
474-
// For TEG, animate to the next transition (skip implicit place)
475-
if (!arc->to.arcsOut.empty())
476-
{
477-
destination = &arc->to.arcsOut[0]->to;
478-
}
479-
default_duration = arc->duration;
480-
}
481-
else if (m_net.type() == TypeOfNet::TimedPetriNet)
482-
{
483-
default_duration = arc->duration;
484-
}
485-
else if (m_net.type() == TypeOfNet::GRAFCET)
486-
{
487-
default_duration = 0.15f; // Fast animation for GRAFCET
488-
}
489-
490-
m_animated_tokens.emplace_back(origin, *destination, target_place,
491-
count, arc->duration, default_duration);
438+
m_timed_tokens.emplace_back(*arc, count, m_net.type());
492439
m_arc_token_counts[arc_idx] = 0u;
493440
}
494441
}
@@ -497,7 +444,7 @@ void Simulation::fireTransitions()
497444
//------------------------------------------------------------------------------
498445
void Simulation::animateTokens(float const dt)
499446
{
500-
if (m_animated_tokens.empty())
447+
if (m_timed_tokens.empty())
501448
{
502449
if ((m_net.type() != TypeOfNet::PetriNet) && (m_net.type() != TypeOfNet::GRAFCET))
503450
{
@@ -508,32 +455,32 @@ void Simulation::animateTokens(float const dt)
508455
return;
509456
}
510457

511-
size_t i = m_animated_tokens.size();
458+
size_t i = m_timed_tokens.size();
512459
while (i--)
513460
{
514-
AnimatedToken& token = m_animated_tokens[i];
461+
TimedToken& token = m_timed_tokens[i];
515462
if (token.update(dt))
516463
{
517464
std::cout << current_time()
518-
<< "Place " << token.targetPlace->caption
465+
<< "Place " << token.arc->to.caption
519466
<< " got " << token.tokens << " token"
520467
<< (token.tokens == 1u ? "" : "s")
521468
<< std::endl;
522469

523-
token.targetPlace->tokens += token.tokens;
470+
token.arc->tokensOut() += token.tokens;
524471

525472
if (m_net.type() != TypeOfNet::PetriNet)
526473
{
527-
Transition& t = reinterpret_cast<Transition&>(*token.origin);
474+
Transition& t = reinterpret_cast<Transition&>(token.arc->from);
528475
if (t.isInput())
529476
{
530477
t.receptivity = true;
531478
}
532479
}
533480

534481
// Remove by swapping with last
535-
m_animated_tokens[i] = m_animated_tokens.back();
536-
m_animated_tokens.pop_back();
482+
m_timed_tokens[i] = m_timed_tokens.back();
483+
m_timed_tokens.pop_back();
537484
}
538485
}
539486
}

src/PetriNet/Simulation.hpp

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# define SIMULATION_NET_HPP
2323

2424
# include "PetriNet/Signal.hpp"
25+
# include "PetriNet/TimedTokens.hpp"
2526

2627
# include <atomic>
2728
# include <string>
@@ -45,40 +46,7 @@ class Simulation
4546
{
4647
public:
4748

48-
// *************************************************************************
49-
//! \brief Animated token moving along an arc from Transition to Place.
50-
//! Stores pointers to origin and destination nodes for position calculation,
51-
//! eliminating the need to store TypeOfNet.
52-
// *************************************************************************
53-
struct AnimatedToken
54-
{
55-
//! \brief Constructor.
56-
//! \param[in] origin_ The origin node (Transition).
57-
//! \param[in] destination_ The visual destination node (Place or next Transition for TEG).
58-
//! \param[in] target_place_ The actual Place where tokens will be deposited.
59-
//! \param[in] tokens_ Number of tokens being animated.
60-
//! \param[in] duration Arc duration for speed calculation.
61-
//! \param[in] default_duration Default duration if arc duration is 0.
62-
AnimatedToken(Node& origin_, Node& destination_, Place& target_place_,
63-
size_t tokens_, float duration, float default_duration);
64-
65-
//! \brief Update position on the screen.
66-
//! \param[in] dt Delta time in seconds.
67-
//! \return true when arriving at destination, false otherwise.
68-
bool update(float dt);
69-
70-
Node* origin; //!< Origin node (Transition)
71-
Node* destination; //!< Visual destination (Place or next Transition for TEG)
72-
Place* targetPlace; //!< Actual Place where tokens are deposited
73-
float x; //!< Current X position for rendering
74-
float y; //!< Current Y position for rendering
75-
size_t tokens; //!< Number of tokens being carried
76-
float magnitude; //!< Length of the path
77-
float speed; //!< Animation speed
78-
float offset = 0.0f; //!< Progress along the path (0.0 to 1.0)
79-
};
80-
81-
using AnimatedTokens = std::vector<AnimatedToken>;
49+
using TimedTokens = std::vector<TimedToken>;
8250
using Receptivities = std::map<size_t, Receptivity>;
8351

8452
// *************************************************************************
@@ -115,7 +83,7 @@ class Simulation
11583
//--------------------------------------------------------------------------
11684
//! \brief Get the animated tokens for rendering.
11785
//--------------------------------------------------------------------------
118-
inline AnimatedTokens const& animatedTokens() const { return m_animated_tokens; }
86+
inline TimedTokens const& animatedTokens() const { return m_timed_tokens; }
11987

12088
//--------------------------------------------------------------------------
12189
//! \brief Get the receptivities map for inspection.
@@ -287,7 +255,7 @@ class Simulation
287255
//! \brief List of shuffled Transitions for random firing order.
288256
std::vector<Transition*> m_shuffled_transitions;
289257
//! \brief Animated tokens transitioning from Transitions to Places.
290-
AnimatedTokens m_animated_tokens;
258+
TimedTokens m_timed_tokens;
291259
//! \brief Initial marking stored at simulation start.
292260
std::vector<size_t> m_initial_tokens;
293261
//! \brief Compiled GRAFCET receptivities (boolean expressions).

0 commit comments

Comments
 (0)