Example #1
0
void HlDebug::Save()
{
	BtChar filename[256];
	sprintf(filename, "%sdebug.txt", ApConfig::GetDocuments() );

	FsFile file;
	file.Open( filename, FsMode_WriteAscii );

	if( file.IsOpen() )
	{
		BtQueue<HlItem*, 32> itemStack;

		file.Write( "<DebugAttributes>\n" );
		BtU32 numItems = m_items.GetNumItems();
		for( BtU32 i=0; i<numItems; i++ )
		{
			HlItem &item = m_items[i];
			if( item.m_type == HlDebugNode )
			{
				file.Write( "<%s>%d</%s>\n", item.m_name, item.m_isCollapsed, item.m_name );
			}
		}		

		file.Write("</DebugAttributes>\n");
		file.Close();
	}
}
Example #2
0
void pgCamera::Update()
{
	if (ApConfig::IsWin())
	{
		static BtBool isLoaded = BtFalse;
		if (isLoaded == BtFalse)
		{
			// If we have a previously saved version of the camera then load
			FsFile file;
			BtChar filename[64];
			sprintf(filename, "%s%s", ApConfig::GetDocuments(), "camera.txt");
			file.Open(filename, FsMode_Read);
			if (file.IsOpen())
			{
				file.Read(m_cameraData);
				file.Close();
			}
			isLoaded = BtTrue;
		}
	}

	if (UiKeyboard::pInstance()->IsPressed(UiKeyCode_F3))
	{
		m_isFlyCam = !m_isFlyCam;
	}


	for (BtU32 i = 1; i < MaxTouches; i += 2)
	{
		if (ShTouch::IsHeld(i) || m_isFlyCam)
		{
			BtFloat speed = BtTime::GetTick() * 10.0f;

			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT))
			{
				speed = speed * 10.0f;
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_W))
			{
				MoveForward(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_S))
			{
				MoveBackward(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_D))
			{
				MoveRight(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_A))
			{
				MoveLeft(speed);
			}
		}
	}


	if (ShTouch::IsHeld(1))
	{
        BtBool onScreen = BtTrue;//ShTouch::OnScreen(1);
		if (onScreen)
		{
			for (BtU32 i = 0; i < MaxTouches; i += 2)
			{
				// Rotate the camera
				MtVector2 v2MouseDirection = ShTouch::GetMovement(i);
				BtFloat speed = BtTime::GetTick() * 0.1f;
				MtMatrix3 m3Rotate;
				m3Rotate.SetRotationY(v2MouseDirection.x * -speed);
				m_cameraData.m_m3Rotation = m3Rotate * m_cameraData.m_m3Rotation;
				m3Rotate.SetRotationX(v2MouseDirection.y * speed);
				m_cameraData.m_m3Rotation = m_cameraData.m_m3Rotation * m3Rotate;
			}
		}
	}

	static BtBool isCursorKeys = BtFalse;

	// Rotate the camera
	BtFloat speed = BtTime::GetTick();

	if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT))
	{
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LEFT))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_yaw += speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_RIGHT))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_yaw -= speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_UP))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_pitch -= speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_DOWN))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_pitch += speed;
		}
	}

	if (!ApConfig::IsWin())
	{
		// Support a landscape quaternion
		MtMatrix3 m_m3Rotation;
		MtQuaternion quaternion = ShIMU::GetQuaternion(0);
		quaternion.x = quaternion.x;
		quaternion.y = quaternion.y;
		quaternion.z = -quaternion.z;

		m_m3Rotation = MtMatrix3(quaternion);
		//m_m3Rotation = m_m3Rotation.GetInverse();

		MtMatrix3 m3RotateY;
		m3RotateY.SetRotationY(MtDegreesToRadians(90.0f));

		MtMatrix3 m3RotateZ;
		m3RotateZ.SetRotationZ(MtDegreesToRadians(-90.0f));

		m_m3Rotation = m3RotateY * m_m3Rotation;
		m_m3Rotation = m3RotateZ * m_m3Rotation;
		m_m3Rotation = m_m3Rotation * m3RotateZ;

		m_camera.SetRotation(m_m3Rotation);

	}
	else if (ShHMD::IsHMD())
	{
		MtMatrix3 m3RotateY;
		m3RotateY.SetRotationX(m_cameraData.m_pitch);
		MtMatrix3 m3RotateX;
		m3RotateX.SetRotationY(m_cameraData.m_yaw);
		m_cameraData.m_m3Rotation = m3RotateX * m3RotateY;

		// Cache the ShHMD rotation
		MtQuaternion quaternion = ShHMD::GetQuaternion();

		// Set the IMU rotation
		MtMatrix4 m4FinalRotation = m_cameraData.m_m3Rotation * MtMatrix3(quaternion);

		// Set the rotation
		m_camera.SetRotation(m4FinalRotation);
	}
	else
	{
		if (isCursorKeys)
		{
			MtMatrix3 m3RotateY;
			m3RotateY.SetRotationX(m_cameraData.m_pitch);
			MtMatrix3 m3RotateX;
			m3RotateX.SetRotationY(m_cameraData.m_yaw);
			m_cameraData.m_m3Rotation = m3RotateX * m3RotateY;
		}

		// Set the rotation
		m_camera.SetRotation(m_cameraData.m_m3Rotation);
	}

	// Set the position
	m_camera.SetPosition(m_cameraData.m_v3Position);

	// Update the camera
	m_camera.Update();

	if (UiKeyboard::pInstance()->IsPressed(SaveCameraKey))
	{
		FsFile file;
		BtChar filename[64];
		sprintf(filename, "%s%s", ApConfig::GetDocuments(), "camera.txt");
		file.Open(filename, FsMode_Write);
		if (file.IsOpen())
		{
			file.Write(m_cameraData);
			file.Close();
		}
	}
}
Example #3
0
void HlView::LoadMenu()
{
	BtChar *pMenu = BtNull;
	BtU32 length = 0;

	// Empty the items
	m_items.Empty();

	m_pCurrentMenuItemSelected = BtNull;
	m_pCurrentMenuItem = BtNull;
	
	// Always load from the userdata 
	BaUserData *userData = m_archive.GetUserData( m_screenName );
	pMenu = (BtChar*)userData->GetData();
    length = userData->GetSize();

	if( ApConfig::IsDebug() )
	{
		if( ApConfig::GetDevice() == ApDevice_WIN )
		{
			// Set the filename
			BtChar filename[256];
			sprintf(filename, "%s..\\gamedata\\%s.archive\\userdata\\%s.txt",
				ApConfig::GetResourcePath(), m_archiveName, m_screenName);

			// Open the file
			FsFile file;
			file.Open(filename, eFsMode_Read);
			if(file.IsOpen())
			{
				BtU32 fileSize = file.GetSize();

				// Read the file into memory
				BtChar contents[1024 * 32];

				BtAssert(fileSize < 1024 * 32);
				length = file.GetSize();
				file.Read((BtU8*)contents, length);
				file.Close();
				*(contents + length) = '\0';
				pMenu = contents;
			}
		}
	}

	// TEST XML PARSER HERE
	tinyxml2::XMLDocument doc;
	tinyxml2::XMLError errorCode = doc.Parse( pMenu, length );

	// http://kokkachiprogramming.wordpress.com/2012/11/23/using-tinyxml2-for-xml-parsing-in-c/
	// attribute= <person sex="female">
	// element= <firstname>Anna</firstname>
	if( errorCode == tinyxml2::XML_NO_ERROR )
	{
       tinyxml2::XMLNode *pNode = doc.FirstChildElement( "MENU" );

		// Is there a child?
		while( pNode )
		{
			tinyxml2::XMLNode *pItem = pNode->FirstChildElement( "ITEM" );
	
			while( pItem )
			{
				HlMenuItems item;

				item.m_alignment = 0;

				BtStrCopy( item.m_id, 64, "unset_id" );

				// Set the default sort order
				item.m_sortOrder = MaxSortOrders-1;

				// Set the default fade
				item.m_fade = 1.0f;

				// We model menu items with a specific resolution in mind. Set this here.
				// Eventually we can pull this from the XML

				item.m_v2OriginalScreenSize = MtVector2( 800.0f, 600.0f );

				// The default for each menu item is that it doesn't matter if it's a joystick or not
				item.m_joystick = HlMenuJoystick_Any;

				item.m_joystickButtonID = JoystickButton_MAX;

				// Find the fade
				tinyxml2::XMLElement *pFade = pItem->FirstChildElement( "FADE" );
				if( pFade )
				{
					const BtChar *pFadeString = pFade->GetText();
					item.m_fade = atof( pFadeString );
				}

				// Get the joystick
				tinyxml2::XMLElement *pJoystickButton = pItem->FirstChildElement( "JOYSTICKBUTTON" );
				if( pJoystickButton )
				{
					const BtChar *pJoystickButtonString = pJoystickButton->GetText();
					if( BtStrCompareNoCase( pJoystickButtonString, "PAUSE" ) )
					{
						item.m_joystickButtonID = JoystickButton_Pause;
					}
					if( BtStrCompareNoCase( pJoystickButtonString, "A" ) )
					{
						item.m_joystickButtonID = JoystickButton_A;
					}
					else if( BtStrCompareNoCase( pJoystickButtonString, "B" ) )
					{
						item.m_joystickButtonID = JoystickButton_B;
					}
					else if( BtStrCompareNoCase( pJoystickButtonString, "Y" ) )
					{
						item.m_joystickButtonID = JoystickButton_Y;
					}
					else if( BtStrCompareNoCase( pJoystickButtonString, "X" ) )
					{
						item.m_joystickButtonID = JoystickButton_X;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "LEFTSHOULDER" ) )
					{
						item.m_joystickButtonID = JoystickButton_LeftShoulder;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "RIGHTSHOULDER" ) )
					{
						item.m_joystickButtonID = JoystickButton_RightShoulder;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "DPADLEFT" ) )
					{
						item.m_joystickButtonID = JoystickButton_Left;
					}
                    else if( BtStrCompareNoCase( pJoystickButtonString, "DPADRIGHT" ) )
					{
						item.m_joystickButtonID = JoystickButton_Right;
					}
				}

				// Get the screen width
				tinyxml2::XMLElement *pScreenWidth = pItem->FirstChildElement( "SCREENWIDTH" );
				if( pScreenWidth )
				{
					const BtChar *pScreenWidthString = pScreenWidth->GetText();
					item.m_v2OriginalScreenSize.x = atoi( pScreenWidthString );
				}
		
				// Get the screen height
				tinyxml2::XMLElement *pScreenHeight = pItem->FirstChildElement( "SCREENHEIGHT" );
				if( pScreenHeight )
				{
					const BtChar *pScreenWidthString = pScreenHeight->GetText();
					item.m_v2OriginalScreenSize.y = atoi( pScreenWidthString );
				}

				// Get the sprite name
				const BtChar *pSpriteName = pItem->FirstChildElement( "SPRITE" )->GetText();
				item.m_pSprite = m_archive.GetSprite( pSpriteName );

				// Get the index
                tinyxml2::XMLElement *pElement = pItem->FirstChildElement( "SORTORDER" );
                if( pElement )
                {
                    const BtChar *sortOrder = pElement->GetText();
                    if( sortOrder )
                    {
                        item.m_sortOrder = atoi(sortOrder);
                    }
                }

				// Get the index 
				const BtChar *index = pItem->FirstChildElement( "INDEX" )->GetText();
				item.m_index = atoi(index);

				// Find the sprite dimension
				item.m_v2OriginalDimension = item.m_pSprite->GetDimension( item.m_index );
							
				// Get the width
                pElement = pItem->FirstChildElement( "WIDTH" );
                if( pElement )
                {
                    const BtChar *widthstring = pElement->GetText();

                    if( widthstring )
                    {
                        item.m_v2OriginalDimension.x = atoi( widthstring );
                    }
                }
				
				// Get the height
                pElement = pItem->FirstChildElement( "HEIGHT" );
                if( pElement )
                {
                    const BtChar *heightstring = pItem->FirstChildElement( "HEIGHT" )->GetText();

                    if( heightstring )
                    {
                        item.m_v2OriginalDimension.y = atoi( heightstring );
                    }
                }
				
				// Get the x 
				const BtChar *xstring = pItem->FirstChildElement( "X" )->GetText();

				// Get the y 
				const BtChar *ystring = pItem->FirstChildElement( "Y" )->GetText();

				BtFloat x, y;

				if( atof( xstring ) == 0 )
				{
					if( BtStrCompareNoCase( xstring, "c" ) )
					{
						item.m_alignment |= HlMenuItemAlignment_HorizontalCentre;
						x = (item.m_v2OriginalScreenSize.x * 0.5f) - (item.m_v2OriginalDimension.x * 0.5f);
					}
					else if( BtStrCompareNoCase( xstring, "l" ) )
					{
						x = 0;
						item.m_alignment |= HlMenuItemAlignment_Left;
					}
					else if( BtStrCompareNoCase( xstring, "r" ) )
					{
						item.m_alignment |= HlMenuItemAlignment_Right;
						x = item.m_v2OriginalScreenSize.x - item.m_v2OriginalDimension.x;
					}
                    else
                    {
                        x = 0;
                    }
				}
				else
				{
					x = atof(xstring);
				}
		
				if (atof(ystring) == 0)
				{
                	if( BtStrCompareNoCase( ystring, "c" ) )
					{
						item.m_alignment |= HlMenuItemAlignment_VerticalCentre;
						y = (item.m_v2OriginalScreenSize.y * 0.5f) - (item.m_v2OriginalDimension.y * 0.5f);
					}
					else if ( BtStrCompareNoCase( ystring, "t") )
					{
						y = 0;
						item.m_alignment |= HlMenuItemAlignment_Top;
					}
					else if ( BtStrCompareNoCase( ystring, "b") )
					{
						y = item.m_v2OriginalScreenSize.y - item.m_v2OriginalDimension.y;
						item.m_alignment |= HlMenuItemAlignment_Bottom;
					}
                    else
                    {
                        y = 0;
                    }
				}
				else
				{
					y = atof(ystring);
				}

				// Set the final position
				item.m_v2OriginalPosition = MtVector2( x, y );

				// Refactor the position
				item.m_v2Position  = HlScreenSize::Refactor( item.m_v2OriginalScreenSize, item.m_v2OriginalPosition );

				// Refactor the size
				item.m_v2Dimension = HlScreenSize::Refactor( item.m_v2OriginalScreenSize, item.m_v2OriginalDimension );

				// Get the ID
				const BtChar *pID = pItem->FirstChildElement( "ID" )->GetText();
				BtStrCopy( item.m_id, 64, pID );

				item.m_isVisible = BtTrue;
				tinyxml2::XMLElement *pIsVisible = pItem->FirstChildElement( "VISIBLE" );
				if( pIsVisible )
				{
					const BtChar *pIsVisibleText = pIsVisible->GetText();

					if( BtStrCompareNoCase( pIsVisibleText, "TRUE" ) )
					{
						item.m_isVisible = BtTrue;
					}
					else if( BtStrCompareNoCase( pIsVisibleText, "FALSE" ) )
					{
						item.m_isVisible = BtFalse;
					}
				}

				// Get the fade when selected
				tinyxml2::XMLElement *pFadeWhenSelected = pItem->FirstChildElement( "FADEWHENSELECTED" );
				if( pFadeWhenSelected )
				{
					const BtChar *pFadeWhenSelectedString = pFadeWhenSelected->GetText();
					item.m_fadeWhenSelected = atof( pFadeWhenSelectedString );
				}
				else
				{
					item.m_fadeWhenSelected = 0.5f;
				}

				// Is this menu item selectable
				item.m_isSelectable = BtFalse;
				tinyxml2::XMLElement *pIsSlectable = pItem->FirstChildElement( "SELECTABLE" );
				if( pIsSlectable )
				{
					const BtChar *pIsSlectableText = pIsSlectable->GetText();

					if( BtStrCompareNoCase( pIsSlectableText, "TRUE" ) )
					{
						item.m_isSelectable = BtTrue;
					}
				}

				// Get whether this is joystick only
				tinyxml2::XMLElement *pJoystickOnly = pItem->FirstChildElement( "JOYSTICK" );
				if( pJoystickOnly )
				{
					const BtChar *pJoystickOnlyText = pJoystickOnly->GetText();

					if( BtStrCompareNoCase( pJoystickOnlyText, "TRUE" ) )
					{
						item.m_joystick = HlMenuJoystick_Yes;
					}
					else
					{
						item.m_joystick = HlMenuJoystick_No;
					}
				}

				// Add each item
				m_items.Add( item );

				// Move to the next child
				pItem = pItem->NextSiblingElement();
			}

			// Move to the next child
			pNode = pNode->NextSiblingElement();
		}
	}
	
	int a=0;
	a++;
}