Game Development Reference
In-Depth Information
string playerInput;
GetPlayerInput(playerInput);
shouldEnd = EvaluateInput(playerInput) == PlayerOptions::Quit;
return !shouldEnd;
}
}
Our functions have not changed since Listing 6-12. The main difference to pay attention to is the
namespace wrapping the function calls. Our GameLoop namespace has been extended to include the
function definitions, if we had not done this, the compiler would complain that it could not find our
functions when building.
PlayerOptions.h is our last new file and is shown in Listing 7-9.
Listing 7-9. PlayerOptions.h
#pragma once
enum class PlayerOptions
{
Quit,
None
};
This file is very simple and contains our enum class .
Hopefully this example will give you a feel for how we use multiple source and header files to
manage our source code. Make sure to download the sample accompanying this chapter from the
following web site http://www.apress.com/9781430264576 .
Summary
This chapter has introduced concepts that C++ provides to help manage large software projects.
Video games definitely qualify as large and complex projects and productive development is only
going to happen through the proper use of header and source files and namespaces.
Header files allow us to create function declarations that can be included for use in multiple source
files. This is necessary to allow the compiler to optimize its processes and to allow programmers to
use functions without concerning themselves with the implementation details.
Having separate source files allows us to simplify the code. Having smaller source files makes
them more readable and also allows us to group functions with functionality that is similar to others
into the same source files. This concept of grouping functions related to similar concepts will be
expanded on in later in this topic when we look at object-oriented programming.
 
Search WWH ::




Custom Search