From c5d73f96a251de17faefdaecdc99aba71a073cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 16 Dec 2015 00:31:07 +0100 Subject: [PATCH] Small source code improvements --- src/basics/InfiniteCylinder.cpp | 3 +++ src/basics/InfiniteCylinder.h | 1 + src/render/opengl/opengl_global.h | 1 - src/render/software/GodRaysSampler.cpp | 25 ++++++++++++------------- src/system/Mutex.h | 9 +++++---- src/system/PictureWriter.cpp | 6 ++++++ src/system/PictureWriter.h | 3 +++ src/system/system_global.h | 9 ++++++++- 8 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/basics/InfiniteCylinder.cpp b/src/basics/InfiniteCylinder.cpp index 3937d16..5c9837f 100644 --- a/src/basics/InfiniteCylinder.cpp +++ b/src/basics/InfiniteCylinder.cpp @@ -9,6 +9,9 @@ InfiniteCylinder::InfiniteCylinder(const InfiniteRay &axis, double radius) : axi validate(); } +InfiniteCylinder::~InfiniteCylinder() { +} + int InfiniteCylinder::findRayIntersection(const InfiniteRay &ray, Vector3 *first_intersection, Vector3 *second_intersection) const { /* diff --git a/src/basics/InfiniteCylinder.h b/src/basics/InfiniteCylinder.h index bcdeef7..a26dfba 100644 --- a/src/basics/InfiniteCylinder.h +++ b/src/basics/InfiniteCylinder.h @@ -15,6 +15,7 @@ class BASICSSHARED_EXPORT InfiniteCylinder { public: InfiniteCylinder() = default; InfiniteCylinder(const InfiniteRay &axis, double radius); + virtual ~InfiniteCylinder(); inline const InfiniteRay &getAxis() const { return axis; diff --git a/src/render/opengl/opengl_global.h b/src/render/opengl/opengl_global.h index bcffd2b..435882b 100644 --- a/src/render/opengl/opengl_global.h +++ b/src/render/opengl/opengl_global.h @@ -25,7 +25,6 @@ class OpenGLVegetationLayer; class OpenGLVegetationInstance; class OpenGLVegetationImpostor; class OpenGLTerrainChunk; -template class VertexArray; } } using namespace paysages::opengl; diff --git a/src/render/software/GodRaysSampler.cpp b/src/render/software/GodRaysSampler.cpp index dffd769..74de4aa 100644 --- a/src/render/software/GodRaysSampler.cpp +++ b/src/render/software/GodRaysSampler.cpp @@ -1,5 +1,7 @@ #include "GodRaysSampler.h" +#include +#include #include "GodRaysDefinition.h" #include "AtmosphereDefinition.h" #include "SoftwareRenderer.h" @@ -13,7 +15,6 @@ #include "TerrainDefinition.h" #include "CloudsRenderer.h" #include "Interpolation.h" -#include GodRaysSampler::GodRaysSampler() { enabled = true; @@ -48,16 +49,14 @@ void GodRaysSampler::prepare(SoftwareRenderer *renderer) { void GodRaysSampler::reset() { *bounds = SpaceSegment(Vector3(camera_location->x - max_length, low_altitude, camera_location->z - max_length), Vector3(camera_location->x + max_length, high_altitude, camera_location->z + max_length)); - samples_x = round(bounds->getXDiff() / sampling_step) + 1; - samples_y = round(bounds->getYDiff() / sampling_step) + 1; - samples_z = round(bounds->getZDiff() / sampling_step) + 1; + samples_x = round_to_int(bounds->getXDiff() / sampling_step) + 1; + samples_y = round_to_int(bounds->getYDiff() / sampling_step) + 1; + samples_z = round_to_int(bounds->getZDiff() / sampling_step) + 1; - long n = samples_x * samples_y * samples_z; + auto n = to_size(samples_x * samples_y * samples_z); delete[] data; data = new double[n]; - for (long i = 0; i < n; i++) { - data[i] = -1.0; - } + fill_n(data, n, -1.0); } void GodRaysSampler::setEnabled(bool enabled) { @@ -110,9 +109,9 @@ double GodRaysSampler::getCachedLight(const Vector3 &location) { double y = location.y - bounds->getStart().y; double z = location.z - bounds->getStart().z; - int ix = (int)floor(x / sampling_step); - int iy = (int)floor(y / sampling_step); - int iz = (int)floor(z / sampling_step); + int ix = floor_to_int(x / sampling_step); + int iy = floor_to_int(y / sampling_step); + int iz = floor_to_int(z / sampling_step); // Check cache limits if (ix < 0 || ix >= samples_x - 1 || iy < 0 || iy >= samples_y - 1 || iz < 0 || iz >= samples_z - 1) { @@ -171,8 +170,8 @@ inline double GodRaysSampler::getCache(int x, int y, int z) { double *cache = data + z * samples_x * samples_y + y * samples_x + x; if (*cache < 0.0) { Vector3 location = - Vector3(bounds->getStart().x + sampling_step * (double)x, bounds->getStart().y + sampling_step * (double)y, - bounds->getStart().z + sampling_step * (double)z); + Vector3(bounds->getStart().x + sampling_step * to_double(x), bounds->getStart().y + sampling_step * to_double(y), + bounds->getStart().z + sampling_step * to_double(z)); double unfiltered_power = getRawLight(location, false).getPower(); if (unfiltered_power == 0.0) { *cache = 1.0; diff --git a/src/system/Mutex.h b/src/system/Mutex.h index 2429b12..eb357e3 100644 --- a/src/system/Mutex.h +++ b/src/system/Mutex.h @@ -2,7 +2,8 @@ #define MUTEX_H #include "system_global.h" -#include + +#include namespace paysages { namespace system { @@ -10,7 +11,7 @@ namespace system { /*! * \brief System mutex */ -class SYSTEMSHARED_EXPORT Mutex : private QMutex { +class SYSTEMSHARED_EXPORT Mutex : private mutex { public: /*! * \brief Create a new mutex @@ -18,10 +19,10 @@ class SYSTEMSHARED_EXPORT Mutex : private QMutex { Mutex(); inline void acquire() { - QMutex::lock(); + mutex::lock(); } inline void release() { - QMutex::unlock(); + mutex::unlock(); } }; } diff --git a/src/system/PictureWriter.cpp b/src/system/PictureWriter.cpp index 36c9bb5..77879ae 100644 --- a/src/system/PictureWriter.cpp +++ b/src/system/PictureWriter.cpp @@ -2,6 +2,12 @@ #include +PictureWriter::PictureWriter() { +} + +PictureWriter::~PictureWriter() { +} + bool PictureWriter::save(const string &filepath, int width, int height) { QImage result(width, height, QImage::Format_ARGB32); diff --git a/src/system/PictureWriter.h b/src/system/PictureWriter.h index 8dcab57..20391b9 100644 --- a/src/system/PictureWriter.h +++ b/src/system/PictureWriter.h @@ -8,6 +8,9 @@ namespace system { class SYSTEMSHARED_EXPORT PictureWriter { public: + PictureWriter(); + virtual ~PictureWriter(); + /** * @brief Start saving the picture in a file. */ diff --git a/src/system/system_global.h b/src/system/system_global.h index d23ea54..4b03fb6 100644 --- a/src/system/system_global.h +++ b/src/system/system_global.h @@ -31,11 +31,18 @@ class PictureWriter; class Time; class RandomGenerator; -extern RandomGenerator &RandomGeneratorDefault; +extern SYSTEMSHARED_EXPORT RandomGenerator &RandomGeneratorDefault; } } using namespace paysages::system; using namespace std; +// Some useful casts +#define to_double(_x_) (static_cast(_x_)) +#define round_to_int(_x_) (static_cast(round(_x_))) +#define floor_to_int(_x_) (static_cast(floor(_x_))) +#define ceil_to_int(_x_) (static_cast(ceil(_x_))) +#define to_size(_x_) (static_cast(_x_)) + #endif // SYSTEM_GLOBAL_H