OOp structure[Solved]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
saltytaco1234
Posts: 20
Joined: Wed Dec 15, 2010 10:39 pm

OOp structure[Solved]

Post by saltytaco1234 »

I tried searching this but couldn't find any good information. What I'm trying to do is make a class for each part. Like Player.h, Core.h, etc. But how would I allow the same device, scenemanger, GUiManager, etc. interact with each class. I'm kind of blind at this part. What I'm asking is, is how to make global pointers that can be used by different classes. Would Inherit each class from another?
Last edited by saltytaco1234 on Tue Jun 28, 2011 5:03 pm, edited 1 time in total.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Not trying to be rude, but:
*taken from old thread*
I am looking to join a game development team, to further progress my skills.
Primary Role: Porgrammer
Secondary Role: Modeling
Age:15
Game: Any game
Irrlicht experience: 1 1/2 years.
C++ Experience: 5 years
What were you doing those 5 years??

*And back on topic*

What I did in my framework was that I wrote a "Game" class or you can call it "Core" or w/e you like and stored the pointers to important stuff there. If other classes need to access any of those pointers it just takes the "Game" pointer to its constructor and stores it. Then it can get any of the important pointers and use them.
Working on game: Marrbles (Currently stopped).
saltytaco1234
Posts: 20
Joined: Wed Dec 15, 2010 10:39 pm

Post by saltytaco1234 »

Doing other things, I was never doing anything like this only small little projects.
saltytaco1234
Posts: 20
Joined: Wed Dec 15, 2010 10:39 pm

Post by saltytaco1234 »

Thanks. :D
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

You should read these tutorials http://www.learncpp.com/ carefully and try to understand them - play around by modifying them, make something with the knowledge the tutorials gave you.
These tutorials however are only the basics to get you started. After that you will need to learn to design the stuff you're going to program as having no design proved to cause real headaches when you see that you're heading to a dead end.
Working on game: Marrbles (Currently stopped).
saltytaco1234
Posts: 20
Joined: Wed Dec 15, 2010 10:39 pm

Post by saltytaco1234 »

Would this work?

Code: Select all

class Game
{ 
public: 
   Game (IrrlichtDevice *device) 
   { 
      this->device = device; 
      this->driver = device->getVideoDriver(); 
      this->env = device->getGUIEnvironment(); 
      this->smgr = device->getSceneManager(); 
   } 

   ~Game () 
   {} 

protected: 
   IrrlichtDevice *device; 
   IGUIEnvironment *env; 
   IVideoDriver *driver; 
   ISceneManager *smgr; 
}; 

Code: Select all

#include "Game.h" or "includes.h"
class MyClass : public Game
{ 
public: 
   MyClass(IrrlichtDevice *device) : Game(device) 
   {} 
};
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

I'm sorry, but 5 years of C++ experience and you still have to ask us that?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Not how I mean't.
You should have something like:

Code: Select all

#include "Game.h" or "includes.h" 
class MyClass 
{ 
public: 
   MyClass(Game *game) : m_Game(game) 
   {} 
protected:
   Game * m_Game;

}; 
And when you create MyClass you would pass the Game class pointer into constructor. Then you would be able to use m_Game in MyClass to access all the things you might need.

And again I must say that you have to read those tutorials or other sites that cover those topics to know how to deal with these kind of things.

Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
Working on game: Marrbles (Currently stopped).
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

serengeor wrote:Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
I have Bruce Eckel's Thinking in Java as a reference for my java work, and it's a very excellent book, so I assume that this one would be rather good too
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Radikalizm wrote:
serengeor wrote:Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
I have Bruce Eckel's Thinking in Java as a reference for my java work, and it's a very excellent book, so I assume that this one would be rather good too
Well I've just read first few pages and I really liked it! :)
At first I was afraid to look at it because I taught I might just see some hieroglyphs, but it turned out to be an easy to follow english text even though now its a bit late (01:30~) :shock:
Working on game: Marrbles (Currently stopped).
saltytaco1234
Posts: 20
Joined: Wed Dec 15, 2010 10:39 pm

Post by saltytaco1234 »

serengeor wrote:
Radikalizm wrote:
serengeor wrote:Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
I have Bruce Eckel's Thinking in Java as a reference for my java work, and it's a very excellent book, so I assume that this one would be rather good too
Well I've just read first few pages and I really liked it! :)
At first I was afraid to look at it because I taught I might just see some hieroglyphs, but it turned out to be an easy to follow english text even though now its a bit late (01:30~) :shock:
My mom is ordering the book, as it looks really nice. ^^ Thanks, for the help and the book suggestion. :D
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Another elegant way to keep such things: In a Singleton.
beer->setMotivationCallback(this);
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

My first attempts were using singleton pattern, but later on I got rid of it. It just didn't feel right for me :?

@saltytaco1234: Have you looked at online version(it's free)?
Working on game: Marrbles (Currently stopped).
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

serengeor wrote:My first attempts were using singleton pattern, but later on I got rid of it. It just didn't feel right for me :?

@saltytaco1234: Have you looked at online version(it's free)?
It's a good way to store all the stuff that's needed anywhere in your project and to make sure it's not instanced more than once. -> IrrlichtDevice and its frequently used chaps.
That way you get rid of passing IrrDev, SMgr and the like to every class' constructor and just take it wherever you'd need it.
beer->setMotivationCallback(this);
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re:

Post by serengeor »

polylux wrote:
serengeor wrote:My first attempts were using singleton pattern, but later on I got rid of it. It just didn't feel right for me :?

@saltytaco1234: Have you looked at online version(it's free)?
It's a good way to store all the stuff that's needed anywhere in your project and to make sure it's not instanced more than once. -> IrrlichtDevice and its frequently used chaps.
That way you get rid of passing IrrDev, SMgr and the like to every class' constructor and just take it wherever you'd need it.
Well I was doing the "just take it wherever you'd need it" part and it looked a bit dirty for me, so I decided I should just pass the pointer to the main class that holds pointers to other classes (like device,physics manager and etc.) to whoever needs it.
Though maybe using it for this purpose is not that bad :wink:
Working on game: Marrbles (Currently stopped).
Post Reply