paysages : Re-enabled modifiers.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@212 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
867ba2513f
commit
e3f692800b
7 changed files with 124 additions and 32 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "lib_paysages/shared/functions.h"
|
#include "lib_paysages/shared/functions.h"
|
||||||
#include "lib_paysages/shared/constants.h"
|
#include "lib_paysages/shared/constants.h"
|
||||||
#include "lib_paysages/water.h"
|
#include "lib_paysages/water.h"
|
||||||
|
#include "lib_paysages/terrain.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
static SmallPreview* _preview_coverage;
|
static SmallPreview* _preview_coverage;
|
||||||
|
|
|
@ -225,6 +225,25 @@ void autoGenRealisticLandscape(int seed)
|
||||||
noiseGenerateBaseNoise(terrain.height_noise, 1048576);
|
noiseGenerateBaseNoise(terrain.height_noise, 1048576);
|
||||||
noiseAddLevelsSimple(terrain.height_noise, 10, 10.0, 1.0);
|
noiseAddLevelsSimple(terrain.height_noise, 10, 10.0, 1.0);
|
||||||
noiseNormalizeHeight(terrain.height_noise, -12.0, 12.0, 0);
|
noiseNormalizeHeight(terrain.height_noise, -12.0, 12.0, 0);
|
||||||
|
/* DEBUG */
|
||||||
|
mod = modifierCreate();
|
||||||
|
zone = modifierGetZone(mod);
|
||||||
|
zoneIncludeCircleArea(zone, 0.4, 0.0, 0.0, 8.0, 20.0);
|
||||||
|
modifierActionFixValue(mod, -2.0);
|
||||||
|
terrainAddModifier(&terrain, mod);
|
||||||
|
modifierDelete(mod);
|
||||||
|
mod = modifierCreate();
|
||||||
|
zone = modifierGetZone(mod);
|
||||||
|
zoneIncludeCircleArea(zone, 1.0, 0.0, 0.0, 0.3, 8.0);
|
||||||
|
modifierActionAddValue(mod, 8.0);
|
||||||
|
terrainAddModifier(&terrain, mod);
|
||||||
|
modifierDelete(mod);
|
||||||
|
mod = modifierCreate();
|
||||||
|
zone = modifierGetZone(mod);
|
||||||
|
zoneIncludeCircleArea(zone, 0.8, 0.0, 0.0, 0.3, 4.0);
|
||||||
|
modifierActionFixValue(mod, -8.0);
|
||||||
|
terrainAddModifier(&terrain, mod);
|
||||||
|
/* DEBUG */
|
||||||
terrainSetDefinition(terrain);
|
terrainSetDefinition(terrain);
|
||||||
terrainDeleteDefinition(terrain);
|
terrainDeleteDefinition(terrain);
|
||||||
|
|
||||||
|
@ -261,23 +280,6 @@ void autoGenRealisticLandscape(int seed)
|
||||||
texturesSetDefinition(layer, texture);
|
texturesSetDefinition(layer, texture);
|
||||||
texturesDeleteDefinition(texture);*/
|
texturesDeleteDefinition(texture);*/
|
||||||
|
|
||||||
/* DEBUG */
|
|
||||||
/*mod = modifierCreate();
|
|
||||||
zone = modifierGetZone(mod);
|
|
||||||
zoneIncludeCircleArea(zone, 0.4, 0.0, 0.0, 8.0, 20.0);
|
|
||||||
modifierActionFixValue(mod, -2.0);
|
|
||||||
terrainAddModifier(mod);
|
|
||||||
mod = modifierCreate();
|
|
||||||
zone = modifierGetZone(mod);
|
|
||||||
zoneIncludeCircleArea(zone, 1.0, 0.0, 0.0, 0.3, 8.0);
|
|
||||||
modifierActionAddValue(mod, 8.0);
|
|
||||||
terrainAddModifier(mod);
|
|
||||||
mod = modifierCreate();
|
|
||||||
zone = modifierGetZone(mod);
|
|
||||||
zoneIncludeCircleArea(zone, 0.8, 0.0, 0.0, 0.3, 4.0);
|
|
||||||
modifierActionFixValue(mod, -8.0);
|
|
||||||
terrainAddModifier(mod);*/
|
|
||||||
|
|
||||||
fogSetDistance(20.0, 100.0);
|
fogSetDistance(20.0, 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ void paysagesInit()
|
||||||
autoSetDaytime(8, 30);
|
autoSetDaytime(8, 30);
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
double 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)
|
||||||
|
@ -38,5 +38,5 @@ void paysagesInit()
|
||||||
x += 0.1;
|
x += 0.1;
|
||||||
}
|
}
|
||||||
cameraSetLocation(x - 2.0, height, 0.0);
|
cameraSetLocation(x - 2.0, height, 0.0);
|
||||||
cameraSetTarget(x - 1.0, height, 0.0);
|
cameraSetTarget(x - 1.0, height, 0.0);*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,39 @@ HeightModifier* modifierCreate()
|
||||||
return modifier;
|
return modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HeightModifier* modifierCreateCopy(HeightModifier* source)
|
||||||
|
{
|
||||||
|
HeightModifier* result;
|
||||||
|
|
||||||
|
result = (HeightModifier*)malloc(sizeof(HeightModifier));
|
||||||
|
result->zone = zoneCreate();
|
||||||
|
zoneCopy(source->zone, result->zone);
|
||||||
|
result->mode = source->mode;
|
||||||
|
result->value = source->value;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void modifierDelete(HeightModifier* modifier)
|
void modifierDelete(HeightModifier* modifier)
|
||||||
{
|
{
|
||||||
zoneDelete(modifier->zone);
|
zoneDelete(modifier->zone);
|
||||||
free(modifier);
|
free(modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void modifierSave(HeightModifier* modifier, FILE* f)
|
||||||
|
{
|
||||||
|
toolsSaveInt(f, modifier->mode);
|
||||||
|
toolsSaveDouble(f, modifier->value);
|
||||||
|
zoneSave(modifier->zone, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void modifierLoad(HeightModifier* modifier, FILE* f)
|
||||||
|
{
|
||||||
|
modifier->mode = toolsLoadInt(f);
|
||||||
|
modifier->value = toolsLoadDouble(f);
|
||||||
|
zoneLoad(modifier->zone, f);
|
||||||
|
}
|
||||||
|
|
||||||
Zone* modifierGetZone(HeightModifier* modifier)
|
Zone* modifierGetZone(HeightModifier* modifier)
|
||||||
{
|
{
|
||||||
return modifier->zone;
|
return modifier->zone;
|
||||||
|
|
|
@ -107,9 +107,10 @@ Color lightingApply(Vector3 location, Vector3 normal, double shadowing, Color ba
|
||||||
|
|
||||||
/* modifiers.c */
|
/* modifiers.c */
|
||||||
HeightModifier* modifierCreate();
|
HeightModifier* modifierCreate();
|
||||||
|
HeightModifier* modifierCreateCopy(HeightModifier* source);
|
||||||
void modifierDelete(HeightModifier* modifier);
|
void modifierDelete(HeightModifier* modifier);
|
||||||
void modifierSave(HeightModifier* zone, FILE* f);
|
void modifierSave(HeightModifier* modifier, FILE* f);
|
||||||
void modifierLoad(HeightModifier* zone, FILE* f);
|
void modifierLoad(HeightModifier* modifier, FILE* f);
|
||||||
Zone* modifierGetZone(HeightModifier* modifier);
|
Zone* modifierGetZone(HeightModifier* modifier);
|
||||||
void modifierActionAddValue(HeightModifier* modifier, double value);
|
void modifierActionAddValue(HeightModifier* modifier, double value);
|
||||||
void modifierActionFixValue(HeightModifier* modifier, double value);
|
void modifierActionFixValue(HeightModifier* modifier, double value);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "shared/types.h"
|
#include "shared/types.h"
|
||||||
#include "shared/functions.h"
|
#include "shared/functions.h"
|
||||||
|
@ -10,16 +11,11 @@
|
||||||
#include "water.h"
|
#include "water.h"
|
||||||
#include "terrain.h"
|
#include "terrain.h"
|
||||||
|
|
||||||
#define MAX_MODIFIERS 50
|
|
||||||
|
|
||||||
static TerrainDefinition _definition;
|
static TerrainDefinition _definition;
|
||||||
static TerrainQuality _quality;
|
static TerrainQuality _quality;
|
||||||
static TerrainEnvironment _environment;
|
static TerrainEnvironment _environment;
|
||||||
static double _max_height = 1.0;
|
static double _max_height = 1.0;
|
||||||
|
|
||||||
static int _modifiers_count = 0;
|
|
||||||
static HeightModifier* _modifiers[MAX_MODIFIERS];
|
|
||||||
|
|
||||||
void terrainInit()
|
void terrainInit()
|
||||||
{
|
{
|
||||||
_definition = terrainCreateDefinition();
|
_definition = terrainCreateDefinition();
|
||||||
|
@ -28,15 +24,33 @@ void terrainInit()
|
||||||
|
|
||||||
void terrainSave(FILE* f)
|
void terrainSave(FILE* f)
|
||||||
{
|
{
|
||||||
noiseSave(_definition.height_noise, f);
|
int i;
|
||||||
|
|
||||||
/* TODO Modifiers */
|
noiseSave(_definition.height_noise, f);
|
||||||
|
toolsSaveInt(f, _definition.height_modifiers_count);
|
||||||
|
for (i = 0; i < _definition.height_modifiers_count; i++)
|
||||||
|
{
|
||||||
|
modifierSave(_definition.height_modifiers[i], f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void terrainLoad(FILE* f)
|
void terrainLoad(FILE* f)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
noiseLoad(_definition.height_noise, f);
|
noiseLoad(_definition.height_noise, f);
|
||||||
_max_height = noiseGetMaxValue(_definition.height_noise);
|
_max_height = noiseGetMaxValue(_definition.height_noise);
|
||||||
|
|
||||||
|
for (i = 0; i < _definition.height_modifiers_count; i++)
|
||||||
|
{
|
||||||
|
modifierDelete(_definition.height_modifiers[i]);
|
||||||
|
}
|
||||||
|
_definition.height_modifiers_count = toolsLoadInt(f);
|
||||||
|
for (i = 0; i < _definition.height_modifiers_count; i++)
|
||||||
|
{
|
||||||
|
_definition.height_modifiers[i] = modifierCreate();
|
||||||
|
modifierLoad(_definition.height_modifiers[i], f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TerrainDefinition terrainCreateDefinition()
|
TerrainDefinition terrainCreateDefinition()
|
||||||
|
@ -44,18 +58,37 @@ TerrainDefinition terrainCreateDefinition()
|
||||||
TerrainDefinition definition;
|
TerrainDefinition definition;
|
||||||
|
|
||||||
definition.height_noise = noiseCreateGenerator();
|
definition.height_noise = noiseCreateGenerator();
|
||||||
|
definition.height_modifiers_count = 0;
|
||||||
|
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void terrainDeleteDefinition(TerrainDefinition definition)
|
void terrainDeleteDefinition(TerrainDefinition definition)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
noiseDeleteGenerator(definition.height_noise);
|
noiseDeleteGenerator(definition.height_noise);
|
||||||
|
for (i = 0; i < definition.height_modifiers_count; i++)
|
||||||
|
{
|
||||||
|
modifierDelete(definition.height_modifiers[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void terrainCopyDefinition(TerrainDefinition source, TerrainDefinition* destination)
|
void terrainCopyDefinition(TerrainDefinition source, TerrainDefinition* destination)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
noiseCopy(source.height_noise, destination->height_noise);
|
noiseCopy(source.height_noise, destination->height_noise);
|
||||||
|
|
||||||
|
for (i = 0; i < destination->height_modifiers_count; i++)
|
||||||
|
{
|
||||||
|
modifierDelete(destination->height_modifiers[i]);
|
||||||
|
}
|
||||||
|
destination->height_modifiers_count = source.height_modifiers_count;
|
||||||
|
for (i = 0; i < destination->height_modifiers_count; i++)
|
||||||
|
{
|
||||||
|
destination->height_modifiers[i] = modifierCreateCopy(source.height_modifiers[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void terrainSetDefinition(TerrainDefinition definition)
|
void terrainSetDefinition(TerrainDefinition definition)
|
||||||
|
@ -70,6 +103,27 @@ TerrainDefinition terrainGetDefinition()
|
||||||
return _definition;
|
return _definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int terrainAddModifier(TerrainDefinition* definition, HeightModifier* modifier)
|
||||||
|
{
|
||||||
|
if (definition->height_modifiers_count < MAX_HEIGHT_MODIFIER_COUNT)
|
||||||
|
{
|
||||||
|
definition->height_modifiers[definition->height_modifiers_count] = modifierCreateCopy(modifier);
|
||||||
|
return definition->height_modifiers_count++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void terrainDelModifier(TerrainDefinition* definition, int modifier_position)
|
||||||
|
{
|
||||||
|
if (modifier_position >= 0 && modifier_position < definition->height_modifiers_count)
|
||||||
|
{
|
||||||
|
/* TODO */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void terrainSetQuality(TerrainQuality quality)
|
void terrainSetQuality(TerrainQuality quality)
|
||||||
{
|
{
|
||||||
_quality = quality;
|
_quality = quality;
|
||||||
|
@ -83,16 +137,16 @@ TerrainQuality terrainGetQuality()
|
||||||
static inline double _getHeight(TerrainDefinition* definition, double x, double z, double detail)
|
static inline double _getHeight(TerrainDefinition* definition, double x, double z, double detail)
|
||||||
{
|
{
|
||||||
Vector3 location;
|
Vector3 location;
|
||||||
/*int i;*/
|
int i;
|
||||||
|
|
||||||
location.x = x;
|
location.x = x;
|
||||||
location.y = noiseGet2DDetail(definition->height_noise, x, z, detail);
|
location.y = noiseGet2DDetail(definition->height_noise, x, z, detail);
|
||||||
location.z = z;
|
location.z = z;
|
||||||
|
|
||||||
/*for (i = 0; i < _modifiers_count; i++)
|
for (i = 0; i < definition->height_modifiers_count; i++)
|
||||||
{
|
{
|
||||||
location = modifierApply(_modifiers[i], location);
|
location = modifierApply(definition->height_modifiers[i], location);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
return location.y;
|
return location.y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,13 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_HEIGHT_MODIFIER_COUNT 50
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
NoiseGenerator* height_noise;
|
NoiseGenerator* height_noise;
|
||||||
|
int height_modifiers_count;
|
||||||
|
HeightModifier* height_modifiers[MAX_HEIGHT_MODIFIER_COUNT];
|
||||||
} TerrainDefinition;
|
} TerrainDefinition;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -34,6 +38,9 @@ void terrainCopyDefinition(TerrainDefinition source, TerrainDefinition* destinat
|
||||||
void terrainSetDefinition(TerrainDefinition definition);
|
void terrainSetDefinition(TerrainDefinition definition);
|
||||||
TerrainDefinition terrainGetDefinition();
|
TerrainDefinition terrainGetDefinition();
|
||||||
|
|
||||||
|
int terrainAddModifier(TerrainDefinition* definition, HeightModifier* modifier);
|
||||||
|
void terrainDelModifier(TerrainDefinition* definition, int modifier_position);
|
||||||
|
|
||||||
void terrainSetQuality(TerrainQuality quality);
|
void terrainSetQuality(TerrainQuality quality);
|
||||||
TerrainQuality terrainGetQuality();
|
TerrainQuality terrainGetQuality();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue