Skip to main content
GameDev.net gamedev.net
🔒 Locked

.h, .cpp, and gamecores

Started by stenny Aug 30, 2006 at 12:25 PM 1 replies 550+ views
Original Post
stenny
stenny
Hello! I've invested money into a book about DirectX and after some intensive reading, I've landed at the chapter about gamecores. That is, turning everything I learned about DirectX Graphics, Input and Sound into gamecores. I have had some problems with the files themselves though. The base of a core looks like this: 1. A header file, like System_Core.h or Sound_Core.h In file 1 the classes, variables and other things are declared. Ónly declared and nothing more... 2. A ccp file, like System_Core.cpp or Graphics_Core.h In this file the classes, variables, functions from file 1 are defined and base functions are written 3. A general header file, called Global_Core.h In this core the main includes needed are included, like System_Core.h and Input_Core.h, but also the directX headers like dshow.h, d3d9.h and windows.h 4. The WinMain.cpp file The base WinMain file in which everything combines into one. I just don't get how these are linked together though. I don't know in which files to include what header and stuff. I've tried posting on these forums with specific errors when trying to compile the input core but it only got worse. Errors that say I included headers twice where they're not supposed to, and errors that say the IDE doesn't recognize DirectX COM object because the right headers aren't included. I'm in a state of flux! I hope I can finally get an answer because I've been stuck at this point for a month or so. Please reply and help, -Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
Aardvajk
Aardvajk
I don't know if this will help, but I'll bash out a quick example of the structure you have described in a way that should work:

D3DCore.h
#ifndef D3DCore_H#define D3DCore_H#include <windows.h>#include <d3d9.h>extern ID3DDevice9 *Dev; // variableextern HWND Hw; // variableclass Surface // class definition{private:    ID3DSurface9 *Ptr;public:    Surface();};#endif


D3DCore.cpp
#include "D3DCore.h"ID3DDevice9 *Dev=0; // initialisersHWND Hw=NULL;Surface::Surface() : Ptr(0) // member implementation{}


GameCore.h
#ifndef GameCore_H#define GameCore_H#include "D3DCore.h" // plus any others#endif


WinMain.cpp
#include "GameCore.h"int WINAPI WinMain() // etc{    // use Dev, Hw and Surface etc...}


D3DCore.cpp and WinMain.cpp will be compiled into two seperate object files which the linker should then be able to turn into an exe assuming it is told to link to the necessary windows libs and d3d9.lib.

Is your structure different from the one above? I appreciate it will be a lot more complex, but in terms of where the includes are, where the externs are, where the initialisers are and so on?

Sorry if this is not much help but you seem at the end of your tether and it is all I could really think to post.
stenny
stenny
Quote:
Is your structure different from the one above? I appreciate it will be a lot more complex, but in terms of where the includes are, where the externs are, where the initialisers are and so on?

Sorry if this is not much help but you seem at the end of your tether and it is all I could really think to post.


Thank you! This actually is a bit clear. I'm indeed quite desperate and I think you're name says it all[grin].

I'll try you're code and edit to post if it works.

-Stenny
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.