mirror of
https://git.lynn.is/Gwen/pretty-automata.git
synced 2024-06-01 20:59:33 +02:00
23 lines
641 B
Plaintext
23 lines
641 B
Plaintext
|
struct CellState {
|
||
|
bool alive;
|
||
|
bool starving;
|
||
|
uint age; // max 65025
|
||
|
uint starve_duration; // max 255
|
||
|
};
|
||
|
|
||
|
CellState cellstate_from_data(uint data) {
|
||
|
bool alive = (data & uint(0x1)) == 1;
|
||
|
bool starving = ((data >> 1) & uint(0x1)) == 1;
|
||
|
uint age = (data >> 8) & uint(0xFFFF);
|
||
|
uint starve_duration = (data >> 24) & uint(0xFF);
|
||
|
|
||
|
return CellState(alive, starving, age, starve_duration);
|
||
|
}
|
||
|
|
||
|
uint cellstate_to_data(CellState cellstate) {
|
||
|
return (cellstate.starve_duration << 24)
|
||
|
| (cellstate.age << 8)
|
||
|
| (cellstate.starving ? uint(0x2) : uint(0x0))
|
||
|
| (cellstate.alive ? uint(0x1) : uint(0x0));
|
||
|
}
|