More timing functions

This commit is contained in:
David 2021-08-28 01:04:31 +02:00
commit 321c677da2
12 changed files with 184 additions and 129 deletions

View file

@ -2,6 +2,7 @@
#define HITTABLE_LIST_H
#include "hittable.hpp"
#include "sphere.hpp"
#include <memory>
#include <vector>
@ -9,30 +10,34 @@
using std::shared_ptr;
using std::make_shared;
struct hittable_list : hittable {
template <typename T = sphere>
struct hittable_list {
/* Attributes */
std::vector<shared_ptr<hittable>> objects;
std::vector<T> objects;
/* Constructors */
hittable_list () {}
hittable_list(shared_ptr<hittable> h) { add(h); }
hittable_list(T object) { add(object); }
/* Methods */
void clear() { objects.clear(); }
void add (shared_ptr<hittable> h) { objects.push_back(h); }
void add (T h) { objects.push_back(h); }
virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const override;
bool hit(const ray& r, float t_min, float t_max, hit_record& rec);
};
bool hittable_list::hit(const ray& r, double t_min, double t_max, hit_record& rec) const
template <typename T>
bool hittable_list<T>::hit(const ray& r, float t_min, float t_max, hit_record& rec)
{
rmt_ScopedCPUSample(HittableList_Hit, RMTSF_Aggregate);
hit_record temp_rec;
bool hit_anything = false;
double closest_so_far = t_max;
float closest_so_far = t_max;
for (const auto& object : objects)
for (uint32_t i = 0; i < objects.size(); ++i)
{
T *object = &objects[i];
if (object->hit(r, t_min, closest_so_far, temp_rec))
{
hit_anything = true;