allegro_wrapper.h :
| 1 | volatile int ticks = 0; // timer |
| 2 | |
| 3 | /* current sprite frame number */ |
| 4 | int frame, frame_number = 0; |
| 5 | |
| 6 | /* pointer to a sprite buffer, two screen buffers, tile, map, chat window */ |
| 7 | |
| 8 | BITMAP *sprite_buffer; |
| 9 | BITMAP *page[2]; |
| 10 | BITMAP *tile[2], *map; |
| 11 | BITMAP *trees; |
| 12 | BITMAP *chat_window; |
| 13 | |
| 14 | /* a boolean - if true, skip to next part */ |
| 15 | int next; |
| 16 | |
| 17 | void ticker(void); |
| 18 | |
| 19 | int init_bitmaps(); |
| 20 | void destroy_bitmaps(); |
allegro_wrapper.cpp
| 1 | void ticker(void) |
| 2 | { |
| 3 | ticks = ticks + 100 ; |
| 4 | } |
| 5 | END_OF_FUNCTION(ticker) |
| 6 | |
| 7 | // initializes the various bitmaps we will be using. |
| 8 | |
| 9 | int init_bitmaps (void) |
| 10 | |
| 11 | { |
| 12 | char datafile_name[256]; |
| 13 | PALETTE pal; |
| 14 | |
| 15 | if (allegro_init() != 0) |
| 16 | return 1; |
| 17 | install_keyboard(); |
| 18 | install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL); |
| 19 | install_timer(); |
| 20 | install_keyboard(); |
| 21 | LOCK_FUNCTION(ticker); |
| 22 | LOCK_VARIABLE(ticks); |
| 23 | install_int_ex(ticker, BPS_TO_TIMER(30)); |
| 24 | |
| 25 | set_color_depth(16); |
| 26 | if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) { |
| 27 | if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { |
| 28 | set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); |
| 29 | allegro_message("Unable to set any graphic mode\n%s\n", |
| 30 | allegro_error); |
| 31 | return 2; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /* create two video memory bitmaps for page flipping */ |
| 36 | page[0] = create_video_bitmap(SCREEN_W, SCREEN_H); |
| 37 | page[1] = create_video_bitmap(SCREEN_W, SCREEN_H); |
| 38 | |
| 39 | // create a bitmap for sprite buffering |
| 40 | |
| 41 | sprite_buffer = create_bitmap((int)(82 * sqrt(2) + 2), |
| 42 | (int)(82 * sqrt(2) + 2)); |
| 43 | |
| 44 | // create a bitmap for the map and the tile |
| 45 | |
| 46 | map = create_bitmap(1280,640); |
| 47 | |
| 48 | // create a bitmap for the chat window; |
| 49 | |
| 50 | chat_window = create_bitmap(680, 272); |
| 51 | |
| 52 | |
| 53 | if ((!page[0])||(!page[1])||(!sprite_buffer) ||(!map)||(!chat_window))return 3; |
| 54 | |
| 55 | // clear what needs clearing |
| 56 | |
| 57 | clear_bitmap(chat_window); |
| 58 | |
| 59 | return 0; |
| 60 | |
| 61 | } |
| 62 | |
| 63 | // destroys the various bitmaps we have been using. |
| 64 | |
| 65 | void destroy_bitmaps (void) |
| 66 | |
| 67 | { |
| 68 | destroy_bitmap(sprite_buffer); |
| 69 | |
| 70 | destroy_bitmap(page[0]); |
| 71 | destroy_bitmap(page[1]); |
| 72 | |
| 73 | destroy_bitmap(tile[0]); destroy_bitmap(tile[1]); |
| 74 | destroy_bitmap(map); |
| 75 | |
| 76 | destroy_bitmap(chat_window); |
| 77 | |
| 78 | } |
when #included from main file, compiler dies a flaming death of
...\game\source\allegro_wrapper.o(.bss+0x8) In function `Z6tickerv':
...\game\source\allegro_wrapper.cpp multiple definition of `frame_number'
and so again and again for every single variable defined. what the hell, i've been trying to figure it out for the past three hours. any ideas ?
You want extern before your variables in the header, then declare them as normal in the top of ONE file (usually the one you use it in most). If that var is only used in one file, it should be local to that file, and not global with the header file.
Before each variable declared in the header files, add the keyword "extern". Then duplicate their declaration in one and only one non-header file, but without the "extern".
Also, remove the value assignment ("= 0") from the ones in the header file, leave that only on the ones in non-header files.
Otherwise, every file that #includes a header creates a duplicate of each variable, and the multiple copies conflict with each other.
edit: beaten!
o god almighty.
(why was i thinking that'd be handled automatically by the compiler ?)
I'm not sure why it was telling you it was in the ticker function, but I suppose that may be something cookey with the C++ mangling or something.
wrap your header in these statememts to keep it from defining multiple variables.
#ifndef _HEADER_FILE_NAME_H_ #define _HEADER_FILE_NAME_H_ //put your header here #endif
you shouldn't initialize the variables in the header either.
I'm not sure why it was telling you it was in the ticker function, but I suppose that may be something cookey with the C++ mangling or something.
i don't think anything's the matter with the mangling. ticker just happens to be the first function right after the #include, it has to point to something (the compiler, i mean).
Why would it report it in a function that it's not in? I'd think it would just say global, or nothing at all.
i'm pretty sure the error could be replicated without using the allegro libraries tho. if i hit a wall and need a break writing for the game i'll try it out.