Exemple #1
0
//-----------------------------------------------------------------------------------------------------------------------------------
void ScreenManager::Draw()
{
	// Draw the background
	m_spriteBatch->Begin(SpriteSortMode_Immediate, m_states->NonPremultiplied());

	m_activeScreens.back()->DrawBackground(m_spriteBatch.get(), m_spriteFont.get());

	m_spriteBatch->End();

	// Draw the camera dependent game objects
	m_spriteBatch->Begin(SpriteSortMode_Immediate, m_states->NonPremultiplied(), nullptr, nullptr, nullptr, nullptr, m_camera.GetViewMatrix());

	for (BaseScreen* screen : m_activeScreens)
	{
		screen->DrawInGameObjects(m_spriteBatch.get(), m_spriteFont.get());
	}

	m_spriteBatch->End();

	// Draw the screen (camera independent) objects
	m_spriteBatch->Begin(SpriteSortMode_Immediate, m_states->NonPremultiplied());

	for (BaseScreen* screen : m_activeScreens)
	{
		screen->DrawScreenObjects(m_spriteBatch.get(), m_spriteFont.get());
	}

	// Draw the game mouse - camera independent
	m_gameMouse.Draw(m_spriteBatch.get(), m_spriteFont.get());

	m_spriteBatch->End();
}
Exemple #2
0
//-----------------------------------------------------------------------------------------------------------------------------------
void ScreenManager::HandleInput(float elapsedSeconds)
{
	m_gameMouse.HandleInput(elapsedSeconds);

	for (BaseScreen* screen : m_activeScreens)
	{
		// Screen input handling
		screen->HandleInput(elapsedSeconds);
	}
}
Exemple #3
0
//-----------------------------------------------------------------------------------------------------------------------------------
void ScreenManager::Update(float elapsedSeconds)
{
	m_keyboard.Update();
	m_camera.Update(elapsedSeconds);
	m_gameMouse.Update(elapsedSeconds);

	for (BaseScreen* screen : m_activeScreens)
	{
		// Screen updating
		screen->Update(elapsedSeconds);
	}

	for (BaseScreen* screen : m_screensToDelete)
	{
		// Clean up dead screens
		m_activeScreens.remove(screen);
		delete screen;
	}

	m_screensToDelete.clear();
}
Exemple #4
0
void Game::Create()
{
	// Set the platform
	ApConfig::SetPlatform( ApPlatform_WinGL );
	ApConfig::SetDevice( ApDevice_WIN );

	GLFWvidmode dvm;

	// Initialise GLFW
	if(!glfwInit())
	{
		fprintf(stderr, "Failed to initialize GLFW\n");
		exit(EXIT_FAILURE);
	}

	glfwGetDesktopMode(&dvm);

	project->Init();

	// Frame counter and window settings variables
	int frame = 0;
	int redBits = 8, greenBits = 8, blueBits = 8;
	int alphaBits = 8, depthBits = 24, stencilBits = 8;
	m_width = RsUtil::GetWidth();
	m_height = RsUtil::GetHeight();

	glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);

	// Create a window
	if(!glfwOpenWindow(m_width, m_height, redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits, GLFW_WINDOW))
	{
		fprintf(stderr, "Failed to open GLFW window\n");

		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	// Set listeners
	glfwSetWindowCloseCallback(windowCloseListener);

	int width, height;
	GetDesktopResolution(width, height);
	glfwSetWindowPos((width / 2) - (RsUtil::GetWidth() / 2), (height / 2) - (RsUtil::GetHeight() / 2));

	// Cache the window handle
	int handle = glfwGetWindowParam( -1 );

	// Create the game mouse
	m_gameMouse.Setup( (HWND)handle );
	m_gameMouse.CreateOnDevice();

	// Create the render system
	RsImpl::pInstance()->Create();

	SdSoundWinGL::CreateManager();

	BtTimeDX11::Init();

	//glfwOpenWindowHint( GLFW_REFRESH_RATE, 1.0f / 30.0f );

	glfwSetWindowTitle( ApConfig::GetTitle() );

	// Ensure we can capture the escape key being pressed below
	glfwEnable(GLFW_STICKY_KEYS);

	// Enable vertical sync (on cards that support it)
	glfwSwapInterval(1);

	// Hide the cursor
	glfwDisable(GLFW_MOUSE_CURSOR);

	project->Create();
	project->Reset();
	do
	{
		// Get window size (may be different than the requested size)
		glfwGetWindowSize(&m_width, &m_height);

		// Set the window size
		glViewport(0, 0, m_width, m_height);

		BtFloat dt = BtTime::GetTick();
		BtFloat elapsedTime = BtTime::GetElapsedTimeInSeconds();
		BtFloat deltaTime = elapsedTime - m_lastGameLogic;

		m_lastGameLogic = elapsedTime;

		// Add the excess
		m_frameRemainder += deltaTime;

		// Cap the frame
		m_frameRemainder = BtClamp(m_frameRemainder, (BtFloat)0, 1.0f);

		BtBool isExiting = BtFalse;

		//while( m_frameRemainder >= dt )
		{
			// Update the keys
			input.Update();

			// Update the game logic
			GameUpdate();

			// Remove the dt from the frame remainder
			m_frameRemainder -= dt;
		}

		if((isClosing == BtFalse) && (project->IsClosing() == BtFalse))
		{
			// Render
			project->Render();

			// Render
			RsImpl::pInstance()->Render();
		}

		// Swap buffers
		glfwSwapBuffers();
	} // Check if the ESC key was pressed or the window was closed
	while(project->IsClosed() == BtFalse);

	// Destroy the renderer
	RsImpl::pInstance()->Destroy();

	// Destroy the sound
	SdSoundWinGL::DestroyManager();

	// Remove the game mouse
	m_gameMouse.RemoveFromDevice();

	// Destroy the project
	project->Destroy();

	// Close OpenGL window and terminate GLFW
	glfwTerminate();
}
Exemple #5
0
void GameUpdate()
{
	// Update the game mouse
	m_gameMouse.Update();

	// Cache the number of mice
	BtU32 numMice = m_gameMouse.GetNumMice();

	for( BtU32 device=0; device<numMice; device++ )
	{
		// Cache the position of the mouse pointer
		MtVector2 v2Position = m_gameMouse.GetPosition( device );

		BtFloat x = v2Position.x;
		BtFloat y = v2Position.y;

		BtU32 mouseIndex = device * 2;

		if( m_gameMouse.Pressed( 0, device ) == BtTrue )
		{
			ShTouch::BeginTouch( mouseIndex, MtVector2( x, y ) );
		}

		if( m_gameMouse.IsAlive( device ) == BtTrue )
		{
			ShTouch::SetAlive( mouseIndex );
		}

		ShTouch::MoveTouch( mouseIndex, MtVector2( x, y ) );

		if( m_gameMouse.Released( 0, device ) == BtTrue )
		{
			ShTouch::EndTouch( mouseIndex, MtVector2( x, y ) );
		}

		BtU32 button2 = mouseIndex + 1;

		if( m_gameMouse.Pressed( 1, device ) == BtTrue )
		{
			ShTouch::BeginTouch( button2, MtVector2( x, y ) );
		}

		ShTouch::MoveTouch( button2, MtVector2( x, y ) );

		if( m_gameMouse.Released( 1, device ) == BtTrue )
		{
			ShTouch::EndTouch( button2, MtVector2( x, y ) );
		}		
	}

	ShTouch::Update();

	if( UiKeyboard::pInstance()->IsPressed( UiKeyCode_F4 ) )
	{
		windowCloseListener();
		project->SetClosing();
	}

	// Update
	if( project->IsClosed() == BtFalse )
	{
		project->Update();
	}
}
Exemple #6
0
//-----------------------------------------------------------------------------------------------------------------------------------
void ScreenManager::Initialize()
{
	m_gameMouse.Initialize();
}
Exemple #7
0
//-----------------------------------------------------------------------------------------------------------------------------------
void ScreenManager::LoadContent()
{
	m_gameMouse.LoadContent(m_device);
}