diff --git a/Makefile b/Makefile index b949d63..ea77449 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,11 @@ release: +make BUILDMODE=release all tests:build +ifdef TESTCASE + LD_LIBRARY_PATH=$(LIBRARY_PATH) ${BUILDPATH}/tests/paysages-tests --gtest_filter=$(TESTCASE).* +else LD_LIBRARY_PATH=$(LIBRARY_PATH) ${BUILDPATH}/tests/paysages-tests +endif run_cli:build LD_LIBRARY_PATH=$(LIBRARY_PATH) ${RUNNER} ${BUILDPATH}/controlling/paysages-cli diff --git a/src/basics/SpaceCoordinates.cpp b/src/basics/SpaceCoordinates.cpp deleted file mode 100644 index 49820f2..0000000 --- a/src/basics/SpaceCoordinates.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "SpaceCoordinates.h" diff --git a/src/basics/SpaceCoordinates.h b/src/basics/SpaceCoordinates.h deleted file mode 100644 index 2b6dc44..0000000 --- a/src/basics/SpaceCoordinates.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SPACECOORDINATES_H -#define SPACECOORDINATES_H - -#include "basics_global.h" - -#include "Vector3.h" - -namespace paysages { -namespace basics { - -/*! - * \brief Space 3D coordinates. - * - * These coordinates allow to work on very large scenes, regardless of the 'double' type precision. - */ -class SpaceCoordinates:public Vector3 -{ -/*public: - SpaceCoordinates();*/ -}; - -} -} - -#endif // SPACECOORDINATES_H diff --git a/src/basics/SpaceSegment.cpp b/src/basics/SpaceSegment.cpp new file mode 100644 index 0000000..2e718d1 --- /dev/null +++ b/src/basics/SpaceSegment.cpp @@ -0,0 +1,56 @@ +#include "SpaceSegment.h" + +SpaceSegment::SpaceSegment(const Vector3& start, const Vector3& end): + start(start), end(end) +{ +} + +bool SpaceSegment::intersectYInterval(double ymin, double ymax) +{ + if (start.y > ymax) + { + if (end.y >= ymax) + { + return false; + } + else + { + Vector3 diff = end.sub(start); + start = start.add(diff.scale((ymax - start.y) / diff.y)); + if (end.y < ymin) + { + end = end.add(diff.scale((ymin - end.y) / diff.y)); + } + } + } + else if (start.y < ymin) + { + if (end.y <= ymin) + { + return false; + } + else + { + Vector3 diff = end.sub(start); + start = start.add(diff.scale((ymin - start.y) / diff.y)); + if (end.y >= ymax) + { + end = end.add(diff.scale((ymax - end.y) / diff.y)); + } + } + } + else /* start is inside layer */ + { + Vector3 diff = end.sub(start); + if (end.y > ymax) + { + end = start.add(diff.scale((ymax - start.y) / diff.y)); + } + else if (end.y < ymin) + { + end = start.add(diff.scale((ymin - start.y) / diff.y)); + } + } + + return true; +} diff --git a/src/basics/SpaceSegment.h b/src/basics/SpaceSegment.h new file mode 100644 index 0000000..d7220ef --- /dev/null +++ b/src/basics/SpaceSegment.h @@ -0,0 +1,39 @@ +#ifndef SPACESEGMENT_H +#define SPACESEGMENT_H + +#include "basics_global.h" + +#include "Vector3.h" + +namespace paysages +{ +namespace basics +{ + +/*! + * \brief A segment in 3D space (mainly useful for rays). + */ +class SpaceSegment +{ +public: + SpaceSegment(const Vector3& start, const Vector3& end); + SpaceSegment(): SpaceSegment(Vector3(), Vector3()) {} + + inline Vector3 getStart() const {return start;} + inline Vector3 getEnd() const {return end;} + + /*! + * \brief Keep only the intersection with a slice orthogonal to the Y axis. + * \return true if a segment remains + */ + bool intersectYInterval(double ymin, double ymax); + +private: + Vector3 start; + Vector3 end; +}; + +} +} + +#endif // SPACESEGMENT_H diff --git a/src/basics/basics.pro b/src/basics/basics.pro index be88900..8801948 100644 --- a/src/basics/basics.pro +++ b/src/basics/basics.pro @@ -19,9 +19,9 @@ SOURCES += \ NoiseFunctionPerlin.cpp \ NoiseFunctionSimplex.cpp \ Interpolation.cpp \ - SpaceCoordinates.cpp \ Vector3.cpp \ - Vector3.inline.cpp + Vector3.inline.cpp \ + SpaceSegment.cpp HEADERS +=\ basics_global.h \ @@ -30,8 +30,8 @@ HEADERS +=\ NoiseFunctionPerlin.h \ NoiseFunctionSimplex.h \ Interpolation.h \ - SpaceCoordinates.h \ - Vector3.h + Vector3.h \ + SpaceSegment.h unix:!symbian { maemo5 { diff --git a/src/basics/basics_global.h b/src/basics/basics_global.h index cda790f..81b7fc8 100644 --- a/src/basics/basics_global.h +++ b/src/basics/basics_global.h @@ -13,6 +13,7 @@ namespace paysages { namespace basics { class Vector3; + class SpaceSegment; } } using namespace paysages::basics; diff --git a/src/common.pri b/src/common.pri index 5018fd3..db8cca7 100644 --- a/src/common.pri +++ b/src/common.pri @@ -1,3 +1,3 @@ CONFIG(release, debug|release): DEFINES += NDEBUG -QMAKE_CXXFLAGS = -std=c++11 +QMAKE_CXXFLAGS += -std=c++11 diff --git a/src/render/software/FluidMediumInterface.h b/src/render/software/FluidMediumInterface.h index 7dc297e..f706080 100644 --- a/src/render/software/FluidMediumInterface.h +++ b/src/render/software/FluidMediumInterface.h @@ -4,9 +4,6 @@ #include "software_global.h" namespace paysages { -namespace basics { - class SpaceCoordinate; -} namespace software { /*! @@ -16,9 +13,10 @@ class SOFTWARESHARED_EXPORT FluidMediumInterface { public: /*! - * Return true if the object may interfere with the fluid medium on the given segment. + * Return true if the object may change the fluid medium on the given segment. + * When returning true, the object may alter 'segment' to limit its influence. */ - virtual bool mayInfluence(const SpaceCoordinate& start, const SpaceCoordinate& end) const = 0; + virtual bool checkInfluence(SpaceSegment& segment) const = 0; }; } diff --git a/src/render/software/FluidMediumManager.cpp b/src/render/software/FluidMediumManager.cpp new file mode 100644 index 0000000..9f66e75 --- /dev/null +++ b/src/render/software/FluidMediumManager.cpp @@ -0,0 +1,51 @@ +#include "FluidMediumManager.h" + +#include "SoftwareRenderer.h" +#include "FluidMediumInterface.h" + +FluidMediumManager::FluidMediumManager(SoftwareRenderer* renderer): + renderer(renderer) +{ +} + +FluidMediumManager::~FluidMediumManager() +{ +} + +void FluidMediumManager::clearMedia() +{ + media.clear(); +} + +void FluidMediumManager::registerMedium(FluidMediumInterface *medium) +{ + media.push_back(medium); +} + +Color FluidMediumManager::applyTraversal(const Vector3 &eye, const Vector3 &location, const Color &color) const +{ + // Collect potential segments + SpaceSegment ray(eye, location); + int max_segments = media.size(); + FluidMediumSegment* segments; + segments = new FluidMediumSegment[max_segments]; + int segment_count = getTraversedMedia(segments, ray, max_segments); + + delete[] segments; + return color; +} + +int FluidMediumManager::getTraversedMedia(FluidMediumSegment segments[], const SpaceSegment &ray, int max_segments) const +{ + int added = 0; + for (auto &medium : media) + { + SpaceSegment ray_inter(ray); + if (added < max_segments and medium->checkInfluence(ray_inter)) + { + // The medium intersect with the ray + segments[added++] = {medium, ray_inter}; + } + } + return added; +} diff --git a/src/render/software/FluidMediumManager.h b/src/render/software/FluidMediumManager.h new file mode 100644 index 0000000..552275c --- /dev/null +++ b/src/render/software/FluidMediumManager.h @@ -0,0 +1,62 @@ +#ifndef FLUIDMEDIUMMANAGER_H +#define FLUIDMEDIUMMANAGER_H + +#include "software_global.h" + +#include "SpaceSegment.h" +#include "tools/color.h" + +namespace paysages { +namespace software { + +typedef struct { + FluidMediumInterface* medium; + SpaceSegment segment; +} FluidMediumSegment; + +/*! + * \brief Global object to interact with fluid medium (air, water, clouds...) + * + * This object handles the traversal of fluid medium and the collecting of + * medium density and properties. + * It is mainly used to compute the alteration made by such media on light. + */ +class SOFTWARESHARED_EXPORT FluidMediumManager +{ +public: + FluidMediumManager(SoftwareRenderer *renderer); + virtual ~FluidMediumManager(); + + /*! + * \brief Remove all registered medium. + */ + void clearMedia(); + + /*! + * \brief Register a new medium in the manager. + */ + void registerMedium(FluidMediumInterface *medium); + + /*! + * \brief Apply complete medium traversal + * \param eye Position of the camera + * \param location Point we look at + * \param color Light initially received from 'location' + * \return Light received by 'eye', transformed by medium traversal + */ + virtual Color applyTraversal(const Vector3 &eye, const Vector3 &location, const Color &color) const; + + /*! + * \brief Get the potential media traversed by a ray, unsorted + */ + virtual int getTraversedMedia(FluidMediumSegment segments[], const SpaceSegment &ray, int max_segments) const; + +private: + SoftwareRenderer *renderer; + std::vector media; +}; + +} +} + +#endif // FLUIDMEDIUMTRAVERSAL_H diff --git a/src/render/software/FluidMediumTraversal.cpp b/src/render/software/FluidMediumTraversal.cpp deleted file mode 100644 index 9250dc1..0000000 --- a/src/render/software/FluidMediumTraversal.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "FluidMediumTraversal.h" - -FluidMediumTraversal::FluidMediumTraversal(SoftwareRenderer* renderer): - renderer(renderer) -{ -} - -FluidMediumTraversal::~FluidMediumTraversal() -{ -} - -void FluidMediumTraversal::setCollector(FluidMediumCollector *collector) -{ -} - -void FluidMediumTraversal::getTraversedMedia(std::vector &media, const SpaceCoordinates &start, const SpaceCoordinates &end) -{ -} - -void FluidMediumTraversal::collectHalfLine(const SpaceCoordinates &start, const Vector3 &direction) -{ -} - -void FluidMediumTraversal::collectSegment(const SpaceCoordinates &start, const SpaceCoordinates &end) -{ -} diff --git a/src/render/software/FluidMediumTraversal.h b/src/render/software/FluidMediumTraversal.h deleted file mode 100644 index 7341f57..0000000 --- a/src/render/software/FluidMediumTraversal.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef FLUIDMEDIUMTRAVERSAL_H -#define FLUIDMEDIUMTRAVERSAL_H - -#include "software_global.h" - -#include -#include "SpaceCoordinates.h" - -namespace paysages { -namespace software { - -class SoftwareRenderer; -class FluidMediumCollector; -class FluidMediumInterface; - -/*! - * \brief Global object to interact with fluid medium (air, water, clouds...) - * - * This object handles the traversal of fluid medium and the collecting of - * medium density and properties. - * It is mainly used to compute the alteration made by such media on light. - */ -class SOFTWARESHARED_EXPORT FluidMediumTraversal -{ -public: - FluidMediumTraversal(SoftwareRenderer *renderer); - virtual ~FluidMediumTraversal(); - - void setCollector(FluidMediumCollector *collector); - - virtual void getTraversedMedia(std::vector &media, const SpaceCoordinates &start, const SpaceCoordinates &end); - - void collectHalfLine(const SpaceCoordinates &start, const Vector3 &direction); - void collectSegment(const SpaceCoordinates &start, const SpaceCoordinates &end); - -private: - SoftwareRenderer* renderer; -}; - -} -} - -#endif // FLUIDMEDIUMTRAVERSAL_H diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index 3463931..bdc375a 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -1,11 +1,12 @@ #include "SoftwareRenderer.h" +#include "camera.h" #include "Scenery.h" -#include "FluidMediumTraversal.h" +#include "FluidMediumManager.h" SoftwareRenderer::SoftwareRenderer(Scenery* scenery) { - fluid_medium = new FluidMediumTraversal(this); + fluid_medium = new FluidMediumManager(this); if (scenery) { @@ -23,8 +24,13 @@ SoftwareRenderer::~SoftwareRenderer() delete fluid_medium; } -Color SoftwareRenderer::applyMediumTraversal(Vector3 location, Color color) +void SoftwareRenderer::initialize() { - // TODO - return color; + //fluid_medium->registerMedium(water_renderer); } + +/*Color SoftwareRenderer::applyMediumTraversal(Vector3 location, Color color) +{ + Vector3 eye = cameraGetLocation(scenery->getCamera()); + return fluid_medium->applyTraversal(eye, location, color); +}*/ diff --git a/src/render/software/SoftwareRenderer.h b/src/render/software/SoftwareRenderer.h index 0f19a70..09a1ee7 100644 --- a/src/render/software/SoftwareRenderer.h +++ b/src/render/software/SoftwareRenderer.h @@ -10,8 +10,6 @@ class Scenery; namespace paysages { namespace software { -class FluidMediumTraversal; - /*! * \brief This class renders a defined scenery in sotware mode (using only standard CPU computations). */ @@ -22,13 +20,16 @@ public: SoftwareRenderer(Scenery* scenery=0); virtual ~SoftwareRenderer(); - inline Scenery* getScenery() const {return scenery;} + virtual void initialize(); - virtual Color applyMediumTraversal(Vector3 location, Color color); + inline Scenery* getScenery() const {return scenery;} + inline FluidMediumManager* getFluidMediumManager() const {return fluid_medium;} + + //virtual Color applyMediumTraversal(Vector3 location, Color color) override; private: Scenery* scenery; - FluidMediumTraversal* fluid_medium; + FluidMediumManager* fluid_medium; }; } diff --git a/src/render/software/software.pro b/src/render/software/software.pro index 1356e79..a7c0148 100644 --- a/src/render/software/software.pro +++ b/src/render/software/software.pro @@ -14,13 +14,13 @@ DEFINES += SOFTWARE_LIBRARY include(../../common.pri) SOURCES += SoftwareRenderer.cpp \ - FluidMediumTraversal.cpp \ - FluidMediumInterface.cpp + FluidMediumInterface.cpp \ + FluidMediumManager.cpp HEADERS += SoftwareRenderer.h\ software_global.h \ - FluidMediumTraversal.h \ - FluidMediumInterface.h + FluidMediumInterface.h \ + FluidMediumManager.h unix:!symbian { maemo5 { diff --git a/src/render/software/software_global.h b/src/render/software/software_global.h index 44b36a6..59a1fb7 100644 --- a/src/render/software/software_global.h +++ b/src/render/software/software_global.h @@ -9,14 +9,17 @@ # define SOFTWARESHARED_EXPORT Q_DECL_IMPORT #endif +#include "basics_global.h" + namespace paysages { -namespace basics {} -namespace definition {} -namespace software {} +namespace software { + class SoftwareRenderer; + class FluidMediumManager; + class FluidMediumInterface; + class FluidMediumCollector; +} } -using namespace paysages::basics; -using namespace paysages::definition; using namespace paysages::software; #endif // SOFTWARE_GLOBAL_H diff --git a/src/rendering/atmosphere/atm_preview.cpp b/src/rendering/atmosphere/atm_preview.cpp index bfdb93e..ec1498b 100644 --- a/src/rendering/atmosphere/atm_preview.cpp +++ b/src/rendering/atmosphere/atm_preview.cpp @@ -51,7 +51,7 @@ static Mount MOUNTS[MOUNTS_COUNT] = { }; static SurfaceMaterial MOUNT_MATERIAL = { - {0.4, 0.4, 0.4, 1.0}, 0.0, 0.0 + {0.4, 0.4, 0.4, 1.0}, 0.0, 0.0, 0.0, 0.0, {0.0, 0.0, 0.0, 0.0} }; static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vector3 v1, Vector3 v2, Vector3* hit) diff --git a/src/rendering/camera.cpp b/src/rendering/camera.cpp index faf719d..8c9a5af 100644 --- a/src/rendering/camera.cpp +++ b/src/rendering/camera.cpp @@ -11,8 +11,9 @@ #include "rendering/terrain/public.h" #include "rendering/water/public.h" -struct CameraDefinition +class CameraDefinition { +public: /* Definition */ Vector3 location; VectorSpherical direction; diff --git a/src/rendering/camera.h b/src/rendering/camera.h index 16826ea..1828e98 100644 --- a/src/rendering/camera.h +++ b/src/rendering/camera.h @@ -9,7 +9,7 @@ namespace paysages { namespace system {class PackStream;} } -typedef struct CameraDefinition CameraDefinition; +class CameraDefinition; typedef struct { diff --git a/src/rendering/render.h b/src/rendering/render.h index 5a788ad..fe6b85e 100644 --- a/src/rendering/render.h +++ b/src/rendering/render.h @@ -6,7 +6,7 @@ #include "tools/color.h" #include "tools/euclid.h" -typedef Color (*f_RenderFragmentCallback)(struct Renderer* renderer, Vector3 location, void* data); +typedef Color (*f_RenderFragmentCallback)(Renderer* renderer, Vector3 location, void* data); typedef void (*RenderCallbackStart)(int width, int height, Color background); typedef void (*RenderCallbackDraw)(int x, int y, Color col); diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 784f3fb..bce527b 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -13,7 +13,7 @@ #include "rendering/textures/public.h" #include "rendering/water/public.h" -static RayCastingResult _RAYCASTING_NULL = {0}; +static RayCastingResult _RAYCASTING_NULL = {0, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}}; static void* _renderFirstPass(void* data) { diff --git a/src/rendering/shared/types.h b/src/rendering/shared/types.h index f7bcc09..f6dc18f 100644 --- a/src/rendering/shared/types.h +++ b/src/rendering/shared/types.h @@ -4,7 +4,7 @@ #include "../tools/euclid.h" #include "../tools/color.h" -typedef struct Renderer Renderer; +class Renderer; typedef struct { diff --git a/src/rendering/terrain/ter_render.cpp b/src/rendering/terrain/ter_render.cpp index e5a59d3..e86d278 100644 --- a/src/rendering/terrain/ter_render.cpp +++ b/src/rendering/terrain/ter_render.cpp @@ -144,7 +144,7 @@ static Color _fakeGetFinalColor(Renderer* renderer, Vector3 location, double pre return COLOR_GREEN; } -static Color _realGetFinalColor(Renderer* renderer, Vector3 location, double precision) +static Color _realGetFinalColor(Renderer* renderer, Vector3 location, double) { /* TODO Restore precision control */ TexturesResult textures = renderer->textures->applyToTerrain(renderer, location.x, location.z); diff --git a/src/rendering/tools/array.cpp b/src/rendering/tools/array.cpp index b52e65f..4e66439 100644 --- a/src/rendering/tools/array.cpp +++ b/src/rendering/tools/array.cpp @@ -6,16 +6,18 @@ void* naiveArrayInsert(void** array, size_t item_size, int item_count, int location) { + char** barray = (char**)array; + assert(location >= 0); assert(location <= item_count); - *array = realloc(*array, item_size * (item_count + 1)); + *barray = (char*)realloc(*barray, item_size * (item_count + 1)); if (location < item_count) { - memmove(*array + item_size * (location + 1), *array + item_size * location, item_size * (item_count - location)); + memmove(*barray + item_size * (location + 1), *barray + item_size * location, item_size * (item_count - location)); } - return *array + item_size * location; + return *barray + item_size * location; } void arrayCreate(Array* array, int item_size) @@ -35,7 +37,7 @@ void arrayDelete(Array* array) void* arrayAppend(Array* array, void* item) { - void* dest; + char* dest; size_t item_size = (size_t)array->item_size; if (array->length >= array->alloc_length) @@ -44,7 +46,7 @@ void* arrayAppend(Array* array, void* item) array->data = realloc(array->data, item_size * array->alloc_length); } - dest = array->data + item_size * array->length; + dest = ((char*)array->data) + item_size * array->length; memcpy(dest, item, item_size); array->length++; @@ -56,7 +58,7 @@ void* arrayAppend(Array* array, void* item) void arrayInsert(Array* array, void* item, int position) { size_t item_size; - void* dest; + char* dest; if (position >= array->length) { @@ -72,9 +74,9 @@ void arrayInsert(Array* array, void* item, int position) array->data = realloc(array->data, item_size * array->alloc_length); } - dest = array->data + item_size * position; + dest = ((char*)array->data) + item_size * position; memmove(dest + item_size, dest, array->length - position); - memcpy(array->data + item_size * position, item, item_size); + memcpy(((char*)array->data) + item_size * position, item, item_size); array->length++; array->dirty = 1; @@ -88,7 +90,7 @@ void arrayReplace(Array* array, void* item, int position) if (position >= 0 && position < array->length) { item_size = (size_t)array->item_size; - memcpy(array->data + item_size * position, item, item_size); + memcpy(((char*)array->data) + item_size * position, item, item_size); array->dirty = 1; } @@ -105,7 +107,7 @@ void arrayLStrip(Array* array, int count) else if (count >= 0) { item_size = (size_t)array->item_size; - memmove(array->data, array->data + item_size * count, item_size * (array->length - count)); + memmove(array->data, ((char*)array->data) + item_size * count, item_size * (array->length - count)); array->length -= count; array->dirty = 1; } diff --git a/src/rendering/tools/color.cpp b/src/rendering/tools/color.cpp index 9d82d62..eaa2cca 100644 --- a/src/rendering/tools/color.cpp +++ b/src/rendering/tools/color.cpp @@ -212,8 +212,9 @@ void colorLimitPower(Color* col, double max_power) } /******************************** ColorProfile ********************************/ -struct ColorProfile +class ColorProfile { +public: double minvalue; double maxvalue; Color(*mapper)(Color col, double exposure); @@ -297,12 +298,12 @@ void colorProfileSetToneMapping(ColorProfile* profile, ToneMappingOperator tonem profile->exposure = exposure; } -void colorProfileSave(PackStream* stream, ColorProfile* profile) +void colorProfileSave(PackStream*, ColorProfile*) { /* TODO */ } -void colorProfileLoad(PackStream* stream, ColorProfile* profile) +void colorProfileLoad(PackStream*, ColorProfile*) { /* TODO */ } diff --git a/src/rendering/tools/color.h b/src/rendering/tools/color.h index cc8ca80..ed4b15f 100644 --- a/src/rendering/tools/color.h +++ b/src/rendering/tools/color.h @@ -48,7 +48,7 @@ RENDERINGSHARED_EXPORT double colorGetPower(Color* col); RENDERINGSHARED_EXPORT void colorLimitPower(Color* col, double max_power); /* HDR profile for tone-mapping */ -typedef struct ColorProfile ColorProfile; +class ColorProfile; typedef enum { TONE_MAPPING_UNCHARTED, diff --git a/src/rendering/tools/lighting.cpp b/src/rendering/tools/lighting.cpp index fb12ffb..4ecc5dd 100644 --- a/src/rendering/tools/lighting.cpp +++ b/src/rendering/tools/lighting.cpp @@ -15,8 +15,9 @@ typedef struct void* data; } LightFilterCallback; -struct LightingManager +class LightingManager { +public: int specularity_enabled; int callbacks_count; LightFilterCallback callbacks[MAX_CALLBACK_COUNT]; diff --git a/src/rendering/tools/lighting.h b/src/rendering/tools/lighting.h index e3992f4..06a6657 100644 --- a/src/rendering/tools/lighting.h +++ b/src/rendering/tools/lighting.h @@ -33,7 +33,7 @@ typedef struct typedef int (*FuncLightingAlterLight)(void* data, LightDefinition* light, Vector3 at); -typedef struct LightingManager LightingManager; +class LightingManager; typedef struct LightStatus LightStatus; RENDERINGSHARED_EXPORT LightingManager* lightingManagerCreate(); diff --git a/src/rendering/tools/memory.cpp b/src/rendering/tools/memory.cpp index 223cad0..02775b6 100644 --- a/src/rendering/tools/memory.cpp +++ b/src/rendering/tools/memory.cpp @@ -3,11 +3,11 @@ #include #include -void* memory2dRealloc(void* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset) +char* memory2dRealloc(char* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset) { int xstart, xend, xlen; int ystart, yend, y; - void* result = malloc(datasize * newxsize * newysize); + char* result = (char*)malloc(datasize * newxsize * newysize); /* Move remaining part*/ ystart = yoffset; diff --git a/src/rendering/tools/memory.h b/src/rendering/tools/memory.h index d5134b9..59475e5 100644 --- a/src/rendering/tools/memory.h +++ b/src/rendering/tools/memory.h @@ -7,6 +7,6 @@ #include "../rendering_global.h" -RENDERINGSHARED_EXPORT void* memory2dRealloc(void* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset); +RENDERINGSHARED_EXPORT char* memory2dRealloc(char* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset); #endif diff --git a/src/tests/FluidMediumManager_Test.cpp b/src/tests/FluidMediumManager_Test.cpp new file mode 100644 index 0000000..53ba9d6 --- /dev/null +++ b/src/tests/FluidMediumManager_Test.cpp @@ -0,0 +1,110 @@ +#include "BaseTestCase.h" + +#include "SpaceSegment.h" +#include "Scenery.h" +#include "SoftwareRenderer.h" +#include "FluidMediumManager.h" +#include "FluidMediumInterface.h" + +class FluidMediumManager_Test:public BaseTestCase +{ +protected: + virtual void setUp() + { + scenery = new Scenery(); + renderer = new SoftwareRenderer(scenery); + } + + virtual void tearDown() + { + delete renderer; + delete scenery; + } + + Scenery* scenery; + SoftwareRenderer* renderer; +}; + + +TEST_F(FluidMediumManager_Test, getTraversedMedia) +{ + FluidMediumManager manager(renderer); + int traversed; + FluidMediumSegment segments[10]; + class FakeMedium:public FluidMediumInterface + { + public: + void setCut(double ymin, double ymax) + { + this->ymin = ymin; + this->ymax = ymax; + } + + virtual bool checkInfluence(SpaceSegment& segment) const override + { + return segment.intersectYInterval(this->ymin, this->ymax); + } + private: + double ymin = -2.0; + double ymax = -1.0; + }; + SpaceSegment ray(Vector3(0.0, 0.0, 0.0), Vector3(8.0, 10.0, -4.0)); + + // Empty manager + traversed = manager.getTraversedMedia(segments, ray, 10); + ASSERT_EQ(0, traversed); + + // Testing with 1 medium outside the range + FakeMedium m1; + manager.registerMedium(&m1); + traversed = manager.getTraversedMedia(segments, ray, 10); + ASSERT_EQ(0, traversed); + + // Setting the medium in range + m1.setCut(1.0, 2.0); + traversed = manager.getTraversedMedia(segments, ray, 10); + ASSERT_EQ(1, traversed); + EXPECT_EQ((FluidMediumInterface*)&m1, segments[0].medium); + EXPECT_VECTOR3_COORDS(segments[0].segment.getStart(), 0.8, 1.0, -0.4); + EXPECT_VECTOR3_COORDS(segments[0].segment.getEnd(), 1.6, 2.0, -0.8); + + // Testing with 2 media + FakeMedium m2; + m2.setCut(4.0, 12.0); + manager.registerMedium(&m2); + traversed = manager.getTraversedMedia(segments, ray, 10); + ASSERT_EQ(2, traversed); + EXPECT_EQ((FluidMediumInterface*)&m1, segments[0].medium); + EXPECT_VECTOR3_COORDS(segments[0].segment.getStart(), 0.8, 1.0, -0.4); + EXPECT_VECTOR3_COORDS(segments[0].segment.getEnd(), 1.6, 2.0, -0.8); + EXPECT_EQ((FluidMediumInterface*)&m2, segments[1].medium); + EXPECT_VECTOR3_COORDS(segments[1].segment.getStart(), 3.2, 4.0, -1.6); + EXPECT_VECTOR3_COORDS(segments[1].segment.getEnd(), 8.0, 10.0, -4.0); + + // Testing with overlapping media + FakeMedium m3; + m3.setCut(3.0, 4.5); + manager.registerMedium(&m3); + traversed = manager.getTraversedMedia(segments, ray, 10); + ASSERT_EQ(3, traversed); + EXPECT_EQ((FluidMediumInterface*)&m1, segments[0].medium); + EXPECT_VECTOR3_COORDS(segments[0].segment.getStart(), 0.8, 1.0, -0.4); + EXPECT_VECTOR3_COORDS(segments[0].segment.getEnd(), 1.6, 2.0, -0.8); + EXPECT_EQ((FluidMediumInterface*)&m2, segments[1].medium); + EXPECT_VECTOR3_COORDS(segments[1].segment.getStart(), 3.2, 4.0, -1.6); + EXPECT_VECTOR3_COORDS(segments[1].segment.getEnd(), 8.0, 10.0, -4.0); + EXPECT_EQ((FluidMediumInterface*)&m3, segments[2].medium); + EXPECT_VECTOR3_COORDS(segments[2].segment.getStart(), 2.4, 3.0, -1.2); + EXPECT_VECTOR3_COORDS(segments[2].segment.getEnd(), 3.6, 4.5, -1.8); + + // Testing the segment count limit + traversed = manager.getTraversedMedia(segments, ray, 2); + ASSERT_EQ(2, traversed); + EXPECT_EQ((FluidMediumInterface*)&m1, segments[0].medium); + EXPECT_EQ((FluidMediumInterface*)&m2, segments[1].medium); + + // Testing after clear + manager.clearMedia(); + traversed = manager.getTraversedMedia(segments, ray, 10); + ASSERT_EQ(0, traversed); +} diff --git a/src/tests/PackStream_Test.cpp b/src/tests/PackStream_Test.cpp index 5926b92..d2e7407 100644 --- a/src/tests/PackStream_Test.cpp +++ b/src/tests/PackStream_Test.cpp @@ -8,7 +8,7 @@ TEST(PackStream, All) int i; int data_i; double data_d; - char* data_s; + const char* data_s; char buffer[100]; /* Writing to pack */ diff --git a/src/tests/googletest/googletest.pro b/src/tests/googletest/googletest.pro index 0b221c0..dad7319 100644 --- a/src/tests/googletest/googletest.pro +++ b/src/tests/googletest/googletest.pro @@ -11,7 +11,7 @@ TEMPLATE = lib DEFINES += GOOGLETEST_LIBRARY -#QMAKE_CXXFLAGS += -pthread +QMAKE_CXXFLAGS += -pthread -Wno-missing-field-initializers INCLUDEPATH += . ./include diff --git a/src/tests/tests.pro b/src/tests/tests.pro index c9a2176..16f6c0b 100644 --- a/src/tests/tests.pro +++ b/src/tests/tests.pro @@ -4,6 +4,8 @@ CONFIG -= app_bundle TARGET = paysages-tests +include(../common.pri) + SOURCES += main.cpp \ Layers_Test.cpp \ PackStream_Test.cpp \ @@ -14,7 +16,8 @@ SOURCES += main.cpp \ Euclid_Test.cpp \ Bruneton_Test.cpp \ Camera_Test.cpp \ - Clouds_Test.cpp + Clouds_Test.cpp \ + FluidMediumManager_Test.cpp HEADERS += \ BaseTestCase.h @@ -48,3 +51,9 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering INCLUDEPATH += $$PWD/../rendering DEPENDPATH += $$PWD/../rendering + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../render/software/release/ -lpaysages_render_software +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../render/software/debug/ -lpaysages_render_software +else:unix: LIBS += -L$$OUT_PWD/../render/software/ -lpaysages_render_software +INCLUDEPATH += $$PWD/../render/software +DEPENDPATH += $$PWD/../render/software