void MyPS2Application::CleanUp()
{
	SPS2Manager.CleanUp();
	pad_cleanup(PAD_0);
	DSP0.Close();
	DSP1.Close();
	
	delete player;
	delete ball;
	delete block;
	player = NULL;
	ball = NULL;
	block = NULL;
}
void MyPS2Application::Init()
{
	// Initialise control pad 0
	if(!pad_init(PAD_0, PAD_INIT_LOCK | PAD_INIT_ANALOGUE | PAD_INIT_PRESSURE))
	{
		printf("Failed to initialise control pad\n");
		pad_cleanup(PAD_0);
		exit(0);
	}	
	
	// Allocate memory for the graphics data
	SPS2Manager.Initialise(1024);	// 1024 * 4K Pages = 4MB Total
	VIFStaticDMA.Initialise(512);	// 512 * 4K Pages = 2MB Static DMA
	VIFDynamicDMA.Initialise(256);	// 256 * 4K Pages * 2 Buffers =
									// 2MB Dynamic DMA
																	
	// Register our signal function for every possible signal (e.g. ctrl + c)
	for(int sig=0; sig<128; sig++)
		signal(sig, sig_handle);

	// Define the clear screen colour. We want to clear to blueish.
	SPS2Manager.InitScreenClear(0, 0x05, 0x30);
	
	// Register our signal function for every possible signal (i.e. ctrl + c)
	for(int sig=0; sig<128; sig++)
		signal(sig, sig_handle);

	// Set up the DMA packet to clear the screen. We want to clear to blue.
	SPS2Manager.InitScreenClear(0, 0x25, 0x10);
	
	// Set up the background sprite's size.
	InitializeBackgroundSprite();
	
	// Set game state.
	game_state = INTRO;
	
	// Initialize the game state booleans.
	intro_loaded = false;
	menu_loaded = false;
	game_loaded = false;
	game_over_loaded = false;
	
	ball_launched = false;
	
	game_music = false;
	
	// Set up the number of rows and columns of blocks to be made.
	num_block_row = 5;
	num_block_column = 8;
}
Example #3
0
int main(void)
{	
	// Make sure these four lines are put first since some of the 
	// other classes need the managers to be initialised so they 
	// can pick up the correct data.	
	SPS2Manager.Initialise(4096);	// 4096 * 4K Pages = 16MB Total
	VIFStaticDMA.Initialise(3072);	// 1536 * 4K Pages = 6MB Static DMA
	VIFDynamicDMA.Initialise(256);	// 256 * 4K Pages * 2 Buffers =
									// 2MB Dynamic DMA
	Pipeline.Initialise();			// Initialise graphics pipline class
	
	
	// Initialise Lighting
	// Three lights and Ambient light
	//							Direction vector				  Colour	
	Pipeline.SetLight1(Vector4( 0.0f, 0.5f, -1.0f, 0.0f),  Vector4( 0.0f, 0.0f, 128.0f, 0.0f));
	Pipeline.SetLight2(Vector4( 1.0f, -0.5f, -1.0f, 0.0f),  Vector4( 0.0f, 128.0f, 0.0f, 0.0f));
	Pipeline.SetLight3(Vector4( -1.0f, -0.5f, -1.0f, 0.0f), Vector4( 128.0f, 0.0f, 0.0f, 0.0f));
	//                            Colour
	Pipeline.SetAmbient(Vector4(50.0f,50.0f,50.0f,50.0f));
	
	// Terrain to render
	CTerrain Terrain;
	
	// Performance timer - call after SPS2Manager.Initialise()
	CTimer Timer;
	
	// Set up audio devices
	AudioDevice DSP0(0);
	// Set up music in sound buffer 0
	SoundSample music("go_cart", &DSP0);
	// Play the music!
	music.Play();
	
	// Initialise control pad 0
	if(!pad_init(PAD_0, PAD_INIT_LOCK | PAD_INIT_ANALOGUE | PAD_INIT_PRESSURE))
	{
		printf("Failed to initialise control pad\n");
		pad_cleanup(PAD_0);
		exit(0);
	}	
	enable_actuator(0, 1, 1);
	
	// Initialise the VU1 manager class
	CVU1MicroProgram VU1MicroCode(&VU_vu1code_start, &VU_vu1code_end);
	
	// Upload the microcode
	VU1MicroCode.Upload();

	// Register our signal function for every possible signal (i.e. ctrl + c)
	for(int sig=0; sig<128; sig++)
		signal(sig, sig_handle);
		
		
	// Set up the DMA packet to clear the screen. We want to clear to blue.
	SPS2Manager.InitScreenClear(0, 0x25, 0x50);
	
	// Set Up Camera --------------------------------------------------------------
	
	Pipeline.PositionCamera(Vector4(0.0f, 55.0f, 80.0f, 1.0f), Vector4(0.0f, 40.0f, 0.0f, 1.0f));
	
	// Load in texture and models ----------------------------------------------
	
	// Set up asset loader
	AssetManager assetManager;
	assetManager.Initialize();
	
	// Terrain texture
	CTexture* terrainTexture = assetManager.GetTexture("terrain");
	
	// Set up game manager
	GameManager* gameManager = new GameManager;
	gameManager->Initialize();
		
	// The main Render loop -------------------------------------------------------
	while(g_bLoop)
	{
		
		// Process Audio
		DSP0.HandleAudio();
		
		VIFDynamicDMA.Fire();
		
		// Update Control Pad
		pad_update(PAD_0);
		Pipeline.Update(0, 0, 0, 0, 0);
		
		// Logic
		g_bLoop = gameManager->Logic();
	
		// Render
		SPS2Manager.BeginScene();
		
		// Render terrain
		AssetManager::GetSingleton().LoadTexture(terrainTexture);
		Matrix4x4 matWorld, matTrans, matScale;
		matTrans.Translation(0.0f, -30.0f, 0.0f);
		matScale.Scaling(20.0f);
		matWorld =  matScale * matTrans;
		Terrain.SetWorldMatrix(matWorld);
		Terrain.Render();
		
		// Render scene
		gameManager->Render();
		SPS2Manager.EndScene();	
		
		// Dump screenshot if requested
		if(pad[0].pressed & PAD_R2)SPS2Manager.ScreenShot();		
	}

	// Shutdown Audio
	DSP0.Close();
	
	// Shutdown control pad
	set_actuator(0, 0, 0);
	pad_cleanup(PAD_0);
	
	// Shutdown game manager
	gameManager->Shutdown();
	
	// Shutdown asset manager
	assetManager.Shutdown();
	
	return 0;
}