File tree Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ target_sources(scratchcpp
4646 include /scratchcpp/target .h
4747 include /scratchcpp/stage.h
4848 include /scratchcpp/sprite.h
49+ include /scratchcpp/itimer.h
4950)
5051
5152add_library (zip SHARED
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ namespace libscratchcpp
6+ {
7+
8+ class ITimer
9+ {
10+ public:
11+ virtual ~ITimer () { }
12+
13+ virtual double value () const = 0;
14+
15+ virtual void reset () = 0;
16+ };
17+
18+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ target_sources(scratchcpp
1111 script_p.h
1212 internal /engine.cpp
1313 internal /engine.h
14+ internal /timer.cpp
15+ internal /timer.h
1416 internal /blocksectioncontainer.cpp
1517 internal /blocksectioncontainer.h
1618 internal /global .h
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include " timer.h"
4+
5+ using namespace libscratchcpp ;
6+
7+ Timer::Timer ()
8+ {
9+ }
10+
11+ double Timer::value () const
12+ {
13+ return (std::chrono::steady_clock::now () - m_startTime).count () / 1000.0 ;
14+ }
15+
16+ void Timer::reset ()
17+ {
18+ m_startTime = std::chrono::steady_clock::now ();
19+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include < scratchcpp/itimer.h>
6+ #include < chrono>
7+
8+ namespace libscratchcpp
9+ {
10+
11+ class Timer : public ITimer
12+ {
13+ public:
14+ Timer ();
15+ Timer (const Timer &) = delete ;
16+
17+ double value () const override ;
18+ void reset () override ;
19+
20+ private:
21+ std::chrono::steady_clock::time_point m_startTime = std::chrono::steady_clock::now();
22+ };
23+
24+ } // namespace libscratchcpp
You can’t perform that action at this time.
0 commit comments