forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
171 lines (135 loc) · 4.54 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
//--------------------------------------------------------------------------------------
// Main.cpp
//
// Entry point for Xbox One exclusive title.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "SimpleTriangle12.h"
#include "Telemetry.h"
using namespace winrt::Windows::ApplicationModel;
using namespace winrt::Windows::ApplicationModel::Core;
using namespace winrt::Windows::ApplicationModel::Activation;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::Foundation;
using namespace DirectX;
bool g_HDRMode = false;
class ViewProvider final : public winrt::implements<ViewProvider, IFrameworkView>
{
public:
ViewProvider() :
m_exit(false)
{
}
// IFrameworkView methods
void Initialize(CoreApplicationView const & applicationView)
{
applicationView.Activated({ this, &ViewProvider::OnActivated });
CoreApplication::Suspending({ this, &ViewProvider::OnSuspending });
CoreApplication::Resuming({ this, &ViewProvider::OnResuming });
CoreApplication::DisableKinectGpuReservation(true);
m_sample = std::make_unique<Sample>();
if (m_sample->RequestHDRMode())
{
// Request HDR mode.
auto determineHDR = winrt::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
while (determineHDR.Status() == AsyncStatus::Started) { Sleep(100); };
if (determineHDR.Status() != AsyncStatus::Completed)
{
throw std::exception("TrySetHdrModeAsync");
}
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);
}
}
void Uninitialize()
{
m_sample.reset();
}
void SetWindow(CoreWindow const & window)
{
window.Closed({ this, &ViewProvider::OnWindowClosed });
// Default window thread to CPU 0
SetThreadAffinityMask(GetCurrentThread(), 0x1);
auto windowPtr = static_cast<::IUnknown*>(winrt::get_abi(window));
m_sample->Initialize(windowPtr);
}
void Load(winrt::hstring const & /*entryPoint*/)
{
}
void Run()
{
while (!m_exit)
{
m_sample->Tick();
CoreWindow::GetForCurrentThread().Dispatcher().ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
}
}
protected:
// Event handlers
void OnActivated(CoreApplicationView const & /*applicationView*/, IActivatedEventArgs const & /*args*/)
{
CoreWindow::GetForCurrentThread().Activate();
}
void OnSuspending(IInspectable const & /*sender*/, SuspendingEventArgs const & args)
{
auto deferral = args.SuspendingOperation().GetDeferral();
auto f = std::async(std::launch::async, [this, deferral]()
{
m_sample->OnSuspending();
deferral.Complete();
});
}
void OnResuming(IInspectable const & /*sender*/, IInspectable const & /*args*/)
{
m_sample->OnResuming();
}
void OnWindowClosed(CoreWindow const & /*sender*/, CoreWindowEventArgs const & /*args*/)
{
m_exit = true;
}
private:
bool m_exit;
std::unique_ptr<Sample> m_sample;
};
class ViewProviderFactory final : public winrt::implements<ViewProviderFactory, IFrameworkViewSource>
{
public:
IFrameworkView CreateView()
{
return winrt::make<ViewProvider>();
}
};
// Entry point
int WINAPIV WinMain()
{
winrt::init_apartment();
ViewProviderFactory viewProviderFactory;
CoreApplication::Run(viewProviderFactory);
winrt::uninit_apartment();
return 0;
}
// Exit helper
void ExitSample()
{
winrt::Windows::ApplicationModel::Core::CoreApplication::Exit();
}