Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c6d832f

Browse files
authoredOct 1, 2023
Merge pull request #240 from scratchcpp/engine_isrunning_method
Add isRunning method to Engine
2 parents dcc6e08 + 7130ccf commit c6d832f

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed
 

‎include/scratchcpp/iengine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class LIBSCRATCHCPP_EXPORT IEngine
8585
*/
8686
virtual void run() = 0;
8787

88+
/*! Returns true if the project is currently running. */
89+
virtual bool isRunning() const = 0;
90+
8891
/*! Returns the framerate of the project. */
8992
virtual double fps() const = 0;
9093

‎src/engine/internal/engine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ void Engine::run()
352352
stop();
353353
}
354354

355+
bool Engine::isRunning() const
356+
{
357+
return m_running;
358+
}
359+
355360
double Engine::fps() const
356361
{
357362
return m_fps;

‎src/engine/internal/engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Engine : public IEngine
3636
void initClone(libscratchcpp::Sprite *clone) override;
3737
void run() override;
3838

39+
bool isRunning() const override;
40+
3941
double fps() const override;
4042
void setFps(double fps) override;
4143

‎test/engine/engine_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ TEST(EngineTest, Clear)
3434
ASSERT_TRUE(engine.registeredSections().empty());
3535
}
3636

37+
TEST(EngineTest, IsRunning)
38+
{
39+
Engine engine;
40+
ASSERT_FALSE(engine.isRunning());
41+
42+
engine.start();
43+
ASSERT_TRUE(engine.isRunning());
44+
45+
engine.stop();
46+
ASSERT_FALSE(engine.isRunning());
47+
48+
engine.start();
49+
engine.run();
50+
ASSERT_FALSE(engine.isRunning());
51+
}
52+
3753
TEST(EngineTest, Fps)
3854
{
3955
Engine engine;

‎test/mocks/enginemock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class EngineMock : public IEngine
2424
MOCK_METHOD(void, initClone, (Sprite *), (override));
2525
MOCK_METHOD(void, run, (), (override));
2626

27+
MOCK_METHOD(bool, isRunning, (), (const, override));
28+
2729
MOCK_METHOD(double, fps, (), (const, override));
2830
MOCK_METHOD(void, setFps, (double fps), (override));
2931

0 commit comments

Comments
 (0)
Please sign in to comment.