Jump to content
  • Advertisement
Sign in to follow this  
dreams05

Structuring "engine" included files

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

I'm having trouble figuring out the best way to structure multiple files so that I can use common dependencies. So I have a couple different parts- the main engine, where I want to include all the sub area's (video, io, scene management, ect) - but some depend on other ones. I'm not getting it correctly, but how would I setup the basics so that: All namespaces have access to core namespace, as well as the basic GL functions, and the engine has all the engine files in it. basically - this doesn't work: (says vector3df is not a member of engine::core...) Engine: ---------------engine.h--------------------- #include "core.h" #include "sceneManager.h" #pragma once #include <iostream> #include <windows.h> #include <stdio.h> // Header File For Standard Input/Output #include <GL/gl.h> // Header File For The OpenGL32 Library #include <GL/glu.h> // Header File For The GLu32 Library #include "C:\resources\SDL-1.2.13\include\SDL.h" #include <list> #include <vector> namespace engine { namespace core { } namespace gui { } namespace io { } namespace scene { } namespace video { } class engine { }; } -----------------------core.h-------- #ifndef _CORE_H #define _CORE_H 1 #include "engine.h" namespace engine { namespace core { struct vector3df { } } } #endif -----------------sceneManager.h------------ #ifndef _SCENEMANAGER_H #define _SCENEMANAGER_H 1 #include "engine.h" namespace engine { namespace scene { class sceneNode { }; class cameraNode :sceneNode { public: GLfloat rotateSpeed; GLfloat moveSpeed; cameraNode() { core::vector3df pos; } }; } } #endif

Share this post


Link to post
Share on other sites
Advertisement
You've got some confusing #include's there, so I'll try to distill it down to as simple as possible and hopefully you can spot the problem:

// engine.h
#include "core.h"
#include "scenemanager.h"

// etc



// core.h
#ifndef _CORE_H
#define _CORE_H

#include "engine.h"

struct abc;

#endif



// scenemanager.h
#ifndef _SCENEMANAGER_H
#define _SCENEMANAGER_H

#include "engine.h"

class def {
abc foo;
};

#endif



Can you spot, if you #include "core.h" before any other file, why you would get that error?

The simplest solution is to add #include "core.h" at the top of your scenemanager.h file.

The correct solution is to minimize the number of includes you have in your header files so that the only things included are things actually needed in that file. For example, don't #include "engine.h" from your core.h, because you don't need anything from it. Don't #include "core.h" in your engine.h because you don't use anything from it. Etc.

Share this post


Link to post
Share on other sites
Don't #include engine into core, it doesn't make sense and it's a recursive include.

Instead of #include "C:\resources\SDL-1.2.13\include\SDL.h" you might consider adding the SDL path to your project, or the SDL folder to your compiler folder.

You don't need the 1 after your defines (#define _CORE_H 1).

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!