-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtextconv.c
67 lines (55 loc) · 1.94 KB
/
textconv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <string.h>
#include "universe.h"
#include "lib.h"
char tile_get_text(tile *t, int x, int y) {
if(!t->text) return ' ';
else return t->text[(y * TILE_WIDTH) + x];
}
void tile_set_text(tile *t, int x, int y, char c) {
if(!t->text) {
t->text = (char *)allocate(TILE_WIDTH * TILE_HEIGHT);
memset(t->text, ' ', TILE_WIDTH * TILE_HEIGHT);
}
t->text[(y * TILE_WIDTH) + x] = c;
}
char generation_get_text(generation *g, int x, int y) {
tile *t = generation_find_tile(g, x, y, 1);
return tile_get_text(t, x % TILE_WIDTH, y % TILE_HEIGHT);
}
void generation_set_text(generation *g, int x, int y, char c) {
tile *t = generation_find_tile(g, x, y, 1);
tile_set_text(t, x % TILE_WIDTH, y % TILE_HEIGHT, c);
}
void generation_to_text(generation *g) {
tile *t;
int x, y;
for(t = g->all_first; t; t = t->all_next) {
for(x=0; x<TILE_WIDTH; x++) for(y=0; y<TILE_HEIGHT; y++) {
cellvalue v = tile_get_cell(t, x, y);
char c = '.';
if(v != OFF)
c = '*';
tile_set_text(t, x, y, c);
}
}
}
void tile_find_bounds_text(tile *t, int *l, int *r, int *t_, int *b) {
int ymin = TILE_HEIGHT, ymax = 0;
int xmin = TILE_WIDTH, xmax = 0;
int x, y;
for(y=0; y<TILE_HEIGHT; y++) {
for(x=0; x<TILE_WIDTH; x++) {
char c = tile_get_text(t, x, y);
if(c != ' ') {
if(y > ymax) ymax = y;
if(y < ymin) ymin = y;
if(x > xmax) xmax = x;
if(x < xmin) xmin = x;
}
}
}
*l = xmin;
*r = xmax;
*t_ = ymin;
*b = ymax;
}