MythTV master
ifs_display.cpp
Go to the documentation of this file.
1#include <algorithm>
2#include <array>
3#include <cstdint>
4
5#include "ifs.h"
6#include "goomconfig.h"
7#include "libmythbase/mythconfig.h"
9
10#if HAVE_MMX
11#include "mmx.h"
12#endif
13
14#include "goom_tools.h"
15
16/* NOLINTNEXTLINE(readability-non-const-parameter) */
17void ifs_update (uint32_t * data, const uint32_t * back, int width, int height,
18 int increment)
19{
20 static int s_couleur = 0xc0c0c0c0;
21 static std::array<int,4> s_v { 2, 4, 3, 2 };
22 static std::array<int,4> s_col { 2, 4, 3, 2 };
23
24 enum MODE : std::uint8_t {
25 MOD_MER = 0,
26 MOD_FEU = 1,
27 MOD_MERVER = 2
28 };
29 static MODE s_mode = MOD_MERVER;
30 static int s_justChanged = 0;
31 static int s_cycle = 0;
32 int cycle10 = 0;
33 int couleursl = s_couleur;
34
35 s_cycle++;
36 if (s_cycle >= 80)
37 s_cycle = 0;
38
39 if (s_cycle < 40)
40 cycle10 = s_cycle / 10;
41 else
42 cycle10 = 7 - (s_cycle / 10);
43
44 {
45 auto *tmp = (unsigned char *) &couleursl;
46
47 for (int i = 0; i < 4; i++) {
48 *tmp = (*tmp) >> cycle10;
49 tmp++;
50 }
51 }
52
53 int nbpt = 0;
54 IFSPoint *points = draw_ifs (&nbpt);
55 nbpt--;
56
57#if HAVE_MMX
58 movd_m2r (couleursl, mm1);
59 punpckldq_r2r (mm1, mm1);
60 for (int i = 0; i < nbpt; i += increment) {
61 int x = points[i].x;
62 int y = points[i].y;
63
64 if ((x < width) && (y < height) && (x > 0) && (y > 0)) {
65 int pos = x + (y * width);
66 movd_m2r (back[pos], mm0);
67 paddusb_r2r (mm1, mm0);
68 movd_r2m (mm0, data[pos]);
69 }
70 }
71 emms();/*__asm__ __volatile__ ("emms");*/
72#else
73 for (int i = 0; i < nbpt; i += increment) {
74 int x = points[i].x & 0x7fffffff;
75 int y = points[i].y & 0x7fffffff;
76
77 if ((x < width) && (y < height)) {
78 int pos = x + (y * width);
79 int tra = 0;
80 auto *bra = (unsigned char *) &back[pos];
81 auto *dra = (unsigned char *) &data[pos];
82 auto *cra = (unsigned char *) &couleursl;
83
84 for (int j = 0; j < 4; j++) {
85 tra = *cra;
86 tra += *bra;
87 tra = std::min(tra, 255);
88 *dra = tra;
89 ++dra;
90 ++cra;
91 ++bra;
92 }
93 }
94 }
95#endif /* HAVE_MMX */
96 s_justChanged--;
97
98 s_col[ALPHA] = s_couleur >> (ALPHA * 8) & 0xff;
99 s_col[BLEU] = s_couleur >> (BLEU * 8) & 0xff;
100 s_col[VERT] = s_couleur >> (VERT * 8) & 0xff;
101 s_col[ROUGE] = s_couleur >> (ROUGE * 8) & 0xff;
102
103 if (s_mode == MOD_MER) {
104 s_col[BLEU] += s_v[BLEU];
105 if (s_col[BLEU] > 255) {
106 s_col[BLEU] = 255;
107 s_v[BLEU] = MythRandomInt(-4, -1);
108 }
109 if (s_col[BLEU] < 32) {
110 s_col[BLEU] = 32;
111 s_v[BLEU] = MythRandomInt(1, 4);
112 }
113
114 s_col[VERT] += s_v[VERT];
115 if (s_col[VERT] > 200) {
116 s_col[VERT] = 200;
117 s_v[VERT] = MythRandomInt(-4, -2);
118 }
119 if (s_col[VERT] > s_col[BLEU]) {
120 s_col[VERT] = s_col[BLEU];
121 s_v[VERT] = s_v[BLEU];
122 }
123 if (s_col[VERT] < 32) {
124 s_col[VERT] = 32;
125 s_v[VERT] = MythRandomInt(2, 4);
126 }
127
128 s_col[ROUGE] += s_v[ROUGE];
129 if (s_col[ROUGE] > 64) {
130 s_col[ROUGE] = 64;
131 s_v[ROUGE] = MythRandomInt(-4, -1);
132 }
133 if (s_col[ROUGE] < 0) {
134 s_col[ROUGE] = 0;
135 s_v[ROUGE] = MythRandomInt(1, 4);
136 }
137
138 s_col[ALPHA] += s_v[ALPHA];
139 if (s_col[ALPHA] > 0) {
140 s_col[ALPHA] = 0;
141 s_v[ALPHA] = MythRandomInt(-4, -1);
142 }
143 if (s_col[ALPHA] < 0) {
144 s_col[ALPHA] = 0;
145 s_v[ALPHA] = MythRandomInt(1, 4);
146 }
147
148 if (((s_col[VERT] > 32) && (s_col[ROUGE] < s_col[VERT] + 40)
149 && (s_col[VERT] < s_col[ROUGE] + 20) && (s_col[BLEU] < 64)
150 && rand_bool(20)) && (s_justChanged < 0)) {
151 s_mode = !rand_bool(3) ? MOD_FEU : MOD_MERVER;
152 s_justChanged = 250;
153 }
154 }
155 else if (s_mode == MOD_MERVER) {
156 s_col[BLEU] += s_v[BLEU];
157 if (s_col[BLEU] > 128) {
158 s_col[BLEU] = 128;
159 s_v[BLEU] = MythRandomInt(-4, -1);
160 }
161 if (s_col[BLEU] < 16) {
162 s_col[BLEU] = 16;
163 s_v[BLEU] = MythRandomInt(1, 4);
164 }
165
166 s_col[VERT] += s_v[VERT];
167 if (s_col[VERT] > 200) {
168 s_col[VERT] = 200;
169 s_v[VERT] = MythRandomInt(-4, -2);
170 }
171 if (s_col[VERT] > s_col[ALPHA]) {
172 s_col[VERT] = s_col[ALPHA];
173 s_v[VERT] = s_v[ALPHA];
174 }
175 if (s_col[VERT] < 32) {
176 s_col[VERT] = 32;
177 s_v[VERT] = MythRandomInt(2, 4);
178 }
179
180 s_col[ROUGE] += s_v[ROUGE];
181 if (s_col[ROUGE] > 128) {
182 s_col[ROUGE] = 128;
183 s_v[ROUGE] = MythRandomInt(-4, -1);
184 }
185 if (s_col[ROUGE] < 0) {
186 s_col[ROUGE] = 0;
187 s_v[ROUGE] = MythRandomInt(1, 4);
188 }
189
190 s_col[ALPHA] += s_v[ALPHA];
191 if (s_col[ALPHA] > 255) {
192 s_col[ALPHA] = 255;
193 s_v[ALPHA] = MythRandomInt(-4, -1);
194 }
195 if (s_col[ALPHA] < 0) {
196 s_col[ALPHA] = 0;
197 s_v[ALPHA] = MythRandomInt(1, 4);
198 }
199
200 if (((s_col[VERT] > 32) && (s_col[ROUGE] < s_col[VERT] + 40)
201 && (s_col[VERT] < s_col[ROUGE] + 20) && (s_col[BLEU] < 64)
202 && rand_bool(20)) && (s_justChanged < 0)) {
203 s_mode = !rand_bool(3) ? MOD_FEU : MOD_MER;
204 s_justChanged = 250;
205 }
206 }
207 else if (s_mode == MOD_FEU) {
208
209 s_col[BLEU] += s_v[BLEU];
210 if (s_col[BLEU] > 64) {
211 s_col[BLEU] = 64;
212 s_v[BLEU] = MythRandomInt(-4, -1);
213 }
214 if (s_col[BLEU] < 0) {
215 s_col[BLEU] = 0;
216 s_v[BLEU] = MythRandomInt(1, 4);
217 }
218
219 s_col[VERT] += s_v[VERT];
220 if (s_col[VERT] > 200) {
221 s_col[VERT] = 200;
222 s_v[VERT] = MythRandomInt(-4, -2);
223 }
224 if (s_col[VERT] > s_col[ROUGE] + 20) {
225 s_col[VERT] = s_col[ROUGE] + 20;
226 s_v[VERT] = MythRandomInt(-4, -2);
227 s_v[ROUGE] = MythRandomInt(1, 4);
228 s_v[BLEU] = MythRandomInt(1, 4);
229 }
230 if (s_col[VERT] < 0) {
231 s_col[VERT] = 0;
232 s_v[VERT] = MythRandomInt(2, 4);
233 }
234
235 s_col[ROUGE] += s_v[ROUGE];
236 if (s_col[ROUGE] > 255) {
237 s_col[ROUGE] = 255;
238 s_v[ROUGE] = MythRandomInt(-4, -1);
239 }
240 if (s_col[ROUGE] > s_col[VERT] + 40) {
241 s_col[ROUGE] = s_col[VERT] + 40;
242 s_v[ROUGE] = MythRandomInt(-4, -1);
243 }
244 if (s_col[ROUGE] < 0) {
245 s_col[ROUGE] = 0;
246 s_v[ROUGE] = MythRandomInt(1, 4);
247 }
248
249 s_col[ALPHA] += s_v[ALPHA];
250 if (s_col[ALPHA] > 0) {
251 s_col[ALPHA] = 0;
252 s_v[ALPHA] = MythRandomInt(-4, -1);
253 }
254 if (s_col[ALPHA] < 0) {
255 s_col[ALPHA] = 0;
256 s_v[ALPHA] = MythRandomInt(1, 4);
257 }
258
259 if (((s_col[ROUGE] < 64) && (s_col[VERT] > 32) && (s_col[VERT] < s_col[BLEU])
260 && (s_col[BLEU] > 32)
261 && rand_bool(20)) && (s_justChanged < 0)) {
262 s_mode = rand_bool() ? MOD_MER : MOD_MERVER;
263 s_justChanged = 250;
264 }
265 }
266
267 s_couleur = (s_col[ALPHA] << (ALPHA * 8))
268 | (s_col[BLEU] << (BLEU * 8))
269 | (s_col[VERT] << (VERT * 8))
270 | (s_col[ROUGE] << (ROUGE * 8));
271}
static uint32_t * back
Definition: goom_core.cpp:27
static uint32_t * tmp
Definition: goom_core.cpp:28
#define VERT
Definition: goomconfig.h:12
#define ROUGE
position des composantes
Definition: goomconfig.h:10
#define BLEU
Definition: goomconfig.h:11
#define ALPHA
Definition: goomconfig.h:13
IFSPoint * draw_ifs(int *nbPoints)
Definition: ifs.cpp:409
void ifs_update(uint32_t *data, const uint32_t *back, int width, int height, int increment)
Definition: ifs_display.cpp:17
#define emms()
Definition: mmx.h:82
#define punpckldq_r2r(regs, regd)
Definition: mmx.h:212
#define paddusb_r2r(regs, regd)
Definition: mmx.h:121
#define movd_r2m(reg, var)
Definition: mmx.h:85
#define movd_m2r(var, reg)
Definition: mmx.h:84
Convenience inline random number generator functions.
#define MODE
int MythRandomInt(int min, int max)
generate a uniformly distributed random signed int in the closed interval [min, max].
Definition: mythrandom.h:58
bool rand_bool(uint32_t chance=2)
return a random bool with P(true) = 1/chance
Definition: mythrandom.h:86
Definition: ifs.h:11
int32_t x
Definition: ifs.h:12
int32_t y
Definition: ifs.h:12