Clearing up some memory to prevent stupid issues
Preparing for some optimisations. (absolutely need to reduce the ammount of allocations done.)
This commit is contained in:
@@ -21,6 +21,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
Intersect();
|
Intersect();
|
||||||
~Intersect();
|
~Intersect();
|
||||||
|
void reset();
|
||||||
void add(Intersection i);
|
void add(Intersection i);
|
||||||
int count() { return this->num; };
|
int count() { return this->num; };
|
||||||
Intersection operator[](const int p) { return *this->list[p]; }
|
Intersection operator[](const int p) { return *this->list[p]; }
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ public:
|
|||||||
if (p == nullptr) { return; }
|
if (p == nullptr) { return; }
|
||||||
|
|
||||||
/* clear up the list */
|
/* clear up the list */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ChainList *next = p->next;
|
||||||
|
free(p);
|
||||||
|
p = next;
|
||||||
|
}
|
||||||
|
while(p != nullptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape *last()
|
Shape *last()
|
||||||
|
|||||||
@@ -31,10 +31,20 @@ Intersect::Intersect()
|
|||||||
|
|
||||||
Intersect::~Intersect()
|
Intersect::~Intersect()
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < this->num; i++)
|
||||||
|
{
|
||||||
|
free(this->list[i]);
|
||||||
|
}
|
||||||
/* Free stuff */
|
/* Free stuff */
|
||||||
free(this->list);
|
free(this->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Intersect::reset()
|
||||||
|
{
|
||||||
|
this->num = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Intersect::add(Intersection i)
|
void Intersect::add(Intersection i)
|
||||||
{
|
{
|
||||||
Intersection *x;
|
Intersection *x;
|
||||||
@@ -46,6 +56,7 @@ void Intersect::add(Intersection i)
|
|||||||
stats.addRealloc();
|
stats.addRealloc();
|
||||||
this->list = (Intersection **)realloc(this->list, sizeof(Intersection *) * this->allocated);
|
this->list = (Intersection **)realloc(this->list, sizeof(Intersection *) * this->allocated);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->list[this->num++] = new Intersection(i.t, i.object);
|
this->list[this->num++] = new Intersection(i.t, i.object);
|
||||||
|
|
||||||
stats.setMaxIntersect(this->num);
|
stats.setMaxIntersect(this->num);
|
||||||
|
|||||||
@@ -30,14 +30,15 @@ Computation Intersection::prepareComputation(Ray r, Intersect *xs)
|
|||||||
Tuple underHitP = hitP - normalV * getEpsilon();
|
Tuple underHitP = hitP - normalV * getEpsilon();
|
||||||
Tuple reflectV = r.direction.reflect(normalV);
|
Tuple reflectV = r.direction.reflect(normalV);
|
||||||
|
|
||||||
if (xs != nullptr)
|
/* If the hit object is not transparent, there is no need to do that. I think .*/
|
||||||
|
if ((xs != nullptr) && (xs->hit().object->material.transparency > 0))
|
||||||
{
|
{
|
||||||
List containers;
|
List containers;
|
||||||
int j, k;
|
int j, k;
|
||||||
|
|
||||||
for(j = 0; j < xs->count(); j++)
|
for (j = 0 ; j < xs->count() ; j++)
|
||||||
{
|
{
|
||||||
Intersection i = (*xs)[j];
|
Intersection i = ( *xs )[j];
|
||||||
if (*this == i)
|
if (*this == i)
|
||||||
{
|
{
|
||||||
if (!containers.isEmpty())
|
if (!containers.isEmpty())
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ Matrix Matrix::transpose()
|
|||||||
int x, y;
|
int x, y;
|
||||||
Matrix ret = Matrix(this->size);
|
Matrix ret = Matrix(this->size);
|
||||||
|
|
||||||
#pragma omp parallel for simd private(y, x)
|
|
||||||
for (y = 0 ; y < this->size ; y++)
|
for (y = 0 ; y < this->size ; y++)
|
||||||
{
|
{
|
||||||
for (x = 0 ; x < this->size ; x++)
|
for (x = 0 ; x < this->size ; x++)
|
||||||
|
|||||||
Reference in New Issue
Block a user