paysages : Switch all doubles to floats (for memory consumption) + added render timer.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@348 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-06-15 09:31:11 +00:00 committed by ThunderK
parent 294dc62156
commit ee86e2d251
80 changed files with 865 additions and 827 deletions

View file

@ -16,10 +16,12 @@ Scenery :
Rendering : Rendering :
* New texture model (perpendicular displacement and thickness). * New texture model (perpendicular displacement and thickness).
* Added full scene antialiasing (FSAA).
GUI : GUI :
* Improved curve rendering. * Improved curve rendering.
* New material editor. * New material editor.
* Added render timer.
Misc : Misc :
* Version handling in saved files. * Version handling in saved files.

1
TODO
View file

@ -14,7 +14,6 @@ Technology Preview 2 :
- Add a terrain modifier dialog with zones. - Add a terrain modifier dialog with zones.
- Use the curve editor in noise editor - Use the curve editor in noise editor
- Add a noise filler (and maybe noise intervals ?). - Add a noise filler (and maybe noise intervals ?).
- Add a popup when rendering is complete (with stats), except for quick render.
- Optimize the use of noiseGetMaxValue (limit its use or cache it). - Optimize the use of noiseGetMaxValue (limit its use or cache it).
- Fix the distorted sun appearance. - Fix the distorted sun appearance.
- Improve curve editor. - Improve curve editor.

View file

@ -31,7 +31,7 @@ void displayHelp()
printf(" -ds x Day step time (float)\n"); printf(" -ds x Day step time (float)\n");
} }
void _previewUpdate(double progress) void _previewUpdate(float progress)
{ {
printf("\rProgress : %0.1f%% ", progress * 100.0); printf("\rProgress : %0.1f%% ", progress * 100.0);
fflush(stdout); fflush(stdout);
@ -43,8 +43,8 @@ int main(int argc, char** argv)
char* conf_file_path = NULL; char* conf_file_path = NULL;
RenderParams conf_render_params = {800, 600, 1, 5}; RenderParams conf_render_params = {800, 600, 1, 5};
int conf_nb_pictures = 1; int conf_nb_pictures = 1;
double conf_daytime_start = 0.4; float conf_daytime_start = 0.4;
double conf_daytime_step = 0.0; float conf_daytime_step = 0.0;
int outputcount; int outputcount;
char outputpath[500]; char outputpath[500];

View file

@ -47,7 +47,7 @@ bool BaseExplorerChunk::maintain()
{ {
if (_texture_current_size <= 1 || i % 2 != 0 || j % 2 != 0) if (_texture_current_size <= 1 || i % 2 != 0 || j % 2 != 0)
{ {
Color color = getTextureColor((double)i / (double)new_texture_size, 1.0 - (double)j / (double)new_texture_size); Color color = getTextureColor((float)i / (float)new_texture_size, 1.0 - (float)j / (float)new_texture_size);
new_image->setPixel(i, j, colorTo32BitBGRA(&color)); new_image->setPixel(i, j, colorTo32BitBGRA(&color));
} }
} }
@ -139,12 +139,12 @@ void BaseExplorerChunk::onRenderEvent(QGLWidget* widget)
{ {
} }
double BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition* camera) float BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition* camera)
{ {
return 0.0; return 0.0;
} }
Color BaseExplorerChunk::getTextureColor(double x, double y) Color BaseExplorerChunk::getTextureColor(float x, float y)
{ {
return COLOR_TRANSPARENT; return COLOR_TRANSPARENT;
} }

View file

@ -15,7 +15,7 @@ public:
void updatePriority(CameraDefinition* camera); void updatePriority(CameraDefinition* camera);
void render(QGLWidget* widget); void render(QGLWidget* widget);
double priority; float priority;
protected: protected:
BaseExplorerChunk(Renderer* renderer); BaseExplorerChunk(Renderer* renderer);
@ -28,8 +28,8 @@ protected:
virtual void onResetEvent(); virtual void onResetEvent();
virtual bool onMaintainEvent(); virtual bool onMaintainEvent();
virtual void onRenderEvent(QGLWidget* widget); virtual void onRenderEvent(QGLWidget* widget);
virtual double getDisplayedSizeHint(CameraDefinition* camera); virtual float getDisplayedSizeHint(CameraDefinition* camera);
virtual Color getTextureColor(double x, double y); virtual Color getTextureColor(float x, float y);
QMutex _lock_data; QMutex _lock_data;

View file

@ -229,7 +229,7 @@ void BaseForm::addInputInt(QString label, int* value, int min, int max, int smal
addInput(new InputInt(form, label, value, min, max, small_step, large_step)); addInput(new InputInt(form, label, value, min, max, small_step, large_step));
} }
void BaseForm::addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step) void BaseForm::addInputDouble(QString label, float* value, float min, float max, float small_step, float large_step)
{ {
addInput(new InputDouble(form, label, value, min, max, small_step, large_step)); addInput(new InputDouble(form, label, value, min, max, small_step, large_step));
} }
@ -254,7 +254,7 @@ void BaseForm::addInputNoise(QString label, NoiseGenerator* value)
addInput(new InputNoise(form, label, value)); addInput(new InputNoise(form, label, value));
} }
void BaseForm::addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax) void BaseForm::addInputCurve(QString label, Curve* value, float xmin, float xmax, float ymin, float ymax)
{ {
addInput(new InputCurve(form, label, value, xmin, xmax, ymin, ymax)); addInput(new InputCurve(form, label, value, xmin, xmax, ymin, ymax));
} }

View file

@ -39,12 +39,12 @@ protected:
QPushButton* addButton(QString label); QPushButton* addButton(QString label);
void addInput(BaseInput* input); void addInput(BaseInput* input);
void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step); void addInputInt(QString label, int* value, int min, int max, int small_step, int large_step);
void addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step); void addInputDouble(QString label, float* value, float min, float max, float small_step, float large_step);
void addInputBoolean(QString label, int* value); void addInputBoolean(QString label, int* value);
void addInputColor(QString label, Color* value); void addInputColor(QString label, Color* value);
void addInputColorGradation(QString label, ColorGradation* value); void addInputColorGradation(QString label, ColorGradation* value);
void addInputNoise(QString label, NoiseGenerator* value); void addInputNoise(QString label, NoiseGenerator* value);
void addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax); void addInputCurve(QString label, Curve* value, float xmin, float xmax, float ymin, float ymax);
void addInputMaterial(QString label, SurfaceMaterial* material); void addInputMaterial(QString label, SurfaceMaterial* material);
int currentLayer(); int currentLayer();

View file

@ -318,14 +318,14 @@ void BasePreview::updateData()
{ {
} }
QColor BasePreview::getColor(double x, double y) QColor BasePreview::getColor(float x, float y)
{ {
return QColor(0, 0, 0); return QColor(0, 0, 0);
} }
void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic) void BasePreview::configScaling(float min, float max, float step, float init, bool logarithmic)
{ {
double size = (double) width(); float size = (float) width();
if (size >= 1.0) if (size >= 1.0)
{ {
@ -345,7 +345,7 @@ void BasePreview::configScaling(double min, double max, double step, double init
} }
} }
void BasePreview::configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit) void BasePreview::configScrolling(float xmin, float xmax, float xinit, float ymin, float ymax, float yinit)
{ {
conf_scroll_xmin = xmin; conf_scroll_xmin = xmin;
conf_scroll_xmax = xmax; conf_scroll_xmax = xmax;
@ -388,7 +388,7 @@ void BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int
QColor BasePreview::getPixelColor(int x, int y) QColor BasePreview::getPixelColor(int x, int y)
{ {
return getColor((double) (x - _width / 2) * scaling + xoffset, (double) (y - _height / 2) * scaling + yoffset); return getColor((float) (x - _width / 2) * scaling + xoffset, (float) (y - _height / 2) * scaling + yoffset);
} }
void BasePreview::handleRedraw() void BasePreview::handleRedraw()
@ -523,8 +523,8 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event)
if (ndx <= -width || ndx >= width || ndy <= -height || ndy >= height) if (ndx <= -width || ndx >= width || ndy <= -height || ndy >= height)
{ {
xoffset -= (double) ndx * scaling; xoffset -= (float) ndx * scaling;
yoffset -= (double) ndy * scaling; yoffset -= (float) ndy * scaling;
lock_drawing->lock(); lock_drawing->lock();
pixbuf->fill(0x00000000); pixbuf->fill(0x00000000);
@ -537,8 +537,8 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event)
lock_drawing->lock(); lock_drawing->lock();
xoffset -= (double) ndx * scaling; xoffset -= (float) ndx * scaling;
yoffset -= (double) ndy * scaling; yoffset -= (float) ndy * scaling;
if (ndx < 0) if (ndx < 0)
{ {
@ -580,8 +580,8 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event)
void BasePreview::wheelEvent(QWheelEvent* event) void BasePreview::wheelEvent(QWheelEvent* event)
{ {
double factor; float factor;
double old_scaling; float old_scaling;
int width, height; int width, height;
int new_width, new_height; int new_width, new_height;
@ -637,8 +637,8 @@ void BasePreview::wheelEvent(QWheelEvent* event)
if (scaling < old_scaling) if (scaling < old_scaling)
{ {
lock_drawing->lock(); lock_drawing->lock();
new_width = (int) floor(((double) width) * scaling / old_scaling); new_width = (int) floor(((float) width) * scaling / old_scaling);
new_height = (int) floor(((double) height) * scaling / old_scaling); new_height = (int) floor(((float) height) * scaling / old_scaling);
QImage part = pixbuf->copy((width - new_width) / 2, (height - new_height) / 2, new_width, new_height).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QImage part = pixbuf->copy((width - new_width) / 2, (height - new_height) / 2, new_width, new_height).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pixbuf->fill(0x00000000); pixbuf->fill(0x00000000);
QPainter painter(pixbuf); QPainter painter(pixbuf);
@ -651,7 +651,7 @@ void BasePreview::wheelEvent(QWheelEvent* event)
else if (scaling > old_scaling) else if (scaling > old_scaling)
{ {
lock_drawing->lock(); lock_drawing->lock();
QImage part = pixbuf->scaled((int) floor(((double) width) * old_scaling / scaling), (int) floor(((double) height) * old_scaling / scaling), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QImage part = pixbuf->scaled((int) floor(((float) width) * old_scaling / scaling), (int) floor(((float) height) * old_scaling / scaling), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pixbuf->fill(0x00000000); pixbuf->fill(0x00000000);
QPainter painter(pixbuf); QPainter painter(pixbuf);
painter.drawImage((width - part.width()) / 2, (height - part.height()) / 2, part); painter.drawImage((width - part.width()) / 2, (height - part.height()) / 2, part);

View file

@ -28,14 +28,14 @@ public:
protected: protected:
virtual void updateData(); virtual void updateData();
virtual QColor getColor(double x, double y); virtual QColor getColor(float x, float y);
void configScaling(double min, double max, double step, double init, bool logarithmic = true); void configScaling(float min, float max, float step, float init, bool logarithmic = true);
void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit); void configScrolling(float xmin, float xmax, float xinit, float ymin, float ymax, float yinit);
double xoffset; float xoffset;
double yoffset; float yoffset;
double scaling; float scaling;
private: private:
void updateScaling(); void updateScaling();
@ -61,21 +61,21 @@ private:
int mousex; int mousex;
int mousey; int mousey;
double scalingbase; float scalingbase;
bool alive; bool alive;
double conf_scroll_xmin; float conf_scroll_xmin;
double conf_scroll_xmax; float conf_scroll_xmax;
double conf_scroll_xinit; float conf_scroll_xinit;
double conf_scroll_ymin; float conf_scroll_ymin;
double conf_scroll_ymax; float conf_scroll_ymax;
double conf_scroll_yinit; float conf_scroll_yinit;
double conf_scale_min; float conf_scale_min;
double conf_scale_max; float conf_scale_max;
double conf_scale_init; float conf_scale_init;
double conf_scale_step; float conf_scale_step;
bool conf_scroll_logarithmic; bool conf_scroll_logarithmic;
signals: signals:

View file

@ -15,7 +15,7 @@
#include "widgetcurveeditor.h" #include "widgetcurveeditor.h"
/**************** Dialog ****************/ /**************** Dialog ****************/
DialogCurve::DialogCurve(QWidget *parent, Curve* curve, double xmin, double xmax, double ymin, double ymax) : QDialog(parent) DialogCurve::DialogCurve(QWidget *parent, Curve* curve, float xmin, float xmax, float ymin, float ymax) : QDialog(parent)
{ {
QWidget* buttons; QWidget* buttons;
QWidget* form; QWidget* form;
@ -70,7 +70,7 @@ DialogCurve::~DialogCurve()
curveDelete(_current); curveDelete(_current);
} }
bool DialogCurve::getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax) bool DialogCurve::getCurve(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax)
{ {
int result; int result;

View file

@ -11,10 +11,10 @@ class DialogCurve : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax); explicit DialogCurve(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax);
~DialogCurve(); ~DialogCurve();
static bool getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax); static bool getCurve(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax);
public slots: public slots:
virtual void accept(); virtual void accept();

View file

@ -32,7 +32,7 @@ protected:
{ {
noiseCopy(_noise_original, _noise_preview); noiseCopy(_noise_original, _noise_preview);
} }
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
if ((_level >= 0) && (y > noiseGet1DLevel(_noise_preview, _level, x))) if ((_level >= 0) && (y > noiseGet1DLevel(_noise_preview, _level, x)))
{ {
@ -64,7 +64,7 @@ protected:
{ {
noiseCopy(_noise_original, _noise_preview); noiseCopy(_noise_original, _noise_preview);
} }
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
if (y > noiseGet1DTotal(_noise_preview, x)) if (y > noiseGet1DTotal(_noise_preview, x))
{ {
@ -295,7 +295,7 @@ void DialogNoise::levelChanged(int row)
void DialogNoise::heightChanged(int value) void DialogNoise::heightChanged(int value)
{ {
_current_level_params.height = ((double)value) / 1000.0; _current_level_params.height = ((float)value) / 1000.0;
noiseSetLevel(_current, _current_level, _current_level_params); noiseSetLevel(_current, _current_level, _current_level_params);
previewLevel->redraw(); previewLevel->redraw();
previewTotal->redraw(); previewTotal->redraw();
@ -303,7 +303,7 @@ void DialogNoise::heightChanged(int value)
void DialogNoise::scalingChanged(int value) void DialogNoise::scalingChanged(int value)
{ {
_current_level_params.scaling = ((double)value) / 1000.0; _current_level_params.scaling = ((float)value) / 1000.0;
noiseSetLevel(_current, _current_level, _current_level_params); noiseSetLevel(_current, _current_level, _current_level_params);
previewLevel->redraw(); previewLevel->redraw();
previewTotal->redraw(); previewTotal->redraw();

View file

@ -1,9 +1,11 @@
#include "dialogrender.h" #include "dialogrender.h"
#include <math.h>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QImage> #include <QImage>
#include <QColor> #include <QColor>
#include <QPainter> #include <QPainter>
#include <QMessageBox>
#include "tools.h" #include "tools.h"
#include "../lib_paysages/scenery.h" #include "../lib_paysages/scenery.h"
@ -24,10 +26,10 @@ static void _renderDraw(int x, int y, Color col)
_current_dialog->pixbuf->setPixel(x, _current_dialog->pixbuf->height() - 1 - y, colorToQColor(col).rgb()); _current_dialog->pixbuf->setPixel(x, _current_dialog->pixbuf->height() - 1 - y, colorToQColor(col).rgb());
} }
static void _renderUpdate(double progress) static void _renderUpdate(float progress)
{ {
_current_dialog->area->update(); _current_dialog->area->update();
_current_dialog->progress_value = progress * 1000.0; _current_dialog->tellProgressChange(progress);
} }
class RenderThread:public QThread class RenderThread:public QThread
@ -60,8 +62,6 @@ public:
{ {
QPainter painter(this); QPainter painter(this);
painter.drawImage(0, 0, *_current_dialog->pixbuf); painter.drawImage(0, 0, *_current_dialog->pixbuf);
_current_dialog->progress->setValue(_current_dialog->progress_value);
_current_dialog->progress->update();
} }
}; };
@ -70,40 +70,45 @@ DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
{ {
pixbuf = new QImage(1, 1, QImage::Format_ARGB32); pixbuf = new QImage(1, 1, QImage::Format_ARGB32);
_current_dialog = this; _current_dialog = this;
render_thread = NULL; _render_thread = NULL;
_renderer = renderer; _renderer = renderer;
setModal(true); setModal(true);
setWindowTitle(tr("Paysages 3D - Render")); setWindowTitle(tr("Paysages 3D - Render"));
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
scroll = new QScrollArea(this); _scroll = new QScrollArea(this);
scroll->setAlignment(Qt::AlignCenter); _scroll->setAlignment(Qt::AlignCenter);
area = new RenderArea(scroll); area = new RenderArea(_scroll);
scroll->setWidget(area); _scroll->setWidget(area);
layout()->addWidget(scroll); layout()->addWidget(_scroll);
progress = new QProgressBar(this); _info = new QWidget(this);
progress->setMinimum(0); _info->setLayout(new QHBoxLayout());
progress->setMaximum(1000); layout()->addWidget(_info);
progress->setValue(0);
layout()->addWidget(progress); _timer = new QLabel(QString("0:00.00"), _info);
progress_value = 0; _info->layout()->addWidget(_timer);
_progress = new QProgressBar(_info);
_progress->setMaximumHeight(12);
_progress->setMinimum(0);
_progress->setMaximum(1000);
_progress->setValue(0);
_info->layout()->addWidget(_progress);
connect(this, SIGNAL(renderSizeChanged(int, int)), this, SLOT(applyRenderSize(int, int))); connect(this, SIGNAL(renderSizeChanged(int, int)), this, SLOT(applyRenderSize(int, int)));
connect(this, SIGNAL(progressChanged(float)), this, SLOT(applyProgress(float)));
// TEMP
progress->hide();
} }
DialogRender::~DialogRender() DialogRender::~DialogRender()
{ {
if (render_thread) if (_render_thread)
{ {
rendererInterrupt(_renderer); rendererInterrupt(_renderer);
render_thread->wait(); _render_thread->wait();
delete render_thread; delete _render_thread;
} }
delete pixbuf; delete pixbuf;
} }
@ -113,13 +118,20 @@ void DialogRender::tellRenderSize(int width, int height)
emit renderSizeChanged(width, height); emit renderSizeChanged(width, height);
} }
void DialogRender::tellProgressChange(float value)
{
emit progressChanged(value);
}
void DialogRender::startRender(RenderParams params) void DialogRender::startRender(RenderParams params)
{ {
_started = time(NULL);
//applyRenderSize(params.width, params.height); //applyRenderSize(params.width, params.height);
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate); rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);
render_thread = new RenderThread(_renderer, params); _render_thread = new RenderThread(_renderer, params);
render_thread->start(); _render_thread->start();
exec(); exec();
} }
@ -127,7 +139,7 @@ void DialogRender::startRender(RenderParams params)
void DialogRender::loadLastRender() void DialogRender::loadLastRender()
{ {
//applyRenderSize(_renderer->render_width, _renderer->render_height); //applyRenderSize(_renderer->render_width, _renderer->render_height);
progress->hide(); _info->hide();
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate); rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);
exec(); exec();
@ -138,5 +150,17 @@ void DialogRender::applyRenderSize(int width, int height)
area->setMinimumSize(width, height); area->setMinimumSize(width, height);
area->setMaximumSize(width, height); area->setMaximumSize(width, height);
area->resize(width, height); area->resize(width, height);
scroll->setMinimumSize(width > 800 ? 820 : width + 20, height > 600 ? 620 : height + 20); _scroll->setMinimumSize(width > 800 ? 820 : width + 20, height > 600 ? 620 : height + 20);
} }
void DialogRender::applyProgress(float value)
{
double diff = difftime(time(NULL), _started);
int hours = (int)floor(diff / 3600.0);
int minutes = (int)floor((diff - 3600.0 * hours) / 60.0);
int seconds = (int)floor(diff - 3600.0 * hours - 60.0 * minutes);
_timer->setText(tr("%1:%2.%3").arg(hours).arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0')));
_progress->setValue((int)(value * 1000.0));
_progress->update();
}

View file

@ -1,10 +1,12 @@
#ifndef _PAYSAGES_QT_DIALOGRENDER_H_ #ifndef _PAYSAGES_QT_DIALOGRENDER_H_
#define _PAYSAGES_QT_DIALOGRENDER_H_ #define _PAYSAGES_QT_DIALOGRENDER_H_
#include <time.h>
#include <QDialog> #include <QDialog>
#include <QThread> #include <QThread>
#include <QProgressBar> #include <QProgressBar>
#include <QScrollArea> #include <QScrollArea>
#include <QLabel>
#include "../lib_paysages/renderer.h" #include "../lib_paysages/renderer.h"
class DialogRender : public QDialog class DialogRender : public QDialog
@ -15,24 +17,29 @@ public:
~DialogRender(); ~DialogRender();
void tellRenderSize(int width, int height); void tellRenderSize(int width, int height);
void tellProgressChange(float value);
void startRender(RenderParams params); void startRender(RenderParams params);
void loadLastRender(); void loadLastRender();
QImage* pixbuf; QImage* pixbuf;
QWidget* area; QWidget* area;
QProgressBar* progress;
int progress_value;
private slots: private slots:
void applyRenderSize(int width, int height); void applyRenderSize(int width, int height);
void applyProgress(float value);
signals: signals:
void renderSizeChanged(int width, int height); void renderSizeChanged(int width, int height);
void progressChanged(float value);
private: private:
QScrollArea* scroll; QScrollArea* _scroll;
QThread* render_thread; QWidget* _info;
QThread* _render_thread;
QLabel* _timer;
Renderer* _renderer; Renderer* _renderer;
QProgressBar* _progress;
time_t _started;
}; };
#endif // _PAYSAGES_QT_DIALOGRENDER_H_ #endif // _PAYSAGES_QT_DIALOGRENDER_H_

View file

@ -4,7 +4,7 @@
#include "baseexplorerchunk.h" #include "baseexplorerchunk.h"
#include "../lib_paysages/camera.h" #include "../lib_paysages/camera.h"
ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, double size, SkyboxOrientation orientation) : BaseExplorerChunk(renderer) ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, float size, SkyboxOrientation orientation) : BaseExplorerChunk(renderer)
{ {
_sky = sky; _sky = sky;
_box_size = size; _box_size = size;
@ -16,7 +16,7 @@ ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, doubl
void ExplorerChunkSky::onRenderEvent(QGLWidget* widget) void ExplorerChunkSky::onRenderEvent(QGLWidget* widget)
{ {
double size = _box_size; float size = _box_size;
Vector3 camera = renderer()->camera_location; Vector3 camera = renderer()->camera_location;
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -86,12 +86,12 @@ void ExplorerChunkSky::onRenderEvent(QGLWidget* widget)
glEnd(); glEnd();
} }
double ExplorerChunkSky::getDisplayedSizeHint(CameraDefinition* camera) float ExplorerChunkSky::getDisplayedSizeHint(CameraDefinition* camera)
{ {
return 1000.0; return 1000.0;
} }
Color ExplorerChunkSky::getTextureColor(double x, double y) Color ExplorerChunkSky::getTextureColor(float x, float y)
{ {
Vector3 location; Vector3 location;

View file

@ -19,16 +19,16 @@ enum SkyboxOrientation
class ExplorerChunkSky:public BaseExplorerChunk class ExplorerChunkSky:public BaseExplorerChunk
{ {
public: public:
ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, double size, SkyboxOrientation orientation); ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, float size, SkyboxOrientation orientation);
void onRenderEvent(QGLWidget* widget); void onRenderEvent(QGLWidget* widget);
double getDisplayedSizeHint(CameraDefinition* camera); float getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(double x, double y); Color getTextureColor(float x, float y);
private: private:
SkyDefinition* _sky; SkyDefinition* _sky;
SkyboxOrientation _orientation; SkyboxOrientation _orientation;
double _box_size; float _box_size;
}; };

View file

@ -4,17 +4,17 @@
#include "baseexplorerchunk.h" #include "baseexplorerchunk.h"
#include "../lib_paysages/camera.h" #include "../lib_paysages/camera.h"
ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks) : BaseExplorerChunk(renderer) ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, float x, float z, float size, int nbchunks) : BaseExplorerChunk(renderer)
{ {
_startx = x; _startx = x;
_startz = z; _startz = z;
_size = size; _size = size;
_overall_step = size * (double)nbchunks; _overall_step = size * (float)nbchunks;
_tessellation_max_size = 32; _tessellation_max_size = 32;
_tessellation = new double[(_tessellation_max_size + 1) * (_tessellation_max_size + 1)]; _tessellation = new float[(_tessellation_max_size + 1) * (_tessellation_max_size + 1)];
_tessellation_current_size = 0; _tessellation_current_size = 0;
_tessellation_step = _size / (double)_tessellation_max_size; _tessellation_step = _size / (float)_tessellation_max_size;
setMaxTextureSize(128); setMaxTextureSize(128);
@ -49,7 +49,7 @@ bool ExplorerChunkTerrain::onMaintainEvent()
{ {
if (_tessellation_current_size == 0 || i % old_tessellation_inc != 0 || j % old_tessellation_inc != 0) if (_tessellation_current_size == 0 || i % old_tessellation_inc != 0 || j % old_tessellation_inc != 0)
{ {
double height = renderer->getTerrainHeight(renderer, _startx + _tessellation_step * (double)i, _startz + _tessellation_step * (double)j); float height = renderer->getTerrainHeight(renderer, _startx + _tessellation_step * (float)i, _startz + _tessellation_step * (float)j);
_tessellation[j * (_tessellation_max_size + 1) + i] = height; _tessellation[j * (_tessellation_max_size + 1) + i] = height;
} }
} }
@ -98,7 +98,7 @@ void ExplorerChunkTerrain::onRenderEvent(QGLWidget* widget)
{ {
_lock_data.lock(); _lock_data.lock();
int tessellation_size = _tessellation_current_size; int tessellation_size = _tessellation_current_size;
double tsize = 1.0 / (double)_tessellation_max_size; float tsize = 1.0 / (float)_tessellation_max_size;
_lock_data.unlock(); _lock_data.unlock();
if (tessellation_size <= 1) if (tessellation_size <= 1)
@ -106,24 +106,24 @@ void ExplorerChunkTerrain::onRenderEvent(QGLWidget* widget)
return; return;
} }
int tessellation_inc = _tessellation_max_size / (double)tessellation_size; int tessellation_inc = _tessellation_max_size / (float)tessellation_size;
for (int j = 0; j < _tessellation_max_size; j += tessellation_inc) for (int j = 0; j < _tessellation_max_size; j += tessellation_inc)
{ {
glBegin(GL_QUAD_STRIP); glBegin(GL_QUAD_STRIP);
for (int i = 0; i <= _tessellation_max_size; i += tessellation_inc) for (int i = 0; i <= _tessellation_max_size; i += tessellation_inc)
{ {
glTexCoord2d(tsize * (double)i, tsize * (double)j); glTexCoord2d(tsize * (float)i, tsize * (float)j);
glVertex3d(_startx + _tessellation_step * (double)i, _tessellation[j * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double)j); glVertex3d(_startx + _tessellation_step * (float)i, _tessellation[j * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (float)j);
glTexCoord2d(tsize * (double)i, tsize * (double)(j + tessellation_inc)); glTexCoord2d(tsize * (float)i, tsize * (float)(j + tessellation_inc));
glVertex3d(_startx + _tessellation_step * (double)i, _tessellation[(j + tessellation_inc) * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double)(j + tessellation_inc)); glVertex3d(_startx + _tessellation_step * (float)i, _tessellation[(j + tessellation_inc) * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (float)(j + tessellation_inc));
} }
glEnd(); glEnd();
} }
} }
double ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera) float ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
{ {
double distance; float distance;
Vector3 center; Vector3 center;
center = getCenter(); center = getCenter();
@ -140,7 +140,7 @@ double ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
} }
} }
Color ExplorerChunkTerrain::getTextureColor(double x, double y) Color ExplorerChunkTerrain::getTextureColor(float x, float y)
{ {
Vector3 location = {_startx + x * _size, 0.0, _startz + y * _size}; Vector3 location = {_startx + x * _size, 0.0, _startz + y * _size};
return renderer()->applyTextures(renderer(), location, 0.01); return renderer()->applyTextures(renderer(), location, 0.01);

View file

@ -8,28 +8,28 @@
class ExplorerChunkTerrain:public BaseExplorerChunk class ExplorerChunkTerrain:public BaseExplorerChunk
{ {
public: public:
ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks); ExplorerChunkTerrain(Renderer* renderer, float x, float z, float size, int nbchunks);
~ExplorerChunkTerrain(); ~ExplorerChunkTerrain();
void onCameraEvent(CameraDefinition* camera); void onCameraEvent(CameraDefinition* camera);
void onResetEvent(); void onResetEvent();
bool onMaintainEvent(); bool onMaintainEvent();
void onRenderEvent(QGLWidget* widget); void onRenderEvent(QGLWidget* widget);
double getDisplayedSizeHint(CameraDefinition* camera); float getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(double x, double y); Color getTextureColor(float x, float y);
private: private:
Vector3 getCenter(); Vector3 getCenter();
double _startx; float _startx;
double _startz; float _startz;
double _size; float _size;
double _overall_step; float _overall_step;
double* _tessellation; float* _tessellation;
int _tessellation_max_size; int _tessellation_max_size;
int _tessellation_current_size; int _tessellation_current_size;
double _tessellation_step; float _tessellation_step;
}; };

View file

@ -21,7 +21,7 @@ public:
configScaling(100.0, 1000.0, 20.0, 200.0); configScaling(100.0, 1000.0, 20.0, 200.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
Vector3 eye, look, location; Vector3 eye, look, location;

View file

@ -25,7 +25,7 @@ public:
configScaling(100.0, 1000.0, 20.0, 200.0); configScaling(100.0, 1000.0, 20.0, 200.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
Vector3 eye, look; Vector3 eye, look;
Color color_layer, result; Color color_layer, result;
@ -89,7 +89,7 @@ public:
configScaling(1.0, 4.0, 0.2, 2.0); configScaling(1.0, 4.0, 0.2, 2.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
Vector3 start, end; Vector3 start, end;
Color color_layer, result; Color color_layer, result;
@ -120,9 +120,9 @@ private:
CloudsLayerDefinition _preview_layer; CloudsLayerDefinition _preview_layer;
LightingDefinition _lighting; LightingDefinition _lighting;
static double _coverageFunc(CloudsLayerDefinition* layer, Vector3 position) static float _coverageFunc(CloudsLayerDefinition* layer, Vector3 position)
{ {
double dist = v3Norm(position); float dist = v3Norm(position);
if (dist >= layer->ymax) if (dist >= layer->ymax)
{ {

View file

@ -37,11 +37,11 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
Vector3 down = {0.0, -1.0, 0.0}; Vector3 down = {0.0, -1.0, 0.0};
Vector3 location; Vector3 location;
double height = terrainGetHeight(&_terrain, x, y); float height = terrainGetHeight(&_terrain, x, y);
if (height < _water.height) if (height < _water.height)
{ {
@ -69,12 +69,12 @@ private:
TexturesDefinition _textures; TexturesDefinition _textures;
LightingDefinition _lighting; LightingDefinition _lighting;
static double _getTerrainHeight(Renderer* renderer, double x, double z) static float _getTerrainHeight(Renderer* renderer, float x, float z)
{ {
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
{ {
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision); return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
} }

View file

@ -25,7 +25,7 @@ public:
configScaling(0.5, 5.0, 0.5, 2.5); configScaling(0.5, 5.0, 0.5, 2.5);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
y -= 100.0 * scaling; y -= 100.0 * scaling;
if (y > 0.0) if (y > 0.0)
@ -65,7 +65,7 @@ public:
configScaling(0.5, 5.0, 0.5, 2.5); configScaling(0.5, 5.0, 0.5, 2.5);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
y -= 100.0 * scaling; y -= 100.0 * scaling;
if (y > 0.0) if (y > 0.0)

View file

@ -23,9 +23,9 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
double height; float height;
height = terrainGetHeightNormalized(&_preview_definition, x, y); height = terrainGetHeightNormalized(&_preview_definition, x, y);
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height)); return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
@ -100,7 +100,7 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
return colorToQColor(terrainGetColor(&_terrain, &_renderer, x, y, scaling)); return colorToQColor(terrainGetColor(&_terrain, &_renderer, x, y, scaling));
} }
@ -115,12 +115,12 @@ private:
TexturesDefinition _textures; TexturesDefinition _textures;
LightingDefinition _lighting; LightingDefinition _lighting;
static double _getTerrainHeight(Renderer* renderer, double x, double z) static float _getTerrainHeight(Renderer* renderer, float x, float z)
{ {
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
{ {
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision); return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
} }

View file

@ -9,14 +9,14 @@ static TextureLayerDefinition _layer;
typedef struct typedef struct
{ {
double height_soft_min; float height_soft_min;
double height_hard_min; float height_hard_min;
double height_hard_max; float height_hard_max;
double height_soft_max; float height_soft_max;
double slope_soft_min; float slope_soft_min;
double slope_hard_min; float slope_hard_min;
double slope_hard_max; float slope_hard_max;
double slope_soft_max; float slope_soft_max;
} TextureSupp; } TextureSupp;
static TextureSupp _supp; static TextureSupp _supp;
@ -39,10 +39,10 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
Vector3 location; Vector3 location;
double coverage; float coverage;
location.x = x; location.x = x;
location.y = terrainGetHeight(&_terrain, x, y); location.y = terrainGetHeight(&_terrain, x, y);
location.z = y; location.z = y;
@ -56,7 +56,7 @@ protected:
} }
private: private:
static double _getTerrainHeight(Renderer* renderer, double x, double z) static float _getTerrainHeight(Renderer* renderer, float x, float z)
{ {
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
} }
@ -101,7 +101,7 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
Vector3 location; Vector3 location;
location.x = x; location.x = x;

View file

@ -28,9 +28,9 @@ public:
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
double height; float height;
height = terrainGetHeight(&_terrain, x, y); height = terrainGetHeight(&_terrain, x, y);
if (height > _definition.height) if (height > _definition.height)
@ -84,7 +84,7 @@ public:
//configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0); //configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(float x, float y)
{ {
Vector3 eye, look, location; Vector3 eye, look, location;
@ -126,7 +126,7 @@ private:
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds) static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
{ {
RayCastingResult result; RayCastingResult result;
double x, y; float x, y;
result.hit = 1; result.hit = 1;
if (direction.z < 0.0001) if (direction.z < 0.0001)

View file

@ -8,7 +8,7 @@
class CurveSmallPreview:public QWidget class CurveSmallPreview:public QWidget
{ {
public: public:
CurveSmallPreview(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax) : QWidget(parent) CurveSmallPreview(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax) : QWidget(parent)
{ {
_curve = curve; _curve = curve;
_xmin = xmin; _xmin = xmin;
@ -27,29 +27,29 @@ public:
QPainter painter(this); QPainter painter(this);
int width = this->width(); int width = this->width();
int height = this->height(); int height = this->height();
double position, value, prev_value, next_value; float position, value, prev_value, next_value;
painter.fillRect(rect(), QColor(255, 255, 255)); painter.fillRect(rect(), QColor(255, 255, 255));
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
painter.setPen(QColor(0, 0, 0)); painter.setPen(QColor(0, 0, 0));
position = _xmin + (_xmax - _xmin) * (double)x / (double)(width - 1); position = _xmin + (_xmax - _xmin) * (float)x / (float)(width - 1);
value = (curveGetValue(_curve, position) - _ymin) * (_ymax - _ymin); value = (curveGetValue(_curve, position) - _ymin) * (_ymax - _ymin);
prev_value = curveGetValue(_curve, position - 1.0 / (double)(width - 1)); prev_value = curveGetValue(_curve, position - 1.0 / (float)(width - 1));
next_value = curveGetValue(_curve, position + 1.0 / (double)(width - 1)); next_value = curveGetValue(_curve, position + 1.0 / (float)(width - 1));
painter.drawLine(x, height - 1 - (int)((value + (prev_value - value) / 2.0) * (double)(height - 1)), x, height - 1 - (int)((value + (next_value - value) / 2.0) * (double)(height - 1))); painter.drawLine(x, height - 1 - (int)((value + (prev_value - value) / 2.0) * (float)(height - 1)), x, height - 1 - (int)((value + (next_value - value) / 2.0) * (float)(height - 1)));
painter.drawPoint(x, height - 1 - (int)(value * (double)(height - 1))); painter.drawPoint(x, height - 1 - (int)(value * (float)(height - 1)));
} }
} }
Curve* _curve; Curve* _curve;
double _xmin; float _xmin;
double _xmax; float _xmax;
double _ymin; float _ymin;
double _ymax; float _ymax;
}; };
InputCurve::InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax) : BaseInput(form, label) InputCurve::InputCurve(QWidget* form, QString label, Curve* value, float xmin, float xmax, float ymin, float ymax) : BaseInput(form, label)
{ {
_value = value; _value = value;
_xmin = xmin; _xmin = xmin;

View file

@ -11,7 +11,7 @@ class InputCurve:public BaseInput
Q_OBJECT Q_OBJECT
public: public:
InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax); InputCurve(QWidget* form, QString label, Curve* value, float xmin, float xmax, float ymin, float ymax);
public slots: public slots:
virtual void updatePreview(); virtual void updatePreview();
@ -23,10 +23,10 @@ private slots:
private: private:
Curve* _value; Curve* _value;
double _xmin; float _xmin;
double _xmax; float _xmax;
double _ymin; float _ymin;
double _ymax; float _ymax;
}; };
#endif #endif

View file

@ -3,7 +3,7 @@
#include <QLabel> #include <QLabel>
#include "math.h" #include "math.h"
InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step): InputDouble::InputDouble(QWidget* form, QString label, float* value, float min, float max, float small_step, float large_step):
BaseInput(form, label), BaseInput(form, label),
value(value), min(min), max(max), small_step(small_step), large_step(large_step) value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{ {
@ -43,7 +43,7 @@ void InputDouble::applyValue()
} }
else else
{ {
*value = min + ((double)ivalue) * small_step; *value = min + ((float)ivalue) * small_step;
} }
if (fabs(*value) < 0.0000001) if (fabs(*value) < 0.0000001)
{ {

View file

@ -10,7 +10,7 @@ class InputDouble:public BaseInput
Q_OBJECT Q_OBJECT
public: public:
InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step); InputDouble(QWidget* form, QString label, float* value, float min, float max, float small_step, float large_step);
public slots: public slots:
virtual void updatePreview(); virtual void updatePreview();
@ -19,11 +19,11 @@ public slots:
private: private:
QSlider* slider; QSlider* slider;
double* value; float* value;
double min; float min;
double max; float max;
double small_step; float small_step;
double large_step; float large_step;
}; };
#endif // _PAYSAGES_QT_INPUTDOUBLE_H_ #endif // _PAYSAGES_QT_INPUTDOUBLE_H_

View file

@ -26,12 +26,12 @@ public:
QPainter painter(this); QPainter painter(this);
int width = this->width(); int width = this->width();
int height = this->height(); int height = this->height();
double value, factor; float value, factor;
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
factor = ((double)(height / 2)) / noiseGetMaxValue(noise); factor = ((float)(height / 2)) / noiseGetMaxValue(noise);
value = noiseGet1DTotal(noise, ((double)x) / factor) * factor; value = noiseGet1DTotal(noise, ((float)x) / factor) * factor;
painter.setPen(QColor(255, 255, 255)); painter.setPen(QColor(255, 255, 255));
painter.drawLine(x, 0, x, height / 2 + value); painter.drawLine(x, 0, x, height / 2 + value);
painter.setPen(QColor(0, 0, 0)); painter.setPen(QColor(0, 0, 0));

View file

@ -49,16 +49,16 @@ void PreviewColorGradation::paintEvent(QPaintEvent* event)
switch (band) switch (band)
{ {
case COLORGRADATIONBAND_RED: case COLORGRADATIONBAND_RED:
painter.setPen(QColor::fromRgbF(curveGetValue(curve, (double)x / (double)width), 0.0, 0.0)); painter.setPen(QColor::fromRgbF(curveGetValue(curve, (float)x / (float)width), 0.0, 0.0));
break; break;
case COLORGRADATIONBAND_GREEN: case COLORGRADATIONBAND_GREEN:
painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (double)x / (double)width), 0.0)); painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (float)x / (float)width), 0.0));
break; break;
case COLORGRADATIONBAND_BLUE: case COLORGRADATIONBAND_BLUE:
painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (double)x / (double)width))); painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (float)x / (float)width)));
break; break;
case COLORGRADATIONBAND_FINAL: case COLORGRADATIONBAND_FINAL:
painter.setPen(colorToQColor(colorGradationGet(gradation, (double)x / (double)width))); painter.setPen(colorToQColor(colorGradationGet(gradation, (float)x / (float)width)));
break; break;
} }
painter.drawLine(x, 0, x, height - 1); painter.drawLine(x, 0, x, height - 1);

View file

@ -39,9 +39,9 @@ SmallMaterialPreview::~SmallMaterialPreview()
rendererDelete(&_renderer); rendererDelete(&_renderer);
} }
QColor SmallMaterialPreview::getColor(double x, double y) QColor SmallMaterialPreview::getColor(float x, float y)
{ {
double dist = sqrt(x * x + y * y); float dist = sqrt(x * x + y * y);
Vector3 point; Vector3 point;
Color color; Color color;
@ -77,24 +77,24 @@ void SmallMaterialPreview::paintEvent(QPaintEvent* event)
QPainter painter(this); QPainter painter(this);
int width = this->width(); int width = this->width();
int height = this->height(); int height = this->height();
double factor, dx, dy; float factor, dx, dy;
if (width > height) if (width > height)
{ {
factor = 2.0 / (double)height; factor = 2.0 / (float)height;
} }
else else
{ {
factor = 2.0 / (double)width; factor = 2.0 / (float)width;
} }
dx = factor * (double)width / 2.0; dx = factor * (float)width / 2.0;
dy = factor * (double)height / 2.0; dy = factor * (float)height / 2.0;
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
painter.setPen(getColor((double)x * factor - dx, (double)y * factor - dy)); painter.setPen(getColor((float)x * factor - dx, (float)y * factor - dy));
painter.drawPoint(x, y); painter.drawPoint(x, y);
} }
} }
@ -115,7 +115,7 @@ PreviewMaterial::~PreviewMaterial()
delete _small; delete _small;
} }
QColor PreviewMaterial::getColor(double x, double y) QColor PreviewMaterial::getColor(float x, float y)
{ {
return _small->getColor(x, y); return _small->getColor(x, y);
} }

View file

@ -12,7 +12,7 @@ public:
SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material); SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material);
~SmallMaterialPreview(); ~SmallMaterialPreview();
QColor getColor(double x, double y); QColor getColor(float x, float y);
protected: protected:
virtual void paintEvent(QPaintEvent* event); virtual void paintEvent(QPaintEvent* event);
@ -32,7 +32,7 @@ public:
~PreviewMaterial(); ~PreviewMaterial();
protected: protected:
virtual QColor getColor(double x, double y); virtual QColor getColor(float x, float y);
private: private:
SmallMaterialPreview* _small; SmallMaterialPreview* _small;

View file

@ -4,7 +4,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include "../lib_paysages/tools.h" #include "../lib_paysages/tools.h"
WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax, double ymin, double ymax) : QWidget(parent) WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, float xmin, float xmax, float ymin, float ymax) : QWidget(parent)
{ {
_curve = curveCreate(); _curve = curveCreate();
_dragged = -1; _dragged = -1;
@ -39,14 +39,14 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event)
{ {
int i, n; int i, n;
int width, height; int width, height;
double dwidth, dheight; float dwidth, dheight;
CurvePoint point; CurvePoint point;
double position, value, prev_value, next_value; float position, value, prev_value, next_value;
width = this->width(); width = this->width();
height = this->height(); height = this->height();
dheight = (double)(height - 1); dheight = (float)(height - 1);
dwidth = (double)(width - 1); dwidth = (float)(width - 1);
QPainter painter(this); QPainter painter(this);
painter.fillRect(0, 0, width, height, QColor(255, 255, 255)); painter.fillRect(0, 0, width, height, QColor(255, 255, 255));
@ -54,7 +54,7 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event)
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
position = ((double)x) / dwidth; position = ((float)x) / dwidth;
value = curveGetValue(_curve, position); value = curveGetValue(_curve, position);
prev_value = curveGetValue(_curve, position - 1.0 / dwidth); prev_value = curveGetValue(_curve, position - 1.0 / dwidth);
@ -88,8 +88,8 @@ void WidgetCurveEditor::mouseMoveEvent(QMouseEvent* event)
if (_dragged >= 0 && (event->buttons() & Qt::LeftButton)) if (_dragged >= 0 && (event->buttons() & Qt::LeftButton))
{ {
point.position = ((double)event->x()) / (double)(width() - 1); point.position = ((float)event->x()) / (float)(width() - 1);
point.value = 1.0 - ((double)event->y()) / (double)(height() - 1); point.value = 1.0 - ((float)event->y()) / (float)(height() - 1);
point.position = (point.position < 0.0) ? 0.0 : point.position; point.position = (point.position < 0.0) ? 0.0 : point.position;
point.position = (point.position > 1.0) ? 1.0 : point.position; point.position = (point.position > 1.0) ? 1.0 : point.position;
@ -138,8 +138,8 @@ void WidgetCurveEditor::mouseDoubleClickEvent(QMouseEvent* event)
{ {
if (getPointAt(event->x(), event->y()) < 0) if (getPointAt(event->x(), event->y()) < 0)
{ {
point.position = ((double)event->x()) / (double)(width() - 1); point.position = ((float)event->x()) / (float)(width() - 1);
point.value = 1.0 - ((double)event->y()) / (double)(height() - 1); point.value = 1.0 - ((float)event->y()) / (float)(height() - 1);
curveAddPoint(_curve, &point); curveAddPoint(_curve, &point);
curveValidate(_curve); curveValidate(_curve);
@ -153,10 +153,10 @@ int WidgetCurveEditor::getPointAt(int x, int y)
{ {
int n; int n;
int nearest; int nearest;
double distance, ndistance; float distance, ndistance;
CurvePoint point; CurvePoint point;
double dx = ((double)x) / (double)(width() - 1); float dx = ((float)x) / (float)(width() - 1);
double dy = 1.0 - ((double)y) / (double)(height() - 1); float dy = 1.0 - ((float)y) / (float)(height() - 1);
n = curveGetPointCount(_curve); n = curveGetPointCount(_curve);
if (n < 1) if (n < 1)

View file

@ -10,7 +10,7 @@ class WidgetCurveEditor : public QWidget
Q_OBJECT Q_OBJECT
public: public:
WidgetCurveEditor(QWidget* parent, double xmin, double xmax, double ymin, double ymax); WidgetCurveEditor(QWidget* parent, float xmin, float xmax, float ymin, float ymax);
~WidgetCurveEditor(); ~WidgetCurveEditor();
void setCurve(Curve* curve); void setCurve(Curve* curve);

View file

@ -48,12 +48,12 @@ private:
static QVector<ChunkMaintenanceThread*> _threads; static QVector<ChunkMaintenanceThread*> _threads;
static double _getTerrainHeight(Renderer* renderer, double x, double z) static float _getTerrainHeight(Renderer* renderer, float x, float z)
{ {
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
{ {
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision); return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
} }
@ -103,14 +103,14 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
// Add terrain // Add terrain
int chunks = 20; int chunks = 20;
double size = 200.0; float size = 200.0;
double chunksize = size / (double)chunks; float chunksize = size / (float)chunks;
double start = -size / 2.0; float start = -size / 2.0;
for (int i = 0; i < chunks; i++) for (int i = 0; i < chunks; i++)
{ {
for (int j = 0; j < chunks; j++) for (int j = 0; j < chunks; j++)
{ {
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(&_renderer, start + chunksize * (double)i, start + chunksize * (double)j, chunksize, chunks); ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(&_renderer, start + chunksize * (float)i, start + chunksize * (float)j, chunksize, chunks);
_chunks.append(chunk); _chunks.append(chunk);
_updateQueue.append(chunk); _updateQueue.append(chunk);
} }
@ -228,7 +228,7 @@ void WidgetExplorer::validateCamera()
void WidgetExplorer::keyPressEvent(QKeyEvent* event) void WidgetExplorer::keyPressEvent(QKeyEvent* event)
{ {
double factor; float factor;
if (event->modifiers() & Qt::ControlModifier) if (event->modifiers() & Qt::ControlModifier)
{ {
@ -290,7 +290,7 @@ void WidgetExplorer::mousePressEvent(QMouseEvent* event)
void WidgetExplorer::mouseMoveEvent(QMouseEvent* event) void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
{ {
double factor; float factor;
if (event->modifiers() & Qt::ControlModifier) if (event->modifiers() & Qt::ControlModifier)
{ {
@ -308,15 +308,15 @@ void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
if (event->buttons() & Qt::LeftButton) if (event->buttons() & Qt::LeftButton)
{ {
cameraRotateYaw(&_current_camera, (double)(event->x() - _last_mouse_x) * factor * 0.1); cameraRotateYaw(&_current_camera, (float)(event->x() - _last_mouse_x) * factor * 0.1);
cameraRotatePitch(&_current_camera, (double)(event->y() - _last_mouse_y) * factor * 0.1); cameraRotatePitch(&_current_camera, (float)(event->y() - _last_mouse_y) * factor * 0.1);
updateGL(); updateGL();
event->accept(); event->accept();
} }
else if (event->buttons() & Qt::RightButton) else if (event->buttons() & Qt::RightButton)
{ {
cameraStrafeRight(&_current_camera, (double)(_last_mouse_x - event->x()) * factor); cameraStrafeRight(&_current_camera, (float)(_last_mouse_x - event->x()) * factor);
cameraStrafeUp(&_current_camera, (double)(event->y() - _last_mouse_y) * factor); cameraStrafeUp(&_current_camera, (float)(event->y() - _last_mouse_y) * factor);
updateGL(); updateGL();
event->accept(); event->accept();
} }
@ -331,7 +331,7 @@ void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
void WidgetExplorer::wheelEvent(QWheelEvent* event) void WidgetExplorer::wheelEvent(QWheelEvent* event)
{ {
double factor; float factor;
if (event->modifiers() & Qt::ControlModifier) if (event->modifiers() & Qt::ControlModifier)
{ {
@ -349,7 +349,7 @@ void WidgetExplorer::wheelEvent(QWheelEvent* event)
if (event->orientation() == Qt::Vertical) if (event->orientation() == Qt::Vertical)
{ {
cameraStrafeForward(&_current_camera, (double)event->delta() * factor); cameraStrafeForward(&_current_camera, (float)event->delta() * factor);
updateGL(); updateGL();
} }
@ -413,7 +413,7 @@ void WidgetExplorer::paintGL()
{ {
GLenum error_code; GLenum error_code;
QTime start_time; QTime start_time;
double frame_time; float frame_time;
if (_current_camera.location.y > 30.0) if (_current_camera.location.y > 30.0)
{ {
@ -452,7 +452,7 @@ void WidgetExplorer::paintGL()
_chunks[i]->render(this); _chunks[i]->render(this);
} }
frame_time = 0.001 * (double)start_time.msecsTo(QTime::currentTime()); frame_time = 0.001 * (float)start_time.msecsTo(QTime::currentTime());
_average_frame_time = _average_frame_time * 0.8 + frame_time * 0.2; _average_frame_time = _average_frame_time * 0.8 + frame_time * 0.2;
//printf("%d %f\n", quality, average_frame_time); //printf("%d %f\n", quality, average_frame_time);

View file

@ -56,7 +56,7 @@ private:
TexturesDefinition _textures; TexturesDefinition _textures;
LightingDefinition _lighting; LightingDefinition _lighting;
double _average_frame_time; float _average_frame_time;
int _quality; int _quality;
int _last_mouse_x; int _last_mouse_x;

View file

@ -254,6 +254,11 @@ Maintenir Ctrl : Plus lent</translation>
<source>Paysages 3D - Render</source> <source>Paysages 3D - Render</source>
<translation>Paysages 3D - Rendu</translation> <translation>Paysages 3D - Rendu</translation>
</message> </message>
<message>
<location filename="../gui_qt/dialogrender.cpp" line="162"/>
<source>%1:%2.%3</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>DialogWanderer</name> <name>DialogWanderer</name>

View file

@ -15,18 +15,18 @@ void atmosphereQuit()
void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition) void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition)
{ {
packWriteDouble(stream, &definition->distance_near); packWriteFloat(stream, &definition->distance_near);
packWriteDouble(stream, &definition->distance_far); packWriteFloat(stream, &definition->distance_far);
packWriteDouble(stream, &definition->full_mask); packWriteFloat(stream, &definition->full_mask);
packWriteInt(stream, &definition->auto_lock_on_haze); packWriteInt(stream, &definition->auto_lock_on_haze);
colorSave(stream, &definition->color); colorSave(stream, &definition->color);
} }
void atmosphereLoad(PackStream* stream, AtmosphereDefinition* definition) void atmosphereLoad(PackStream* stream, AtmosphereDefinition* definition)
{ {
packReadDouble(stream, &definition->distance_near); packReadFloat(stream, &definition->distance_near);
packReadDouble(stream, &definition->distance_far); packReadFloat(stream, &definition->distance_far);
packReadDouble(stream, &definition->full_mask); packReadFloat(stream, &definition->full_mask);
packReadInt(stream, &definition->auto_lock_on_haze); packReadInt(stream, &definition->auto_lock_on_haze);
colorLoad(stream, &definition->color); colorLoad(stream, &definition->color);
@ -85,8 +85,8 @@ void atmosphereValidateDefinition(AtmosphereDefinition* definition)
Color atmosphereApply(AtmosphereDefinition* definition, Renderer* renderer, Vector3 location, Color base) Color atmosphereApply(AtmosphereDefinition* definition, Renderer* renderer, Vector3 location, Color base)
{ {
Color mask = definition->color; Color mask = definition->color;
double distance = v3Norm(v3Sub(renderer->camera_location, location)); float distance = v3Norm(v3Sub(renderer->camera_location, location));
double value; float value;
if (distance < definition->distance_near) if (distance < definition->distance_near)
{ {

View file

@ -12,9 +12,9 @@ extern "C" {
typedef struct typedef struct
{ {
double distance_near; float distance_near;
double distance_far; float distance_far;
double full_mask; float full_mask;
int auto_lock_on_haze; int auto_lock_on_haze;
Color color; Color color;
} AtmosphereDefinition; } AtmosphereDefinition;

View file

@ -20,10 +20,10 @@
void autoSetDaytime(int hour, int minute) void autoSetDaytime(int hour, int minute)
{ {
autoSetDaytimeFraction((double)hour / 24.0 + (double)minute / 1440.0); autoSetDaytimeFraction((float)hour / 24.0 + (float)minute / 1440.0);
} }
void autoSetDaytimeFraction(double daytime) void autoSetDaytimeFraction(float daytime)
{ {
SkyDefinition sky; SkyDefinition sky;
/*ColorGradation grad_sun; /*ColorGradation grad_sun;

View file

@ -8,7 +8,7 @@ extern "C" {
#endif #endif
void autoSetDaytime(int hour, int minute); void autoSetDaytime(int hour, int minute);
void autoSetDaytimeFraction(double daytime); void autoSetDaytimeFraction(float daytime);
void autoGenRealisticLandscape(int seed); void autoGenRealisticLandscape(int seed);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -20,17 +20,17 @@ void cameraQuit()
void cameraSave(PackStream* stream, CameraDefinition* camera) void cameraSave(PackStream* stream, CameraDefinition* camera)
{ {
v3Save(stream, &camera->location); v3Save(stream, &camera->location);
packWriteDouble(stream, &camera->yaw); packWriteFloat(stream, &camera->yaw);
packWriteDouble(stream, &camera->pitch); packWriteFloat(stream, &camera->pitch);
packWriteDouble(stream, &camera->roll); packWriteFloat(stream, &camera->roll);
} }
void cameraLoad(PackStream* stream, CameraDefinition* camera) void cameraLoad(PackStream* stream, CameraDefinition* camera)
{ {
v3Load(stream, &camera->location); v3Load(stream, &camera->location);
packReadDouble(stream, &camera->yaw); packReadFloat(stream, &camera->yaw);
packReadDouble(stream, &camera->pitch); packReadFloat(stream, &camera->pitch);
packReadDouble(stream, &camera->roll); packReadFloat(stream, &camera->roll);
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
@ -73,7 +73,7 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
{ {
WaterDefinition water; WaterDefinition water;
TerrainDefinition terrain; TerrainDefinition terrain;
double water_height, terrain_height, diff; float water_height, terrain_height, diff;
Vector3 move; Vector3 move;
Matrix4 rotation; Matrix4 rotation;
@ -128,7 +128,7 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
definition->unproject = m4Inverse(definition->project); definition->unproject = m4Inverse(definition->project);
} }
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z) void cameraSetLocation(CameraDefinition* camera, float x, float y, float z)
{ {
camera->location.x = x; camera->location.x = x;
camera->location.y = y; camera->location.y = y;
@ -137,7 +137,7 @@ void cameraSetLocation(CameraDefinition* camera, double x, double y, double z)
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraSetTarget(CameraDefinition* camera, double x, double y, double z) void cameraSetTarget(CameraDefinition* camera, float x, float y, float z)
{ {
Vector3 forward, target; Vector3 forward, target;
@ -172,49 +172,49 @@ void cameraSetTarget(CameraDefinition* camera, double x, double y, double z)
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraSetRoll(CameraDefinition* camera, double angle) void cameraSetRoll(CameraDefinition* camera, float angle)
{ {
camera->roll = angle; camera->roll = angle;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraStrafeForward(CameraDefinition* camera, double value) void cameraStrafeForward(CameraDefinition* camera, float value)
{ {
camera->location = v3Add(camera->location, v3Scale(camera->forward, value)); camera->location = v3Add(camera->location, v3Scale(camera->forward, value));
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraStrafeRight(CameraDefinition* camera, double value) void cameraStrafeRight(CameraDefinition* camera, float value)
{ {
camera->location = v3Add(camera->location, v3Scale(camera->right, value)); camera->location = v3Add(camera->location, v3Scale(camera->right, value));
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraStrafeUp(CameraDefinition* camera, double value) void cameraStrafeUp(CameraDefinition* camera, float value)
{ {
camera->location = v3Add(camera->location, v3Scale(camera->up, value)); camera->location = v3Add(camera->location, v3Scale(camera->up, value));
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraRotateYaw(CameraDefinition* camera, double value) void cameraRotateYaw(CameraDefinition* camera, float value)
{ {
camera->yaw += value; camera->yaw += value;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraRotatePitch(CameraDefinition* camera, double value) void cameraRotatePitch(CameraDefinition* camera, float value)
{ {
camera->pitch += value; camera->pitch += value;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraRotateRoll(CameraDefinition* camera, double value) void cameraRotateRoll(CameraDefinition* camera, float value)
{ {
camera->roll += value; camera->roll += value;
@ -223,8 +223,8 @@ void cameraRotateRoll(CameraDefinition* camera, double value)
void cameraSetRenderSize(CameraDefinition* camera, int width, int height) void cameraSetRenderSize(CameraDefinition* camera, int width, int height)
{ {
camera->width = (double)width; camera->width = (float)width;
camera->height = (double)height; camera->height = (float)height;
camera->xratio = camera->width / camera->height; camera->xratio = camera->width / camera->height;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
@ -250,7 +250,7 @@ Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 po
return m4Transform(camera->unproject, point); return m4Transform(camera->unproject, point);
} }
void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, double x, double y, double z, RenderFragment* result) void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float x, float y, float z, RenderFragment* result)
{ {
Vector3 point = {x, y, z}; Vector3 point = {x, y, z};
point = cameraProject(camera, renderer, point); point = cameraProject(camera, renderer, point);
@ -279,20 +279,20 @@ void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, doubl
v1.callback = callback; v1.callback = callback;
v.x = 0.0; v.x = 0.0;
v.y = (double)render_height; v.y = (float)render_height;
v.z = 10.0; v.z = 10.0;
v2.location = cameraUnproject(camera, v); v2.location = cameraUnproject(camera, v);
v2.color = col; v2.color = col;
v2.callback = callback; v2.callback = callback;
v.x = (double)render_width; v.x = (float)render_width;
v.y = (double)render_height; v.y = (float)render_height;
v.z = 10.0; v.z = 10.0;
v3.location = cameraUnproject(camera, v); v3.location = cameraUnproject(camera, v);
v3.color = col; v3.color = col;
v3.callback = callback; v3.callback = callback;
v.x = (double)render_width; v.x = (float)render_width;
v.y = 0.0; v.y = 0.0;
v.z = 10.0; v.z = 10.0;
v4.location = cameraUnproject(camera, v); v4.location = cameraUnproject(camera, v);
@ -302,7 +302,7 @@ void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, doubl
renderPushQuad(&v1, &v2, &v3, &v4); renderPushQuad(&v1, &v2, &v3, &v4);
}*/ }*/
static inline void _updateBox(Vector3* point, double* xmin, double* xmax, double* ymin, double* ymax, double* zmax) static inline void _updateBox(Vector3* point, float* xmin, float* xmax, float* ymin, float* ymax, float* zmax)
{ {
*xmin = MIN(*xmin, point->x); *xmin = MIN(*xmin, point->x);
*xmax = MAX(*xmax, point->x); *xmax = MAX(*xmax, point->x);
@ -311,10 +311,10 @@ static inline void _updateBox(Vector3* point, double* xmin, double* xmax, double
*zmax = MAX(*zmax, point->z); *zmax = MAX(*zmax, point->z);
} }
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize) int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, float xsize, float ysize, float zsize)
{ {
Vector3 projected; Vector3 projected;
double xmin, xmax, ymin, ymax, zmax; float xmin, xmax, ymin, ymax, zmax;
center.x -= xsize / 2.0; center.x -= xsize / 2.0;
center.y -= ysize / 2.0; center.y -= ysize / 2.0;

View file

@ -19,24 +19,24 @@ void cameraDeleteDefinition(CameraDefinition* definition);
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination); void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination);
void cameraValidateDefinition(CameraDefinition* definition, int check_above); void cameraValidateDefinition(CameraDefinition* definition, int check_above);
void cameraSetLocation(CameraDefinition* camera, double x, double y, double z); void cameraSetLocation(CameraDefinition* camera, float x, float y, float z);
void cameraSetTarget(CameraDefinition* camera, double x, double y, double z); void cameraSetTarget(CameraDefinition* camera, float x, float y, float z);
void cameraSetRoll(CameraDefinition* camera, double angle); void cameraSetRoll(CameraDefinition* camera, float angle);
void cameraStrafeForward(CameraDefinition* camera, double value); void cameraStrafeForward(CameraDefinition* camera, float value);
void cameraStrafeRight(CameraDefinition* camera, double value); void cameraStrafeRight(CameraDefinition* camera, float value);
void cameraStrafeUp(CameraDefinition* camera, double value); void cameraStrafeUp(CameraDefinition* camera, float value);
void cameraRotateYaw(CameraDefinition* camera, double value); void cameraRotateYaw(CameraDefinition* camera, float value);
void cameraRotatePitch(CameraDefinition* camera, double value); void cameraRotatePitch(CameraDefinition* camera, float value);
void cameraRotateRoll(CameraDefinition* camera, double value); void cameraRotateRoll(CameraDefinition* camera, float value);
void cameraSetRenderSize(CameraDefinition* camera, int width, int height); void cameraSetRenderSize(CameraDefinition* camera, int width, int height);
Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 point); Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 point);
Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 point); Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 point);
void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, double x, double y, double z, RenderFragment* result); void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float x, float y, float z, RenderFragment* result);
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/ /*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize); int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, float xsize, float ysize, float zsize);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -13,7 +13,7 @@ typedef struct
{ {
Vector3 start; Vector3 start;
Vector3 end; Vector3 end;
double length; float length;
} CloudSegment; } CloudSegment;
static CloudsLayerDefinition NULL_LAYER; static CloudsLayerDefinition NULL_LAYER;
@ -39,20 +39,20 @@ void cloudsSave(PackStream* stream, CloudsDefinition* definition)
{ {
layer = definition->layers + i; layer = definition->layers + i;
packWriteDouble(stream, &layer->ymin); packWriteFloat(stream, &layer->ymin);
packWriteDouble(stream, &layer->ymax); packWriteFloat(stream, &layer->ymax);
curveSave(stream, layer->coverage_by_altitude); curveSave(stream, layer->coverage_by_altitude);
noiseSaveGenerator(stream, layer->shape_noise); noiseSaveGenerator(stream, layer->shape_noise);
noiseSaveGenerator(stream, layer->edge_noise); noiseSaveGenerator(stream, layer->edge_noise);
materialSave(stream, &layer->material); materialSave(stream, &layer->material);
packWriteDouble(stream, &layer->hardness); packWriteFloat(stream, &layer->hardness);
packWriteDouble(stream, &layer->transparencydepth); packWriteFloat(stream, &layer->transparencydepth);
packWriteDouble(stream, &layer->lighttraversal); packWriteFloat(stream, &layer->lighttraversal);
packWriteDouble(stream, &layer->minimumlight); packWriteFloat(stream, &layer->minimumlight);
packWriteDouble(stream, &layer->shape_scaling); packWriteFloat(stream, &layer->shape_scaling);
packWriteDouble(stream, &layer->edge_scaling); packWriteFloat(stream, &layer->edge_scaling);
packWriteDouble(stream, &layer->edge_length); packWriteFloat(stream, &layer->edge_length);
packWriteDouble(stream, &layer->base_coverage); packWriteFloat(stream, &layer->base_coverage);
} }
} }
@ -71,20 +71,20 @@ void cloudsLoad(PackStream* stream, CloudsDefinition* definition)
{ {
layer = definition->layers + cloudsAddLayer(definition); layer = definition->layers + cloudsAddLayer(definition);
packReadDouble(stream, &layer->ymin); packReadFloat(stream, &layer->ymin);
packReadDouble(stream, &layer->ymax); packReadFloat(stream, &layer->ymax);
curveLoad(stream, layer->coverage_by_altitude); curveLoad(stream, layer->coverage_by_altitude);
noiseLoadGenerator(stream, layer->shape_noise); noiseLoadGenerator(stream, layer->shape_noise);
noiseLoadGenerator(stream, layer->edge_noise); noiseLoadGenerator(stream, layer->edge_noise);
materialLoad(stream, &layer->material); materialLoad(stream, &layer->material);
packReadDouble(stream, &layer->hardness); packReadFloat(stream, &layer->hardness);
packReadDouble(stream, &layer->transparencydepth); packReadFloat(stream, &layer->transparencydepth);
packReadDouble(stream, &layer->lighttraversal); packReadFloat(stream, &layer->lighttraversal);
packReadDouble(stream, &layer->minimumlight); packReadFloat(stream, &layer->minimumlight);
packReadDouble(stream, &layer->shape_scaling); packReadFloat(stream, &layer->shape_scaling);
packReadDouble(stream, &layer->edge_scaling); packReadFloat(stream, &layer->edge_scaling);
packReadDouble(stream, &layer->edge_length); packReadFloat(stream, &layer->edge_length);
packReadDouble(stream, &layer->base_coverage); packReadFloat(stream, &layer->base_coverage);
} }
} }
@ -130,7 +130,7 @@ void cloudsValidateDefinition(CloudsDefinition* definition)
} }
} }
static double _standardCoverageFunc(CloudsLayerDefinition* layer, Vector3 position) static float _standardCoverageFunc(CloudsLayerDefinition* layer, Vector3 position)
{ {
if (position.y > layer->ymax || position.y < layer->ymin) if (position.y > layer->ymax || position.y < layer->ymin)
{ {
@ -269,9 +269,9 @@ void cloudsDeleteLayer(CloudsDefinition* definition, int layer)
} }
} }
static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position) static inline float _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position)
{ {
double density, coverage, val; float density, coverage, val;
val = noiseGet3DTotal(layer->shape_noise, position.x / layer->shape_scaling, position.y / layer->shape_scaling, position.z / layer->shape_scaling) / noiseGetMaxValue(layer->shape_noise); val = noiseGet3DTotal(layer->shape_noise, position.x / layer->shape_scaling, position.y / layer->shape_scaling, position.z / layer->shape_scaling) / noiseGetMaxValue(layer->shape_noise);
coverage = layer->_custom_coverage(layer, position); coverage = layer->_custom_coverage(layer, position);
@ -302,11 +302,11 @@ static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3
} }
} }
static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, double detail) static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, float detail)
{ {
Vector3 result = {0.0, 0.0, 0.0}; Vector3 result = {0.0, 0.0, 0.0};
Vector3 dposition; Vector3 dposition;
double val, dval; float val, dval;
val = _getDistanceToBorder(layer, position); val = _getDistanceToBorder(layer, position);
@ -418,21 +418,21 @@ static int _optimizeSearchLimits(CloudsLayerDefinition* layer, Vector3* start, V
* @param out_segments Allocated space to fill found segments * @param out_segments Allocated space to fill found segments
* @return Number of segments found * @return Number of segments found
*/ */
static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, double detail, int max_segments, double max_inside_length, double max_total_length, double* inside_length, double* total_length, CloudSegment* out_segments) static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, float detail, int max_segments, float max_inside_length, float max_total_length, float* inside_length, float* total_length, CloudSegment* out_segments)
{ {
int inside, segment_count; int inside, segment_count;
double current_total_length, current_inside_length; float current_total_length, current_inside_length;
double step_length, segment_length, remaining_length; float step_length, segment_length, remaining_length;
double noise_distance, last_noise_distance; float noise_distance, last_noise_distance;
Vector3 walker, step, segment_start; Vector3 walker, step, segment_start;
double render_precision; float render_precision;
if (max_segments <= 0) if (max_segments <= 0)
{ {
return 0; return 0;
} }
render_precision = 15.2 - 1.5 * (double)renderer->render_quality; render_precision = 15.2 - 1.5 * (float)renderer->render_quality;
render_precision = render_precision * definition->shape_scaling / 50.0; render_precision = render_precision * definition->shape_scaling / 50.0;
if (render_precision > max_total_length / 10.0) if (render_precision > max_total_length / 10.0)
{ {
@ -513,7 +513,7 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer,
return segment_count; return segment_count;
} }
static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 position, double detail) static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 position, float detail)
{ {
Vector3 normal; Vector3 normal;
Color col1, col2; Color col1, col2;
@ -546,7 +546,7 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
Color cloudsGetLayerColor(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 end) Color cloudsGetLayerColor(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 end)
{ {
int i, segment_count; int i, segment_count;
double max_length, detail, total_length, inside_length; float max_length, detail, total_length, inside_length;
Vector3 direction; Vector3 direction;
Color result, col; Color result, col;
CloudSegment segments[20]; CloudSegment segments[20];
@ -613,7 +613,7 @@ Color cloudsGetColor(CloudsDefinition* definition, Renderer* renderer, Vector3 s
Color cloudsLayerFilterLight(CloudsLayerDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light) Color cloudsLayerFilterLight(CloudsLayerDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{ {
double inside_depth, total_depth, factor; float inside_depth, total_depth, factor;
CloudSegment segments[20]; CloudSegment segments[20];
_optimizeSearchLimits(definition, &location, &light_location); _optimizeSearchLimits(definition, &location, &light_location);

View file

@ -14,24 +14,24 @@ extern "C" {
typedef struct CloudsLayerDefinition CloudsLayerDefinition; typedef struct CloudsLayerDefinition CloudsLayerDefinition;
typedef double (*CloudCoverageFunc)(CloudsLayerDefinition* definition, Vector3 position); typedef float (*CloudCoverageFunc)(CloudsLayerDefinition* definition, Vector3 position);
struct CloudsLayerDefinition struct CloudsLayerDefinition
{ {
double ymin; float ymin;
double ymax; float ymax;
double base_coverage; float base_coverage;
Curve* coverage_by_altitude; Curve* coverage_by_altitude;
NoiseGenerator* shape_noise; NoiseGenerator* shape_noise;
double shape_scaling; float shape_scaling;
NoiseGenerator* edge_noise; NoiseGenerator* edge_noise;
double edge_scaling; float edge_scaling;
double edge_length; float edge_length;
SurfaceMaterial material; SurfaceMaterial material;
double hardness; float hardness;
double transparencydepth; float transparencydepth;
double lighttraversal; float lighttraversal;
double minimumlight; float minimumlight;
CloudCoverageFunc _custom_coverage; CloudCoverageFunc _custom_coverage;
}; };

View file

@ -23,18 +23,18 @@ struct ColorGradation
void colorSave(PackStream* stream, Color* col) void colorSave(PackStream* stream, Color* col)
{ {
packWriteDouble(stream, &col->r); packWriteFloat(stream, &col->r);
packWriteDouble(stream, &col->g); packWriteFloat(stream, &col->g);
packWriteDouble(stream, &col->b); packWriteFloat(stream, &col->b);
packWriteDouble(stream, &col->a); packWriteFloat(stream, &col->a);
} }
void colorLoad(PackStream* stream, Color* col) void colorLoad(PackStream* stream, Color* col)
{ {
packReadDouble(stream, &col->r); packReadFloat(stream, &col->r);
packReadDouble(stream, &col->g); packReadFloat(stream, &col->g);
packReadDouble(stream, &col->b); packReadFloat(stream, &col->b);
packReadDouble(stream, &col->a); packReadFloat(stream, &col->a);
} }
unsigned int colorTo32BitRGBA(Color* col) unsigned int colorTo32BitRGBA(Color* col)
@ -59,15 +59,15 @@ unsigned int colorTo32BitABGR(Color* col)
void colorMask(Color* base, Color* mask) void colorMask(Color* base, Color* mask)
{ {
double new_a; float new_a;
new_a = base->a + mask->a - (base->a * mask->a); new_a = base->a + mask->a - (base->a * mask->a);
base->r = (mask->r * mask->a + base->r * base->a - base->r * base->a * mask->a) / new_a; base->r = (mask->r * mask->a + base->r * base->a - base->r * base->a * mask->a) / new_a;
base->g = (mask->g * mask->a + base->g * base->a - base->g * base->a * mask->a) / new_a; base->g = (mask->g * mask->a + base->g * base->a - base->g * base->a * mask->a) / new_a;
base->b = (mask->b * mask->a + base->b * base->a - base->b * base->a * mask->a) / new_a; base->b = (mask->b * mask->a + base->b * base->a - base->b * base->a * mask->a) / new_a;
base->a = new_a; base->a = new_a;
/*double mask_weight = mask->a; /*float mask_weight = mask->a;
double base_weight = 1.0 - mask_weight; float base_weight = 1.0 - mask_weight;
base->r = mask->r * mask_weight + base->r * base_weight; base->r = mask->r * mask_weight + base->r * base_weight;
base->g = mask->g * mask_weight + base->g * base_weight; base->g = mask->g * mask_weight + base->g * base_weight;
@ -75,9 +75,9 @@ void colorMask(Color* base, Color* mask)
base->a = base->a + mask_weight * (1.0 - base->a);*/ base->a = base->a + mask_weight * (1.0 - base->a);*/
} }
double colorNormalize(Color* col) float colorNormalize(Color* col)
{ {
double max = colorGetValue(col); float max = colorGetValue(col);
assert(col->r >= 0.0); assert(col->r >= 0.0);
assert(col->g >= 0.0); assert(col->g >= 0.0);
@ -93,9 +93,9 @@ double colorNormalize(Color* col)
return max; return max;
} }
double colorGetValue(Color* col) float colorGetValue(Color* col)
{ {
double max; float max;
max = col->r; max = col->r;
if (col->g > max) if (col->g > max)
@ -183,12 +183,12 @@ void colorGradationSetBlueCurve(ColorGradation* gradation, Curve* curve)
curveValidate(gradation->blue); curveValidate(gradation->blue);
} }
void colorGradationQuickAdd(ColorGradation* gradation, double value, Color* col) void colorGradationQuickAdd(ColorGradation* gradation, float value, Color* col)
{ {
colorGradationQuickAddRgb(gradation, value, col->r, col->g, col->b); colorGradationQuickAddRgb(gradation, value, col->r, col->g, col->b);
} }
void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r, double g, double b) void colorGradationQuickAddRgb(ColorGradation* gradation, float value, float r, float g, float b)
{ {
curveQuickAddPoint(gradation->red, value, r); curveQuickAddPoint(gradation->red, value, r);
curveValidate(gradation->red); curveValidate(gradation->red);
@ -200,7 +200,7 @@ void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r
curveValidate(gradation->blue); curveValidate(gradation->blue);
} }
Color colorGradationGet(ColorGradation* gradation, double value) Color colorGradationGet(ColorGradation* gradation, float value)
{ {
Color result; Color result;

View file

@ -9,10 +9,10 @@ extern "C" {
typedef struct typedef struct
{ {
double r; float r;
double g; float g;
double b; float b;
double a; float a;
} Color; } Color;
extern Color COLOR_TRANSPARENT; extern Color COLOR_TRANSPARENT;
@ -33,8 +33,8 @@ unsigned int colorTo32BitARGB(Color* col);
unsigned int colorTo32BitABGR(Color* col); unsigned int colorTo32BitABGR(Color* col);
void colorMask(Color* base, Color* mask); void colorMask(Color* base, Color* mask);
double colorNormalize(Color* col); float colorNormalize(Color* col);
double colorGetValue(Color* col); float colorGetValue(Color* col);
/* ColorGradation */ /* ColorGradation */
typedef struct ColorGradation ColorGradation; typedef struct ColorGradation ColorGradation;
@ -54,10 +54,10 @@ void colorGradationSetRedCurve(ColorGradation* gradation, Curve* curve);
void colorGradationSetGreenCurve(ColorGradation* gradation, Curve* curve); void colorGradationSetGreenCurve(ColorGradation* gradation, Curve* curve);
void colorGradationSetBlueCurve(ColorGradation* gradation, Curve* curve); void colorGradationSetBlueCurve(ColorGradation* gradation, Curve* curve);
void colorGradationQuickAdd(ColorGradation* gradation, double value, Color* col); void colorGradationQuickAdd(ColorGradation* gradation, float value, Color* col);
void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r, double g, double b); void colorGradationQuickAddRgb(ColorGradation* gradation, float value, float r, float g, float b);
Color colorGradationGet(ColorGradation* gradation, double value); Color colorGradationGet(ColorGradation* gradation, float value);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -39,8 +39,8 @@ void curveSave(PackStream* stream, Curve* curve)
packWriteInt(stream, &curve->nbpoints); packWriteInt(stream, &curve->nbpoints);
for (i = 0; i < curve->nbpoints; i++) for (i = 0; i < curve->nbpoints; i++)
{ {
packWriteDouble(stream, &curve->points[i].position); packWriteFloat(stream, &curve->points[i].position);
packWriteDouble(stream, &curve->points[i].value); packWriteFloat(stream, &curve->points[i].value);
} }
} }
@ -51,8 +51,8 @@ void curveLoad(PackStream* stream, Curve* curve)
packReadInt(stream, &curve->nbpoints); packReadInt(stream, &curve->nbpoints);
for (i = 0; i < curve->nbpoints; i++) for (i = 0; i < curve->nbpoints; i++)
{ {
packReadDouble(stream, &curve->points[i].position); packReadFloat(stream, &curve->points[i].position);
packReadDouble(stream, &curve->points[i].value); packReadFloat(stream, &curve->points[i].value);
} }
} }
@ -74,7 +74,7 @@ int curveAddPoint(Curve* curve, CurvePoint* point)
} }
} }
int curveQuickAddPoint(Curve* curve, double position, double value) int curveQuickAddPoint(Curve* curve, float position, float value)
{ {
CurvePoint point; CurvePoint point;
@ -137,10 +137,10 @@ void curveValidate(Curve* curve)
} }
} }
double curveGetValue(Curve* curve, double position) float curveGetValue(Curve* curve, float position)
{ {
int i; int i;
double fact; float fact;
if (curve->nbpoints == 0) if (curve->nbpoints == 0)
{ {

View file

@ -8,8 +8,8 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
double position; float position;
double value; float value;
} CurvePoint; } CurvePoint;
typedef struct Curve Curve; typedef struct Curve Curve;
@ -22,14 +22,14 @@ void curveLoad(PackStream* stream, Curve* curve);
void curveClear(Curve* curve); void curveClear(Curve* curve);
int curveAddPoint(Curve* curve, CurvePoint* point); int curveAddPoint(Curve* curve, CurvePoint* point);
int curveQuickAddPoint(Curve* curve, double position, double value); int curveQuickAddPoint(Curve* curve, float position, float value);
int curveGetPointCount(Curve* curve); int curveGetPointCount(Curve* curve);
void curveGetPoint(Curve* curve, int number, CurvePoint* point); void curveGetPoint(Curve* curve, int number, CurvePoint* point);
void curveSetPoint(Curve* curve, int number, CurvePoint* point); void curveSetPoint(Curve* curve, int number, CurvePoint* point);
void curveRemovePoint(Curve* curve, int number); void curveRemovePoint(Curve* curve, int number);
void curveValidate(Curve* curve); void curveValidate(Curve* curve);
double curveGetValue(Curve* curve, double position); float curveGetValue(Curve* curve, float position);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -8,19 +8,19 @@ Vector3 VECTOR_ZERO = {0.0, 0.0, 0.0};
void v3Save(PackStream* stream, Vector3* v) void v3Save(PackStream* stream, Vector3* v)
{ {
packWriteDouble(stream, &v->x); packWriteFloat(stream, &v->x);
packWriteDouble(stream, &v->y); packWriteFloat(stream, &v->y);
packWriteDouble(stream, &v->z); packWriteFloat(stream, &v->z);
} }
void v3Load(PackStream* stream, Vector3* v) void v3Load(PackStream* stream, Vector3* v)
{ {
packReadDouble(stream, &v->x); packReadFloat(stream, &v->x);
packReadDouble(stream, &v->y); packReadFloat(stream, &v->y);
packReadDouble(stream, &v->z); packReadFloat(stream, &v->z);
} }
Vector3 v3Translate(Vector3 v1, double x, double y, double z) Vector3 v3Translate(Vector3 v1, float x, float y, float z)
{ {
Vector3 result; Vector3 result;
result.x = v1.x + x; result.x = v1.x + x;
@ -56,7 +56,7 @@ Vector3 v3Neg(Vector3 v)
return result; return result;
} }
Vector3 v3Scale(Vector3 v, double scale) Vector3 v3Scale(Vector3 v, float scale)
{ {
Vector3 result; Vector3 result;
result.x = v.x * scale; result.x = v.x * scale;
@ -65,14 +65,14 @@ Vector3 v3Scale(Vector3 v, double scale)
return result; return result;
} }
double v3Norm(Vector3 v) float v3Norm(Vector3 v)
{ {
return sqrt(v.x * v.x + v.y * v.y + v.z * v.z); return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
} }
Vector3 v3Normalize(Vector3 v) Vector3 v3Normalize(Vector3 v)
{ {
double norm = v3Norm(v); float norm = v3Norm(v);
if (norm == 0.0) if (norm == 0.0)
{ {
return VECTOR_ZERO; return VECTOR_ZERO;
@ -83,7 +83,7 @@ Vector3 v3Normalize(Vector3 v)
} }
} }
double v3Dot(Vector3 v1, Vector3 v2) float v3Dot(Vector3 v1, Vector3 v2)
{ {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
} }
@ -99,42 +99,42 @@ Vector3 v3Cross(Vector3 v1, Vector3 v2)
void m4Save(PackStream* stream, Matrix4* m) void m4Save(PackStream* stream, Matrix4* m)
{ {
packWriteDouble(stream, &m->a); packWriteFloat(stream, &m->a);
packWriteDouble(stream, &m->b); packWriteFloat(stream, &m->b);
packWriteDouble(stream, &m->c); packWriteFloat(stream, &m->c);
packWriteDouble(stream, &m->d); packWriteFloat(stream, &m->d);
packWriteDouble(stream, &m->e); packWriteFloat(stream, &m->e);
packWriteDouble(stream, &m->f); packWriteFloat(stream, &m->f);
packWriteDouble(stream, &m->g); packWriteFloat(stream, &m->g);
packWriteDouble(stream, &m->h); packWriteFloat(stream, &m->h);
packWriteDouble(stream, &m->i); packWriteFloat(stream, &m->i);
packWriteDouble(stream, &m->j); packWriteFloat(stream, &m->j);
packWriteDouble(stream, &m->k); packWriteFloat(stream, &m->k);
packWriteDouble(stream, &m->l); packWriteFloat(stream, &m->l);
packWriteDouble(stream, &m->m); packWriteFloat(stream, &m->m);
packWriteDouble(stream, &m->n); packWriteFloat(stream, &m->n);
packWriteDouble(stream, &m->o); packWriteFloat(stream, &m->o);
packWriteDouble(stream, &m->p); packWriteFloat(stream, &m->p);
} }
void m4Load(PackStream* stream, Matrix4* m) void m4Load(PackStream* stream, Matrix4* m)
{ {
packReadDouble(stream, &m->a); packReadFloat(stream, &m->a);
packReadDouble(stream, &m->b); packReadFloat(stream, &m->b);
packReadDouble(stream, &m->c); packReadFloat(stream, &m->c);
packReadDouble(stream, &m->d); packReadFloat(stream, &m->d);
packReadDouble(stream, &m->e); packReadFloat(stream, &m->e);
packReadDouble(stream, &m->f); packReadFloat(stream, &m->f);
packReadDouble(stream, &m->g); packReadFloat(stream, &m->g);
packReadDouble(stream, &m->h); packReadFloat(stream, &m->h);
packReadDouble(stream, &m->i); packReadFloat(stream, &m->i);
packReadDouble(stream, &m->j); packReadFloat(stream, &m->j);
packReadDouble(stream, &m->k); packReadFloat(stream, &m->k);
packReadDouble(stream, &m->l); packReadFloat(stream, &m->l);
packReadDouble(stream, &m->m); packReadFloat(stream, &m->m);
packReadDouble(stream, &m->n); packReadFloat(stream, &m->n);
packReadDouble(stream, &m->o); packReadFloat(stream, &m->o);
packReadDouble(stream, &m->p); packReadFloat(stream, &m->p);
} }
Matrix4 m4NewIdentity() Matrix4 m4NewIdentity()
@ -180,7 +180,7 @@ Vector3 m4MultPoint(Matrix4 m, Vector3 v)
Vector3 m4Transform(Matrix4 m, Vector3 v) Vector3 m4Transform(Matrix4 m, Vector3 v)
{ {
Vector3 result; Vector3 result;
double w; float w;
result.x = m.a * v.x + m.b * v.y + m.c * v.z + m.d; result.x = m.a * v.x + m.b * v.y + m.c * v.z + m.d;
result.y = m.e * v.x + m.f * v.y + m.g * v.z + m.h; result.y = m.e * v.x + m.f * v.y + m.g * v.z + m.h;
result.z = m.i * v.x + m.j * v.y + m.k * v.z + m.l; result.z = m.i * v.x + m.j * v.y + m.k * v.z + m.l;
@ -216,7 +216,7 @@ Matrix4 m4Transpose(Matrix4 m)
return result; return result;
} }
Matrix4 m4NewScale(double x, double y, double z) Matrix4 m4NewScale(float x, float y, float z)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
result.a = x; result.a = x;
@ -225,7 +225,7 @@ Matrix4 m4NewScale(double x, double y, double z)
return result; return result;
} }
Matrix4 m4NewTranslate(double x, double y, double z) Matrix4 m4NewTranslate(float x, float y, float z)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
result.d = x; result.d = x;
@ -234,45 +234,45 @@ Matrix4 m4NewTranslate(double x, double y, double z)
return result; return result;
} }
Matrix4 m4NewRotateX(double angle) Matrix4 m4NewRotateX(float angle)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
double s = sin(angle); float s = sin(angle);
double c = cos(angle); float c = cos(angle);
result.f = result.k = c; result.f = result.k = c;
result.g = -s; result.g = -s;
result.j = s; result.j = s;
return result; return result;
} }
Matrix4 m4NewRotateY(double angle) Matrix4 m4NewRotateY(float angle)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
double s = sin(angle); float s = sin(angle);
double c = cos(angle); float c = cos(angle);
result.a = result.k = c; result.a = result.k = c;
result.c = s; result.c = s;
result.i = -s; result.i = -s;
return result; return result;
} }
Matrix4 m4NewRotateZ(double angle) Matrix4 m4NewRotateZ(float angle)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
double s = sin(angle); float s = sin(angle);
double c = cos(angle); float c = cos(angle);
result.a = result.f = c; result.a = result.f = c;
result.b = -s; result.b = -s;
result.e = s; result.e = s;
return result; return result;
} }
Matrix4 m4NewRotateAxis(double angle, Vector3 axis) Matrix4 m4NewRotateAxis(float angle, Vector3 axis)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
double s = sin(angle); float s = sin(angle);
double c = cos(angle); float c = cos(angle);
double c1 = 1.0 - c; float c1 = 1.0 - c;
axis = v3Normalize(axis); axis = v3Normalize(axis);
result.a = axis.x * axis.x * c1 + c; result.a = axis.x * axis.x * c1 + c;
result.b = axis.x * axis.y * c1 - axis.z * s; result.b = axis.x * axis.y * c1 - axis.z * s;
@ -286,15 +286,15 @@ Matrix4 m4NewRotateAxis(double angle, Vector3 axis)
return result; return result;
} }
Matrix4 m4NewRotateEuler(double heading, double attitude, double bank) Matrix4 m4NewRotateEuler(float heading, float attitude, float bank)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
double ch = cos(heading); float ch = cos(heading);
double sh = sin(heading); float sh = sin(heading);
double ca = cos(attitude); float ca = cos(attitude);
double sa = sin(attitude); float sa = sin(attitude);
double cb = cos(bank); float cb = cos(bank);
double sb = sin(bank); float sb = sin(bank);
result.a = ch * ca; result.a = ch * ca;
result.b = sh * sb - ch * sa * cb; result.b = sh * sb - ch * sa * cb;
result.c = ch * sa * sb + sh * cb; result.c = ch * sa * sb + sh * cb;
@ -334,10 +334,10 @@ Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up)
return m4Inverse(result); return m4Inverse(result);
} }
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far) Matrix4 m4NewPerspective(float fov_y, float aspect, float near, float far)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
double f = 1 / tan(fov_y / 2.0); float f = 1 / tan(fov_y / 2.0);
result.a = f / aspect; result.a = f / aspect;
result.f = f; result.f = f;
result.k = (far + near) / (near - far); result.k = (far + near) / (near - far);
@ -347,7 +347,7 @@ Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far)
return result; return result;
} }
double m4Determinant(Matrix4 m) float m4Determinant(Matrix4 m)
{ {
return ((m.a * m.f - m.e * m.b) return ((m.a * m.f - m.e * m.b)
* (m.k * m.p - m.o * m.l) * (m.k * m.p - m.o * m.l)
@ -366,7 +366,7 @@ double m4Determinant(Matrix4 m)
Matrix4 m4Inverse(Matrix4 m) Matrix4 m4Inverse(Matrix4 m)
{ {
Matrix4 result; Matrix4 result;
double d = m4Determinant(m); float d = m4Determinant(m);
if (fabs(d) < 0.00001) if (fabs(d) < 0.00001)
{ {

View file

@ -9,43 +9,43 @@ extern "C" {
typedef struct typedef struct
{ {
double x; float x;
double y; float y;
double z; float z;
} Vector3; } Vector3;
typedef struct typedef struct
{ {
double a; float a;
double b; float b;
double c; float c;
double d; float d;
double e; float e;
double f; float f;
double g; float g;
double h; float h;
double i; float i;
double j; float j;
double k; float k;
double l; float l;
double m; float m;
double n; float n;
double o; float o;
double p; float p;
} Matrix4; } Matrix4;
extern Vector3 VECTOR_ZERO; extern Vector3 VECTOR_ZERO;
void v3Save(PackStream* stream, Vector3* v); void v3Save(PackStream* stream, Vector3* v);
void v3Load(PackStream* stream, Vector3* v); void v3Load(PackStream* stream, Vector3* v);
Vector3 v3Translate(Vector3 v1, double x, double y, double z); Vector3 v3Translate(Vector3 v1, float x, float y, float z);
Vector3 v3Add(Vector3 v1, Vector3 v2); Vector3 v3Add(Vector3 v1, Vector3 v2);
Vector3 v3Sub(Vector3 v1, Vector3 v2); Vector3 v3Sub(Vector3 v1, Vector3 v2);
Vector3 v3Neg(Vector3 v); Vector3 v3Neg(Vector3 v);
Vector3 v3Scale(Vector3 v, double scale); Vector3 v3Scale(Vector3 v, float scale);
double v3Norm(Vector3 v); float v3Norm(Vector3 v);
Vector3 v3Normalize(Vector3 v); Vector3 v3Normalize(Vector3 v);
double v3Dot(Vector3 v1, Vector3 v2); float v3Dot(Vector3 v1, Vector3 v2);
Vector3 v3Cross(Vector3 v1, Vector3 v2); Vector3 v3Cross(Vector3 v1, Vector3 v2);
void m4Save(PackStream* stream, Matrix4* m); void m4Save(PackStream* stream, Matrix4* m);
@ -55,17 +55,17 @@ Matrix4 m4Mult(Matrix4 m1, Matrix4 m2);
Vector3 m4MultPoint(Matrix4 m, Vector3 v); Vector3 m4MultPoint(Matrix4 m, Vector3 v);
Vector3 m4Transform(Matrix4 m, Vector3 v); Vector3 m4Transform(Matrix4 m, Vector3 v);
Matrix4 m4Transpose(Matrix4 m); Matrix4 m4Transpose(Matrix4 m);
Matrix4 m4NewScale(double x, double y, double z); Matrix4 m4NewScale(float x, float y, float z);
Matrix4 m4NewTranslate(double x, double y, double z); Matrix4 m4NewTranslate(float x, float y, float z);
Matrix4 m4NewRotateX(double angle); Matrix4 m4NewRotateX(float angle);
Matrix4 m4NewRotateY(double angle); Matrix4 m4NewRotateY(float angle);
Matrix4 m4NewRotateZ(double angle); Matrix4 m4NewRotateZ(float angle);
Matrix4 m4NewRotateAxis(double angle, Vector3 axis); Matrix4 m4NewRotateAxis(float angle, Vector3 axis);
Matrix4 m4NewRotateEuler(double heading, double attitude, double bank); Matrix4 m4NewRotateEuler(float heading, float attitude, float bank);
Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z); Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z);
Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up); Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up);
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far); Matrix4 m4NewPerspective(float fov_y, float aspect, float near, float far);
double m4Determinant(Matrix4 m); float m4Determinant(Matrix4 m);
Matrix4 m4Inverse(Matrix4 m); Matrix4 m4Inverse(Matrix4 m);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -43,10 +43,10 @@ void lightingSave(PackStream* stream, LightingDefinition* definition)
{ {
v3Save(stream, &definition->lights[i].direction); v3Save(stream, &definition->lights[i].direction);
colorSave(stream, &definition->lights[i].color); colorSave(stream, &definition->lights[i].color);
packWriteDouble(stream, &definition->lights[i].reflection); packWriteFloat(stream, &definition->lights[i].reflection);
packWriteInt(stream, &definition->lights[i].filtered); packWriteInt(stream, &definition->lights[i].filtered);
packWriteInt(stream, &definition->lights[i].masked); packWriteInt(stream, &definition->lights[i].masked);
packWriteDouble(stream, &definition->lights[i].amplitude); packWriteFloat(stream, &definition->lights[i].amplitude);
} }
} }
@ -60,10 +60,10 @@ void lightingLoad(PackStream* stream, LightingDefinition* definition)
{ {
v3Load(stream, &definition->lights[i].direction); v3Load(stream, &definition->lights[i].direction);
colorLoad(stream, &definition->lights[i].color); colorLoad(stream, &definition->lights[i].color);
packReadDouble(stream, &definition->lights[i].reflection); packReadFloat(stream, &definition->lights[i].reflection);
packReadInt(stream, &definition->lights[i].filtered); packReadInt(stream, &definition->lights[i].filtered);
packReadInt(stream, &definition->lights[i].masked); packReadInt(stream, &definition->lights[i].masked);
packReadDouble(stream, &definition->lights[i].amplitude); packReadFloat(stream, &definition->lights[i].amplitude);
} }
lightingValidateDefinition(definition); lightingValidateDefinition(definition);
@ -170,7 +170,7 @@ static int _getLightStatus(LightDefinition* definition, Renderer* renderer, Vect
static Color _applyDirectLight(LightDefinition* definition, Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) static Color _applyDirectLight(LightDefinition* definition, Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
{ {
Color result, light; Color result, light;
double diffuse, specular, normal_norm; float diffuse, specular, normal_norm;
Vector3 view, reflect, direction_inv; Vector3 view, reflect, direction_inv;
light = definition->color; light = definition->color;
@ -180,16 +180,16 @@ static Color _applyDirectLight(LightDefinition* definition, Renderer* renderer,
{ {
/* TODO Sampling around light direction */ /* TODO Sampling around light direction */
int xsamples, ysamples, samples, x, y; int xsamples, ysamples, samples, x, y;
double xstep, ystep, factor; float xstep, ystep, factor;
LightDefinition sublight; LightDefinition sublight;
ysamples = renderer->render_quality / 4 + 1; ysamples = renderer->render_quality / 4 + 1;
xsamples = renderer->render_quality / 2 + 1; xsamples = renderer->render_quality / 2 + 1;
samples = xsamples * ysamples + 1; samples = xsamples * ysamples + 1;
factor = 1.0 / (double)samples; factor = 1.0 / (float)samples;
xstep = M_PI * 2.0 / (double)xsamples; xstep = M_PI * 2.0 / (float)xsamples;
ystep = M_PI * 0.5 / (double)(ysamples - 1); ystep = M_PI * 0.5 / (float)(ysamples - 1);
sublight = *definition; sublight = *definition;
sublight.amplitude = 0.0; sublight.amplitude = 0.0;

View file

@ -15,10 +15,10 @@ struct LightDefinition
{ {
Vector3 direction; /* Global direction of the light */ Vector3 direction; /* Global direction of the light */
Color color; /* Main color of the light */ Color color; /* Main color of the light */
double reflection; /* Reflected factor of the light (for specular lighting) */ float reflection; /* Reflected factor of the light (for specular lighting) */
int filtered; /* Should the light be filtered (by atmosphere, water...) */ int filtered; /* Should the light be filtered (by atmosphere, water...) */
int masked; /* Should the light be masked (cast shadows..) */ int masked; /* Should the light be masked (cast shadows..) */
double amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */ float amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */
}; };
typedef struct typedef struct

View file

@ -14,7 +14,7 @@
#include "render.h" #include "render.h"
#include "main.h" #include "main.h"
#define APP_HEADER 1986325632.125 #define APP_HEADER 198632.125
void paysagesInit() void paysagesInit()
{ {
@ -38,7 +38,7 @@ void paysagesInit()
autoSetDaytime(8, 30); autoSetDaytime(8, 30);
// DEBUG // DEBUG
/*double last_height, height, x; /*float last_height, height, x;
last_height = height = 0.0; last_height = height = 0.0;
x = 0.0; x = 0.0;
while (height <= 1.0 || height >= last_height || last_height < 0.1) while (height <= 1.0 || height >= last_height || last_height < 0.1)
@ -60,17 +60,17 @@ void paysagesQuit()
FileOperationResult paysagesSave(char* filepath) FileOperationResult paysagesSave(char* filepath)
{ {
PackStream* stream = packWriteFile(filepath); PackStream* stream = packWriteFile(filepath);
double app_header, version_header; float app_header, version_header;
if (!stream) if (!stream)
{ {
return FILE_OPERATION_IOERROR; return FILE_OPERATION_IOERROR;
} }
app_header = (double)APP_HEADER; app_header = (float)APP_HEADER;
packWriteDouble(stream, &app_header); packWriteFloat(stream, &app_header);
version_header = (double)PAYSAGES_CURRENT_DATA_VERSION; version_header = (float)PAYSAGES_CURRENT_DATA_VERSION;
packWriteDouble(stream, &version_header); packWriteFloat(stream, &version_header);
scenerySave(stream); scenerySave(stream);
@ -82,21 +82,21 @@ FileOperationResult paysagesSave(char* filepath)
FileOperationResult paysagesLoad(char* filepath) FileOperationResult paysagesLoad(char* filepath)
{ {
PackStream* stream = packReadFile(filepath); PackStream* stream = packReadFile(filepath);
double app_header, version_header; float app_header, version_header;
if (!stream) if (!stream)
{ {
return FILE_OPERATION_IOERROR; return FILE_OPERATION_IOERROR;
} }
packReadDouble(stream, &app_header); packReadFloat(stream, &app_header);
if (app_header != APP_HEADER) if (app_header != APP_HEADER)
{ {
packCloseStream(stream); packCloseStream(stream);
return FILE_OPERATION_APP_MISMATCH; return FILE_OPERATION_APP_MISMATCH;
} }
packReadDouble(stream, &version_header); packReadFloat(stream, &version_header);
if ((int)version_header != PAYSAGES_CURRENT_DATA_VERSION) if ((int)version_header != PAYSAGES_CURRENT_DATA_VERSION)
{ {
packCloseStream(stream); packCloseStream(stream);

View file

@ -13,7 +13,7 @@ struct HeightModifier
{ {
Zone* zone; Zone* zone;
int mode; int mode;
double value; float value;
}; };
HeightModifier* modifierCreate() HeightModifier* modifierCreate()
@ -49,14 +49,14 @@ void modifierDelete(HeightModifier* modifier)
void modifierSave(PackStream* stream, HeightModifier* modifier) void modifierSave(PackStream* stream, HeightModifier* modifier)
{ {
packWriteInt(stream, &modifier->mode); packWriteInt(stream, &modifier->mode);
packWriteDouble(stream, &modifier->value); packWriteFloat(stream, &modifier->value);
zoneSave(stream, modifier->zone); zoneSave(stream, modifier->zone);
} }
void modifierLoad(PackStream* stream, HeightModifier* modifier) void modifierLoad(PackStream* stream, HeightModifier* modifier)
{ {
packReadInt(stream, &modifier->mode); packReadInt(stream, &modifier->mode);
packReadDouble(stream, &modifier->value); packReadFloat(stream, &modifier->value);
zoneLoad(stream, modifier->zone); zoneLoad(stream, modifier->zone);
} }
@ -65,13 +65,13 @@ Zone* modifierGetZone(HeightModifier* modifier)
return modifier->zone; return modifier->zone;
} }
void modifierActionAddValue(HeightModifier* modifier, double value) void modifierActionAddValue(HeightModifier* modifier, float value)
{ {
modifier->mode = MODE_ADD_VALUE; modifier->mode = MODE_ADD_VALUE;
modifier->value = value; modifier->value = value;
} }
void modifierActionFixValue(HeightModifier* modifier, double value) void modifierActionFixValue(HeightModifier* modifier, float value)
{ {
modifier->mode = MODE_FIX_VALUE; modifier->mode = MODE_FIX_VALUE;
modifier->value = value; modifier->value = value;
@ -79,7 +79,7 @@ void modifierActionFixValue(HeightModifier* modifier, double value)
Vector3 modifierApply(HeightModifier* modifier, Vector3 location) Vector3 modifierApply(HeightModifier* modifier, Vector3 location)
{ {
double influence, diff; float influence, diff;
Vector3 normal; Vector3 normal;
switch (modifier->mode) switch (modifier->mode)

View file

@ -16,8 +16,8 @@ void modifierDelete(HeightModifier* modifier);
void modifierSave(PackStream* stream, HeightModifier* modifier); void modifierSave(PackStream* stream, HeightModifier* modifier);
void modifierLoad(PackStream* stream, HeightModifier* modifier); void modifierLoad(PackStream* stream, HeightModifier* modifier);
Zone* modifierGetZone(HeightModifier* modifier); Zone* modifierGetZone(HeightModifier* modifier);
void modifierActionAddValue(HeightModifier* modifier, double value); void modifierActionAddValue(HeightModifier* modifier, float value);
void modifierActionFixValue(HeightModifier* modifier, double value); void modifierActionFixValue(HeightModifier* modifier, float value);
Vector3 modifierApply(HeightModifier* modifier, Vector3 location); Vector3 modifierApply(HeightModifier* modifier, Vector3 location);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -15,15 +15,15 @@ struct NoiseGenerator
int size1; int size1;
int size2; int size2;
int size3; int size3;
double height_offset; float height_offset;
int level_count; int level_count;
struct NoiseLevel levels[MAX_LEVEL_COUNT]; struct NoiseLevel levels[MAX_LEVEL_COUNT];
}; };
static int _noise_pool_size; static int _noise_pool_size;
static double* _noise_pool; static float* _noise_pool;
static inline double _cubicInterpolate(double* p, double x) static inline float _cubicInterpolate(float* p, float x)
{ {
return p[1] + 0.5 * x * (p[2] - p[0] + x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + x * (3.0 * (p[1] - p[2]) + p[3] - p[0]))); return p[1] + 0.5 * x * (p[2] - p[0] + x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + x * (3.0 * (p[1] - p[2]) + p[3] - p[0])));
} }
@ -33,7 +33,7 @@ void noiseInit()
int i; int i;
_noise_pool_size = 1048576; _noise_pool_size = 1048576;
_noise_pool = malloc(sizeof(double) * _noise_pool_size); _noise_pool = malloc(sizeof(float) * _noise_pool_size);
for (i = 0; i < _noise_pool_size; i++) for (i = 0; i < _noise_pool_size; i++)
{ {
@ -53,7 +53,7 @@ void noiseSave(PackStream* stream)
packWriteInt(stream, &_noise_pool_size); packWriteInt(stream, &_noise_pool_size);
for (i = 0; i < _noise_pool_size; i++) for (i = 0; i < _noise_pool_size; i++)
{ {
packWriteDouble(stream, _noise_pool + i); packWriteFloat(stream, _noise_pool + i);
} }
} }
@ -62,10 +62,10 @@ void noiseLoad(PackStream* stream)
int i; int i;
packReadInt(stream, &_noise_pool_size); packReadInt(stream, &_noise_pool_size);
_noise_pool = realloc(_noise_pool, sizeof(double) * _noise_pool_size); _noise_pool = realloc(_noise_pool, sizeof(float) * _noise_pool_size);
for (i = 0; i < _noise_pool_size; i++) for (i = 0; i < _noise_pool_size; i++)
{ {
packReadDouble(stream, _noise_pool + i); packReadFloat(stream, _noise_pool + i);
} }
} }
@ -96,18 +96,18 @@ void noiseSaveGenerator(PackStream* stream, NoiseGenerator* perlin)
packWriteInt(stream, &perlin->size1); packWriteInt(stream, &perlin->size1);
packWriteInt(stream, &perlin->size2); packWriteInt(stream, &perlin->size2);
packWriteInt(stream, &perlin->size3); packWriteInt(stream, &perlin->size3);
packWriteDouble(stream, &perlin->height_offset); packWriteFloat(stream, &perlin->height_offset);
packWriteInt(stream, &perlin->level_count); packWriteInt(stream, &perlin->level_count);
for (x = 0; x < perlin->level_count; x++) for (x = 0; x < perlin->level_count; x++)
{ {
NoiseLevel* level = perlin->levels + x; NoiseLevel* level = perlin->levels + x;
packWriteDouble(stream, &level->scaling); packWriteFloat(stream, &level->scaling);
packWriteDouble(stream, &level->height); packWriteFloat(stream, &level->height);
packWriteDouble(stream, &level->xoffset); packWriteFloat(stream, &level->xoffset);
packWriteDouble(stream, &level->yoffset); packWriteFloat(stream, &level->yoffset);
packWriteDouble(stream, &level->zoffset); packWriteFloat(stream, &level->zoffset);
} }
} }
@ -118,18 +118,18 @@ void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin)
packReadInt(stream, &perlin->size1); packReadInt(stream, &perlin->size1);
packReadInt(stream, &perlin->size2); packReadInt(stream, &perlin->size2);
packReadInt(stream, &perlin->size3); packReadInt(stream, &perlin->size3);
packReadDouble(stream, &perlin->height_offset); packReadFloat(stream, &perlin->height_offset);
packReadInt(stream, &perlin->level_count); packReadInt(stream, &perlin->level_count);
for (x = 0; x < perlin->level_count; x++) for (x = 0; x < perlin->level_count; x++)
{ {
NoiseLevel* level = perlin->levels + x; NoiseLevel* level = perlin->levels + x;
packReadDouble(stream, &level->scaling); packReadFloat(stream, &level->scaling);
packReadDouble(stream, &level->height); packReadFloat(stream, &level->height);
packReadDouble(stream, &level->xoffset); packReadFloat(stream, &level->xoffset);
packReadDouble(stream, &level->yoffset); packReadFloat(stream, &level->yoffset);
packReadDouble(stream, &level->zoffset); packReadFloat(stream, &level->zoffset);
} }
} }
@ -159,10 +159,10 @@ int noiseGetBaseSize(NoiseGenerator* generator)
return generator->size1; return generator->size1;
} }
double noiseGetMaxValue(NoiseGenerator* generator) float noiseGetMaxValue(NoiseGenerator* generator)
{ {
int x; int x;
double result = generator->height_offset; float result = generator->height_offset;
for (x = 0; x < generator->level_count; x++) for (x = 0; x < generator->level_count; x++)
{ {
@ -191,7 +191,7 @@ void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level)
} }
} }
void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double height) void noiseAddLevelSimple(NoiseGenerator* generator, float scaling, float height)
{ {
NoiseLevel level; NoiseLevel level;
@ -204,7 +204,7 @@ void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double heigh
noiseAddLevel(generator, level); noiseAddLevel(generator, level);
} }
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, double scaling_factor, double height_factor, int randomize_offset) void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, float scaling_factor, float height_factor, int randomize_offset)
{ {
int i; int i;
@ -222,7 +222,7 @@ void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start
} }
} }
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, double scaling, double height) void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, float scaling, float height)
{ {
NoiseLevel level; NoiseLevel level;
@ -264,7 +264,7 @@ void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params)
} }
} }
void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, double height) void noiseSetLevelSimple(NoiseGenerator* generator, int level, float scaling, float height)
{ {
NoiseLevel params; NoiseLevel params;
@ -277,11 +277,11 @@ void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, d
noiseSetLevel(generator, level, params); noiseSetLevel(generator, level, params);
} }
void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double max_height, int adjust_scaling) void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max_height, int adjust_scaling)
{ {
int level; int level;
double height = 0.0; float height = 0.0;
double target_height = max_height - min_height; float target_height = max_height - min_height;
if (generator->level_count == 0) if (generator->level_count == 0)
{ {
@ -306,13 +306,13 @@ void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double m
static inline double _get1DRawNoiseValue(NoiseGenerator* generator, double x) static inline float _get1DRawNoiseValue(NoiseGenerator* generator, float x)
{ {
int size = generator->size1; int size = generator->size1;
int xbase = (int)floor(x); int xbase = (int)floor(x);
double xinternal = x - (double)xbase; float xinternal = x - (float)xbase;
int x0 = (xbase - 1) % size; int x0 = (xbase - 1) % size;
if (x0 < 0) if (x0 < 0)
@ -335,7 +335,7 @@ static inline double _get1DRawNoiseValue(NoiseGenerator* generator, double x)
x3 += size; x3 += size;
} }
double buf_cubic_x[4]; float buf_cubic_x[4];
buf_cubic_x[0] = _noise_pool[x0 % _noise_pool_size]; buf_cubic_x[0] = _noise_pool[x0 % _noise_pool_size];
buf_cubic_x[1] = _noise_pool[x1 % _noise_pool_size]; buf_cubic_x[1] = _noise_pool[x1 % _noise_pool_size];
@ -345,12 +345,12 @@ static inline double _get1DRawNoiseValue(NoiseGenerator* generator, double x)
return _cubicInterpolate(buf_cubic_x, xinternal); return _cubicInterpolate(buf_cubic_x, xinternal);
} }
static inline double _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x) static inline float _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x)
{ {
return _get1DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size1) * level->height; return _get1DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size1) * level->height;
} }
double noiseGet1DLevel(NoiseGenerator* generator, int level, double x) float noiseGet1DLevel(NoiseGenerator* generator, int level, float x)
{ {
if (level >= 0 && level < generator->level_count) if (level >= 0 && level < generator->level_count)
{ {
@ -362,10 +362,10 @@ double noiseGet1DLevel(NoiseGenerator* generator, int level, double x)
} }
} }
double noiseGet1DTotal(NoiseGenerator* generator, double x) float noiseGet1DTotal(NoiseGenerator* generator, float x)
{ {
int level; int level;
double result; float result;
result = 0.0; result = 0.0;
for (level = 0; level < generator->level_count; level++) for (level = 0; level < generator->level_count; level++)
@ -375,10 +375,10 @@ double noiseGet1DTotal(NoiseGenerator* generator, double x)
return result + generator->height_offset; return result + generator->height_offset;
} }
double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail) float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail)
{ {
int level; int level;
double result, height, factor; float result, height, factor;
result = 0.0; result = 0.0;
for (level = 0; level < generator->level_count; level++) for (level = 0; level < generator->level_count; level++)
@ -402,15 +402,15 @@ double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail)
static inline double _get2DRawNoiseValue(NoiseGenerator* generator, double x, double y) static inline float _get2DRawNoiseValue(NoiseGenerator* generator, float x, float y)
{ {
int size = generator->size2; int size = generator->size2;
int xbase = (int)floor(x); int xbase = (int)floor(x);
int ybase = (int)floor(y); int ybase = (int)floor(y);
double xinternal = x - (double)xbase; float xinternal = x - (float)xbase;
double yinternal = y - (double)ybase; float yinternal = y - (float)ybase;
int x0 = (xbase - 1) % size; int x0 = (xbase - 1) % size;
if (x0 < 0) if (x0 < 0)
@ -454,8 +454,8 @@ static inline double _get2DRawNoiseValue(NoiseGenerator* generator, double x, do
y3 += size; y3 += size;
} }
double buf_cubic_x[4]; float buf_cubic_x[4];
double buf_cubic_y[4]; float buf_cubic_y[4];
buf_cubic_x[0] = _noise_pool[(y0 * size + x0) % _noise_pool_size]; buf_cubic_x[0] = _noise_pool[(y0 * size + x0) % _noise_pool_size];
buf_cubic_x[1] = _noise_pool[(y0 * size + x1) % _noise_pool_size]; buf_cubic_x[1] = _noise_pool[(y0 * size + x1) % _noise_pool_size];
@ -484,12 +484,12 @@ static inline double _get2DRawNoiseValue(NoiseGenerator* generator, double x, do
return _cubicInterpolate(buf_cubic_y, yinternal); return _cubicInterpolate(buf_cubic_y, yinternal);
} }
static inline double _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y) static inline float _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x, float y)
{ {
return _get2DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size2, y / level->scaling + level->yoffset * generator->size2) * level->height; return _get2DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size2, y / level->scaling + level->yoffset * generator->size2) * level->height;
} }
double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y) float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y)
{ {
if (level >= 0 && level < generator->level_count) if (level >= 0 && level < generator->level_count)
{ {
@ -501,10 +501,10 @@ double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y)
} }
} }
double noiseGet2DTotal(NoiseGenerator* generator, double x, double y) float noiseGet2DTotal(NoiseGenerator* generator, float x, float y)
{ {
int level; int level;
double result; float result;
result = 0.0; result = 0.0;
for (level = 0; level < generator->level_count; level++) for (level = 0; level < generator->level_count; level++)
@ -514,10 +514,10 @@ double noiseGet2DTotal(NoiseGenerator* generator, double x, double y)
return result + generator->height_offset; return result + generator->height_offset;
} }
double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double detail) float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail)
{ {
int level; int level;
double result, height, factor; float result, height, factor;
result = 0.0; result = 0.0;
for (level = 0; level < generator->level_count; level++) for (level = 0; level < generator->level_count; level++)
@ -541,7 +541,7 @@ double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double de
static inline double _get3DRawNoiseValue(NoiseGenerator* generator, double x, double y, double z) static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, float y, float z)
{ {
int size = generator->size3; int size = generator->size3;
@ -549,9 +549,9 @@ static inline double _get3DRawNoiseValue(NoiseGenerator* generator, double x, do
int ybase = (int)floor(y); int ybase = (int)floor(y);
int zbase = (int)floor(z); int zbase = (int)floor(z);
double xinternal = x - (double)xbase; float xinternal = x - (float)xbase;
double yinternal = y - (double)ybase; float yinternal = y - (float)ybase;
double zinternal = z - (double)zbase; float zinternal = z - (float)zbase;
int x0 = (xbase - 1) % size; int x0 = (xbase - 1) % size;
if (x0 < 0) if (x0 < 0)
@ -616,9 +616,9 @@ static inline double _get3DRawNoiseValue(NoiseGenerator* generator, double x, do
z3 += size; z3 += size;
} }
double buf_cubic_x[4]; float buf_cubic_x[4];
double buf_cubic_y[4]; float buf_cubic_y[4];
double buf_cubic_z[4]; float buf_cubic_z[4];
buf_cubic_x[0] = _noise_pool[(y0 * size * size + x0 * size + z0) % _noise_pool_size]; buf_cubic_x[0] = _noise_pool[(y0 * size * size + x0 * size + z0) % _noise_pool_size];
buf_cubic_x[1] = _noise_pool[(y0 * size * size + x1 * size + z0) % _noise_pool_size]; buf_cubic_x[1] = _noise_pool[(y0 * size * size + x1 * size + z0) % _noise_pool_size];
@ -727,12 +727,12 @@ static inline double _get3DRawNoiseValue(NoiseGenerator* generator, double x, do
return _cubicInterpolate(buf_cubic_z, zinternal); return _cubicInterpolate(buf_cubic_z, zinternal);
} }
static inline double _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y, double z) static inline float _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x, float y, float z)
{ {
return _get3DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size3, y / level->scaling + level->yoffset * generator->size3, z / level->scaling + level->zoffset * generator->size3) * level->height; return _get3DRawNoiseValue(generator, x / level->scaling + level->xoffset * generator->size3, y / level->scaling + level->yoffset * generator->size3, z / level->scaling + level->zoffset * generator->size3) * level->height;
} }
double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z) float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, float z)
{ {
if (level >= 0 && level < generator->level_count) if (level >= 0 && level < generator->level_count)
{ {
@ -744,10 +744,10 @@ double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y,
} }
} }
double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z) float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z)
{ {
int level; int level;
double result; float result;
result = 0.0; result = 0.0;
for (level = 0; level < generator->level_count; level++) for (level = 0; level < generator->level_count; level++)
@ -757,10 +757,10 @@ double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z)
return result + generator->height_offset; return result + generator->height_offset;
} }
double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double detail) float noiseGet3DDetail(NoiseGenerator* generator, float x, float y, float z, float detail)
{ {
int level; int level;
double result, height, factor; float result, height, factor;
result = 0.0; result = 0.0;
for (level = 0; level < generator->level_count; level++) for (level = 0; level < generator->level_count; level++)

View file

@ -9,11 +9,11 @@ extern "C" {
struct NoiseLevel struct NoiseLevel
{ {
double scaling; float scaling;
double height; float height;
double xoffset; float xoffset;
double yoffset; float yoffset;
double zoffset; float zoffset;
}; };
typedef struct NoiseLevel NoiseLevel; typedef struct NoiseLevel NoiseLevel;
typedef struct NoiseGenerator NoiseGenerator; typedef struct NoiseGenerator NoiseGenerator;
@ -30,27 +30,27 @@ void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin);
void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination); void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination);
void noiseGenerateBaseNoise(NoiseGenerator* generator, int size); void noiseGenerateBaseNoise(NoiseGenerator* generator, int size);
int noiseGetBaseSize(NoiseGenerator* generator); int noiseGetBaseSize(NoiseGenerator* generator);
double noiseGetMaxValue(NoiseGenerator* generator); float noiseGetMaxValue(NoiseGenerator* generator);
int noiseGetLevelCount(NoiseGenerator* generator); int noiseGetLevelCount(NoiseGenerator* generator);
void noiseClearLevels(NoiseGenerator* generator); void noiseClearLevels(NoiseGenerator* generator);
void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level); void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level);
void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double height); void noiseAddLevelSimple(NoiseGenerator* generator, float scaling, float height);
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, double scaling_factor, double height_factor, int randomize_offset); void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, float scaling_factor, float height_factor, int randomize_offset);
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, double scaling, double height); void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, float scaling, float height);
void noiseRemoveLevel(NoiseGenerator* generator, int level); void noiseRemoveLevel(NoiseGenerator* generator, int level);
int noiseGetLevel(NoiseGenerator* generator, int level, NoiseLevel* params); int noiseGetLevel(NoiseGenerator* generator, int level, NoiseLevel* params);
void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params); void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params);
void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, double height); void noiseSetLevelSimple(NoiseGenerator* generator, int level, float scaling, float height);
void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double max_height, int adjust_scaling); void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max_height, int adjust_scaling);
double noiseGet1DLevel(NoiseGenerator* generator, int level, double x); float noiseGet1DLevel(NoiseGenerator* generator, int level, float x);
double noiseGet1DTotal(NoiseGenerator* generator, double x); float noiseGet1DTotal(NoiseGenerator* generator, float x);
double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail); float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail);
double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y); float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y);
double noiseGet2DTotal(NoiseGenerator* generator, double x, double y); float noiseGet2DTotal(NoiseGenerator* generator, float x, float y);
double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double detail); float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail);
double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z); float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, float z);
double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z); float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z);
double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double detail); float noiseGet3DDetail(NoiseGenerator* generator, float x, float y, float z, float detail);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -20,9 +20,9 @@ struct PackStream
#define unpack754_32(i) (unpack754((i), 32, 8)) #define unpack754_32(i) (unpack754((i), 32, 8))
#define unpack754_64(i) (unpack754((i), 64, 11)) #define unpack754_64(i) (unpack754((i), 64, 11))
static uint64_t pack754(double f, unsigned bits, unsigned expbits) static uint64_t pack754(float f, unsigned bits, unsigned expbits)
{ {
double fnorm; float fnorm;
int shift; int shift;
long long sign, exp, significand; long long sign, exp, significand;
unsigned significandbits = bits - expbits - 1; // -1 for sign bit unsigned significandbits = bits - expbits - 1; // -1 for sign bit
@ -49,9 +49,9 @@ static uint64_t pack754(double f, unsigned bits, unsigned expbits)
return (sign<<(bits-1)) | (exp<<(bits-expbits-1)) | significand; return (sign<<(bits-1)) | (exp<<(bits-expbits-1)) | significand;
} }
static double unpack754(uint64_t i, unsigned bits, unsigned expbits) static float unpack754(uint64_t i, unsigned bits, unsigned expbits)
{ {
double result; float result;
long long shift; long long shift;
unsigned bias; unsigned bias;
unsigned significandbits = bits - expbits - 1; // -1 for sign bit unsigned significandbits = bits - expbits - 1; // -1 for sign bit
@ -107,15 +107,15 @@ void packCloseStream(PackStream* stream)
free(stream); free(stream);
} }
void packWriteDouble(PackStream* stream, double* value) void packWriteFloat(PackStream* stream, float* value)
{ {
uint64_t servalue; uint64_t servalue;
servalue = pack754_64(*value); servalue = pack754_32(*value);
fwrite(&servalue, sizeof(uint64_t), 1, stream->fd); fwrite(&servalue, sizeof(uint64_t), 1, stream->fd);
} }
void packReadDouble(PackStream* stream, double* value) void packReadFloat(PackStream* stream, float* value)
{ {
int read; int read;
uint64_t servalue; uint64_t servalue;
@ -123,7 +123,7 @@ void packReadDouble(PackStream* stream, double* value)
read = fread(&servalue, sizeof(uint64_t), 1, stream->fd); read = fread(&servalue, sizeof(uint64_t), 1, stream->fd);
assert(read == 1); assert(read == 1);
*value = unpack754_64(servalue); *value = unpack754_32(servalue);
} }
void packWriteInt(PackStream* stream, int* value) void packWriteInt(PackStream* stream, int* value)

View file

@ -11,8 +11,8 @@ PackStream* packReadFile(char* filepath);
PackStream* packWriteFile(char* filepath); PackStream* packWriteFile(char* filepath);
void packCloseStream(PackStream* stream); void packCloseStream(PackStream* stream);
void packWriteDouble(PackStream* stream, double* value); void packWriteFloat(PackStream* stream, float* value);
void packReadDouble(PackStream* stream, double* value); void packReadFloat(PackStream* stream, float* value);
void packWriteInt(PackStream* stream, int* value); void packWriteInt(PackStream* stream, int* value);
void packReadInt(PackStream* stream, int* value); void packReadInt(PackStream* stream, int* value);

View file

@ -37,7 +37,7 @@ struct RenderArea
static void _callbackStart(int width, int height, Color background) {} static void _callbackStart(int width, int height, Color background) {}
static void _callbackDraw(int x, int y, Color col) {} static void _callbackDraw(int x, int y, Color col) {}
static void _callbackUpdate(double progress) {} static void _callbackUpdate(float progress) {}
void renderInit() void renderInit()
{ {
@ -169,7 +169,7 @@ void renderClear(RenderArea* area)
/*static int _sortRenderFragment(void const* a, void const* b) /*static int _sortRenderFragment(void const* a, void const* b)
{ {
double za, zb; float za, zb;
za = ((RenderFragment*)a)->z; za = ((RenderFragment*)a)->z;
zb = ((RenderFragment*)b)->z; zb = ((RenderFragment*)b)->z;
if (za > zb) if (za > zb)
@ -242,9 +242,9 @@ static inline Color _getFinalPixel(RenderArea* area, int x, int y)
if (1 || pixel_data->dirty) if (1 || pixel_data->dirty)
{ {
col = _getPixelColor(area->background_color, pixel_data); col = _getPixelColor(area->background_color, pixel_data);
result.r += col.r / (double)(area->params.antialias * area->params.antialias); result.r += col.r / (float)(area->params.antialias * area->params.antialias);
result.g += col.g / (double)(area->params.antialias * area->params.antialias); result.g += col.g / (float)(area->params.antialias * area->params.antialias);
result.b += col.b / (double)(area->params.antialias * area->params.antialias); result.b += col.b / (float)(area->params.antialias * area->params.antialias);
pixel_data->dirty = 0; pixel_data->dirty = 0;
} }
} }
@ -310,7 +310,7 @@ void renderAddFragment(RenderArea* area, RenderFragment* fragment)
Array* pixel_data; Array* pixel_data;
int x = fragment->x; int x = fragment->x;
int y = fragment->y; int y = fragment->y;
double z = fragment->z; float z = fragment->z;
int i, dirty; int i, dirty;
int fragments_count; int fragments_count;
@ -371,7 +371,7 @@ void renderAddFragment(RenderArea* area, RenderFragment* fragment)
} }
} }
void renderPushFragment(RenderArea* area, int x, int y, double z, Vertex* vertex) void renderPushFragment(RenderArea* area, int x, int y, float z, Vertex* vertex)
{ {
RenderFragment fragment; RenderFragment fragment;
@ -399,7 +399,7 @@ static void __vertexGetDiff(Vertex* v1, Vertex* v2, Vertex* result)
result->callback_data = v1->callback_data; result->callback_data = v1->callback_data;
} }
static void __vertexInterpolate(Vertex* v1, Vertex* diff, double value, Vertex* result) static void __vertexInterpolate(Vertex* v1, Vertex* diff, float value, Vertex* result)
{ {
result->location.x = v1->location.x + diff->location.x * value; result->location.x = v1->location.x + diff->location.x * value;
result->location.y = v1->location.y + diff->location.y * value; result->location.y = v1->location.y + diff->location.y * value;
@ -453,7 +453,7 @@ static void __pushScanLinePoint(RenderArea* area, RenderFragment point)
static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex* vertex1, Vertex* vertex2) static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex* vertex1, Vertex* vertex2)
{ {
double dx, dy, dz, fx; float dx, dy, dz, fx;
Vertex diff; Vertex diff;
int startx = lround(v1.x); int startx = lround(v1.x);
int endx = lround(v2.x); int endx = lround(v2.x);
@ -501,7 +501,7 @@ static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex*
__vertexGetDiff(vertex1, vertex2, &diff); __vertexGetDiff(vertex1, vertex2, &diff);
for (curx = startx; curx <= endx; curx++) for (curx = startx; curx <= endx; curx++)
{ {
fx = (double)curx + 0.5; fx = (float)curx + 0.5;
if (fx < v1.x) if (fx < v1.x)
{ {
fx = v1.x; fx = v1.x;
@ -537,7 +537,7 @@ static void __renderScanLines(RenderArea* area)
{ {
int x, starty, endy, cury; int x, starty, endy, cury;
Vertex diff; Vertex diff;
double dy, dz, fy; float dy, dz, fy;
RenderFragment up, down, current; RenderFragment up, down, current;
if (area->scanline_right > 0) if (area->scanline_right > 0)
@ -564,14 +564,14 @@ static void __renderScanLines(RenderArea* area)
endy = area->params.height * area->params.antialias - 1; endy = area->params.height * area->params.antialias - 1;
} }
dy = (double)(up.y - down.y); dy = (float)(up.y - down.y);
dz = up.z - down.z; dz = up.z - down.z;
__vertexGetDiff(&down.vertex, &up.vertex, &diff); __vertexGetDiff(&down.vertex, &up.vertex, &diff);
current.x = x; current.x = x;
for (cury = starty; cury <= endy; cury++) for (cury = starty; cury <= endy; cury++)
{ {
fy = (double)cury - down.y; fy = (float)cury - down.y;
current.y = cury; current.y = cury;
current.z = down.z + dz * fy / dy; current.z = down.z + dz * fy / dy;
@ -592,8 +592,8 @@ static void __renderScanLines(RenderArea* area)
void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3) void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3)
{ {
double limit_width = (double)(area->params.width * area->params.antialias - 1); float limit_width = (float)(area->params.width * area->params.antialias - 1);
double limit_height = (double)(area->params.height * area->params.antialias - 1); float limit_height = (float)(area->params.height * area->params.antialias - 1);
/* Filter if outside screen */ /* Filter if outside screen */
if (p1.z < 1.0 || p2.z < 1.0 || p3.z < 1.0 || (p1.x < 0.0 && p2.x < 0.0 && p3.x < 0.0) || (p1.y < 0.0 && p2.y < 0.0 && p3.y < 0.0) || (p1.x > limit_width && p2.x > limit_width && p3.x > limit_width) || (p1.y > limit_height && p2.y > limit_height && p3.y > limit_height)) if (p1.z < 1.0 || p2.z < 1.0 || p3.z < 1.0 || (p1.x < 0.0 && p2.x < 0.0 && p3.x < 0.0) || (p1.y < 0.0 && p2.y < 0.0 && p3.y < 0.0) || (p1.x > limit_width && p2.x > limit_width && p3.x > limit_width) || (p1.y > limit_height && p2.y > limit_height && p3.y > limit_height))
@ -761,7 +761,7 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks)
if (++loops >= 10) if (++loops >= 10)
{ {
mutexAcquire(area->lock); mutexAcquire(area->lock);
/*_progress = (double)_progress_pixels / (double)_pixel_count;*/ /*_progress = (float)_progress_pixels / (float)_pixel_count;*/
_processDirtyPixels(area); _processDirtyPixels(area);
mutexRelease(area->lock); mutexRelease(area->lock);
@ -771,6 +771,7 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks)
/*_progress = 1.0;*/ /*_progress = 1.0;*/
_processDirtyPixels(area); _processDirtyPixels(area);
area->callback_update(1.0);
} }
int renderSaveToFile(RenderArea* area, const char* path) int renderSaveToFile(RenderArea* area, const char* path)

View file

@ -21,7 +21,7 @@ void renderClear(RenderArea* area);
void renderUpdate(RenderArea* area); void renderUpdate(RenderArea* area);
void renderAddFragment(RenderArea* area, RenderFragment* fragment); void renderAddFragment(RenderArea* area, RenderFragment* fragment);
void renderPushFragment(RenderArea* area, int x, int y, double z, Vertex* vertex); void renderPushFragment(RenderArea* area, int x, int y, float z, Vertex* vertex);
void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3); void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3);
void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks); void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks);

View file

@ -17,12 +17,12 @@ static void* _renderFirstPass(void* data)
return NULL; return NULL;
} }
static int _addRenderProgress(Renderer* renderer, double progress) static int _addRenderProgress(Renderer* renderer, float progress)
{ {
return !renderer->render_interrupt; return !renderer->render_interrupt;
} }
static double _getPrecision(Renderer* renderer, Vector3 location) static float _getPrecision(Renderer* renderer, Vector3 location)
{ {
return 0.001; return 0.001;
} }
@ -73,7 +73,7 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
return _RAYCASTING_NULL; return _RAYCASTING_NULL;
} }
static double _getTerrainHeight(Renderer* renderer, double x, double z) static float _getTerrainHeight(Renderer* renderer, float x, float z)
{ {
return 0.0; return 0.0;
} }
@ -83,7 +83,7 @@ static HeightInfo _getWaterHeightInfo(Renderer* renderer)
return _WATER_HEIGHT_INFO; return _WATER_HEIGHT_INFO;
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
{ {
return COLOR_TRANSPARENT; return COLOR_TRANSPARENT;
} }

View file

@ -20,21 +20,21 @@ struct Renderer
/* Render related */ /* Render related */
RenderArea* render_area; RenderArea* render_area;
double render_progress; float render_progress;
int render_interrupt; int render_interrupt;
int is_rendering; int is_rendering;
double (*getPrecision)(Renderer* renderer, Vector3 location); float (*getPrecision)(Renderer* renderer, Vector3 location);
Vector3 (*projectPoint)(Renderer* renderer, Vector3 point); Vector3 (*projectPoint)(Renderer* renderer, Vector3 point);
Vector3 (*unprojectPoint)(Renderer* renderer, Vector3 point); Vector3 (*unprojectPoint)(Renderer* renderer, Vector3 point);
int (*addRenderProgress)(Renderer* renderer, double progress); int (*addRenderProgress)(Renderer* renderer, float progress);
void (*pushTriangle)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3); void (*pushTriangle)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3);
void (*pushQuad)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4); void (*pushQuad)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4);
/* Scenery related */ /* Scenery related */
RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds); RayCastingResult (*rayWalking)(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds);
double (*getTerrainHeight)(Renderer* renderer, double x, double z); float (*getTerrainHeight)(Renderer* renderer, float x, float z);
HeightInfo (*getWaterHeightInfo)(Renderer* renderer); HeightInfo (*getWaterHeightInfo)(Renderer* renderer);
Color (*applyTextures)(Renderer* renderer, Vector3 location, double precision); Color (*applyTextures)(Renderer* renderer, Vector3 location, float precision);
Color (*applyAtmosphere)(Renderer* renderer, Vector3 location, Color base); Color (*applyAtmosphere)(Renderer* renderer, Vector3 location, Color base);
Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end); Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end);

View file

@ -282,7 +282,7 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
return result; return result;
} }
static double _getTerrainHeight(Renderer* renderer, double x, double z) static float _getTerrainHeight(Renderer* renderer, float x, float z)
{ {
return terrainGetHeight(&_terrain, x, z); return terrainGetHeight(&_terrain, x, z);
} }
@ -292,7 +292,7 @@ static HeightInfo _getWaterHeightInfo(Renderer* renderer)
return waterGetHeightInfo(&_water); return waterGetHeightInfo(&_water);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision) static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
{ {
return texturesGetColor(&_textures, renderer, location.x, location.z, precision); return texturesGetColor(&_textures, renderer, location.x, location.z, precision);
} }
@ -322,7 +322,7 @@ static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
return cameraUnproject(&renderer->render_camera, renderer, point); return cameraUnproject(&renderer->render_camera, renderer, point);
} }
static double _getPrecision(Renderer* renderer, Vector3 location) static float _getPrecision(Renderer* renderer, Vector3 location)
{ {
Vector3 projected; Vector3 projected;
@ -330,7 +330,7 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
projected.x += 1.0; projected.x += 1.0;
//projected.y += 1.0; //projected.y += 1.0;
return v3Norm(v3Sub(cameraUnproject(&renderer->render_camera, renderer, projected), location)); // / (double)render_quality; return v3Norm(v3Sub(cameraUnproject(&renderer->render_camera, renderer, projected), location)); // / (float)render_quality;
} }
Renderer sceneryCreateStandardRenderer() Renderer sceneryCreateStandardRenderer()

View file

@ -29,7 +29,7 @@ typedef struct RenderFragment
{ {
int x; int x;
int y; int y;
double z; float z;
Vertex vertex; Vertex vertex;
} RenderFragment; } RenderFragment;
@ -53,13 +53,13 @@ typedef struct
typedef struct typedef struct
{ {
Color base; Color base;
double reflection; float reflection;
double shininess; float shininess;
} SurfaceMaterial; } SurfaceMaterial;
typedef void (*RenderCallbackStart)(int width, int height, Color background); typedef void (*RenderCallbackStart)(int width, int height, Color background);
typedef void (*RenderCallbackDraw)(int x, int y, Color col); typedef void (*RenderCallbackDraw)(int x, int y, Color col);
typedef void (*RenderCallbackUpdate)(double progress); typedef void (*RenderCallbackUpdate)(float progress);
typedef struct RenderArea RenderArea; typedef struct RenderArea RenderArea;
@ -73,29 +73,29 @@ typedef RayCastingResult (*RayCastingFunction)(Vector3 start, Vector3 direction)
typedef struct typedef struct
{ {
double min_height; float min_height;
double max_height; float max_height;
double base_height; float base_height;
} HeightInfo; } HeightInfo;
typedef struct typedef struct
{ {
Vector3 location; Vector3 location;
double yaw; float yaw;
double pitch; float pitch;
double roll; float roll;
Vector3 target; Vector3 target;
Vector3 forward; Vector3 forward;
Vector3 right; Vector3 right;
Vector3 up; Vector3 up;
double width; float width;
double height; float height;
double yfov; float yfov;
double xratio; float xratio;
double znear; float znear;
double zfar; float zfar;
Matrix4 project; Matrix4 project;
Matrix4 unproject; Matrix4 unproject;

View file

@ -23,28 +23,28 @@ void skyQuit()
void skySave(PackStream* stream, SkyDefinition* definition) void skySave(PackStream* stream, SkyDefinition* definition)
{ {
packWriteDouble(stream, &definition->daytime); packWriteFloat(stream, &definition->daytime);
colorGradationSave(stream, definition->sun_color); colorGradationSave(stream, definition->sun_color);
packWriteDouble(stream, &definition->sun_radius); packWriteFloat(stream, &definition->sun_radius);
packWriteDouble(stream, &definition->sun_halo_size); packWriteFloat(stream, &definition->sun_halo_size);
curveSave(stream, definition->sun_halo_profile); curveSave(stream, definition->sun_halo_profile);
colorGradationSave(stream, definition->zenith_color); colorGradationSave(stream, definition->zenith_color);
colorGradationSave(stream, definition->haze_color); colorGradationSave(stream, definition->haze_color);
packWriteDouble(stream, &definition->haze_height); packWriteFloat(stream, &definition->haze_height);
packWriteDouble(stream, &definition->haze_smoothing); packWriteFloat(stream, &definition->haze_smoothing);
} }
void skyLoad(PackStream* stream, SkyDefinition* definition) void skyLoad(PackStream* stream, SkyDefinition* definition)
{ {
packReadDouble(stream, &definition->daytime); packReadFloat(stream, &definition->daytime);
colorGradationLoad(stream, definition->sun_color); colorGradationLoad(stream, definition->sun_color);
packReadDouble(stream, &definition->sun_radius); packReadFloat(stream, &definition->sun_radius);
packReadDouble(stream, &definition->sun_halo_size); packReadFloat(stream, &definition->sun_halo_size);
curveLoad(stream, definition->sun_halo_profile); curveLoad(stream, definition->sun_halo_profile);
colorGradationLoad(stream, definition->zenith_color); colorGradationLoad(stream, definition->zenith_color);
colorGradationLoad(stream, definition->haze_color); colorGradationLoad(stream, definition->haze_color);
packReadDouble(stream, &definition->haze_height); packReadFloat(stream, &definition->haze_height);
packReadDouble(stream, &definition->haze_smoothing); packReadFloat(stream, &definition->haze_smoothing);
skyValidateDefinition(definition); skyValidateDefinition(definition);
} }
@ -108,7 +108,7 @@ void skyValidateDefinition(SkyDefinition* definition)
int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights) int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)
{ {
double sun_angle; float sun_angle;
Vector3 sun_direction; Vector3 sun_direction;
int nblights = 0; int nblights = 0;
@ -152,7 +152,7 @@ int skyGetLights(SkyDefinition* sky, LightDefinition* lights, int max_lights)
Color skyGetColor(SkyDefinition* definition, Renderer* renderer, Vector3 eye, Vector3 look) Color skyGetColor(SkyDefinition* definition, Renderer* renderer, Vector3 eye, Vector3 look)
{ {
double dist; float dist;
Vector3 sun_position; Vector3 sun_position;
Color sun_color, sky_color; Color sun_color, sky_color;
@ -206,16 +206,16 @@ void skyRender(SkyDefinition* definition, Renderer* renderer)
{ {
int res_i, res_j; int res_i, res_j;
int i, j; int i, j;
double step_i, step_j; float step_i, step_j;
double current_i, current_j; float current_i, current_j;
Vertex vertex1, vertex2, vertex3, vertex4; Vertex vertex1, vertex2, vertex3, vertex4;
Color col; Color col;
Vector3 direction; Vector3 direction;
res_i = renderer->render_quality * 40; res_i = renderer->render_quality * 40;
res_j = renderer->render_quality * 20; res_j = renderer->render_quality * 20;
step_i = M_PI * 2.0 / (double)res_i; step_i = M_PI * 2.0 / (float)res_i;
step_j = M_PI / (double)res_j; step_j = M_PI / (float)res_j;
col.r = 0.0; col.r = 0.0;
col.g = 0.0; col.g = 0.0;
@ -228,11 +228,11 @@ void skyRender(SkyDefinition* definition, Renderer* renderer)
return; return;
} }
current_j = (double)(j - res_j / 2) * step_j; current_j = (float)(j - res_j / 2) * step_j;
for (i = 0; i < res_i; i++) for (i = 0; i < res_i; i++)
{ {
current_i = (double)i * step_i; current_i = (float)i * step_i;
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j); direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j); direction.y = SPHERE_SIZE * sin(current_j);
@ -279,7 +279,7 @@ void skyRender(SkyDefinition* definition, Renderer* renderer)
Vector3 skyGetSunDirection(SkyDefinition* definition) Vector3 skyGetSunDirection(SkyDefinition* definition)
{ {
Vector3 result; Vector3 result;
double sun_angle = (definition->daytime + 0.75) * M_PI * 2.0; float sun_angle = (definition->daytime + 0.75) * M_PI * 2.0;
result.x = cos(sun_angle); result.x = cos(sun_angle);
result.y = sin(sun_angle); result.y = sin(sun_angle);
result.z = 0.0; result.z = 0.0;

View file

@ -12,15 +12,15 @@ extern "C" {
typedef struct typedef struct
{ {
double daytime; float daytime;
ColorGradation* sun_color; ColorGradation* sun_color;
double sun_radius; float sun_radius;
double sun_halo_size; float sun_halo_size;
Curve* sun_halo_profile; Curve* sun_halo_profile;
ColorGradation* zenith_color; ColorGradation* zenith_color;
ColorGradation* haze_color; ColorGradation* haze_color;
double haze_height; float haze_height;
double haze_smoothing; float haze_smoothing;
ColorGradation* _sky_gradation; ColorGradation* _sky_gradation;
} SkyDefinition; } SkyDefinition;

View file

@ -25,8 +25,8 @@ void terrainSave(PackStream* stream, TerrainDefinition* definition)
int i; int i;
noiseSaveGenerator(stream, definition->height_noise); noiseSaveGenerator(stream, definition->height_noise);
packWriteDouble(stream, &definition->height_factor); packWriteFloat(stream, &definition->height_factor);
packWriteDouble(stream, &definition->scaling); packWriteFloat(stream, &definition->scaling);
packWriteInt(stream, &definition->height_modifiers_count); packWriteInt(stream, &definition->height_modifiers_count);
for (i = 0; i < definition->height_modifiers_count; i++) for (i = 0; i < definition->height_modifiers_count; i++)
@ -41,8 +41,8 @@ void terrainLoad(PackStream* stream, TerrainDefinition* definition)
HeightModifier* modifier; HeightModifier* modifier;
noiseLoadGenerator(stream, definition->height_noise); noiseLoadGenerator(stream, definition->height_noise);
packReadDouble(stream, &definition->height_factor); packReadFloat(stream, &definition->height_factor);
packReadDouble(stream, &definition->scaling); packReadFloat(stream, &definition->scaling);
while (definition->height_modifiers_count > 0) while (definition->height_modifiers_count > 0)
{ {
@ -139,7 +139,7 @@ void terrainDelModifier(TerrainDefinition* definition, int modifier_position)
} }
} }
static inline double _getHeight(TerrainDefinition* definition, double x, double z) static inline float _getHeight(TerrainDefinition* definition, float x, float z)
{ {
Vector3 location; Vector3 location;
int i; int i;
@ -156,7 +156,7 @@ static inline double _getHeight(TerrainDefinition* definition, double x, double
return location.y; return location.y;
} }
static inline double _getHeightDetail(TerrainDefinition* definition, double x, double z, double detail) static inline float _getHeightDetail(TerrainDefinition* definition, float x, float z, float detail)
{ {
Vector3 location; Vector3 location;
int i; int i;
@ -173,7 +173,7 @@ static inline double _getHeightDetail(TerrainDefinition* definition, double x, d
return location.y; return location.y;
} }
static inline Vector3 _getPoint(TerrainDefinition* definition, double x, double z) static inline Vector3 _getPoint(TerrainDefinition* definition, float x, float z)
{ {
Vector3 result; Vector3 result;
@ -187,7 +187,7 @@ static inline Vector3 _getPoint(TerrainDefinition* definition, double x, double
Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light) Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{ {
Vector3 inc_vector; Vector3 inc_vector;
double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length; float inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length;
direction_to_light = v3Normalize(direction_to_light); direction_to_light = v3Normalize(direction_to_light);
if (fabs(direction_to_light.x) < 0.0001 && fabs(direction_to_light.z) < 0.0001) if (fabs(direction_to_light.x) < 0.0001 && fabs(direction_to_light.z) < 0.0001)
@ -205,7 +205,7 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo
light.b *= (0.05 + direction_to_light.y) / 0.05; light.b *= (0.05 + direction_to_light.y) / 0.05;
} }
inc_factor = (double)renderer->render_quality; inc_factor = (float)renderer->render_quality;
inc_base = 1.0; inc_base = 1.0;
inc_value = inc_base / inc_factor; inc_value = inc_base / inc_factor;
smoothing = 0.03 * inc_factor; smoothing = 0.03 * inc_factor;
@ -253,7 +253,7 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo
} }
} }
static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector3 point, double precision) static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector3 point, float precision)
{ {
Color color; Color color;
@ -267,10 +267,10 @@ static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector
int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, Vector3* hit_point, Color* hit_color) int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, Vector3* hit_point, Color* hit_color)
{ {
Vector3 inc_vector; Vector3 inc_vector;
double inc_value, inc_base, inc_factor, height, diff, lastdiff, length; float inc_value, inc_base, inc_factor, height, diff, lastdiff, length;
direction = v3Normalize(direction); direction = v3Normalize(direction);
inc_factor = (double)renderer->render_quality; inc_factor = (float)renderer->render_quality;
inc_base = 1.0; inc_base = 1.0;
inc_value = inc_base / inc_factor; inc_value = inc_base / inc_factor;
lastdiff = start.y - _getHeight(definition, start.x, start.z); lastdiff = start.y - _getHeight(definition, start.x, start.z);
@ -320,7 +320,7 @@ int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data) static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data)
{ {
Vector3 point; Vector3 point;
double precision; float precision;
TerrainDefinition* definition; TerrainDefinition* definition;
definition = (TerrainDefinition*)data; definition = (TerrainDefinition*)data;
@ -334,10 +334,10 @@ static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, vo
return 1; return 1;
} }
static Vertex _getFirstPassVertex(TerrainDefinition* definition, double x, double z, double detail) static Vertex _getFirstPassVertex(TerrainDefinition* definition, float x, float z, float detail)
{ {
Vertex result; Vertex result;
double value; float value;
result.location = _getPoint(definition, x, z); result.location = _getPoint(definition, x, z);
value = sin(x) * sin(x) * cos(z) * cos(z); value = sin(x) * sin(x) * cos(z) * cos(z);
@ -352,7 +352,7 @@ static Vertex _getFirstPassVertex(TerrainDefinition* definition, double x, doubl
return result; return result;
} }
static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, double x, double z, double size, double water_height) static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, float x, float z, float size, float water_height)
{ {
Vertex v1, v2, v3, v4; Vertex v1, v2, v3, v4;
@ -367,12 +367,12 @@ static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, doubl
} }
} }
double terrainGetHeight(TerrainDefinition* definition, double x, double z) float terrainGetHeight(TerrainDefinition* definition, float x, float z)
{ {
return _getHeight(definition, x, z); return _getHeight(definition, x, z);
} }
double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z) float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z)
{ {
if (definition->_max_height == 0.0) if (definition->_max_height == 0.0)
{ {
@ -384,7 +384,7 @@ double terrainGetHeightNormalized(TerrainDefinition* definition, double x, doubl
} }
} }
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double x, double z, double detail) Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x, float z, float detail)
{ {
Vector3 point = _getPoint(definition, x, z); Vector3 point = _getPoint(definition, x, z);
return _getColor(definition, renderer, point, detail); return _getColor(definition, renderer, point, detail);
@ -393,14 +393,14 @@ Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double
void terrainRender(TerrainDefinition* definition, Renderer* renderer) void terrainRender(TerrainDefinition* definition, Renderer* renderer)
{ {
int chunk_factor, chunk_count, i; int chunk_factor, chunk_count, i;
double cx = renderer->camera_location.x; float cx = renderer->camera_location.x;
double cz = renderer->camera_location.z; float cz = renderer->camera_location.z;
double min_chunk_size, visible_chunk_size; float min_chunk_size, visible_chunk_size;
double radius_int, radius_ext, chunk_size; float radius_int, radius_ext, chunk_size;
double water_height; float water_height;
min_chunk_size = 0.1 / (double)renderer->render_quality; min_chunk_size = 0.1 / (float)renderer->render_quality;
visible_chunk_size = 0.05 / (double)renderer->render_quality; visible_chunk_size = 0.05 / (float)renderer->render_quality;
chunk_factor = 1; chunk_factor = 1;
chunk_count = 2; chunk_count = 2;

View file

@ -16,12 +16,12 @@ extern "C" {
typedef struct typedef struct
{ {
NoiseGenerator* height_noise; NoiseGenerator* height_noise;
double height_factor; float height_factor;
double scaling; float scaling;
int height_modifiers_count; int height_modifiers_count;
HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS]; HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS];
double _max_height; float _max_height;
} TerrainDefinition; } TerrainDefinition;
void terrainInit(); void terrainInit();
@ -39,9 +39,9 @@ void terrainDelModifier(TerrainDefinition* definition, int modifier_position);
Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light); Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light);
int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, Vector3* hit_point, Color* hit_color); int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3 start, Vector3 direction, Vector3* hit_point, Color* hit_color);
double terrainGetHeight(TerrainDefinition* definition, double x, double z); float terrainGetHeight(TerrainDefinition* definition, float x, float z);
double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z); float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z);
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double x, double z, double detail); Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x, float z, float detail);
void terrainRender(TerrainDefinition* definition, Renderer* renderer); void terrainRender(TerrainDefinition* definition, Renderer* renderer);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -16,7 +16,7 @@ static TextureLayerDefinition _NULL_LAYER;
typedef struct typedef struct
{ {
double thickness; float thickness;
Vector3 location; Vector3 location;
Vector3 normal; Vector3 normal;
TextureLayerDefinition* definition; TextureLayerDefinition* definition;
@ -41,12 +41,12 @@ void texturesSave(PackStream* stream, TexturesDefinition* definition)
{ {
zoneSave(stream, definition->textures[i].zone); zoneSave(stream, definition->textures[i].zone);
noiseSaveGenerator(stream, definition->textures[i].bump_noise); noiseSaveGenerator(stream, definition->textures[i].bump_noise);
packWriteDouble(stream, &definition->textures[i].bump_height); packWriteFloat(stream, &definition->textures[i].bump_height);
packWriteDouble(stream, &definition->textures[i].bump_scaling); packWriteFloat(stream, &definition->textures[i].bump_scaling);
materialSave(stream, &definition->textures[i].material); materialSave(stream, &definition->textures[i].material);
packWriteDouble(stream, &definition->textures[i].thickness); packWriteFloat(stream, &definition->textures[i].thickness);
packWriteDouble(stream, &definition->textures[i].slope_range); packWriteFloat(stream, &definition->textures[i].slope_range);
packWriteDouble(stream, &definition->textures[i].thickness_transparency); packWriteFloat(stream, &definition->textures[i].thickness_transparency);
} }
} }
@ -67,12 +67,12 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition)
zoneLoad(stream, layer->zone); zoneLoad(stream, layer->zone);
noiseLoadGenerator(stream, layer->bump_noise); noiseLoadGenerator(stream, layer->bump_noise);
packReadDouble(stream, &layer->bump_height); packReadFloat(stream, &layer->bump_height);
packReadDouble(stream, &layer->bump_scaling); packReadFloat(stream, &layer->bump_scaling);
materialLoad(stream, &layer->material); materialLoad(stream, &layer->material);
packReadDouble(stream, &definition->textures[i].thickness); packReadFloat(stream, &definition->textures[i].thickness);
packReadDouble(stream, &definition->textures[i].slope_range); packReadFloat(stream, &definition->textures[i].slope_range);
packReadDouble(stream, &definition->textures[i].thickness_transparency); packReadFloat(stream, &definition->textures[i].thickness_transparency);
} }
texturesValidateDefinition(definition); texturesValidateDefinition(definition);
@ -236,7 +236,7 @@ static inline Vector3 _getNormal2(Vector3 center, Vector3 east, Vector3 south)
return v3Normalize(v3Cross(v3Sub(south, center), v3Sub(east, center))); return v3Normalize(v3Cross(v3Sub(south, center), v3Sub(east, center)));
} }
static inline TextureResult _getTerrainResult(Renderer* renderer, double x, double z, double detail) static inline TextureResult _getTerrainResult(Renderer* renderer, float x, float z, float detail)
{ {
TextureResult result; TextureResult result;
Vector3 center, north, east, south, west; Vector3 center, north, east, south, west;
@ -279,10 +279,10 @@ static inline TextureResult _getTerrainResult(Renderer* renderer, double x, doub
return result; return result;
} }
static inline void _getLayerThickness(TextureLayerDefinition* definition, Renderer* renderer, double x, double z, TextureResult* result) static inline void _getLayerThickness(TextureLayerDefinition* definition, Renderer* renderer, float x, float z, TextureResult* result)
{ {
TextureResult base; TextureResult base;
double coverage; float coverage;
base = _getTerrainResult(renderer, x, z, definition->slope_range); base = _getTerrainResult(renderer, x, z, definition->slope_range);
coverage = zoneGetValue(definition->zone, base.location, base.normal); coverage = zoneGetValue(definition->zone, base.location, base.normal);
@ -300,7 +300,7 @@ static inline void _getLayerThickness(TextureLayerDefinition* definition, Render
} }
} }
static inline TextureResult _getLayerResult(TextureLayerDefinition* definition, Renderer* renderer, double x, double z, double detail) static inline TextureResult _getLayerResult(TextureLayerDefinition* definition, Renderer* renderer, float x, float z, float detail)
{ {
TextureResult result_center, result_north, result_east, result_south, result_west; TextureResult result_center, result_north, result_east, result_south, result_west;
@ -330,7 +330,7 @@ static int _cmpResults(const void* result1, const void* result2)
return ((TextureResult*)result1)->thickness > ((TextureResult*)result2)->thickness; return ((TextureResult*)result1)->thickness > ((TextureResult*)result2)->thickness;
} }
double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail) float texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail)
{ {
TextureResult base = _getTerrainResult(renderer, location.x, location.z, definition->slope_range); TextureResult base = _getTerrainResult(renderer, location.x, location.z, definition->slope_range);
return zoneGetValue(definition->zone, base.location, base.normal); return zoneGetValue(definition->zone, base.location, base.normal);
@ -341,7 +341,7 @@ static inline Color _getLayerColor(Renderer* renderer, TextureResult result, Lig
return renderer->applyLightStatus(renderer, light, result.location, result.normal, result.definition->material); return renderer->applyLightStatus(renderer, light, result.location, result.normal, result.definition->material);
} }
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail) Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail)
{ {
LightStatus light; LightStatus light;
TextureResult result = _getLayerResult(definition, renderer, location.x, location.z, detail); TextureResult result = _getLayerResult(definition, renderer, location.x, location.z, detail);
@ -349,11 +349,11 @@ Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* render
return _getLayerColor(renderer, result, &light); return _getLayerColor(renderer, result, &light);
} }
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail) Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, float x, float z, float detail)
{ {
TextureResult results[TEXTURES_MAX_LAYERS + 1]; TextureResult results[TEXTURES_MAX_LAYERS + 1];
Color result, color; Color result, color;
double thickness, last_height; float thickness, last_height;
int i, start; int i, start;
detail *= 0.1; detail *= 0.1;

View file

@ -17,12 +17,12 @@ typedef struct
{ {
Zone* zone; Zone* zone;
NoiseGenerator* bump_noise; NoiseGenerator* bump_noise;
double bump_scaling; float bump_scaling;
double bump_height; float bump_height;
SurfaceMaterial material; SurfaceMaterial material;
double thickness; float thickness;
double slope_range; float slope_range;
double thickness_transparency; float thickness_transparency;
} TextureLayerDefinition; } TextureLayerDefinition;
typedef struct typedef struct
@ -51,9 +51,9 @@ TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int lay
int texturesAddLayer(TexturesDefinition* definition); int texturesAddLayer(TexturesDefinition* definition);
void texturesDeleteLayer(TexturesDefinition* definition, int layer); void texturesDeleteLayer(TexturesDefinition* definition, int layer);
double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail); float texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail);
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail); Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail);
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail); Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, float x, float z, float detail);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -8,19 +8,19 @@
#include "color.h" #include "color.h"
#include "euclid.h" #include "euclid.h"
double toolsRandom() float toolsRandom()
{ {
return (double)rand() / (double)RAND_MAX; return (float)rand() / (float)RAND_MAX;
} }
static inline double __cubicInterpolate(double p[4], double x) static inline float __cubicInterpolate(float p[4], float x)
{ {
return p[1] + 0.5 * x * (p[2] - p[0] + x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + x * (3.0 * (p[1] - p[2]) + p[3] - p[0]))); return p[1] + 0.5 * x * (p[2] - p[0] + x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + x * (3.0 * (p[1] - p[2]) + p[3] - p[0])));
} }
double toolsBicubicInterpolate(double stencil[16], double x, double y) float toolsBicubicInterpolate(float stencil[16], float x, float y)
{ {
double buf_cubic_y[4]; float buf_cubic_y[4];
buf_cubic_y[0] = __cubicInterpolate(stencil, x); buf_cubic_y[0] = __cubicInterpolate(stencil, x);
buf_cubic_y[1] = __cubicInterpolate(stencil + 4, x); buf_cubic_y[1] = __cubicInterpolate(stencil + 4, x);
@ -30,12 +30,12 @@ double toolsBicubicInterpolate(double stencil[16], double x, double y)
return __cubicInterpolate(buf_cubic_y, y); return __cubicInterpolate(buf_cubic_y, y);
} }
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep) void toolsFloat2DMapCopy(float* src, float* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep)
{ {
/* TODO Optimize with memcpy if src_xstep == dest_xstep == 1 */ /* TODO Optimize with memcpy if src_xstep == dest_xstep == 1 */
int x, y; int x, y;
double* src_row; float* src_row;
double* dest_row; float* dest_row;
src += src_ystart * src_ystep + src_xstart * src_xstep; src += src_ystart * src_ystep + src_xstart * src_xstep;
dest += dest_ystart * dest_ystep + dest_xstart * dest_xstep; dest += dest_ystart * dest_ystep + dest_xstart * dest_xstep;
for (y = 0; y < ysize; y++) for (y = 0; y < ysize; y++)
@ -60,23 +60,23 @@ Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right
return v3Normalize(v3Cross(dz, dx)); return v3Normalize(v3Cross(dz, dx));
} }
double toolsGetDistance2D(double x1, double y1, double x2, double y2) float toolsGetDistance2D(float x1, float y1, float x2, float y2)
{ {
double dx = x2 - x1; float dx = x2 - x1;
double dy = y2 - y1; float dy = y2 - y1;
return sqrt(dx * dx + dy * dy); return sqrt(dx * dx + dy * dy);
} }
void materialSave(PackStream* stream, SurfaceMaterial* material) void materialSave(PackStream* stream, SurfaceMaterial* material)
{ {
colorSave(stream, &material->base); colorSave(stream, &material->base);
packWriteDouble(stream, &material->reflection); packWriteFloat(stream, &material->reflection);
packWriteDouble(stream, &material->shininess); packWriteFloat(stream, &material->shininess);
} }
void materialLoad(PackStream* stream, SurfaceMaterial* material) void materialLoad(PackStream* stream, SurfaceMaterial* material)
{ {
colorLoad(stream, &material->base); colorLoad(stream, &material->base);
packReadDouble(stream, &material->reflection); packReadFloat(stream, &material->reflection);
packReadDouble(stream, &material->shininess); packReadFloat(stream, &material->shininess);
} }

View file

@ -8,11 +8,11 @@
extern "C" { extern "C" {
#endif #endif
double toolsRandom(); float toolsRandom();
double toolsBicubicInterpolate(double stencil[16], double x, double y); float toolsBicubicInterpolate(float stencil[16], float x, float y);
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep); void toolsFloat2DMapCopy(float* src, float* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep);
Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right); Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
double toolsGetDistance2D(double x1, double y1, double x2, double y2); float toolsGetDistance2D(float x1, float y1, float x2, float y2);
void materialSave(PackStream* stream, SurfaceMaterial* material); void materialSave(PackStream* stream, SurfaceMaterial* material);
void materialLoad(PackStream* stream, SurfaceMaterial* material); void materialLoad(PackStream* stream, SurfaceMaterial* material);

View file

@ -13,7 +13,7 @@ extern "C" {
typedef struct typedef struct
{ {
Zone* zone; Zone* zone;
double max_height; float max_height;
} VegetationLayerDefinition; } VegetationLayerDefinition;
typedef struct VegetationDefinition VegetationDefinition; typedef struct VegetationDefinition VegetationDefinition;
@ -39,7 +39,7 @@ int vegetationSetLayer(VegetationDefinition* definition, int position, Vegetatio
int vegetationAddLayer(VegetationDefinition* definition); int vegetationAddLayer(VegetationDefinition* definition);
void vegetationDeleteLayer(VegetationDefinition* definition, int layer); void vegetationDeleteLayer(VegetationDefinition* definition, int layer);
/*double vegetationGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);*/ /*float vegetationGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail);*/
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -20,30 +20,30 @@ void waterQuit()
void waterSave(PackStream* stream, WaterDefinition* definition) void waterSave(PackStream* stream, WaterDefinition* definition)
{ {
packWriteDouble(stream, &definition->height); packWriteFloat(stream, &definition->height);
materialSave(stream, &definition->material); materialSave(stream, &definition->material);
colorSave(stream, &definition->depth_color); colorSave(stream, &definition->depth_color);
packWriteDouble(stream, &definition->transparency_depth); packWriteFloat(stream, &definition->transparency_depth);
packWriteDouble(stream, &definition->transparency); packWriteFloat(stream, &definition->transparency);
packWriteDouble(stream, &definition->reflection); packWriteFloat(stream, &definition->reflection);
packWriteDouble(stream, &definition->lighting_depth); packWriteFloat(stream, &definition->lighting_depth);
noiseSaveGenerator(stream, definition->waves_noise); noiseSaveGenerator(stream, definition->waves_noise);
packWriteDouble(stream, &definition->waves_noise_height); packWriteFloat(stream, &definition->waves_noise_height);
packWriteDouble(stream, &definition->waves_noise_scale); packWriteFloat(stream, &definition->waves_noise_scale);
} }
void waterLoad(PackStream* stream, WaterDefinition* definition) void waterLoad(PackStream* stream, WaterDefinition* definition)
{ {
packReadDouble(stream, &definition->height); packReadFloat(stream, &definition->height);
materialLoad(stream, &definition->material); materialLoad(stream, &definition->material);
colorLoad(stream, &definition->depth_color); colorLoad(stream, &definition->depth_color);
packReadDouble(stream, &definition->transparency_depth); packReadFloat(stream, &definition->transparency_depth);
packReadDouble(stream, &definition->transparency); packReadFloat(stream, &definition->transparency);
packReadDouble(stream, &definition->reflection); packReadFloat(stream, &definition->reflection);
packReadDouble(stream, &definition->lighting_depth); packReadFloat(stream, &definition->lighting_depth);
noiseLoadGenerator(stream, definition->waves_noise); noiseLoadGenerator(stream, definition->waves_noise);
packReadDouble(stream, &definition->waves_noise_height); packReadFloat(stream, &definition->waves_noise_height);
packReadDouble(stream, &definition->waves_noise_scale); packReadFloat(stream, &definition->waves_noise_scale);
waterValidateDefinition(definition); waterValidateDefinition(definition);
} }
@ -87,15 +87,15 @@ void waterValidateDefinition(WaterDefinition* definition)
{ {
} }
static inline double _getHeight(WaterDefinition* definition, double x, double z, double detail) static inline float _getHeight(WaterDefinition* definition, float x, float z, float detail)
{ {
return definition->height + noiseGet2DDetail(definition->waves_noise, x / definition->waves_noise_scale, z / definition->waves_noise_scale, detail) * definition->waves_noise_height; return definition->height + noiseGet2DDetail(definition->waves_noise, x / definition->waves_noise_scale, z / definition->waves_noise_scale, detail) * definition->waves_noise_height;
} }
static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail) static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, float detail)
{ {
Vector3 back, right; Vector3 back, right;
double x, z; float x, z;
x = base.x; x = base.x;
z = base.z; z = base.z;
@ -115,7 +115,7 @@ static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, doub
static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal) static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
{ {
double c; float c;
c = v3Dot(normal, v3Scale(incoming, -1.0)); c = v3Dot(normal, v3Scale(incoming, -1.0));
return v3Add(incoming, v3Scale(normal, 2.0 * c)); return v3Add(incoming, v3Scale(normal, 2.0 * c));
@ -123,7 +123,7 @@ static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal) static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
{ {
double c1, c2, f; float c1, c2, f;
f = 1.0 / 1.33; f = 1.0 / 1.33;
c1 = v3Dot(normal, v3Scale(incoming, -1.0)); c1 = v3Dot(normal, v3Scale(incoming, -1.0));
@ -151,7 +151,7 @@ HeightInfo waterGetHeightInfo(WaterDefinition* definition)
Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light) Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{ {
double factor; float factor;
if (location.y < definition->height) if (location.y < definition->height)
{ {
@ -189,7 +189,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
Color color; Color color;
LightStatus light; LightStatus light;
SurfaceMaterial material; SurfaceMaterial material;
double detail, depth; float detail, depth;
detail = renderer->getPrecision(renderer, location); detail = renderer->getPrecision(renderer, location);
@ -243,10 +243,10 @@ static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, vo
return 1; return 1;
} }
static Vertex _getFirstPassVertex(WaterDefinition* definition, double x, double z, double precision) static Vertex _getFirstPassVertex(WaterDefinition* definition, float x, float z, float precision)
{ {
Vertex result; Vertex result;
double value; float value;
result.location.x = x; result.location.x = x;
result.location.y = _getHeight(definition, x, z, 0.0); result.location.y = _getHeight(definition, x, z, 0.0);
@ -263,7 +263,7 @@ static Vertex _getFirstPassVertex(WaterDefinition* definition, double x, double
return result; return result;
} }
static void _renderQuad(WaterDefinition* definition, Renderer* renderer, double x, double z, double size) static void _renderQuad(WaterDefinition* definition, Renderer* renderer, float x, float z, float size)
{ {
Vertex v1, v2, v3, v4; Vertex v1, v2, v3, v4;
@ -277,11 +277,11 @@ static void _renderQuad(WaterDefinition* definition, Renderer* renderer, double
void waterRender(WaterDefinition* definition, Renderer* renderer) void waterRender(WaterDefinition* definition, Renderer* renderer)
{ {
int chunk_factor, chunk_count, i; int chunk_factor, chunk_count, i;
double cx = renderer->camera_location.x; float cx = renderer->camera_location.x;
double cz = renderer->camera_location.z; float cz = renderer->camera_location.z;
double radius_int, radius_ext, base_chunk_size, chunk_size; float radius_int, radius_ext, base_chunk_size, chunk_size;
base_chunk_size = 2.0 / (double)renderer->render_quality; base_chunk_size = 2.0 / (float)renderer->render_quality;
chunk_factor = 1; chunk_factor = 1;
chunk_count = 2; chunk_count = 2;
@ -304,7 +304,7 @@ void waterRender(WaterDefinition* definition, Renderer* renderer)
_renderQuad(definition, renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size); _renderQuad(definition, renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size);
} }
if (radius_int > 20.0 && chunk_count % 64 == 0 && (double)chunk_factor < radius_int / 20.0) if (radius_int > 20.0 && chunk_count % 64 == 0 && (float)chunk_factor < radius_int / 20.0)
{ {
chunk_count /= 2; chunk_count /= 2;
chunk_factor *= 2; chunk_factor *= 2;

View file

@ -13,16 +13,16 @@ extern "C" {
typedef struct typedef struct
{ {
double height; float height;
double transparency; float transparency;
double reflection; float reflection;
SurfaceMaterial material; SurfaceMaterial material;
Color depth_color; Color depth_color;
double transparency_depth; float transparency_depth;
double lighting_depth; float lighting_depth;
NoiseGenerator* waves_noise; NoiseGenerator* waves_noise;
double waves_noise_height; float waves_noise_height;
double waves_noise_scale; float waves_noise_scale;
} WaterDefinition; } WaterDefinition;
typedef struct typedef struct

View file

@ -9,11 +9,11 @@
typedef struct typedef struct
{ {
double value; float value;
double centerx; float centerx;
double centerz; float centerz;
double softradius; float softradius;
double hardradius; float hardradius;
} Circle; } Circle;
struct Zone { struct Zone {
@ -55,41 +55,41 @@ void zoneSave(PackStream* stream, Zone* zone)
packWriteInt(stream, &zone->height_ranges_count); packWriteInt(stream, &zone->height_ranges_count);
for (i = 0; i < zone->height_ranges_count; i++) for (i = 0; i < zone->height_ranges_count; i++)
{ {
packWriteDouble(stream, &zone->height_ranges[i].value); packWriteFloat(stream, &zone->height_ranges[i].value);
packWriteDouble(stream, &zone->height_ranges[i].hardmin); packWriteFloat(stream, &zone->height_ranges[i].hardmin);
packWriteDouble(stream, &zone->height_ranges[i].softmin); packWriteFloat(stream, &zone->height_ranges[i].softmin);
packWriteDouble(stream, &zone->height_ranges[i].softmax); packWriteFloat(stream, &zone->height_ranges[i].softmax);
packWriteDouble(stream, &zone->height_ranges[i].hardmax); packWriteFloat(stream, &zone->height_ranges[i].hardmax);
} }
packWriteInt(stream, &zone->slope_ranges_count); packWriteInt(stream, &zone->slope_ranges_count);
for (i = 0; i < zone->slope_ranges_count; i++) for (i = 0; i < zone->slope_ranges_count; i++)
{ {
packWriteDouble(stream, &zone->slope_ranges[i].value); packWriteFloat(stream, &zone->slope_ranges[i].value);
packWriteDouble(stream, &zone->slope_ranges[i].hardmin); packWriteFloat(stream, &zone->slope_ranges[i].hardmin);
packWriteDouble(stream, &zone->slope_ranges[i].softmin); packWriteFloat(stream, &zone->slope_ranges[i].softmin);
packWriteDouble(stream, &zone->slope_ranges[i].softmax); packWriteFloat(stream, &zone->slope_ranges[i].softmax);
packWriteDouble(stream, &zone->slope_ranges[i].hardmax); packWriteFloat(stream, &zone->slope_ranges[i].hardmax);
} }
packWriteInt(stream, &zone->circles_included_count); packWriteInt(stream, &zone->circles_included_count);
for (i = 0; i < zone->circles_included_count; i++) for (i = 0; i < zone->circles_included_count; i++)
{ {
packWriteDouble(stream, &zone->circles_included[i].value); packWriteFloat(stream, &zone->circles_included[i].value);
packWriteDouble(stream, &zone->circles_included[i].centerx); packWriteFloat(stream, &zone->circles_included[i].centerx);
packWriteDouble(stream, &zone->circles_included[i].centerz); packWriteFloat(stream, &zone->circles_included[i].centerz);
packWriteDouble(stream, &zone->circles_included[i].softradius); packWriteFloat(stream, &zone->circles_included[i].softradius);
packWriteDouble(stream, &zone->circles_included[i].hardradius); packWriteFloat(stream, &zone->circles_included[i].hardradius);
} }
packWriteInt(stream, &zone->circles_excluded_count); packWriteInt(stream, &zone->circles_excluded_count);
for (i = 0; i < zone->circles_excluded_count; i++) for (i = 0; i < zone->circles_excluded_count; i++)
{ {
packWriteDouble(stream, &zone->circles_excluded[i].value); packWriteFloat(stream, &zone->circles_excluded[i].value);
packWriteDouble(stream, &zone->circles_excluded[i].centerx); packWriteFloat(stream, &zone->circles_excluded[i].centerx);
packWriteDouble(stream, &zone->circles_excluded[i].centerz); packWriteFloat(stream, &zone->circles_excluded[i].centerz);
packWriteDouble(stream, &zone->circles_excluded[i].softradius); packWriteFloat(stream, &zone->circles_excluded[i].softradius);
packWriteDouble(stream, &zone->circles_excluded[i].hardradius); packWriteFloat(stream, &zone->circles_excluded[i].hardradius);
} }
} }
@ -100,41 +100,41 @@ void zoneLoad(PackStream* stream, Zone* zone)
packReadInt(stream, &zone->height_ranges_count); packReadInt(stream, &zone->height_ranges_count);
for (i = 0; i < zone->height_ranges_count; i++) for (i = 0; i < zone->height_ranges_count; i++)
{ {
packReadDouble(stream, &zone->height_ranges[i].value); packReadFloat(stream, &zone->height_ranges[i].value);
packReadDouble(stream, &zone->height_ranges[i].hardmin); packReadFloat(stream, &zone->height_ranges[i].hardmin);
packReadDouble(stream, &zone->height_ranges[i].softmin); packReadFloat(stream, &zone->height_ranges[i].softmin);
packReadDouble(stream, &zone->height_ranges[i].softmax); packReadFloat(stream, &zone->height_ranges[i].softmax);
packReadDouble(stream, &zone->height_ranges[i].hardmax); packReadFloat(stream, &zone->height_ranges[i].hardmax);
} }
packReadInt(stream, &zone->slope_ranges_count); packReadInt(stream, &zone->slope_ranges_count);
for (i = 0; i < zone->slope_ranges_count; i++) for (i = 0; i < zone->slope_ranges_count; i++)
{ {
packReadDouble(stream, &zone->slope_ranges[i].value); packReadFloat(stream, &zone->slope_ranges[i].value);
packReadDouble(stream, &zone->slope_ranges[i].hardmin); packReadFloat(stream, &zone->slope_ranges[i].hardmin);
packReadDouble(stream, &zone->slope_ranges[i].softmin); packReadFloat(stream, &zone->slope_ranges[i].softmin);
packReadDouble(stream, &zone->slope_ranges[i].softmax); packReadFloat(stream, &zone->slope_ranges[i].softmax);
packReadDouble(stream, &zone->slope_ranges[i].hardmax); packReadFloat(stream, &zone->slope_ranges[i].hardmax);
} }
packReadInt(stream, &zone->circles_included_count); packReadInt(stream, &zone->circles_included_count);
for (i = 0; i < zone->circles_included_count; i++) for (i = 0; i < zone->circles_included_count; i++)
{ {
packReadDouble(stream, &zone->circles_included[i].value); packReadFloat(stream, &zone->circles_included[i].value);
packReadDouble(stream, &zone->circles_included[i].centerx); packReadFloat(stream, &zone->circles_included[i].centerx);
packReadDouble(stream, &zone->circles_included[i].centerz); packReadFloat(stream, &zone->circles_included[i].centerz);
packReadDouble(stream, &zone->circles_included[i].softradius); packReadFloat(stream, &zone->circles_included[i].softradius);
packReadDouble(stream, &zone->circles_included[i].hardradius); packReadFloat(stream, &zone->circles_included[i].hardradius);
} }
packReadInt(stream, &zone->circles_excluded_count); packReadInt(stream, &zone->circles_excluded_count);
for (i = 0; i < zone->circles_excluded_count; i++) for (i = 0; i < zone->circles_excluded_count; i++)
{ {
packReadDouble(stream, &zone->circles_excluded[i].value); packReadFloat(stream, &zone->circles_excluded[i].value);
packReadDouble(stream, &zone->circles_excluded[i].centerx); packReadFloat(stream, &zone->circles_excluded[i].centerx);
packReadDouble(stream, &zone->circles_excluded[i].centerz); packReadFloat(stream, &zone->circles_excluded[i].centerz);
packReadDouble(stream, &zone->circles_excluded[i].softradius); packReadFloat(stream, &zone->circles_excluded[i].softradius);
packReadDouble(stream, &zone->circles_excluded[i].hardradius); packReadFloat(stream, &zone->circles_excluded[i].hardradius);
} }
} }
@ -143,7 +143,7 @@ void zoneCopy(Zone* source, Zone* destination)
*destination = *source; *destination = *source;
} }
void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius) void zoneIncludeCircleArea(Zone* zone, float value, float centerx, float centerz, float softradius, float hardradius)
{ {
Circle circle = {value, centerx, centerz, softradius, hardradius}; Circle circle = {value, centerx, centerz, softradius, hardradius};
@ -153,7 +153,7 @@ void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double cent
} }
} }
void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double hardradius) void zoneExcludeCircleArea(Zone* zone, float centerx, float centerz, float softradius, float hardradius)
{ {
/* TODO */ /* TODO */
} }
@ -206,7 +206,7 @@ int zoneSetHeightRange(Zone* zone, int position, ZoneRangeCondition* range)
} }
} }
int zoneAddHeightRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax) int zoneAddHeightRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax)
{ {
ZoneRangeCondition range = {value, hardmin, softmin, softmax, hardmax}; ZoneRangeCondition range = {value, hardmin, softmin, softmax, hardmax};
int position; int position;
@ -267,7 +267,7 @@ int zoneSetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range)
} }
} }
int zoneAddSlopeRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax) int zoneAddSlopeRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax)
{ {
ZoneRangeCondition range = {value, hardmin, softmin, softmax, hardmax}; ZoneRangeCondition range = {value, hardmin, softmin, softmax, hardmax};
int position; int position;
@ -280,7 +280,7 @@ int zoneAddSlopeRangeQuick(Zone* zone, double value, double hardmin, double soft
return position; return position;
} }
static inline double _getRangeInfluence(ZoneRangeCondition range, double position) static inline float _getRangeInfluence(ZoneRangeCondition range, float position)
{ {
if (position >= range.hardmin && position <= range.hardmax) if (position >= range.hardmin && position <= range.hardmax)
{ {
@ -303,9 +303,9 @@ static inline double _getRangeInfluence(ZoneRangeCondition range, double positio
} }
} }
static inline double _getCircleInfluence(Circle circle, Vector3 position) static inline float _getCircleInfluence(Circle circle, Vector3 position)
{ {
double radius, dx, dz; float radius, dx, dz;
dx = position.x - circle.centerx; dx = position.x - circle.centerx;
dz = position.z - circle.centerz; dz = position.z - circle.centerz;
@ -325,10 +325,10 @@ static inline double _getCircleInfluence(Circle circle, Vector3 position)
} }
} }
double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal) float zoneGetValue(Zone* zone, Vector3 location, Vector3 normal)
{ {
int i; int i;
double value, value_height, value_steepness, value_circle; float value, value_height, value_steepness, value_circle;
if (zone->circles_included_count > 0) if (zone->circles_included_count > 0)
{ {

View file

@ -12,11 +12,11 @@ typedef struct Zone Zone;
typedef struct typedef struct
{ {
double value; float value;
double hardmin; float hardmin;
double softmin; float softmin;
double softmax; float softmax;
double hardmax; float hardmax;
} ZoneRangeCondition; } ZoneRangeCondition;
Zone* zoneCreate(); Zone* zoneCreate();
@ -24,22 +24,22 @@ void zoneDelete(Zone* zone);
void zoneSave(PackStream* stream, Zone* zone); void zoneSave(PackStream* stream, Zone* zone);
void zoneLoad(PackStream* stream, Zone* zone); void zoneLoad(PackStream* stream, Zone* zone);
void zoneCopy(Zone* source, Zone* destination); void zoneCopy(Zone* source, Zone* destination);
void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius); void zoneIncludeCircleArea(Zone* zone, float value, float centerx, float centerz, float softradius, float hardradius);
void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double hardradius); void zoneExcludeCircleArea(Zone* zone, float centerx, float centerz, float softradius, float hardradius);
int zoneAddHeightRange(Zone* zone); int zoneAddHeightRange(Zone* zone);
int zoneGetHeightRangeCount(Zone* zone); int zoneGetHeightRangeCount(Zone* zone);
int zoneGetHeightRange(Zone* zone, int position, ZoneRangeCondition* range); int zoneGetHeightRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneSetHeightRange(Zone* zone, int position, ZoneRangeCondition* range); int zoneSetHeightRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneAddHeightRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax); int zoneAddHeightRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax);
int zoneAddSlopeRange(Zone* zone); int zoneAddSlopeRange(Zone* zone);
int zoneGetSlopeRangeCount(Zone* zone); int zoneGetSlopeRangeCount(Zone* zone);
int zoneGetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range); int zoneGetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneSetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range); int zoneSetSlopeRange(Zone* zone, int position, ZoneRangeCondition* range);
int zoneAddSlopeRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax); int zoneAddSlopeRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax);
double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal); float zoneGetValue(Zone* zone, Vector3 location, Vector3 normal);
#ifdef __cplusplus #ifdef __cplusplus
} }