Public Access
A new page element runs Conway's Game of Life in an area (the whole display by default), one per page. Start: random dots, one pattern, or the icons whose names start with a text in turn or in random order. Edges: wrap around, dead, or a hidden margin where gliders fly out of view (leftovers that stay put in the margin are cleared, so a glider gun runs cleanly). It restarts when the board is still or repeats within 16 generations and/or after a number of generations, after a hold time (an empty board at once). logic/life holds the board and timing (tested), display/life_player runs the board of the shown page, ticked before each frame; frames are paced like scrolling text. The element reuses existing fields, so the page format stays the same. The Icons tab has a library of 17 LifeWiki patterns (checked with a simulation), and the built-in page "Game of Life" shuffles through the life_ icons. About 12 KB flash, 8 KB RAM. Version 2.17.0, tested on the display over OTA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <vector>
|
|
|
|
#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<String> _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;
|