/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/sgx/game/scenario.hpp

*/

#ifndef SGX_GAME_SCENARIO_HPP
#define SGX_GAME_SCENARIO_HPP	1

/**
A game scenario can comprise of any wholely self-contained play experience.
That is, a level from a game, the front end menus, a sub-game, and so on.

When moving between scenarios, you need to remove all game objects from
their respective engines, and add new ones. There could be potential 
problems if you remove game objects from the engine while the engine was
updating that particular object. Therefore, we have a 'scenario' that sits
above all the different engines, to handle the change-over.

CSGXGameScenario is a factory-like method. You should derive from this to
create scenarios for each part of your game, creating instances of them.

e.g.

pFarmMiniGame = new FarmScenario();

This switches as appropriate in the main update loop with,

if (CSGXScenarioManager::get()->hasScenarioChanged()) {
	CSGXScenarioManager::get()->switchScenario();
}

In reality, switchScenario checks for whether it's changed. We 
include the hasScenarioChanged explicitly to demonstrate the process.

The implementation of the FarmScenario is then:

tBOOL FarmScenario::create() {
	CSGXHappening::get()->registerScenarioObjectToAllEngines(new FarmGameWorld());
}

Naturally, you can create as many game objects as you like here, since they will
all be destroyed when the scenario is switched out and CSGXGameScenario::release is called.
*/


class CSGXGameScenario {
public:
	CSGXGameScenario() : m_pWorldObject(NULL) {}
	virtual ~CSGXGameScenario();

	virtual tBOOL create(const tMEM_SIZE userdata) { SGX_UNUSED(userdata); return TRUE; }
	virtual tBOOL release();

protected:
	CGameHandler *m_pWorldObject;

};

class CSGXScenarioManager {
public:

	static CSGXScenarioManager *get();
	static CSGXScenarioManager *create();

	void	initialize();
	void	cueNextScenario(CSGXGameScenario *pScenario, tMEM_SIZE userdata = 0);

	tBOOL	hasScenarioChanged();
	tBOOL	switchScenario();

protected:
	static CSGXScenarioManager *m_pSingleton;
	CSGXGameScenario *	m_pCurrentScenario;
	CSGXGameScenario *	m_pReplacementScenario;
	tMEM_SIZE			m_ReplacementUserdata;
};

#endif /* #define SGX_GAME_SCENARIO_HPP */
