-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPebbleMain.cpp
92 lines (77 loc) · 2.83 KB
/
PebbleMain.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
#include "pch.h"
#include "PebbleMain.h"
#include "Common\DirectXHelper.h"
using namespace Pebble;
using namespace Windows::Foundation;
using namespace Windows::System::Threading;
using namespace Concurrency;
// The DirectX 12 Application template is documented at https://go.microsoft.com/fwlink/?LinkID=613670&clcid=0x409
// Loads and initializes application assets when the application is loaded.
PebbleMain::PebbleMain()
{
// TODO: Change the timer settings if you want something other than the default variable timestep mode.
// e.g. for 60 FPS fixed timestep update logic, call:
/*
m_timer.SetFixedTimeStep(true);
m_timer.SetTargetElapsedSeconds(1.0 / 60);
*/
}
// Creates and initializes the renderers.
void PebbleMain::CreateRenderers(const std::shared_ptr<DX::DeviceResources>& deviceResources)
{
// TODO: Replace this with your app's content initialization.
m_sceneRenderer = std::unique_ptr<Sample3DSceneRenderer>(new Sample3DSceneRenderer(deviceResources));
OnWindowSizeChanged();
}
// Updates the application state once per frame.
void PebbleMain::Update()
{
// Update scene objects.
m_timer.Tick([&]()
{
// TODO: Replace this with your app's content update functions.
m_sceneRenderer->Update(m_timer);
});
}
// Renders the current frame according to the current application state.
// Returns true if the frame was rendered and is ready to be displayed.
bool PebbleMain::Render()
{
// Don't try to render anything before the first Update.
if (m_timer.GetFrameCount() == 0)
{
return false;
}
// Render the scene objects.
// TODO: Replace this with your app's content rendering functions.
return m_sceneRenderer->Render();
}
// Updates application state when the window's size changes (e.g. device orientation change)
void PebbleMain::OnWindowSizeChanged()
{
// TODO: Replace this with the size-dependent initialization of your app's content.
m_sceneRenderer->CreateWindowSizeDependentResources();
}
// Notifies the app that it is being suspended.
void PebbleMain::OnSuspending()
{
// TODO: Replace this with your app's suspending logic.
// Process lifetime management may terminate suspended apps at any time, so it is
// good practice to save any state that will allow the app to restart where it left off.
m_sceneRenderer->SaveState();
// If your application uses video memory allocations that are easy to re-create,
// consider releasing that memory to make it available to other applications.
}
// Notifes the app that it is no longer suspended.
void PebbleMain::OnResuming()
{
// TODO: Replace this with your app's resuming logic.
}
// Notifies renderers that device resources need to be released.
void PebbleMain::OnDeviceRemoved()
{
// TODO: Save any necessary application or renderer state and release the renderer
// and its resources which are no longer valid.
m_sceneRenderer->SaveState();
m_sceneRenderer = nullptr;
}