paysages: Sources refactoring (splitting lib and gui).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@200 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2011-12-23 22:39:13 +00:00 committed by ThunderK
parent bfd25bcf42
commit ef68f38061
14 changed files with 88 additions and 157 deletions

View file

@ -1,7 +1,9 @@
all:
cd lib_paysages && make
cd gui_gtk && make
clean:
cd lib_paysages && make clean
cd gui_gtk && make clean
.PHONY:all clean

21
gui_gtk/Makefile Normal file
View file

@ -0,0 +1,21 @@
SOURCES=$(wildcard *.c)
OBJECTS=${SOURCES:.c=.o}
HEADERS=$(wildcard ../lib_paysages/shared/*.h ../lib_paysages/*.h *.h)
RESULT=paysages-gtk
CC_FLAGS=-g -pg -Wall $(shell pkg-config --cflags gtk+-3.0) -I..
CC_LDFLAGS=$(shell pkg-config --libs gtk+-3.0) -L../lib_paysages/ -lpaysages
all:${RESULT}
clean:
rm -f ${OBJECTS}
rm -f ${RESULT}
%.o:%.c ${HEADERS}
${CC} -c ${CC_FLAGS} $< -o $@
${RESULT}:${OBJECTS}
${CC} $^ ${CC_LDFLAGS} -o $@
.PHONY:all clean

View file

@ -1,7 +1,7 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "../shared/types.h"
#include "lib_paysages/shared/types.h"
#include <stdio.h>
@ -24,6 +24,8 @@ static inline GtkWidget* _get_widget(const char* name, const char* file, int lin
}
#define GET_WIDGET(_name_) (_get_widget(_name_, __FILE__, __LINE__))
void guiUpdate();
void guiTerrainInit();
void guiWaterInit();

View file

@ -1,8 +1,8 @@
/* Noise editor dialog */
#include "common.h"
#include "../shared/functions.h"
#include "../shared/constants.h"
#include "lib_paysages/shared/functions.h"
#include "lib_paysages/shared/constants.h"
static GtkWidget* _dialog;
static SmallPreview* _preview;
@ -28,13 +28,13 @@ static Color _cbPreview2DRenderPixel(SmallPreview* preview, double x, double y,
{
Color col;
double max_value;
/* TODO Cache this value */
max_value = noiseGetMaxValue(_generator);
col.r = col.g = col.b = (noiseGet2DTotal(_generator, x, y) / max_value) * 0.5 + 0.5;
col.a = 1.0;
return col;
}
@ -42,16 +42,16 @@ static void _setPreviewMode(int mode)
{
GtkButton* button;
double max_value;
max_value = noiseGetMaxValue(_generator);
button = GTK_BUTTON(GET_WIDGET("noise_editor_preview_mode"));
if (mode == 1)
{
_current_mode = 1;
guiPreviewSetRenderer(_preview, _cbPreview1DRenderPixel);
gtk_button_set_label(button, "1D");
guiPreviewConfigScrolling(_preview, -max_value * 100.0, max_value * 100.0, -max_value, max_value);
}
else if (mode == 2)
@ -59,10 +59,10 @@ static void _setPreviewMode(int mode)
_current_mode = 2;
guiPreviewSetRenderer(_preview, _cbPreview2DRenderPixel);
gtk_button_set_label(button, "2D");
guiPreviewConfigScrolling(_preview, -max_value * 100.0, max_value * 100.0, -max_value * 100.0, max_value * 100.0);
}
guiPreviewConfigScaling(_preview, max_value * 0.001, max_value * 0.1, max_value * 0.001);
guiPreviewSetViewport(_preview, 0.0, 0.0, max_value * 0.01);
}
@ -75,7 +75,7 @@ static void _redrawPreview()
static void _resetPreview()
{
_setPreviewMode(_current_mode);
_redrawPreview();
}

View file

@ -2,8 +2,8 @@
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "../shared/functions.h"
#include "../shared/constants.h"
#include "lib_paysages/shared/functions.h"
#include "lib_paysages/shared/constants.h"
#include "common.h"
GtkBuilder* gui_definition;
@ -106,3 +106,11 @@ void guiUpdate()
guiPreviewRedrawAll();
}
int main(int argc, char** argv)
{
paysagesInit();
guiInit();
guiStart();
return 0;
}

View file

@ -3,11 +3,10 @@
#include <string.h>
#include <math.h>
#include "common.h"
#include "../shared/types.h"
#include "../shared/functions.h"
#include "../shared/constants.h"
#include "../shared/system.h"
#include "../water.h"
#include "lib_paysages/shared/types.h"
#include "lib_paysages/shared/functions.h"
#include "lib_paysages/shared/constants.h"
#include "lib_paysages/shared/system.h"
#define MAX_PREVIEWS 30
@ -17,7 +16,7 @@ struct SmallPreview
double conf_scroll_xmax;
double conf_scroll_ymin;
double conf_scroll_ymax;
double conf_scale_min;
double conf_scale_max;
double conf_scale_step;
@ -241,7 +240,7 @@ static inline int _fixScaling(SmallPreview* preview, double scaling, double* new
static int _cbMouseScroll(GtkEventBox* image, GdkEventScroll* event, gpointer data)
{
SmallPreview* preview = (SmallPreview*)data;
/* TODO Center the zoom on the cursor */
if (event->direction == GDK_SCROLL_UP)
@ -262,7 +261,7 @@ static int _cbMouseScroll(GtkEventBox* image, GdkEventScroll* event, gpointer da
}
mutexRelease(preview->lock);
}
return 1;
}
@ -287,18 +286,18 @@ static int _cbMouseMove(GtkEventBox* image, GdkEventMotion* event, gpointer data
if (event->state & GDK_BUTTON1_MASK)
{
mutexAcquire(preview->lock);
dx = (int)event->x - preview->mousex;
dy = (int)event->y - preview->mousey;
if (_fixScroll(preview, dx, dy, &dx, &dy))
{
_scrollPixbuf(preview, dx, dy);
}
preview->mousex = (int)event->x;
preview->mousey = (int)event->y;
mutexRelease(preview->lock);
}

View file

@ -1,9 +1,9 @@
/* Terrain tab */
#include "common.h"
#include "../shared/functions.h"
#include "../shared/constants.h"
#include "../clouds.h"
#include "lib_paysages/shared/functions.h"
#include "lib_paysages/shared/constants.h"
#include "lib_paysages/clouds.h"
#include <math.h>
static SmallPreview* _preview;
@ -21,16 +21,16 @@ static void _revertCurrentLayer()
{
cloudsCopyDefinition(cloudsGetDefinition(_current_layer), &_definition);
}
/* TODO Revert layer from config */
guiPreviewRedraw(_preview);
}
static void _applyCurrentLayer()
{
/* TODO Apply layer config */
guiUpdate();
}
@ -48,7 +48,7 @@ static void _revertAll()
gtk_list_store_append(_list_layers_model, &row);
gtk_list_store_set(_list_layers_model, &row, 0, layer.ymin, 1, layer.ymax - layer.ymin, -1);
}
if (_current_layer < 0 || _current_layer >= n)
{
_current_layer = -1;
@ -62,7 +62,7 @@ static Color _cbPreviewPixel(SmallPreview* preview, double x, double y, double x
{
Color result, layer_color;
Vector3 start, end;
if (_current_layer < 0)
{
return COLOR_BLACK;
@ -118,7 +118,7 @@ void guiCloudsInit()
guiPreviewConfigScrolling(_preview, -10000.0, 10000.0, -10000.0, 10000.0);
guiPreviewSetViewport(_preview, 0.0, 0.0, 10.0);
guiPreviewSetRenderer(_preview, _cbPreviewPixel);
g_signal_connect(_list_layers, "cursor-changed", G_CALLBACK(_cbLayerSelected), NULL);
guiCloudsUpdate();

View file

@ -1,10 +1,10 @@
/* Terrain tab */
#include "common.h"
#include "../shared/functions.h"
#include "../shared/constants.h"
#include "../shared/globals.h"
#include "../shared/system.h"
#include "lib_paysages/shared/functions.h"
#include "lib_paysages/shared/constants.h"
#include "lib_paysages/shared/globals.h"
#include "lib_paysages/shared/system.h"
static GtkImage* _render_final;
static GdkPixbuf* _render_buffer = NULL;
@ -59,20 +59,20 @@ static void* _threadRender(void* data)
static void _cbStartRender(GtkWidget* widget, gpointer data)
{
Thread* thread;
/* Prepare render */
renderSetSize(gtk_spin_button_get_value(GTK_SPIN_BUTTON(GET_WIDGET("render_width"))), gtk_spin_button_get_value(GTK_SPIN_BUTTON(GET_WIDGET("render_height"))));
autoSetRenderQuality((int)gtk_range_get_value(GTK_RANGE(GET_WIDGET("render_quality"))));
gtk_widget_set_size_request(GET_WIDGET("render_preview"), render_width, render_height);
gtk_image_clear(GTK_IMAGE(GET_WIDGET("render_preview")));
renderSetPreviewCallbacks(_previewResize, _previewClear, _previewDraw, _previewUpdate);
/* Open render dialog */
gtk_window_set_deletable(GTK_WINDOW(GET_WIDGET("dialog_render")), 0);
gtk_widget_show(GET_WIDGET("dialog_render"));
gtk_widget_set_sensitive(GET_WIDGET("render_stop"), 1);
gtk_widget_set_sensitive(GET_WIDGET("render_close"), 0);
/* Do the render */
_rendering = 1;
thread = threadCreate(_threadRender, NULL);
@ -85,7 +85,7 @@ static void _cbStartRender(GtkWidget* widget, gpointer data)
}
}
threadJoin(thread);
/* Clean up */
renderSetPreviewCallbacks(NULL, NULL, NULL, NULL);
gtk_widget_set_sensitive(GET_WIDGET("render_stop"), 0);

View file

@ -1,9 +1,9 @@
/* Terrain tab */
#include "common.h"
#include "../shared/functions.h"
#include "../shared/constants.h"
#include "../sky.h"
#include "lib_paysages/shared/functions.h"
#include "lib_paysages/shared/constants.h"
#include "lib_paysages/sky.h"
#include <math.h>
static SmallPreview* _preview_horizon;

View file

@ -1,7 +1,7 @@
/* Terrain tab */
#include "common.h"
#include "../shared/functions.h"
#include "lib_paysages/shared/functions.h"
static SmallPreview* _preview;
@ -11,7 +11,7 @@ static Color _cbPreviewRenderPixel(SmallPreview* preview, double x, double y, do
result.r = result.g = result.b = terrainGetHeightNormalized(x, y);
result.a = 1.0;
return result;
}
@ -30,7 +30,7 @@ static void _cbEditNoise(GtkWidget* widget, gpointer data)
void guiTerrainInit()
{
g_signal_connect(GET_WIDGET("terrain_noise_edit"), "clicked", G_CALLBACK(_cbEditNoise), NULL);
_preview = guiPreviewNew(GTK_IMAGE(GET_WIDGET("terrain_preview")));
guiPreviewConfigScaling(_preview, 0.01, 1.0, 0.05);
guiPreviewConfigScrolling(_preview, -1000.0, 1000.0, -1000.0, 1000.0);

View file

@ -1,9 +1,9 @@
/* Terrain tab */
#include "common.h"
#include "../shared/functions.h"
#include "../shared/constants.h"
#include "../water.h"
#include "lib_paysages/shared/functions.h"
#include "lib_paysages/shared/constants.h"
#include "lib_paysages/water.h"
#include <math.h>
static SmallPreview* _preview_coverage;

View file

@ -3,7 +3,7 @@ OBJECTS=${SOURCES:.c=.o}
HEADERS=$(wildcard shared/*.h *.h)
RESULT=libpaysages.so
CC_FLAGS=-g -pg -Wall $(shell pkg-config --cflags glib-2.0)
CC_LDFLAGS=$(shell pkg-config --libs glib-2.0)
CC_LDFLAGS=$(shell pkg-config --libs glib-2.0) -lIL -lILU
all:${RESULT}
@ -15,7 +15,7 @@ clean:
${CC} -c ${CC_FLAGS} $< -o $@
${RESULT}:${OBJECTS}
${CC} -o $@ -shared -Wl ${CC_LDFLAGS} $*
${CC} $^ -shared ${CC_LDFLAGS} -o $@
.PHONY:all clean

View file

@ -12,94 +12,8 @@
#include "shared/functions.h"
#include "shared/globals.h"
/*static char _filename[22];
static void _setupFilename(int number)
void paysagesInit()
{
_filename[15] = (char)(97 + number / 26);
_filename[16] = (char)(97 + number % 26);
}
static void _doRender(int number, int postonly)
{
_setupFilename(number);
fprintf(stderr, "Rendering %s...\n", _filename);
autoRenderAll(postonly);
fprintf(stderr, "Saving %s...\n", _filename);
remove(_filename);
renderSaveToFile(_filename);
}
static void _renderTurnTable(int count)
{
int i;
for (i = 0; i < count; i++)
{
cameraSetLocation(sin(M_PI * 2.0 * (double)i / (double)count) * 20.0, 8.0, cos(M_PI * 2.0 * (double)i / (double)count) * 20.0);
_doRender(i, 0);
}
}
static void _renderFly(int count, double speed)
{
int i;
double x, y, z, ty1;
x = 0.0;
y = 8.0;
z = 0.0;
for (i = 0; i < count; i++)
{
cameraSetLocation(x, y, z);
cameraSetTarget(x, y, z + 1.0);
_doRender(i, 0);
ty1 = terrainGetHeight(x, z);
if (y > ty1 + 9.0)
{
y -= speed;
}
if (y < ty1 + 7.0)
{
y += speed;
}
z += speed;
}
}
static void _renderDayTime(int count)
{
int i;
for (i = 0; i < count; i++)
{
autoSetDaytimeFraction(0.4 + (double)i / (double)count);
_doRender(i, i > 0 ? 1 : 0);
}
}
static void _renderQuality()
{
int i;
for (i = 1; i <= 10; i++)
{
autoSetRenderQuality(i);
renderSetSize(800, 600);
_doRender(i - 1, 0);
}
}*/
int main(int argc, char** argv)
{
/*strcpy(_filename, "./output/result__.png");*/
ilInit();
iluInit();
@ -107,20 +21,8 @@ int main(int argc, char** argv)
cameraSetTarget(0.0, 5.0, 0.0);
autoInit();
guiInit();
autoSetRenderQuality(5);
autoGenRealisticLandscape(0);
autoSetDaytime(8, 30);
guiStart();
//_doRender(0, 0);
//_renderTurnTable(600);
//_renderDayTime(600);
//_renderFly(600, 0.1);
//_renderQuality();
return 0;
}

View file

@ -4,6 +4,8 @@
#include "types.h"
#include <stdio.h>
void paysagesInit();
/* array.c */
void arrayCreate(Array* array, int item_size);
void arrayDelete(Array* array);
@ -91,11 +93,6 @@ void fogSetColor(Color col);
void fogSetDistance(double near, double far);
Color fogApplyToLocation(Vector3 location, Color base);
/* gui.c */
void guiInit();
void guiStart();
void guiUpdate();
/* lighting.c */
void lightingSave(FILE* f);
void lightingLoad(FILE* f);