int main (int argc, char **argv) { nile_Process_t *init; char *mem; int nthreads; if (argc > 1) { nthreads = atoi (argv[1]); if (nthreads < 1) nthreads = 1; if (nthreads > 100) nthreads = 100; } else nthreads = 1; log ("nthreads: %d", nthreads); mem = malloc (NBYTES_PER_THREAD * nthreads); init = nile_startup (mem, NBYTES_PER_THREAD * nthreads, nthreads); if (!init) die ("Failed to start up"); nile_sync (init); if (nile_error (init)) die ("nile_error gave error"); nile_print_leaks (init); if (nile_shutdown (init) != mem) die ("Didn't get memory back"); free (mem); log ("Success"); exit (0); }
int main (int argc, char **argv) { int i; gezira_Window_t window; nile_Process_t *init; gezira_snowflake_t flakes[NFLAKES]; int nthreads = 1; int mem_size; gezira_Window_init (&window, WINDOW_WIDTH, WINDOW_HEIGHT); for (i = 0; i < NFLAKES; i++) { flakes[i].x = gezira_random (0, window.image.width); flakes[i].y = gezira_random (0, window.image.height); flakes[i].dy = gezira_random (0.5, 3.0); flakes[i].scale = gezira_random (0.2, 0.7); flakes[i].angle = gezira_random (0, 4); flakes[i].dangle = gezira_random (-0.1, 0.1); } mem_size = nthreads * NBYTES_PER_THREAD; init = nile_startup (malloc (mem_size), mem_size, nthreads); if (!init) { fprintf (stderr, "nile_startup failed\n"); exit (1); } for (;;) { char c = gezira_Window_key_pressed (&window); while (c != -1) { switch (c) { case ')': nthreads = 10; break; case '!': nthreads = 11; break; case '@': nthreads = 12; break; case '#': nthreads = 13; break; case '$': nthreads = 14; break; case '%': nthreads = 15; break; case '^': nthreads = 16; break; case '&': nthreads = 17; break; case '*': nthreads = 18; break; case '(': nthreads = 19; break; case 'z': is_zooming = !is_zooming; break; default: nthreads = c - '0'; break; } if (!nthreads) break; if (c == 'z') break; printf ("Requesting %d threads\n", nthreads); fflush (stdout); if (nthreads < 0 || nthreads > 50) printf ("Invalid thread count\n"); else { nile_sync (init); free (nile_shutdown (init)); mem_size = nthreads * NBYTES_PER_THREAD; init = nile_startup (malloc (mem_size), mem_size, nthreads); gezira_Image_reset_gate (&window.image); } c = gezira_Window_key_pressed (&window); } if (!nthreads) break; gezira_Window_update_and_clear (&window, init, 1, 0, 0, 0); for (i = 0; i < NFLAKES; i++) { gezira_snowflake_render (&flakes[i], &window, init); gezira_snowflake_update (&flakes[i]); } if (nile_error (init)) { fprintf (stderr, "nile error (OOM)\n"); fflush (stderr); break; } gezira_update_fps (init); if (is_zooming) { zoom += dzoom; if (zoom > 8 || zoom < 1 - dzoom) dzoom = -dzoom; } } nile_sync (init); free (nile_shutdown (init)); //printf ("Just Window_fini left\n"); fflush (stdout); // TODO why does the line below cause a segfault every now and then? //gezira_Window_fini (&window); return 0; }