Added bounds checking for triangles.
This commit is contained in:
124
src/gen.c
124
src/gen.c
@@ -1,122 +1,44 @@
|
||||
#include "include/gen.h"
|
||||
#include "include/geom.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
Vec2 asth[WORLD_SZ][WORLD_SZ] = {
|
||||
{
|
||||
(Vec2){.x = 1, .y = 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
{
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
{
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
{
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
{
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
{
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
{
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
{
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
(Vec2){1, 2},
|
||||
},
|
||||
};
|
||||
Vec2 asth[WORLD_SZ][WORLD_SZ];
|
||||
|
||||
Plate lith[NPLATES];
|
||||
|
||||
// Find the point for an index to the edge of the world.
|
||||
Pt world_edge_idx_to_pt(int idx) {
|
||||
if (0 <= idx && idx < 8) {
|
||||
if (0 <= idx && idx < WORLD_SZ) {
|
||||
return (Pt){idx, 0};
|
||||
} else if (8 <= idx && idx < 16) {
|
||||
return (Pt){7, idx - 8};
|
||||
} else if (16 <= idx && idx < 24) {
|
||||
return (Pt){idx - 16, 0};
|
||||
} else if (24 <= idx && idx < 32) {
|
||||
return (Pt){7, idx - 24};
|
||||
} else if (WORLD_SZ <= idx && idx < 2 * WORLD_SZ) {
|
||||
return (Pt){WORLD_SZ - 1, idx - WORLD_SZ};
|
||||
} else if (2 * WORLD_SZ <= idx && idx < 3 * WORLD_SZ) {
|
||||
return (Pt){idx - 2 * WORLD_SZ, 0};
|
||||
} else if (3 * WORLD_SZ <= idx && idx < 4 * WORLD_SZ) {
|
||||
return (Pt){WORLD_SZ - 1, idx - 3 * WORLD_SZ};
|
||||
} else {
|
||||
exit(122);
|
||||
}
|
||||
}
|
||||
|
||||
void gen_asth() {
|
||||
srand(time(NULL));
|
||||
|
||||
for (int i = 0; i < WORLD_SZ; i++) {
|
||||
for (int j = 0; j < WORLD_SZ; j++) {
|
||||
asth[i][j] = (Vec2){rand() % 7 - 3, rand() % 7 - 3};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gen_lith() {
|
||||
srand(time(NULL));
|
||||
|
||||
Tri tri1 = {
|
||||
(Pt){0, 0},
|
||||
(Pt){0, 7},
|
||||
(Pt){7, 0},
|
||||
};
|
||||
Tri tri2 = {
|
||||
(Pt){7, 0},
|
||||
(Pt){0, 7},
|
||||
(Pt){7, 7},
|
||||
};
|
||||
Tri* tri1 = tri_init((Pt){0, 0}, (Pt){0, 7}, (Pt){7, 0});
|
||||
Tri* tri2 = tri_init((Pt){7, 0}, (Pt){0, 7}, (Pt){7, 7});
|
||||
|
||||
lith[0] = (Plate){.tris = {tri1}};
|
||||
lith[1] = (Plate){.tris = {tri2}};
|
||||
lith[0] = (Plate){.col = BLUE, .ntris = 1, .tris = tri1};
|
||||
lith[1] = (Plate){.col = GREEN, .ntris = 1, .tris = tri2};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user