paysages : Revert to doubles instead of floats + Fixed maximum memory size for render area.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@350 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-06-17 09:40:40 +00:00 committed by ThunderK
parent 5deb2fdced
commit 203dd0ab12
78 changed files with 1073 additions and 1091 deletions

5
TODO
View file

@ -1,4 +1,9 @@
Technology Preview 2 : Technology Preview 2 :
- InputInt doesn't honor small_step.
- Improve shadow smoothness
=> Configurable smoothness factor
=> Smoothness depends on distance to hit
=> Smoothness stays the same when quality changes, but has better resolution
- Fix the fog impression when cloud layer overlaps with ground range. - Fix the fog impression when cloud layer overlaps with ground range.
- Remove color gradations (replace with automatic boolean and simple colors). - Remove color gradations (replace with automatic boolean and simple colors).
- Replace zone ranges with curves (with curve input and curve dialog). - Replace zone ranges with curves (with curve input and curve dialog).

View file

@ -27,11 +27,11 @@ void displayHelp()
printf(" -rh x Render height (int)\n"); printf(" -rh x Render height (int)\n");
printf(" -rq x Render quality (int, 1 to 10)\n"); printf(" -rq x Render quality (int, 1 to 10)\n");
printf(" -ra x Render anti-aliasing (int, 1 to 4)\n"); printf(" -ra x Render anti-aliasing (int, 1 to 4)\n");
printf(" -di x Day start time (float, 0.0 to 1.0)\n"); printf(" -di x Day start time (double, 0.0 to 1.0)\n");
printf(" -ds x Day step time (float)\n"); printf(" -ds x Day step time (double)\n");
} }
void _previewUpdate(float progress) void _previewUpdate(double 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;
float conf_daytime_start = 0.4; double conf_daytime_start = 0.4;
float conf_daytime_step = 0.0; double conf_daytime_step = 0.0;
int outputcount; int outputcount;
char outputpath[500]; char outputpath[500];

View file

@ -47,7 +47,8 @@ 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((float)i / (float)new_texture_size, 1.0 - (float)j / (float)new_texture_size); Color color = getTextureColor((double)i / (double)new_texture_size, 1.0 - (double)j / (double)new_texture_size);
colorNormalize(&color);
new_image->setPixel(i, j, colorTo32BitBGRA(&color)); new_image->setPixel(i, j, colorTo32BitBGRA(&color));
} }
} }
@ -139,12 +140,12 @@ void BaseExplorerChunk::onRenderEvent(QGLWidget* widget)
{ {
} }
float BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition* camera) double BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition* camera)
{ {
return 0.0; return 0.0;
} }
Color BaseExplorerChunk::getTextureColor(float x, float y) Color BaseExplorerChunk::getTextureColor(double x, double 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);
float priority; double 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 float getDisplayedSizeHint(CameraDefinition* camera); virtual double getDisplayedSizeHint(CameraDefinition* camera);
virtual Color getTextureColor(float x, float y); virtual Color getTextureColor(double x, double 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, float* value, float min, float max, float small_step, float large_step) void BaseForm::addInputDouble(QString label, double* value, double min, double max, double small_step, double 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, float xmin, float xmax, float ymin, float ymax) void BaseForm::addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double 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, float* value, float min, float max, float small_step, float large_step); void addInputDouble(QString label, double* value, double min, double max, double small_step, double 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, float xmin, float xmax, float ymin, float ymax); void addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double 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(float x, float y) QColor BasePreview::getColor(double x, double y)
{ {
return QColor(0, 0, 0); return QColor(0, 0, 0);
} }
void BasePreview::configScaling(float min, float max, float step, float init, bool logarithmic) void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic)
{ {
float size = (float) width(); double size = (double) width();
if (size >= 1.0) if (size >= 1.0)
{ {
@ -345,7 +345,7 @@ void BasePreview::configScaling(float min, float max, float step, float init, bo
} }
} }
void BasePreview::configScrolling(float xmin, float xmax, float xinit, float ymin, float ymax, float yinit) void BasePreview::configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double 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((float) (x - _width / 2) * scaling + xoffset, (float) (y - _height / 2) * scaling + yoffset); return getColor((double) (x - _width / 2) * scaling + xoffset, (double) (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 -= (float) ndx * scaling; xoffset -= (double) ndx * scaling;
yoffset -= (float) ndy * scaling; yoffset -= (double) 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 -= (float) ndx * scaling; xoffset -= (double) ndx * scaling;
yoffset -= (float) ndy * scaling; yoffset -= (double) 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)
{ {
float factor; double factor;
float old_scaling; double 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(((float) width) * scaling / old_scaling); new_width = (int) floor(((double) width) * scaling / old_scaling);
new_height = (int) floor(((float) height) * scaling / old_scaling); new_height = (int) floor(((double) 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(((float) width) * old_scaling / scaling), (int) floor(((float) height) * old_scaling / scaling), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QImage part = pixbuf->scaled((int) floor(((double) width) * old_scaling / scaling), (int) floor(((double) 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(float x, float y); virtual QColor getColor(double x, double y);
void configScaling(float min, float max, float step, float init, bool logarithmic = true); void configScaling(double min, double max, double step, double init, bool logarithmic = true);
void configScrolling(float xmin, float xmax, float xinit, float ymin, float ymax, float yinit); void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit);
float xoffset; double xoffset;
float yoffset; double yoffset;
float scaling; double scaling;
private: private:
void updateScaling(); void updateScaling();
@ -61,21 +61,21 @@ private:
int mousex; int mousex;
int mousey; int mousey;
float scalingbase; double scalingbase;
bool alive; bool alive;
float conf_scroll_xmin; double conf_scroll_xmin;
float conf_scroll_xmax; double conf_scroll_xmax;
float conf_scroll_xinit; double conf_scroll_xinit;
float conf_scroll_ymin; double conf_scroll_ymin;
float conf_scroll_ymax; double conf_scroll_ymax;
float conf_scroll_yinit; double conf_scroll_yinit;
float conf_scale_min; double conf_scale_min;
float conf_scale_max; double conf_scale_max;
float conf_scale_init; double conf_scale_init;
float conf_scale_step; double 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, float xmin, float xmax, float ymin, float ymax) : QDialog(parent) DialogCurve::DialogCurve(QWidget *parent, Curve* curve, double xmin, double xmax, double ymin, double 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, float xmin, float xmax, float ymin, float ymax) bool DialogCurve::getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double 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, float xmin, float xmax, float ymin, float ymax); explicit DialogCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double ymax);
~DialogCurve(); ~DialogCurve();
static bool getCurve(QWidget* parent, Curve* curve, float xmin, float xmax, float ymin, float ymax); static bool getCurve(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double 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(float x, float y) QColor getColor(double x, double 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(float x, float y) QColor getColor(double x, double 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 = ((float)value) / 1000.0; _current_level_params.height = ((double)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 = ((float)value) / 1000.0; _current_level_params.scaling = ((double)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

@ -26,7 +26,7 @@ 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(float progress) static void _renderUpdate(double progress)
{ {
_current_dialog->area->update(); _current_dialog->area->update();
_current_dialog->tellProgressChange(progress); _current_dialog->tellProgressChange(progress);
@ -98,7 +98,7 @@ DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
_info->layout()->addWidget(_progress); _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))); connect(this, SIGNAL(progressChanged(double)), this, SLOT(applyProgress(double)));
} }
DialogRender::~DialogRender() DialogRender::~DialogRender()
@ -118,7 +118,7 @@ void DialogRender::tellRenderSize(int width, int height)
emit renderSizeChanged(width, height); emit renderSizeChanged(width, height);
} }
void DialogRender::tellProgressChange(float value) void DialogRender::tellProgressChange(double value)
{ {
emit progressChanged(value); emit progressChanged(value);
} }
@ -153,7 +153,7 @@ void DialogRender::applyRenderSize(int width, int 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) void DialogRender::applyProgress(double value)
{ {
double diff = difftime(time(NULL), _started); double diff = difftime(time(NULL), _started);
int hours = (int)floor(diff / 3600.0); int hours = (int)floor(diff / 3600.0);

View file

@ -17,7 +17,7 @@ public:
~DialogRender(); ~DialogRender();
void tellRenderSize(int width, int height); void tellRenderSize(int width, int height);
void tellProgressChange(float value); void tellProgressChange(double value);
void startRender(RenderParams params); void startRender(RenderParams params);
void loadLastRender(); void loadLastRender();
@ -26,11 +26,11 @@ public:
private slots: private slots:
void applyRenderSize(int width, int height); void applyRenderSize(int width, int height);
void applyProgress(float value); void applyProgress(double value);
signals: signals:
void renderSizeChanged(int width, int height); void renderSizeChanged(int width, int height);
void progressChanged(float value); void progressChanged(double value);
private: private:
QScrollArea* _scroll; QScrollArea* _scroll;

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, float size, SkyboxOrientation orientation) : BaseExplorerChunk(renderer) ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, double 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, float
void ExplorerChunkSky::onRenderEvent(QGLWidget* widget) void ExplorerChunkSky::onRenderEvent(QGLWidget* widget)
{ {
float size = _box_size; double 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();
} }
float ExplorerChunkSky::getDisplayedSizeHint(CameraDefinition* camera) double ExplorerChunkSky::getDisplayedSizeHint(CameraDefinition* camera)
{ {
return 1000.0; return 1000.0;
} }
Color ExplorerChunkSky::getTextureColor(float x, float y) Color ExplorerChunkSky::getTextureColor(double x, double 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, float size, SkyboxOrientation orientation); ExplorerChunkSky(Renderer* renderer, SkyDefinition* sky, double size, SkyboxOrientation orientation);
void onRenderEvent(QGLWidget* widget); void onRenderEvent(QGLWidget* widget);
float getDisplayedSizeHint(CameraDefinition* camera); double getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(float x, float y); Color getTextureColor(double x, double y);
private: private:
SkyDefinition* _sky; SkyDefinition* _sky;
SkyboxOrientation _orientation; SkyboxOrientation _orientation;
float _box_size; double _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, float x, float z, float size, int nbchunks) : BaseExplorerChunk(renderer) ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks) : BaseExplorerChunk(renderer)
{ {
_startx = x; _startx = x;
_startz = z; _startz = z;
_size = size; _size = size;
_overall_step = size * (float)nbchunks; _overall_step = size * (double)nbchunks;
_tessellation_max_size = 32; _tessellation_max_size = 32;
_tessellation = new float[(_tessellation_max_size + 1) * (_tessellation_max_size + 1)]; _tessellation = new double[(_tessellation_max_size + 1) * (_tessellation_max_size + 1)];
_tessellation_current_size = 0; _tessellation_current_size = 0;
_tessellation_step = _size / (float)_tessellation_max_size; _tessellation_step = _size / (double)_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)
{ {
float height = renderer->getTerrainHeight(renderer, _startx + _tessellation_step * (float)i, _startz + _tessellation_step * (float)j); double height = renderer->getTerrainHeight(renderer, _startx + _tessellation_step * (double)i, _startz + _tessellation_step * (double)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;
float tsize = 1.0 / (float)_tessellation_max_size; double tsize = 1.0 / (double)_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 / (float)tessellation_size; int tessellation_inc = _tessellation_max_size / (double)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 * (float)i, tsize * (float)j); glTexCoord2d(tsize * (double)i, tsize * (double)j);
glVertex3d(_startx + _tessellation_step * (float)i, _tessellation[j * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (float)j); glVertex3d(_startx + _tessellation_step * (double)i, _tessellation[j * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double)j);
glTexCoord2d(tsize * (float)i, tsize * (float)(j + tessellation_inc)); glTexCoord2d(tsize * (double)i, tsize * (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)); glVertex3d(_startx + _tessellation_step * (double)i, _tessellation[(j + tessellation_inc) * (_tessellation_max_size + 1) + i], _startz + _tessellation_step * (double)(j + tessellation_inc));
} }
glEnd(); glEnd();
} }
} }
float ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera) double ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
{ {
float distance; double distance;
Vector3 center; Vector3 center;
center = getCenter(); center = getCenter();
@ -140,7 +140,7 @@ float ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
} }
} }
Color ExplorerChunkTerrain::getTextureColor(float x, float y) Color ExplorerChunkTerrain::getTextureColor(double x, double 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, float x, float z, float size, int nbchunks); ExplorerChunkTerrain(Renderer* renderer, double x, double z, double 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);
float getDisplayedSizeHint(CameraDefinition* camera); double getDisplayedSizeHint(CameraDefinition* camera);
Color getTextureColor(float x, float y); Color getTextureColor(double x, double y);
private: private:
Vector3 getCenter(); Vector3 getCenter();
float _startx; double _startx;
float _startz; double _startz;
float _size; double _size;
float _overall_step; double _overall_step;
float* _tessellation; double* _tessellation;
int _tessellation_max_size; int _tessellation_max_size;
int _tessellation_current_size; int _tessellation_current_size;
float _tessellation_step; double _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(float x, float y) QColor getColor(double x, double 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(float x, float y) QColor getColor(double x, double 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(float x, float y) QColor getColor(double x, double 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 float _coverageFunc(CloudsLayerDefinition* layer, Vector3 position) static double _coverageFunc(CloudsLayerDefinition* layer, Vector3 position)
{ {
float dist = v3Norm(position); double 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(float x, float y) QColor getColor(double x, double y)
{ {
Vector3 down = {0.0, -1.0, 0.0}; Vector3 down = {0.0, -1.0, 0.0};
Vector3 location; Vector3 location;
float height = terrainGetHeight(&_terrain, x, y); double 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 float _getTerrainHeight(Renderer* renderer, float x, float z) static double _getTerrainHeight(Renderer* renderer, double x, double z)
{ {
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision) static Color _applyTextures(Renderer* renderer, Vector3 location, double 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(float x, float y) QColor getColor(double x, double 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(float x, float y) QColor getColor(double x, double 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(float x, float y) QColor getColor(double x, double y)
{ {
float height; double 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(float x, float y) QColor getColor(double x, double 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 float _getTerrainHeight(Renderer* renderer, float x, float z) static double _getTerrainHeight(Renderer* renderer, double x, double z)
{ {
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision) static Color _applyTextures(Renderer* renderer, Vector3 location, double 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
{ {
float height_soft_min; double height_soft_min;
float height_hard_min; double height_hard_min;
float height_hard_max; double height_hard_max;
float height_soft_max; double height_soft_max;
float slope_soft_min; double slope_soft_min;
float slope_hard_min; double slope_hard_min;
float slope_hard_max; double slope_hard_max;
float slope_soft_max; double 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(float x, float y) QColor getColor(double x, double y)
{ {
Vector3 location; Vector3 location;
float coverage; double 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 float _getTerrainHeight(Renderer* renderer, float x, float z) static double _getTerrainHeight(Renderer* renderer, double x, double 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(float x, float y) QColor getColor(double x, double 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(float x, float y) QColor getColor(double x, double y)
{ {
float height; double 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(float x, float y) QColor getColor(double x, double 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;
float x, y; double 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, float xmin, float xmax, float ymin, float ymax) : QWidget(parent) CurveSmallPreview(QWidget* parent, Curve* curve, double xmin, double xmax, double ymin, double 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();
float position, value, prev_value, next_value; double 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) * (float)x / (float)(width - 1); position = _xmin + (_xmax - _xmin) * (double)x / (double)(width - 1);
value = (curveGetValue(_curve, position) - _ymin) * (_ymax - _ymin); value = (curveGetValue(_curve, position) - _ymin) * (_ymax - _ymin);
prev_value = curveGetValue(_curve, position - 1.0 / (float)(width - 1)); prev_value = curveGetValue(_curve, position - 1.0 / (double)(width - 1));
next_value = curveGetValue(_curve, position + 1.0 / (float)(width - 1)); next_value = curveGetValue(_curve, position + 1.0 / (double)(width - 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.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.drawPoint(x, height - 1 - (int)(value * (float)(height - 1))); painter.drawPoint(x, height - 1 - (int)(value * (double)(height - 1)));
} }
} }
Curve* _curve; Curve* _curve;
float _xmin; double _xmin;
float _xmax; double _xmax;
float _ymin; double _ymin;
float _ymax; double _ymax;
}; };
InputCurve::InputCurve(QWidget* form, QString label, Curve* value, float xmin, float xmax, float ymin, float ymax) : BaseInput(form, label) InputCurve::InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double 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, float xmin, float xmax, float ymin, float ymax); InputCurve(QWidget* form, QString label, Curve* value, double xmin, double xmax, double ymin, double ymax);
public slots: public slots:
virtual void updatePreview(); virtual void updatePreview();
@ -23,10 +23,10 @@ private slots:
private: private:
Curve* _value; Curve* _value;
float _xmin; double _xmin;
float _xmax; double _xmax;
float _ymin; double _ymin;
float _ymax; double _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, float* value, float min, float max, float small_step, float large_step): InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double 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 + ((float)ivalue) * small_step; *value = min + ((double)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, float* value, float min, float max, float small_step, float large_step); InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step);
public slots: public slots:
virtual void updatePreview(); virtual void updatePreview();
@ -19,11 +19,11 @@ public slots:
private: private:
QSlider* slider; QSlider* slider;
float* value; double* value;
float min; double min;
float max; double max;
float small_step; double small_step;
float large_step; double 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();
float value, factor; double value, factor;
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
factor = ((float)(height / 2)) / noiseGetMaxValue(noise); factor = ((double)(height / 2)) / noiseGetMaxValue(noise);
value = noiseGet1DTotal(noise, ((float)x) / factor) * factor; value = noiseGet1DTotal(noise, ((double)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, (float)x / (float)width), 0.0, 0.0)); painter.setPen(QColor::fromRgbF(curveGetValue(curve, (double)x / (double)width), 0.0, 0.0));
break; break;
case COLORGRADATIONBAND_GREEN: case COLORGRADATIONBAND_GREEN:
painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (float)x / (float)width), 0.0)); painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (double)x / (double)width), 0.0));
break; break;
case COLORGRADATIONBAND_BLUE: case COLORGRADATIONBAND_BLUE:
painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (float)x / (float)width))); painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (double)x / (double)width)));
break; break;
case COLORGRADATIONBAND_FINAL: case COLORGRADATIONBAND_FINAL:
painter.setPen(colorToQColor(colorGradationGet(gradation, (float)x / (float)width))); painter.setPen(colorToQColor(colorGradationGet(gradation, (double)x / (double)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(float x, float y) QColor SmallMaterialPreview::getColor(double x, double y)
{ {
float dist = sqrt(x * x + y * y); double 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();
float factor, dx, dy; double factor, dx, dy;
if (width > height) if (width > height)
{ {
factor = 2.0 / (float)height; factor = 2.0 / (double)height;
} }
else else
{ {
factor = 2.0 / (float)width; factor = 2.0 / (double)width;
} }
dx = factor * (float)width / 2.0; dx = factor * (double)width / 2.0;
dy = factor * (float)height / 2.0; dy = factor * (double)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((float)x * factor - dx, (float)y * factor - dy)); painter.setPen(getColor((double)x * factor - dx, (double)y * factor - dy));
painter.drawPoint(x, y); painter.drawPoint(x, y);
} }
} }
@ -115,7 +115,7 @@ PreviewMaterial::~PreviewMaterial()
delete _small; delete _small;
} }
QColor PreviewMaterial::getColor(float x, float y) QColor PreviewMaterial::getColor(double x, double 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(float x, float y); QColor getColor(double x, double 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(float x, float y); virtual QColor getColor(double x, double 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, float xmin, float xmax, float ymin, float ymax) : QWidget(parent) WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax, double ymin, double 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;
float dwidth, dheight; double dwidth, dheight;
CurvePoint point; CurvePoint point;
float position, value, prev_value, next_value; double position, value, prev_value, next_value;
width = this->width(); width = this->width();
height = this->height(); height = this->height();
dheight = (float)(height - 1); dheight = (double)(height - 1);
dwidth = (float)(width - 1); dwidth = (double)(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 = ((float)x) / dwidth; position = ((double)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 = ((float)event->x()) / (float)(width() - 1); point.position = ((double)event->x()) / (double)(width() - 1);
point.value = 1.0 - ((float)event->y()) / (float)(height() - 1); point.value = 1.0 - ((double)event->y()) / (double)(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 = ((float)event->x()) / (float)(width() - 1); point.position = ((double)event->x()) / (double)(width() - 1);
point.value = 1.0 - ((float)event->y()) / (float)(height() - 1); point.value = 1.0 - ((double)event->y()) / (double)(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;
float distance, ndistance; double distance, ndistance;
CurvePoint point; CurvePoint point;
float dx = ((float)x) / (float)(width() - 1); double dx = ((double)x) / (double)(width() - 1);
float dy = 1.0 - ((float)y) / (float)(height() - 1); double dy = 1.0 - ((double)y) / (double)(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, float xmin, float xmax, float ymin, float ymax); WidgetCurveEditor(QWidget* parent, double xmin, double xmax, double ymin, double 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 float _getTerrainHeight(Renderer* renderer, float x, float z) static double _getTerrainHeight(Renderer* renderer, double x, double z)
{ {
return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z); return terrainGetHeight((TerrainDefinition*)(renderer->customData[0]), x, z);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision) static Color _applyTextures(Renderer* renderer, Vector3 location, double 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;
float size = 200.0; double size = 200.0;
float chunksize = size / (float)chunks; double chunksize = size / (double)chunks;
float start = -size / 2.0; double 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 * (float)i, start + chunksize * (float)j, chunksize, chunks); ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(&_renderer, start + chunksize * (double)i, start + chunksize * (double)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)
{ {
float factor; double 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)
{ {
float factor; double 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, (float)(event->x() - _last_mouse_x) * factor * 0.1); cameraRotateYaw(&_current_camera, (double)(event->x() - _last_mouse_x) * factor * 0.1);
cameraRotatePitch(&_current_camera, (float)(event->y() - _last_mouse_y) * factor * 0.1); cameraRotatePitch(&_current_camera, (double)(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, (float)(_last_mouse_x - event->x()) * factor); cameraStrafeRight(&_current_camera, (double)(_last_mouse_x - event->x()) * factor);
cameraStrafeUp(&_current_camera, (float)(event->y() - _last_mouse_y) * factor); cameraStrafeUp(&_current_camera, (double)(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)
{ {
float factor; double 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, (float)event->delta() * factor); cameraStrafeForward(&_current_camera, (double)event->delta() * factor);
updateGL(); updateGL();
} }
@ -413,7 +413,7 @@ void WidgetExplorer::paintGL()
{ {
GLenum error_code; GLenum error_code;
QTime start_time; QTime start_time;
float frame_time; double 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 * (float)start_time.msecsTo(QTime::currentTime()); frame_time = 0.001 * (double)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;
float _average_frame_time; double _average_frame_time;
int _quality; int _quality;
int _last_mouse_x; int _last_mouse_x;

View file

@ -15,18 +15,18 @@ void atmosphereQuit()
void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition) void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition)
{ {
packWriteFloat(stream, &definition->distance_near); packWriteDouble(stream, &definition->distance_near);
packWriteFloat(stream, &definition->distance_far); packWriteDouble(stream, &definition->distance_far);
packWriteFloat(stream, &definition->full_mask); packWriteDouble(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)
{ {
packReadFloat(stream, &definition->distance_near); packReadDouble(stream, &definition->distance_near);
packReadFloat(stream, &definition->distance_far); packReadDouble(stream, &definition->distance_far);
packReadFloat(stream, &definition->full_mask); packReadDouble(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;
float distance = v3Norm(v3Sub(renderer->camera_location, location)); double distance = v3Norm(v3Sub(renderer->camera_location, location));
float value; double value;
if (distance < definition->distance_near) if (distance < definition->distance_near)
{ {

View file

@ -12,9 +12,9 @@ extern "C" {
typedef struct typedef struct
{ {
float distance_near; double distance_near;
float distance_far; double distance_far;
float full_mask; double 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((float)hour / 24.0 + (float)minute / 1440.0); autoSetDaytimeFraction((double)hour / 24.0 + (double)minute / 1440.0);
} }
void autoSetDaytimeFraction(float daytime) void autoSetDaytimeFraction(double 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(float daytime); void autoSetDaytimeFraction(double 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);
packWriteFloat(stream, &camera->yaw); packWriteDouble(stream, &camera->yaw);
packWriteFloat(stream, &camera->pitch); packWriteDouble(stream, &camera->pitch);
packWriteFloat(stream, &camera->roll); packWriteDouble(stream, &camera->roll);
} }
void cameraLoad(PackStream* stream, CameraDefinition* camera) void cameraLoad(PackStream* stream, CameraDefinition* camera)
{ {
v3Load(stream, &camera->location); v3Load(stream, &camera->location);
packReadFloat(stream, &camera->yaw); packReadDouble(stream, &camera->yaw);
packReadFloat(stream, &camera->pitch); packReadDouble(stream, &camera->pitch);
packReadFloat(stream, &camera->roll); packReadDouble(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;
float water_height, terrain_height, diff; double 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, float x, float y, float z) void cameraSetLocation(CameraDefinition* camera, double x, double y, double 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, float x, float y, float z)
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraSetTarget(CameraDefinition* camera, float x, float y, float z) void cameraSetTarget(CameraDefinition* camera, double x, double y, double z)
{ {
Vector3 forward, target; Vector3 forward, target;
@ -172,49 +172,49 @@ void cameraSetTarget(CameraDefinition* camera, float x, float y, float z)
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraSetRoll(CameraDefinition* camera, float angle) void cameraSetRoll(CameraDefinition* camera, double angle)
{ {
camera->roll = angle; camera->roll = angle;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraStrafeForward(CameraDefinition* camera, float value) void cameraStrafeForward(CameraDefinition* camera, double 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, float value) void cameraStrafeRight(CameraDefinition* camera, double 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, float value) void cameraStrafeUp(CameraDefinition* camera, double 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, float value) void cameraRotateYaw(CameraDefinition* camera, double value)
{ {
camera->yaw += value; camera->yaw += value;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraRotatePitch(CameraDefinition* camera, float value) void cameraRotatePitch(CameraDefinition* camera, double value)
{ {
camera->pitch += value; camera->pitch += value;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
} }
void cameraRotateRoll(CameraDefinition* camera, float value) void cameraRotateRoll(CameraDefinition* camera, double value)
{ {
camera->roll += value; camera->roll += value;
@ -223,8 +223,8 @@ void cameraRotateRoll(CameraDefinition* camera, float value)
void cameraSetRenderSize(CameraDefinition* camera, int width, int height) void cameraSetRenderSize(CameraDefinition* camera, int width, int height)
{ {
camera->width = (float)width; camera->width = (double)width;
camera->height = (float)height; camera->height = (double)height;
camera->xratio = camera->width / camera->height; camera->xratio = camera->width / camera->height;
cameraValidateDefinition(camera, 0); cameraValidateDefinition(camera, 0);
@ -250,15 +250,6 @@ Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 po
return m4Transform(camera->unproject, point); return m4Transform(camera->unproject, point);
} }
void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float x, float y, float z, RenderFragment* result)
{
Vector3 point = {x, y, z};
point = cameraProject(camera, renderer, point);
result->x = lround(point.x);
result->y = lround(point.y);
result->z = point.z;
}
/** /**
* Render a quad that will fill the view in front of the camera. * Render a quad that will fill the view in front of the camera.
* This quad can be used for post-processing. * This quad can be used for post-processing.
@ -279,20 +270,20 @@ void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float
v1.callback = callback; v1.callback = callback;
v.x = 0.0; v.x = 0.0;
v.y = (float)render_height; v.y = (double)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 = (float)render_width; v.x = (double)render_width;
v.y = (float)render_height; v.y = (double)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 = (float)render_width; v.x = (double)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 +293,7 @@ void cameraProjectToFragment(CameraDefinition* camera, Renderer* renderer, float
renderPushQuad(&v1, &v2, &v3, &v4); renderPushQuad(&v1, &v2, &v3, &v4);
}*/ }*/
static inline void _updateBox(Vector3* point, float* xmin, float* xmax, float* ymin, float* ymax, float* zmax) static inline void _updateBox(Vector3* point, double* xmin, double* xmax, double* ymin, double* ymax, double* zmax)
{ {
*xmin = MIN(*xmin, point->x); *xmin = MIN(*xmin, point->x);
*xmax = MAX(*xmax, point->x); *xmax = MAX(*xmax, point->x);
@ -311,10 +302,10 @@ static inline void _updateBox(Vector3* point, float* xmin, float* xmax, float* y
*zmax = MAX(*zmax, point->z); *zmax = MAX(*zmax, point->z);
} }
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, float xsize, float ysize, float zsize) int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize)
{ {
Vector3 projected; Vector3 projected;
float xmin, xmax, ymin, ymax, zmax; double 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,23 @@ 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, float x, float y, float z); void cameraSetLocation(CameraDefinition* camera, double x, double y, double z);
void cameraSetTarget(CameraDefinition* camera, float x, float y, float z); void cameraSetTarget(CameraDefinition* camera, double x, double y, double z);
void cameraSetRoll(CameraDefinition* camera, float angle); void cameraSetRoll(CameraDefinition* camera, double angle);
void cameraStrafeForward(CameraDefinition* camera, float value); void cameraStrafeForward(CameraDefinition* camera, double value);
void cameraStrafeRight(CameraDefinition* camera, float value); void cameraStrafeRight(CameraDefinition* camera, double value);
void cameraStrafeUp(CameraDefinition* camera, float value); void cameraStrafeUp(CameraDefinition* camera, double value);
void cameraRotateYaw(CameraDefinition* camera, float value); void cameraRotateYaw(CameraDefinition* camera, double value);
void cameraRotatePitch(CameraDefinition* camera, float value); void cameraRotatePitch(CameraDefinition* camera, double value);
void cameraRotateRoll(CameraDefinition* camera, float value); void cameraRotateRoll(CameraDefinition* camera, double 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, 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, float xsize, float ysize, float zsize); int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -13,7 +13,7 @@ typedef struct
{ {
Vector3 start; Vector3 start;
Vector3 end; Vector3 end;
float length; double 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;
packWriteFloat(stream, &layer->ymin); packWriteDouble(stream, &layer->ymin);
packWriteFloat(stream, &layer->ymax); packWriteDouble(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);
packWriteFloat(stream, &layer->hardness); packWriteDouble(stream, &layer->hardness);
packWriteFloat(stream, &layer->transparencydepth); packWriteDouble(stream, &layer->transparencydepth);
packWriteFloat(stream, &layer->lighttraversal); packWriteDouble(stream, &layer->lighttraversal);
packWriteFloat(stream, &layer->minimumlight); packWriteDouble(stream, &layer->minimumlight);
packWriteFloat(stream, &layer->shape_scaling); packWriteDouble(stream, &layer->shape_scaling);
packWriteFloat(stream, &layer->edge_scaling); packWriteDouble(stream, &layer->edge_scaling);
packWriteFloat(stream, &layer->edge_length); packWriteDouble(stream, &layer->edge_length);
packWriteFloat(stream, &layer->base_coverage); packWriteDouble(stream, &layer->base_coverage);
} }
} }
@ -71,20 +71,20 @@ void cloudsLoad(PackStream* stream, CloudsDefinition* definition)
{ {
layer = definition->layers + cloudsAddLayer(definition); layer = definition->layers + cloudsAddLayer(definition);
packReadFloat(stream, &layer->ymin); packReadDouble(stream, &layer->ymin);
packReadFloat(stream, &layer->ymax); packReadDouble(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);
packReadFloat(stream, &layer->hardness); packReadDouble(stream, &layer->hardness);
packReadFloat(stream, &layer->transparencydepth); packReadDouble(stream, &layer->transparencydepth);
packReadFloat(stream, &layer->lighttraversal); packReadDouble(stream, &layer->lighttraversal);
packReadFloat(stream, &layer->minimumlight); packReadDouble(stream, &layer->minimumlight);
packReadFloat(stream, &layer->shape_scaling); packReadDouble(stream, &layer->shape_scaling);
packReadFloat(stream, &layer->edge_scaling); packReadDouble(stream, &layer->edge_scaling);
packReadFloat(stream, &layer->edge_length); packReadDouble(stream, &layer->edge_length);
packReadFloat(stream, &layer->base_coverage); packReadDouble(stream, &layer->base_coverage);
} }
} }
@ -130,7 +130,7 @@ void cloudsValidateDefinition(CloudsDefinition* definition)
} }
} }
static float _standardCoverageFunc(CloudsLayerDefinition* layer, Vector3 position) static double _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 float _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position) static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position)
{ {
float density, coverage, val; double 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 float _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 p
} }
} }
static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, float detail) static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, double detail)
{ {
Vector3 result = {0.0, 0.0, 0.0}; Vector3 result = {0.0, 0.0, 0.0};
Vector3 dposition; Vector3 dposition;
float val, dval; double 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, float detail, int max_segments, float max_inside_length, float max_total_length, float* inside_length, float* total_length, CloudSegment* out_segments) 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)
{ {
int inside, segment_count; int inside, segment_count;
float current_total_length, current_inside_length; double current_total_length, current_inside_length;
float step_length, segment_length, remaining_length; double step_length, segment_length, remaining_length;
float noise_distance, last_noise_distance; double noise_distance, last_noise_distance;
Vector3 walker, step, segment_start; Vector3 walker, step, segment_start;
float render_precision; double render_precision;
if (max_segments <= 0) if (max_segments <= 0)
{ {
return 0; return 0;
} }
render_precision = 15.2 - 1.5 * (float)renderer->render_quality; render_precision = 15.2 - 1.5 * (double)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, float detail) static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 position, double 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;
float max_length, detail, total_length, inside_length; double 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)
{ {
float inside_depth, total_depth, factor; double 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 float (*CloudCoverageFunc)(CloudsLayerDefinition* definition, Vector3 position); typedef double (*CloudCoverageFunc)(CloudsLayerDefinition* definition, Vector3 position);
struct CloudsLayerDefinition struct CloudsLayerDefinition
{ {
float ymin; double ymin;
float ymax; double ymax;
float base_coverage; double base_coverage;
Curve* coverage_by_altitude; Curve* coverage_by_altitude;
NoiseGenerator* shape_noise; NoiseGenerator* shape_noise;
float shape_scaling; double shape_scaling;
NoiseGenerator* edge_noise; NoiseGenerator* edge_noise;
float edge_scaling; double edge_scaling;
float edge_length; double edge_length;
SurfaceMaterial material; SurfaceMaterial material;
float hardness; double hardness;
float transparencydepth; double transparencydepth;
float lighttraversal; double lighttraversal;
float minimumlight; double 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)
{ {
packWriteFloat(stream, &col->r); packWriteDouble(stream, &col->r);
packWriteFloat(stream, &col->g); packWriteDouble(stream, &col->g);
packWriteFloat(stream, &col->b); packWriteDouble(stream, &col->b);
packWriteFloat(stream, &col->a); packWriteDouble(stream, &col->a);
} }
void colorLoad(PackStream* stream, Color* col) void colorLoad(PackStream* stream, Color* col)
{ {
packReadFloat(stream, &col->r); packReadDouble(stream, &col->r);
packReadFloat(stream, &col->g); packReadDouble(stream, &col->g);
packReadFloat(stream, &col->b); packReadDouble(stream, &col->b);
packReadFloat(stream, &col->a); packReadDouble(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)
{ {
float new_a; double 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;
/*float mask_weight = mask->a; /*double mask_weight = mask->a;
float base_weight = 1.0 - mask_weight; double 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);*/
} }
float colorNormalize(Color* col) double colorNormalize(Color* col)
{ {
float max = colorGetValue(col); double 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 @@ float colorNormalize(Color* col)
return max; return max;
} }
float colorGetValue(Color* col) double colorGetValue(Color* col)
{ {
float max; double 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, float value, Color* col) void colorGradationQuickAdd(ColorGradation* gradation, double 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, float value, float r, float g, float b) void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r, double g, double 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, float value, float r,
curveValidate(gradation->blue); curveValidate(gradation->blue);
} }
Color colorGradationGet(ColorGradation* gradation, float value) Color colorGradationGet(ColorGradation* gradation, double value)
{ {
Color result; Color result;

View file

@ -9,10 +9,10 @@ extern "C" {
typedef struct typedef struct
{ {
float r; double r;
float g; double g;
float b; double b;
float a; double 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);
float colorNormalize(Color* col); double colorNormalize(Color* col);
float colorGetValue(Color* col); double 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, float value, Color* col); void colorGradationQuickAdd(ColorGradation* gradation, double value, Color* col);
void colorGradationQuickAddRgb(ColorGradation* gradation, float value, float r, float g, float b); void colorGradationQuickAddRgb(ColorGradation* gradation, double value, double r, double g, double b);
Color colorGradationGet(ColorGradation* gradation, float value); Color colorGradationGet(ColorGradation* gradation, double 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++)
{ {
packWriteFloat(stream, &curve->points[i].position); packWriteDouble(stream, &curve->points[i].position);
packWriteFloat(stream, &curve->points[i].value); packWriteDouble(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++)
{ {
packReadFloat(stream, &curve->points[i].position); packReadDouble(stream, &curve->points[i].position);
packReadFloat(stream, &curve->points[i].value); packReadDouble(stream, &curve->points[i].value);
} }
} }
@ -74,7 +74,7 @@ int curveAddPoint(Curve* curve, CurvePoint* point)
} }
} }
int curveQuickAddPoint(Curve* curve, float position, float value) int curveQuickAddPoint(Curve* curve, double position, double value)
{ {
CurvePoint point; CurvePoint point;
@ -137,10 +137,10 @@ void curveValidate(Curve* curve)
} }
} }
float curveGetValue(Curve* curve, float position) double curveGetValue(Curve* curve, double position)
{ {
int i; int i;
float fact; double fact;
if (curve->nbpoints == 0) if (curve->nbpoints == 0)
{ {

View file

@ -8,8 +8,8 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
float position; double position;
float value; double 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, float position, float value); int curveQuickAddPoint(Curve* curve, double position, double 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);
float curveGetValue(Curve* curve, float position); double curveGetValue(Curve* curve, double 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)
{ {
packWriteFloat(stream, &v->x); packWriteDouble(stream, &v->x);
packWriteFloat(stream, &v->y); packWriteDouble(stream, &v->y);
packWriteFloat(stream, &v->z); packWriteDouble(stream, &v->z);
} }
void v3Load(PackStream* stream, Vector3* v) void v3Load(PackStream* stream, Vector3* v)
{ {
packReadFloat(stream, &v->x); packReadDouble(stream, &v->x);
packReadFloat(stream, &v->y); packReadDouble(stream, &v->y);
packReadFloat(stream, &v->z); packReadDouble(stream, &v->z);
} }
Vector3 v3Translate(Vector3 v1, float x, float y, float z) Vector3 v3Translate(Vector3 v1, double x, double y, double 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, float scale) Vector3 v3Scale(Vector3 v, double scale)
{ {
Vector3 result; Vector3 result;
result.x = v.x * scale; result.x = v.x * scale;
@ -65,14 +65,14 @@ Vector3 v3Scale(Vector3 v, float scale)
return result; return result;
} }
float v3Norm(Vector3 v) double 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)
{ {
float norm = v3Norm(v); double 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)
} }
} }
float v3Dot(Vector3 v1, Vector3 v2) double 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)
{ {
packWriteFloat(stream, &m->a); packWriteDouble(stream, &m->a);
packWriteFloat(stream, &m->b); packWriteDouble(stream, &m->b);
packWriteFloat(stream, &m->c); packWriteDouble(stream, &m->c);
packWriteFloat(stream, &m->d); packWriteDouble(stream, &m->d);
packWriteFloat(stream, &m->e); packWriteDouble(stream, &m->e);
packWriteFloat(stream, &m->f); packWriteDouble(stream, &m->f);
packWriteFloat(stream, &m->g); packWriteDouble(stream, &m->g);
packWriteFloat(stream, &m->h); packWriteDouble(stream, &m->h);
packWriteFloat(stream, &m->i); packWriteDouble(stream, &m->i);
packWriteFloat(stream, &m->j); packWriteDouble(stream, &m->j);
packWriteFloat(stream, &m->k); packWriteDouble(stream, &m->k);
packWriteFloat(stream, &m->l); packWriteDouble(stream, &m->l);
packWriteFloat(stream, &m->m); packWriteDouble(stream, &m->m);
packWriteFloat(stream, &m->n); packWriteDouble(stream, &m->n);
packWriteFloat(stream, &m->o); packWriteDouble(stream, &m->o);
packWriteFloat(stream, &m->p); packWriteDouble(stream, &m->p);
} }
void m4Load(PackStream* stream, Matrix4* m) void m4Load(PackStream* stream, Matrix4* m)
{ {
packReadFloat(stream, &m->a); packReadDouble(stream, &m->a);
packReadFloat(stream, &m->b); packReadDouble(stream, &m->b);
packReadFloat(stream, &m->c); packReadDouble(stream, &m->c);
packReadFloat(stream, &m->d); packReadDouble(stream, &m->d);
packReadFloat(stream, &m->e); packReadDouble(stream, &m->e);
packReadFloat(stream, &m->f); packReadDouble(stream, &m->f);
packReadFloat(stream, &m->g); packReadDouble(stream, &m->g);
packReadFloat(stream, &m->h); packReadDouble(stream, &m->h);
packReadFloat(stream, &m->i); packReadDouble(stream, &m->i);
packReadFloat(stream, &m->j); packReadDouble(stream, &m->j);
packReadFloat(stream, &m->k); packReadDouble(stream, &m->k);
packReadFloat(stream, &m->l); packReadDouble(stream, &m->l);
packReadFloat(stream, &m->m); packReadDouble(stream, &m->m);
packReadFloat(stream, &m->n); packReadDouble(stream, &m->n);
packReadFloat(stream, &m->o); packReadDouble(stream, &m->o);
packReadFloat(stream, &m->p); packReadDouble(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;
float w; double 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(float x, float y, float z) Matrix4 m4NewScale(double x, double y, double z)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
result.a = x; result.a = x;
@ -225,7 +225,7 @@ Matrix4 m4NewScale(float x, float y, float z)
return result; return result;
} }
Matrix4 m4NewTranslate(float x, float y, float z) Matrix4 m4NewTranslate(double x, double y, double z)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
result.d = x; result.d = x;
@ -234,45 +234,45 @@ Matrix4 m4NewTranslate(float x, float y, float z)
return result; return result;
} }
Matrix4 m4NewRotateX(float angle) Matrix4 m4NewRotateX(double angle)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
float s = sin(angle); double s = sin(angle);
float c = cos(angle); double 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(float angle) Matrix4 m4NewRotateY(double angle)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
float s = sin(angle); double s = sin(angle);
float c = cos(angle); double 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(float angle) Matrix4 m4NewRotateZ(double angle)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
float s = sin(angle); double s = sin(angle);
float c = cos(angle); double 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(float angle, Vector3 axis) Matrix4 m4NewRotateAxis(double angle, Vector3 axis)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
float s = sin(angle); double s = sin(angle);
float c = cos(angle); double c = cos(angle);
float c1 = 1.0 - c; double 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(float angle, Vector3 axis)
return result; return result;
} }
Matrix4 m4NewRotateEuler(float heading, float attitude, float bank) Matrix4 m4NewRotateEuler(double heading, double attitude, double bank)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
float ch = cos(heading); double ch = cos(heading);
float sh = sin(heading); double sh = sin(heading);
float ca = cos(attitude); double ca = cos(attitude);
float sa = sin(attitude); double sa = sin(attitude);
float cb = cos(bank); double cb = cos(bank);
float sb = sin(bank); double 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(float fov_y, float aspect, float near, float far) Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far)
{ {
Matrix4 result = m4NewIdentity(); Matrix4 result = m4NewIdentity();
float f = 1 / tan(fov_y / 2.0); double 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(float fov_y, float aspect, float near, float far)
return result; return result;
} }
float m4Determinant(Matrix4 m) double 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 @@ float m4Determinant(Matrix4 m)
Matrix4 m4Inverse(Matrix4 m) Matrix4 m4Inverse(Matrix4 m)
{ {
Matrix4 result; Matrix4 result;
float d = m4Determinant(m); double 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
{ {
float x; double x;
float y; double y;
float z; double z;
} Vector3; } Vector3;
typedef struct typedef struct
{ {
float a; double a;
float b; double b;
float c; double c;
float d; double d;
float e; double e;
float f; double f;
float g; double g;
float h; double h;
float i; double i;
float j; double j;
float k; double k;
float l; double l;
float m; double m;
float n; double n;
float o; double o;
float p; double 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, float x, float y, float z); Vector3 v3Translate(Vector3 v1, double x, double y, double 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, float scale); Vector3 v3Scale(Vector3 v, double scale);
float v3Norm(Vector3 v); double v3Norm(Vector3 v);
Vector3 v3Normalize(Vector3 v); Vector3 v3Normalize(Vector3 v);
float v3Dot(Vector3 v1, Vector3 v2); double 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(float x, float y, float z); Matrix4 m4NewScale(double x, double y, double z);
Matrix4 m4NewTranslate(float x, float y, float z); Matrix4 m4NewTranslate(double x, double y, double z);
Matrix4 m4NewRotateX(float angle); Matrix4 m4NewRotateX(double angle);
Matrix4 m4NewRotateY(float angle); Matrix4 m4NewRotateY(double angle);
Matrix4 m4NewRotateZ(float angle); Matrix4 m4NewRotateZ(double angle);
Matrix4 m4NewRotateAxis(float angle, Vector3 axis); Matrix4 m4NewRotateAxis(double angle, Vector3 axis);
Matrix4 m4NewRotateEuler(float heading, float attitude, float bank); Matrix4 m4NewRotateEuler(double heading, double attitude, double 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(float fov_y, float aspect, float near, float far); Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far);
float m4Determinant(Matrix4 m); double 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);
packWriteFloat(stream, &definition->lights[i].reflection); packWriteDouble(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);
packWriteFloat(stream, &definition->lights[i].amplitude); packWriteDouble(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);
packReadFloat(stream, &definition->lights[i].reflection); packReadDouble(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);
packReadFloat(stream, &definition->lights[i].amplitude); packReadDouble(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;
float diffuse, specular, normal_norm; double 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;
float xstep, ystep, factor; double 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 / (float)samples; factor = 1.0 / (double)samples;
xstep = M_PI * 2.0 / (float)xsamples; xstep = M_PI * 2.0 / (double)xsamples;
ystep = M_PI * 0.5 / (float)(ysamples - 1); ystep = M_PI * 0.5 / (double)(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 */
float reflection; /* Reflected factor of the light (for specular lighting) */ double 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..) */
float amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */ double amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */
}; };
typedef struct typedef struct

View file

@ -38,7 +38,7 @@ void paysagesInit()
autoSetDaytime(8, 30); autoSetDaytime(8, 30);
// DEBUG // DEBUG
/*float last_height, height, x; /*double 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);
float app_header, version_header; double app_header, version_header;
if (!stream) if (!stream)
{ {
return FILE_OPERATION_IOERROR; return FILE_OPERATION_IOERROR;
} }
app_header = (float)APP_HEADER; app_header = (double)APP_HEADER;
packWriteFloat(stream, &app_header); packWriteDouble(stream, &app_header);
version_header = (float)PAYSAGES_CURRENT_DATA_VERSION; version_header = (double)PAYSAGES_CURRENT_DATA_VERSION;
packWriteFloat(stream, &version_header); packWriteDouble(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);
float app_header, version_header; double app_header, version_header;
if (!stream) if (!stream)
{ {
return FILE_OPERATION_IOERROR; return FILE_OPERATION_IOERROR;
} }
packReadFloat(stream, &app_header); packReadDouble(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;
} }
packReadFloat(stream, &version_header); packReadDouble(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;
float value; double 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);
packWriteFloat(stream, &modifier->value); packWriteDouble(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);
packReadFloat(stream, &modifier->value); packReadDouble(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, float value) void modifierActionAddValue(HeightModifier* modifier, double value)
{ {
modifier->mode = MODE_ADD_VALUE; modifier->mode = MODE_ADD_VALUE;
modifier->value = value; modifier->value = value;
} }
void modifierActionFixValue(HeightModifier* modifier, float value) void modifierActionFixValue(HeightModifier* modifier, double 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, float value)
Vector3 modifierApply(HeightModifier* modifier, Vector3 location) Vector3 modifierApply(HeightModifier* modifier, Vector3 location)
{ {
float influence, diff; double 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, float value); void modifierActionAddValue(HeightModifier* modifier, double value);
void modifierActionFixValue(HeightModifier* modifier, float value); void modifierActionFixValue(HeightModifier* modifier, double 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;
float height_offset; double 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 float* _noise_pool; static double* _noise_pool;
static inline float _cubicInterpolate(float* p, float x) static inline double _cubicInterpolate(double* p, double 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(float) * _noise_pool_size); _noise_pool = malloc(sizeof(double) * _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++)
{ {
packWriteFloat(stream, _noise_pool + i); packWriteDouble(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(float) * _noise_pool_size); _noise_pool = realloc(_noise_pool, sizeof(double) * _noise_pool_size);
for (i = 0; i < _noise_pool_size; i++) for (i = 0; i < _noise_pool_size; i++)
{ {
packReadFloat(stream, _noise_pool + i); packReadDouble(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);
packWriteFloat(stream, &perlin->height_offset); packWriteDouble(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;
packWriteFloat(stream, &level->scaling); packWriteDouble(stream, &level->scaling);
packWriteFloat(stream, &level->height); packWriteDouble(stream, &level->height);
packWriteFloat(stream, &level->xoffset); packWriteDouble(stream, &level->xoffset);
packWriteFloat(stream, &level->yoffset); packWriteDouble(stream, &level->yoffset);
packWriteFloat(stream, &level->zoffset); packWriteDouble(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);
packReadFloat(stream, &perlin->height_offset); packReadDouble(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;
packReadFloat(stream, &level->scaling); packReadDouble(stream, &level->scaling);
packReadFloat(stream, &level->height); packReadDouble(stream, &level->height);
packReadFloat(stream, &level->xoffset); packReadDouble(stream, &level->xoffset);
packReadFloat(stream, &level->yoffset); packReadDouble(stream, &level->yoffset);
packReadFloat(stream, &level->zoffset); packReadDouble(stream, &level->zoffset);
} }
} }
@ -150,8 +150,8 @@ void noiseGenerateBaseNoise(NoiseGenerator* generator, int size)
size = (size > _noise_pool_size) ? _noise_pool_size : size; size = (size > _noise_pool_size) ? _noise_pool_size : size;
generator->size1 = size; generator->size1 = size;
generator->size2 = (int)floor(sqrt((float)size)); generator->size2 = (int)floor(sqrt((double)size));
generator->size3 = (int)floor(cbrt((float)size)); generator->size3 = (int)floor(cbrt((double)size));
} }
int noiseGetBaseSize(NoiseGenerator* generator) int noiseGetBaseSize(NoiseGenerator* generator)
@ -159,10 +159,10 @@ int noiseGetBaseSize(NoiseGenerator* generator)
return generator->size1; return generator->size1;
} }
float noiseGetMaxValue(NoiseGenerator* generator) double noiseGetMaxValue(NoiseGenerator* generator)
{ {
int x; int x;
float result = generator->height_offset; double 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, float scaling, float height) void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double height)
{ {
NoiseLevel level; NoiseLevel level;
@ -204,7 +204,7 @@ void noiseAddLevelSimple(NoiseGenerator* generator, float scaling, float height)
noiseAddLevel(generator, level); noiseAddLevel(generator, level);
} }
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, float scaling_factor, float height_factor, int randomize_offset) void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, double scaling_factor, double 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, float scaling, float height) void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, double scaling, double height)
{ {
NoiseLevel level; NoiseLevel level;
@ -264,7 +264,7 @@ void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params)
} }
} }
void noiseSetLevelSimple(NoiseGenerator* generator, int level, float scaling, float height) void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, double height)
{ {
NoiseLevel params; NoiseLevel params;
@ -277,11 +277,11 @@ void noiseSetLevelSimple(NoiseGenerator* generator, int level, float scaling, fl
noiseSetLevel(generator, level, params); noiseSetLevel(generator, level, params);
} }
void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max_height, int adjust_scaling) void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double max_height, int adjust_scaling)
{ {
int level; int level;
float height = 0.0; double height = 0.0;
float target_height = max_height - min_height; double target_height = max_height - min_height;
if (generator->level_count == 0) if (generator->level_count == 0)
{ {
@ -306,13 +306,13 @@ void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max
static inline float _get1DRawNoiseValue(NoiseGenerator* generator, float x) static inline double _get1DRawNoiseValue(NoiseGenerator* generator, double x)
{ {
int size = generator->size1; int size = generator->size1;
int xbase = (int)floor(x); int xbase = (int)floor(x);
float xinternal = x - (float)xbase; double xinternal = x - (double)xbase;
int x0 = (xbase - 1) % size; int x0 = (xbase - 1) % size;
if (x0 < 0) if (x0 < 0)
@ -335,7 +335,7 @@ static inline float _get1DRawNoiseValue(NoiseGenerator* generator, float x)
x3 += size; x3 += size;
} }
float buf_cubic_x[4]; double 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 float _get1DRawNoiseValue(NoiseGenerator* generator, float x)
return _cubicInterpolate(buf_cubic_x, xinternal); return _cubicInterpolate(buf_cubic_x, xinternal);
} }
static inline float _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x) static inline double _get1DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double 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;
} }
float noiseGet1DLevel(NoiseGenerator* generator, int level, float x) double noiseGet1DLevel(NoiseGenerator* generator, int level, double x)
{ {
if (level >= 0 && level < generator->level_count) if (level >= 0 && level < generator->level_count)
{ {
@ -362,10 +362,10 @@ float noiseGet1DLevel(NoiseGenerator* generator, int level, float x)
} }
} }
float noiseGet1DTotal(NoiseGenerator* generator, float x) double noiseGet1DTotal(NoiseGenerator* generator, double x)
{ {
int level; int level;
float result; double 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 @@ float noiseGet1DTotal(NoiseGenerator* generator, float x)
return result + generator->height_offset; return result + generator->height_offset;
} }
float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail) double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail)
{ {
int level; int level;
float result, height, factor; double 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 @@ float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail)
static inline float _get2DRawNoiseValue(NoiseGenerator* generator, float x, float y) static inline double _get2DRawNoiseValue(NoiseGenerator* generator, double x, double 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);
float xinternal = x - (float)xbase; double xinternal = x - (double)xbase;
float yinternal = y - (float)ybase; double yinternal = y - (double)ybase;
int x0 = (xbase - 1) % size; int x0 = (xbase - 1) % size;
if (x0 < 0) if (x0 < 0)
@ -454,8 +454,8 @@ static inline float _get2DRawNoiseValue(NoiseGenerator* generator, float x, floa
y3 += size; y3 += size;
} }
float buf_cubic_x[4]; double buf_cubic_x[4];
float buf_cubic_y[4]; double 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 float _get2DRawNoiseValue(NoiseGenerator* generator, float x, floa
return _cubicInterpolate(buf_cubic_y, yinternal); return _cubicInterpolate(buf_cubic_y, yinternal);
} }
static inline float _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x, float y) static inline double _get2DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double 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;
} }
float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y) double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y)
{ {
if (level >= 0 && level < generator->level_count) if (level >= 0 && level < generator->level_count)
{ {
@ -501,10 +501,10 @@ float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y)
} }
} }
float noiseGet2DTotal(NoiseGenerator* generator, float x, float y) double noiseGet2DTotal(NoiseGenerator* generator, double x, double y)
{ {
int level; int level;
float result; double 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 @@ float noiseGet2DTotal(NoiseGenerator* generator, float x, float y)
return result + generator->height_offset; return result + generator->height_offset;
} }
float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail) double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double detail)
{ {
int level; int level;
float result, height, factor; double 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 @@ float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail
static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, float y, float z) static inline double _get3DRawNoiseValue(NoiseGenerator* generator, double x, double y, double z)
{ {
int size = generator->size3; int size = generator->size3;
@ -549,9 +549,9 @@ static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, floa
int ybase = (int)floor(y); int ybase = (int)floor(y);
int zbase = (int)floor(z); int zbase = (int)floor(z);
float xinternal = x - (float)xbase; double xinternal = x - (double)xbase;
float yinternal = y - (float)ybase; double yinternal = y - (double)ybase;
float zinternal = z - (float)zbase; double zinternal = z - (double)zbase;
int x0 = (xbase - 1) % size; int x0 = (xbase - 1) % size;
if (x0 < 0) if (x0 < 0)
@ -616,9 +616,9 @@ static inline float _get3DRawNoiseValue(NoiseGenerator* generator, float x, floa
z3 += size; z3 += size;
} }
float buf_cubic_x[4]; double buf_cubic_x[4];
float buf_cubic_y[4]; double buf_cubic_y[4];
float buf_cubic_z[4]; double 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 float _get3DRawNoiseValue(NoiseGenerator* generator, float x, floa
return _cubicInterpolate(buf_cubic_z, zinternal); return _cubicInterpolate(buf_cubic_z, zinternal);
} }
static inline float _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, float x, float y, float z) static inline double _get3DLevelValue(NoiseGenerator* generator, NoiseLevel* level, double x, double y, double 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;
} }
float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, float z) double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z)
{ {
if (level >= 0 && level < generator->level_count) if (level >= 0 && level < generator->level_count)
{ {
@ -744,10 +744,10 @@ float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, fl
} }
} }
float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z) double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z)
{ {
int level; int level;
float result; double 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 @@ float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z)
return result + generator->height_offset; return result + generator->height_offset;
} }
float noiseGet3DDetail(NoiseGenerator* generator, float x, float y, float z, float detail) double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double detail)
{ {
int level; int level;
float result, height, factor; double 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
{ {
float scaling; double scaling;
float height; double height;
float xoffset; double xoffset;
float yoffset; double yoffset;
float zoffset; double 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);
float noiseGetMaxValue(NoiseGenerator* generator); double 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, float scaling, float height); void noiseAddLevelSimple(NoiseGenerator* generator, double scaling, double height);
void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, float scaling_factor, float height_factor, int randomize_offset); void noiseAddLevels(NoiseGenerator* generator, int level_count, NoiseLevel start_level, double scaling_factor, double height_factor, int randomize_offset);
void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, float scaling, float height); void noiseAddLevelsSimple(NoiseGenerator* generator, int level_count, double scaling, double 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, float scaling, float height); void noiseSetLevelSimple(NoiseGenerator* generator, int level, double scaling, double height);
void noiseNormalizeHeight(NoiseGenerator* generator, float min_height, float max_height, int adjust_scaling); void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double max_height, int adjust_scaling);
float noiseGet1DLevel(NoiseGenerator* generator, int level, float x); double noiseGet1DLevel(NoiseGenerator* generator, int level, double x);
float noiseGet1DTotal(NoiseGenerator* generator, float x); double noiseGet1DTotal(NoiseGenerator* generator, double x);
float noiseGet1DDetail(NoiseGenerator* generator, float x, float detail); double noiseGet1DDetail(NoiseGenerator* generator, double x, double detail);
float noiseGet2DLevel(NoiseGenerator* generator, int level, float x, float y); double noiseGet2DLevel(NoiseGenerator* generator, int level, double x, double y);
float noiseGet2DTotal(NoiseGenerator* generator, float x, float y); double noiseGet2DTotal(NoiseGenerator* generator, double x, double y);
float noiseGet2DDetail(NoiseGenerator* generator, float x, float y, float detail); double noiseGet2DDetail(NoiseGenerator* generator, double x, double y, double detail);
float noiseGet3DLevel(NoiseGenerator* generator, int level, float x, float y, float z); double noiseGet3DLevel(NoiseGenerator* generator, int level, double x, double y, double z);
float noiseGet3DTotal(NoiseGenerator* generator, float x, float y, float z); double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z);
float noiseGet3DDetail(NoiseGenerator* generator, float x, float y, float z, float detail); double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double 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(float f, unsigned bits, unsigned expbits) static uint64_t pack754(double f, unsigned bits, unsigned expbits)
{ {
float fnorm; double 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
@ -39,7 +39,7 @@ static uint64_t pack754(float f, unsigned bits, unsigned expbits)
while(fnorm < 1.0) { fnorm *= 2.0; shift--; } while(fnorm < 1.0) { fnorm *= 2.0; shift--; }
fnorm = fnorm - 1.0; fnorm = fnorm - 1.0;
// calculate the binary form (non-float) of the significand data // calculate the binary form (non-double) of the significand data
significand = fnorm * ((1LL<<significandbits) + 0.5f); significand = fnorm * ((1LL<<significandbits) + 0.5f);
// get the biased exponent // get the biased exponent
@ -49,9 +49,9 @@ static uint64_t pack754(float f, unsigned bits, unsigned expbits)
return (sign<<(bits-1)) | (exp<<(bits-expbits-1)) | significand; return (sign<<(bits-1)) | (exp<<(bits-expbits-1)) | significand;
} }
static float unpack754(uint64_t i, unsigned bits, unsigned expbits) static double unpack754(uint64_t i, unsigned bits, unsigned expbits)
{ {
float result; double 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
@ -60,7 +60,7 @@ static float unpack754(uint64_t i, unsigned bits, unsigned expbits)
// pull the significand // pull the significand
result = (i&((1LL<<significandbits)-1)); // mask result = (i&((1LL<<significandbits)-1)); // mask
result /= (1LL<<significandbits); // convert back to float result /= (1LL<<significandbits); // convert back to double
result += 1.0f; // add the one back on result += 1.0f; // add the one back on
// deal with the exponent // deal with the exponent
@ -107,15 +107,15 @@ void packCloseStream(PackStream* stream)
free(stream); free(stream);
} }
void packWriteFloat(PackStream* stream, float* value) void packWriteDouble(PackStream* stream, double* value)
{ {
uint64_t servalue; uint64_t servalue;
servalue = pack754_32(*value); servalue = pack754_64(*value);
fwrite(&servalue, sizeof(uint64_t), 1, stream->fd); fwrite(&servalue, sizeof(uint64_t), 1, stream->fd);
} }
void packReadFloat(PackStream* stream, float* value) void packReadDouble(PackStream* stream, double* value)
{ {
int read; int read;
uint64_t servalue; uint64_t servalue;
@ -123,7 +123,7 @@ void packReadFloat(PackStream* stream, float* 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_32(servalue); *value = unpack754_64(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 packWriteFloat(PackStream* stream, float* value); void packWriteDouble(PackStream* stream, double* value);
void packReadFloat(PackStream* stream, float* value); void packReadDouble(PackStream* stream, double* 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

@ -10,13 +10,50 @@
#include "color.h" #include "color.h"
#include "system.h" #include "system.h"
typedef struct
{
struct
{
unsigned char dirty : 1;
unsigned char edge : 1;
unsigned char callback : 6;
} flags;
union
{
Vector3 location;
struct {
double r;
double g;
double b;
} color;
} data;
double z;
} RenderFragment;
typedef struct
{
int x;
int y;
Vector3 pixel;
Vector3 location;
int callback;
} ScanPoint;
typedef struct
{
f_RenderFragmentCallback function;
void* data;
} FragmentCallback;
struct RenderArea struct RenderArea
{ {
RenderParams params; RenderParams params;
int pixel_count; int pixel_count;
RenderFragment* pixels; RenderFragment* pixels;
RenderFragment* scanline_up; ScanPoint* scanline_up;
RenderFragment* scanline_down; ScanPoint* scanline_down;
int fragment_callbacks_count;
FragmentCallback fragment_callbacks[64];
int scanline_left; int scanline_left;
int scanline_right; int scanline_right;
Color background_color; Color background_color;
@ -31,12 +68,23 @@ struct RenderArea
RenderCallbackUpdate callback_update; RenderCallbackUpdate callback_update;
}; };
typedef struct {
int startx;
int endx;
int starty;
int endy;
int finished;
int interrupt;
Thread* thread;
RenderArea* area;
Renderer* renderer;
} RenderChunk;
#define RENDER_INVERSE 1 #define RENDER_INVERSE 1
#define RENDER_WIREFRAME 1
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(float progress) {} static void _callbackUpdate(double progress) {}
void renderInit() void renderInit()
{ {
@ -57,8 +105,9 @@ RenderArea* renderCreateArea()
result->params.quality = 5; result->params.quality = 5;
result->pixel_count = 1; result->pixel_count = 1;
result->pixels = malloc(sizeof(RenderFragment)); result->pixels = malloc(sizeof(RenderFragment));
result->scanline_up = malloc(sizeof(RenderFragment)); result->fragment_callbacks_count = 0;
result->scanline_down = malloc(sizeof(RenderFragment)); result->scanline_up = malloc(sizeof(ScanPoint));
result->scanline_down = malloc(sizeof(ScanPoint));
result->scanline_left = 0; result->scanline_left = 0;
result->scanline_right = 0; result->scanline_right = 0;
result->background_color = COLOR_TRANSPARENT; result->background_color = COLOR_TRANSPARENT;
@ -97,8 +146,8 @@ void renderSetParams(RenderArea* area, RenderParams params)
area->scanline_left = 0; area->scanline_left = 0;
area->scanline_right = width - 1; area->scanline_right = width - 1;
area->scanline_up = realloc(area->scanline_up, sizeof(RenderFragment) * width); area->scanline_up = realloc(area->scanline_up, sizeof(ScanPoint) * width);
area->scanline_down = realloc(area->scanline_down, sizeof(RenderFragment) * width); area->scanline_down = realloc(area->scanline_down, sizeof(ScanPoint) * width);
area->dirty_left = width; area->dirty_left = width;
area->dirty_right = -1; area->dirty_right = -1;
@ -114,24 +163,45 @@ void renderSetBackgroundColor(RenderArea* area, Color* col)
area->background_color = *col; area->background_color = *col;
} }
static void _clearScanLines(RenderArea* area)
{
int x;
for (x = area->scanline_left; x <= area->scanline_right; x++)
{
area->scanline_up[x].y = -1;
area->scanline_down[x].y = area->params.height * area->params.antialias;
}
area->scanline_left = area->params.width * area->params.antialias;
area->scanline_right = -1;
}
void renderClear(RenderArea* area) void renderClear(RenderArea* area)
{ {
RenderFragment* pixel; RenderFragment* pixel;
int x; int x;
int y; int y;
area->fragment_callbacks_count = 1;
area->fragment_callbacks[0].function = NULL;
area->fragment_callbacks[0].data = NULL;
for (x = 0; x < area->params.width * area->params.antialias; x++) for (x = 0; x < area->params.width * area->params.antialias; x++)
{ {
for (y = 0; y < area->params.height * area->params.antialias; y++) for (y = 0; y < area->params.height * area->params.antialias; y++)
{ {
pixel = area->pixels + (y * area->params.width * area->params.antialias + x); pixel = area->pixels + (y * area->params.width * area->params.antialias + x);
pixel->z = -100000000.0; pixel->z = -100000000.0;
pixel->vertex.color = area->background_color; pixel->flags.dirty = 0;
pixel->flags.callback = 0;
pixel->data.color.r = area->background_color.r;
pixel->data.color.g = area->background_color.g;
pixel->data.color.b = area->background_color.b;
} }
} }
area->scanline_left = 0; area->scanline_left = 0;
area->scanline_right = area->params.width * area->params.antialias - 1; area->scanline_right = area->params.width * area->params.antialias - 1;
_clearScanLines(area);
area->callback_start(area->params.width, area->params.height, area->background_color); area->callback_start(area->params.width, area->params.height, area->background_color);
@ -142,26 +212,7 @@ void renderClear(RenderArea* area)
area->dirty_count = 0; area->dirty_count = 0;
} }
/*static int _sortRenderFragment(void const* a, void const* b) static inline void _setDirtyPixel(RenderArea* area, int x, int y)
{
float za, zb;
za = ((RenderFragment*)a)->z;
zb = ((RenderFragment*)b)->z;
if (za > zb)
{
return 1;
}
else if (za < zb)
{
return -1;
}
else
{
return 0;
}
}*/
static inline void _setDirtyPixel(RenderArea* area, RenderFragment* fragment, int x, int y)
{ {
if (x < area->dirty_left) if (x < area->dirty_left)
{ {
@ -196,10 +247,26 @@ static inline Color _getFinalPixel(RenderArea* area, int x, int y)
for (sy = 0; sy < area->params.antialias; sy++) for (sy = 0; sy < area->params.antialias; sy++)
{ {
pixel_data = area->pixels + (y * area->params.antialias + sy) * area->params.width * area->params.antialias + (x * area->params.antialias + sx); pixel_data = area->pixels + (y * area->params.antialias + sy) * area->params.width * area->params.antialias + (x * area->params.antialias + sx);
col = pixel_data->vertex.color; if (pixel_data->flags.dirty)
result.r += col.r / (float)(area->params.antialias * area->params.antialias); {
result.g += col.g / (float)(area->params.antialias * area->params.antialias); if (pixel_data->flags.edge)
result.b += col.b / (float)(area->params.antialias * area->params.antialias); {
col = COLOR_RED;
}
else
{
col = COLOR_GREY;
}
}
else
{
col.r = pixel_data->data.color.r;
col.g = pixel_data->data.color.g;
col.b = pixel_data->data.color.b;
}
result.r += col.r / (double)(area->params.antialias * area->params.antialias);
result.g += col.g / (double)(area->params.antialias * area->params.antialias);
result.b += col.b / (double)(area->params.antialias * area->params.antialias);
} }
} }
@ -248,12 +315,32 @@ static void _setAllDirty(RenderArea* area)
area->dirty_up = area->params.height * area->params.antialias - 1; area->dirty_up = area->params.height * area->params.antialias - 1;
} }
void renderAddFragment(RenderArea* area, RenderFragment* fragment) static inline unsigned int _pushCallback(RenderArea* area, FragmentCallback callback)
{
int i;
for (i = 0; i < area->fragment_callbacks_count; i++)
{
if (area->fragment_callbacks[i].function == callback.function && area->fragment_callbacks[i].data == callback.data)
{
return i;
}
}
if (area->fragment_callbacks_count >= 64)
{
return 0;
}
else
{
area->fragment_callbacks[area->fragment_callbacks_count].function = callback.function;
area->fragment_callbacks[area->fragment_callbacks_count].data = callback.data;
return area->fragment_callbacks_count++;
}
}
static void _pushFragment(RenderArea* area, int x, int y, double z, int edge, Vector3 location, int callback)
{ {
RenderFragment* pixel_data; RenderFragment* pixel_data;
int x = fragment->x;
int y = fragment->y;
float z = fragment->z;
if (x >= 0 && x < area->params.width * area->params.antialias && y >= 0 && y < area->params.height * area->params.antialias && z > 1.0) if (x >= 0 && x < area->params.width * area->params.antialias && y >= 0 && y < area->params.height * area->params.antialias && z > 1.0)
{ {
@ -261,98 +348,88 @@ void renderAddFragment(RenderArea* area, RenderFragment* fragment)
if (z > pixel_data->z) if (z > pixel_data->z)
{ {
*pixel_data = *fragment; pixel_data->flags.dirty = (unsigned char)1;
_setDirtyPixel(area, pixel_data, x, y); pixel_data->flags.edge = (unsigned char)edge;
pixel_data->flags.callback = (unsigned char)callback;
pixel_data->data.location = location;
pixel_data->z = z;
_setDirtyPixel(area, x, y);
} }
} }
} }
void renderPushFragment(RenderArea* area, int x, int y, float z, Vertex* vertex) static void _scanGetDiff(ScanPoint* v1, ScanPoint* v2, ScanPoint* result)
{
RenderFragment fragment;
fragment.x = x;
fragment.y = y;
fragment.z = z;
fragment.vertex = *vertex;
renderAddFragment(area, &fragment);
}
static void __vertexGetDiff(Vertex* v1, Vertex* v2, Vertex* result)
{ {
result->pixel.x = v2->pixel.x - v1->pixel.x;
result->pixel.y = v2->pixel.y - v1->pixel.y;
result->pixel.z = v2->pixel.z - v1->pixel.z;
result->location.x = v2->location.x - v1->location.x; result->location.x = v2->location.x - v1->location.x;
result->location.y = v2->location.y - v1->location.y; result->location.y = v2->location.y - v1->location.y;
result->location.z = v2->location.z - v1->location.z; result->location.z = v2->location.z - v1->location.z;
result->color.r = v2->color.r - v1->color.r;
result->color.g = v2->color.g - v1->color.g;
result->color.b = v2->color.b - v1->color.b;
result->color.a = v2->color.a - v1->color.a;
result->callback = v1->callback; result->callback = v1->callback;
result->callback_data = v1->callback_data;
} }
static void __vertexInterpolate(Vertex* v1, Vertex* diff, float value, Vertex* result) static void _scanInterpolate(ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
{ {
result->pixel.x = v1->pixel.x + diff->pixel.x * value;
result->pixel.y = v1->pixel.y + diff->pixel.y * value;
result->pixel.z = v1->pixel.z + diff->pixel.z * value;
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;
result->location.z = v1->location.z + diff->location.z * value; result->location.z = v1->location.z + diff->location.z * value;
result->color.r = v1->color.r + diff->color.r * value;
result->color.g = v1->color.g + diff->color.g * value;
result->color.b = v1->color.b + diff->color.b * value;
result->color.a = v1->color.a + diff->color.a * value;
result->callback = v1->callback; result->callback = v1->callback;
result->callback_data = v1->callback_data;
} }
static void __pushScanLinePoint(RenderArea* area, RenderFragment point) static void _pushScanPoint(RenderArea* area, ScanPoint* point)
{ {
if (point.x < 0 || point.x >= area->params.width * area->params.antialias) point->x = (int)floor(point->pixel.x);
point->y = (int)floor(point->pixel.y);
if (point->x < 0 || point->x >= area->params.width * area->params.antialias)
{ {
return; return;
} }
if (point.x > area->scanline_right) if (point->x > area->scanline_right)
{ {
area->scanline_right = point.x; area->scanline_right = point->x;
area->scanline_up[area->scanline_right] = point; area->scanline_up[area->scanline_right] = *point;
area->scanline_down[area->scanline_right] = point; area->scanline_down[area->scanline_right] = *point;
if (point.x < area->scanline_left) if (point->x < area->scanline_left)
{ {
area->scanline_left = point.x; area->scanline_left = point->x;
} }
} }
else if (point.x < area->scanline_left) else if (point->x < area->scanline_left)
{ {
area->scanline_left = point.x; area->scanline_left = point->x;
area->scanline_up[area->scanline_left] = point; area->scanline_up[area->scanline_left] = *point;
area->scanline_down[area->scanline_left] = point; area->scanline_down[area->scanline_left] = *point;
} }
else else
{ {
if (point.y > area->scanline_up[point.x].y) if (point->y > area->scanline_up[point->x].y)
{ {
area->scanline_up[point.x] = point; area->scanline_up[point->x] = *point;
} }
if (point.y < area->scanline_down[point.x].y) if (point->y < area->scanline_down[point->x].y)
{ {
area->scanline_down[point.x] = point; area->scanline_down[point->x] = *point;
} }
} }
} }
static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex* vertex1, Vertex* vertex2) static void _pushScanLineEdge(RenderArea* area, ScanPoint* point1, ScanPoint* point2)
{ {
float dx, dy, dz, fx; double dx, fx;
Vertex diff; ScanPoint diff, point;
int startx = lround(v1.x); int startx = lround(point1->pixel.x);
int endx = lround(v2.x); int endx = lround(point2->pixel.x);
int curx; int curx;
RenderFragment fragment;
if (endx < startx) if (endx < startx)
{ {
__pushScanLineEdge(area, v2, v1, vertex2, vertex1); _pushScanLineEdge(area, point2, point1);
} }
else if (endx < 0 || startx >= area->params.width * area->params.antialias) else if (endx < 0 || startx >= area->params.width * area->params.antialias)
{ {
@ -360,19 +437,8 @@ static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex*
} }
else if (startx == endx) else if (startx == endx)
{ {
fragment.x = startx; _pushScanPoint(area, point1);
fragment.y = lround(v1.y); _pushScanPoint(area, point2);
fragment.z = v1.z;
fragment.vertex = *vertex1;
__pushScanLinePoint(area, fragment);
fragment.x = endx;
fragment.y = lround(v2.y);
fragment.z = v2.z;
fragment.vertex = *vertex2;
__pushScanLinePoint(area, fragment);
} }
else else
{ {
@ -385,50 +451,35 @@ static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex*
endx = area->params.width * area->params.antialias - 1; endx = area->params.width * area->params.antialias - 1;
} }
dx = v2.x - v1.x; dx = point2->pixel.x - point1->pixel.x;
dy = v2.y - v1.y; _scanGetDiff(point1, point2, &diff);
dz = v2.z - v1.z;
__vertexGetDiff(vertex1, vertex2, &diff);
for (curx = startx; curx <= endx; curx++) for (curx = startx; curx <= endx; curx++)
{ {
fx = (float)curx + 0.5; fx = (double)curx + 0.5;
if (fx < v1.x) if (fx < point1->pixel.x)
{ {
fx = v1.x; fx = point1->pixel.x;
} }
else if (fx > v2.x) else if (fx > point2->pixel.x)
{ {
fx = v2.x; fx = point2->pixel.x;
} }
fx = fx - v1.x; fx = fx - point1->pixel.x;
fragment.x = curx; _scanInterpolate(point1, &diff, fx / dx, &point);
fragment.y = lround(v1.y + dy * fx / dx);
fragment.z = v1.z + dz * fx / dx;
__vertexInterpolate(vertex1, &diff, fx / dx, &(fragment.vertex));
__pushScanLinePoint(area, fragment); /*point.pixel.x = (double)curx;*/
_pushScanPoint(area, &point);
} }
} }
} }
static void __clearScanLines(RenderArea* area) static void _renderScanLines(RenderArea* area)
{
int x;
for (x = area->scanline_left; x <= area->scanline_right; x++)
{
area->scanline_up[x].y = -1;
area->scanline_down[x].y = area->params.height * area->params.antialias;
}
area->scanline_left = area->params.width * area->params.antialias;
area->scanline_right = -1;
}
static void __renderScanLines(RenderArea* area)
{ {
int x, starty, endy, cury; int x, starty, endy, cury;
Vertex diff; ScanPoint diff;
float dy, dz, fy; double dy, fy;
RenderFragment up, down, current; ScanPoint up, down, current;
if (area->scanline_right > 0) if (area->scanline_right > 0)
{ {
@ -454,64 +505,68 @@ static void __renderScanLines(RenderArea* area)
endy = area->params.height * area->params.antialias - 1; endy = area->params.height * area->params.antialias - 1;
} }
dy = (float)(up.y - down.y); dy = up.pixel.y - down.pixel.y;
dz = up.z - down.z; _scanGetDiff(&down, &up, &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 = (float)cury - down.y; fy = (double)cury + 0.5;
if (fy < down.pixel.y)
{
fy = down.pixel.y;
}
else if (fy > up.pixel.y)
{
fy = up.pixel.y;
}
fy = fy - down.pixel.y;
current.y = cury; current.y = cury;
current.z = down.z + dz * fy / dy; _scanInterpolate(&down, &diff, fy / dy, &current);
__vertexInterpolate(&down.vertex, &diff, fy / dy, &current.vertex);
#ifdef RENDER_WIREFRAME _pushFragment(area, current.x, current.y, current.pixel.z, (cury == starty || cury == endy), current.location, current.callback);
if (cury == starty || cury == endy) }
}
}
}
void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data)
{ {
current.vertex.color = COLOR_RED; FragmentCallback fragment_callback = {callback, callback_data};
} ScanPoint point1, point2, point3;
#endif double limit_width = (double)(area->params.width * area->params.antialias - 1);
double limit_height = (double)(area->params.height * area->params.antialias - 1);
renderAddFragment(area, &current);
}
}
}
}
void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3)
{
float limit_width = (float)(area->params.width * 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 (pixel1.z < 1.0 || pixel2.z < 1.0 || pixel3.z < 1.0 || (pixel1.x < 0.0 && pixel2.x < 0.0 && pixel3.x < 0.0) || (pixel1.y < 0.0 && pixel2.y < 0.0 && pixel3.y < 0.0) || (pixel1.x > limit_width && pixel2.x > limit_width && pixel3.x > limit_width) || (pixel1.y > limit_height && pixel2.y > limit_height && pixel3.y > limit_height))
{ {
return; return;
} }
__clearScanLines(area); point1.pixel = pixel1;
__pushScanLineEdge(area, p1, p2, v1, v2); point1.location = location1;
__pushScanLineEdge(area, p2, p3, v2, v3); point1.callback = _pushCallback(area, fragment_callback);
__pushScanLineEdge(area, p3, p1, v3, v1);
point2.pixel = pixel2;
point2.location = location2;
point2.callback = _pushCallback(area, fragment_callback);
point3.pixel = pixel3;
point3.location = location3;
point3.callback = _pushCallback(area, fragment_callback);
_clearScanLines(area);
_pushScanLineEdge(area, &point1, &point2);
_pushScanLineEdge(area, &point2, &point3);
_pushScanLineEdge(area, &point3, &point1);
mutexAcquire(area->lock); mutexAcquire(area->lock);
__renderScanLines(area); _renderScanLines(area);
mutexRelease(area->lock); mutexRelease(area->lock);
} }
typedef struct {
int startx;
int endx;
int starty;
int endy;
int finished;
int interrupt;
Thread* thread;
RenderArea* area;
Renderer* renderer;
} RenderChunk;
void* _renderPostProcessChunk(void* data) void* _renderPostProcessChunk(void* data)
{ {
int x, y; int x, y;
@ -527,13 +582,28 @@ void* _renderPostProcessChunk(void* data)
for (x = chunk->startx; x <= chunk->endx; x++) for (x = chunk->startx; x <= chunk->endx; x++)
{ {
fragment = chunk->area->pixels + (y * chunk->area->params.width * chunk->area->params.antialias + x); fragment = chunk->area->pixels + (y * chunk->area->params.width * chunk->area->params.antialias + x);
if (fragment->vertex.callback) if (fragment->flags.dirty)
{ {
if (fragment->vertex.callback(fragment, chunk->renderer, fragment->vertex.callback_data)) FragmentCallback callback;
Color col;
callback = chunk->area->fragment_callbacks[fragment->flags.callback];
if (callback.function)
{ {
colorNormalize(&fragment->vertex.color); col = callback.function(chunk->renderer, fragment->data.location, callback.data);
_setDirtyPixel(chunk->area, fragment, x, y); colorNormalize(&col);
} }
else
{
col = COLOR_BLACK;
}
fragment->data.color.r = col.r;
fragment->data.color.g = col.g;
fragment->data.color.b = col.b;
fragment->flags.dirty = 0;
_setDirtyPixel(chunk->area, x, y);
} }
/* chunk->area->progress_pixels++; */ /* chunk->area->progress_pixels++; */
} }
@ -638,7 +708,7 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks)
if (++loops >= 10) if (++loops >= 10)
{ {
mutexAcquire(area->lock); mutexAcquire(area->lock);
/*_progress = (float)_progress_pixels / (float)_pixel_count;*/ /*_progress = (double)_progress_pixels / (double)_pixel_count;*/
_processDirtyPixels(area); _processDirtyPixels(area);
mutexRelease(area->lock); mutexRelease(area->lock);

View file

@ -20,9 +20,7 @@ void renderSetBackgroundColor(RenderArea* area, Color* col);
void renderClear(RenderArea* area); void renderClear(RenderArea* area);
void renderUpdate(RenderArea* area); void renderUpdate(RenderArea* area);
void renderAddFragment(RenderArea* area, RenderFragment* fragment); void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data);
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 renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks); void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks);
int renderSaveToFile(RenderArea* area, const char* path); int renderSaveToFile(RenderArea* area, const char* path);

View file

@ -17,12 +17,12 @@ static void* _renderFirstPass(void* data)
return NULL; return NULL;
} }
static int _addRenderProgress(Renderer* renderer, float progress) static int _addRenderProgress(Renderer* renderer, double progress)
{ {
return !renderer->render_interrupt; return !renderer->render_interrupt;
} }
static float _getPrecision(Renderer* renderer, Vector3 location) static double _getPrecision(Renderer* renderer, Vector3 location)
{ {
return 0.001; return 0.001;
} }
@ -37,21 +37,21 @@ static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
return point; return point;
} }
static void _pushTriangle(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3) static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
{ {
Vector3 p1, p2, p3; Vector3 p1, p2, p3;
p1 = renderer->projectPoint(renderer, v1->location); p1 = renderer->projectPoint(renderer, v1);
p2 = renderer->projectPoint(renderer, v2->location); p2 = renderer->projectPoint(renderer, v2);
p3 = renderer->projectPoint(renderer, v3->location); p3 = renderer->projectPoint(renderer, v3);
renderPushTriangle(renderer->render_area, v1, v2, v3, p1, p2, p3); renderPushTriangle(renderer->render_area, p1, p2, p3, v1, v2, v3, callback, callback_data);
} }
static void _pushQuad(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4) static void _pushQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data)
{ {
renderer->pushTriangle(renderer, v2, v3, v1); renderer->pushTriangle(renderer, v2, v3, v1, callback, callback_data);
renderer->pushTriangle(renderer, v4, v1, v3); renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
} }
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location) static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
@ -73,7 +73,7 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
return _RAYCASTING_NULL; return _RAYCASTING_NULL;
} }
static float _getTerrainHeight(Renderer* renderer, float x, float z) static double _getTerrainHeight(Renderer* renderer, double x, double 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, float precision) static Color _applyTextures(Renderer* renderer, Vector3 location, double 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;
float render_progress; double render_progress;
int render_interrupt; int render_interrupt;
int is_rendering; int is_rendering;
float (*getPrecision)(Renderer* renderer, Vector3 location); double (*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, float progress); int (*addRenderProgress)(Renderer* renderer, double progress);
void (*pushTriangle)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3); void (*pushTriangle)(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data);
void (*pushQuad)(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4); void (*pushQuad)(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data);
/* 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);
float (*getTerrainHeight)(Renderer* renderer, float x, float z); double (*getTerrainHeight)(Renderer* renderer, double x, double z);
HeightInfo (*getWaterHeightInfo)(Renderer* renderer); HeightInfo (*getWaterHeightInfo)(Renderer* renderer);
Color (*applyTextures)(Renderer* renderer, Vector3 location, float precision); Color (*applyTextures)(Renderer* renderer, Vector3 location, double 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

@ -213,21 +213,9 @@ void sceneryGetWater(WaterDefinition* water)
void sceneryRenderFirstPass(Renderer* renderer) void sceneryRenderFirstPass(Renderer* renderer)
{ {
/*if (!renderSetNextProgressStep(0.0, 0.01))
{
return;
}*/
skyRender(&_sky, renderer);
/*if (!renderSetNextProgressStep(0.01, 0.085))
{
return;
}*/
terrainRender(&_terrain, renderer); terrainRender(&_terrain, renderer);
/*if (!renderSetNextProgressStep(0.085, 0.1))
{
return;
}*/
waterRender(&_water, renderer); waterRender(&_water, renderer);
skyRender(&_sky, renderer);
} }
@ -282,7 +270,7 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
return result; return result;
} }
static float _getTerrainHeight(Renderer* renderer, float x, float z) static double _getTerrainHeight(Renderer* renderer, double x, double z)
{ {
return terrainGetHeight(&_terrain, x, z); return terrainGetHeight(&_terrain, x, z);
} }
@ -292,7 +280,7 @@ static HeightInfo _getWaterHeightInfo(Renderer* renderer)
return waterGetHeightInfo(&_water); return waterGetHeightInfo(&_water);
} }
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision) static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
{ {
return texturesGetColor(&_textures, renderer, location.x, location.z, precision); return texturesGetColor(&_textures, renderer, location.x, location.z, precision);
} }
@ -322,7 +310,7 @@ static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
return cameraUnproject(&renderer->render_camera, renderer, point); return cameraUnproject(&renderer->render_camera, renderer, point);
} }
static float _getPrecision(Renderer* renderer, Vector3 location) static double _getPrecision(Renderer* renderer, Vector3 location)
{ {
Vector3 projected; Vector3 projected;
@ -330,7 +318,7 @@ static float _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)); // / (float)render_quality; return v3Norm(v3Sub(cameraUnproject(&renderer->render_camera, renderer, projected), location)); // / (double)render_quality;
} }
Renderer sceneryCreateStandardRenderer() Renderer sceneryCreateStandardRenderer()

View file

@ -8,29 +8,12 @@
extern "C" { extern "C" {
#endif #endif
struct RenderFragment;
struct Renderer; struct Renderer;
typedef struct LightDefinition LightDefinition; typedef struct LightDefinition LightDefinition;
typedef struct LightStatus LightStatus; typedef struct LightStatus LightStatus;
typedef int(*f_RenderFragmentCallback)(struct RenderFragment*, struct Renderer* renderer, void* data); typedef Color (*f_RenderFragmentCallback)(struct Renderer* renderer, Vector3 location, void* data);
typedef struct
{
Vector3 location;
Color color;
f_RenderFragmentCallback callback;
void* callback_data;
} Vertex;
typedef struct RenderFragment
{
short int x;
short int y;
float z;
Vertex vertex;
} RenderFragment;
typedef struct typedef struct
{ {
@ -52,13 +35,13 @@ typedef struct
typedef struct typedef struct
{ {
Color base; Color base;
float reflection; double reflection;
float shininess; double 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)(float progress); typedef void (*RenderCallbackUpdate)(double progress);
typedef struct RenderArea RenderArea; typedef struct RenderArea RenderArea;
@ -72,29 +55,29 @@ typedef RayCastingResult (*RayCastingFunction)(Vector3 start, Vector3 direction)
typedef struct typedef struct
{ {
float min_height; double min_height;
float max_height; double max_height;
float base_height; double base_height;
} HeightInfo; } HeightInfo;
typedef struct typedef struct
{ {
Vector3 location; Vector3 location;
float yaw; double yaw;
float pitch; double pitch;
float roll; double roll;
Vector3 target; Vector3 target;
Vector3 forward; Vector3 forward;
Vector3 right; Vector3 right;
Vector3 up; Vector3 up;
float width; double width;
float height; double height;
float yfov; double yfov;
float xratio; double xratio;
float znear; double znear;
float zfar; double 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)
{ {
packWriteFloat(stream, &definition->daytime); packWriteDouble(stream, &definition->daytime);
colorGradationSave(stream, definition->sun_color); colorGradationSave(stream, definition->sun_color);
packWriteFloat(stream, &definition->sun_radius); packWriteDouble(stream, &definition->sun_radius);
packWriteFloat(stream, &definition->sun_halo_size); packWriteDouble(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);
packWriteFloat(stream, &definition->haze_height); packWriteDouble(stream, &definition->haze_height);
packWriteFloat(stream, &definition->haze_smoothing); packWriteDouble(stream, &definition->haze_smoothing);
} }
void skyLoad(PackStream* stream, SkyDefinition* definition) void skyLoad(PackStream* stream, SkyDefinition* definition)
{ {
packReadFloat(stream, &definition->daytime); packReadDouble(stream, &definition->daytime);
colorGradationLoad(stream, definition->sun_color); colorGradationLoad(stream, definition->sun_color);
packReadFloat(stream, &definition->sun_radius); packReadDouble(stream, &definition->sun_radius);
packReadFloat(stream, &definition->sun_halo_size); packReadDouble(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);
packReadFloat(stream, &definition->haze_height); packReadDouble(stream, &definition->haze_height);
packReadFloat(stream, &definition->haze_smoothing); packReadDouble(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)
{ {
float sun_angle; double 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)
{ {
float dist; double dist;
Vector3 sun_position; Vector3 sun_position;
Color sun_color, sky_color; Color sun_color, sky_color;
@ -183,43 +183,35 @@ Color skyGetColor(SkyDefinition* definition, Renderer* renderer, Vector3 eye, Ve
} }
} }
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data) static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
{ {
Vector3 location, direction; Vector3 direction;
Color result; Color result;
SkyDefinition* definition; SkyDefinition* definition;
definition = (SkyDefinition*)data; definition = (SkyDefinition*)data;
location = fragment->vertex.location;
direction = v3Sub(location, renderer->camera_location); direction = v3Sub(location, renderer->camera_location);
result = skyGetColor(definition, renderer, renderer->camera_location, v3Normalize(direction)); result = skyGetColor(definition, renderer, renderer->camera_location, v3Normalize(direction));
result = renderer->applyClouds(renderer, result, renderer->camera_location, v3Add(renderer->camera_location, v3Scale(direction, 10.0))); result = renderer->applyClouds(renderer, result, renderer->camera_location, v3Add(renderer->camera_location, v3Scale(direction, 10.0)));
fragment->vertex.color = result; return result;
return 1;
} }
void skyRender(SkyDefinition* definition, Renderer* renderer) void skyRender(SkyDefinition* definition, Renderer* renderer)
{ {
int res_i, res_j; int res_i, res_j;
int i, j; int i, j;
float step_i, step_j; double step_i, step_j;
float current_i, current_j; double current_i, current_j;
Vertex vertex1, vertex2, vertex3, vertex4; Vector3 vertex1, vertex2, vertex3, vertex4;
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 / (float)res_i; step_i = M_PI * 2.0 / (double)res_i;
step_j = M_PI / (float)res_j; step_j = M_PI / (double)res_j;
col.r = 0.0;
col.g = 0.0;
col.a = 1.0;
for (j = 0; j < res_j; j++) for (j = 0; j < res_j; j++)
{ {
@ -228,50 +220,34 @@ void skyRender(SkyDefinition* definition, Renderer* renderer)
return; return;
} }
current_j = (float)(j - res_j / 2) * step_j; current_j = (double)(j - res_j / 2) * step_j;
for (i = 0; i < res_i; i++) for (i = 0; i < res_i; i++)
{ {
current_i = (float)i * step_i; current_i = (double)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);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j); direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j);
vertex1.location = v3Add(renderer->camera_location, direction); vertex1 = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex1.color = col;
vertex1.callback = _postProcessFragment;
vertex1.callback_data = definition;
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j); direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j); direction.y = SPHERE_SIZE * sin(current_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j); direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j);
vertex2.location = v3Add(renderer->camera_location, direction); vertex2 = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex2.color = col;
vertex2.callback = _postProcessFragment;
vertex2.callback_data = definition;
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j); direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j); direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j + step_j); direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j + step_j);
vertex3.location = v3Add(renderer->camera_location, direction); vertex3 = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex3.color = col;
vertex3.callback = _postProcessFragment;
vertex3.callback_data = definition;
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j); direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j); direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j + step_j); direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j + step_j);
vertex4.location = v3Add(renderer->camera_location, direction); vertex4 = v3Add(renderer->camera_location, direction);
col.b = sin(direction.x) * sin(direction.x) * cos(direction.z) * cos(direction.z);
vertex4.color = col;
vertex4.callback = _postProcessFragment;
vertex4.callback_data = definition;
/* TODO Triangles at poles */ /* TODO Triangles at poles */
renderer->pushQuad(renderer, &vertex1, &vertex4, &vertex3, &vertex2); renderer->pushQuad(renderer, vertex1, vertex4, vertex3, vertex2, _postProcessFragment, definition);
} }
} }
} }
@ -279,7 +255,7 @@ void skyRender(SkyDefinition* definition, Renderer* renderer)
Vector3 skyGetSunDirection(SkyDefinition* definition) Vector3 skyGetSunDirection(SkyDefinition* definition)
{ {
Vector3 result; Vector3 result;
float sun_angle = (definition->daytime + 0.75) * M_PI * 2.0; double 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
{ {
float daytime; double daytime;
ColorGradation* sun_color; ColorGradation* sun_color;
float sun_radius; double sun_radius;
float sun_halo_size; double sun_halo_size;
Curve* sun_halo_profile; Curve* sun_halo_profile;
ColorGradation* zenith_color; ColorGradation* zenith_color;
ColorGradation* haze_color; ColorGradation* haze_color;
float haze_height; double haze_height;
float haze_smoothing; double 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);
packWriteFloat(stream, &definition->height_factor); packWriteDouble(stream, &definition->height_factor);
packWriteFloat(stream, &definition->scaling); packWriteDouble(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);
packReadFloat(stream, &definition->height_factor); packReadDouble(stream, &definition->height_factor);
packReadFloat(stream, &definition->scaling); packReadDouble(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 float _getHeight(TerrainDefinition* definition, float x, float z) static inline double _getHeight(TerrainDefinition* definition, double x, double z)
{ {
Vector3 location; Vector3 location;
int i; int i;
@ -156,7 +156,7 @@ static inline float _getHeight(TerrainDefinition* definition, float x, float z)
return location.y; return location.y;
} }
static inline float _getHeightDetail(TerrainDefinition* definition, float x, float z, float detail) static inline double _getHeightDetail(TerrainDefinition* definition, double x, double z, double detail)
{ {
Vector3 location; Vector3 location;
int i; int i;
@ -173,7 +173,7 @@ static inline float _getHeightDetail(TerrainDefinition* definition, float x, flo
return location.y; return location.y;
} }
static inline Vector3 _getPoint(TerrainDefinition* definition, float x, float z) static inline Vector3 _getPoint(TerrainDefinition* definition, double x, double z)
{ {
Vector3 result; Vector3 result;
@ -187,7 +187,7 @@ static inline Vector3 _getPoint(TerrainDefinition* definition, float x, float z)
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;
float inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length; double 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 = (float)renderer->render_quality; inc_factor = (double)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, float precision) static Color _getColor(TerrainDefinition* definition, Renderer* renderer, Vector3 point, double 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;
float inc_value, inc_base, inc_factor, height, diff, lastdiff, length; double inc_value, inc_base, inc_factor, height, diff, lastdiff, length;
direction = v3Normalize(direction); direction = v3Normalize(direction);
inc_factor = (float)renderer->render_quality; inc_factor = (double)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);
@ -317,61 +317,40 @@ int terrainProjectRay(TerrainDefinition* definition, Renderer* renderer, Vector3
return 0; return 0;
} }
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data) static Color _postProcessFragment(Renderer* renderer, Vector3 point, void* data)
{ {
Vector3 point; double precision;
float precision;
TerrainDefinition* definition; TerrainDefinition* definition;
definition = (TerrainDefinition*)data; definition = (TerrainDefinition*)data;
point = fragment->vertex.location;
point = _getPoint(definition, point.x, point.z); point = _getPoint(definition, point.x, point.z);
precision = renderer->getPrecision(renderer, point); precision = renderer->getPrecision(renderer, point);
fragment->vertex.color = _getColor(definition, renderer, point, precision); return _getColor(definition, renderer, point, precision);
return 1;
} }
static Vertex _getFirstPassVertex(TerrainDefinition* definition, float x, float z, float detail) static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, double x, double z, double size, double water_height)
{ {
Vertex result; Vector3 v1, v2, v3, v4;
float value;
result.location = _getPoint(definition, x, z); v1 = _getPoint(definition, x, z);
value = sin(x) * sin(x) * cos(z) * cos(z); v2 = _getPoint(definition, x, z + size);
result.color.r = value; v3 = _getPoint(definition, x + size, z + size);
result.color.g = value; v4 = _getPoint(definition, x + size, z);
result.color.b = value;
result.color.a = 1.0;
result.callback = _postProcessFragment;
result.callback_data = definition;
return result; if (v1.y > water_height || v2.y > water_height || v3.y > water_height || v4.y > water_height)
}
static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, float x, float z, float size, float water_height)
{ {
Vertex v1, v2, v3, v4; renderer->pushQuad(renderer, v1, v2, v3, v4, _postProcessFragment, definition);
v1 = _getFirstPassVertex(definition, x, z, size);
v2 = _getFirstPassVertex(definition, x, z + size, size);
v3 = _getFirstPassVertex(definition, x + size, z + size, size);
v4 = _getFirstPassVertex(definition, x + size, z, size);
if (v1.location.y > water_height || v2.location.y > water_height || v3.location.y > water_height || v4.location.y > water_height)
{
renderer->pushQuad(renderer, &v1, &v2, &v3, &v4);
} }
} }
float terrainGetHeight(TerrainDefinition* definition, float x, float z) double terrainGetHeight(TerrainDefinition* definition, double x, double z)
{ {
return _getHeight(definition, x, z); return _getHeight(definition, x, z);
} }
float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z) double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z)
{ {
if (definition->_max_height == 0.0) if (definition->_max_height == 0.0)
{ {
@ -383,7 +362,7 @@ float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z
} }
} }
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x, float z, float detail) Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double x, double z, double 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);
@ -392,14 +371,14 @@ Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x
void terrainRender(TerrainDefinition* definition, Renderer* renderer) void terrainRender(TerrainDefinition* definition, Renderer* renderer)
{ {
int chunk_factor, chunk_count, i; int chunk_factor, chunk_count, i;
float cx = renderer->camera_location.x; double cx = renderer->camera_location.x;
float cz = renderer->camera_location.z; double cz = renderer->camera_location.z;
float min_chunk_size, visible_chunk_size; double min_chunk_size, visible_chunk_size;
float radius_int, radius_ext, chunk_size; double radius_int, radius_ext, chunk_size;
float water_height; double water_height;
min_chunk_size = 0.1 / (float)renderer->render_quality; min_chunk_size = 0.1 / (double)renderer->render_quality;
visible_chunk_size = 0.05 / (float)renderer->render_quality; visible_chunk_size = 0.05 / (double)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;
float height_factor; double height_factor;
float scaling; double scaling;
int height_modifiers_count; int height_modifiers_count;
HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS]; HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS];
float _max_height; double _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);
float terrainGetHeight(TerrainDefinition* definition, float x, float z); double terrainGetHeight(TerrainDefinition* definition, double x, double z);
float terrainGetHeightNormalized(TerrainDefinition* definition, float x, float z); double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z);
Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, float x, float z, float detail); Color terrainGetColor(TerrainDefinition* definition, Renderer* renderer, double x, double z, double 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
{ {
float thickness; double 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);
packWriteFloat(stream, &definition->textures[i].bump_height); packWriteDouble(stream, &definition->textures[i].bump_height);
packWriteFloat(stream, &definition->textures[i].bump_scaling); packWriteDouble(stream, &definition->textures[i].bump_scaling);
materialSave(stream, &definition->textures[i].material); materialSave(stream, &definition->textures[i].material);
packWriteFloat(stream, &definition->textures[i].thickness); packWriteDouble(stream, &definition->textures[i].thickness);
packWriteFloat(stream, &definition->textures[i].slope_range); packWriteDouble(stream, &definition->textures[i].slope_range);
packWriteFloat(stream, &definition->textures[i].thickness_transparency); packWriteDouble(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);
packReadFloat(stream, &layer->bump_height); packReadDouble(stream, &layer->bump_height);
packReadFloat(stream, &layer->bump_scaling); packReadDouble(stream, &layer->bump_scaling);
materialLoad(stream, &layer->material); materialLoad(stream, &layer->material);
packReadFloat(stream, &definition->textures[i].thickness); packReadDouble(stream, &definition->textures[i].thickness);
packReadFloat(stream, &definition->textures[i].slope_range); packReadDouble(stream, &definition->textures[i].slope_range);
packReadFloat(stream, &definition->textures[i].thickness_transparency); packReadDouble(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, float x, float z, float detail) static inline TextureResult _getTerrainResult(Renderer* renderer, double x, double z, double 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, float x, float
return result; return result;
} }
static inline void _getLayerThickness(TextureLayerDefinition* definition, Renderer* renderer, float x, float z, TextureResult* result) static inline void _getLayerThickness(TextureLayerDefinition* definition, Renderer* renderer, double x, double z, TextureResult* result)
{ {
TextureResult base; TextureResult base;
float coverage; double 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, float x, float z, float detail) static inline TextureResult _getLayerResult(TextureLayerDefinition* definition, Renderer* renderer, double x, double z, double 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;
} }
float texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail) double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double 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, float detail) Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double 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, float x, float z, float detail) Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail)
{ {
TextureResult results[TEXTURES_MAX_LAYERS + 1]; TextureResult results[TEXTURES_MAX_LAYERS + 1];
Color result, color; Color result, color;
float thickness, last_height; double 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;
float bump_scaling; double bump_scaling;
float bump_height; double bump_height;
SurfaceMaterial material; SurfaceMaterial material;
float thickness; double thickness;
float slope_range; double slope_range;
float thickness_transparency; double 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);
float texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail); double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail); Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, float x, float z, float detail); Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -8,19 +8,19 @@
#include "color.h" #include "color.h"
#include "euclid.h" #include "euclid.h"
float toolsRandom() double toolsRandom()
{ {
return (float)rand() / (float)RAND_MAX; return ((double)rand()) / (double)RAND_MAX;
} }
static inline float __cubicInterpolate(float p[4], float x) static inline double __cubicInterpolate(double p[4], double 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])));
} }
float toolsBicubicInterpolate(float stencil[16], float x, float y) double toolsBicubicInterpolate(double stencil[16], double x, double y)
{ {
float buf_cubic_y[4]; double 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 @@ float toolsBicubicInterpolate(float stencil[16], float x, float y)
return __cubicInterpolate(buf_cubic_y, y); return __cubicInterpolate(buf_cubic_y, y);
} }
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) 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)
{ {
/* 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;
float* src_row; double* src_row;
float* dest_row; double* 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));
} }
float toolsGetDistance2D(float x1, float y1, float x2, float y2) double toolsGetDistance2D(double x1, double y1, double x2, double y2)
{ {
float dx = x2 - x1; double dx = x2 - x1;
float dy = y2 - y1; double 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);
packWriteFloat(stream, &material->reflection); packWriteDouble(stream, &material->reflection);
packWriteFloat(stream, &material->shininess); packWriteDouble(stream, &material->shininess);
} }
void materialLoad(PackStream* stream, SurfaceMaterial* material) void materialLoad(PackStream* stream, SurfaceMaterial* material)
{ {
colorLoad(stream, &material->base); colorLoad(stream, &material->base);
packReadFloat(stream, &material->reflection); packReadDouble(stream, &material->reflection);
packReadFloat(stream, &material->shininess); packReadDouble(stream, &material->shininess);
} }

View file

@ -8,11 +8,11 @@
extern "C" { extern "C" {
#endif #endif
float toolsRandom(); double toolsRandom();
float toolsBicubicInterpolate(float stencil[16], float x, float y); double toolsBicubicInterpolate(double stencil[16], double x, double y);
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); 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);
Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right); Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
float toolsGetDistance2D(float x1, float y1, float x2, float y2); double toolsGetDistance2D(double x1, double y1, double x2, double 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;
float max_height; double 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);
/*float vegetationGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, float detail);*/ /*double vegetationGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double 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)
{ {
packWriteFloat(stream, &definition->height); packWriteDouble(stream, &definition->height);
materialSave(stream, &definition->material); materialSave(stream, &definition->material);
colorSave(stream, &definition->depth_color); colorSave(stream, &definition->depth_color);
packWriteFloat(stream, &definition->transparency_depth); packWriteDouble(stream, &definition->transparency_depth);
packWriteFloat(stream, &definition->transparency); packWriteDouble(stream, &definition->transparency);
packWriteFloat(stream, &definition->reflection); packWriteDouble(stream, &definition->reflection);
packWriteFloat(stream, &definition->lighting_depth); packWriteDouble(stream, &definition->lighting_depth);
noiseSaveGenerator(stream, definition->waves_noise); noiseSaveGenerator(stream, definition->waves_noise);
packWriteFloat(stream, &definition->waves_noise_height); packWriteDouble(stream, &definition->waves_noise_height);
packWriteFloat(stream, &definition->waves_noise_scale); packWriteDouble(stream, &definition->waves_noise_scale);
} }
void waterLoad(PackStream* stream, WaterDefinition* definition) void waterLoad(PackStream* stream, WaterDefinition* definition)
{ {
packReadFloat(stream, &definition->height); packReadDouble(stream, &definition->height);
materialLoad(stream, &definition->material); materialLoad(stream, &definition->material);
colorLoad(stream, &definition->depth_color); colorLoad(stream, &definition->depth_color);
packReadFloat(stream, &definition->transparency_depth); packReadDouble(stream, &definition->transparency_depth);
packReadFloat(stream, &definition->transparency); packReadDouble(stream, &definition->transparency);
packReadFloat(stream, &definition->reflection); packReadDouble(stream, &definition->reflection);
packReadFloat(stream, &definition->lighting_depth); packReadDouble(stream, &definition->lighting_depth);
noiseLoadGenerator(stream, definition->waves_noise); noiseLoadGenerator(stream, definition->waves_noise);
packReadFloat(stream, &definition->waves_noise_height); packReadDouble(stream, &definition->waves_noise_height);
packReadFloat(stream, &definition->waves_noise_scale); packReadDouble(stream, &definition->waves_noise_scale);
waterValidateDefinition(definition); waterValidateDefinition(definition);
} }
@ -87,15 +87,15 @@ void waterValidateDefinition(WaterDefinition* definition)
{ {
} }
static inline float _getHeight(WaterDefinition* definition, float x, float z, float detail) static inline double _getHeight(WaterDefinition* definition, double x, double z, double 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, float detail) static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail)
{ {
Vector3 back, right; Vector3 back, right;
float x, z; double 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, floa
static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal) static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
{ {
float c; double 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)
{ {
float c1, c2, f; double 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)
{ {
float factor; double 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;
float detail, depth; double detail, depth;
detail = renderer->getPrecision(renderer, location); detail = renderer->getPrecision(renderer, location);
@ -237,50 +237,42 @@ Color waterGetColor(WaterDefinition* definition, Renderer* renderer, Vector3 loc
return waterGetColorDetail(definition, renderer, location, look).final; return waterGetColorDetail(definition, renderer, location, look).final;
} }
static int _postProcessFragment(RenderFragment* fragment, Renderer* renderer, void* data) static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
{ {
fragment->vertex.color = waterGetColor((WaterDefinition*)data, renderer, fragment->vertex.location, v3Sub(fragment->vertex.location, renderer->camera_location)); return waterGetColor((WaterDefinition*)data, renderer, location, v3Sub(location, renderer->camera_location));
return 1;
} }
static Vertex _getFirstPassVertex(WaterDefinition* definition, float x, float z, float precision) static Vector3 _getFirstPassVertex(WaterDefinition* definition, double x, double z, double precision)
{ {
Vertex result; Vector3 result;
float value;
result.location.x = x; result.x = x;
result.location.y = _getHeight(definition, x, z, 0.0); result.y = _getHeight(definition, x, z, 0.0);
result.location.z = z; result.z = z;
value = sin(x) * sin(x) * cos(z) * cos(z);
result.color.r = 0.0;
result.color.g = value;
result.color.b = value;
result.color.a = 1.0;
result.callback = _postProcessFragment;
result.callback_data = definition;
return result; return result;
} }
static void _renderQuad(WaterDefinition* definition, Renderer* renderer, float x, float z, float size) static void _renderQuad(WaterDefinition* definition, Renderer* renderer, double x, double z, double size)
{ {
Vertex v1, v2, v3, v4; Vector3 v1, v2, v3, v4;
v1 = _getFirstPassVertex(definition, x, z, size); v1 = _getFirstPassVertex(definition, x, z, size);
v2 = _getFirstPassVertex(definition, x, z + size, size); v2 = _getFirstPassVertex(definition, x, z + size, size);
v3 = _getFirstPassVertex(definition, x + size, z + size, size); v3 = _getFirstPassVertex(definition, x + size, z + size, size);
v4 = _getFirstPassVertex(definition, x + size, z, size); v4 = _getFirstPassVertex(definition, x + size, z, size);
renderer->pushQuad(renderer, &v1, &v2, &v3, &v4);
renderer->pushQuad(renderer, v1, v2, v3, v4, _postProcessFragment, definition);
} }
void waterRender(WaterDefinition* definition, Renderer* renderer) void waterRender(WaterDefinition* definition, Renderer* renderer)
{ {
int chunk_factor, chunk_count, i; int chunk_factor, chunk_count, i;
float cx = renderer->camera_location.x; double cx = renderer->camera_location.x;
float cz = renderer->camera_location.z; double cz = renderer->camera_location.z;
float radius_int, radius_ext, base_chunk_size, chunk_size; double radius_int, radius_ext, base_chunk_size, chunk_size;
base_chunk_size = 2.0 / (float)renderer->render_quality; base_chunk_size = 2.0 / (double)renderer->render_quality;
chunk_factor = 1; chunk_factor = 1;
chunk_count = 2; chunk_count = 2;
@ -303,7 +295,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 && (float)chunk_factor < radius_int / 20.0) if (radius_int > 20.0 && chunk_count % 64 == 0 && (double)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
{ {
float height; double height;
float transparency; double transparency;
float reflection; double reflection;
SurfaceMaterial material; SurfaceMaterial material;
Color depth_color; Color depth_color;
float transparency_depth; double transparency_depth;
float lighting_depth; double lighting_depth;
NoiseGenerator* waves_noise; NoiseGenerator* waves_noise;
float waves_noise_height; double waves_noise_height;
float waves_noise_scale; double waves_noise_scale;
} WaterDefinition; } WaterDefinition;
typedef struct typedef struct

View file

@ -9,11 +9,11 @@
typedef struct typedef struct
{ {
float value; double value;
float centerx; double centerx;
float centerz; double centerz;
float softradius; double softradius;
float hardradius; double 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++)
{ {
packWriteFloat(stream, &zone->height_ranges[i].value); packWriteDouble(stream, &zone->height_ranges[i].value);
packWriteFloat(stream, &zone->height_ranges[i].hardmin); packWriteDouble(stream, &zone->height_ranges[i].hardmin);
packWriteFloat(stream, &zone->height_ranges[i].softmin); packWriteDouble(stream, &zone->height_ranges[i].softmin);
packWriteFloat(stream, &zone->height_ranges[i].softmax); packWriteDouble(stream, &zone->height_ranges[i].softmax);
packWriteFloat(stream, &zone->height_ranges[i].hardmax); packWriteDouble(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++)
{ {
packWriteFloat(stream, &zone->slope_ranges[i].value); packWriteDouble(stream, &zone->slope_ranges[i].value);
packWriteFloat(stream, &zone->slope_ranges[i].hardmin); packWriteDouble(stream, &zone->slope_ranges[i].hardmin);
packWriteFloat(stream, &zone->slope_ranges[i].softmin); packWriteDouble(stream, &zone->slope_ranges[i].softmin);
packWriteFloat(stream, &zone->slope_ranges[i].softmax); packWriteDouble(stream, &zone->slope_ranges[i].softmax);
packWriteFloat(stream, &zone->slope_ranges[i].hardmax); packWriteDouble(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++)
{ {
packWriteFloat(stream, &zone->circles_included[i].value); packWriteDouble(stream, &zone->circles_included[i].value);
packWriteFloat(stream, &zone->circles_included[i].centerx); packWriteDouble(stream, &zone->circles_included[i].centerx);
packWriteFloat(stream, &zone->circles_included[i].centerz); packWriteDouble(stream, &zone->circles_included[i].centerz);
packWriteFloat(stream, &zone->circles_included[i].softradius); packWriteDouble(stream, &zone->circles_included[i].softradius);
packWriteFloat(stream, &zone->circles_included[i].hardradius); packWriteDouble(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++)
{ {
packWriteFloat(stream, &zone->circles_excluded[i].value); packWriteDouble(stream, &zone->circles_excluded[i].value);
packWriteFloat(stream, &zone->circles_excluded[i].centerx); packWriteDouble(stream, &zone->circles_excluded[i].centerx);
packWriteFloat(stream, &zone->circles_excluded[i].centerz); packWriteDouble(stream, &zone->circles_excluded[i].centerz);
packWriteFloat(stream, &zone->circles_excluded[i].softradius); packWriteDouble(stream, &zone->circles_excluded[i].softradius);
packWriteFloat(stream, &zone->circles_excluded[i].hardradius); packWriteDouble(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++)
{ {
packReadFloat(stream, &zone->height_ranges[i].value); packReadDouble(stream, &zone->height_ranges[i].value);
packReadFloat(stream, &zone->height_ranges[i].hardmin); packReadDouble(stream, &zone->height_ranges[i].hardmin);
packReadFloat(stream, &zone->height_ranges[i].softmin); packReadDouble(stream, &zone->height_ranges[i].softmin);
packReadFloat(stream, &zone->height_ranges[i].softmax); packReadDouble(stream, &zone->height_ranges[i].softmax);
packReadFloat(stream, &zone->height_ranges[i].hardmax); packReadDouble(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++)
{ {
packReadFloat(stream, &zone->slope_ranges[i].value); packReadDouble(stream, &zone->slope_ranges[i].value);
packReadFloat(stream, &zone->slope_ranges[i].hardmin); packReadDouble(stream, &zone->slope_ranges[i].hardmin);
packReadFloat(stream, &zone->slope_ranges[i].softmin); packReadDouble(stream, &zone->slope_ranges[i].softmin);
packReadFloat(stream, &zone->slope_ranges[i].softmax); packReadDouble(stream, &zone->slope_ranges[i].softmax);
packReadFloat(stream, &zone->slope_ranges[i].hardmax); packReadDouble(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++)
{ {
packReadFloat(stream, &zone->circles_included[i].value); packReadDouble(stream, &zone->circles_included[i].value);
packReadFloat(stream, &zone->circles_included[i].centerx); packReadDouble(stream, &zone->circles_included[i].centerx);
packReadFloat(stream, &zone->circles_included[i].centerz); packReadDouble(stream, &zone->circles_included[i].centerz);
packReadFloat(stream, &zone->circles_included[i].softradius); packReadDouble(stream, &zone->circles_included[i].softradius);
packReadFloat(stream, &zone->circles_included[i].hardradius); packReadDouble(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++)
{ {
packReadFloat(stream, &zone->circles_excluded[i].value); packReadDouble(stream, &zone->circles_excluded[i].value);
packReadFloat(stream, &zone->circles_excluded[i].centerx); packReadDouble(stream, &zone->circles_excluded[i].centerx);
packReadFloat(stream, &zone->circles_excluded[i].centerz); packReadDouble(stream, &zone->circles_excluded[i].centerz);
packReadFloat(stream, &zone->circles_excluded[i].softradius); packReadDouble(stream, &zone->circles_excluded[i].softradius);
packReadFloat(stream, &zone->circles_excluded[i].hardradius); packReadDouble(stream, &zone->circles_excluded[i].hardradius);
} }
} }
@ -143,7 +143,7 @@ void zoneCopy(Zone* source, Zone* destination)
*destination = *source; *destination = *source;
} }
void zoneIncludeCircleArea(Zone* zone, float value, float centerx, float centerz, float softradius, float hardradius) void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius)
{ {
Circle circle = {value, centerx, centerz, softradius, hardradius}; Circle circle = {value, centerx, centerz, softradius, hardradius};
@ -153,7 +153,7 @@ void zoneIncludeCircleArea(Zone* zone, float value, float centerx, float centerz
} }
} }
void zoneExcludeCircleArea(Zone* zone, float centerx, float centerz, float softradius, float hardradius) void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double hardradius)
{ {
/* TODO */ /* TODO */
} }
@ -206,7 +206,7 @@ int zoneSetHeightRange(Zone* zone, int position, ZoneRangeCondition* range)
} }
} }
int zoneAddHeightRangeQuick(Zone* zone, float value, float hardmin, float softmin, float softmax, float hardmax) int zoneAddHeightRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double 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, float value, float hardmin, float softmin, float softmax, float hardmax) int zoneAddSlopeRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double 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, float value, float hardmin, float softmin
return position; return position;
} }
static inline float _getRangeInfluence(ZoneRangeCondition range, float position) static inline double _getRangeInfluence(ZoneRangeCondition range, double position)
{ {
if (position >= range.hardmin && position <= range.hardmax) if (position >= range.hardmin && position <= range.hardmax)
{ {
@ -303,9 +303,9 @@ static inline float _getRangeInfluence(ZoneRangeCondition range, float position)
} }
} }
static inline float _getCircleInfluence(Circle circle, Vector3 position) static inline double _getCircleInfluence(Circle circle, Vector3 position)
{ {
float radius, dx, dz; double 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 float _getCircleInfluence(Circle circle, Vector3 position)
} }
} }
float zoneGetValue(Zone* zone, Vector3 location, Vector3 normal) double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal)
{ {
int i; int i;
float value, value_height, value_steepness, value_circle; double 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
{ {
float value; double value;
float hardmin; double hardmin;
float softmin; double softmin;
float softmax; double softmax;
float hardmax; double 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, float value, float centerx, float centerz, float softradius, float hardradius); void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius);
void zoneExcludeCircleArea(Zone* zone, float centerx, float centerz, float softradius, float hardradius); void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double 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, float value, float hardmin, float softmin, float softmax, float hardmax); int zoneAddHeightRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double 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, float value, float hardmin, float softmin, float softmax, float hardmax); int zoneAddSlopeRangeQuick(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax);
float zoneGetValue(Zone* zone, Vector3 location, Vector3 normal); double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal);
#ifdef __cplusplus #ifdef __cplusplus
} }