-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathScene.cpp
More file actions
51 lines (41 loc) · 1.52 KB
/
Scene.cpp
File metadata and controls
51 lines (41 loc) · 1.52 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
#include "Scene.h"
#include "BufferUtils.h"
#include <iostream>
Scene::Scene(Device* device) : device(device) {
BufferUtils::CreateBuffer(device, sizeof(Time), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, timeBuffer, timeBufferMemory);
vkMapMemory(device->GetVkDevice(), timeBufferMemory, 0, sizeof(Time), 0, &mappedData);
memcpy(mappedData, &time, sizeof(Time));
totalFrames = 0;
}
const std::vector<Model*>& Scene::GetModels() const {
return models;
}
const std::vector<Blades*>& Scene::GetBlades() const {
return blades;
}
void Scene::AddModel(Model* model) {
models.push_back(model);
}
void Scene::AddBlades(Blades* blades) {
this->blades.push_back(blades);
}
void Scene::UpdateTime() {
high_resolution_clock::time_point currentTime = high_resolution_clock::now();
duration<float> nextDeltaTime = duration_cast<duration<float>>(currentTime - startTime);
startTime = currentTime;
time.deltaTime = nextDeltaTime.count();
time.totalTime += time.deltaTime;
++totalFrames;
memcpy(mappedData, &time, sizeof(Time));
}
VkBuffer Scene::GetTimeBuffer() const {
return timeBuffer;
}
Scene::~Scene() {
vkUnmapMemory(device->GetVkDevice(), timeBufferMemory);
vkDestroyBuffer(device->GetVkDevice(), timeBuffer, nullptr);
vkFreeMemory(device->GetVkDevice(), timeBufferMemory, nullptr);
float fps = (float)totalFrames / time.totalTime;
std::cout << fps << std::endl;
//abort(); // To see fps before application exits
}