Une grande partie du code de base des règles.
This commit is contained in:
parent
673770fd74
commit
96d8b12b04
5
Makefile
5
Makefile
|
@ -1,9 +1,10 @@
|
||||||
CXX=g++
|
CXX=g++
|
||||||
# -ansi -pedantic -Wconversion
|
# -ansi -pedantic -Wconversion
|
||||||
CCWARN=-Wall -Wextra -Werror
|
CCWARN=-Wall -Wextra -Werror
|
||||||
CFLAGS=-O3 $(CCWARN) -g3
|
# -flto (nécessite GCC 4.5) -m32 ou -m64
|
||||||
|
CFLAGS=-O3 -g3 -I. $(CCWARN)
|
||||||
|
|
||||||
OBJECTS = main.o hash.o segment.o vertex.o io.o rules/rectangleroutes.o rules/route.o rules/carrefour.o
|
OBJECTS = main.o hash.o segment.o vertex.o triangle.o io.o rules/chose.o rules/rectangleroutes.o rules/route.o rules/carrefour.o rules/batiment.o
|
||||||
EXECUTABLE = city
|
EXECUTABLE = city
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|
26
all_includes.hh
Normal file
26
all_includes.hh
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef _ALL_INCLUDES_HH_
|
||||||
|
#define _ALL_INCLUDES_HH_
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "vertex.hh"
|
||||||
|
#include "segment.hh"
|
||||||
|
#include "triangle.hh"
|
||||||
|
#include "directions.hh"
|
||||||
|
#include "io.hh"
|
||||||
|
#include "hash.hh"
|
||||||
|
|
||||||
|
class Chose;
|
||||||
|
// class Batiment;
|
||||||
|
// class Carrefour;
|
||||||
|
// class Route;
|
||||||
|
// class RectangleRoutes;
|
||||||
|
|
||||||
|
#include "rules/chose.hh"
|
||||||
|
#include "rules/batiment.hh"
|
||||||
|
#include "rules/carrefour.hh"
|
||||||
|
#include "rules/route.hh"
|
||||||
|
#include "rules/rectangleroutes.hh"
|
||||||
|
|
||||||
|
#endif
|
2
bugs/open/2011-11-24-0045-todo
Normal file
2
bugs/open/2011-11-24-0045-todo
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
* Route et Carrefour à mettre à jour pour qu'ils soient sous-classe de Chose.
|
||||||
|
* Vertex en 3D
|
13
main.cpp
13
main.cpp
|
@ -1,12 +1,17 @@
|
||||||
#include "vertex.hh"
|
#include "all_includes.hh"
|
||||||
#include "hash.hh"
|
|
||||||
#include "rules/rectangleroutes.hh"
|
// TODO : bâtiments.
|
||||||
|
// TODO : split route en 2 triangles.
|
||||||
|
// TODO : split bâtiment en faces, puis en triangles.
|
||||||
|
// TODO : probabilités des différents types de bâtiments.
|
||||||
|
// TODO : midpoint displacement sur les probabilités des différents types de bâtiments.
|
||||||
|
// TODO : largeur des routes : ???
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Générer une tile de base
|
// Générer une tile de base
|
||||||
Vertex ne(100, 100);
|
Vertex ne(100, 100);
|
||||||
Vertex sw(0, 0);
|
Vertex sw(0, 0);
|
||||||
RectangleRoutes r(ne, sw, random());
|
RectangleRoutes r(ne, sw);
|
||||||
r.subdivide();
|
r.subdivide();
|
||||||
// tile.subdivide tant qu'on n'a pas le niveau de détail désiré.
|
// tile.subdivide tant qu'on n'a pas le niveau de détail désiré.
|
||||||
return 0;
|
return 0;
|
||||||
|
|
43
rules/batiment.cpp
Normal file
43
rules/batiment.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
Batiment::Batiment(Vertex ne, Vertex sw) : ne(ne), sw(sw) {
|
||||||
|
std::cout << this << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Batiment::width() { return this->ne.x - this->sw.x; }
|
||||||
|
|
||||||
|
int Batiment::height() { return this->ne.y - this->sw.y; }
|
||||||
|
|
||||||
|
void Batiment::subdivide() {
|
||||||
|
// TODO : rien ?
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batiment::triangulation() {
|
||||||
|
// // abcd sont les quatre coins du bâtiment.
|
||||||
|
// int h = 6;
|
||||||
|
// Vertex ah = a + Vertex(0,0,h);
|
||||||
|
// Vertex bh = b + Vertex(0,0,h);
|
||||||
|
// Vertex ch = c + Vertex(0,0,h);
|
||||||
|
// Vertex dh = d + Vertex(0,0,h);
|
||||||
|
// Vertex toit = (ah + bh + ch + dh) / 4 + Vertex(0,0,h/5);
|
||||||
|
|
||||||
|
// // 4 Murs
|
||||||
|
// new Triangle(a,bh,ah); new Triangle(a,b,bh); // a-b-bh-ah
|
||||||
|
// new Triangle(b,dh,bh); new Triangle(b,d,dh); // b-d-dh-bh
|
||||||
|
// new Triangle(d,ch,dh); new Triangle(d,c,ch); // d-c-ch-dh
|
||||||
|
// new Triangle(c,ah,ch); new Triangle(c,a,ah); // c-a-ah-ch
|
||||||
|
|
||||||
|
// // 1 Toit
|
||||||
|
// new Triangle(ah,toit,bh);
|
||||||
|
// new Triangle(bh,toit,dh);
|
||||||
|
// new Triangle(dh,toit,ch);
|
||||||
|
// new Triangle(ch,toit,ah);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Batiment* r) {
|
||||||
|
return os << *r;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Batiment& r) {
|
||||||
|
return os << "Batiment " << r.ne << "-" << r.sw;
|
||||||
|
}
|
23
rules/batiment.hh
Normal file
23
rules/batiment.hh
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef _RULES_BATIMENT_HH_
|
||||||
|
#define _RULES_BATIMENT_HH_
|
||||||
|
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°.
|
||||||
|
class Batiment : public Chose {
|
||||||
|
public:
|
||||||
|
Vertex ne;
|
||||||
|
Vertex sw;
|
||||||
|
int seed;
|
||||||
|
public:
|
||||||
|
Batiment(Vertex ne, Vertex sw);
|
||||||
|
int width();
|
||||||
|
int height();
|
||||||
|
virtual void subdivide();
|
||||||
|
virtual void triangulation();
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Batiment& r);
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Batiment* r);
|
||||||
|
|
||||||
|
#endif
|
12
rules/chose.cpp
Normal file
12
rules/chose.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
Chose::Chose() : seed(initialSeed) {}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Chose* r) {
|
||||||
|
return os << *r;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Chose& r) {
|
||||||
|
(void)r; // unused
|
||||||
|
return os << "Chose";
|
||||||
|
}
|
28
rules/chose.hh
Normal file
28
rules/chose.hh
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef _RULES_CHOSE_HH_
|
||||||
|
#define _RULES_CHOSE_HH_
|
||||||
|
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°.
|
||||||
|
class Chose {
|
||||||
|
public:
|
||||||
|
static const unsigned int initialSeed = 42;
|
||||||
|
unsigned int seed;
|
||||||
|
public:
|
||||||
|
Chose();
|
||||||
|
inline void addEntropy(unsigned int x1) { seed = hash2(seed, x1); }
|
||||||
|
inline void addEntropy(unsigned int x1, unsigned int x2) { addEntropy(x1); addEntropy(x2); }
|
||||||
|
inline void addEntropy(unsigned int x1, unsigned int x2, unsigned int x3) { addEntropy(x1, x2); addEntropy(x3); }
|
||||||
|
inline void addEntropy(unsigned int x1, unsigned int x2, unsigned int x3, unsigned int x4) { addEntropy(x1, x2); addEntropy(x3, x4); }
|
||||||
|
inline void addEntropy(Vertex v1) { addEntropy(v1.x, v1.y); }
|
||||||
|
inline void addEntropy(Vertex v1, Vertex v2) { addEntropy(v1); addEntropy(v2); }
|
||||||
|
inline void addEntropy(Vertex v1, Vertex v2, Vertex v3) { addEntropy(v1, v2); addEntropy(v3); }
|
||||||
|
inline void addEntropy(Vertex v1, Vertex v2, Vertex v3, Vertex v4) { addEntropy(v1, v2); addEntropy(v3, v4); }
|
||||||
|
virtual void subdivide() = 0;
|
||||||
|
virtual void triangulation() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Chose& r);
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Chose* r);
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,12 +1,8 @@
|
||||||
#include "rectangleroutes.hh"
|
#include "all_includes.hh"
|
||||||
#include "../vertex.hh"
|
|
||||||
#include "../directions.hh"
|
|
||||||
#include "../hash.hh"
|
|
||||||
|
|
||||||
#include "carrefour.hh"
|
RectangleRoutes::RectangleRoutes(Vertex ne, Vertex sw) : ne(ne), sw(sw) {
|
||||||
#include "route.hh"
|
addEntropy(ne);
|
||||||
|
addEntropy(sw);
|
||||||
RectangleRoutes::RectangleRoutes(Vertex ne, Vertex sw, int seed) : ne(ne), sw(sw), seed(seed) {
|
|
||||||
std::cout << this << std::endl;
|
std::cout << this << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +26,31 @@ void RectangleRoutes::subdivide() {
|
||||||
Route rs(roadEndS.add(+1,0), roadEndS.add(-1,0), split.add(-1,-1), split.add(+1,-1));
|
Route rs(roadEndS.add(+1,0), roadEndS.add(-1,0), split.add(-1,-1), split.add(+1,-1));
|
||||||
Route rw(roadEndW.add(0,-1), roadEndW.add(0,+1), split.add(-1,+1), split.add(-1,-1));
|
Route rw(roadEndW.add(0,-1), roadEndW.add(0,+1), split.add(-1,+1), split.add(-1,-1));
|
||||||
// Sous-quartiers
|
// Sous-quartiers
|
||||||
RectangleRoutes rrne(this->ne, re.corners[NW], newSeed(this->seed, 2));
|
Chose* rrne = sub(this->ne, re.corners[NW]);
|
||||||
RectangleRoutes rrse(re.corners[SE], rs.corners[SE], newSeed(this->seed, 3));
|
Chose* rrse = sub(re.corners[SE], rs.corners[SE]);
|
||||||
RectangleRoutes rrsw(rs.corners[NW], this->sw, newSeed(this->seed, 4));
|
Chose* rrsw = sub(rs.corners[NW], this->sw);
|
||||||
RectangleRoutes rrnw(Vertex(this->sw.x, this->ne.y), rn.corners[SW], newSeed(this->seed, 5));
|
Chose* rrnw = sub(Vertex(this->sw.x, this->ne.y), rn.corners[SW]);
|
||||||
// Entrées/sorties par mètre carré en fonction du type de terrain ?
|
// TODO : stocker ces objets quelque part.
|
||||||
// rrnw.io[N].in += …;
|
(void)rrne;
|
||||||
|
(void)rrse;
|
||||||
|
(void)rrsw;
|
||||||
|
(void)rrnw;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RectangleRoutes::triangulation() {
|
||||||
|
Vertex nw(this->sw.x, this->ne.y);
|
||||||
|
Vertex se(this->ne.x, this->sw.y);
|
||||||
|
new Triangle(this->sw, nw, this->ne);
|
||||||
|
new Triangle(this->sw, se, this->ne);
|
||||||
|
}
|
||||||
|
|
||||||
|
Chose* RectangleRoutes::sub(Vertex ne, Vertex sw) {
|
||||||
|
Segment rect = Segment(ne,sw);
|
||||||
|
if (rect.width() < 10 || rect.height() < 10) {
|
||||||
|
return new Batiment(ne, sw);
|
||||||
|
} else {
|
||||||
|
return new RectangleRoutes(ne, sw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const RectangleRoutes* r) {
|
std::ostream& operator<<(std::ostream& os, const RectangleRoutes* r) {
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
#ifndef _RULES_RECTANGLEROUTES_HH_
|
#ifndef _RULES_RECTANGLEROUTES_HH_
|
||||||
#define _RULES_RECTANGLEROUTES_HH_
|
#define _RULES_RECTANGLEROUTES_HH_
|
||||||
|
|
||||||
#include <iostream>
|
#include "all_includes.hh"
|
||||||
#include "../vertex.hh"
|
|
||||||
#include "../directions.hh"
|
|
||||||
#include "../io.hh"
|
|
||||||
|
|
||||||
// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°.
|
// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°.
|
||||||
class RectangleRoutes {
|
class RectangleRoutes : Chose {
|
||||||
public:
|
public:
|
||||||
Vertex ne;
|
Vertex ne;
|
||||||
Vertex sw;
|
Vertex sw;
|
||||||
IO io [4];
|
|
||||||
int seed;
|
|
||||||
public:
|
public:
|
||||||
RectangleRoutes(Vertex ne, Vertex sw, int seed);
|
RectangleRoutes(Vertex ne, Vertex sw);
|
||||||
int width();
|
int width();
|
||||||
int height();
|
int height();
|
||||||
void subdivide();
|
virtual void subdivide();
|
||||||
|
virtual void triangulation();
|
||||||
|
private:
|
||||||
|
Chose* sub(Vertex ne, Vertex sw);
|
||||||
|
public:
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const RectangleRoutes& r);
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const RectangleRoutes* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const RectangleRoutes& r);
|
|
||||||
std::ostream& operator<<(std::ostream& os, const RectangleRoutes* r);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
segment.cpp
12
segment.cpp
|
@ -1,6 +1,4 @@
|
||||||
#include "segment.hh"
|
#include "all_includes.hh"
|
||||||
#include "vertex.hh"
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
Segment::Segment(Vertex u, Vertex v): u(u), v(v) {}
|
Segment::Segment(Vertex u, Vertex v): u(u), v(v) {}
|
||||||
|
|
||||||
|
@ -9,3 +7,11 @@ int Segment::length() {
|
||||||
int y = u.y - v.y;
|
int y = u.y - v.y;
|
||||||
return sqrt(x*x + y*y);
|
return sqrt(x*x + y*y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Segment::width() {
|
||||||
|
return u.x - v.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Segment::height() {
|
||||||
|
return u.y - v.y;
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef _SEGMENT_HH_
|
#ifndef _SEGMENT_HH_
|
||||||
#define _SEGMENT_HH_
|
#define _SEGMENT_HH_
|
||||||
|
|
||||||
#include "vertex.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
class Segment {
|
class Segment {
|
||||||
public:
|
public:
|
||||||
|
@ -10,6 +10,8 @@ public:
|
||||||
public:
|
public:
|
||||||
Segment(Vertex u, Vertex v);
|
Segment(Vertex u, Vertex v);
|
||||||
int length();
|
int length();
|
||||||
|
int width();
|
||||||
|
int height();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
9
triangle.cpp
Normal file
9
triangle.cpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
Triangle::Triangle(Vertex a, Vertex b, Vertex c): a(a), b(b), c(c) {
|
||||||
|
std::cout << this << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Triangle& t) {
|
||||||
|
return os << "Triangle " << t.a << "--" << t.b << "--" << t.c << "-- cycle";
|
||||||
|
}
|
17
triangle.hh
Normal file
17
triangle.hh
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef _TRIANGLE_HH_
|
||||||
|
#define _TRIANGLE_HH_
|
||||||
|
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
class Triangle {
|
||||||
|
public:
|
||||||
|
Vertex a;
|
||||||
|
Vertex b;
|
||||||
|
Vertex c;
|
||||||
|
public:
|
||||||
|
Triangle(Vertex a, Vertex b, Vertex c);
|
||||||
|
public:
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const Triangle& t);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
20
vertex.cpp
20
vertex.cpp
|
@ -14,3 +14,23 @@ Vertex Vertex::add(int dx, int dy) {
|
||||||
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
|
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
|
||||||
return os << "(" << v.x << "," << v.y << ")";
|
return os << "(" << v.x << "," << v.y << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vertex operator+(const Vertex& u, const Vertex& v) {
|
||||||
|
return Vertex(u.x + v.x, u.y + v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator-(const Vertex& u, const Vertex& v) {
|
||||||
|
return Vertex(u.x + v.x, u.y + v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator-(const Vertex& v) {
|
||||||
|
return Vertex(-v.x, -v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator*(const Vertex& v, const int n) {
|
||||||
|
return Vertex(v.x * n, v.y * n);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator/(const Vertex& v, const int n) {
|
||||||
|
return Vertex(v.x / n, v.y / n);
|
||||||
|
}
|
||||||
|
|
|
@ -12,8 +12,13 @@ public:
|
||||||
Vertex();
|
Vertex();
|
||||||
Vertex(int x, int y);
|
Vertex(int x, int y);
|
||||||
Vertex add(int dx, int dy);
|
Vertex add(int dx, int dy);
|
||||||
|
public:
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
|
||||||
|
friend Vertex operator+(const Vertex& u, const Vertex& v);
|
||||||
|
friend Vertex operator-(const Vertex& u, const Vertex& v);
|
||||||
|
friend Vertex operator-(const Vertex& v);
|
||||||
|
friend Vertex operator*(const Vertex& v, const int n);
|
||||||
|
friend Vertex operator/(const Vertex& v, const int n);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Vertex& v);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user