Turned into a lib.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -16,7 +16,7 @@
|
|||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
ds
|
island
|
||||||
|
|
||||||
# Emacs backups
|
# 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: CFLAGS += -O3
|
||||||
all: ds
|
all: lib island
|
||||||
|
|
||||||
debug: CFLAGS = -g -ansi -pedantic
|
debug: CFLAGS += -g
|
||||||
debug: ds
|
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:
|
clean:
|
||||||
$(RM) *.o ds
|
$(RM) *.o *.a island
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ds.h"
|
#include "island.h"
|
||||||
|
|
||||||
static const float SEED = 1000.0;
|
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 ( i = 0; i < MAP_SIZE; ++i ) {
|
||||||
for ( j = 0; j < MAP_SIZE; ++j ) {
|
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 );
|
( * 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;
|
r = ( r * 2.0 ) - 1.0;
|
||||||
return r;
|
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,10 +1,19 @@
|
|||||||
#ifndef DS_H
|
#ifndef ISLAND_H
|
||||||
#define DS_H
|
#define ISLAND_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef enum TERRAIN_TYPE { DEEP_WATER,
|
||||||
|
SHALLOW_WATER,
|
||||||
|
SAND,
|
||||||
|
GRASS,
|
||||||
|
FOREST,
|
||||||
|
HILL,
|
||||||
|
MOUNTAIN
|
||||||
|
} terrain_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a diamond-square fractal map.
|
* Generate a diamond-square fractal map.
|
||||||
*/
|
*/
|
||||||
@@ -34,7 +43,13 @@ extern "C" {
|
|||||||
* Multiply the diamond square map with the island mask.
|
* Multiply the diamond square map with the island mask.
|
||||||
* Both matrices must have been normalized before.
|
* 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user