Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualIcebone1000

Posted 22 October 2012 - 01:54 PM

[source lang="cpp"]class Game{ list < GameObjects * > m_gos; void Update(float delta){ for(list::it goIt ..) (*goIt)->Update(delta); } ...};[/source]


Pseudo code..

Id like to make the Class Game the sole responsible for the creation and deletion of the gameobjects.
I always do this with a template function:
[source lang="cpp"]template< class derivedGO>derivedGO* Create(){ derivedGO *p = new derivedGO(); m_gos.add(p); return p;}[/source]
And this is the only way to give the Game class the objects (so if they got created externally, they will not be part of the game).
The only (really annoying imo) problem is that derivedGO must provide a compatible constructor, this sucks, cause I always, then, have to create a Init(params) function that is always called just after calling create..

Is this poor design?

#4Icebone1000

Posted 22 October 2012 - 01:53 PM

[source lang="cpp"]class Game{ list <GameObjects*> m_gos; void Update(float delta){ for(list::it goIt ..) (*goIt)->Update(delta); } ...};[/source]


Pseudo code..

Id like to make the Class Game the sole responsible for the creation and deletion of the gameobjects.
I always do this with a template function:
[source lang="cpp"]template< class derivedGO>derivedGO* Create(){ derivedGO *p = new derivedGO(); m_gos.add(p); return p;}[/source]
And this is the only way to give the Game class the objects (so if they got created externally, they will not be part of the game).
The only (really annoying imo) problem is that derivedGO must provide a compatible constructor, this sucks, cause I always, then, have to create a Init(params) function that is always called just after calling create..

Is this poor design?

#3Icebone1000

Posted 22 October 2012 - 01:53 PM

[source lang="c++"]class Game{ list <GameObjects*> m_gos; void Update(float delta){ for(list::it goIt ..) (*goIt)->Update(delta); } ...};[/source]

Pseudo code..

Id like to make the Class Game the sole responsible for the creation and deletion of the gameobjects.
I always do this with a template function:
[source lang="cpp"]template< class derivedGO>derivedGO* Create(){ derivedGO *p = new derivedGO(); m_gos.add(p); return p;}[/source]
And this is the only way to give the Game class the objects (so if they got created externally, they will not be part of the game).
The only (really annoying imo) problem is that derivedGO must provide a compatible constructor, this sucks, cause I always, then, have to create a Init(params) function that is always called just after calling create..

Is this poor design?

#2Icebone1000

Posted 22 October 2012 - 01:53 PM

[source lang="java"]class Game{ list <GameObjects*> m_gos; void Update(float delta){ for(list::it goIt ..) (*goIt)->Update(delta); } ...};[/source]

Pseudo code..

Id like to make the Class Game the sole responsible for the creation and deletion of the gameobjects.
I always do this with a template function:
[source lang="cpp"]template< class derivedGO>derivedGO* Create(){ derivedGO *p = new derivedGO(); m_gos.add(p); return p;}[/source]
And this is the only way to give the Game class the objects (so if they got created externally, they will not be part of the game).
The only (really annoying imo) problem is that derivedGO must provide a compatible constructor, this sucks, cause I always, then, have to create a Init(params) function that is always called just after calling create..

Is this poor design?

#1Icebone1000

Posted 22 October 2012 - 01:52 PM

[source lang="java"]class Game{ list<GameObjects*> m_gos; void Update(float delta){ for(list::it goIt ..) (*goIt)->Update(delta); } ...};[/source]

Pseudo code..

Id like to make the Class Game the sole responsible for the creation and deletion of the gameobjects.
I always do this with a template function:
[source lang="cpp"]template< class derivedGO>derivedGO* Create(){ derivedGO *p = new derivedGO(); m_gos.add(p); return p;}[/source]
And this is the only way to give the Game class the objects (so if they got created externally, they will not be part of the game).
The only (really annoying imo) problem is that derivedGO must provide a compatible constructor, this sucks, cause I always, then, have to create a Init(params) function that is always called just after calling create..

Is this poor design?

PARTNERS