Question about header files etc

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Question about header files etc

      Im currently putting together some of the systems described in GCC3 and I noticed that my #include's were getting hard to keep track of.

      I read somewhere online that the use of a global header file is a good idea (like having 1 headerfile like global.h and including it to everything)


      // global.h
      #include <windows.h>
      #include <windowsx.h>
      #include <d3d9.h>
      #include <d3dx9.h>
      #include "gamewindow.h"

      #pragma comment (lib, "d3d9.lib")
      #pragma comment (lib, "d3dx9.lib")

      // prototypes

      // WinMain.cpp
      LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
      void DisplayWindow(GAMEWINDOW* gw, HINSTANCE hInstance, int nCmdShow);
      bool HandleMessages();

      // Loop.cpp
      void MainLoop();
      // Direct3D.cpp
      void InitDirect3D(GAMEWINDOW* gw);
      void CloseDirect3D();


      Is this the right kind of idea? and if so how is the propper way to implement it with the GCC architecture?
    • would something like this be the way to go?

      #pragma once

      //global.h
      #include <windows.h>
      #include <windowsx.h>
      #include <d3d9.h>
      #include <d3dx9.h>

      #pragma comment (lib, "d3d9.lib")
      #pragma comment (lib, "d3dx9.lib")

      //STD libary
      #include <string>
      #include <map>

      //Prototypes for classes/functions
      class Application;

      etc...

      //game specific headers

      #include <LuaStateManager.h>
      #include <EventManager.h>

      etc...






      and then have that included in all the .cpp's then when i need it add other includes to the game specific headers like "GameLogic.h" etc, and as needed add prototypes for any classes/functions that need to be known by the game specific headers that were declared after them?

      thanx

      Nex
    • Putting common header files into this, and precompiling it (like GCC does in GameCodeStd.h) is generally a good idea but be warned - this does have a dark side.

      If anything in the header changes, or anything it includes changes, everything that includes it must be recompiled!

      So, be very careful about what you include in the header file - it shouldn't be any header that is still changing fairly often.
      Mr.Mike
      Author, Programmer, Brewer, Patriot