61int main(
int argc,
char* argv[]) {
63 setlocale(LC_ALL,
"POSIX");
72 char ver_str[128] =
"";
74 while ((
getoptret = getopt(argc, argv,
"hvV:L:")) != EOF) {
77 n_log(
LOG_NOTICE,
"\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG)\n", argv[0]);
80 sprintf(ver_str,
"%s %s", __DATE__, __TIME__);
84 if (!strncmp(
"INFO", optarg, 6)) {
87 if (!strncmp(
"NOTICE", optarg, 6)) {
90 if (!strncmp(
"VERBOSE", optarg, 7)) {
93 if (!strncmp(
"ERROR", optarg, 5)) {
96 if (!strncmp(
"DEBUG", optarg, 5)) {
116 n_log(
LOG_ERR,
"\nPlease specify a log level after -V. \nAvailable values: NOLOG,VERBOSE,NOTICE,ERROR,DEBUG");
126 n_log(
LOG_ERR,
"\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG) -L logfile", argv[0]);
133 int threadedProcessing = 0;
140 double fluid_factor = fluid_data->
cScale;
145 n_abort(
"Could not init Allegro.\n");
147 if (!al_init_acodec_addon()) {
148 n_abort(
"Could not register addons.\n");
150 if (!al_install_audio()) {
151 n_log(
LOG_ERR,
"Unable to initialize audio addon, disabling bgmusic\n");
154 if (!al_init_acodec_addon()) {
155 n_abort(
"Unable to initialize acoded addon\n");
157 if (!al_init_image_addon()) {
158 n_abort(
"Unable to initialize image addon\n");
160 if (!al_init_primitives_addon()) {
161 n_abort(
"Unable to initialize primitives addon\n");
163 if (!al_init_font_addon()) {
164 n_abort(
"Unable to initialize font addon\n");
166 if (!al_init_ttf_addon()) {
167 n_abort(
"Unable to initialize ttf_font addon\n");
169 if (!al_install_keyboard()) {
170 n_abort(
"Unable to initialize keyboard handler\n");
172 if (!al_install_mouse()) {
173 n_abort(
"Unable to initialize mouse handler\n");
177 n_abort(
"Could not set up voice and mixer.\n");
181 memset(sample_data, 0,
sizeof(sample_data));
183 ALLEGRO_EVENT_QUEUE* event_queue = NULL;
185 event_queue = al_create_event_queue();
187 fprintf(stderr,
"failed to create event_queue!\n");
192 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_FULLSCREEN_WINDOW);
194 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
198 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP | ALLEGRO_NO_PRESERVE_TEXTURE);
203 n_abort(
"Unable to create display\n");
206 al_set_window_title(
display, argv[0]);
208 ALLEGRO_FONT* font = al_load_font(
"DATAS/2Dumb.ttf", 18, 0);
210 n_abort(
"Unable to load font DATAS/2Dumb.ttf\n");
217 al_register_event_source(event_queue, al_get_display_event_source(
display));
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));
223 al_register_event_source(event_queue, al_get_keyboard_event_source());
224 al_register_event_source(event_queue, al_get_mouse_event_source());
227 ALLEGRO_BITMAP* scrbuf = NULL;
228 ALLEGRO_BITMAP* bitmap = al_create_bitmap(
WIDTH,
HEIGHT);
253 int key[19] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
256 if (!(sample_data[0] = al_load_sample(
bgmusic))) {
260 al_play_sample(sample_data[0], 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, NULL);
296 for (
size_t j = 0; j < minJ; j++)
298 for (
size_t j = minJ; j < maxJ; j++)
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;
308 al_flush_event_queue(event_queue);
311 int w = al_get_display_width(
display);
312 int h = al_get_display_height(
display);
316 size_t logic_duration = 0;
317 size_t drawing_duration = 0;
322 al_wait_for_event(event_queue, &ev);
324 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
325 switch (ev.keyboard.keycode) {
329 case ALLEGRO_KEY_DOWN:
332 case ALLEGRO_KEY_LEFT:
335 case ALLEGRO_KEY_RIGHT:
338 case ALLEGRO_KEY_ESCAPE:
341 case ALLEGRO_KEY_SPACE:
344 case ALLEGRO_KEY_LSHIFT:
345 case ALLEGRO_KEY_RSHIFT:
348 case ALLEGRO_KEY_PAD_MINUS:
349 key[KEY_PAD_MINUS] = 1;
351 case ALLEGRO_KEY_PAD_PLUS:
352 key[KEY_PAD_PLUS] = 1;
354 case ALLEGRO_KEY_PAD_ENTER:
355 key[KEY_PAD_ENTER] = 1;
363 case ALLEGRO_KEY_LCTRL:
364 case ALLEGRO_KEY_RCTRL:
388 }
else if (ev.type == ALLEGRO_EVENT_KEY_UP) {
389 switch (ev.keyboard.keycode) {
393 case ALLEGRO_KEY_DOWN:
396 case ALLEGRO_KEY_LEFT:
399 case ALLEGRO_KEY_RIGHT:
402 case ALLEGRO_KEY_ESCAPE:
405 case ALLEGRO_KEY_SPACE:
408 case ALLEGRO_KEY_LSHIFT:
409 case ALLEGRO_KEY_RSHIFT:
412 case ALLEGRO_KEY_PAD_MINUS:
413 key[KEY_PAD_MINUS] = 0;
415 case ALLEGRO_KEY_PAD_PLUS:
416 key[KEY_PAD_PLUS] = 0;
418 case ALLEGRO_KEY_PAD_ENTER:
419 key[KEY_PAD_ENTER] = 0;
427 case ALLEGRO_KEY_LCTRL:
428 case ALLEGRO_KEY_RCTRL:
453 }
else if (ev.type == ALLEGRO_EVENT_TIMER) {
454 if (al_get_timer_event_source(
fps_timer) == ev.any.source) {
456 }
else if (al_get_timer_event_source(
logic_timer) == ev.any.source) {
459 }
else if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) {
462 }
else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
463 if (ev.mouse.button == 1)
465 if (ev.mouse.button == 2)
467 }
else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
468 if (ev.mouse.button == 1)
470 if (ev.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);
514 if (
key[KEY_RIGHT]) {
518 if (
key[KEY_PAD_PLUS]) {
522 if (
key[KEY_PAD_MINUS]) {
526 if (mouse_button != -1) {
530 }
while (!al_is_event_queue_empty(event_queue));
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) {
554 for (
size_t j = 0; j < minJ; j++)
556 for (
size_t j = minJ; j < maxJ; j++)
560 for (
size_t j = minJ; j < maxJ; j++)
563 if (threadedProcessing == 1)
575 scrbuf = al_get_backbuffer(
display);
579 al_set_target_bitmap(scrbuf);
582 al_lock_bitmap(scrbuf, al_get_bitmap_format(scrbuf), ALLEGRO_LOCK_READWRITE);
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);
592 static N_STR* textout = NULL;
594 al_draw_text(font, al_map_rgb(0, 0, 255),
WIDTH, 10, ALLEGRO_ALIGN_RIGHT,
_nstr(textout));
597 al_draw_text(font, al_map_rgb(0, 0, 255),
WIDTH, 25, ALLEGRO_ALIGN_RIGHT,
_nstr(textout));
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));
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));
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);
618 }
while (!
key[KEY_ESC] && !
DONE);
620 al_uninstall_system();