commit 753c61072d1c1b4ecfd4d8081a2a1a409f342bdd
parent dcf00b464d9af6569028cbaf3c6f2e0305b99e29
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Fri, 4 Nov 2011 18:46:47 +0100
Détection automatique des dépendances dans le Makefile.
Diffstat:
6 files changed, 50 insertions(+), 26 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -2,4 +2,6 @@ simple-terrain
display
roam
roads
+rules
*.o
+.*.d
diff --git a/Makefile b/Makefile
@@ -4,26 +4,37 @@ CCWARN=-Wall -Wextra -Werror
CFLAGS=-O3 $(CCWARN) -g3
.PHONY: all
-all: display roads
+all: display roads rules
.PHONY: test
-test: all
- # ./simple-terrain | display
+test: display
./display
+.PHONY: test
+test-simple-terrain: simple-terrain
+ ./simple-terrain | display
+
.PHONY: testroads
-testroads: all
+testroads: roads
./roads | display
+.PHONY: clean
+clean:
+ rm simple-terrain display roads rules *.o
+
simple-terrain: simple-terrain.c
$(CC) $< -o $@
-display: display.o roam.o square.o
+display: display.o roam.o square.o hash.o
$(CC) -lGLEW -lSDL -lGLU $^ -o $@
roads: roads.o
$(CC) -lm $^ -o $@
-# Create objects from C source code
+rules: rules.o hash.o
+ $(CC) -lm $^ -o $@
+
+-include .*.d
+
%.o: %.c Makefile
- $(CC) -c $< $(CFLAGS) -o $@
+ $(CC) -MMD -MF .$(@:.o=.d) -c $< $(CFLAGS) -o $@
diff --git a/hash.c b/hash.c
@@ -0,0 +1,18 @@
+// Ce hash donne des bons résultats sur tous les bits de l'entier
+// généré (pas d'artefacts, répartition homogène des 0 et des 1).
+unsigned int hash2(unsigned int a, unsigned int b) {
+ unsigned int h = 1;
+ int i;
+ for (i = 0; i < 32; i+=8) {
+ a = a*h + 1;
+ b = b*h + 1;
+ // marche aussi avec 65521.
+ h = (h << 6) + (h << 16) - h + ((a >> i) & 0xff); // h * 65599 + ieme octet de a
+ h = (h << 6) + (h << 16) - h + ((b >> i) & 0xff); // h * 65599 + ieme octet de b
+ }
+ return h;
+}
+
+unsigned int hash3(unsigned int seed, int x, int y) {
+ return hash2(seed,hash2(x, y));
+}
diff --git a/hash.h b/hash.h
@@ -0,0 +1,2 @@
+unsigned int hash2(unsigned int a, unsigned int b);
+unsigned int hash3(unsigned int seed, int x, int y);
diff --git a/roam.c b/roam.c
@@ -1,4 +1,5 @@
#include "roam.h"
+#include "hash.h"
/* Implémentation de ROAM
* http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.22.1811&rep=rep1&type=pdf
@@ -41,25 +42,6 @@ int getFirstTriangleSize(Triangle* t) {
return sqrt(((t->vRight->x - t->vLeft->x)^2) + ((t->vRight->y - t->vLeft->y)^2));
}
-// Ce hash donne des bons résultats sur tous les bits de l'entier
-// généré (pas d'artefacts, répartition homogène des 0 et des 1).
-unsigned int hash2(unsigned int a, unsigned int b) {
- unsigned int h = 1;
- int i;
- for (i = 0; i < 32; i+=8) {
- a = a*h + 1;
- b = b*h + 1;
- // marche aussi avec 65521.
- h = (h << 6) + (h << 16) - h + ((a >> i) & 0xff); // h * 65599 + ieme octet de a
- h = (h << 6) + (h << 16) - h + ((b >> i) & 0xff); // h * 65599 + ieme octet de b
- }
- return h;
-}
-
-unsigned int hash3(unsigned int seed, int x, int y) {
- return hash2(seed,hash2(x, y));
-}
-
/* Interpolation linéaire entre deux points.
* (x,y) est le point dont on veut connaître la valeur
* (x1,y1)--(x2,y2) est le carré dont on connaît les valeurs
diff --git a/terrain.md b/terrain.md
@@ -38,3 +38,12 @@ Erosion
-------
Modélisation correcte : trop lent. À la place, outil "courbes" de gimp.
+
+Rivières
+========
+
+[Pathfinding pour créer des rivières](http://www.umbrarumregnum.net/articles/creating-rivers).
+Si on utilise une méthode de coût qui favorise de passer par un petit
+bout de bruit plutôt que de le contourner, mais favorise le
+contournement pour une grosse accumulation de bruit, on pourra même
+simuler l'érosion qui efface les méandres trop petits.