This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
/
Main.cpp
174 lines (138 loc) · 4.57 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//--------------------------------------------------------------------------------------
// Main.cpp
//
// Entry point for Xbox One exclusive title.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "CoroutinesXDK.h"
#include "Telemetry.h"
#include <ppltasks.h>
using namespace concurrency;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::UI::Core;
using namespace Windows::Foundation;
using namespace DirectX;
bool g_HDRMode = false;
ref class ViewProvider sealed : public IFrameworkView
{
public:
ViewProvider() :
m_exit(false)
{
}
// IFrameworkView methods
virtual void Initialize(CoreApplicationView^ applicationView)
{
applicationView->Activated +=
ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &ViewProvider::OnActivated);
CoreApplication::Suspending +=
ref new EventHandler<SuspendingEventArgs^>(this, &ViewProvider::OnSuspending);
CoreApplication::Resuming +=
ref new EventHandler<Platform::Object^>(this, &ViewProvider::OnResuming);
CoreApplication::DisableKinectGpuReservation = true;
m_sample = std::make_unique<Sample>();
if (m_sample->RequestHDRMode())
{
// Request HDR mode.
auto determineHDR = Concurrency::create_task(
Windows::Xbox::Graphics::Display::DisplayConfiguration::TrySetHdrModeAsync()
);
// In a real game, you'd do some initialization here to hide the HDR mode switch.
// Finish up HDR mode detection (waiting for async if needed)
g_HDRMode = determineHDR.get()->HdrEnabled;
#ifdef _DEBUG
OutputDebugStringA((g_HDRMode) ? "INFO: Display in HDR Mode\n" : "INFO: Display in SDR Mode\n");
#endif
}
// Sample Usage Telemetry
//
// Disable or remove this code block to opt-out of sample usage telemetry
//
if (EventRegisterATGSampleTelemetry() == ERROR_SUCCESS)
{
wchar_t exePath[MAX_PATH + 1] = {};
if (!GetModuleFileNameW(nullptr, exePath, MAX_PATH))
{
wcscpy_s(exePath, L"Unknown");
}
EventWriteSampleLoaded(exePath);
}
}
virtual void Uninitialize()
{
m_sample.reset();
}
virtual void SetWindow(CoreWindow^ window)
{
window->Closed +=
ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &ViewProvider::OnWindowClosed);
// Default window thread to CPU 0
SetThreadAffinityMask(GetCurrentThread(), 0x1);
m_sample->Initialize(reinterpret_cast<IUnknown*>(window));
}
virtual void Load(Platform::String^ entryPoint)
{
}
virtual void Run()
{
while (!m_exit)
{
m_sample->Tick();
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
}
}
protected:
// Event handlers
void OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
CoreWindow::GetForCurrentThread()->Activate();
}
void OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
{
auto deferral = args->SuspendingOperation->GetDeferral();
create_task([this, deferral]()
{
m_sample->OnSuspending();
deferral->Complete();
});
}
void OnResuming(Platform::Object^ sender, Platform::Object^ args)
{
m_sample->OnResuming();
}
void OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
{
m_exit = true;
}
private:
bool m_exit;
std::unique_ptr<Sample> m_sample;
};
ref class ViewProviderFactory : IFrameworkViewSource
{
public:
virtual IFrameworkView^ CreateView()
{
return ref new ViewProvider();
}
};
// Entry point
[Platform::MTAThread]
int __cdecl main(Platform::Array<Platform::String^>^ /*argv*/)
{
// Default main thread to CPU 0
SetThreadAffinityMask(GetCurrentThread(), 0x1);
auto viewProviderFactory = ref new ViewProviderFactory();
CoreApplication::Run(viewProviderFactory);
return 0;
}
// Exit helper
void ExitSample() noexcept
{
Windows::ApplicationModel::Core::CoreApplication::Exit();
}