#define ALLEGRO_UNSTABLE 1
#include <locale.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_ttf.h>
#include "allegro5/allegro_audio.h"
#include "allegro5/allegro_acodec.h"
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
#define RESERVED_SAMPLES 16
#define MAX_SAMPLE_DATA 10
int main(
int argc,
char* argv[]) {
setlocale(LC_ALL, "POSIX");
char ver_str[128] = "";
while ((
getoptret = getopt(argc, argv,
"hvV:L:")) != EOF) {
case 'h':
n_log(
LOG_NOTICE,
"\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG)\n", argv[0]);
exit(TRUE);
case 'v':
sprintf(ver_str, "%s %s", __DATE__, __TIME__);
exit(TRUE);
break;
case 'V':
if (!strncmp("INFO", optarg, 6)) {
} else {
if (!strncmp("NOTICE", optarg, 6)) {
} else {
if (!strncmp("VERBOSE", optarg, 7)) {
} else {
if (!strncmp("ERROR", optarg, 5)) {
} else {
if (!strncmp("DEBUG", optarg, 5)) {
} else {
exit(FALSE);
}
}
}
}
}
break;
case 'L':
break;
case '?': {
switch (optopt) {
case 'V':
n_log(
LOG_ERR,
"\nPlease specify a log level after -V. \nAvailable values: NOLOG,VERBOSE,NOTICE,ERROR,DEBUG");
break;
case 'L':
default:
break;
}
}
default:
n_log(
LOG_ERR,
"\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG) -L logfile", argv[0]);
exit(FALSE);
}
}
int threadedProcessing = 0;
exit(1);
}
double fluid_factor = fluid_data->
cScale;
if (!al_init()) {
n_abort(
"Could not init Allegro.\n");
}
if (!al_init_acodec_addon()) {
n_abort(
"Could not register addons.\n");
}
if (!al_install_audio()) {
n_log(
LOG_ERR,
"Unable to initialize audio addon, disabling bgmusic\n");
}
if (!al_init_acodec_addon()) {
n_abort(
"Unable to initialize acoded addon\n");
}
if (!al_init_image_addon()) {
n_abort(
"Unable to initialize image addon\n");
}
if (!al_init_primitives_addon()) {
n_abort(
"Unable to initialize primitives addon\n");
}
if (!al_init_font_addon()) {
n_abort(
"Unable to initialize font addon\n");
}
if (!al_init_ttf_addon()) {
n_abort(
"Unable to initialize ttf_font addon\n");
}
if (!al_install_keyboard()) {
n_abort(
"Unable to initialize keyboard handler\n");
}
if (!al_install_mouse()) {
n_abort(
"Unable to initialize mouse handler\n");
}
n_abort(
"Could not set up voice and mixer.\n");
}
memset(sample_data, 0, sizeof(sample_data));
ALLEGRO_EVENT_QUEUE* event_queue = NULL;
event_queue = al_create_event_queue();
if (!event_queue) {
fprintf(stderr, "failed to create event_queue!\n");
return -1;
}
al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_FULLSCREEN_WINDOW);
} else {
al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
}
#ifdef __windows__
al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP | ALLEGRO_NO_PRESERVE_TEXTURE);
#endif
n_abort(
"Unable to create display\n");
}
al_set_window_title(
display, argv[0]);
ALLEGRO_FONT* font = al_load_font("DATAS/2Dumb.ttf", 18, 0);
if (!font) {
n_abort(
"Unable to load font DATAS/2Dumb.ttf\n");
}
al_register_event_source(event_queue, al_get_display_event_source(
display));
al_register_event_source(event_queue, al_get_timer_event_source(
fps_timer));
al_register_event_source(event_queue, al_get_timer_event_source(
logic_timer));
al_register_event_source(event_queue, al_get_keyboard_event_source());
al_register_event_source(event_queue, al_get_mouse_event_source());
bool backbuffer = 1;
ALLEGRO_BITMAP* scrbuf = NULL;
ALLEGRO_BITMAP* bitmap = al_create_bitmap(
WIDTH,
HEIGHT);
enum APP_KEYS {
KEY_UP,
KEY_DOWN,
KEY_LEFT,
KEY_RIGHT,
KEY_ESC,
KEY_SPACE,
KEY_CTRL,
KEY_SHIFT,
KEY_PAD_MINUS,
KEY_PAD_PLUS,
KEY_PAD_ENTER,
KEY_M,
KEY_W,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6
};
int key[19] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
if (!(sample_data[0] = al_load_sample(
bgmusic))) {
exit(1);
}
al_play_sample(sample_data[0], 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, NULL);
}
double inVel = 2.0;
double s = 1.0;
s = 0.0;
if (i == 1) {
}
}
}
for (size_t j = 0; j < minJ; j++)
for (size_t j = minJ; j < maxJ; j++)
bool do_draw = 1, do_logic = 1;
int mx =
WIDTH / 3, my =
HEIGHT / 2, mouse_button = 0, mouse_b1 = 0, mouse_b2 = 0;
al_flush_event_queue(event_queue);
int w = al_get_display_width(
display);
int h = al_get_display_height(
display);
size_t logic_duration = 0;
size_t drawing_duration = 0;
do {
do {
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_UP:
break;
case ALLEGRO_KEY_DOWN:
break;
case ALLEGRO_KEY_LEFT:
break;
case ALLEGRO_KEY_RIGHT:
break;
case ALLEGRO_KEY_ESCAPE:
break;
case ALLEGRO_KEY_SPACE:
break;
case ALLEGRO_KEY_LSHIFT:
case ALLEGRO_KEY_RSHIFT:
break;
case ALLEGRO_KEY_PAD_MINUS:
break;
case ALLEGRO_KEY_PAD_PLUS:
break;
case ALLEGRO_KEY_PAD_ENTER:
break;
case ALLEGRO_KEY_M:
break;
case ALLEGRO_KEY_W:
break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
break;
case ALLEGRO_KEY_F1:
break;
case ALLEGRO_KEY_F2:
break;
case ALLEGRO_KEY_F3:
break;
case ALLEGRO_KEY_F4:
break;
case ALLEGRO_KEY_F5:
break;
case ALLEGRO_KEY_F6:
break;
default:
break;
}
} else if (ev.type == ALLEGRO_EVENT_KEY_UP) {
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_UP:
break;
case ALLEGRO_KEY_DOWN:
break;
case ALLEGRO_KEY_LEFT:
break;
case ALLEGRO_KEY_RIGHT:
break;
case ALLEGRO_KEY_ESCAPE:
break;
case ALLEGRO_KEY_SPACE:
break;
case ALLEGRO_KEY_LSHIFT:
case ALLEGRO_KEY_RSHIFT:
break;
case ALLEGRO_KEY_PAD_MINUS:
break;
case ALLEGRO_KEY_PAD_PLUS:
break;
case ALLEGRO_KEY_PAD_ENTER:
break;
case ALLEGRO_KEY_M:
break;
case ALLEGRO_KEY_W:
break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
break;
case ALLEGRO_KEY_F1:
break;
case ALLEGRO_KEY_F2:
break;
case ALLEGRO_KEY_F3:
break;
case ALLEGRO_KEY_F4:
break;
case ALLEGRO_KEY_F5:
break;
case ALLEGRO_KEY_F6:
break;
default:
break;
}
} else if (ev.type == ALLEGRO_EVENT_TIMER) {
if (al_get_timer_event_source(
fps_timer) == ev.any.source) {
do_draw = 1;
}
else if (al_get_timer_event_source(
logic_timer) == ev.any.source) {
do_logic = 1;
}
} else if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) {
mx = ev.mouse.x;
my = ev.mouse.y;
} else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
if (ev.mouse.button == 1)
mouse_b1 = 1;
if (ev.mouse.button == 2)
mouse_b2 = 1;
} else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
if (ev.mouse.button == 1)
mouse_b1 = 0;
if (ev.mouse.button == 2)
mouse_b2 = 0;
}
mouse_button = -1;
if (mouse_b1 == 1)
mouse_button = 1;
if (mouse_b2 == 1)
mouse_button = 2;
else if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN || ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) {
al_flush_event_queue(event_queue);
} else {
}
}
}
}
}
}
}
}
}
}
}
if (
key[KEY_PAD_MINUS]) {
}
if (mouse_button != -1) {
}
}
} while (!al_is_event_queue_empty(event_queue));
if (do_logic == 1) {
static int old_mx = -1, old_my = -1;
double vx = 0.0, vy = 0.0;
if (old_mx != mx || old_my != my) {
if (old_mx != -1 && old_my != -1) {
}
old_mx = mx;
old_my = my;
}
for (size_t j = 0; j < minJ; j++)
for (size_t j = minJ; j < maxJ; j++)
for (size_t j = minJ; j < maxJ; j++)
if (threadedProcessing == 1)
else
do_logic = 0;
}
if (do_draw == 1) {
if (backbuffer)
scrbuf = al_get_backbuffer(
display);
else
scrbuf = bitmap;
al_set_target_bitmap(scrbuf);
if (!backbuffer)
al_lock_bitmap(scrbuf, al_get_bitmap_format(scrbuf), ALLEGRO_LOCK_READWRITE);
al_draw_circle(mx, my - 20 * fluid_factor, fluid_factor * fluid_factor / 2, al_map_rgb(255, 0, 0), 2.0);
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);
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);
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);
al_draw_circle(mx, my + 20 * fluid_factor, fluid_factor * fluid_factor / 2, al_map_rgb(255, 0, 0), 2.0);
static N_STR* textout = NULL;
al_draw_text(font, al_map_rgb(0, 0, 255),
WIDTH, 10, ALLEGRO_ALIGN_RIGHT,
_nstr(textout));
al_draw_text(font, al_map_rgb(0, 0, 255),
WIDTH, 25, ALLEGRO_ALIGN_RIGHT,
_nstr(textout));
nstrprintf(textout,
"logic(max %zd): %zd usecs", (
size_t)(1000000.0 /
logicFPS), logic_duration);
al_draw_text(font, al_map_rgb(0, 0, 255), 5, 10, ALLEGRO_ALIGN_LEFT,
_nstr(textout));
nstrprintf(textout,
"drawing(max %zd): %zd usecs", (
size_t)(1000000.0 /
drawFPS), drawing_duration);
al_draw_text(font, al_map_rgb(0, 0, 255), 5, 30, ALLEGRO_ALIGN_LEFT,
_nstr(textout));
if (!backbuffer) {
al_unlock_bitmap(scrbuf);
al_set_target_bitmap(al_get_backbuffer(
display));
al_draw_bitmap(scrbuf, w / 2 - al_get_bitmap_width(scrbuf) / 2, h / 2 - al_get_bitmap_height(scrbuf) / 2, 0);
}
al_flip_display();
do_draw = 0;
}
al_uninstall_system();
return 0;
}
ALLEGRO_TIMER * fps_timer
THREAD_POOL * thread_pool
#define MAX_SAMPLE_DATA
audio MAX_SAMPLE_DATA for bgmusic
#define RESERVED_SAMPLES
audio RESERVED_SAMPLES for bgmusic
ALLEGRO_TIMER * logic_timer
ALLEGRO_DISPLAY * display
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 Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define _str(__PTR)
define true
void n_abort(char const *format,...)
abort program with a text
#define Free(__ptr)
Free Handler to get errors.
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
int set_log_file(char *file)
Set the logging to a file instead of stderr.
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_INFO
informational
size_t numY
number of cells in Y
double fluid_production_percentage
size of the produced fluid
bool showSmoke
display fluid as a colored cloud instead of black and white, can be combined with showPressure
size_t numX
number of cells in X
double overRelaxation
over relaxation
bool showPressure
display fluids pressures as color variations, can be combined with showSmoke
bool showPaint
activate a fonky palette, override smoke and pressure display
double * u
holder for u arrays
double dt
time between frames
double * s
holder for s arrays
size_t numIters
number of fluid processing iterations for each frame
double density
density of the fluid (not working ?)
double * m
holder for m arrays
double cScale
scale used to deduce cellX and cellY from screen/window width and height
double gravity
gravity on Y
int n_fluid_draw(N_FLUID *fluid)
draw a N_FLUID on screen / targert bitmap
int n_fluid_simulate_threaded(N_FLUID *fluid, THREAD_POOL *thread_pool)
a threaded version of N_FLUID global processing function
int n_fluid_simulate(N_FLUID *fluid)
non threaded version of N_FLUID global processing function
int n_fluid_resetObstacles(N_FLUID *fluid)
reset the obstacles set in a N_FLUID
int n_fluid_setObstacle(N_FLUID *fluid, double x, double y, double vx, double vy, double r)
set an obstacle in the fluid grid
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
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
#define nstrprintf(__nstr_var, __format,...)
Macro to quickly allocate and sprintf to N_STR.
A box including a string and his lenght.
int start_HiTimer(N_TIME *timer)
Initialize or restart from zero any N_TIME HiTimer.
time_t get_usec(N_TIME *timer)
Poll any N_TIME HiTimer, returning usec, and moving currentTime to startTime.
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
N_STR and string function declaration.