OSDN Git Service

SDKサンプルを参考にXAudio2でストリーミング再生してみた。
[shooting3/shootinggame.git] / ShootingGame / App.xaml.cpp
1 //
2 // App.xaml.cpp
3 // App.xaml クラスの実装。
4 //
5
6 #include "pch.h"
7 #include "App.xaml.h"
8 #include "MainPage.xaml.h"
9
10 using namespace ShootingGame;
11
12 using namespace Platform;
13 using namespace Windows::ApplicationModel;
14 using namespace Windows::ApplicationModel::Activation;
15 using namespace Windows::ApplicationModel::Core;
16 using namespace Windows::UI::Core;
17 using namespace Windows::UI::Input;
18 using namespace Windows::UI::ViewManagement;
19 using namespace Windows::Foundation;
20 using namespace Windows::Foundation::Collections;
21 using namespace Windows::UI::Xaml;
22 using namespace Windows::UI::Xaml::Controls;
23 using namespace Windows::UI::Xaml::Controls::Primitives;
24 using namespace Windows::UI::Xaml::Data;
25 using namespace Windows::UI::Xaml::Input;
26 using namespace Windows::UI::Xaml::Interop;
27 using namespace Windows::UI::Xaml::Media;
28 using namespace Windows::UI::Xaml::Navigation;
29 using namespace Windows::UI::Xaml::Media::Animation;
30 using namespace Windows::Graphics::Display;
31
32
33 // The Split Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234228
34
35 /// <summary>
36 /// Initializes the singleton application object.  This is the first line of authored code
37 /// executed, and as such is the logical equivalent of main() or WinMain().
38 /// </summary>
39 App::App()
40 {
41         InitializeComponent();
42         Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
43 }
44
45 /// <summary>
46 /// Invoked when the application is launched normally by the end user.  Other entry points
47 /// will be used when the application is launched to open a specific file, to display
48 /// search results, and so forth.
49 /// </summary>
50 /// <param name="args">Details about the launch request and process.</param>
51 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
52 {
53         if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
54         {
55                 //TODO: Load state from previously suspended application
56         }
57
58         auto mainPage = ref new MainPage();
59
60         // Place the frame in the current Window and ensure that it is active
61         Window::Current->Content = mainPage;
62         Window::Current->Activated += ref new WindowActivatedEventHandler(this, &App::OnWindowActivationChanged);
63         Window::Current->Activate();
64
65         gameMain_ = ref new GameMain();
66         gameMain_->Initialize(Window::Current->CoreWindow,mainPage,DisplayProperties::LogicalDpi);
67
68         eventToken_ = 
69                 CompositionTarget::Rendering::add
70                 (ref new EventHandler<Object^>(this, &App::OnRendering));
71
72         ApplicationView::GetForCurrentView()->ViewStateChanged +=
73                 ref new TypedEventHandler<ApplicationView^, ApplicationViewStateChangedEventArgs^>(
74                 this,
75                 &App::OnViewStateChanged
76                 );
77
78         CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
79         CoreApplication::Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
80
81
82         DisplayProperties::LogicalDpiChanged +=
83                 ref new DisplayPropertiesEventHandler(this, &App::OnLogicalDpiChanged);
84
85         CoreWindow^ window = Window::Current->CoreWindow;
86         window->SizeChanged += 
87                 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
88
89         window->PointerPressed +=
90                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerPressed);
91
92         window->PointerReleased +=
93                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased);
94
95         window->PointerMoved +=
96                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved);
97
98
99         timer_ = ref new BasicTimer();
100
101 }
102
103 /// <summary>
104 /// Invoked when application execution is being suspended.  Application state is saved
105 /// without knowing whether the application will be terminated or resumed with the contents
106 /// of memory still intact.
107 /// </summary>
108 /// <param name="sender">The source of the suspend request.</param>
109 /// <param name="e">Details about the suspend request.</param>
110 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
111 {
112         //TODO: Save application state and stop any background activity
113 }
114
115 //----------------------------------------------------------------------
116 void App::OnRendering(
117         _In_ Object^ sender, 
118         _In_ Object^ args
119         )
120 {
121         timer_->Update();
122         gameMain_->Update(timer_->Total,timer_->Delta);
123         gameMain_->Render();
124         gameMain_->Present();
125
126 }
127 //--------------------------------------------------------------------------------------
128 void App::OnWindowSizeChanged(
129         _In_ CoreWindow^ sender,
130         _In_ WindowSizeChangedEventArgs^ args
131         )
132 {
133         gameMain_->UpdateForWindowSizeChange();
134
135 }
136 //--------------------------------------------------------------------------------------
137 void App::OnLogicalDpiChanged(
138         _In_ Object^ sender
139         )
140 {
141         gameMain_->SetDpi(DisplayProperties::LogicalDpi);
142 }
143 //--------------------------------------------------------------------------------------
144 void App::OnWindowActivationChanged(
145         _In_ Platform::Object^ sender,
146         _In_ Windows::UI::Core::WindowActivatedEventArgs^ args
147         )
148 {
149 }
150 //--------------------------------------------------------------------------------------
151 void App::OnResuming(
152         _In_ Platform::Object^ sender,
153         _In_ Platform::Object^ args
154         )
155 {
156 }
157 //--------------------------------------------------------------------------------------
158 void App::OnViewStateChanged(
159         _In_ ApplicationView^ view, 
160         _In_ ApplicationViewStateChangedEventArgs^ args
161         )
162 {
163 }
164
165 void App::OnPointerPressed(
166         _In_ Windows::UI::Core::CoreWindow^ sender,
167         _In_ Windows::UI::Core::PointerEventArgs^ args
168         )
169 {
170 }
171
172 void App::OnPointerReleased(
173         _In_ Windows::UI::Core::CoreWindow^ sender,
174         _In_ Windows::UI::Core::PointerEventArgs^ args
175         )
176 {
177 }
178
179 void App::OnPointerMoved(
180         _In_ Windows::UI::Core::CoreWindow^ sender,
181         _In_ Windows::UI::Core::PointerEventArgs^ args
182         )
183 {
184 }
185