Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

a class question

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

#ifndef _GAME_H
#define _GAME_H


#include <lang/Object.h>


namespace id {
	class InputDriver;}

namespace io {
	class InputStreamArchive;}

namespace sg {
	class Font;
	class Context;}

namespace sgu {
	class SceneManager;}

namespace snd {
	class SoundManager;}

namespace music {
	class MusicManager;}

namespace ps {
	class ParticleSystemManager;}

namespace script {
	class VM;}

namespace util {
	class ExProperties; }

class GameCamera;
class GameLevel;


/**
 * High level game class.
 * @author Jani Kajala (jani.kajala@helsinki.fi)
 */
class Game :
	public lang::Object
{
public:
	Game( script::VM* vm, io::InputStreamArchive* arch, sg::Context* context, sg::Font* dbgFont, util::ExProperties* cfg,
		snd::SoundManager*, ps::ParticleSystemManager*, music::MusicManager*, sgu::SceneManager*, id::InputDriver* inputDriver );

	~Game();

	/** Called at exit. */
	void	destroy();

	/** Called between rendered frames. */
	void	update( float dt );

	/** Called to render single frame. */
	void	render();

	/** Set true if arc ball camera is enabled. */
	void	setArcBallCameraEnabled( bool enabled );

	/** Called when window focus is lost. */
	void	focusLost();

	/** Sets active camera. */
	void	selectActiveCamera( int n );

	/** Sets main character invulnerable. */
	void	setInvulnerable();

	/** Flushes input. */
	void	resetInputState();

	/** Skips notice screen (displayed after loading). */
	void	skipNoticeScreen();

	/** Returns true if arc ball camera is enabled. */
	bool	arcBallCameraEnabled() const;

	/** Returns active camera if any. */
	GameCamera*	activeCamera() const;

	/** Returns current level. */
	GameLevel*	level() const;

private:
	class Impl;
	P(Impl) m_this;

	Game( const Game& );
	Game& operator=( const Game& );
};


#endif // _GAME_H


// ---------============Game.cpp=============----------


Game::Game( VM* vm, InputStreamArchive* arch, Context* context, Font* dbgFont, ExProperties* cfg, 
	SoundManager* soundMgr, ParticleSystemManager* particleMgr, MusicManager* musicMgr, 
	SceneManager* sceneMgr, InputDriver* inputDriver )
{
	m_this = new Impl( vm, arch, context, dbgFont, cfg, soundMgr, particleMgr, musicMgr, sceneMgr, inputDriver );
}

Game::~Game()
{
}

void Game::update( float dt )
{
	m_this->update( dt );
}

void Game::render()
{
	m_this->render();
}

void Game::destroy()
{
	m_this = 0;
}

void Game::focusLost()
{
	m_this->focusLost();
}

void Game::selectActiveCamera( int n )
{
	m_this->selectActiveCamera(n);
}

void Game::resetInputState() 
{
	m_this->resetInputState();
}

void Game::setInvulnerable() 
{
	m_this->setInvulnerable();
}

GameCamera*	Game::activeCamera() const
{
	return m_this->activeCamera();
}

GameLevel* Game::level() const
{
	return m_this->level();
}

void Game::skipNoticeScreen()
{
	m_this->skipNoticeScreen();
}

void Game::setArcBallCameraEnabled( bool enabled )
{
	m_this->setArcBallCameraEnabled( enabled );
}



it is opensource code. here are 2 class Game and Impl; you see,class Game have a pointer to class Impl; Impl is defined in Game class cpp file. so why not directly just put impl in Game class?

Share this post


Link to post
Share on other sites
Advertisement
I do that sort of thing for organization all the time...Say I have a class "City." In city I may want to hold data about population and geography...Rather than have that put right in City, I would make 2 classes for each.


Also, I would do it if another part of the program will require the same data I can then just pass the pointe). If another part of the program will have a use for the class, I would make it a class.

Share this post


Link to post
Share on other sites
The only purpose I see for this, that you can change the interface of impl, without the need to change the interface of Game and with that rest of the program.

for more information take a look at the following Design Patterns (published by Erich Gamma): Proxy, Adapter

Share this post


Link to post
Share on other sites
Quote:
Original post by Sparhawk42
The only purpose I see for this, that you can change the interface of impl, without the need to change the interface of Game and with that rest of the program.

for more information take a look at the following Design Patterns (published by Erich Gamma): Proxy, Adapter


You mean I could change interface this way.everything is ok.usually changing interface is not allowed?

Share this post


Link to post
Share on other sites
I found it is widely used in that engine.

many class divide into 2 class. one for common. one for impl.

so I think it should have much advantage.

Or has it just advantage of
Quote:
you can change the interface of impl, without the need to change the interface of Game and with that rest of the program.
"
?

Maybe this advantage do not make it widely used.

Share this post


Link to post
Share on other sites
Bridge Design Pattern
Facade Design Pattern

Code that uses the Game class do not need to know about the Impl class. Modifying the Impl class doesn't require recompilation of code that uses the Game class - as it would if Impl was directly in Game - in large systems (think, for example, the entire Windows OS source code), this is a major benefit. You can also have multiple, polymorphic Impl classes which are all seen through the same Game facade. This allows you to benefit from the polymorphic behaviour without having any visible pointer or reference: you can have a vector of Game objects pointing to different Impl typesm, which would require a vector of pointers to Impl if Game didn't exist (otherwise you would have slicing and/or problems due to Impl objects having different sizes in memory).

Share this post


Link to post
Share on other sites
I know the reason.
I read a book.
The impl class make dependency less in compiler time.
so to use the class and it do not need include so many .h file.
so make compile fast.

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!