Removing Qt dependency in core (WIP)

This commit is contained in:
Michaël Lemaire 2020-03-25 17:12:53 +01:00
parent be8a5f9764
commit 8cc8a1d068
71 changed files with 305 additions and 304 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 512 KiB

After

Width:  |  Height:  |  Size: 512 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 MiB

After

Width:  |  Height:  |  Size: 2 MiB

View file

@ -65,9 +65,9 @@ static constexpr double AVERAGE_GROUND_REFLECTANCE = 0.1;
#define INSCATTER_SPHERICAL_INTEGRAL_SAMPLES 8 #define INSCATTER_SPHERICAL_INTEGRAL_SAMPLES 8
#endif #endif
Texture2D *_transmittanceTexture = NULL; Texture2D *_transmittanceTexture = nullptr;
Texture2D *_irradianceTexture = NULL; Texture2D *_irradianceTexture = nullptr;
Texture4D *_inscatterTexture = NULL; Texture4D *_inscatterTexture = nullptr;
/* Rayleigh */ /* Rayleigh */
static const double HR = 8.0; static const double HR = 8.0;
@ -951,7 +951,7 @@ int brunetonInit() {
int x, y, z, w, order; int x, y, z, w, order;
ParallelWork *work; ParallelWork *work;
assert(_inscatterTexture == NULL); assert(_inscatterTexture == nullptr);
/* TODO Deletes */ /* TODO Deletes */
_transmittanceTexture = new Texture2D(TRANSMITTANCE_W, TRANSMITTANCE_H); _transmittanceTexture = new Texture2D(TRANSMITTANCE_W, TRANSMITTANCE_H);

View file

@ -1,20 +1,14 @@
#include "CacheFile.h" #include "CacheFile.h"
#include "DataFile.h" #include "DataFile.h"
#include <QString>
#include <sstream>
CacheFile::CacheFile(const string &module, const string &ext, const string &tag1, int tag2, int tag3, int tag4, CacheFile::CacheFile(const string &module, const string &ext, const string &tag1, int tag2, int tag3, int tag4,
int tag5, int tag6) { int tag5, int tag6) {
filepath = QString("cache/%1-%2-%3-%4-%5-%6-%7.%8") ostringstream buf;
.arg(QString::fromStdString(module)) buf << "cache/" << module << "-" << tag1 << "-" << tag2 << "-" << tag3 << "-" << tag4 << "-" << tag5 << "-" << tag6 << "." << ext;
.arg(QString::fromStdString(tag1)) filepath = buf.str();
.arg(tag2)
.arg(tag3)
.arg(tag4)
.arg(tag5)
.arg(tag6)
.arg(QString::fromStdString(ext))
.toStdString();
} }
bool CacheFile::isReadable() { bool CacheFile::isReadable() {

View file

@ -19,7 +19,7 @@ typedef struct {
class CORESHARED_EXPORT CameraDefinition : public DefinitionNode { class CORESHARED_EXPORT CameraDefinition : public DefinitionNode {
public: public:
CameraDefinition(DefinitionNode *parent = NULL); CameraDefinition(DefinitionNode *parent = nullptr);
virtual void save(PackStream *pack) const override; virtual void save(PackStream *pack) const override;
virtual void load(PackStream *pack) override; virtual void load(PackStream *pack) override;

View file

@ -76,7 +76,7 @@ Color CanvasPictureWriter::getRawPixel(int x, int y) {
cache_width = canvas->getWidth(); cache_width = canvas->getWidth();
cache = new Color[cache_width * antialias]; cache = new Color[cache_width * antialias];
CanvasPortion *portion = NULL; CanvasPortion *portion = nullptr;
PackStream *stream = new PackStream; PackStream *stream = new PackStream;
Color *itcolor = cache; Color *itcolor = cache;

View file

@ -9,7 +9,7 @@ CanvasPixel::CanvasPixel() {
const CanvasFragment *CanvasPixel::getFrontFragment() const { const CanvasFragment *CanvasPixel::getFrontFragment() const {
if (count == 0) { if (count == 0) {
return NULL; return nullptr;
} else { } else {
return fragments + (count - 1); return fragments + (count - 1);
} }

View file

@ -41,7 +41,7 @@ void CanvasPixelShader::processParallelUnit(int unit) {
const CanvasPixel &pixel = portion->at(base_x + x, base_y + y); const CanvasPixel &pixel = portion->at(base_x + x, base_y + y);
int n = pixel.getFragmentCount(); int n = pixel.getFragmentCount();
Color composite = COLOR_BLACK; Color composite = COLOR_BLACK;
const CanvasFragment *previous = NULL; const CanvasFragment *previous = nullptr;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
const CanvasFragment &fragment = pixel.getFragment(i); const CanvasFragment &fragment = pixel.getFragment(i);
const Rasterizer &rasterizer = renderer.getRasterizer(fragment.getClient()); const Rasterizer &rasterizer = renderer.getRasterizer(fragment.getClient());

View file

@ -15,7 +15,7 @@
assert(x < width); \ assert(x < width); \
assert(y >= 0); \ assert(y >= 0); \
assert(y < height); \ assert(y < height); \
assert(pixels != NULL) assert(pixels != nullptr)
// Keep track of created files to erase them at program exit // Keep track of created files to erase them at program exit
static vector<string> _files; static vector<string> _files;
@ -31,7 +31,7 @@ CanvasPortion::CanvasPortion(int index, CanvasPreview *preview) : index(index),
height = 1; height = 1;
xoffset = 0; xoffset = 0;
yoffset = 0; yoffset = 0;
pixels = NULL; pixels = nullptr;
} }
CanvasPortion::~CanvasPortion() { CanvasPortion::~CanvasPortion() {
@ -79,7 +79,7 @@ void CanvasPortion::discardPixels(bool save) {
saveToDisk(); saveToDisk();
} }
delete[] pixels; delete[] pixels;
pixels = NULL; pixels = nullptr;
} }
} }

View file

@ -16,7 +16,7 @@ namespace software {
*/ */
class CORESHARED_EXPORT CanvasPortion { class CORESHARED_EXPORT CanvasPortion {
public: public:
CanvasPortion(int index = 0, CanvasPreview *preview = NULL); CanvasPortion(int index = 0, CanvasPreview *preview = nullptr);
virtual ~CanvasPortion(); virtual ~CanvasPortion();
inline int getWidth() const { inline int getWidth() const {

View file

@ -13,7 +13,7 @@ void CloudsDefinition::applyPreset(CloudsPreset preset, RandomGenerator &random)
clear(); clear();
if (preset == CLOUDS_PRESET_PARTLY_CLOUDY) { if (preset == CLOUDS_PRESET_PARTLY_CLOUDY) {
CloudLayerDefinition layer(NULL, "Strato-cumulus"); CloudLayerDefinition layer(nullptr, "Strato-cumulus");
layer.type = CloudLayerDefinition::STRATOCUMULUS; layer.type = CloudLayerDefinition::STRATOCUMULUS;
layer.noise_state.randomizeOffsets(random); layer.noise_state.randomizeOffsets(random);
addLayer(layer); addLayer(layer);

View file

@ -20,7 +20,7 @@ CloudsRenderer::CloudsRenderer(SoftwareRenderer *parent) : parent(parent) {
enabled = true; enabled = true;
fake_renderer = new BaseCloudLayerRenderer(parent); fake_renderer = new BaseCloudLayerRenderer(parent);
CloudLayerDefinition *fake_layer = new CloudLayerDefinition(NULL, "#fake#"); CloudLayerDefinition *fake_layer = new CloudLayerDefinition(nullptr, "#fake#");
fake_model = new BaseCloudsModel(fake_layer); fake_model = new BaseCloudsModel(fake_layer);
} }

View file

@ -1,16 +1,18 @@
#include "DataFile.h" #include "DataFile.h"
#include "Logs.h" #include "Logs.h"
#include <QDir> #include <filesystem>
using namespace std::filesystem;
string DataFile::findFile(const string &relpath) { string DataFile::findFile(const string &relpath) {
if (dataDir.empty()) { if (dataDir.empty()) {
dataDir = initDataDir(); dataDir = initDataDir();
} }
QDir dir(QString::fromStdString(dataDir)); auto absPath = path(dataDir) / path(relpath);
if (dir.exists(QString::fromStdString(relpath))) { if (exists(absPath)) {
return dir.absoluteFilePath(QString::fromStdString(relpath)).toStdString(); return absPath;
} else { } else {
return ""; return "";
} }
@ -20,28 +22,29 @@ string DataFile::findDir(const string &relpath) {
return findFile(relpath); return findFile(relpath);
} }
bool DataFile::tryDataDir(const QDir &dir) { bool DataFile::tryDataDir(const string &dir) {
Logs::debug("System") << "Try data dir " << dir.absolutePath().toStdString() << endl; const auto abs_path = absolute(path(dir));
return dir.exists("data/.paysages_data"); Logs::debug("System") << "Try data dir " << abs_path << endl;
return exists(abs_path / path("data") / path(".paysages_data"));
} }
string DataFile::locateDataDir() { string DataFile::locateDataDir() {
QDir dir = QDir::current(); auto dir = absolute(current_path());
int i = 0; int i = 0;
// TODO /usr/share/paysages3d/ // TODO /usr/share/paysages3d/
while (i++ < 100 and not dir.isRoot()) { while (i++ < 100 and dir.has_parent_path()) {
if (tryDataDir(dir)) { if (tryDataDir(dir)) {
return dir.absolutePath().toStdString(); return dir;
} }
QDir dir2(dir.absoluteFilePath("paysages3d")); const auto dir2 = dir / path("paysages3d");
if (tryDataDir(dir2)) { if (tryDataDir(dir2)) {
return dir2.absolutePath().toStdString(); return dir2;
} }
dir = QDir(QDir(dir.absoluteFilePath("..")).canonicalPath()); dir = dir.parent_path();
} }
return ""; return "";
@ -53,7 +56,7 @@ string DataFile::initDataDir() {
Logs::warning("System") << "Data files not found" << endl; Logs::warning("System") << "Data files not found" << endl;
return parent; return parent;
} else { } else {
string result = QDir(QString::fromStdString(parent)).absoluteFilePath("data").toStdString(); string result = parent / path("data");
Logs::debug("System") << "Data files found : " << result << endl; Logs::debug("System") << "Data files found : " << result << endl;
return result; return result;
} }

View file

@ -29,7 +29,7 @@ class CORESHARED_EXPORT DataFile {
static string findDir(const string &relpath); static string findDir(const string &relpath);
private: private:
static bool tryDataDir(const QDir &dir); static bool tryDataDir(const string &dir);
static string locateDataDir(); static string locateDataDir();
static string initDataDir(); static string initDataDir();
static string dataDir; static string dataDir;

View file

@ -27,7 +27,7 @@ DefinitionNode::DefinitionNode(DefinitionNode *parent, const string &name, const
: parent(parent), type_name(type_name), name(name) { : parent(parent), type_name(type_name), name(name) {
if (parent) { if (parent) {
root = parent->root; root = parent->root;
diffs = NULL; diffs = nullptr;
parent->addChild(this); parent->addChild(this);
} else { } else {
root = this; root = this;
@ -38,12 +38,12 @@ DefinitionNode::DefinitionNode(DefinitionNode *parent, const string &name, const
DefinitionNode::~DefinitionNode() { DefinitionNode::~DefinitionNode() {
if (parent) { if (parent) {
parent->removeChild(this); parent->removeChild(this);
parent = NULL; parent = nullptr;
} }
if (diffs) { if (diffs) {
delete diffs; delete diffs;
diffs = NULL; diffs = nullptr;
} }
// Work on a copy, because the child destructor will modify the array by removing itself using removeChild // Work on a copy, because the child destructor will modify the array by removing itself using removeChild
@ -63,7 +63,7 @@ const Scenery *DefinitionNode::getScenery() const {
if (parent) { if (parent) {
return parent->getScenery(); return parent->getScenery();
} else { } else {
return NULL; return nullptr;
} }
} }
@ -93,7 +93,7 @@ string DefinitionNode::getPath() const {
DefinitionNode *DefinitionNode::findByPath(const string &path) const { DefinitionNode *DefinitionNode::findByPath(const string &path) const {
if (path.empty()) { if (path.empty()) {
return NULL; return nullptr;
} else if (path[0] == '/') { } else if (path[0] == '/') {
if (path.length() == 1) { if (path.length() == 1) {
return root; return root;
@ -113,7 +113,7 @@ DefinitionNode *DefinitionNode::findByPath(const string &path) const {
return child->findByPath(path.substr(seppos + 1)); return child->findByPath(path.substr(seppos + 1));
} }
} else { } else {
return NULL; return nullptr;
} }
} }
} }
@ -218,7 +218,7 @@ void DefinitionNode::addChild(DefinitionNode *child) {
void DefinitionNode::removeChild(DefinitionNode *child) { void DefinitionNode::removeChild(DefinitionNode *child) {
vector<DefinitionNode *>::iterator it = find(children.begin(), children.end(), child); vector<DefinitionNode *>::iterator it = find(children.begin(), children.end(), child);
if (it != children.end()) { if (it != children.end()) {
child->parent = NULL; child->parent = nullptr;
children.erase(it); children.erase(it);
} else { } else {
Logs::warning("Definition") << "Trying to remove not found child '" << child->name << "' from '" << name << "'" Logs::warning("Definition") << "Trying to remove not found child '" << child->name << "' from '" << name << "'"
@ -232,7 +232,7 @@ DefinitionNode *DefinitionNode::findChildByName(const string &name) const {
return child; return child;
} }
} }
return NULL; return nullptr;
} }
void DefinitionNode::tellChanged() { void DefinitionNode::tellChanged() {
@ -267,7 +267,7 @@ void DefinitionNode::setRoot(DefinitionNode *root) {
this->root = root; this->root = root;
if (diffs) { if (diffs) {
delete diffs; delete diffs;
diffs = NULL; diffs = nullptr;
} }
for (auto &child : children) { for (auto &child : children) {
child->setRoot(root); child->setRoot(root);

View file

@ -59,7 +59,7 @@ class CORESHARED_EXPORT DefinitionNode {
/** /**
* Find a node in this tree, by its path (as returned by getPath). * Find a node in this tree, by its path (as returned by getPath).
* *
* Return NULL if the path does not exists. * Return nullptr if the path does not exists.
*/ */
DefinitionNode *findByPath(const string &path) const; DefinitionNode *findByPath(const string &path) const;

View file

@ -1,20 +1,27 @@
#include "FileSystem.h" #include "FileSystem.h"
#include <QDir> #include <filesystem>
#include <QFileInfo>
#include <cstdio> using namespace std::filesystem;
string FileSystem::getTempFile(const string &filename) { string FileSystem::getTempFile(const string &filename) {
return QDir::temp().filePath(QString::fromStdString(filename)).toStdString(); const auto temp_dir = temp_directory_path() / path("paysages3d");
if (!exists(temp_dir)) {
create_directory(temp_dir);
}
return temp_dir / path(filename);
} }
bool FileSystem::isFile(const string &filepath) { bool FileSystem::isFile(const string &filepath) {
return QFileInfo(QString::fromStdString(filepath)).exists(); const auto path(filepath);
return exists(path) && is_regular_file(path);
} }
bool FileSystem::removeFile(const string &filepath) { bool FileSystem::removeFile(const string &filepath) {
if (FileSystem::isFile(filepath)) { const auto path(filepath);
remove(filepath.c_str());
if (exists(path) && is_regular_file(path)) {
remove(filepath);
return true; return true;
} else { } else {
return false; return false;

View file

@ -19,9 +19,9 @@
GodRaysSampler::GodRaysSampler() { GodRaysSampler::GodRaysSampler() {
enabled = true; enabled = true;
bounds = new SpaceSegment(); bounds = new SpaceSegment();
definition = new GodRaysDefinition(NULL); definition = new GodRaysDefinition(nullptr);
camera_location = new Vector3(0, 0, 0); camera_location = new Vector3(0, 0, 0);
lighting = NULL; lighting = nullptr;
low_altitude = -1.0; low_altitude = -1.0;
high_altitude = 1.0; high_altitude = 1.0;
sampling_step = 1.0; sampling_step = 1.0;

View file

@ -90,7 +90,7 @@ bool Layers::applyDiff(const DefinitionDiff *diff, bool backward) {
Logs::error("Definition") << "Add layer ignored because requested position was incorrect" << endl; Logs::error("Definition") << "Add layer ignored because requested position was incorrect" << endl;
return false; return false;
} else { } else {
DefinitionNode *layer = layer_constructor(NULL, "temp"); DefinitionNode *layer = layer_constructor(nullptr, "temp");
layer_diff->restoreSavedLayer(layer); layer_diff->restoreSavedLayer(layer);
if (position == layer_count) { if (position == layer_count) {
layers.push_back(layer); layers.push_back(layer);
@ -134,7 +134,7 @@ void Layers::addLayer(const DefinitionNode &tocopy) {
} }
void Layers::addLayer(const string &name) { void Layers::addLayer(const string &name) {
auto layer = layer_constructor(NULL, name); auto layer = layer_constructor(nullptr, name);
addLayer(*layer); addLayer(*layer);
delete layer; delete layer;
} }

View file

@ -5,11 +5,11 @@
#include "PackStream.h" #include "PackStream.h"
LayersDiff::LayersDiff(const Layers *layers, LayersDiffOp op, int layer1) LayersDiff::LayersDiff(const Layers *layers, LayersDiffOp op, int layer1)
: DefinitionDiff(layers), op(op), layer1(layer1), saved(NULL) { : DefinitionDiff(layers), op(op), layer1(layer1), saved(nullptr) {
} }
LayersDiff::LayersDiff(const LayersDiff *other, LayersDiff::LayersDiffOp op, int layer1) LayersDiff::LayersDiff(const LayersDiff *other, LayersDiff::LayersDiffOp op, int layer1)
: DefinitionDiff(other), op(op), layer1(layer1), saved(NULL) { : DefinitionDiff(other), op(op), layer1(layer1), saved(nullptr) {
} }
LayersDiff::~LayersDiff() { LayersDiff::~LayersDiff() {

View file

@ -12,7 +12,7 @@
class MoonRenderer::pimpl { class MoonRenderer::pimpl {
public: public:
pimpl() : definition(NULL, "moon") { pimpl() : definition(nullptr, "moon") {
} }
CelestialBodyDefinition definition; CelestialBodyDefinition definition;
}; };

View file

@ -621,7 +621,7 @@ double NoiseFunctionSimplex::getBase3d(double x, double y, double z) const {
} }
static constexpr double TEXTURE_SCALING = 15.0; static constexpr double TEXTURE_SCALING = 15.0;
static Texture2D *_valueTexture = NULL; static Texture2D *_valueTexture = nullptr;
const Texture2D *NoiseFunctionSimplex::getValueTexture() { const Texture2D *NoiseFunctionSimplex::getValueTexture() {
if (!_valueTexture) { if (!_valueTexture) {
@ -644,7 +644,7 @@ const Texture2D *NoiseFunctionSimplex::getValueTexture() {
return _valueTexture; return _valueTexture;
} }
static Texture2D *_normalTexture = NULL; static Texture2D *_normalTexture = nullptr;
const Texture2D *NoiseFunctionSimplex::getNormalTexture() { const Texture2D *NoiseFunctionSimplex::getNormalTexture() {
if (!_normalTexture) { if (!_normalTexture) {

View file

@ -1,163 +1,137 @@
#include "PackStream.h" #include "PackStream.h"
#include "Logs.h" #include "Logs.h"
#include <QByteArray>
#include <QDataStream> #include <cstring>
#include <QFile> #include <fstream>
#include <QString> #include <sstream>
class PackStream::pimpl { class PackStream::pimpl {
public: public:
QFile *file; fstream *file;
QByteArray *buffer; stringstream *buffer;
QDataStream *stream; iostream* stream;
}; };
PackStream::PackStream() : pv(new pimpl) { PackStream::PackStream() : pv(new pimpl) {
pv->file = NULL; pv->file = new fstream();
pv->buffer = new QByteArray(); pv->buffer = new stringstream();
pv->stream = new QDataStream(pv->buffer, QIODevice::WriteOnly); pv->stream = pv->buffer;
pv->stream->setVersion(QDataStream::Qt_5_4);
} }
PackStream::PackStream(const PackStream *other) : pv(new pimpl) { PackStream::PackStream(const PackStream *other) : pv(new pimpl) {
pv->file = NULL; pv->file = new fstream();
pv->buffer = new QByteArray(); pv->buffer = new stringstream();
if (other->pv->file) { if (other->pv->file->is_open()) {
Logs::error("System") << "Try to read from a substream bound to a file: " Logs::error("System") << "Try to read from a substream bound to a file: "
<< other->pv->file->fileName().toStdString() << endl; << other->pv->file << endl;
pv->stream = new QDataStream(pv->buffer, QIODevice::ReadOnly);
} else { } else {
pv->stream = new QDataStream(other->pv->buffer, QIODevice::ReadOnly); other->pv->buffer->seekg(0);
other->pv->buffer->get(*pv->buffer->rdbuf());
} }
pv->stream->setVersion(QDataStream::Qt_5_4); pv->stream = pv->buffer;
} }
PackStream::PackStream(const string &buffer_content) : pv(new pimpl) { PackStream::PackStream(const string &buffer_content) : pv(new pimpl) {
pv->file = NULL; pv->file = new fstream();
pv->buffer = new QByteArray(buffer_content.c_str(), buffer_content.size()); pv->buffer = new stringstream(buffer_content);
pv->stream = new QDataStream(pv->buffer, QIODevice::ReadOnly); pv->stream = pv->buffer;
pv->stream->setVersion(QDataStream::Qt_5_4);
} }
PackStream::~PackStream() { PackStream::~PackStream() {
delete pv->file;
delete pv->buffer; delete pv->buffer;
delete pv->stream;
if (pv->file) {
delete pv->file;
}
} }
bool PackStream::bindToFile(const string &filepath, bool write) { bool PackStream::bindToFile(const string &filepath, bool write) {
if (not pv->file) { if (pv->file->is_open()) {
pv->file = new QFile(QString::fromStdString(filepath)); return false;
if (not pv->file->open(write ? QIODevice::WriteOnly : QIODevice::ReadOnly)) { } else {
return false; pv->file->open(filepath, write ? ios_base::out : ios_base::in);
} if (pv->file->is_open()) {
pv->stream = pv->file;
QDataStream *new_stream = new QDataStream(pv->file);
if (new_stream) {
delete pv->stream;
pv->stream = new_stream;
pv->stream->setVersion(QDataStream::Qt_5_4);
return true; return true;
} else { } else {
return false; return false;
} }
} else {
return false;
} }
} }
void PackStream::write(const int *value) { void PackStream::write(const int *value) {
if (value) { if (value) {
*pv->stream << *value; // TODO endianness and int size portability
pv->stream->write(reinterpret_cast<const char*>(value), sizeof(int));
} }
} }
void PackStream::write(const double *value) { void PackStream::write(const double *value) {
if (value) { if (value) {
*pv->stream << *value; // TODO float format portability
} pv->stream->write(reinterpret_cast<const char*>(value), sizeof(double));
}
void PackStream::write(const char *value, int max_length) {
if (value) {
int length = qstrlen(value);
*pv->stream << QString::fromUtf8(value, length > max_length ? max_length : length);
} }
} }
void PackStream::write(const string &value) { void PackStream::write(const string &value) {
*pv->stream << QString::fromStdString(value); const int length = value.length();
write(&length);
pv->stream->write(value.c_str(), length);
} }
void PackStream::writeFromBuffer(const PackStream &other, bool prepend_size) { void PackStream::writeFromBuffer(const PackStream &other, bool prepend_size) {
if (other.pv->file) { if (other.pv->file->is_open()) {
Logs::error("System") << "Try to write from a substream bound to a file: " Logs::error("System") << "Try to write from a substream bound to a file: "
<< other.pv->file->fileName().toStdString() << endl; << other.pv->file << endl;
} else { } else {
int buffer_size = other.pv->buffer->rdbuf()->str().length();
if (prepend_size) { if (prepend_size) {
int buffer_size = (int)other.pv->buffer->size();
write(&buffer_size); write(&buffer_size);
} }
pv->stream->writeRawData(other.pv->buffer->data(), other.pv->buffer->size()); pv->stream->write(other.pv->buffer->rdbuf()->str().c_str(), buffer_size);
} }
} }
string PackStream::getBuffer() { string PackStream::getBuffer() {
if (pv->file) { if (pv->file->is_open()) {
Logs::error("System") << "Try to get buffer on a stream bound to a file: " << pv->file->fileName().toStdString() Logs::error("System") << "Try to get buffer on a stream bound to a file: " << pv->file << endl;
<< endl;
return ""; return "";
} else { } else {
return pv->buffer->toStdString(); return pv->buffer->rdbuf()->str();
} }
} }
void PackStream::read(int *value) { void PackStream::read(int *value) {
if (value and not pv->stream->atEnd()) { if (value and not pv->stream->eof()) {
int output; pv->stream->read(reinterpret_cast<char*>(value), sizeof(int));
*pv->stream >> output;
*value = output;
} }
} }
void PackStream::read(double *value) { void PackStream::read(double *value) {
if (value and not pv->stream->atEnd()) { if (value and not pv->stream->eof()) {
double output; pv->stream->read(reinterpret_cast<char*>(value), sizeof(double));
*pv->stream >> output;
*value = output;
}
}
void PackStream::read(char *value, int max_length) {
if (value and not pv->stream->atEnd()) {
QString output;
*pv->stream >> output;
QByteArray array = output.toUtf8();
qstrncpy(value, array.constData(), max_length);
} }
} }
string PackStream::readString() { string PackStream::readString() {
if (not pv->stream->atEnd()) { if (not pv->stream->eof()) {
QString output; int size;
*pv->stream >> output; read(&size);
return output.toStdString(); if (size > 0) {
} else { std::string str(size, '\0');
return ""; pv->stream->read(&str[0], size);
return str;
}
} }
return "";
} }
void PackStream::skip(const int &value, int count) { void PackStream::skip(const int &value, int count) {
pv->stream->skipRawData(sizeof(value) * count); skipBytes(sizeof(value) * count);
} }
void PackStream::skip(const double &value, int count) { void PackStream::skip(const double &value, int count) {
pv->stream->skipRawData(sizeof(value) * count); skipBytes(sizeof(value) * count);
} }
void PackStream::skipBytes(int bytes) { void PackStream::skipBytes(int bytes) {
pv->stream->skipRawData(bytes); pv->stream->seekg(bytes, ios_base::cur);
} }

View file

@ -30,7 +30,6 @@ class CORESHARED_EXPORT PackStream {
void write(const int *value); void write(const int *value);
void write(const double *value); void write(const double *value);
void write(const char *value, const int max_length);
void write(const string &value); void write(const string &value);
/** /**
@ -49,7 +48,6 @@ class CORESHARED_EXPORT PackStream {
void read(int *value); void read(int *value);
void read(double *value); void read(double *value);
void read(char *value, int max_length);
string readString(); string readString();
void skip(const int &value, int count = 1); void skip(const int &value, int count = 1);

View file

@ -44,7 +44,7 @@ bool PaintedGrid::getInterpolatedValue(double x, double y, double *result) const
int hit = 0; int hit = 0;
for (ix = xlow - 1; ix <= xlow + 2 && !hit; ix++) { for (ix = xlow - 1; ix <= xlow + 2 && !hit; ix++) {
for (iy = ylow - 1; iy <= ylow + 2 && !hit; iy++) { for (iy = ylow - 1; iy <= ylow + 2 && !hit; iy++) {
if (getDataPointer(brush_data, x, y, NULL, false) || getDataPointer(merged_data, x, y, NULL, false)) { if (getDataPointer(brush_data, x, y, nullptr, false) || getDataPointer(merged_data, x, y, nullptr, false)) {
hit = 1; hit = 1;
} }
} }
@ -70,12 +70,12 @@ bool PaintedGrid::getInterpolatedValue(double x, double y, double *result) const
bool PaintedGrid::getGridValue(int x, int y, double *result) const { bool PaintedGrid::getGridValue(int x, int y, double *result) const {
double *dpointer; double *dpointer;
dpointer = getDataPointer(brush_data, x, y, NULL, false); dpointer = getDataPointer(brush_data, x, y, nullptr, false);
if (dpointer) { if (dpointer) {
*result = *dpointer; *result = *dpointer;
return true; return true;
} else { } else {
dpointer = getDataPointer(merged_data, x, y, NULL, false); dpointer = getDataPointer(merged_data, x, y, nullptr, false);
if (dpointer) { if (dpointer) {
*result = *dpointer; *result = *dpointer;
return true; return true;
@ -100,7 +100,7 @@ bool PaintedGrid::hasPainting() const {
} }
bool PaintedGrid::isPainted(int x, int y) const { bool PaintedGrid::isPainted(int x, int y) const {
return getDataPointer(brush_data, x, y, NULL, false) || getDataPointer(merged_data, x, y, NULL, false); return getDataPointer(brush_data, x, y, nullptr, false) || getDataPointer(merged_data, x, y, nullptr, false);
} }
unsigned long PaintedGrid::getMemoryStats() const { unsigned long PaintedGrid::getMemoryStats() const {
@ -147,7 +147,7 @@ void PaintedGrid::endBrushStroke() {
for (j = 0; j < data->rows[i].pixel_groups_count; j++) { for (j = 0; j < data->rows[i].pixel_groups_count; j++) {
for (k = 0; k < data->rows[i].pixel_groups[j].xend - data->rows[i].pixel_groups[j].xstart + 1; k++) { for (k = 0; k < data->rows[i].pixel_groups[j].xend - data->rows[i].pixel_groups[j].xstart + 1; k++) {
double *dpointer = double *dpointer =
getDataPointer(merged_data, data->rows[i].pixel_groups[j].xstart + k, data->rows[i].y, NULL, true); getDataPointer(merged_data, data->rows[i].pixel_groups[j].xstart + k, data->rows[i].y, nullptr, true);
*dpointer = data->rows[i].pixel_groups[j].height[k]; *dpointer = data->rows[i].pixel_groups[j].height[k];
} }
} }
@ -183,7 +183,7 @@ double *PaintedGrid::getDataPointer(PaintedGridData *data, int x, int y, Painted
data->rows_count++; data->rows_count++;
data->memsize += sizeof(PaintedGridData::HeightMapRow); data->memsize += sizeof(PaintedGridData::HeightMapRow);
} else { } else {
return NULL; return nullptr;
} }
#ifndef NDEBUG #ifndef NDEBUG
@ -194,7 +194,7 @@ double *PaintedGrid::getDataPointer(PaintedGridData *data, int x, int y, Painted
#endif #endif
/* Find pixel group */ /* Find pixel group */
PaintedGridData::HeightMapPixelGroup *pixel_group = NULL; PaintedGridData::HeightMapPixelGroup *pixel_group = nullptr;
for (i = 0; i < row->pixel_groups_count; i++) { for (i = 0; i < row->pixel_groups_count; i++) {
if (x < row->pixel_groups[i].xstart - 1) { if (x < row->pixel_groups[i].xstart - 1) {
break; break;
@ -214,7 +214,7 @@ double *PaintedGrid::getDataPointer(PaintedGridData *data, int x, int y, Painted
int added = 1; int added = 1;
if (!pixel_group) { if (!pixel_group) {
if (!grow) { if (!grow) {
return NULL; return nullptr;
} }
/* Create the pixel group with one pixel */ /* Create the pixel group with one pixel */
@ -231,7 +231,7 @@ double *PaintedGrid::getDataPointer(PaintedGridData *data, int x, int y, Painted
data->memsize += sizeof(PaintedGridData::HeightMapPixelGroup) + sizeof(double); data->memsize += sizeof(PaintedGridData::HeightMapPixelGroup) + sizeof(double);
} else if (x == pixel_group->xstart - 1) { } else if (x == pixel_group->xstart - 1) {
if (!grow) { if (!grow) {
return NULL; return nullptr;
} }
/* Extend the rowgroup at start */ /* Extend the rowgroup at start */
@ -241,7 +241,7 @@ double *PaintedGrid::getDataPointer(PaintedGridData *data, int x, int y, Painted
data->memsize += sizeof(double); data->memsize += sizeof(double);
} else if (x == pixel_group->xend + 1) { } else if (x == pixel_group->xend + 1) {
if (!grow) { if (!grow) {
return NULL; return nullptr;
} }
/* Extend the rowgroup at end */ /* Extend the rowgroup at end */
@ -273,7 +273,7 @@ double *PaintedGrid::getDataPointer(PaintedGridData *data, int x, int y, Painted
/* Reset pixel if it had been added */ /* Reset pixel if it had been added */
if (added) { if (added) {
if (fallback) { if (fallback) {
double *dpointer = getDataPointer(fallback, x, y, NULL, false); double *dpointer = getDataPointer(fallback, x, y, nullptr, false);
if (dpointer) { if (dpointer) {
*pixel = *dpointer; *pixel = *dpointer;
} else { } else {

View file

@ -1,12 +1,13 @@
#include "ParallelPool.h" #include "ParallelPool.h"
#include "Logs.h"
#include "System.h" #include "System.h"
#include "Thread.h" #include "Thread.h"
static void *_threadFunction(void *data) { static void *_threadFunction(void *data) {
ParallelPool *pool = (ParallelPool *)data; ParallelPool *pool = (ParallelPool *)data;
pool->work(); pool->work();
return NULL; return nullptr;
} }
ParallelPool::ParallelPool() { ParallelPool::ParallelPool() {
@ -26,7 +27,7 @@ ParallelPool::~ParallelPool() {
void ParallelPool::start(int thread_count) { void ParallelPool::start(int thread_count) {
if (running) { if (running) {
qCritical("Starting an already started parallel pool !"); Logs::error("System") << "Starting an already started parallel pool !" << endl;
return; return;
} }
running = true; running = true;

View file

@ -1,7 +1,5 @@
#include "PictureWriter.h" #include "PictureWriter.h"
#include <QImage>
PictureWriter::PictureWriter() { PictureWriter::PictureWriter() {
} }
@ -9,7 +7,7 @@ PictureWriter::~PictureWriter() {
} }
bool PictureWriter::save(const string &filepath, int width, int height) { bool PictureWriter::save(const string &filepath, int width, int height) {
QImage result(width, height, QImage::Format_ARGB32); /*QImage result(width, height, QImage::Format_ARGB32);
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
@ -17,5 +15,7 @@ bool PictureWriter::save(const string &filepath, int width, int height) {
} }
} }
return result.save(QString::fromStdString(filepath)); return result.save(QString::fromStdString(filepath));*/
// TODO
return false;
} }

View file

@ -19,7 +19,7 @@
static const double APP_HEADER = 19866544632.125; static const double APP_HEADER = 19866544632.125;
static const int DATA_VERSION = 1; static const int DATA_VERSION = 1;
Scenery::Scenery() : DefinitionNode(NULL, "scenery", "scenery") { Scenery::Scenery() : DefinitionNode(nullptr, "scenery", "scenery") {
atmosphere = new AtmosphereDefinition(this); atmosphere = new AtmosphereDefinition(this);
camera = new CameraDefinition(this); camera = new CameraDefinition(this);
clouds = new CloudsDefinition(this); clouds = new CloudsDefinition(this);

View file

@ -1,4 +1,4 @@
#include "Semaphore.h" #include "Semaphore.h"
Semaphore::Semaphore(int resources) : QSemaphore(resources) { Semaphore::Semaphore(int resources) : resources(resources) {
} }

View file

@ -2,21 +2,29 @@
#include "core_global.h" #include "core_global.h"
#include <QSemaphore> #include <mutex>
#include <condition_variable>
namespace paysages { namespace paysages {
namespace system { namespace system {
class Semaphore : private QSemaphore { class Semaphore {
public: public:
Semaphore(int resources); Semaphore(int resources);
inline void acquire() { inline void acquire() {
QSemaphore::acquire(); unique_lock lk(mex);
cond.wait(lk, [this]{ return resources > 0; });
} }
inline void release() { inline void release() {
QSemaphore::release(); lock_guard lk(mex);
resources++;
cond.notify_one();
} }
private:
int resources;
condition_variable cond;
mutex mex;
}; };
} }
} }

View file

@ -32,7 +32,7 @@ SoftwareCanvasRenderer::SoftwareCanvasRenderer(Scenery *scenery) : SoftwareRende
rasterizers.push_back(rasterizer_vegetation = rasterizers.push_back(rasterizer_vegetation =
new VegetationRasterizer(this, progress, RASTERIZER_CLIENT_VEGETATION)); new VegetationRasterizer(this, progress, RASTERIZER_CLIENT_VEGETATION));
current_work = NULL; current_work = nullptr;
setQuality(0.5); setQuality(0.5);
} }
@ -170,7 +170,7 @@ void SoftwareCanvasRenderer::applyPixelShader(CanvasPortion *portion) {
current_work = &work; current_work = &work;
work.perform(); work.perform();
current_work = NULL; current_work = nullptr;
} }
progress->exitSub(); progress->exitSub();
} }

View file

@ -1,16 +1,18 @@
#include "System.h" #include "System.h"
#include <QCoreApplication> #include "Logs.h"
#include <QThread>
#include <unistd.h>
#include <thread>
static int core_count = -1; static int core_count = -1;
int System::getCoreCount() { int System::getCoreCount() {
if (core_count < 0) { if (core_count < 0) {
#ifdef NDEBUG #ifdef NDEBUG
core_count = QThread::idealThreadCount(); core_count = thread::hardware_concurrency();
if (core_count <= 0) { if (core_count <= 0) {
qWarning("Can't find number of CPU cores, using only 1"); Logs::warning("System") << "Can't find number of CPU cores, using only 1" << endl;
core_count = 1; core_count = 1;
} }
#else #else
@ -21,5 +23,5 @@ int System::getCoreCount() {
} }
int System::getProcessId() { int System::getProcessId() {
return QCoreApplication::applicationPid(); return getpid();
} }

View file

@ -215,7 +215,7 @@ void TerrainRasterizer::processChunk(CanvasPortion *canvas, TerrainChunkInfo *ch
int TerrainRasterizer::prepareRasterization() { int TerrainRasterizer::prepareRasterization() {
// TODO Chunks could be saved and reused in rasterizeToCanvas // TODO Chunks could be saved and reused in rasterizeToCanvas
return performTessellation(NULL); return performTessellation(nullptr);
} }
void TerrainRasterizer::rasterizeToCanvas(CanvasPortion *canvas) { void TerrainRasterizer::rasterizeToCanvas(CanvasPortion *canvas) {

View file

@ -56,7 +56,7 @@ class CORESHARED_EXPORT TerrainRasterizer : public Rasterizer {
* *
* Return the number of quads that has been pushed. * Return the number of quads that has been pushed.
* *
* 'canvas' may be NULL to only simulate the tessellation. * 'canvas' may be nullptr to only simulate the tessellation.
*/ */
int performTessellation(CanvasPortion *canvas); int performTessellation(CanvasPortion *canvas);

View file

@ -10,7 +10,7 @@ TexturesDefinition::TexturesDefinition(DefinitionNode *parent) : Layers(parent,
} }
void TexturesDefinition::applyPreset(TexturesPreset preset, RandomGenerator &random) { void TexturesDefinition::applyPreset(TexturesPreset preset, RandomGenerator &random) {
TextureLayerDefinition layer(NULL, "temp"); TextureLayerDefinition layer(nullptr, "temp");
clear(); clear();
layer.applyPreset(TextureLayerDefinition::TEXTURES_LAYER_PRESET_MUD, random); layer.applyPreset(TextureLayerDefinition::TEXTURES_LAYER_PRESET_MUD, random);

View file

@ -1,18 +1,25 @@
#include "Thread.h" #include "Thread.h"
Thread::Thread(ThreadFunction function) : data(0), result(0), function(function) { Thread::Thread(ThreadFunction function) : data(0), result(0), function(function) {
go.lock();
systhread = new thread([this]{ wait(); });
} }
Thread::~Thread() { Thread::~Thread() {
} }
void Thread::wait() {
unique_lock lock(go);
run();
}
void Thread::start(void *data) { void Thread::start(void *data) {
this->data = data; this->data = data;
QThread::start(); go.unlock();
} }
void *Thread::join() { void *Thread::join() {
QThread::wait(); systhread->join();
return result; return result;
} }

View file

@ -1,7 +1,10 @@
#pragma once #pragma once
#include "core_global.h" #include "core_global.h"
#include <QThread>
#include <thread>
#include <mutex>
#include <chrono>
namespace paysages { namespace paysages {
namespace system { namespace system {
@ -11,7 +14,7 @@ typedef void *(*ThreadFunction)(void *data);
/** /**
* System thread * System thread
*/ */
class CORESHARED_EXPORT Thread : private QThread { class CORESHARED_EXPORT Thread {
public: public:
/** /**
* Create a new thread. * Create a new thread.
@ -41,11 +44,11 @@ class CORESHARED_EXPORT Thread : private QThread {
* Return true if the thread is currently running. * Return true if the thread is currently running.
*/ */
inline bool isWorking() const { inline bool isWorking() const {
return not isFinished(); return systhread->joinable();
} }
static inline void timeSleepMs(unsigned long ms) { static inline void timeSleepMs(unsigned long ms) {
QThread::msleep(ms); this_thread::sleep_for(chrono::milliseconds(ms));
} }
protected: protected:
@ -58,7 +61,11 @@ class CORESHARED_EXPORT Thread : private QThread {
void *result; void *result;
private: private:
void wait();
ThreadFunction function; ThreadFunction function;
thread* systhread;
mutex go;
}; };
} }
} }

View file

@ -1,9 +1,10 @@
#include "Timing.h" #include "Timing.h"
#include <QTime> #include <chrono>
using namespace std::chrono;
static QTime EPOCH = QTime::currentTime(); const auto EPOCH = steady_clock::now();
unsigned long Timing::getRelativeTimeMs() { unsigned long Timing::getRelativeTimeMs() {
return EPOCH.msecsTo(QTime::currentTime()); return duration_cast<milliseconds>(steady_clock::now() - EPOCH).count();
} }

View file

@ -36,7 +36,7 @@ void VegetationRasterizer::rasterizeToCanvas(CanvasPortion *canvas) {
} }
Color VegetationRasterizer::shadeFragment(const CanvasFragment &fragment, const CanvasFragment *previous) const { Color VegetationRasterizer::shadeFragment(const CanvasFragment &fragment, const CanvasFragment *previous) const {
assert(previous != NULL); assert(previous != nullptr);
if (not fragment.isFrontFacing() or previous->getClient() == RASTERIZER_CLIENT_SKY) { if (not fragment.isFrontFacing() or previous->getClient() == RASTERIZER_CLIENT_SKY) {
// This is an exit fragment, or the last before sky // This is an exit fragment, or the last before sky
@ -44,7 +44,7 @@ Color VegetationRasterizer::shadeFragment(const CanvasFragment &fragment, const
} }
// Even if we assert, this may happen in rare circumstances (no opaque background fragment), so don't crash // Even if we assert, this may happen in rare circumstances (no opaque background fragment), so don't crash
if (previous == NULL) { if (previous == nullptr) {
return COLOR_TRANSPARENT; return COLOR_TRANSPARENT;
} }

View file

@ -33,7 +33,7 @@ void WaterRasterizer::rasterizeQuad(CanvasPortion *canvas, double x, double z, d
} }
int WaterRasterizer::prepareRasterization() { int WaterRasterizer::prepareRasterization() {
return performTessellation(NULL); return performTessellation(nullptr);
} }
void WaterRasterizer::rasterizeToCanvas(CanvasPortion *canvas) { void WaterRasterizer::rasterizeToCanvas(CanvasPortion *canvas) {

View file

@ -4,6 +4,8 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT -= core gui
TARGET = paysages_core TARGET = paysages_core
TEMPLATE = lib TEMPLATE = lib

View file

@ -33,7 +33,7 @@ static void displayHelp() {
int main(int argc, char **argv) { int main(int argc, char **argv) {
SoftwareCanvasRenderer *renderer; SoftwareCanvasRenderer *renderer;
char *conf_file_path = NULL; char *conf_file_path = nullptr;
RenderConfig conf_render_params(480, 270, 1, 3); RenderConfig conf_render_params(480, 270, 1, 3);
int conf_first_picture = 0; int conf_first_picture = 0;
int conf_nb_pictures = 1; int conf_nb_pictures = 1;

View file

@ -112,7 +112,7 @@ static void testGroundShadowQuality() {
scenery.getAtmosphere()->applyPreset(AtmosphereDefinition::ATMOSPHERE_PRESET_CLEAR_SUNSET, random); scenery.getAtmosphere()->applyPreset(AtmosphereDefinition::ATMOSPHERE_PRESET_CLEAR_SUNSET, random);
scenery.getAtmosphere()->setDayTime(16, 45); scenery.getAtmosphere()->setDayTime(16, 45);
scenery.getTextures()->clear(); scenery.getTextures()->clear();
TextureLayerDefinition texture(NULL, "test"); TextureLayerDefinition texture(nullptr, "test");
texture.applyPreset(TextureLayerDefinition::TEXTURES_LAYER_PRESET_ROCK); texture.applyPreset(TextureLayerDefinition::TEXTURES_LAYER_PRESET_ROCK);
texture.terrain_zone->clear(); texture.terrain_zone->clear();
scenery.getTextures()->addLayer(texture); scenery.getTextures()->addLayer(texture);
@ -356,7 +356,7 @@ static void testVegetationModels() {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// TODO Make random sequence repeatable // TODO Make random sequence repeatable
VegetationModelDefinition model(NULL); VegetationModelDefinition model(nullptr);
InstanceRenderer renderer(&scenery, model); InstanceRenderer renderer(&scenery, model);
renderer.setSize(width, height); renderer.setSize(width, height);
renderer.setSoloRasterizer(&renderer); renderer.setSoloRasterizer(&renderer);
@ -374,7 +374,7 @@ static void testOpenGLVegetationImpostor() {
scenery.autoPreset(i); scenery.autoPreset(i);
OpenGLVegetationImpostor impostor(128); OpenGLVegetationImpostor impostor(128);
VegetationModelDefinition model(NULL); VegetationModelDefinition model(nullptr);
bool interrupted = false; bool interrupted = false;
impostor.prepareTexture(model, scenery, &interrupted); impostor.prepareTexture(model, scenery, &interrupted);
@ -399,7 +399,7 @@ static void testTextures() {
// TODO Customize terrain function // TODO Customize terrain function
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
TextureLayerDefinition layer(NULL, "test"); TextureLayerDefinition layer(nullptr, "test");
layer.applyPreset(static_cast<TextureLayerDefinition::TextureLayerPreset>(i)); layer.applyPreset(static_cast<TextureLayerDefinition::TextureLayerPreset>(i));
layer.terrain_zone->clear(); layer.terrain_zone->clear();
scenery.getTextures()->clear(); scenery.getTextures()->clear();
@ -502,7 +502,7 @@ static void testCloudsLighting() {
scenery.getCamera()->setTarget(VECTOR_ZERO); scenery.getCamera()->setTarget(VECTOR_ZERO);
scenery.getCamera()->setLocation(Vector3(0.0, 10.0, 11.0)); scenery.getCamera()->setLocation(Vector3(0.0, 10.0, 11.0));
CloudLayerDefinition layer(NULL, "test"); CloudLayerDefinition layer(nullptr, "test");
scenery.getClouds()->clear(); scenery.getClouds()->clear();
scenery.getClouds()->addLayer(layer); scenery.getClouds()->addLayer(layer);

View file

@ -16,7 +16,7 @@ FloatPropertyBind::FloatPropertyBind(MainModelerWindow *window, const string &ob
string signal_name("2" + property_name + "Changed()"); string signal_name("2" + property_name + "Changed()");
connect(item, signal_name.c_str(), this, SLOT(propertyChanged())); connect(item, signal_name.c_str(), this, SLOT(propertyChanged()));
} else { } else {
item = NULL; item = nullptr;
Logs::error("UI") << "Can't find object :" << object_name << endl; Logs::error("UI") << "Can't find object :" << object_name << endl;
} }
} }

View file

@ -14,7 +14,7 @@ IntPropertyBind::IntPropertyBind(MainModelerWindow *window, const string &object
string signal_name("2" + property_name + "Changed()"); string signal_name("2" + property_name + "Changed()");
connect(item, signal_name.c_str(), this, SLOT(propertyChanged())); connect(item, signal_name.c_str(), this, SLOT(propertyChanged()));
} else { } else {
item = NULL; item = nullptr;
Logs::error("UI") << "Can't find object :" << object_name << endl; Logs::error("UI") << "Can't find object :" << object_name << endl;
} }
} }

View file

@ -8,8 +8,8 @@
OpenGLView::OpenGLView(QQuickItem *parent) : QQuickItem(parent) { OpenGLView::OpenGLView(QQuickItem *parent) : QQuickItem(parent) {
initialized = false; initialized = false;
window = NULL; window = nullptr;
renderer = NULL; renderer = nullptr;
delayed = 10; delayed = 10;
setAcceptedMouseButtons(Qt::AllButtons); setAcceptedMouseButtons(Qt::AllButtons);

View file

@ -10,7 +10,7 @@ static inline QColor colorToQColor(Color color) {
} }
RenderPreviewProvider::RenderPreviewProvider() : QQuickImageProvider(QQuickImageProvider::Image) { RenderPreviewProvider::RenderPreviewProvider() : QQuickImageProvider(QQuickImageProvider::Image) {
canvas = NULL; canvas = nullptr;
pixbuf = new QImage(1, 1, QImage::Format_ARGB32); pixbuf = new QImage(1, 1, QImage::Format_ARGB32);
hide(); hide();
} }
@ -42,7 +42,7 @@ void RenderPreviewProvider::setCanvas(const Canvas *canvas) {
void RenderPreviewProvider::releaseCanvas() { void RenderPreviewProvider::releaseCanvas() {
if (canvas) { if (canvas) {
canvas->getPreview()->updateLive(this); canvas->getPreview()->updateLive(this);
canvas = NULL; canvas = nullptr;
} }
} }

View file

@ -17,7 +17,7 @@ class RenderPreviewProvider : public QQuickImageProvider, public CanvasLiveClien
virtual ~RenderPreviewProvider(); virtual ~RenderPreviewProvider();
/** /**
* Set the canvas to watch and display, null to stop watching. * Set the canvas to watch and display, nullptr to stop watching.
* *
* This function must be called from the graphics thread. * This function must be called from the graphics thread.
*/ */

View file

@ -29,8 +29,8 @@ RenderProcess::RenderProcess(MainModelerWindow *window, RenderPreviewProvider *d
: window(window), destination(destination) { : window(window), destination(destination) {
has_render = false; has_render = false;
rendering = false; rendering = false;
renderer = NULL; renderer = nullptr;
render_thread = NULL; render_thread = nullptr;
QObject *button_quick = window->findQmlObject("tool_render_quick"); QObject *button_quick = window->findQmlObject("tool_render_quick");
if (button_quick) { if (button_quick) {
@ -172,7 +172,7 @@ void RenderProcess::timerEvent(QTimerEvent *) {
render_thread->join(); render_thread->join();
delete render_thread; delete render_thread;
render_thread = NULL; render_thread = nullptr;
window->setQmlProperty("render_dialog", "rendering", false); window->setQmlProperty("render_dialog", "rendering", false);
window->getRenderer()->resume(); window->getRenderer()->resume();

View file

@ -32,7 +32,7 @@ class OPENGLSHARED_EXPORT OpenGLShaderProgram {
* *
* 'state' is optional and may add ponctual variables to the global state. * 'state' is optional and may add ponctual variables to the global state.
*/ */
void draw(OpenGLVertexArray *vertices, OpenGLSharedState *state = NULL, int start = 0, int count = -1); void draw(OpenGLVertexArray *vertices, OpenGLSharedState *state = nullptr, int start = 0, int count = -1);
/** /**
* Check if the program is currently bound to OpenGL context. * Check if the program is currently bound to OpenGL context.
@ -65,7 +65,7 @@ class OPENGLSHARED_EXPORT OpenGLShaderProgram {
friend class OpenGLVariable; friend class OpenGLVariable;
private: private:
bool bind(OpenGLSharedState *state = NULL); bool bind(OpenGLSharedState *state = nullptr);
void release(); void release();
void compile(); void compile();

View file

@ -23,7 +23,7 @@ void OpenGLSharedState::destroy(OpenGLFunctions *functions) {
OpenGLVariable *OpenGLSharedState::get(const string &name) { OpenGLVariable *OpenGLSharedState::get(const string &name) {
OpenGLVariable *&var = variables[name]; OpenGLVariable *&var = variables[name];
if (var == NULL) { if (var == nullptr) {
var = new OpenGLVariable(name); var = new OpenGLVariable(name);
} }
return var; return var;

View file

@ -153,7 +153,7 @@ void OpenGLTerrain::performChunksMaintenance() {
chunk = pv->queue.back(); chunk = pv->queue.back();
pv->queue.pop_back(); pv->queue.pop_back();
} else { } else {
chunk = NULL; chunk = nullptr;
} }
pv->lock.release(); pv->lock.release();

View file

@ -128,7 +128,7 @@ OpenGLVegetationLayer *OpenGLVegetation::findLayer(VegetationLayerDefinition *la
return l; return l;
} }
} }
return NULL; return nullptr;
} }
void OpenGLVegetation::setEnabled(bool enabled) { void OpenGLVegetation::setEnabled(bool enabled) {

View file

@ -37,8 +37,8 @@ void OpenGLVegetationLayer::produceInstancesInArea(double xmin, double xmax, dou
} }
} }
static bool isNull(void *ptr) { static bool isnullptr(void *ptr) {
return ptr == NULL; return ptr == nullptr;
} }
static bool compareInstances(OpenGLVegetationInstance *instance1, OpenGLVegetationInstance *instance2) { static bool compareInstances(OpenGLVegetationInstance *instance1, OpenGLVegetationInstance *instance2) {
@ -53,10 +53,10 @@ void OpenGLVegetationLayer::removeInstancesOutsideArea(double xmin, double xmax,
if (own_instances) { if (own_instances) {
delete instance; delete instance;
} }
instance = NULL; instance = nullptr;
} }
} }
instances->erase(remove_if(instances->begin(), instances->end(), isNull), instances->end()); instances->erase(remove_if(instances->begin(), instances->end(), isnullptr), instances->end());
} }
void OpenGLVegetationLayer::updateInstances() { void OpenGLVegetationLayer::updateInstances() {

View file

@ -17,7 +17,7 @@ static void check_auto_daytime(AtmosphereDefinition &atmo, int hour, int minute
} }
TEST(AtmosphereDefinition, setDayTime) { TEST(AtmosphereDefinition, setDayTime) {
AtmosphereDefinition atmo(NULL); AtmosphereDefinition atmo(nullptr);
atmo.setDayTime(0.0); atmo.setDayTime(0.0);
check_daytime(atmo, 0); check_daytime(atmo, 0);

View file

@ -4,7 +4,7 @@
#include "FloatNode.h" #include "FloatNode.h"
TEST(CelestialBodyDefinition, getAngularRadius) { TEST(CelestialBodyDefinition, getAngularRadius) {
CelestialBodyDefinition moon(NULL, "moon"); CelestialBodyDefinition moon(nullptr, "moon");
moon.propDistance()->setValue(384403.0); moon.propDistance()->setValue(384403.0);
moon.propRadius()->setValue(1737.4); moon.propRadius()->setValue(1737.4);

View file

@ -6,21 +6,21 @@
#include "PackStream.h" #include "PackStream.h"
TEST(ColorNode, toString) { TEST(ColorNode, toString) {
ColorNode test(NULL, "test", Color(0.1, 0.2, 0.3, 0.4)); ColorNode test(nullptr, "test", Color(0.1, 0.2, 0.3, 0.4));
EXPECT_EQ("test 0.1,0.2,0.3,0.4", test.toString(0)); EXPECT_EQ("test 0.1,0.2,0.3,0.4", test.toString(0));
EXPECT_EQ(" test 0.1,0.2,0.3,0.4", test.toString(2)); EXPECT_EQ(" test 0.1,0.2,0.3,0.4", test.toString(2));
} }
TEST(ColorNode, saveLoadAndSkip) { TEST(ColorNode, saveLoadAndSkip) {
DefinitionNode root1(NULL, "root"); DefinitionNode root1(nullptr, "root");
ColorNode testa1(&root1, "testa", COLOR_RED); ColorNode testa1(&root1, "testa", COLOR_RED);
ColorNode testb1(&root1, "testb", COLOR_GREEN); ColorNode testb1(&root1, "testb", COLOR_GREEN);
PackStream stream1; PackStream stream1;
root1.save(&stream1); root1.save(&stream1);
DefinitionNode root2(NULL, "root"); DefinitionNode root2(nullptr, "root");
ColorNode testb2(&root2, "testb"); ColorNode testb2(&root2, "testb");
PackStream stream2(&stream1); PackStream stream2(&stream1);
@ -30,9 +30,9 @@ TEST(ColorNode, saveLoadAndSkip) {
} }
TEST(ColorNode, copy) { TEST(ColorNode, copy) {
ColorNode base(NULL, "test", COLOR_BLUE); ColorNode base(nullptr, "test", COLOR_BLUE);
ColorNode other(NULL, "test", COLOR_RED); ColorNode other(nullptr, "test", COLOR_RED);
DefinitionNode badother(NULL, "test"); DefinitionNode badother(nullptr, "test");
base.copy(&other); base.copy(&other);
EXPECT_EQ(COLOR_BLUE, base.getValue()); EXPECT_EQ(COLOR_BLUE, base.getValue());
@ -46,7 +46,7 @@ TEST(ColorNode, copy) {
} }
TEST(ColorNode, produceDiff) { TEST(ColorNode, produceDiff) {
ColorNode node(NULL, "test", COLOR_BLUE); ColorNode node(nullptr, "test", COLOR_BLUE);
const ColorDiff *diff = node.produceDiff(COLOR_RED); const ColorDiff *diff = node.produceDiff(COLOR_RED);
EXPECT_EQ("color", diff->getTypeName()); EXPECT_EQ("color", diff->getTypeName());
@ -62,9 +62,9 @@ TEST(ColorNode, produceDiff) {
} }
TEST(ColorNode, applyDiff) { TEST(ColorNode, applyDiff) {
ColorNode node(NULL, "test", COLOR_BLUE); ColorNode node(nullptr, "test", COLOR_BLUE);
ColorDiff diff(&node, COLOR_BLUE, COLOR_RED); ColorDiff diff(&node, COLOR_BLUE, COLOR_RED);
DefinitionNode onode(NULL, "test", "badtype"); DefinitionNode onode(nullptr, "test", "badtype");
IntDiff odiff(&onode, 1, 2); IntDiff odiff(&onode, 1, 2);
bool result; bool result;

View file

@ -8,7 +8,7 @@
#include "System.h" #include "System.h"
TEST(DefinitionNode, toString) { TEST(DefinitionNode, toString) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
DefinitionNode branch(&root, "branch"); DefinitionNode branch(&root, "branch");
DefinitionNode leaf1(&branch, "leaf1"); DefinitionNode leaf1(&branch, "leaf1");
DefinitionNode leaf2(&branch, "leaf2"); DefinitionNode leaf2(&branch, "leaf2");
@ -18,7 +18,7 @@ TEST(DefinitionNode, toString) {
} }
TEST(DefinitionNode, getPath) { TEST(DefinitionNode, getPath) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
DefinitionNode branch(&root, "branch"); DefinitionNode branch(&root, "branch");
DefinitionNode leaf(&branch, "leaf"); DefinitionNode leaf(&branch, "leaf");
@ -28,16 +28,16 @@ TEST(DefinitionNode, getPath) {
} }
TEST(DefinitionNode, findByPath) { TEST(DefinitionNode, findByPath) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
DefinitionNode branch(&root, "branch"); DefinitionNode branch(&root, "branch");
DefinitionNode leaf(&branch, "leaf"); DefinitionNode leaf(&branch, "leaf");
EXPECT_EQ(&root, root.findByPath("/")); EXPECT_EQ(&root, root.findByPath("/"));
EXPECT_EQ(&branch, root.findByPath("/branch")); EXPECT_EQ(&branch, root.findByPath("/branch"));
EXPECT_EQ(NULL, root.findByPath("/branche")); EXPECT_EQ(nullptr, root.findByPath("/branche"));
EXPECT_EQ(&leaf, root.findByPath("/branch/leaf")); EXPECT_EQ(&leaf, root.findByPath("/branch/leaf"));
EXPECT_EQ(NULL, root.findByPath("/branche/leaf")); EXPECT_EQ(nullptr, root.findByPath("/branche/leaf"));
EXPECT_EQ(NULL, root.findByPath("/branch/leave")); EXPECT_EQ(nullptr, root.findByPath("/branch/leave"));
EXPECT_EQ(&branch, root.findByPath("branch")); EXPECT_EQ(&branch, root.findByPath("branch"));
EXPECT_EQ(&leaf, root.findByPath("branch/leaf")); EXPECT_EQ(&leaf, root.findByPath("branch/leaf"));
@ -45,7 +45,7 @@ TEST(DefinitionNode, findByPath) {
} }
TEST(DefinitionNode, attachDetach) { TEST(DefinitionNode, attachDetach) {
DefinitionNode *root = new DefinitionNode(NULL, "root"); DefinitionNode *root = new DefinitionNode(nullptr, "root");
DefinitionNode *child1 = new DefinitionNode(root, "child1"); DefinitionNode *child1 = new DefinitionNode(root, "child1");
DefinitionNode *child2 = new DefinitionNode(root, "child2"); DefinitionNode *child2 = new DefinitionNode(root, "child2");
@ -68,7 +68,7 @@ TEST(DefinitionNode, saveLoadCopy) {
PackStream *stream; PackStream *stream;
int check_in = 42, check_out = 0; int check_in = 42, check_out = 0;
DefinitionNode *before = new DefinitionNode(NULL, "root"); DefinitionNode *before = new DefinitionNode(nullptr, "root");
DefinitionNode *before1 = new DefinitionNode(before, "before1"); DefinitionNode *before1 = new DefinitionNode(before, "before1");
new FloatNode(before1, "before11", 2.1); new FloatNode(before1, "before11", 2.1);
new FloatNode(before1, "before12", -4.3); new FloatNode(before1, "before12", -4.3);
@ -84,7 +84,7 @@ TEST(DefinitionNode, saveLoadCopy) {
delete stream; delete stream;
// Same definition tree, but with missing nodes, and added ones // Same definition tree, but with missing nodes, and added ones
DefinitionNode *after = new DefinitionNode(NULL, "root"); DefinitionNode *after = new DefinitionNode(nullptr, "root");
DefinitionNode *after1 = new DefinitionNode(after, "before1"); DefinitionNode *after1 = new DefinitionNode(after, "before1");
FloatNode *after12 = new FloatNode(after1, "before12"); FloatNode *after12 = new FloatNode(after1, "before12");
FloatNode *after13 = new FloatNode(after1, "before13"); FloatNode *after13 = new FloatNode(after1, "before13");
@ -131,7 +131,7 @@ TEST(DefinitionNode, onChildChange) {
vector<pair<int, string>> changes; vector<pair<int, string>> changes;
}; };
CapturingNode root(NULL, "root"); CapturingNode root(nullptr, "root");
CapturingNode branch(&root, "branch"); CapturingNode branch(&root, "branch");
IntNode leaf(&branch, "leaf"); IntNode leaf(&branch, "leaf");

View file

@ -17,7 +17,7 @@ TEST(DefinitionWatcher, destructor) {
int &counter; int &counter;
}; };
IntNode root(NULL, "test", 5); IntNode root(nullptr, "test", 5);
int counter = 0; int counter = 0;
auto watcher = new FakeWatcher(&root, counter); auto watcher = new FakeWatcher(&root, counter);

View file

@ -8,7 +8,7 @@
#include "TestToolDefinition.h" #include "TestToolDefinition.h"
TEST(DiffManager, undoRedo) { TEST(DiffManager, undoRedo) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
DiffManager *diffs = root.getDiffManager(); DiffManager *diffs = root.getDiffManager();
FloatNode leaf(&root, "value", 2.6); FloatNode leaf(&root, "value", 2.6);
@ -34,7 +34,7 @@ TEST(DiffManager, undoRedo) {
} }
TEST(DiffManager, undoTooMuch) { TEST(DiffManager, undoTooMuch) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
DiffManager *diffs = root.getDiffManager(); DiffManager *diffs = root.getDiffManager();
FloatNode leaf(&root, "value", 1.1); FloatNode leaf(&root, "value", 1.1);
@ -54,7 +54,7 @@ TEST(DiffManager, undoTooMuch) {
} }
TEST(DiffManager, redoTooMuch) { TEST(DiffManager, redoTooMuch) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
DiffManager *diffs = root.getDiffManager(); DiffManager *diffs = root.getDiffManager();
FloatNode leaf(&root, "value", 1.1); FloatNode leaf(&root, "value", 1.1);
@ -77,7 +77,7 @@ TEST(DiffManager, redoTooMuch) {
} }
TEST(DiffManager, undoBranch) { TEST(DiffManager, undoBranch) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
DiffManager *diffs = root.getDiffManager(); DiffManager *diffs = root.getDiffManager();
FloatNode leaf(&root, "value", 1.1); FloatNode leaf(&root, "value", 1.1);
@ -141,7 +141,7 @@ class TestWatcher : public DefinitionWatcher {
} }
TEST(DiffManager, addWatcher) { TEST(DiffManager, addWatcher) {
FloatNode node(NULL, "node"); FloatNode node(nullptr, "node");
TestWatcher watcher(&node, 1.3, -4.0); TestWatcher watcher(&node, 1.3, -4.0);
node.setValue(1.3); node.setValue(1.3);
@ -155,7 +155,7 @@ TEST(DiffManager, addWatcher) {
} }
TEST(DiffManager, addWatcherWithInitDiffs) { TEST(DiffManager, addWatcherWithInitDiffs) {
FloatNode node(NULL, "node", 1.3); FloatNode node(nullptr, "node", 1.3);
TestWatcher watcher(&node, 1.3, 1.3); TestWatcher watcher(&node, 1.3, 1.3);
watcher.start(true); watcher.start(true);
@ -163,7 +163,7 @@ TEST(DiffManager, addWatcherWithInitDiffs) {
} }
TEST(DiffManager, publishToWatcher) { TEST(DiffManager, publishToWatcher) {
DefinitionNode root(NULL, "root"); DefinitionNode root(nullptr, "root");
FloatNode node(&root, "node", 1.3); FloatNode node(&root, "node", 1.3);
RecordingDefinitionWatcher watcher; RecordingDefinitionWatcher watcher;

View file

@ -6,21 +6,21 @@
#include "PackStream.h" #include "PackStream.h"
TEST(FloatNode, toString) { TEST(FloatNode, toString) {
FloatNode test(NULL, "test", 2.1); FloatNode test(nullptr, "test", 2.1);
EXPECT_EQ("test 2.1", test.toString(0)); EXPECT_EQ("test 2.1", test.toString(0));
EXPECT_EQ(" test 2.1", test.toString(2)); EXPECT_EQ(" test 2.1", test.toString(2));
} }
TEST(FloatNode, saveLoadAndSkip) { TEST(FloatNode, saveLoadAndSkip) {
DefinitionNode root1(NULL, "root"); DefinitionNode root1(nullptr, "root");
FloatNode testa1(&root1, "testa", 1.5); FloatNode testa1(&root1, "testa", 1.5);
FloatNode testb1(&root1, "testb", 4.3); FloatNode testb1(&root1, "testb", 4.3);
PackStream stream1; PackStream stream1;
root1.save(&stream1); root1.save(&stream1);
DefinitionNode root2(NULL, "root"); DefinitionNode root2(nullptr, "root");
FloatNode testb2(&root2, "testb"); FloatNode testb2(&root2, "testb");
PackStream stream2(&stream1); PackStream stream2(&stream1);
@ -30,9 +30,9 @@ TEST(FloatNode, saveLoadAndSkip) {
} }
TEST(FloatNode, copy) { TEST(FloatNode, copy) {
FloatNode base(NULL, "test", 2.1); FloatNode base(nullptr, "test", 2.1);
FloatNode other(NULL, "test", 4.3); FloatNode other(nullptr, "test", 4.3);
DefinitionNode badother(NULL, "test"); DefinitionNode badother(nullptr, "test");
base.copy(&other); base.copy(&other);
EXPECT_DOUBLE_EQ(2.1, base.getValue()); EXPECT_DOUBLE_EQ(2.1, base.getValue());
@ -46,7 +46,7 @@ TEST(FloatNode, copy) {
} }
TEST(FloatNode, produceDiff) { TEST(FloatNode, produceDiff) {
FloatNode node(NULL, "test", 8.3); FloatNode node(nullptr, "test", 8.3);
const FloatDiff *diff = node.produceDiff(-4.1); const FloatDiff *diff = node.produceDiff(-4.1);
EXPECT_EQ("float", diff->getTypeName()); EXPECT_EQ("float", diff->getTypeName());
@ -62,9 +62,9 @@ TEST(FloatNode, produceDiff) {
} }
TEST(FloatNode, applyDiff) { TEST(FloatNode, applyDiff) {
FloatNode node(NULL, "test", 1.2); FloatNode node(nullptr, "test", 1.2);
FloatDiff diff(&node, 1.2, 2.4); FloatDiff diff(&node, 1.2, 2.4);
DefinitionNode onode(NULL, "test", "badtype"); DefinitionNode onode(nullptr, "test", "badtype");
IntDiff odiff(&onode, 1, 2); IntDiff odiff(&onode, 1, 2);
bool result; bool result;

View file

@ -6,21 +6,21 @@
#include "PackStream.h" #include "PackStream.h"
TEST(IntNode, toString) { TEST(IntNode, toString) {
IntNode test(NULL, "test", 2); IntNode test(nullptr, "test", 2);
EXPECT_EQ("test 2", test.toString(0)); EXPECT_EQ("test 2", test.toString(0));
EXPECT_EQ(" test 2", test.toString(2)); EXPECT_EQ(" test 2", test.toString(2));
} }
TEST(IntNode, saveLoadAndSkip) { TEST(IntNode, saveLoadAndSkip) {
DefinitionNode root1(NULL, "root"); DefinitionNode root1(nullptr, "root");
IntNode testa1(&root1, "testa", 1); IntNode testa1(&root1, "testa", 1);
IntNode testb1(&root1, "testb", 4); IntNode testb1(&root1, "testb", 4);
PackStream stream1; PackStream stream1;
root1.save(&stream1); root1.save(&stream1);
DefinitionNode root2(NULL, "root"); DefinitionNode root2(nullptr, "root");
IntNode testb2(&root2, "testb"); IntNode testb2(&root2, "testb");
PackStream stream2(&stream1); PackStream stream2(&stream1);
@ -30,9 +30,9 @@ TEST(IntNode, saveLoadAndSkip) {
} }
TEST(IntNode, copy) { TEST(IntNode, copy) {
IntNode base(NULL, "test", 2); IntNode base(nullptr, "test", 2);
IntNode other(NULL, "test", 4); IntNode other(nullptr, "test", 4);
DefinitionNode badother(NULL, "test"); DefinitionNode badother(nullptr, "test");
base.copy(&other); base.copy(&other);
EXPECT_DOUBLE_EQ(2, base.getValue()); EXPECT_DOUBLE_EQ(2, base.getValue());
@ -46,7 +46,7 @@ TEST(IntNode, copy) {
} }
TEST(IntNode, produceDiff) { TEST(IntNode, produceDiff) {
IntNode node(NULL, "test", 8); IntNode node(nullptr, "test", 8);
const IntDiff *diff = node.produceDiff(-4); const IntDiff *diff = node.produceDiff(-4);
EXPECT_EQ("int", diff->getTypeName()); EXPECT_EQ("int", diff->getTypeName());
@ -62,9 +62,9 @@ TEST(IntNode, produceDiff) {
} }
TEST(IntNode, applyDiff) { TEST(IntNode, applyDiff) {
IntNode node(NULL, "test", 1); IntNode node(nullptr, "test", 1);
IntDiff diff(&node, 1, 2); IntDiff diff(&node, 1, 2);
DefinitionNode onode(NULL, "test", "badtype"); DefinitionNode onode(nullptr, "test", "badtype");
FloatDiff odiff(&onode, 1.0, 2.0); FloatDiff odiff(&onode, 1.0, 2.0);
bool result; bool result;

View file

@ -8,7 +8,7 @@
#include "System.h" #include "System.h"
static DefinitionNode *_construc1(Layers *, const string &name) { static DefinitionNode *_construc1(Layers *, const string &name) {
return new DefinitionNode(NULL, name); return new DefinitionNode(nullptr, name);
} }
static DefinitionNode *_construc2(Layers *parent, const string &name) { static DefinitionNode *_construc2(Layers *parent, const string &name) {
@ -17,18 +17,18 @@ static DefinitionNode *_construc2(Layers *parent, const string &name) {
} }
TEST(Layers, Constructor) { TEST(Layers, Constructor) {
Layers layers1(NULL, "test", _construc1); Layers layers1(nullptr, "test", _construc1);
EXPECT_EQ(0, layers1.getLayerCount()); EXPECT_EQ(0, layers1.getLayerCount());
} }
TEST(Layers, NullLayer) { TEST(Layers, nullptrLayer) {
Layers layers1(NULL, "test", _construc1); Layers layers1(nullptr, "test", _construc1);
for (int i = -2; i < 5; i++) { for (int i = -2; i < 5; i++) {
DefinitionNode *layer = layers1.getLayer(0); DefinitionNode *layer = layers1.getLayer(0);
EXPECT_NE((DefinitionNode *)NULL, layer); EXPECT_NE((DefinitionNode *)nullptr, layer);
EXPECT_EQ(NULL, layer->getParent()); EXPECT_EQ(nullptr, layer->getParent());
EXPECT_EQ(layer, layer->getRoot()); EXPECT_EQ(layer, layer->getRoot());
EXPECT_EQ("#NULL#", layer->getName()); EXPECT_EQ("#NULL#", layer->getName());
@ -38,12 +38,12 @@ TEST(Layers, NullLayer) {
} }
TEST(Layers, copy) { TEST(Layers, copy) {
Layers layers1(NULL, "test", _construc2); Layers layers1(nullptr, "test", _construc2);
layers1.addLayer("test"); layers1.addLayer("test");
EXPECT_EQ(1, layers1.getLayerCount()); EXPECT_EQ(1, layers1.getLayerCount());
// Copy with the same constructor // Copy with the same constructor
Layers layers2(NULL, "test", _construc2); Layers layers2(nullptr, "test", _construc2);
EXPECT_EQ(0, layers2.getLayerCount()); EXPECT_EQ(0, layers2.getLayerCount());
layers1.copy(&layers2); layers1.copy(&layers2);
EXPECT_EQ(1, layers2.getLayerCount()); EXPECT_EQ(1, layers2.getLayerCount());
@ -55,7 +55,7 @@ TEST(Layers, copy) {
} }
TEST(Layers, maxLayerCount) { TEST(Layers, maxLayerCount) {
Layers layers1(NULL, "test", _construc1); Layers layers1(nullptr, "test", _construc1);
layers1.setMaxLayerCount(2); layers1.setMaxLayerCount(2);
EXPECT_EQ(0, layers1.getLayerCount()); EXPECT_EQ(0, layers1.getLayerCount());
@ -83,7 +83,7 @@ TEST(Layers, maxLayerCount) {
TEST(Layers, saveLoad) { TEST(Layers, saveLoad) {
PackStream *stream; PackStream *stream;
Layers layers1(NULL, "test", _construc1); Layers layers1(nullptr, "test", _construc1);
layers1.addLayer("first"); layers1.addLayer("first");
layers1.addLayer("second"); layers1.addLayer("second");
ASSERT_EQ(2, layers1.getLayerCount()); ASSERT_EQ(2, layers1.getLayerCount());
@ -93,7 +93,7 @@ TEST(Layers, saveLoad) {
layers1.save(stream); layers1.save(stream);
delete stream; delete stream;
Layers layers2(NULL, "test", _construc1); Layers layers2(nullptr, "test", _construc1);
stream = new PackStream(); stream = new PackStream();
stream->bindToFile(TMP_DIRECTORY "test_paysages_pack"); stream->bindToFile(TMP_DIRECTORY "test_paysages_pack");
@ -125,7 +125,7 @@ static DefinitionNode *_construc3(Layers *parent, const string &name) {
} }
TEST(Layers, undoRedo) { TEST(Layers, undoRedo) {
Layers layers(NULL, "layers", _construc3); Layers layers(nullptr, "layers", _construc3);
EXPECT_EQ(0, layers.getLayerCount()); EXPECT_EQ(0, layers.getLayerCount());
EXPECT_EQ(0u, layers.getDiffManager()->getDiffCount()); EXPECT_EQ(0u, layers.getDiffManager()->getDiffCount());
@ -173,7 +173,7 @@ TEST(Layers, undoRedo) {
} }
TEST(Layers, generateInitDiffs) { TEST(Layers, generateInitDiffs) {
Layers layers(NULL, "layers", _construc1); Layers layers(nullptr, "layers", _construc1);
vector<const DefinitionDiff *> diffs; vector<const DefinitionDiff *> diffs;
layers.generateInitDiffs(&diffs); layers.generateInitDiffs(&diffs);
@ -187,7 +187,7 @@ TEST(Layers, generateInitDiffs) {
layers.generateInitDiffs(&diffs); layers.generateInitDiffs(&diffs);
EXPECT_EQ(3, (int)diffs.size()); EXPECT_EQ(3, (int)diffs.size());
Layers layers1(NULL, "layers", _construc1); Layers layers1(nullptr, "layers", _construc1);
for (auto diff : diffs) { for (auto diff : diffs) {
layers1.applyDiff(diff); layers1.applyDiff(diff);
} }

View file

@ -9,8 +9,8 @@ TEST(OpenGLSkybox, glvariable_atmosphereHumidity) {
Scenery scenery; Scenery scenery;
OpenGLRenderer renderer(&scenery); OpenGLRenderer renderer(&scenery);
OpenGLSkybox glvegetation(&renderer); OpenGLSkybox glskybox(&renderer);
glvegetation.initialize(); glskybox.initialize();
EXPECT_GLVARIABLE_FLOAT(0.0, renderer.getSharedState(), "atmosphereHumidity"); EXPECT_GLVARIABLE_FLOAT(0.0, renderer.getSharedState(), "atmosphereHumidity");
scenery.set("/atmosphere/humidity", 0.8); scenery.set("/atmosphere/humidity", 0.8);

View file

@ -9,7 +9,7 @@
class FakeLayerRenderer : public OpenGLVegetationLayer { class FakeLayerRenderer : public OpenGLVegetationLayer {
public: public:
FakeLayerRenderer(VegetationLayerDefinition *definition) : OpenGLVegetationLayer(NULL, definition, false) { FakeLayerRenderer(VegetationLayerDefinition *definition) : OpenGLVegetationLayer(nullptr, definition, false) {
} }
virtual ~FakeLayerRenderer() { virtual ~FakeLayerRenderer() {
for (auto instance : static_instances) { for (auto instance : static_instances) {
@ -30,9 +30,9 @@ class FakeLayerRenderer : public OpenGLVegetationLayer {
TEST(OpenGLVegetationLayer, updateInstances) { TEST(OpenGLVegetationLayer, updateInstances) {
CameraDefinition camera; CameraDefinition camera;
VegetationLayerDefinition definition(NULL, "test"); VegetationLayerDefinition definition(nullptr, "test");
FakeLayerRenderer rendering(&definition); FakeLayerRenderer rendering(&definition);
VegetationModelDefinition model(NULL); VegetationModelDefinition model(nullptr);
EXPECT_EQ(0, rendering.getInstanceCount()); EXPECT_EQ(0, rendering.getInstanceCount());

View file

@ -8,8 +8,7 @@ TEST(PackStream, All) {
int i; int i;
int data_i; int data_i;
double data_d; double data_d;
const char *data_s; string data_s;
char buffer[100];
/* Writing to pack */ /* Writing to pack */
stream = new PackStream(); stream = new PackStream();
@ -20,11 +19,11 @@ TEST(PackStream, All) {
data_d = to_double(i); data_d = to_double(i);
stream->write(&data_d); stream->write(&data_d);
data_d = to_double(i + 0.142378632);
stream->write(&data_d);
data_s = "Testing string 0123 (accentué) !"; data_s = "Testing string 0123 (accentué) !";
stream->write(data_s, 100); stream->write(data_s);
stream->write(data_s, 4);
stream->write(data_s, 5);
} }
delete stream; delete stream;
@ -37,13 +36,11 @@ TEST(PackStream, All) {
stream->read(&data_d); stream->read(&data_d);
ASSERT_DOUBLE_EQ(to_double(i), data_d); ASSERT_DOUBLE_EQ(to_double(i), data_d);
stream->read(&data_d);
ASSERT_DOUBLE_EQ(to_double(i) + 0.142378632, data_d);
stream->read(buffer, 100); data_s = stream->readString();
ASSERT_STREQ("Testing string 0123 (accentué) !", buffer); ASSERT_STREQ("Testing string 0123 (accentué) !", data_s.c_str());
stream->read(buffer, 4);
ASSERT_STREQ("Tes", buffer);
stream->read(buffer, 3);
ASSERT_STREQ("Te", buffer);
} }
delete stream; delete stream;
} }

View file

@ -10,7 +10,7 @@
class FakeRasterizer : public Rasterizer { class FakeRasterizer : public Rasterizer {
public: public:
FakeRasterizer(SoftwareRenderer *renderer) : Rasterizer(renderer, NULL, 0, COLOR_WHITE) { FakeRasterizer(SoftwareRenderer *renderer) : Rasterizer(renderer, nullptr, 0, COLOR_WHITE) {
} }
virtual Color shadeFragment(const CanvasFragment &, const CanvasFragment *) const override { virtual Color shadeFragment(const CanvasFragment &, const CanvasFragment *) const override {
return COLOR_RED; return COLOR_RED;

View file

@ -44,7 +44,7 @@ class TerrainPainting_Test : public BaseTestCase {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
terrain = new TerrainDefinition(NULL); terrain = new TerrainDefinition(nullptr);
terrain->propHeightNoise()->forceSetGenerator(new SinFractalNoise); terrain->propHeightNoise()->forceSetGenerator(new SinFractalNoise);
terrain->propWaterHeight()->setValue(0.0); terrain->propWaterHeight()->setValue(0.0);
} }

View file

@ -8,20 +8,20 @@
TEST(TexturesRenderer, getLayersPresence) { TEST(TexturesRenderer, getLayersPresence) {
TexturesRenderer renderer; TexturesRenderer renderer;
TexturesDefinition textures(NULL); TexturesDefinition textures(nullptr);
vector<double> result; vector<double> result;
result = renderer.getLayersPresence(&textures, VECTOR_ZERO, VECTOR_UP); result = renderer.getLayersPresence(&textures, VECTOR_ZERO, VECTOR_UP);
ASSERT_EQ(0u, result.size()); ASSERT_EQ(0u, result.size());
TextureLayerDefinition layer1(NULL, "t1"); TextureLayerDefinition layer1(nullptr, "t1");
textures.addLayer(layer1); textures.addLayer(layer1);
result = renderer.getLayersPresence(&textures, VECTOR_ZERO, VECTOR_UP); result = renderer.getLayersPresence(&textures, VECTOR_ZERO, VECTOR_UP);
ASSERT_EQ(1u, result.size()); ASSERT_EQ(1u, result.size());
EXPECT_DOUBLE_EQ(1.0, result[0]); EXPECT_DOUBLE_EQ(1.0, result[0]);
TextureLayerDefinition layer2(NULL, "t2"); TextureLayerDefinition layer2(nullptr, "t2");
layer2.terrain_zone->addHeightRangeQuick(0.8, 0.0, 1.0, 2.0, 3.0); layer2.terrain_zone->addHeightRangeQuick(0.8, 0.0, 1.0, 2.0, 3.0);
textures.addLayer(layer2); textures.addLayer(layer2);

View file

@ -13,7 +13,7 @@ TEST(VegetationRasterizer, isUseful) {
EXPECT_FALSE(rast.isUseful()); EXPECT_FALSE(rast.isUseful());
VegetationLayerDefinition layer(NULL, "test"); VegetationLayerDefinition layer(nullptr, "test");
layer.applyPreset(VegetationLayerDefinition::VEGETATION_BASIC_TREES); layer.applyPreset(VegetationLayerDefinition::VEGETATION_BASIC_TREES);
scenery.getVegetation()->addLayer(layer); scenery.getVegetation()->addLayer(layer);