Jump to content
  • Advertisement
Sign in to follow this  
jakobnator

multiple .cpp files?

This topic is 2706 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

So I am just getting started in Game development, and I have been watching some dev marathons, and I noticed they have multiple .cpp files? I already know about header files and they are all incorparated into main.cpp but what is the point of multiple .cpp files? Can you add them all to the main.cpp file whats the difference between the .cpp and .h? Please explain in detail.

EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,

SDL_LoadBMP("BlackJack/Art/Table.png");

is not working!

Share this post


Link to post
Share on other sites
Advertisement

So I am just getting started in Game development, and I have been watching some dev marathons, and I noticed they have multiple .cpp files?

Yes. Generally, you'll have one or more related classes defined in a header file. When you implement the member functions and constructors of these classes, it is common to do so in a source (.cpp) file.

I already know about header files and they are all incorparated into main.cpp[/quote]
This is not necessary in the least.

but what is the point of multiple .cpp files? Can you add them all to the main.cpp file whats the difference between the .cpp and .h? Please explain in detail.
[/quote]
.cpp is a "source file" and is compiled and linked automatically by an IDE.
The point in having multiple is that it's easier to manage your code if it's split up in an orderly fashion.

Share this post


Link to post
Share on other sites
I personally like to keep some parts of the program separated from the main program so provide easier readability. I don't know what the professional coders do it for, or what it's called, though.

Share this post


Link to post
Share on other sites

So I am just getting started in Game development, and I have been watching some dev marathons, and I noticed they have multiple .cpp files? I already know about header files and they are all incorparated into main.cpp but what is the point of multiple .cpp files? Can you add them all to the main.cpp file whats the difference between the .cpp and .h? Please explain in detail.

Mandatory reading.

You split up code into multiple cpp files to organize it. A common suggestion is to place one class per cpp file, or at the very least, give one purpose to each cpp file. Once you code is inside seperate compilation units, you have to provide enough forward declarations/prototypes to make each cpp file compile. That is where the headers come in. You put the declaration of each of your public interfaces into headers, and then include those headers in any cpp file that needs to be able to call those functions. There are some exceptions, like templates, that must be contained in full in your headers so that their full definition is available at point of use.

Share this post


Link to post
Share on other sites

EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,

SDL_LoadBMP("BlackJack/Art/Table.png");

is not working!


SDL_LoadBMP is for bitmap (.bmp) files. use SDL_Image and IMG_Load for a generic image loading function.

Share this post


Link to post
Share on other sites

[quote name='jakobnator' timestamp='1304133567' post='4804635']
EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,

SDL_LoadBMP("BlackJack/Art/Table.bmp");

is not working!


SDL_LoadBMP is for bitmap (.bmp) files. use SDL_Image and IMG_Load for a generic image loading function.
[/quote]

Thats what I meant I had a predefined loading function so I just changed it to that for that, it was able to load .png files anyway, the problem is the file path what do I use if my art is in a folder inside of where the executable is because

("BlackJack/Art/Table.bmp");

is not loading that file path.


Share this post


Link to post
Share on other sites

[quote name='nfries88' timestamp='1304135893' post='4804645']
[quote name='jakobnator' timestamp='1304133567' post='4804635']
EDIT: Also came across another problem, in SDL for my game I am trying to organize my art into files so how do I load something in a file path because,

SDL_LoadBMP("BlackJack/Art/Table.bmp");

is not working!


SDL_LoadBMP is for bitmap (.bmp) files. use SDL_Image and IMG_Load for a generic image loading function.
[/quote]

Thats what I meant I had a predefined loading function so I just changed it to that for that, it was able to load .png files anyway, the problem is the file path what do I use if my art is in a folder inside of where the executable is because

("BlackJack/Art/Table.bmp");

is not loading that file path.



[/quote]

all directories sent to files will be relative to your PATH environment variable (negligible for this) and your current execution directory, which is by default the same folder as your .exe.

So if your folder is in C:/My Code/BlackJack/, and Table.bmp is in C:/My Code/BlackJack/Art/; then what you need to send to your function is merely "Art/Table.bmp".

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!