Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_fluid.c
Go to the documentation of this file.
1
9#define ALLEGRO_UNSTABLE 1
10
11#include <locale.h>
12
13#include "nilorea/n_common.h"
14#include "nilorea/n_log.h"
15#include "nilorea/n_list.h"
16#include "nilorea/n_str.h"
17#include "nilorea/n_time.h"
18#include "nilorea/n_fluids.h"
19
20#include <allegro5/allegro.h>
21#include <allegro5/allegro_ttf.h>
22#include "allegro5/allegro_audio.h"
23#include "allegro5/allegro_acodec.h"
24#include <allegro5/allegro_font.h>
25#include <allegro5/allegro_image.h>
26#include <allegro5/allegro_primitives.h>
27
28#include "ex_fluid_config.h"
29
31#define RESERVED_SAMPLES 16
33#define MAX_SAMPLE_DATA 10
34
35ALLEGRO_DISPLAY* display = NULL;
36
37/******************************************************************************
38 * VARIOUS DECLARATIONS *
39 ******************************************************************************/
40
41int DONE = 0, /* Flag to check if we are always running */
42 getoptret = 0, /* launch parameter check */
43 log_level = LOG_ERR; /* default LOG_LEVEL */
44
45double drawFPS = 60.0;
46double logicFPS = 120.0;
47
48ALLEGRO_TIMER* fps_timer = NULL;
49ALLEGRO_TIMER* logic_timer = NULL;
52
54size_t WIDTH = 800,
55 HEIGHT = 600;
56bool fullscreen = 0;
57char* bgmusic = NULL;
58
60
61int main(int argc, char* argv[]) {
62 /* Set the locale to the POSIX C environment */
63 setlocale(LC_ALL, "POSIX");
64
66
67 N_STR* log_file = NULL;
68 nstrprintf(log_file, "%s.log", argv[0]);
69 /*set_log_file( _nstr( log_file ) );*/
71
72 char ver_str[128] = "";
73
74 while ((getoptret = getopt(argc, argv, "hvV:L:")) != EOF) {
75 switch (getoptret) {
76 case 'h':
77 n_log(LOG_NOTICE, "\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG)\n", argv[0]);
78 exit(TRUE);
79 case 'v':
80 sprintf(ver_str, "%s %s", __DATE__, __TIME__);
81 exit(TRUE);
82 break;
83 case 'V':
84 if (!strncmp("INFO", optarg, 6)) {
86 } else {
87 if (!strncmp("NOTICE", optarg, 6)) {
89 } else {
90 if (!strncmp("VERBOSE", optarg, 7)) {
92 } else {
93 if (!strncmp("ERROR", optarg, 5)) {
95 } else {
96 if (!strncmp("DEBUG", optarg, 5)) {
98 } else {
99 n_log(LOG_ERR, "%s is not a valid log level", optarg);
100 exit(FALSE);
101 }
102 }
103 }
104 }
105 }
106 n_log(LOG_NOTICE, "LOG LEVEL UP TO: %d", log_level);
108 break;
109 case 'L':
110 n_log(LOG_NOTICE, "LOG FILE: %s", optarg);
111 set_log_file(optarg);
112 break;
113 case '?': {
114 switch (optopt) {
115 case 'V':
116 n_log(LOG_ERR, "\nPlease specify a log level after -V. \nAvailable values: NOLOG,VERBOSE,NOTICE,ERROR,DEBUG");
117 break;
118 case 'L':
119 n_log(LOG_ERR, "\nPlease specify a log file after -L");
120 default:
121 break;
122 }
123 }
124 __attribute__((fallthrough));
125 default:
126 n_log(LOG_ERR, "\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG) -L logfile", argv[0]);
127 exit(FALSE);
128 }
129 }
130 /*
131 * INITIALISATION
132 */
133 int threadedProcessing = 0;
134 N_FLUID* fluid_data = NULL;
135 Malloc(fluid_data, N_FLUID, 1);
136 if (load_app_state("CONFIGS/ex_fluid.cfg", &WIDTH, &HEIGHT, &fullscreen, &bgmusic, &drawFPS, &logicFPS, fluid_data, &threadedProcessing) != TRUE) {
137 n_log(LOG_ERR, "couldn't load CONFIGS/ex_fluid.cfg !");
138 exit(1);
139 }
140 double fluid_factor = fluid_data->cScale;
141 n_log(LOG_DEBUG, "%s starting with params: %dx%d fullscreen(%d), music: %s", argv[0], WIDTH, HEIGHT, fullscreen, _str(bgmusic));
142
143 /* allegro 5 + addons loading */
144 if (!al_init()) {
145 n_abort("Could not init Allegro.\n");
146 }
147 if (!al_init_acodec_addon()) {
148 n_abort("Could not register addons.\n");
149 }
150 if (!al_install_audio()) {
151 n_log(LOG_ERR, "Unable to initialize audio addon, disabling bgmusic\n");
152 Free(bgmusic);
153 }
154 if (!al_init_acodec_addon()) {
155 n_abort("Unable to initialize acoded addon\n");
156 }
157 if (!al_init_image_addon()) {
158 n_abort("Unable to initialize image addon\n");
159 }
160 if (!al_init_primitives_addon()) {
161 n_abort("Unable to initialize primitives addon\n");
162 }
163 if (!al_init_font_addon()) {
164 n_abort("Unable to initialize font addon\n");
165 }
166 if (!al_init_ttf_addon()) {
167 n_abort("Unable to initialize ttf_font addon\n");
168 }
169 if (!al_install_keyboard()) {
170 n_abort("Unable to initialize keyboard handler\n");
171 }
172 if (!al_install_mouse()) {
173 n_abort("Unable to initialize mouse handler\n");
174 }
175
176 if (bgmusic && !al_reserve_samples(RESERVED_SAMPLES)) {
177 n_abort("Could not set up voice and mixer.\n");
178 }
179
180 ALLEGRO_SAMPLE* sample_data[MAX_SAMPLE_DATA] = {NULL};
181 memset(sample_data, 0, sizeof(sample_data));
182
183 ALLEGRO_EVENT_QUEUE* event_queue = NULL;
184
185 event_queue = al_create_event_queue();
186 if (!event_queue) {
187 fprintf(stderr, "failed to create event_queue!\n");
188 return -1;
189 }
190
191 if (fullscreen) {
192 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_FULLSCREEN_WINDOW);
193 } else {
194 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
195 }
196
197#ifdef __windows__
198 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP | ALLEGRO_NO_PRESERVE_TEXTURE);
199#endif
200
201 display = al_create_display(WIDTH, HEIGHT);
202 if (!display) {
203 n_abort("Unable to create display\n");
204 }
205
206 al_set_window_title(display, argv[0]);
207
208 ALLEGRO_FONT* font = al_load_font("DATAS/2Dumb.ttf", 18, 0);
209 if (!font) {
210 n_abort("Unable to load font DATAS/2Dumb.ttf\n");
211 }
212
213 DONE = 0;
214 fps_timer = al_create_timer(1.0 / drawFPS);
215 logic_timer = al_create_timer(1.0 / logicFPS);
216
217 al_register_event_source(event_queue, al_get_display_event_source(display));
218 al_start_timer(fps_timer);
219 al_start_timer(logic_timer);
220 al_register_event_source(event_queue, al_get_timer_event_source(fps_timer));
221 al_register_event_source(event_queue, al_get_timer_event_source(logic_timer));
222
223 al_register_event_source(event_queue, al_get_keyboard_event_source());
224 al_register_event_source(event_queue, al_get_mouse_event_source());
225
226 bool backbuffer = 1;
227 ALLEGRO_BITMAP* scrbuf = NULL;
228 ALLEGRO_BITMAP* bitmap = al_create_bitmap(WIDTH, HEIGHT);
229
230 al_hide_mouse_cursor(display);
231
232 enum APP_KEYS {
233 KEY_UP,
234 KEY_DOWN,
235 KEY_LEFT,
236 KEY_RIGHT,
237 KEY_ESC,
238 KEY_SPACE,
239 KEY_CTRL,
240 KEY_SHIFT,
241 KEY_PAD_MINUS,
242 KEY_PAD_PLUS,
243 KEY_PAD_ENTER,
244 KEY_M,
245 KEY_W,
246 KEY_F1,
247 KEY_F2,
248 KEY_F3,
249 KEY_F4,
250 KEY_F5,
251 KEY_F6
252 };
253 int key[19] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
254
255 if (bgmusic) {
256 if (!(sample_data[0] = al_load_sample(bgmusic))) {
257 n_log(LOG_ERR, "Could not load %s", bgmusic);
258 exit(1);
259 }
260 al_play_sample(sample_data[0], 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, NULL);
261 }
262
264
265 /* set fluid */
266 fluid_sim = new_n_fluid(fluid_data->density, fluid_data->gravity, fluid_data->numIters, fluid_data->fluid_production_percentage, fluid_data->overRelaxation, WIDTH / fluid_factor, HEIGHT / fluid_factor);
267
268 fluid_sim->density = fluid_data->density;
269 fluid_sim->gravity = fluid_data->gravity;
270 fluid_sim->numIters = fluid_data->numIters;
273 fluid_sim->cScale = fluid_data->cScale;
274 Free(fluid_data);
275
276 fluid_sim->dt = 1.0 / logicFPS;
277
278 size_t n = fluid_sim->numY;
279 double inVel = 2.0;
280 for (size_t i = 0; i < fluid_sim->numX; i++) {
281 for (size_t j = 0; j < fluid_sim->numY; j++) {
282 double s = 1.0; // fluid
283 if (i == 0 || j == 0 || j == fluid_sim->numY - 1)
284 s = 0.0; // solid
285 //
286 fluid_sim->s[i * n + j] = s;
287
288 if (i == 1) {
289 fluid_sim->u[i * n + j] = inVel;
290 }
291 }
292 }
294 size_t minJ = floor(0.5 * fluid_sim->numY - 0.5 * pipeH);
295 size_t maxJ = floor(0.5 * fluid_sim->numY + 0.5 * pipeH);
296 for (size_t j = 0; j < minJ; j++)
297 fluid_sim->m[j] = 1.0;
298 for (size_t j = minJ; j < maxJ; j++)
299 fluid_sim->m[j] = 0.0;
300 for (size_t j = maxJ; j < fluid_sim->numY; j++)
301 fluid_sim->m[j] = 1.0;
302
303 bool do_draw = 1, do_logic = 1;
304 int mx = WIDTH / 3, my = HEIGHT / 2, mouse_button = 0, mouse_b1 = 0, mouse_b2 = 0;
305
307
308 al_flush_event_queue(event_queue);
309 al_set_mouse_xy(display, WIDTH / 3, HEIGHT / 2);
310
311 int w = al_get_display_width(display);
312 int h = al_get_display_height(display);
313
314 bitmap = al_create_bitmap(WIDTH, HEIGHT);
315
316 size_t logic_duration = 0;
317 size_t drawing_duration = 0;
318 do {
319 do {
320 ALLEGRO_EVENT ev;
321
322 al_wait_for_event(event_queue, &ev);
323
324 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
325 switch (ev.keyboard.keycode) {
326 case ALLEGRO_KEY_UP:
327 key[KEY_UP] = 1;
328 break;
329 case ALLEGRO_KEY_DOWN:
330 key[KEY_DOWN] = 1;
331 break;
332 case ALLEGRO_KEY_LEFT:
333 key[KEY_LEFT] = 1;
334 break;
335 case ALLEGRO_KEY_RIGHT:
336 key[KEY_RIGHT] = 1;
337 break;
338 case ALLEGRO_KEY_ESCAPE:
339 key[KEY_ESC] = 1;
340 break;
341 case ALLEGRO_KEY_SPACE:
342 key[KEY_SPACE] = 1;
343 break;
344 case ALLEGRO_KEY_LSHIFT:
345 case ALLEGRO_KEY_RSHIFT:
346 key[KEY_SHIFT] = 1;
347 break;
348 case ALLEGRO_KEY_PAD_MINUS:
349 key[KEY_PAD_MINUS] = 1;
350 break;
351 case ALLEGRO_KEY_PAD_PLUS:
352 key[KEY_PAD_PLUS] = 1;
353 break;
354 case ALLEGRO_KEY_PAD_ENTER:
355 key[KEY_PAD_ENTER] = 1;
356 break;
357 case ALLEGRO_KEY_M:
358 key[KEY_M] = 1;
359 break;
360 case ALLEGRO_KEY_W:
361 key[KEY_W] = 1;
362 break;
363 case ALLEGRO_KEY_LCTRL:
364 case ALLEGRO_KEY_RCTRL:
365 key[KEY_CTRL] = 1;
366 break;
367 case ALLEGRO_KEY_F1:
368 key[KEY_F1] = 1;
369 break;
370 case ALLEGRO_KEY_F2:
371 key[KEY_F2] = 1;
372 break;
373 case ALLEGRO_KEY_F3:
374 key[KEY_F3] = 1;
375 break;
376 case ALLEGRO_KEY_F4:
377 key[KEY_F4] = 1;
378 break;
379 case ALLEGRO_KEY_F5:
380 key[KEY_F5] = 1;
381 break;
382 case ALLEGRO_KEY_F6:
383 key[KEY_F6] = 1;
384 break;
385 default:
386 break;
387 }
388 } else if (ev.type == ALLEGRO_EVENT_KEY_UP) {
389 switch (ev.keyboard.keycode) {
390 case ALLEGRO_KEY_UP:
391 key[KEY_UP] = 0;
392 break;
393 case ALLEGRO_KEY_DOWN:
394 key[KEY_DOWN] = 0;
395 break;
396 case ALLEGRO_KEY_LEFT:
397 key[KEY_LEFT] = 0;
398 break;
399 case ALLEGRO_KEY_RIGHT:
400 key[KEY_RIGHT] = 0;
401 break;
402 case ALLEGRO_KEY_ESCAPE:
403 key[KEY_ESC] = 0;
404 break;
405 case ALLEGRO_KEY_SPACE:
406 key[KEY_SPACE] = 0;
407 break;
408 case ALLEGRO_KEY_LSHIFT:
409 case ALLEGRO_KEY_RSHIFT:
410 key[KEY_SHIFT] = 0;
411 break;
412 case ALLEGRO_KEY_PAD_MINUS:
413 key[KEY_PAD_MINUS] = 0;
414 break;
415 case ALLEGRO_KEY_PAD_PLUS:
416 key[KEY_PAD_PLUS] = 0;
417 break;
418 case ALLEGRO_KEY_PAD_ENTER:
419 key[KEY_PAD_ENTER] = 0;
420 break;
421 case ALLEGRO_KEY_M:
422 key[KEY_M] = 0;
423 break;
424 case ALLEGRO_KEY_W:
425 key[KEY_W] = 0;
426 break;
427 case ALLEGRO_KEY_LCTRL:
428 case ALLEGRO_KEY_RCTRL:
429 key[KEY_CTRL] = 0;
430 break;
431 case ALLEGRO_KEY_F1:
432 key[KEY_F1] = 0;
433 break;
434 case ALLEGRO_KEY_F2:
435 key[KEY_F2] = 0;
436 break;
437 case ALLEGRO_KEY_F3:
438 key[KEY_F3] = 0;
439 break;
440 case ALLEGRO_KEY_F4:
441 key[KEY_F4] = 0;
442 break;
443 case ALLEGRO_KEY_F5:
444 key[KEY_F5] = 0;
445 break;
446 case ALLEGRO_KEY_F6:
447 key[KEY_F6] = 0;
448 break;
449
450 default:
451 break;
452 }
453 } else if (ev.type == ALLEGRO_EVENT_TIMER) {
454 if (al_get_timer_event_source(fps_timer) == ev.any.source) {
455 do_draw = 1;
456 } else if (al_get_timer_event_source(logic_timer) == ev.any.source) {
457 do_logic = 1;
458 }
459 } else if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) {
460 mx = ev.mouse.x;
461 my = ev.mouse.y;
462 } else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
463 if (ev.mouse.button == 1)
464 mouse_b1 = 1;
465 if (ev.mouse.button == 2)
466 mouse_b2 = 1;
467 } else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
468 if (ev.mouse.button == 1)
469 mouse_b1 = 0;
470 if (ev.mouse.button == 2)
471 mouse_b2 = 0;
472 }
473
474 /* Processing inputs */
475 mouse_button = -1;
476 if (mouse_b1 == 1)
477 mouse_button = 1;
478 if (mouse_b2 == 1)
479 mouse_button = 2;
480 else if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN || ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) {
481 al_clear_keyboard_state(display);
482 al_flush_event_queue(event_queue);
483 } else {
484 // Processing inputs
485 // get_keyboard( chat_line , ev );
486 if (key[KEY_F1]) {
487 fluid_sim->showSmoke = 1;
488 }
489 if (key[KEY_F2]) {
490 fluid_sim->showSmoke = 0;
491 }
492 if (key[KEY_F3]) {
494 }
495 if (key[KEY_F4]) {
497 }
498 if (key[KEY_F5]) {
499 fluid_sim->showPaint = 1;
500 }
501 if (key[KEY_F6]) {
502 fluid_sim->showPaint = 0;
503 }
504 if (key[KEY_UP]) {
505 fluid_sim->density += 100.0;
506 }
507 if (key[KEY_DOWN]) {
508 fluid_sim->density -= 100.0;
509 if (fluid_sim->density < 1.0) fluid_sim->density = 1.0;
510 }
511 if (key[KEY_LEFT]) {
513 }
514 if (key[KEY_RIGHT]) {
516 if (fluid_sim->numIters < 1.0) fluid_sim->numIters = 1.0;
517 }
518 if (key[KEY_PAD_PLUS]) {
521 }
522 if (key[KEY_PAD_MINUS]) {
525 }
526 if (mouse_button != -1) {
527 n_log(LOG_DEBUG, "mouse button: %d", mouse_button);
528 }
529 }
530 } while (!al_is_event_queue_empty(event_queue));
531
532 if (do_logic == 1) {
534 static int old_mx = -1, old_my = -1;
535 double vx = 0.0, vy = 0.0;
536 if (old_mx != mx || old_my != my) {
537 if (old_mx != -1 && old_my != -1) {
538 vx = (old_mx - mx) / logicFPS;
539 vy = (old_my - my) / logicFPS;
540 }
541 old_mx = mx;
542 old_my = my;
544 n_fluid_setObstacle(fluid_sim, mx / fluid_factor, (my / fluid_factor) - 20.0, vx, vy, fluid_factor / 2);
545 n_fluid_setObstacle(fluid_sim, (mx / fluid_factor) - 15, my / fluid_factor, vx, vy, fluid_factor / 2 + fluid_factor / 3);
546 n_fluid_setObstacle(fluid_sim, (mx / fluid_factor) + 15, my / fluid_factor - 10.0, vx, vy, fluid_factor / 2 + fluid_factor / 2);
547 n_fluid_setObstacle(fluid_sim, (mx / fluid_factor) + 15, my / fluid_factor + 10.0, vx, vy, fluid_factor / 2 + fluid_factor / 2);
548 n_fluid_setObstacle(fluid_sim, mx / fluid_factor, (my / fluid_factor) + 20.0, vx, vy, fluid_factor / 2);
549 }
550
552 minJ = floor(0.5 * fluid_sim->numY - 0.5 * pipeH);
553 maxJ = floor(0.5 * fluid_sim->numY + 0.5 * pipeH);
554 for (size_t j = 0; j < minJ; j++)
555 fluid_sim->m[j] = 1.0;
556 for (size_t j = minJ; j < maxJ; j++)
557 fluid_sim->m[j] = 0.0;
558 for (size_t j = maxJ; j < fluid_sim->numY; j++)
559 fluid_sim->m[j] = 1.0;
560 for (size_t j = minJ; j < maxJ; j++)
561 fluid_sim->m[j] = 0.0;
562
563 if (threadedProcessing == 1)
565 else
567
568 logic_duration = (logic_duration + get_usec(&logic_chrono)) / 2;
569 do_logic = 0;
570 }
571 if (do_draw == 1) {
573
574 if (backbuffer)
575 scrbuf = al_get_backbuffer(display);
576 else
577 scrbuf = bitmap;
578
579 al_set_target_bitmap(scrbuf);
580
581 if (!backbuffer)
582 al_lock_bitmap(scrbuf, al_get_bitmap_format(scrbuf), ALLEGRO_LOCK_READWRITE);
583
585
586 al_draw_circle(mx, my - 20 * fluid_factor, fluid_factor * fluid_factor / 2, al_map_rgb(255, 0, 0), 2.0);
587 al_draw_circle(mx - 15 * fluid_factor, my, fluid_factor * fluid_factor / 2 + (fluid_factor * fluid_factor) / 3, al_map_rgb(255, 0, 0), 2.0);
588 al_draw_circle(mx + 15 * fluid_factor, my + 10.0 * fluid_factor, fluid_factor * fluid_factor / 2 + (fluid_factor * fluid_factor) / 2, al_map_rgb(255, 0, 0), 2.0);
589 al_draw_circle(mx + 15 * fluid_factor, my - 10.0 * fluid_factor, fluid_factor * fluid_factor / 2 + (fluid_factor * fluid_factor) / 2, al_map_rgb(255, 0, 0), 2.0);
590 al_draw_circle(mx, my + 20 * fluid_factor, fluid_factor * fluid_factor / 2, al_map_rgb(255, 0, 0), 2.0);
591
592 static N_STR* textout = NULL;
593 nstrprintf(textout, "[F1/F2]:showSmoke:%d [F3/F4]:showPressure:%d [F5/F6]:showPaint:%d", fluid_sim->showSmoke, fluid_sim->showPressure, fluid_sim->showPaint);
594 al_draw_text(font, al_map_rgb(0, 0, 255), WIDTH, 10, ALLEGRO_ALIGN_RIGHT, _nstr(textout));
595
596 nstrprintf(textout, "numIters: %zd production: %3.3g density: %3.3g", fluid_sim->numIters, fluid_sim->fluid_production_percentage, fluid_sim->density);
597 al_draw_text(font, al_map_rgb(0, 0, 255), WIDTH, 25, ALLEGRO_ALIGN_RIGHT, _nstr(textout));
598
599 nstrprintf(textout, "logic(max %zd): %zd usecs", (size_t)(1000000.0 / logicFPS), logic_duration);
600 al_draw_text(font, al_map_rgb(0, 0, 255), 5, 10, ALLEGRO_ALIGN_LEFT, _nstr(textout));
601
602 nstrprintf(textout, "drawing(max %zd): %zd usecs", (size_t)(1000000.0 / drawFPS), drawing_duration);
603 al_draw_text(font, al_map_rgb(0, 0, 255), 5, 30, ALLEGRO_ALIGN_LEFT, _nstr(textout));
604
605 if (!backbuffer) {
606 al_unlock_bitmap(scrbuf);
607 al_set_target_bitmap(al_get_backbuffer(display));
608 al_draw_bitmap(scrbuf, w / 2 - al_get_bitmap_width(scrbuf) / 2, h / 2 - al_get_bitmap_height(scrbuf) / 2, 0);
609 }
610
611 drawing_duration = (drawing_duration + get_usec(&drawing_chrono)) / 2;
612
613 al_flip_display();
614
615 do_draw = 0;
616 }
617
618 } while (!key[KEY_ESC] && !DONE);
619
620 al_uninstall_system();
621
622 return 0;
623}
int main(void)
ALLEGRO_TIMER * fps_timer
Definition ex_fluid.c:48
THREAD_POOL * thread_pool
Definition ex_fluid.c:59
#define MAX_SAMPLE_DATA
audio MAX_SAMPLE_DATA for bgmusic
Definition ex_fluid.c:33
int getoptret
Definition ex_fluid.c:42
double drawFPS
Definition ex_fluid.c:45
int DONE
Definition ex_fluid.c:41
bool fullscreen
Definition ex_fluid.c:56
N_TIME drawing_chrono
Definition ex_fluid.c:51
N_FLUID * fluid_sim
Definition ex_fluid.c:53
N_TIME logic_chrono
Definition ex_fluid.c:50
int log_level
Definition ex_fluid.c:43
char * bgmusic
Definition ex_fluid.c:57
#define RESERVED_SAMPLES
audio RESERVED_SAMPLES for bgmusic
Definition ex_fluid.c:31
ALLEGRO_TIMER * logic_timer
Definition ex_fluid.c:49
double logicFPS
Definition ex_fluid.c:46
ALLEGRO_DISPLAY * display
Definition ex_fluid.c:35
int load_app_state(char *state_filename, size_t *WIDTH, size_t *HEIGHT, bool *fullscreen, char **bgmusic, double *drawFPS, double *logicFPS, N_FLUID *fluid, int *threaded)
#define WIDTH
Definition ex_gui.c:9
#define HEIGHT
Definition ex_gui.c:10
char * key
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
Definition n_common.h:185
#define _str(__PTR)
define true
Definition n_common.h:174
void n_abort(char const *format,...)
abort program with a text
Definition n_common.c:39
#define Free(__ptr)
Free Handler to get errors.
Definition n_common.h:240
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
Definition n_common.h:180
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition n_log.h:70
#define LOG_DEBUG
debug-level messages
Definition n_log.h:65
#define LOG_ERR
error conditions
Definition n_log.h:57
int set_log_file(char *file)
Set the logging to a file instead of stderr.
Definition n_log.c:151
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition n_log.c:104
#define LOG_NOTICE
normal but significant condition
Definition n_log.h:61
#define LOG_INFO
informational
Definition n_log.h:63
size_t numY
number of cells in Y
Definition n_fluids.h:55
double fluid_production_percentage
size of the produced fluid
Definition n_fluids.h:85
bool showSmoke
display fluid as a colored cloud instead of black and white, can be combined with showPressure
Definition n_fluids.h:73
size_t numX
number of cells in X
Definition n_fluids.h:53
double overRelaxation
over relaxation
Definition n_fluids.h:71
bool showPressure
display fluids pressures as color variations, can be combined with showSmoke
Definition n_fluids.h:77
bool showPaint
activate a fonky palette, override smoke and pressure display
Definition n_fluids.h:75
double * u
holder for u arrays
Definition n_fluids.h:90
double dt
time between frames
Definition n_fluids.h:65
double * s
holder for s arrays
Definition n_fluids.h:102
size_t numIters
number of fluid processing iterations for each frame
Definition n_fluids.h:61
double density
density of the fluid (not working ?)
Definition n_fluids.h:63
double * m
holder for m arrays
Definition n_fluids.h:105
double cScale
scale used to deduce cellX and cellY from screen/window width and height
Definition n_fluids.h:87
double gravity
gravity on Y
Definition n_fluids.h:69
int n_fluid_draw(N_FLUID *fluid)
draw a N_FLUID on screen / targert bitmap
Definition n_fluids.c:782
int n_fluid_simulate_threaded(N_FLUID *fluid, THREAD_POOL *thread_pool)
a threaded version of N_FLUID global processing function
Definition n_fluids.c:580
int n_fluid_simulate(N_FLUID *fluid)
non threaded version of N_FLUID global processing function
Definition n_fluids.c:563
int n_fluid_resetObstacles(N_FLUID *fluid)
reset the obstacles set in a N_FLUID
Definition n_fluids.c:679
int n_fluid_setObstacle(N_FLUID *fluid, double x, double y, double vx, double vy, double r)
set an obstacle in the fluid grid
Definition n_fluids.c:652
N_FLUID * new_n_fluid(double density, double gravity, size_t numIters, double dt, double overRelaxation, size_t sx, size_t sy)
return a newly allocated fluid
Definition n_fluids.c:72
structure of a fluid
Definition n_fluids.h:51
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
Definition n_str.h:176
#define nstrprintf(__nstr_var, __format,...)
Macro to quickly allocate and sprintf to N_STR.
Definition n_str.h:94
A box including a string and his lenght.
Definition n_str.h:39
int start_HiTimer(N_TIME *timer)
Initialize or restart from zero any N_TIME HiTimer.
Definition n_time.c:67
time_t get_usec(N_TIME *timer)
Poll any N_TIME HiTimer, returning usec, and moving currentTime to startTime.
Definition n_time.c:89
Timing Structure.
Definition n_time.h:32
THREAD_POOL * new_thread_pool(size_t nbmaxthr, size_t nb_max_waiting)
Create a new pool of nbmaxthr threads.
long int get_nb_cpu_cores()
get number of core of current system
Structure of a trhead pool.
Common headers and low-level functions & define.
Fluid management port from "How to write an Eulerian fluid simulator with 200 lines of code",...
List structures and definitions.
static FILE * log_file
static FILE handling if logging to file is enabled
Definition n_log.c:67
Generic log system.
__attribute__((unused))
Definition n_network.c:1071
N_STR and string function declaration.
Timing utilities.