• Advertisement
Sign in to follow this  

Handling C++ Projects

This topic is 3623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Coming from a language (BlitzMax) in which all source is compiled as though it were one big file, I'm having trouble understanding how to handle a multiple-file C++ project. Are there any tutorials concerning this? I'm using HGE in my current project, but any resource that shows good examples would be appreciated. Small, simple games with source code would be very useful too. Here are a few things I don't understand: In my Main.cpp file, I create an instance of the HGE engine, which is then used, among other things, to draw to the screen. In a separate file, Entity.cpp, I want to have a render function in my cEntity class. This said, how do I code the render function, when Entity.cpp cannot see the instance of HGE that I created before? In a similar situation, I load the textures in the Main function. To allow my other classes to view and use this texture, do I make it global? Should I load the textures somewhere else? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
One way to know about the HGE object in that file would be to include something like:


extern HGE* myHge;


Near the top of the Entity.cpp file (you will also have to include the HGE headers). Another option would be to pass the HGE object into the render function by a call in Main.cpp.

As for textures, you could do the same things, either pass them in or use the extern keyword on the globals in the other file. I'm not sure about what is the neatest/proper way to do this since I'm also a beginner, so far I've been using globals for textures. I'd imaging in a larger project some sort of texture manager or something would be needed since manually declaring all of the textures would get huge.

Share this post


Link to post
Share on other sites
Quote:
Original post by Torrente
Are there any tutorials concerning this?

Here's one

Quote:
In my Main.cpp file, I create an instance of the HGE engine, which is then used, among other things, to draw to the screen. In a separate file, Entity.cpp, I want to have a render function in my cEntity class. This said, how do I code the render function, when Entity.cpp cannot see the instance of HGE that I created before?

In a similar situation, I load the textures in the Main function. To allow my other classes to view and use this texture, do I make it global? Should I load the textures somewhere else?

One of the parameters of your class method/contructor could be a reference to your texture/texture pool/texture manager etc.

Share this post


Link to post
Share on other sites
That article is perfect!

Thank you very much.

I'll take a look at creating a texture manager of some sort to fix my other problems. The only problem with this, as I see it, is that I'd have to pass the texture/texture manager into the constructor, even though each instance of the class will be using the same texture. Surely there's a way around that?

Again, thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement