Turned into a lib.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -16,7 +16,7 @@
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
ds
|
||||
island
|
||||
|
||||
# Emacs backups
|
||||
*~
|
||||
|
26
Makefile
26
Makefile
@@ -1,16 +1,24 @@
|
||||
LDLIBS = -lm
|
||||
CC := gcc
|
||||
CFLAGS := -I./ -ansi -pedantic
|
||||
LDFLAGS := -L./
|
||||
LDLIBS := -lm -lisland
|
||||
|
||||
all: CFLAGS = -O3 -ansi -pedantic
|
||||
all: ds
|
||||
all: CFLAGS += -O3
|
||||
all: lib island
|
||||
|
||||
debug: CFLAGS = -g -ansi -pedantic
|
||||
debug: ds
|
||||
debug: CFLAGS += -g
|
||||
debug: lib island
|
||||
|
||||
ds: main.o ds.o
|
||||
lib: libisland.a
|
||||
|
||||
main.o: main.c ds.h
|
||||
libisland.a: island.o
|
||||
ar rcs libisland.a island.o
|
||||
|
||||
ds.o: ds.c ds.h
|
||||
island: main.o
|
||||
|
||||
main.o: main.c island.h
|
||||
|
||||
island.o: island.c island.h
|
||||
|
||||
clean:
|
||||
$(RM) *.o ds
|
||||
$(RM) *.o *.a island
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
#include "ds.h"
|
||||
#include "island.h"
|
||||
|
||||
static const float SEED = 1000.0;
|
||||
|
||||
@@ -160,7 +160,6 @@ extern void mult ( float *** fmap, int *** imap, unsigned int MAP_SIZE ) {
|
||||
|
||||
for ( i = 0; i < MAP_SIZE; ++i ) {
|
||||
for ( j = 0; j < MAP_SIZE; ++j ) {
|
||||
/*fprintf ( stderr, "%f %d\n", ( * fmap )[ i ][ j ], ( * imap )[ i ][ j ] );*/
|
||||
( * imap )[ i ][ j ] = ( int )( ( ( * fmap )[ i ][ j ] * ( ( float ) ( * imap )[ i ][ j ] / 255.0f ) ) * 250.0f );
|
||||
}
|
||||
}
|
||||
@@ -212,3 +211,25 @@ static float randomFloat() {
|
||||
r = ( r * 2.0 ) - 1.0;
|
||||
return r;
|
||||
}
|
||||
|
||||
terrain_t terrainType( int h ) {
|
||||
if ( h < 30 ) {
|
||||
if ( h < 15 ) {
|
||||
return DEEP_WATER;
|
||||
} else {
|
||||
return SHALLOW_WATER;
|
||||
}
|
||||
} else {
|
||||
if ( h < 40 ) {
|
||||
return SAND;
|
||||
} else if ( h >= 40 && h < 100 ) {
|
||||
return GRASS;
|
||||
} else if ( h >= 100 && h < 150 ) {
|
||||
return FOREST;
|
||||
} else if ( h >= 180 ) {
|
||||
return MOUNTAIN;
|
||||
} else {
|
||||
return HILL;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,15 +1,24 @@
|
||||
#ifndef DS_H
|
||||
#define DS_H
|
||||
#ifndef ISLAND_H
|
||||
#define ISLAND_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum TERRAIN_TYPE { DEEP_WATER,
|
||||
SHALLOW_WATER,
|
||||
SAND,
|
||||
GRASS,
|
||||
FOREST,
|
||||
HILL,
|
||||
MOUNTAIN
|
||||
} terrain_t;
|
||||
|
||||
/**
|
||||
* Generate a diamond-square fractal map.
|
||||
*/
|
||||
extern void ds ( float ***, const unsigned int );
|
||||
|
||||
|
||||
/**
|
||||
* Generate a mask using particle deposition.
|
||||
*/
|
||||
@@ -34,7 +43,13 @@ extern "C" {
|
||||
* Multiply the diamond square map with the island mask.
|
||||
* Both matrices must have been normalized before.
|
||||
*/
|
||||
extern void mult ( float ***, int *** , unsigned int);
|
||||
extern void mult ( float ***, int ***, unsigned int );
|
||||
|
||||
/**
|
||||
* Given a sample from a heightmap, return the terrain
|
||||
* type that correspond it.
|
||||
*/
|
||||
terrain_t terrainType( int );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
Reference in New Issue
Block a user