Advertisement

Class dependencies

Started by November 27, 2000 06:15 AM
1 comment, last by Moot 24 years, 1 month ago
Can an exprienced C++ developer please give me a little advice? I'm currently writing my own wrappers for Direct Draw. The problem is that every class is going to be dependent on the Direct Draw object class itself. For example, my surface class needs to initialise using the 'create surface' method of the DD object, so I'm currently passing a pointer to my Direct Draw class to a 'create' method of my surface. I'm also going to write a scrolling map class, which will contain a surface object for the tiles bitmap, so I will need to pass the Direct Draw pointer to that, because it will need to pass it in turn to the surface 'create' method when loading the bitmap file. I need to know whether this approach is correct or whether there is a better (or more object oriented) way of doing this. I'm fairly new to C++ and so I may still be thinking too "procedurally". I don't see the dependence on the Direct Draw object as being a problem. After all, all classes are dependent on the standard C++ data types. However, I would like to hear the opinions of someone with a couple of years C++ coding experience under their belt. Below I've included a very simplified, pseudocodey version of my classes and app which hopefully makes things a little clearer. Note: I've not yet implemented the 'Tile Map' class, so the code below is just what I'm planning to do, and I hope that everything is clear, despite my having left out so much code. Thanks to anyone taking the time to look at this. Sorry it's so long. Moot
    

////// The Direct Draw object


#include "MyDirectSurfaceClass.h"

class MyDirectDrawClass {

  //... 


  private

  //...

  LPDIRECTDRAW7         lpDDPointer;
  MyDirectSurfaceClass  PrimarySurface
  MyDirectSurfaceClass  BackBufferSurface
  //...


};

////// The Surface object


#include "MyDirectDrawClass.h"

class MyDirectSurfaceClass {

  public
  
  //... 

  //Create method: Pass a pointer to the DD object, along with a

  // the filename of a bitmap

  bool Create(MyDirectDrawClass*, char*);
  //..


  private

  //...


};

////// The Tile Map class


#include "MyDirectDrawClass.h"
#include "MyDirectSurfaceClass.h"

class MyTileMapClass {

  public
  
  //... 

  //Create method: Pass a pointer to the DD object, along with

  // the filename of the bitmap containing the tiles

  bool Create(MyDirectDrawClass*, char*);
  //...


  private

  //...

  MyDirectSurfaceClass TileMapSurface
  //...


};

///// The game itself



// includes here



// variables global to the game module

MyDirectDrawClass    DD
MyDirectSurfaceClass Sprites
MyTileMapClass       Map

// Init, main loop and shutdown functions


void Game_Init(HWND hWnd) {

  DD.InitFullScreen(hWnd, 640, 480, 16, 1);
  Sprites.Create(ⅅ, "MyGamesSprites.bmp");
  Map.Create(ⅅ, "MyGamesTiles.bmp");

}

void Game_Main(void) {

  //.. do game stuff here..


  DD.Flip();

}

void Game_Shutdown(void) {

  Map.Release();
  Sprites.Release();
  DD.Shutdown();
}

  
Edited by - Moot on 11/27/00 6:27:16 AM
Hey Moot,

What you''ve done looks good - there are many ways to skin a cat. I have just got my ddraw wrapper to a useful point and I have done it in a slightly different way to you. I have created a single interface which provides a load of high level functions eg/
loadSprite (from file)
displaySprite (to screen)
loadLayer (from file) -- used for backdrops etc...
displayLayer
loadMap
displayMap

Each abstraction is encapsulated, just like you seperated out the surface and tile map classes. So for example I have a sprite class which the main interface uses. The reason I went for a single interface was because it simplifies the main program.

-DeVore
Advertisement
Thanks for the feedback, DeVore.

Is there any chance you could send me some of your source code? I don''t want to steal your code, just look at how you''ve solved the problem, so just sending the header files would be cool.

My email is mistermoot@hotmail.com

Don''t worry if you''d rather keep your code to yourself. I won''t be offended!

Moot

This topic is closed to new replies.

Advertisement