• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ZwodahS

C++ files organisation

12 posts in this topic

I have been coding C++ for more than a year now and I just realized that the way I package my project is very different from how all the C++ open source projects package their projects.
Most of the C++ projects package in such a way that it looks like this

project
 |_ include
 |_ src

while I usually store them in deep folder structures.
project
|_folder A
 |_ sub folder A
 |_ sub folder B
|_ folder B

When I learn a language, I want to embrace it fully and not just use it like another language. But before I migrate some of my projects, I thought I asked, what are the advantages/disadvantages to doing either way ? I know my way probably came from back when I just started programming and Java has a really deep folder structure. Do anyone do the same as I ?
 

Edited by ZwodahS
0

Share this post


Link to post
Share on other sites

Putting header files into a include folder has the advantage that you have all interfaces to your modules in a single place, like /usr/include and /usr/local/include on UNIX style systems. To make the software available to others, maybe as a library gives you a  more simple way to find the header files to the libraries.

 

But at the end I suspect that it is up to your personal feeling about how to handle header files.

0

Share this post


Link to post
Share on other sites
Nested source layout seems to have two problems:
 
1) Includes may have to still be relative i.e #include "../../player/LeftHand.h" which may get a little bit messy and a pain if you decide to move the project structure.
2) At work when we used Unity we had an issue with locating scripts (quickly). A location that makes sense to one person does not to another. We decided to have all game script files in the same directory, all library scripts in their own directory. So much easier.
 
Note that Visual Studio provides structures in the IDE call "filters". Even though these appear to be nested, they only point to files which are all in the same directory. This may be the best of both worlds.
 
I recommend nesting source only if they are unique to a lib or .exe such as
 
mygame
- bin
  - game.exe
- lib
  - libplatform.a
  - libnetcode.a
  - libimageloader.a
- src
  - platform
    - *.cpp *.h
  - game
    - *.cpp *.h
  - netcode
    - *.cpp *.h
  - imageloader
    - *.cpp *.h
And then -Isrc/platform -Isrc/netcode -Isrc/imageloader so that library headers can be included using < >. Edited by Karsten_
0

Share this post


Link to post
Share on other sites
Personally I'm never putting my headers into a different directory. The only point to do that would be for publishing just the headers for a library I want to publish, but I would rather use CMake or some other build tool to copy the relevant headers from the source directory to a published include directory when needed.
0

Share this post


Link to post
Share on other sites

1) Includes may have to still be relative i.e #include "../../player/LeftHand.h" which may get a little bit messy and a pain if you decide to move the project structure.

 

I would suggest to not include files relative to the location of the source file or whatever, that is just asking for trouble in my opinion. Always include files from a base relative directory (e.g. project root, or more likely the "include" folder) and the problem disappears.

0

Share this post


Link to post
Share on other sites

Using relative includes is a good choice to prevent many -I<include dir> compiler parameters. This way you can go inside a subdir with sources and start the compiler/make in there without thinking about where you are and how your compiler include parameter must look.

 

But... in fact it is awesome to handle if you move a module around.

 

Because I use UML with a code generator that produces the include statements I do not think about the positioning. It is always right and works, even if I move around the modules in the model.

0

Share this post


Link to post
Share on other sites

Wow that is a lot of feedback :P. Thanks a lot.

 

I will think about this more before converting my projects.

 

 


1) Includes may have to still be relative i.e #include "../../player/LeftHand.h" which may get a little bit messy and a pain if you decide to move the project structure.

 

I would suggest to not include files relative to the location of the source file or whatever, that is just asking for trouble in my opinion. Always include files from a base relative directory (e.g. project root, or more likely the "include" folder) and the problem disappears.

 

 

So instead of relative includes, what would be a good way if I don't want a centralized include folder ?

I have this problem recently when I was reorganizing my files and I need to update quite a few of the includes.

0

Share this post


Link to post
Share on other sites

Using relative includes is a good choice to prevent many -I<include dir> compiler parameters. This way you can go inside a subdir with sources and start the compiler/make in there without thinking about where you are and how your compiler include parameter must look.


I would avoid relative includes if at all possible and rather use something like CMake to generate my makesfiles then.
0

Share this post


Link to post
Share on other sites

Avoiding lots of search pathes on the command line has the benefit that it is clear what version of a header file is used and you need not read hundreds of -I parameters with long pathes to find at which point something goes wrong.

 

But as I already said. It is always alot of work if you move a module around.

0

Share this post


Link to post
Share on other sites

So instead of relative includes, what would be a good way if I don't want a centralized include folder ?
I have this problem recently when I was reorganizing my files and I need to update quite a few of the includes.


Unless you are making reusable libraries as part of your project, I would recommend a single folder for both your src and header files. i.e a single .exe means I would create a single src directory. If you find this folder simply has too much source code files in, then this might even suggest that you need to break your project up into multiple separate libraries (in which case they would get their own src directories (containing .cpp and .h).

So since these libraries and binaries are separate projects, you could say that I don't do any nesting in my projects. Some places where you may be tempted however is if some code is completely standalone from the rest of the project (i.e so no #include "../" needed since it has no dependence on other headers). If a part of a project is also in a separate namespace then you may also want to nest, however often parts in a nested namespace still require ../headers and I do typically try to avoid this pattern.

One system that I have found to be very effective is the following (I use cmake but this should work with many build systems). Imagine a folder structure as follows:
 
proj/
  src/
    game/
    foolib/
    barlib/
If I specify on the command like -Isrc, this means that anywhere in the game source code, I can do
 
  #include <foolib/foolib.h>
If foolib has a dependency on barlib, I can do in the foolib code:
 
  #include <barlib/barlib.h>
This means that you can separate your project into logical libraries (and separate .cpp / .h directories) and yet still be able to reference the correct headers you need.

Whats quite useful about this system is that if barlib was really made to be a standalone library, I could have an installer script like:
 
# mkdir /usr/local/include/barlib
# cp -r src/barlib/*.h /usr/local/include/barlib
# cp lib/barlib.a /usr/local/lib/
And now any project on my computer can access the barlib.h in exactly the same way as when it was part of my project. Edited by Karsten_
1

Share this post


Link to post
Share on other sites

Avoiding lots of search pathes on the command line has the benefit that it is clear what version of a header file is used and you need not read hundreds of -I parameters with long pathes to find at which point something goes wrong.


Well, in general I set exactly one include directory for my project (excluding 3rd party libraries). Every file can then simply include what it needs using <mytool/file.h> or <mylibrary/file.h>. CMake just simplifies doing that because every sub-makefile is aware of that include directory without any work on my part. An added benefit is that you immediately see which library/subproject an include is from.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0