OSDN Git Service

サウンド再生を別スレッドにしてみた。
[shooting3/shootinggame.git] / ShootingGame / App.xaml.cpp
1 //
2 // App.xaml.cpp
3 // App.xaml クラスの実装。
4 //
5
6 #include "pch.h"
7 #include "MainPage.xaml.h"
8 #include "App.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
46 /// <summary>
47 /// Invoked when the application is launched normally by the end user.  Other entry points
48 /// will be used when the application is launched to open a specific file, to display
49 /// search results, and so forth.
50 /// </summary>
51 /// <param name="args">Details about the launch request and process.</param>
52 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
53 {
54         if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
55         {
56                 //TODO: Load state from previously suspended application
57         }
58
59         mainPage_ = ref new MainPage();
60
61         // Place the frame in the current Window and ensure that it is active
62         Window::Current->Content = mainPage_;
63         Window::Current->Activated += ref new WindowActivatedEventHandler(this, &App::OnWindowActivationChanged);
64         Window::Current->Activate();
65
66         gameMain_ = ref new GameMain();
67         gameMain_->Initialize(Window::Current->CoreWindow,mainPage_,DisplayProperties::LogicalDpi);
68
69         eventToken_ = 
70                 CompositionTarget::Rendering::add
71                 (ref new EventHandler<Object^>(this, &App::OnRendering));
72
73         ApplicationView::GetForCurrentView()->ViewStateChanged +=
74                 ref new TypedEventHandler<ApplicationView^, ApplicationViewStateChangedEventArgs^>(
75                 this,
76                 &App::OnViewStateChanged
77                 );
78
79         CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
80         CoreApplication::Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
81
82
83         DisplayProperties::LogicalDpiChanged +=
84                 ref new DisplayPropertiesEventHandler(this, &App::OnLogicalDpiChanged);
85
86         CoreWindow^ window = Window::Current->CoreWindow;
87         window->SizeChanged += 
88                 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
89
90         window->PointerPressed +=
91                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerPressed);
92
93         window->PointerReleased +=
94                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased);
95
96         window->PointerMoved +=
97                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved);
98
99
100         timer_ = ref new BasicTimer();
101
102 }
103
104 /// <summary>
105 /// Invoked when application execution is being suspended.  Application state is saved
106 /// without knowing whether the application will be terminated or resumed with the contents
107 /// of memory still intact.
108 /// </summary>
109 /// <param name="sender">The source of the suspend request.</param>
110 /// <param name="e">Details about the suspend request.</param>
111 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
112 {
113         //TODO: Save application state and stop any background activity
114 }
115
116 //----------------------------------------------------------------------
117 void App::OnRendering(
118         _In_ Object^ sender, 
119         _In_ Object^ args
120         )
121 {
122         static bool first = true;
123         static float count = 1.0f;
124         static float elapsed = 1.0f / 60.0f;
125         static float framemax = -1.0f;
126         static float framemin = 1000000.0f;
127         static float delta = 1.0f / 60.0f;
128         timer_->Update();
129         if(!first){
130                 framemax = max(framemax,timer_->Delta);
131                 framemin = min(framemin,timer_->Delta);
132                 mainPage_->UpdateFrameTime(timer_->Delta,framemax,framemin,delta / count);
133         } else {
134                 first = false;
135         }
136         count += 1.0f;
137         delta += timer_->Delta;
138         if(count > 10000000.0f)
139         {
140                 delta = delta / count;
141                 count = 1.0f;
142         }
143
144         mainPage_->UpdateProcessTime(elapsed);
145         gameMain_->Update(timer_->Total,timer_->Delta);
146         gameMain_->Render();
147         gameMain_->Present();
148         elapsed = timer_->Elapsed;
149 }
150 //--------------------------------------------------------------------------------------
151 void App::OnWindowSizeChanged(
152         _In_ CoreWindow^ sender,
153         _In_ WindowSizeChangedEventArgs^ args
154         )
155 {
156         gameMain_->UpdateForWindowSizeChange();
157
158 }
159 //--------------------------------------------------------------------------------------
160 void App::OnLogicalDpiChanged(
161         _In_ Object^ sender
162         )
163 {
164         gameMain_->SetDpi(DisplayProperties::LogicalDpi);
165 }
166 //--------------------------------------------------------------------------------------
167 void App::OnWindowActivationChanged(
168         _In_ Platform::Object^ sender,
169         _In_ Windows::UI::Core::WindowActivatedEventArgs^ args
170         )
171 {
172 }
173 //--------------------------------------------------------------------------------------
174 void App::OnResuming(
175         _In_ Platform::Object^ sender,
176         _In_ Platform::Object^ args
177         )
178 {
179 }
180 //--------------------------------------------------------------------------------------
181 void App::OnViewStateChanged(
182         _In_ ApplicationView^ view, 
183         _In_ ApplicationViewStateChangedEventArgs^ args
184         )
185 {
186 }
187
188 void App::OnPointerPressed(
189         _In_ Windows::UI::Core::CoreWindow^ sender,
190         _In_ Windows::UI::Core::PointerEventArgs^ args
191         )
192 {
193 }
194
195 void App::OnPointerReleased(
196         _In_ Windows::UI::Core::CoreWindow^ sender,
197         _In_ Windows::UI::Core::PointerEventArgs^ args
198         )
199 {
200 }
201
202 void App::OnPointerMoved(
203         _In_ Windows::UI::Core::CoreWindow^ sender,
204         _In_ Windows::UI::Core::PointerEventArgs^ args
205         )
206 {
207 }
208