7 #include "MainPage.xaml.h"
10 using namespace ShootingGame;
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;
33 // The Split Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234228
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().
41 InitializeComponent();
42 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
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.
50 /// <param name="args">Details about the launch request and process.</param>
51 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
53 if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)
55 //TODO: Load state from previously suspended application
58 mainPage_ = ref new MainPage();
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();
65 gameMain_ = ref new GameMain();
66 gameMain_->Initialize(Window::Current->CoreWindow,mainPage_,DisplayProperties::LogicalDpi);
69 CompositionTarget::Rendering::add
70 (ref new EventHandler<Object^>(this, &App::OnRendering));
72 CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
73 CoreApplication::Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
76 DisplayProperties::LogicalDpiChanged +=
77 ref new DisplayPropertiesEventHandler(this, &App::OnLogicalDpiChanged);
79 CoreWindow^ window = Window::Current->CoreWindow;
80 window->SizeChanged +=
81 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
83 window->PointerPressed +=
84 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerPressed);
86 window->PointerReleased +=
87 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerReleased);
89 window->PointerMoved +=
90 ref new TypedEventHandler<CoreWindow^, Windows::UI::Core::PointerEventArgs^>(this, &App::OnPointerMoved);
93 timer_ = ref new BasicTimer();
98 /// Invoked when application execution is being suspended. Application state is saved
99 /// without knowing whether the application will be terminated or resumed with the contents
100 /// of memory still intact.
102 /// <param name="sender">The source of the suspend request.</param>
103 /// <param name="e">Details about the suspend request.</param>
104 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
106 //TODO: Save application state and stop any background activity
109 //----------------------------------------------------------------------
110 void App::OnRendering(
115 static bool first = true;
116 static float count = 1.0f;
117 static float elapsed = 1.0f / 60.0f;
118 static float framemax = -1.0f;
119 static float framemin = 1000000.0f;
120 static float delta = 1.0f / 60.0f;
123 framemax = max(framemax,timer_->Delta);
124 framemin = min(framemin,timer_->Delta);
125 mainPage_->UpdateFrameTime(timer_->Delta,framemax,framemin,delta / count);
130 delta += timer_->Delta;
131 if(count > 10000000.0f)
133 delta = delta / count;
137 mainPage_->UpdateProcessTime(elapsed);
138 gameMain_->Update(timer_->Total,timer_->Delta);
140 gameMain_->Present();
141 elapsed = timer_->Elapsed;
143 //--------------------------------------------------------------------------------------
144 void App::OnWindowSizeChanged(
145 _In_ CoreWindow^ sender,
146 _In_ WindowSizeChangedEventArgs^ args
149 gameMain_->UpdateForWindowSizeChange();
152 //--------------------------------------------------------------------------------------
153 void App::OnLogicalDpiChanged(
157 gameMain_->SetDpi(DisplayProperties::LogicalDpi);
159 //--------------------------------------------------------------------------------------
160 void App::OnWindowActivationChanged(
161 _In_ Platform::Object^ sender,
162 _In_ Windows::UI::Core::WindowActivatedEventArgs^ args
166 //--------------------------------------------------------------------------------------
167 void App::OnResuming(
168 _In_ Platform::Object^ sender,
169 _In_ Platform::Object^ args
174 void App::OnPointerPressed(
175 _In_ Windows::UI::Core::CoreWindow^ sender,
176 _In_ Windows::UI::Core::PointerEventArgs^ args
181 void App::OnPointerReleased(
182 _In_ Windows::UI::Core::CoreWindow^ sender,
183 _In_ Windows::UI::Core::PointerEventArgs^ args
188 void App::OnPointerMoved(
189 _In_ Windows::UI::Core::CoreWindow^ sender,
190 _In_ Windows::UI::Core::PointerEventArgs^ args