|
Initialization source file |
AceBlkwell
Member #13,038
July 2011
|
All, I'm creating a framework for my first A5 program. If I put all my allegro setup / inits in a separate source file, are the pointers global or will they need to be passed in order to be used. Some items are just activated and working. However, some are pointers. In order to use timer or queue outside of the init source file, will I need to pass the pointer to all functions needing it. ALLEGRO_TIMER* timer = al_create_timer(1.0 / 30.0); Meaning, if I create queue in alleg_init.cpp will I have to pass it to main.cpp or will it just be available. I'm a ways off from having anything compilable so I can't test my question out on my own yet. Was trying to get a head of the curve. Thanks |
DanielH
Member #934
January 2001
|
You can DECLARE your pointers for other files to see using extern. // myheader.h // declare in your header file extern ALLEGRO_BITMAP* bitmap;
// source1.h // define only once #include "myheader.h" ALLEGRO_BITMAP* bitmap;
// source2.h #include "myheader.h"
|
AceBlkwell
Member #13,038
July 2011
|
Thanks Daniel. I thought about a header file last night. I had forgotten about extern. I haven't used it a lot in the past. Either way would be easier than trying to pass a pointer back and forth. I watch part of your framework video. Not bad. I'm not a VC guy but the concept is still the same. As I work through my framework, I may check it out again to see how you handled certain difficulties. Thanks again. |
DanielH
Member #934
January 2001
|
You don't actually need a header file. You can always just put the extern declaration in your other source files. As long as you only define it once. // source1.cpp ALLEGRO_BITMAP* bitmap = nullptr;
//source2.cpp extern ALLEGRO_BITMAP* bitmap;
|
AceBlkwell
Member #13,038
July 2011
|
Thanks Daniel. I have decided to start a lot smaller. Based on tutorials and other code, I was trying to create a framework for all setups and initiations needed for an entire game. At this point I don’t have enough experience with A5 to develop an initiation “black box”. I’m going take my previous approach, which works for me. I’m going to start writing code to learn a specific aspect of the library and expand from there. Once I have that, I’ll then start working on grouping like actions together. |
|