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:
|
||||
Intersect();
|
||||
~Intersect();
|
||||
void reset();
|
||||
void add(Intersection i);
|
||||
int count() { return this->num; };
|
||||
Intersection operator[](const int p) { return *this->list[p]; }
|
||||
|
||||
@@ -31,6 +31,14 @@ public:
|
||||
if (p == nullptr) { return; }
|
||||
|
||||
/* clear up the list */
|
||||
do
|
||||
{
|
||||
ChainList *next = p->next;
|
||||
free(p);
|
||||
p = next;
|
||||
}
|
||||
while(p != nullptr);
|
||||
|
||||
}
|
||||
|
||||
Shape *last()
|
||||
|
||||
@@ -31,10 +31,20 @@ Intersect::Intersect()
|
||||
|
||||
Intersect::~Intersect()
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < this->num; i++)
|
||||
{
|
||||
free(this->list[i]);
|
||||
}
|
||||
/* Free stuff */
|
||||
free(this->list);
|
||||
}
|
||||
|
||||
void Intersect::reset()
|
||||
{
|
||||
this->num = 0;
|
||||
}
|
||||
|
||||
void Intersect::add(Intersection i)
|
||||
{
|
||||
Intersection *x;
|
||||
@@ -46,6 +56,7 @@ void Intersect::add(Intersection i)
|
||||
stats.addRealloc();
|
||||
this->list = (Intersection **)realloc(this->list, sizeof(Intersection *) * this->allocated);
|
||||
}
|
||||
|
||||
this->list[this->num++] = new Intersection(i.t, i.object);
|
||||
|
||||
stats.setMaxIntersect(this->num);
|
||||
|
||||
@@ -30,7 +30,8 @@ Computation Intersection::prepareComputation(Ray r, Intersect *xs)
|
||||
Tuple underHitP = hitP - normalV * getEpsilon();
|
||||
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;
|
||||
int j, k;
|
||||
|
||||
@@ -125,7 +125,6 @@ Matrix Matrix::transpose()
|
||||
int x, y;
|
||||
Matrix ret = Matrix(this->size);
|
||||
|
||||
#pragma omp parallel for simd private(y, x)
|
||||
for (y = 0 ; y < this->size ; y++)
|
||||
{
|
||||
for (x = 0 ; x < this->size ; x++)
|
||||
|
||||
Reference in New Issue
Block a user