// HEADER FILE
// FILENAME :: MENU.H
// VERSION :: 0.0.0.1
// CODERS INVOLVED :: John Sedlak
// DATE CREATED :: Saturday, December 14, 2002
// DATE MODIFIED :: Saturday, December 14, 2002
// DESCRIPTION :: Menu class for the Unknown Engine, adds support for out-of-game
// menus and sub-menus.
#ifndef MENU_H
#include "3ds.h"
#include "texture.h"
#include <string>
using namespace std
class menu
{
public:
// Data Members
// General
string ID; // A univeral ID that identifies the menu
bool active; // Is the menu active and should it be drawn?
// Textures
texture background; // The texture for the background picture
texture foreground; // The texture for the foreground picture
// Choice Variables
string Choices[20]; // An array of strings that represents all the choices possible
int n_choices; // The total amount of choices
int c_choice; // An integer representing the current choice, it is a reference to the choice array
// 3DS Models
3ds mdl_l; // The model for the left side of the menu
3ds mdl_r; // The model for the right side of the screen
// Alpha Variables
float c_alpha; // The current alpha value of the text.
float alpha_speed; // The speed at which to de/in-crement c_alpha
float alpha_rgb[3]; // An array of floats that represents color of the alpha (red, green, blue)
// Accessors
// Operators
// Functions
// Initiation
void Init(string identification, string bg, string fg, string ml, string mr, bool activate);
void ShutDown();
// General
void SetColor(float red, float green, float blue);
private:
};
#define MENU_H
#include "menu.cpp"
#endif
Problems with multiple .h files...
Hello, I have started my game/engine and tonight I coded the first version of menu.h and I was wondering, if I am planning to include this in the main engine, how do I get all the declare it needs...like... (look at the code...)
you can see I include 3ds.h and texture.h as well as , which will also all be included in engine.h, just like menu.h will be...
So what I am asking is is there a way to see if that code is compiled or not or is it safe to keep it like this or how should I set it up!? Thanks, much much thanks!
(HAPPY HOLIDAYS btw!)
<- Digital Explosions ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)
also...how should the code from menu.h be run... like, durr how do i say this...
like, should i include menu.cpp in menu.h, or should i just include menu.h in menu.cpp, or should i do both...
<- Digital Explosions ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)
like, should i include menu.cpp in menu.h, or should i just include menu.h in menu.cpp, or should i do both...
<- Digital Explosions ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)
You should not include .cpp files. If you need something in one, you include it's header. In your case, you would put: include "menu.h" in the menu.cpp file, and any other files which need to use the menu class.
Headers including other headers is normal. However, you can't have two headers which both rely on each other (that I know of, at least). So you can't put make a class in 3ds.h which has a "menu myMenu" or whatever.
Oh, and you're missing a semicolon after using namespace std
------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It's all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."
[edited by - LockePick on December 15, 2002 2:29:00 AM]
Headers including other headers is normal. However, you can't have two headers which both rely on each other (that I know of, at least). So you can't put make a class in 3ds.h which has a "menu myMenu" or whatever.
Oh, and you're missing a semicolon after using namespace std
------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It's all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."
[edited by - LockePick on December 15, 2002 2:29:00 AM]
_______________________________________Pixelante Game Studios - Fowl Language
dude, you rule, thx...
and using namespace std needs a semicolon!? dang, thx
oh and btw, how is it so far?
<- Digital Explosions ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)
and using namespace std needs a semicolon!? dang, thx
oh and btw, how is it so far?
<- Digital Explosions ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)
ok. the ins and outs of headers. volume 1 
just roughly,
the idea of a header is to define what everything in your class is named, and the structure of the class (eg, byte layout, etc), access rights, etc... The idea of the source file (.cpp) is to define the code for all the classes/functions that have been defined in the header file.
(this is the general case btw)
Code is only generated from the source files, not the headers.
This may be a tad confusing, as you can put the code inside a header... this is because when you do this, that function becomes inline, which means it will be compiled into the code wherever it is called... Whereas a function in a source file only occurs once in the final generated code, and is linked to with function calls.
Don't automatically think that inline functions are therefor always faster. They do have their problems.
One of the better things you can do with headers/source files that is harder to do with inline is where classes both rely on each other... There may, for example, be a string class and a, say, game object class. The string class may be able to print out a game object, and the game object may store a string... But here is a problem.. You can't do this inline because they both require to have complete access to the other object... Ie, the string needs to know how a game object works, as does a game object need to know how a string works. So you need to declar each, then let the source files do all the accessing between the types... it's hard to explain but I'm sure your've come accross it... it can be boggling when anyone is new to programming...
if you want one to store an instance of the other, well, this is impossible directly, and would crash anyway. You can store pointers to each other, by simply predefining all your class names before you actually define their insides... eg, this code works fine:
class CMyOtherClass;
class CMyClass
{
CMyOtherClass * pointer;
};
class CMyOtherClass
{
CMyClass * backagain;
};
the class is defined before it's contents are. so a pointer can be used, but not an actual object.
ie, you can't do this:
class C1
{
C2 ops;
};
class C2
{
C1 dang;
};
that would be an infinite loop anyway. (although I think it's possible in java due to weird things it does
)
That said, how does it apply?
now, there is a nice little tool you can use to make everything MUCH simpler... and thats all to do with code linking...
if you have made a large, multi file program before, you might have come accross situations where every time it gets to a new .ccp file, it seems to recompile every single included header in that .cpp file over again...
linking to those classes...
This has the effect of making compile times absolutly massive... I've had 20k line projects spread over 20 files compile in 5 minutes... which is utterly rediculous...
yet my current project is 3-4x that size (if not more), contains some ~120 source files, and yet compiles in probably 15 seconds.... The reason is because I take advantage of a tool called precompiled headers...
what this is, is a standard header, and a standard source file, that are designated to the compiler to be a precompiled header combination. In the .h file, you add every header file and setting you want to be global - ie, all of them, almost - then.. the .cpp file will be compiled first...
This will take as long as a normal files used to, BUT, once thats done, then whenever the precompiled header is included in ANY other source file, as is all the info in the precompiled header.. with no extra compile time... This means the compiler will rip through the remaining source files very, very quickly..
and has the huge benifit that any source file will have everything else in the application defined... so there is none of the situation where you need to add an include if you want to use something new in a source file... You add it once to the pch, and bang, the entire project knows it... Hence you will only ever usually have 2 includes in every source file (one to it's associated header, and one to the pch, although it can only be the pch).. and these are both added automatically by VC.
it also has the other benifit that you shoud never need to inlcude anything in a header, and the single automatic include statment in all your source files is all you will ever likly need.
(you have
#include "3ds.h"#include "texture.h"#include <string>using namespace std in your header.. this would be only needed once in the precompiled header, and would take effect over your entire application).
if you create a appwizard program in VC, it will amost always have the standard precompiled header stdafx.h... Use it, and use it well.
[edited by - RipTorn on December 15, 2002 4:59:23 AM]

just roughly,
the idea of a header is to define what everything in your class is named, and the structure of the class (eg, byte layout, etc), access rights, etc... The idea of the source file (.cpp) is to define the code for all the classes/functions that have been defined in the header file.
(this is the general case btw)
Code is only generated from the source files, not the headers.
This may be a tad confusing, as you can put the code inside a header... this is because when you do this, that function becomes inline, which means it will be compiled into the code wherever it is called... Whereas a function in a source file only occurs once in the final generated code, and is linked to with function calls.
Don't automatically think that inline functions are therefor always faster. They do have their problems.
One of the better things you can do with headers/source files that is harder to do with inline is where classes both rely on each other... There may, for example, be a string class and a, say, game object class. The string class may be able to print out a game object, and the game object may store a string... But here is a problem.. You can't do this inline because they both require to have complete access to the other object... Ie, the string needs to know how a game object works, as does a game object need to know how a string works. So you need to declar each, then let the source files do all the accessing between the types... it's hard to explain but I'm sure your've come accross it... it can be boggling when anyone is new to programming...
if you want one to store an instance of the other, well, this is impossible directly, and would crash anyway. You can store pointers to each other, by simply predefining all your class names before you actually define their insides... eg, this code works fine:
class CMyOtherClass;
class CMyClass
{
CMyOtherClass * pointer;
};
class CMyOtherClass
{
CMyClass * backagain;
};
the class is defined before it's contents are. so a pointer can be used, but not an actual object.
ie, you can't do this:
class C1
{
C2 ops;
};
class C2
{
C1 dang;
};
that would be an infinite loop anyway. (although I think it's possible in java due to weird things it does

That said, how does it apply?
now, there is a nice little tool you can use to make everything MUCH simpler... and thats all to do with code linking...
if you have made a large, multi file program before, you might have come accross situations where every time it gets to a new .ccp file, it seems to recompile every single included header in that .cpp file over again...
linking to those classes...
This has the effect of making compile times absolutly massive... I've had 20k line projects spread over 20 files compile in 5 minutes... which is utterly rediculous...
yet my current project is 3-4x that size (if not more), contains some ~120 source files, and yet compiles in probably 15 seconds.... The reason is because I take advantage of a tool called precompiled headers...
what this is, is a standard header, and a standard source file, that are designated to the compiler to be a precompiled header combination. In the .h file, you add every header file and setting you want to be global - ie, all of them, almost - then.. the .cpp file will be compiled first...
This will take as long as a normal files used to, BUT, once thats done, then whenever the precompiled header is included in ANY other source file, as is all the info in the precompiled header.. with no extra compile time... This means the compiler will rip through the remaining source files very, very quickly..
and has the huge benifit that any source file will have everything else in the application defined... so there is none of the situation where you need to add an include if you want to use something new in a source file... You add it once to the pch, and bang, the entire project knows it... Hence you will only ever usually have 2 includes in every source file (one to it's associated header, and one to the pch, although it can only be the pch).. and these are both added automatically by VC.
it also has the other benifit that you shoud never need to inlcude anything in a header, and the single automatic include statment in all your source files is all you will ever likly need.
(you have
#include "3ds.h"#include "texture.h"#include <string>using namespace std in your header.. this would be only needed once in the precompiled header, and would take effect over your entire application).
if you create a appwizard program in VC, it will amost always have the standard precompiled header stdafx.h... Use it, and use it well.
[edited by - RipTorn on December 15, 2002 4:59:23 AM]
how will the compiler know that stdafx.h is the header file to compile as the pch...?
<- Digital Explosions ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)
<- Digital Explosions ->
"Discipline is my sword, faith is my shield
do not dive into uncertainty, and you may live to reap the rewards" - (Unreal Championship)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement