Skip to content

Commit

Permalink
Clearing up some memory to prevent stupid issues
Browse files Browse the repository at this point in the history
Preparing for some optimisations. (absolutely need to reduce the ammount of allocations done.)
  • Loading branch information
Godzil committed Mar 2, 2020
1 parent 0ac44c3 commit ace7d53
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions source/include/intersect.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Intersect
public:
Intersect();
~Intersect();
void reset();
void add(Intersection i);
int count() { return this->num; };
Intersection operator[](const int p) { return *this->list[p]; }
Expand Down
8 changes: 8 additions & 0 deletions source/include/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class List
if (p == nullptr) { return; }

/* clear up the list */
do
{
ChainList *next = p->next;
free(p);
p = next;
}
while(p != nullptr);

}

Shape *last()
Expand Down
11 changes: 11 additions & 0 deletions source/intersect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions source/intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ 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;

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 (!containers.isEmpty())
Expand Down
1 change: 0 additions & 1 deletion source/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down

0 comments on commit ace7d53

Please sign in to comment.