Beispiel #1
0
bool ds::StringTable::Open( const ds::String& Filename, ds::String& Language )
{
	BoostXmlTree Tree;

	try
	{
		boost::property_tree::read_xml( Filename, Tree );
	}
	catch( const std::exception& e )
	{
		dsPushError( "%s", e.what( ) );
		return false;
	}

	Tree = Tree.get_child( "translate" );

	if( Language.empty( ) )
		Language = Tree.get< ds::String >( "<xmlattr>.default", "eng" );

	for( auto It = Tree.begin( ); It != Tree.end( ); It++ )
		if( It->first == "lang" && It->second.get< ds::String >( "<xmlattr>.id" ) == Language )
			for( auto Line = It->second.begin( ); Line != It->second.end( ); Line++ )
				if( Line->first == "string" )
				{
					ds::String Text = ds::String( Line->second.data( ).begin( ), Line->second.data( ).end( ) );
					for ( unsigned i = 0; i < Text.size( ); i++ )
					{
						if( ( int)Text[ i ] == 92 )
							Text[ i ] = '\n';
					}
					Set( Line->second.get< ds::String >( "<xmlattr>.id", ""), Text );
				}

	return true;
}
Beispiel #2
0
bool ds::Render::Create( HWND Handle, const ds::String& BasicEffect )
{
	g_SwapChain.OutputWindow = Handle;

	RECT Rect;
	GetClientRect(  Handle, &Rect  );
	g_SwapChain.BufferDesc.Width = (  unsigned  ) Rect.right - (  unsigned  ) Rect.left;
	g_SwapChain.BufferDesc.Height = (  unsigned  ) Rect.bottom - (  unsigned  ) Rect.top;

	for( unsigned i = 0; i < 2; i++ )
	{
		if( SUCCEEDED( D3D10CreateDeviceAndSwapChain( 
			nullptr,
			( D3D10_DRIVER_TYPE )i, 
			nullptr,
			0,
			D3D10_SDK_VERSION,
			&g_SwapChain,
			&Swap,
			&Device
			 ) ) )
		{
			if( ( D3D10_DRIVER_TYPE )i == D3D10_DRIVER_TYPE_REFERENCE )
				dsPushMessage( ErrRenderCreateDevice );
			break;
		}
	}

	if( !Device )
	{
		dsPushErrorStatic( ErrRenderCreateDevice );
		return false;
	}

	IDXGIOutput* l_Info;
	unsigned l_ModesCount = 0;
	Swap->GetContainingOutput( &l_Info );
	l_Info->GetDisplayModeList( g_SwapChain.BufferDesc.Format,
		0, &l_ModesCount, nullptr );

	DXGI_MODE_DESC* l_Modes = new DXGI_MODE_DESC[l_ModesCount];
	l_Info->GetDisplayModeList( g_SwapChain.BufferDesc.Format,
		0, &l_ModesCount, l_Modes );	

	for( unsigned i = 0; i < l_ModesCount; i++ )
		VideoModes.push_back( VideoMode( ds::Size( l_Modes[i].Width, l_Modes[i].Height ), l_Modes[i].RefreshRate.Numerator / l_Modes[i].RefreshRate.Denominator ) );

	delete[] l_Modes;
	l_Info->Release( );

	ID3D10Texture2D* l_BackBuffer = nullptr;
	if( FAILED( Swap->GetBuffer( 0, __uuidof( ID3D10Texture2D ), ( LPVOID* )&l_BackBuffer ) ) )
		return false;

	if( FAILED( Device->CreateRenderTargetView( l_BackBuffer, nullptr, &RenderTargetView ) ) )
		return false;

	l_BackBuffer->Release( );

	CreateDepthBuffer( ds::Size( 
		g_SwapChain.BufferDesc.Width,
		g_SwapChain.BufferDesc.Height
		 ) );

	Device->OMSetRenderTargets( 1, &RenderTargetView, DepthBufferEnable ? DepthStencilView : nullptr );
	Device->RSSetViewports( 1, &g_ViewPort );

	SetRenderRect( v4<unsigned>( 0, 0, 
		g_SwapChain.BufferDesc.Width,
		g_SwapChain.BufferDesc.Height ) );

	if( !BasicEffect.empty( ) )
		Effect = new ds::BasicEffect( BasicEffect, "Render" );
	else
		Effect = nullptr;

	SetRenderMode( 1 );

	SetView( v2<unsigned>( 
		g_SwapChain.BufferDesc.Width, g_SwapChain.BufferDesc.Height ), 
		v2<unsigned>( g_ViewPort.TopLeftX, g_ViewPort.TopLeftY ),
		g_ViewPort.MinDepth, g_ViewPort.MaxDepth );
	
	ds::Clock::Reset( );

	return true;
}