Add panel incrmementing

This commit is contained in:
Tyler Perkins 2021-12-20 13:14:47 -05:00
parent 38dfa2a8b6
commit 282edfc7aa
3 changed files with 16 additions and 1 deletions

View File

@ -31,6 +31,10 @@ up to you to call this, to give you the option of lazy loading it.
because SDL will not be setup when your constructor is called, and therefore because SDL will not be setup when your constructor is called, and therefore
will not be able to properly create the texture for the renderer. will not be able to properly create the texture for the renderer.
The *_time_on_screen* value is in milliseconds, and will be the amount of time
the board will display the panel before transitioning. This value can be
modified at runtime if needed (ie displaying a dynamic length video).
The provided memory api stores textures (SDL_Texture), fonts (TTF_Font), and The provided memory api stores textures (SDL_Texture), fonts (TTF_Font), and
strings (SDL_Texture). Both static values can be added that will exist for the strings (SDL_Texture). Both static values can be added that will exist for the
lifetime of the program, as well as dynamic versions that will be stored in a lifetime of the program, as well as dynamic versions that will be stored in a

View File

@ -346,13 +346,23 @@ void board::start(){
//frame counter //frame counter
static unsigned long long int fcount = 0; static unsigned long long int fcount = 0;
//time since last panel
auto last_panel = start;
SDL_Log("Starting main loop...\n"); SDL_Log("Starting main loop...\n");
for(;;){ for(;;){
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
fcount++; fcount++;
//check if its time to increment the panel
if(std::chrono::duration_cast<std::chrono::milliseconds>(
start - last_panel).count() >= PANELS[i]->_time_on_screen){
i++;
last_panel = start;
}
//check if we can loop back over //check if we can loop back over
if(i > PANELS_LENGTH) if(i >= PANELS_LENGTH)
i = 0; i = 0;
SDL_RenderClear(_renderer); SDL_RenderClear(_renderer);

View File

@ -25,6 +25,7 @@ namespace dashboard::panel {
virtual void draw() = 0; virtual void draw() = 0;
//in milliseconds
size_t _time_on_screen = 0; size_t _time_on_screen = 0;
protected: protected: