-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfa6005
commit 89ceb5a
Showing
5 changed files
with
77 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
engine/include/cubos/engine/fixedstep/accumulated_time.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// @file | ||
/// @brief Resource @ref cubos::engine::AccumulatedTime. | ||
/// @ingroup fixedstep-plugin | ||
|
||
#pragma once | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Resource which holds the time passed without running fixedStep systems, incremented every frame | ||
/// by deltaTime and decremented once the systems run. | ||
/// @ingroup fixedstep-plugin | ||
struct AccumulatedTime | ||
{ | ||
float value = 0.0F; | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// @dir | ||
/// @brief @ref fixedstep-plugin plugin directory. | ||
|
||
/// @file | ||
/// @brief Plugin entry point. | ||
/// @ingroup fixedstep-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/prelude.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @defgroup fixedstep-plugin FixedStep | ||
/// @ingroup engine | ||
/// @brief Adds cubos.fixedStep tag which makes its systems run at a fixed framerate. | ||
/// | ||
|
||
/// @brief Plugin entry function. | ||
/// @param cubos @b CUBOS. main class | ||
/// @ingroup fixedstep-plugin | ||
void fixedStepPlugin(Cubos& cubos); | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <cubos/engine/fixedstep/plugin.hpp> | ||
#include <cubos/engine/fixedstep/accumulated_time.hpp> | ||
|
||
|
||
using namespace cubos::engine; | ||
|
||
const float frametime = 1/60; | ||
|
||
|
||
|
||
void cubos::engine::fixedStepPlugin(Cubos& cubos) | ||
{ | ||
cubos.addResource<AccumulatedTime>(); | ||
|
||
cubos.system("accumulate time resource").call([](AccumulatedTime& timer, const DeltaTime& dt) { | ||
timer.value += dt.value; | ||
}); | ||
|
||
cubos.tag("cubos.fixedStep").repeatWhile([](AccumulatedTime& timer) { | ||
if (timer.value >= frametime) { | ||
timer.value -= frametime; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters