9 using namespace ShootingGame;
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;
33 // 空のアプリケーション テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234227 を参照してください
36 /// 単一アプリケーション オブジェクトを初期化します。これは、実行される作成したコードの
37 /// 最初の行であり、main() または WinMain() と論理的に等価です。
41 InitializeComponent();
42 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
46 /// アプリケーションがエンド ユーザーによって正常に起動されたときに呼び出されます。他のエントリ ポイントは、
47 /// アプリケーションが特定のファイルを開くために呼び出されたときに
48 /// 検索結果やその他の情報を表示するために使用されます。
50 /// <param name="pArgs">Details about the launch request and process.</param>
51 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
53 // Do not repeat app initialization when already running, just ensure that
54 // the window is active
55 if (pArgs->PreviousExecutionState == ApplicationExecutionState::Running)
57 Window::Current->Activate();
61 if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
63 //TODO: 以前中断したアプリケーションから状態を読み込みます。
66 // ナビゲーション コンテキストとして動作するフレームを作成し、最初のページに移動します
67 //auto rootFrame = ref new Frame();
68 //if (!rootFrame->Navigate(TypeName(MainPage::typeid)))
70 // throw ref new FailureException("Failed to create initial page");
72 // mainPage_ = safe_cast<MainPage^>(rootFrame->Content);//ref new MainPage();
73 // Window::Current->Content = rootFrame;
74 // Window::Current->Activate();
78 gameMain_ = ref new GameMain();
80 // フレームを現在のウィンドウに配置し、アクティブであることを確認します
81 mainPage_ = ref new MainPage(gameMain_);
83 gameMain_->Initialize(Window::Current->CoreWindow,mainPage_->SwapChainBackgroundPanel(),DisplayProperties::LogicalDpi);
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();
91 CompositionTarget::Rendering::add
92 (ref new EventHandler<Object^>(this, &App::OnRendering));
94 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
95 Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
98 DisplayProperties::LogicalDpiChanged +=
99 ref new DisplayPropertiesEventHandler(this, &App::OnLogicalDpiChanged);
101 auto window = Window::Current->CoreWindow;
102 window->SizeChanged +=
103 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
105 window->PointerPressed +=
106 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerPressed);
108 window->PointerReleased +=
109 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased);
111 window->PointerMoved +=
112 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved);
115 timer_ = ref new BasicTimer();
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.
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)
128 //TODO: Save application state and stop any background activity
131 //----------------------------------------------------------------------
132 void App::OnRendering(
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;
145 framemax = max(framemax,timer_->Delta);
146 framemin = min(framemin,timer_->Delta);
147 mainPage_->UpdateFrameTime(timer_->Delta,framemax,framemin,delta / count);
152 delta += timer_->Delta;
153 if(count > 10000000.0f)
155 delta = delta / count;
159 mainPage_->UpdateProcessTime(elapsed);
160 gameMain_->Update(timer_->Total,timer_->Delta);
162 gameMain_->Present();
163 elapsed = timer_->Elapsed;
165 //--------------------------------------------------------------------------------------
166 void App::OnWindowSizeChanged(
167 _In_ CoreWindow^ sender,
168 _In_ WindowSizeChangedEventArgs^ args
171 gameMain_->UpdateForWindowSizeChange();
174 //--------------------------------------------------------------------------------------
175 void App::OnLogicalDpiChanged(
179 gameMain_->SetDpi(DisplayProperties::LogicalDpi);
181 //--------------------------------------------------------------------------------------
182 void App::OnWindowActivationChanged(
183 _In_ Platform::Object^ sender,
184 _In_ Windows::UI::Core::WindowActivatedEventArgs^ args
188 //--------------------------------------------------------------------------------------
189 void App::OnResuming(
190 _In_ Platform::Object^ sender,
191 _In_ Platform::Object^ args
196 void App::OnPointerPressed(
197 _In_ Windows::UI::Core::CoreWindow^ sender,
198 _In_ Windows::UI::Core::PointerEventArgs^ args
203 void App::OnPointerReleased(
204 _In_ Windows::UI::Core::CoreWindow^ sender,
205 _In_ Windows::UI::Core::PointerEventArgs^ args
210 void App::OnPointerMoved(
211 _In_ Windows::UI::Core::CoreWindow^ sender,
212 _In_ Windows::UI::Core::PointerEventArgs^ args