OSDN Git Service

Boost.MSMでメニュー部分を実装
[shooting3/shootinggame.git] / ShootingGame / App.xaml.cpp
1 //
2 // App.xaml.cpp
3 // App クラスの実装。
4 //
5
6 #include "pch.h"
7 #include "App.xaml.h"
8
9 using namespace ShootingGame;
10
11 using namespace Platform;
12 using namespace concurrency;
13 using namespace DirectX;
14 using namespace Windows::ApplicationModel;
15 using namespace Windows::ApplicationModel::Activation;
16 using namespace Windows::ApplicationModel::Core;
17 using namespace Windows::ApplicationModel::Store;
18 using namespace Windows::Foundation;
19 using namespace Windows::Foundation::Collections;
20 using namespace Windows::Graphics::Display;
21 using namespace Windows::UI::Core;
22 using namespace Windows::UI::Input;
23 using namespace Windows::UI::ViewManagement;
24 using namespace Windows::UI::Xaml;
25 using namespace Windows::UI::Xaml::Controls;
26 using namespace Windows::UI::Xaml::Controls::Primitives;
27 using namespace Windows::UI::Xaml::Data;
28 using namespace Windows::UI::Xaml::Input;
29 using namespace Windows::UI::Xaml::Interop;
30 using namespace Windows::UI::Xaml::Media;
31 using namespace Windows::UI::Xaml::Navigation;
32
33 // 空のアプリケーション テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234227 を参照してください
34
35 /// <summary>
36 /// 単一アプリケーション オブジェクトを初期化します。これは、実行される作成したコードの
37 /// 最初の行であり、main() または WinMain() と論理的に等価です。
38 /// </summary>
39 App::App()
40 {
41         InitializeComponent();
42         Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
43 }
44
45 /// <summary>
46 /// アプリケーションがエンド ユーザーによって正常に起動されたときに呼び出されます。他のエントリ ポイントは、
47 /// アプリケーションが特定のファイルを開くために呼び出されたときに
48 /// 検索結果やその他の情報を表示するために使用されます。
49 /// </summary>
50 /// <param name="pArgs">Details about the launch request and process.</param>
51 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
52 {
53         // Do not repeat app initialization when already running, just ensure that
54         // the window is active
55         if (pArgs->PreviousExecutionState == ApplicationExecutionState::Running)
56         {
57                 Window::Current->Activate();
58                 return;
59         }
60
61         if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
62         {
63                 //TODO: 以前中断したアプリケーションから状態を読み込みます。
64         }
65
66         // ナビゲーション コンテキストとして動作するフレームを作成し、最初のページに移動します
67         //auto rootFrame = ref new Frame();
68         //if (!rootFrame->Navigate(TypeName(MainPage::typeid)))
69         //{
70         //      throw ref new FailureException("Failed to create initial page");
71         //}
72 //      mainPage_ = safe_cast<MainPage^>(rootFrame->Content);//ref new MainPage();
73 //  Window::Current->Content = rootFrame;
74 //      Window::Current->Activate();
75
76
77   //state_;
78   gameMain_ = ref new GameMain();
79
80         // フレームを現在のウィンドウに配置し、アクティブであることを確認します
81         mainPage_ = ref new MainPage(gameMain_);
82
83   gameMain_->Initialize(Window::Current->CoreWindow,mainPage_->SwapChainBackgroundPanel(),DisplayProperties::LogicalDpi);
84
85         // Place the frame in the current Window and ensure that it is active
86         Window::Current->Content = mainPage_;
87         Window::Current->Activated += ref new WindowActivatedEventHandler(this, &App::OnWindowActivationChanged);
88         Window::Current->Activate();
89
90         eventToken_ = 
91                 CompositionTarget::Rendering::add
92                 (ref new EventHandler<Object^>(this, &App::OnRendering));
93
94   Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
95         Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
96
97
98         DisplayProperties::LogicalDpiChanged +=
99                 ref new DisplayPropertiesEventHandler(this, &App::OnLogicalDpiChanged);
100
101         auto window = Window::Current->CoreWindow;
102         window->SizeChanged += 
103                 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
104
105         window->PointerPressed +=
106                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerPressed);
107
108         window->PointerReleased +=
109                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased);
110
111         window->PointerMoved +=
112                 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved);
113
114
115         timer_ = ref new BasicTimer();
116
117 }
118
119 /// <summary>
120 /// Invoked when application execution is being suspended.  Application state is saved
121 /// without knowing whether the application will be terminated or resumed with the contents
122 /// of memory still intact.
123 /// </summary>
124 /// <param name="sender">The source of the suspend request.</param>
125 /// <param name="e">Details about the suspend request.</param>
126 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
127 {
128         //TODO: Save application state and stop any background activity
129 }
130
131 //----------------------------------------------------------------------
132 void App::OnRendering(
133         _In_ Object^ sender, 
134         _In_ Object^ args
135         )
136 {
137         static bool first = true;
138         static float count = 1.0f;
139         static float elapsed = 1.0f / 60.0f;
140         static float framemax = -1.0f;
141         static float framemin = 1000000.0f;
142         static float delta = 1.0f / 60.0f;
143         timer_->Update();
144         if(!first){
145                 framemax = max(framemax,timer_->Delta);
146                 framemin = min(framemin,timer_->Delta);
147                 mainPage_->UpdateFrameTime(timer_->Delta,framemax,framemin,delta / count);
148         } else {
149                 first = false;
150         }
151         count += 1.0f;
152         delta += timer_->Delta;
153         if(count > 10000000.0f)
154         {
155                 delta = delta / count;
156                 count = 1.0f;
157         }
158
159         mainPage_->UpdateProcessTime(elapsed);
160         gameMain_->Update(timer_->Total,timer_->Delta);
161         gameMain_->Render();
162         gameMain_->Present();
163         elapsed = timer_->Elapsed;
164 }
165 //--------------------------------------------------------------------------------------
166 void App::OnWindowSizeChanged(
167         _In_ CoreWindow^ sender,
168         _In_ WindowSizeChangedEventArgs^ args
169         )
170 {
171         gameMain_->UpdateForWindowSizeChange();
172
173 }
174 //--------------------------------------------------------------------------------------
175 void App::OnLogicalDpiChanged(
176         _In_ Object^ sender
177         )
178 {
179         gameMain_->SetDpi(DisplayProperties::LogicalDpi);
180 }
181 //--------------------------------------------------------------------------------------
182 void App::OnWindowActivationChanged(
183         _In_ Platform::Object^ sender,
184         _In_ Windows::UI::Core::WindowActivatedEventArgs^ args
185         )
186 {
187 }
188 //--------------------------------------------------------------------------------------
189 void App::OnResuming(
190         _In_ Platform::Object^ sender,
191         _In_ Platform::Object^ args
192         )
193 {
194 }
195
196 void App::OnPointerPressed(
197         _In_ Windows::UI::Core::CoreWindow^ sender,
198         _In_ Windows::UI::Core::PointerEventArgs^ args
199         )
200 {
201 }
202
203 void App::OnPointerReleased(
204         _In_ Windows::UI::Core::CoreWindow^ sender,
205         _In_ Windows::UI::Core::PointerEventArgs^ args
206         )
207 {
208 }
209
210 void App::OnPointerMoved(
211         _In_ Windows::UI::Core::CoreWindow^ sender,
212         _In_ Windows::UI::Core::PointerEventArgs^ args
213         )
214 {
215 }