Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Moot

Class dependencies

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

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(&DD, "MyGamesSprites.bmp");
  Map.Create(&DD, "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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • 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!