paysages: Fixed memleaks + improved clouds lighting.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@265 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-02-12 16:57:29 +00:00 committed by ThunderK
parent 932552bc48
commit 8100fefad8
27 changed files with 106 additions and 8 deletions

2
TODO
View file

@ -3,3 +3,5 @@
- Implement scaling and scrolling on previews. - Implement scaling and scrolling on previews.
- Water and terrain LOD moves with the camera, fix it like in the wanderer. - Water and terrain LOD moves with the camera, fix it like in the wanderer.
- Restore render progress. - Restore render progress.
- Find a licence and apply it.
- Translate UI ?

View file

@ -111,7 +111,9 @@ int main(int argc, char** argv)
conf_daytime_start += conf_daytime_step; conf_daytime_start += conf_daytime_step;
} }
printf("Cleaning up ...\n");
rendererDelete(&renderer); rendererDelete(&renderer);
paysagesQuit();
printf("\rDone. \n"); printf("\rDone. \n");

View file

@ -24,6 +24,8 @@
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int result;
paysagesInit(); paysagesInit();
QApplication app(argc, argv); QApplication app(argc, argv);
@ -31,7 +33,10 @@ int main(int argc, char** argv)
window.show(); window.show();
return app.exec(); result = app.exec();
paysagesQuit();
return result;
} }
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :

View file

@ -9,7 +9,7 @@ void arrayCreate(Array* array, int item_size)
array->alloc_length = 3; array->alloc_length = 3;
array->item_size = item_size; array->item_size = item_size;
array->dirty = 1; array->dirty = 1;
array->data = malloc((size_t)item_size * 3); array->data = malloc((size_t)item_size * array->alloc_length);
} }
void arrayDelete(Array* array) void arrayDelete(Array* array)

View file

@ -10,6 +10,10 @@ void atmosphereInit()
{ {
} }
void atmosphereQuit()
{
}
void atmosphereSave(FILE* f, AtmosphereDefinition* definition) void atmosphereSave(FILE* f, AtmosphereDefinition* definition)
{ {
toolsSaveDouble(f, &definition->distance_near); toolsSaveDouble(f, &definition->distance_near);

View file

@ -19,6 +19,7 @@ typedef struct
} AtmosphereDefinition; } AtmosphereDefinition;
void atmosphereInit(); void atmosphereInit();
void atmosphereQuit();
void atmosphereSave(FILE* f, AtmosphereDefinition* definition); void atmosphereSave(FILE* f, AtmosphereDefinition* definition);
void atmosphereLoad(FILE* f, AtmosphereDefinition* definition); void atmosphereLoad(FILE* f, AtmosphereDefinition* definition);

View file

@ -62,7 +62,6 @@ void autoGenRealisticLandscape(int seed)
TerrainDefinition terrain; TerrainDefinition terrain;
WaterDefinition water; WaterDefinition water;
CloudsDefinition clouds; CloudsDefinition clouds;
CloudsLayerDefinition* cloud;
SkyDefinition sky; SkyDefinition sky;
TexturesDefinition textures; TexturesDefinition textures;
TextureLayerDefinition* texture; TextureLayerDefinition* texture;
@ -78,7 +77,7 @@ void autoGenRealisticLandscape(int seed)
/* Cloud layer */ /* Cloud layer */
clouds = cloudsCreateDefinition(); clouds = cloudsCreateDefinition();
cloud = cloudsGetLayer(&clouds, cloudsAddLayer(&clouds)); cloudsAddLayer(&clouds);
scenerySetClouds(&clouds); scenerySetClouds(&clouds);
cloudsDeleteDefinition(&clouds); cloudsDeleteDefinition(&clouds);
@ -163,6 +162,7 @@ void autoGenRealisticLandscape(int seed)
zoneIncludeCircleArea(zone, 0.8, 0.0, 0.0, 0.3, 4.0); zoneIncludeCircleArea(zone, 0.8, 0.0, 0.0, 0.3, 4.0);
modifierActionFixValue(mod, -8.0); modifierActionFixValue(mod, -8.0);
terrainAddModifier(&terrain, mod); terrainAddModifier(&terrain, mod);
modifierDelete(mod);
/* DEBUG */ /* DEBUG */
scenerySetTerrain(&terrain); scenerySetTerrain(&terrain);
terrainDeleteDefinition(&terrain); terrainDeleteDefinition(&terrain);

View file

@ -13,6 +13,10 @@ void cameraInit()
{ {
} }
void cameraQuit()
{
}
void cameraSave(FILE* f, CameraDefinition* camera) void cameraSave(FILE* f, CameraDefinition* camera)
{ {
v3Save(f, &camera->location); v3Save(f, &camera->location);

View file

@ -10,6 +10,7 @@ extern "C" {
#endif #endif
void cameraInit(); void cameraInit();
void cameraQuit();
void cameraSave(FILE* f, CameraDefinition* camera); void cameraSave(FILE* f, CameraDefinition* camera);
void cameraLoad(FILE* f, CameraDefinition* camera); void cameraLoad(FILE* f, CameraDefinition* camera);

View file

@ -27,6 +27,11 @@ void cloudsInit()
cloudsLayerValidateDefinition(&NULL_LAYER); cloudsLayerValidateDefinition(&NULL_LAYER);
} }
void cloudsQuit()
{
cloudsLayerDeleteDefinition(&NULL_LAYER);
}
void cloudsSave(FILE* f, CloudsDefinition* definition) void cloudsSave(FILE* f, CloudsDefinition* definition)
{ {
int i; int i;
@ -476,10 +481,10 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
{ {
Vector3 normal; Vector3 normal;
normal = v3Scale(_getNormal(definition, position, 1.0), 0.25); normal = v3Scale(_getNormal(definition, position, 3.0), 0.25);
normal = v3Add(normal, v3Scale(_getNormal(definition, position, 2.0), 0.25));
normal = v3Add(normal, v3Scale(_getNormal(definition, position, 1.0), 0.25));
normal = v3Add(normal, v3Scale(_getNormal(definition, position, 0.5), 0.25)); normal = v3Add(normal, v3Scale(_getNormal(definition, position, 0.5), 0.25));
normal = v3Add(normal, v3Scale(_getNormal(definition, position, 0.2), 0.25));
normal = v3Add(normal, v3Scale(_getNormal(definition, position, 0.1), 0.25));
normal = v3Scale(v3Normalize(normal), 0.1); normal = v3Scale(v3Normalize(normal), 0.1);
return renderer->applyLightingToSurface(renderer, position, normal, definition->material); return renderer->applyLightingToSurface(renderer, position, normal, definition->material);

View file

@ -38,6 +38,7 @@ typedef struct
} CloudsDefinition; } CloudsDefinition;
void cloudsInit(); void cloudsInit();
void cloudsQuit();
void cloudsSave(FILE* f, CloudsDefinition* definition); void cloudsSave(FILE* f, CloudsDefinition* definition);
void cloudsLoad(FILE* f, CloudsDefinition* definition); void cloudsLoad(FILE* f, CloudsDefinition* definition);

View file

@ -30,6 +30,10 @@ void lightingInit()
_LIGHT_NULL.amplitude = 0.0; _LIGHT_NULL.amplitude = 0.0;
} }
void lightingQuit()
{
}
void lightingSave(FILE* f, LightingDefinition* definition) void lightingSave(FILE* f, LightingDefinition* definition)
{ {
int i; int i;

View file

@ -31,6 +31,7 @@ typedef struct
} LightingDefinition; } LightingDefinition;
void lightingInit(); void lightingInit();
void lightingQuit();
void lightingSave(FILE* f, LightingDefinition* definition); void lightingSave(FILE* f, LightingDefinition* definition);
void lightingLoad(FILE* f, LightingDefinition* definition); void lightingLoad(FILE* f, LightingDefinition* definition);

View file

@ -47,6 +47,12 @@ void paysagesInit()
cameraSetTarget(x - 1.0, height, 0.0);*/ cameraSetTarget(x - 1.0, height, 0.0);*/
} }
void paysagesQuit()
{
sceneryQuit();
renderQuit();
}
void paysagesSave(char* filepath) void paysagesSave(char* filepath)
{ {
scenerySaveToFile(filepath); scenerySaveToFile(filepath);

View file

@ -6,6 +6,7 @@ extern "C" {
#endif #endif
void paysagesInit(); void paysagesInit();
void paysagesQuit();
void paysagesSave(char* filepath); void paysagesSave(char* filepath);
void paysagesLoad(char* filepath); void paysagesLoad(char* filepath);

View file

@ -44,6 +44,10 @@ void renderInit()
{ {
} }
void renderQuit()
{
}
RenderArea* renderCreateArea() RenderArea* renderCreateArea()
{ {
RenderArea* result; RenderArea* result;
@ -74,8 +78,19 @@ RenderArea* renderCreateArea()
void renderDeleteArea(RenderArea* area) void renderDeleteArea(RenderArea* area)
{ {
int x;
int y;
for (x = 0; x < area->width; x++)
{
for (y = 0; y < area->height; y++)
{
arrayDelete(area->pixels + (y * area->width + x));
}
}
mutexDestroy(area->lock); mutexDestroy(area->lock);
arrayDelete(area->pixels); free(area->pixels);
free(area->scanline_up); free(area->scanline_up);
free(area->scanline_down); free(area->scanline_down);
free(area); free(area);

View file

@ -10,6 +10,8 @@ extern "C" {
#endif #endif
void renderInit(); void renderInit();
void renderQuit();
RenderArea* renderCreateArea(); RenderArea* renderCreateArea();
void renderDeleteArea(RenderArea* area); void renderDeleteArea(RenderArea* area);

View file

@ -36,6 +36,27 @@ void sceneryInit()
_water = waterCreateDefinition(); _water = waterCreateDefinition();
} }
void sceneryQuit()
{
atmosphereDeleteDefinition(&_atmosphere);
cameraDeleteDefinition(&_camera);
cloudsDeleteDefinition(&_clouds);
lightingDeleteDefinition(&_lighting);
skyDeleteDefinition(&_sky);
terrainDeleteDefinition(&_terrain);
texturesDeleteDefinition(&_textures);
waterDeleteDefinition(&_water);
atmosphereQuit();
cameraQuit();
cloudsQuit();
lightingQuit();
skyQuit();
terrainQuit();
texturesQuit();
waterQuit();
}
void scenerySaveToFile(char* filepath) void scenerySaveToFile(char* filepath)
{ {
FILE* f = fopen(filepath, "wb"); FILE* f = fopen(filepath, "wb");

View file

@ -24,6 +24,8 @@ extern "C" {
#endif #endif
void sceneryInit(); void sceneryInit();
void sceneryQuit();
void scenerySaveToFile(char* filepath); void scenerySaveToFile(char* filepath);
void sceneryLoadFromFile(char* filepath); void sceneryLoadFromFile(char* filepath);

View file

@ -18,6 +18,10 @@ void skyInit()
{ {
} }
void skyQuit()
{
}
void skySave(FILE* f, SkyDefinition* definition) void skySave(FILE* f, SkyDefinition* definition)
{ {
toolsSaveDouble(f, &definition->daytime); toolsSaveDouble(f, &definition->daytime);

View file

@ -22,6 +22,7 @@ typedef struct
} SkyDefinition; } SkyDefinition;
void skyInit(); void skyInit();
void skyQuit();
void skySave(FILE* f, SkyDefinition* definition); void skySave(FILE* f, SkyDefinition* definition);
void skyLoad(FILE* f, SkyDefinition* definition); void skyLoad(FILE* f, SkyDefinition* definition);

View file

@ -17,6 +17,10 @@ void terrainInit()
{ {
} }
void terrainQuit()
{
}
void terrainSave(FILE* f, TerrainDefinition* definition) void terrainSave(FILE* f, TerrainDefinition* definition)
{ {
int i; int i;

View file

@ -25,6 +25,7 @@ typedef struct
} TerrainDefinition; } TerrainDefinition;
void terrainInit(); void terrainInit();
void terrainQuit();
void terrainSave(FILE* f, TerrainDefinition* definition); void terrainSave(FILE* f, TerrainDefinition* definition);
void terrainLoad(FILE* f, TerrainDefinition* definition); void terrainLoad(FILE* f, TerrainDefinition* definition);

View file

@ -20,6 +20,11 @@ void texturesInit()
_NULL_LAYER = texturesLayerCreateDefinition(); _NULL_LAYER = texturesLayerCreateDefinition();
} }
void texturesQuit()
{
texturesLayerDeleteDefinition(&_NULL_LAYER);
}
void texturesSave(FILE* f, TexturesDefinition* definition) void texturesSave(FILE* f, TexturesDefinition* definition)
{ {
int i; int i;

View file

@ -26,6 +26,7 @@ typedef struct
} TexturesDefinition; } TexturesDefinition;
void texturesInit(); void texturesInit();
void texturesQuit();
void texturesSave(FILE* f, TexturesDefinition* definition); void texturesSave(FILE* f, TexturesDefinition* definition);
void texturesLoad(FILE* f, TexturesDefinition* definition); void texturesLoad(FILE* f, TexturesDefinition* definition);

View file

@ -15,6 +15,10 @@ void waterInit()
{ {
} }
void waterQuit()
{
}
void waterSave(FILE* f, WaterDefinition* definition) void waterSave(FILE* f, WaterDefinition* definition)
{ {
toolsSaveDouble(f, &definition->height); toolsSaveDouble(f, &definition->height);

View file

@ -35,6 +35,7 @@ typedef struct
} WaterResult; } WaterResult;
void waterInit(); void waterInit();
void waterQuit();
void waterSave(FILE* f, WaterDefinition* definition); void waterSave(FILE* f, WaterDefinition* definition);
void waterLoad(FILE* f, WaterDefinition* definition); void waterLoad(FILE* f, WaterDefinition* definition);