แสดงบทความที่มีป้ายกำกับ XNA แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ XNA แสดงบทความทั้งหมด

วันพุธที่ 9 พฤษภาคม พ.ศ. 2555

Optimizing Performance for Windows Phone Emulator

Optimizing Performance for Windows Phone Emulator

Several factors affect the performance of Windows Phone Emulator, such as the presence of a graphics processing unit (GPU) and whether hardware-assisted virtualization is enabled.
You cannot precisely simulate the performance of a Windows Phone device, because the performance of the emulator depends partly on factors that do not affect performance on a distinct physical device, such as the current operating system, the CPU, and the available system memory. However, you can achieve compatible performance in most applications by using GPU emulation, and, in some cases, hardware-assisted virtualization.
Important noteImportant Note:
Verify that your development computer meets hardware and available memory requirements. For more information, see Setup and System Requirements for Windows Phone Emulator. The Windows Experience Index in the Control Panel also provides data about computer performance.
GPU emulation is required for the following applications:
  • Game applications that are based on the XNA Framework.
  • Silverlight applications.
  • Applications that use the MultiScaleImage control.
Important noteImportant Note:
Silverlight applications may run without GPU emulation on Windows Phone Emulator, but this scenario is not supported.
Some Silverlight animations such as perspective transforms are processed by the GPU. In these scenarios, the CPU will draw and compose the scene if GPU emulation is not available. For detailed information, see Graphics on Windows Phone.
NoteNote:
GPU emulation requires DirectX. For the required version of DirectX and the WDDM driver, see Setup and System Requirements for Windows Phone Emulator.
You can check whether GPU emulation is available by including the following code in your application:
System.Windows.Interop.Settings.EnableFrameRateCounter = true;
If you set EnableFrameRateCounter to true, and the framerate counter appears as an overlay on the top of the running application, the emulator has GPU access.
To determine whether the computer running the emulator is GPU-enabled, you can check the emulator when it starts. If the arrow to open the application list points to the left, the computer is not GPU-enabled. If the arrow to open the application list points to the right, the computer is GPU-enabled. The following illustration shows an example of the emulator running on a computer that is not GPU-enabled.
Icon that indicates computer is not GPU enabled
The following illustration shows an example of the emulator running on a computer that is GPU-enabled.
Icon that indicates computer is GPU enabled
Hardware-assisted virtualization improves the overall performance of the emulator. If your processor supports hardware-assisted virtualization, you can often improve the performance of tasks that require the CPU, including startup time, by enabling this feature in the BIOS.
If the GPU is not available to process Deep Zoom compositions and Silverlight animations such as perspective transforms, you can improve the performance of these tasks on the CPU by enabling hardware-assisted virtualization. For additional information about animations and GPU caching, see Graphics on Windows Phone.
To determine whether your processor supports hardware-assisted virtualization, run the Hardware-Assisted Virtualization Detection Tool.
For information about configuring hardware-assisted virtualization, see Configure BIOS for Hardware Assisted Virtualization (HAV) PCs.

Using the Project Template that Combines Silverlight and XNA

Using the Project Template that Combines Silverlight and XNA

Starting in Windows Phone OS 7.1, you can combine Silverlight and XNA content in the same application or game. This enables you to add rich text support to your XNA games using Silverlight and enables you to add pages with XNA content to your Silverlight applications. This topic describes the Silverlight and XNA template and how to use it.
When you install the Windows Phone SDK 7.1, the Windows Phone Silverlight and XNA Application template is installed to help you combine Silverlight and XNA content in a single Windows Phone application. The template is available in the New Project dialog box for the Silverlight for Windows Phone or the XNA Game Studio 4.0 categories in both Visual Basic and C#. This template is the same whether you select it from the Silverlight or XNA categories.
This template creates a Silverlight page and a Silverlight page that renders XNA content. This template also provides a way to navigate from the Silverlight page to the page that renders the XNA content.
When you create a new project with this template, the following three projects are created for you in Solution Explorer.
  • Main application project
  • XNA library project
  • XNA library content project
The main application project contains application level files, a Silverlight page, a Silverlight page that renders XNA content, and a button to navigate from the Silverlight page to the XNA content.
FilesPurpose
App.xaml
App.xaml.cs/vb
Contains application-level data, initialization code, and lifecycle code. App.xaml provides a GameTimer and ContentManager at the application level, and contains a SharedGraphicsDeviceManager object. These enable Silverlight and XNA to run in the same application.
MainPage.xaml
MainPage.xaml.cs/vb
Contains Silverlight content and provides the application start-up experience.
GamePage.xaml.cs/vbContains XNA content.
GamePage.xaml can only be used with the UIElementRenderer class, which renders Silverlight content in a XNA game. For more information, see How to: Create Your First XNA Framework Application for Windows Phone.
The XNA library project acts as a bridge between the Silverlight and XNA build systems.
The XNA library content project provides a location for XNA resources, such as sound and image files.
Caution noteCaution:
To debug an application that renders XNA content in the emulator, the computer you are debugging the application on must be GPU-enabled. For more information, see Optimizing Performance for Windows Phone Emulator.
You create the application start-up experience by modifying the MainPage.xaml and MainPage.xaml.cs/vb files. MainPage.xaml contains the standard title text boxes found in other Silverlight for Windows Phone applications and also a button. The code-behind file contains the click event handler for the button that navigates to GamePage.xaml, which is the Silverlight page that renders the XNA content. The following example shows the navigation code.
NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
If you delete the button, you will have to add a way to navigate to the page that renders the XNA content elsewhere in the Silverlight page.
You can add UI elements and controls to MainPage.xaml and code, such as event handlers for UI elements, to MainPage.xaml.cs/vb. For information about the different kinds of controls you can use in Silverlight for Windows Phone applications, see Controls for Windows Phone and Types of Controls QuickStart.
To add additional Silverlight pages to the application, choose the Project menu and then Add New Item.
GamePage.xaml.cs/vb contains the main game loop for your application. Although the navigation URL is to GamePage.xaml, GamePage.xaml contains no XAML content because XNA cannot render XAML. All of the content for GamePage is added in the code-behind file.
You add XNA content to the application by adding resources, such as images and sound files, to the XNA library content project and referencing them in GamePage.xaml.cs/vb. There are several important methods in GamePage.xaml.cs/vb that are added by the template. The following table lists the methods and their purpose. For more information, see How to: Create Your First XNA Framework Application for Windows Phone.
MethodPurpose
GamePage constructorInitializes the game timer that is used to update and draw the page. In addition, this method initializes the ContentManager for the page by setting it to the ContentManager for the application. The constructor is called when the page is first created.
OnNavigatedToSets the SharingMode to true, which enables XNA content to be drawn in a Silverlight application. Initializes a SpriteBatch for the page and starts the game timer. Use this method to load additional content using the ContentManager for the page. This method is called every time the page is navigated to.
OnNavigatedFromSets SharingMode to false. Stops the timer. This method is called every time the page is navigated from.
OnUpdateHandles the Timer.Update event. This method should contain updates to the page, such as gathering input and playing audio files.
OnDrawHandles the Timer.Draw event. This method should contain code for drawing the contents of the page.
In addition to navigating between the Silverlight and XNA pages, you can render Silverlight controls with XNA content using the UIElementRenderer class. For more information about how to do this, see How to: Combine Silverlight and the XNA Framework in a Windows Phone Application.
NoteNote:
You cannot remove the Silverlight UIElement specified in the UIElementRenderer constructor from the visual tree.