-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (46 loc) · 1.99 KB
/
main.cpp
File metadata and controls
56 lines (46 loc) · 1.99 KB
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
#include "common/MediaLayer.h"
#include "common/Rendering/ForwardRenderer.h"
#include "FreeImage.h"
#include "assignment1/Assignment1.h"
#include "assignment2/Assignment2.h"
#include "assignment3/Assignment3.h"
#include "assignment4/Assignment4.h"
#include "assignment5/Assignment5.h"
// Change this line to switch between the assignments
#define APPLICATION Assignment2
// For example:
// #define APPLICATION Assignment2
// #define APPLICATION Assignment3
// #define APPLICATION Assignment4
// #define APPLICATION Assignment5
#include <iostream>
#include <chrono>
int main(int argc, char** argv) {
FreeImage_Initialise();
std::unique_ptr<Application> app = APPLICATION::CreateApplication(APPLICATION::CreateScene(), APPLICATION::CreateCamera());
if (!app) {
std::cerr << "ERROR: Created application is not valid." << std::endl;
return 1;
}
// The renderer depends on the camera and the scene generated by the application.
// Make sure those are initialized first before continuing.
std::unique_ptr<Renderer> renderer = app->CreateRenderer();
if (!renderer) {
std::cerr << "ERROR: Created renderer is not valid." << std::endl;
return 1;
}
MediaLayer media(std::move(app), std::move(renderer));
// NOTE: 'app' is no longer a valid pointer here. Make sure you do any initialization for your Application before
// the MediaLayer is constructed.
auto lastTickTime = std::chrono::high_resolution_clock::now();
auto startTickTime = lastTickTime;
while (media.CanTick()) {
auto currentTickTime = std::chrono::high_resolution_clock::now();
auto deltaTime = std::chrono::duration_cast<std::chrono::duration<double>>(currentTickTime - lastTickTime);
auto totalElapsedTime = std::chrono::duration_cast<std::chrono::duration<double>>(currentTickTime - startTickTime);
media.Tick(deltaTime.count(), totalElapsedTime.count());
lastTickTime = currentTickTime;
}
FreeImage_DeInitialise();
return 0;
}