Début de l'implémentation de l'algo utilisant les motifs.
This commit is contained in:
parent
ceeadcac13
commit
973cf6cb77
33
Makefile
33
Makefile
|
@ -1,40 +1,19 @@
|
|||
CC=gcc
|
||||
CXX=g++
|
||||
# -ansi -pedantic -Wconversion
|
||||
CCWARN=-Wall -Wextra -Werror
|
||||
CFLAGS=-O3 $(CCWARN) -g3
|
||||
|
||||
.PHONY: all
|
||||
all: display roads rules
|
||||
|
||||
.PHONY: test
|
||||
test: display
|
||||
./display
|
||||
|
||||
.PHONY: test
|
||||
test-simple-terrain: simple-terrain
|
||||
./simple-terrain | display
|
||||
|
||||
.PHONY: testroads
|
||||
testroads: roads
|
||||
./roads | display
|
||||
all: rules
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm simple-terrain display roads rules *.o
|
||||
|
||||
simple-terrain: simple-terrain.c
|
||||
$(CC) $< -o $@
|
||||
|
||||
display: display.o roam.o square.o hash.o
|
||||
$(CC) -lGLEW -lSDL -lGLU $^ -o $@
|
||||
|
||||
roads: roads.o
|
||||
$(CC) -lm $^ -o $@
|
||||
rm rules *.o .*.d
|
||||
|
||||
rules: rules.o hash.o
|
||||
$(CC) -lm $^ -o $@
|
||||
$(CXX) -lm $^ -o $@
|
||||
|
||||
-include .*.d
|
||||
|
||||
%.o: %.c Makefile
|
||||
$(CC) -MMD -MF .$(@:.o=.d) -c $< $(CFLAGS) -o $@
|
||||
%.o: %.cpp Makefile
|
||||
$(CXX) -MMD -MF .$(@:.o=.d) -c $< $(CFLAGS) -o $@
|
||||
|
|
|
@ -16,3 +16,11 @@ unsigned int hash2(unsigned int a, unsigned int b) {
|
|||
unsigned int hash3(unsigned int seed, int x, int y) {
|
||||
return hash2(seed,hash2(x, y));
|
||||
}
|
||||
|
||||
int randomInRange(int seed, int n, int a, int b) {
|
||||
return (hash2(seed, n) % (b - a)) + a;
|
||||
}
|
||||
|
||||
int newSeed(int seed, int n) {
|
||||
return hash2(seed, n);
|
||||
}
|
2
hash.h
2
hash.h
|
@ -1,2 +1,4 @@
|
|||
unsigned int hash2(unsigned int a, unsigned int b);
|
||||
unsigned int hash3(unsigned int seed, int x, int y);
|
||||
int randomInRange(int seed, int n, int a, int b);
|
||||
int newSeed(int seed, int n);
|
||||
|
|
12
rules.c
12
rules.c
|
@ -1,12 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "hash.h"
|
||||
|
||||
void regle1() {
|
||||
// carré(x1,y1,x2,y2) → carré()*4 avec une croix de routes au milieu.
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Générer une tile de base
|
||||
// tile.subdivide tant qu'on n'a pas le niveau de détail désiré.
|
||||
return 0;
|
||||
}
|
61
rules.cpp
Normal file
61
rules.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include <iostream>
|
||||
#include "rules.h"
|
||||
#include "hash.h"
|
||||
|
||||
// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°.
|
||||
class RectangleRoutes {
|
||||
public:
|
||||
Vertex ne;
|
||||
Vertex so;
|
||||
IO io [4];
|
||||
int seed;
|
||||
public:
|
||||
RectangleRoutes(Vertex ne, Vertex so, int seed) : ne(ne), so(so), seed(seed) {}
|
||||
void display() { };
|
||||
int width() { return this->ne.x - this->so.x; }
|
||||
int height() { return this->ne.y - this->so.y; }
|
||||
void subdivide() {
|
||||
Vertex split = {
|
||||
randomInRange(this->seed, 0, this->so.x + this->width()*1/4, this->so.x + this->width()*3/4),
|
||||
randomInRange(this->seed, 1, this->so.y + this->height()*1/4, this->so.y + this->height()*3/4)
|
||||
};
|
||||
split = split;
|
||||
std::cout << this << std::endl;
|
||||
RectangleRoutes rr(ne, so, 42);
|
||||
// std::cout << rr << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
|
||||
return os << "(" << v.x << "," << v.y << ")";
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const RectangleRoutes& r) {
|
||||
int a = r.ne.x;
|
||||
a = a;
|
||||
return os << "42!";//<< r.ne << "-" << r.so;
|
||||
}
|
||||
|
||||
|
||||
/* Carrefour(split + (1,1), split - (1,1)) */
|
||||
/* // routes au NESW du carrefour */
|
||||
/* Route((r.ne.x, split.y) + (0,1)), split + (1,1)) */
|
||||
/* Route((split.x, r.se.y) + (1,0)), split + (-1,1)) */
|
||||
/* Route((r.so.x, split.y) + (0,-1)), split + (-1,-1)) */
|
||||
/* Route((split.x, r.no.y) + (-1,0)), split + (1,-1)) */
|
||||
/* // subrectangles */
|
||||
/* RectangleRoutes(split + (1,1), r.ne, newSeed(r.seed, 2)); */
|
||||
/* RectangleRoutes(split + (1,-1), r.se, newSeed(r.seed, 3)); */
|
||||
/* RectangleRoutes(split + (-1,-1), r.so, newSeed(r.seed, 4)); */
|
||||
/* RectangleRoutes(split + (-1,1), r.no, newSeed(r.seed, 5)); */
|
||||
|
||||
int main() {
|
||||
// Générer une tile de base
|
||||
Vertex ne = {100,0};
|
||||
Vertex so = {0,100};
|
||||
RectangleRoutes r(ne, so, 42);
|
||||
r.subdivide();
|
||||
std::cout << r << std::endl;
|
||||
// tile.subdivide tant qu'on n'a pas le niveau de détail désiré.
|
||||
return 0;
|
||||
}
|
24
rules.h
Normal file
24
rules.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
typedef struct Vertex {
|
||||
int x;
|
||||
int y;
|
||||
//int z;
|
||||
} Vertex;
|
||||
|
||||
typedef enum Cardinaux {
|
||||
N = 0,
|
||||
E = 1,
|
||||
S = 2,
|
||||
O = 3
|
||||
} Cardinaux;
|
||||
|
||||
typedef enum Diagonales {
|
||||
NE = 0,
|
||||
SE = 1,
|
||||
SO = 2,
|
||||
NO = 3
|
||||
} Diagonales;
|
||||
|
||||
typedef struct IO {
|
||||
int in;
|
||||
int out;
|
||||
} IO;
|
21
rules.md
21
rules.md
|
@ -9,28 +9,7 @@ rectangle suffisemment petit, commercial → magasin
|
|||
|
||||
// TODO : faire pour des angles entre 70° et 110°.
|
||||
|
||||
// RectangleRoutes(Vertex coins[4]) est un quadrilatère de routes avec des angles aux coins égaux à 90°.
|
||||
// TODO : distinguer à la création les RectangleRoutes avec (all sides length > 10) et les autres cas.
|
||||
struct RectangleRoutes {
|
||||
Vertex ne;
|
||||
Vertex se;
|
||||
Vertex so;
|
||||
Vertex no;
|
||||
// TODO : prendre en compte les entrées/sorties.
|
||||
IO n;
|
||||
IO e;
|
||||
IO s;
|
||||
IO o;
|
||||
int seed;
|
||||
}
|
||||
|
||||
int randomInRange(int seed, int n, int a, int b) {
|
||||
return (hash(seed, n) % (b - a)) + a;
|
||||
}
|
||||
|
||||
int newSeed(int seed, int n) {
|
||||
return hash(seed, n);
|
||||
}
|
||||
|
||||
RectangleRoutes r (all sides length > 10) {
|
||||
Vertex split = { .x = randomInRange(r.seed, 0, r.no.x+5, r.ne.x-5), .y = randomInRange(r.seed, 1, r.no.x+5, r.ne.x-5) };
|
||||
|
|
Loading…
Reference in New Issue
Block a user