#pragma once #include #include #include "logic/life.h" #include "logic/page.h" // Runs the Game of Life element of the shown page (logic/life): FlipdotFrames sets the page // and ticks it before each frame, StoredPageResources gives the board to the renderer. // Patterns are bitmaps or icons (loaded through pageResources); for rotating, the icons // whose names start with the element's text, listed once per change of the icons. class LifePlayer { public: // The shown page changed or was loaded again. A Life element that starts the same way // (sameLifeStart) keeps running with the new timing; otherwise it starts again. void setPage(const DynamicPage &page); // Starts a run when needed, steps when a generation is due, restarts after the hold time void tick(uint32_t now); // The running board when the element starts like the running one, otherwise nullptr const LifeRunner *runner(const PageElement &element) const; private: LifeRunner _runner; PageElement _element; bool _active = false; bool _start_needed = false; uint32_t _random = 0; int _pattern = -1; // index in _patterns of the running one std::vector _patterns; bool _patterns_loaded = false; uint32_t _patterns_revision = 0; String _patterns_start; void _start(uint32_t now); bool _place(const char *name); void _loadPatterns(); }; extern LifePlayer lifePlayer;