-
Notifications
You must be signed in to change notification settings - Fork 746
/
LIFE.cpp
119 lines (108 loc) · 2.58 KB
/
LIFE.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "simulation/ElementCommon.h"
static int graphics(GRAPHICS_FUNC_ARGS);
static void create(ELEMENT_CREATE_FUNC_ARGS);
void Element::Element_LIFE()
{
Identifier = "DEFAULT_PT_LIFE";
Name = "LIFE";
Colour = 0x0CAC00_rgb;
MenuVisible = 0;
MenuSection = SC_LIFE;
Enabled = 1;
Advection = 0.0f;
AirDrag = 0.00f * CFDS;
AirLoss = 0.90f;
Loss = 0.00f;
Collision = 0.0f;
Gravity = 0.0f;
Diffusion = 0.00f;
HotAir = 0.000f * CFDS;
Falldown = 0;
Flammable = 0;
Explosive = 0;
Meltable = 0;
Hardness = 0;
Weight = 100;
DefaultProperties.temp = 9000.0f;
HeatConduct = 40;
Description = "Game Of Life! B3/S23";
Properties = TYPE_SOLID|PROP_LIFE;
LowPressure = IPL;
LowPressureTransition = NT;
HighPressure = IPH;
HighPressureTransition = NT;
LowTemperature = ITL;
LowTemperatureTransition = NT;
HighTemperature = ITH;
HighTemperatureTransition = NT;
Graphics = &graphics;
Create = &create;
}
static int graphics(GRAPHICS_FUNC_ARGS)
{
auto &builtinGol = SimulationData::builtinGol;
auto colour1 = RGB<uint8_t>::Unpack(cpart->dcolour);
auto colour2 = RGB<uint8_t>::Unpack(cpart->tmp);
if (!cpart->dcolour)
{
colour1 = 0xFFFFFF_rgb;
}
auto ruleset = cpart->ctype;
bool renderDeco = !gfctx.blackDecorations;
if (ruleset >= 0 && ruleset < NGOL)
{
if (!renderDeco || !gfctx.decorationsEnable)
{
colour1 = builtinGol[ruleset].colour;
colour2 = builtinGol[ruleset].colour2;
renderDeco = true;
}
ruleset = builtinGol[ruleset].ruleset;
}
if (renderDeco)
{
auto states = ((ruleset >> 17) & 0xF) + 2;
if (states == 2)
{
*colr = colour1.Red;
*colg = colour1.Green;
*colb = colour1.Blue;
}
else
{
auto mul = (cpart->tmp2 - 1) / float(states - 2);
*colr = int(colour1.Red * mul + colour2.Red * (1.f - mul));
*colg = int(colour1.Green * mul + colour2.Green * (1.f - mul));
*colb = int(colour1.Blue * mul + colour2.Blue * (1.f - mul));
}
}
*pixel_mode |= NO_DECO;
return 0;
}
static void create(ELEMENT_CREATE_FUNC_ARGS)
{
auto &sd = SimulationData::CRef();
auto &builtinGol = sd.builtinGol;
if (v == -1)
v = 0;
// * 0x200000: No need to look for colours, they'll be set later anyway.
bool skipLookup = v & 0x200000;
v &= 0x1FFFFF;
sim->parts[i].ctype = v;
if (v < NGOL)
{
sim->parts[i].dcolour = builtinGol[v].colour.Pack();
sim->parts[i].tmp = builtinGol[v].colour2.Pack();
v = builtinGol[v].ruleset;
}
else if (!skipLookup)
{
auto *cgol = sd.GetCustomGOLByRule(v);
if (cgol)
{
sim->parts[i].dcolour = cgol->colour1;
sim->parts[i].tmp = cgol->colour2;
}
}
sim->parts[i].tmp2 = ((v >> 17) & 0xF) + 1;
}