Compare commits
No commits in common. "1b3e0eab80a5295e9d966083de5c27c53e1514ee" and "878e9d65400670e4acbe53e174422a48a925f05d" have entirely different histories.
1b3e0eab80
...
878e9d6540
|
@ -117,7 +117,7 @@ void drawNumberToRenderer(SDL_Renderer* renderer, imgs data, int n, int X, int Y
|
||||||
nIter--;
|
nIter--;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int toDraw = 0, remaining = -n, nIter = ln_baseN(-n, 10);
|
int toDraw = 0, remaining = -n, nIter = 1+ln_baseN(-n, 10);
|
||||||
drawDigitToRenderer(renderer, data, -727, X, Y, W, H);
|
drawDigitToRenderer(renderer, data, -727, X, Y, W, H);
|
||||||
while(nIter != 0) {
|
while(nIter != 0) {
|
||||||
toDraw = remaining%10;
|
toDraw = remaining%10;
|
||||||
|
@ -136,7 +136,7 @@ void drawStringToRenderer(SDL_Renderer* renderer, imgs data, char* s, int X, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax) {
|
void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax, int di) {
|
||||||
if(ch->draw_id != draw_par) {
|
if(ch->draw_id != draw_par) {
|
||||||
ch->draw_id = draw_par ;
|
ch->draw_id = draw_par ;
|
||||||
//printf("[DDDDD] chunk (%d, %d) has signature : \n", ch.chx, ch.chy);
|
//printf("[DDDDD] chunk (%d, %d) has signature : \n", ch.chx, ch.chy);
|
||||||
|
@ -172,7 +172,7 @@ void drawHashToRenderer(SDL_Renderer* renderer, int chx, int chy, int xmin, int
|
||||||
fprintf(stderr, "NO\n");
|
fprintf(stderr, "NO\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
};
|
};
|
||||||
drawChunkToRenderer(renderer, todraw, xmin, xmax, ymin, ymax);
|
drawChunkToRenderer(renderer, todraw, xmin, xmax, ymin, ymax, dist);
|
||||||
|
|
||||||
if(dist != render_distance -1 && !gridMem(map, chx+1, chy)) {
|
if(dist != render_distance -1 && !gridMem(map, chx+1, chy)) {
|
||||||
generate_chunk_all(chx+1, chy);
|
generate_chunk_all(chx+1, chy);
|
||||||
|
|
|
@ -21,7 +21,7 @@ void drawNumberToRenderer(SDL_Renderer* renderer, imgs data, int n, int X, int Y
|
||||||
|
|
||||||
void drawStringToRenderer(SDL_Renderer* renderer, imgs data, char* s, int X, int Y, int W, int H);
|
void drawStringToRenderer(SDL_Renderer* renderer, imgs data, char* s, int X, int Y, int W, int H);
|
||||||
|
|
||||||
void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax);
|
void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax, int di);
|
||||||
|
|
||||||
void drawHashToRenderer(SDL_Renderer* renderer, int chx, int chy, int xmin, int xmax, int ymin, int ymax, int dist);
|
void drawHashToRenderer(SDL_Renderer* renderer, int chx, int chy, int xmin, int xmax, int ymin, int ymax, int dist);
|
||||||
|
|
||||||
|
|
139
src/generation.c
139
src/generation.c
|
@ -45,10 +45,55 @@ template full ;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------ //
|
// ------------------------------------------------------------------------ //
|
||||||
|
|
||||||
|
void one_debug() {
|
||||||
|
matches = malloc(sizeof(array*)*4);
|
||||||
|
|
||||||
|
matches[0] = malloc(sizeof(array));
|
||||||
|
matches[1] = malloc(sizeof(array));
|
||||||
|
matches[2] = malloc(sizeof(array));
|
||||||
|
matches[3] = malloc(sizeof(array));
|
||||||
|
|
||||||
|
matches[0][0].arr = malloc(sizeof(int));
|
||||||
|
matches[0][0].arr[0] = 0;
|
||||||
|
matches[0][0].len = 1;
|
||||||
|
|
||||||
|
matches[1][0].arr = malloc(sizeof(int));
|
||||||
|
matches[1][0].arr[0] = 0;
|
||||||
|
matches[1][0].len = 1;
|
||||||
|
|
||||||
|
matches[2][0].arr = malloc(sizeof(int));
|
||||||
|
matches[2][0].arr[0] = 0;
|
||||||
|
matches[2][0].len = 1;
|
||||||
|
|
||||||
|
matches[3][0].arr = malloc(sizeof(int));
|
||||||
|
matches[3][0].arr[0] = 0;
|
||||||
|
matches[3][0].len = 1;
|
||||||
|
|
||||||
|
configs = malloc(sizeof(template));
|
||||||
|
|
||||||
|
configs[0].lines = malloc(sizeof(uint8_t)*8);
|
||||||
|
configs[0].lines[0] = 255;
|
||||||
|
configs[0].lines[1] = 129;
|
||||||
|
configs[0].lines[2] = 129;
|
||||||
|
configs[0].lines[3] = 129;
|
||||||
|
configs[0].lines[4] = 129;
|
||||||
|
configs[0].lines[5] = 129;
|
||||||
|
configs[0].lines[6] = 129;
|
||||||
|
configs[0].lines[7] = 255;
|
||||||
|
|
||||||
|
configs[0].id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------ //
|
||||||
|
|
||||||
bool unpack_coord(uint8_t* lines, int cx, int cy) {
|
bool unpack_coord(uint8_t* lines, int cx, int cy) {
|
||||||
return (bool)((lines[cy]/pw(2, cx))%2);
|
return (bool)((lines[cy]/pw(2, cx))%2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_compatible(chunk ch, cardinal dir, int config_id) {
|
||||||
|
return arr_mem(matches[(int)dir][ch.chdata.id], config_id);
|
||||||
|
}
|
||||||
|
|
||||||
template copy(template src) {
|
template copy(template src) {
|
||||||
template new ;
|
template new ;
|
||||||
new.id = src.id ;
|
new.id = src.id ;
|
||||||
|
@ -87,7 +132,14 @@ void print_template(int config_id) {
|
||||||
rem = rem/2 ;
|
rem = rem/2 ;
|
||||||
};
|
};
|
||||||
printf("(%d)\n", configs[config_id].lines[i]);
|
printf("(%d)\n", configs[config_id].lines[i]);
|
||||||
};
|
};/*
|
||||||
|
for(int i = 0; i < 4; i++) {
|
||||||
|
printf("[");
|
||||||
|
for(int j = 0; j < matches[i][config_id].len; j++) {
|
||||||
|
printf("%d ", matches[i][config_id].arr[j]);
|
||||||
|
}
|
||||||
|
printf("]\n");
|
||||||
|
};*/
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +167,47 @@ void rotateTemplateClockWise(int config_id) {
|
||||||
//print_template(config_id);
|
//print_template(config_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(false) {
|
||||||
|
int* temp = matches[0][config_id].arr;
|
||||||
|
int len0 = matches[0][config_id].len;
|
||||||
|
|
||||||
|
matches[0][config_id].arr = matches[1][config_id].arr;
|
||||||
|
matches[0][config_id].len = matches[1][config_id].len;
|
||||||
|
|
||||||
|
matches[1][config_id].arr = matches[2][config_id].arr;
|
||||||
|
matches[1][config_id].len = matches[2][config_id].len;
|
||||||
|
|
||||||
|
matches[2][config_id].arr = matches[3][config_id].arr;
|
||||||
|
matches[2][config_id].len = matches[3][config_id].len;
|
||||||
|
|
||||||
|
matches[3][config_id].arr = temp;
|
||||||
|
matches[3][config_id].len = len0;
|
||||||
|
|
||||||
|
for(int tp = 0; tp < n_configs; tp++) {
|
||||||
|
pop(&matches[0][tp], config_id);
|
||||||
|
append(&matches[1][tp], config_id);
|
||||||
|
|
||||||
|
pop(&matches[1][tp], config_id);
|
||||||
|
append(&matches[2][tp], config_id);
|
||||||
|
|
||||||
|
pop(&matches[2][tp], config_id);
|
||||||
|
append(&matches[3][tp], config_id);
|
||||||
|
|
||||||
|
pop(&matches[3][tp], config_id);
|
||||||
|
append(&matches[0][tp], config_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free(new);
|
free(new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_compat_one(int cx, int cy, cardinal dir, int idx) {
|
||||||
|
if(idx == -1 || !gridMem(map, cx, cy)) {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return is_compatible(*gridGet(map, cx, cy), dir, idx);
|
||||||
|
}
|
||||||
|
|
||||||
bool is_compat_sig_north(int cx, int cy, int idx) {
|
bool is_compat_sig_north(int cx, int cy, int idx) {
|
||||||
chunk* cp = gridGet(map, cx, cy-1);
|
chunk* cp = gridGet(map, cx, cy-1);
|
||||||
if(cp == NULL) {
|
if(cp == NULL) {
|
||||||
|
@ -160,7 +250,34 @@ void signature(template t) {
|
||||||
|
|
||||||
bool is_compat_with_spins(int cx, int cy, int idx) {
|
bool is_compat_with_spins(int cx, int cy, int idx) {
|
||||||
for(int k = 0; k < 4; k++) {
|
for(int k = 0; k < 4; k++) {
|
||||||
|
//printf(" (%d %d %d %d)\n", is_compat_one(cx-1, cy, EAST, idx), is_compat_one(cx+1, cy, WEST, idx), is_compat_one(cx, cy-1, SOUTH, idx), is_compat_one(cx, cy+1, NORTH, idx));
|
||||||
|
//if(is_compat_one(cx-1, cy, EAST, idx) && is_compat_one(cx+1, cy, WEST, idx) && is_compat_one(cx, cy-1, SOUTH, idx) && is_compat_one(cx, cy+1, NORTH, idx)) {
|
||||||
if(is_compat_sig_north(cx, cy, idx) && is_compat_sig_east(cx, cy, idx) && is_compat_sig_south(cx, cy, idx) && is_compat_sig_west(cx, cy, idx)) {
|
if(is_compat_sig_north(cx, cy, idx) && is_compat_sig_east(cx, cy, idx) && is_compat_sig_south(cx, cy, idx) && is_compat_sig_west(cx, cy, idx)) {
|
||||||
|
|
||||||
|
/*printf("---------------------------------\n");
|
||||||
|
signature(configs[idx]);
|
||||||
|
if(gridGet(map, cx, cy+1) != NULL) {
|
||||||
|
printf("[SOUTH] - %d\n", (gridGet(map, cx, cy+1)->chdata).lines[7]);
|
||||||
|
} else {
|
||||||
|
printf("[SOUTH] - \n");
|
||||||
|
}
|
||||||
|
if(gridGet(map, cx+1, cy) != NULL) {
|
||||||
|
printf("[EAST] - %d\n", (gridGet(map, cx+1, cy)->chdata).westsig);
|
||||||
|
} else {
|
||||||
|
printf("[EAST] - \n");
|
||||||
|
}
|
||||||
|
if(gridGet(map, cx, cy-1) != NULL) {
|
||||||
|
printf("[NORTH] - %d\n", (gridGet(map, cx, cy-1)->chdata).lines[0]);
|
||||||
|
} else {
|
||||||
|
printf("[NORTH] - \n");
|
||||||
|
}
|
||||||
|
if(gridGet(map, cx-1, cy) != NULL) {
|
||||||
|
printf("[WEST] - %d\n\n", (gridGet(map, cx-1, cy)->chdata).eastsig);
|
||||||
|
} else {
|
||||||
|
printf("[WEST] - \n");
|
||||||
|
}
|
||||||
|
printf("---------------------------------\n");*/
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
} else {
|
} else {
|
||||||
rotateTemplateClockWise(idx);
|
rotateTemplateClockWise(idx);
|
||||||
|
@ -253,7 +370,18 @@ void parse_one(FILE* ptr, FILE* ptr2, int index) {
|
||||||
configs[index].eastsig += xres;
|
configs[index].eastsig += xres;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};/*
|
||||||
|
for(int i = 0; i < 4; i++) {
|
||||||
|
int len = count_char_in_line(ptr2, ',');
|
||||||
|
matches[i][index].len = len ;
|
||||||
|
matches[i][index].arr = malloc(sizeof(int)*n_configs); // just in case
|
||||||
|
int wasted = fgetc(ptr); // always a '['
|
||||||
|
for(int j = 0; j < len; j++) {
|
||||||
|
int read = get_integer(ptr);
|
||||||
|
matches[i][index].arr[j] = read ;
|
||||||
};
|
};
|
||||||
|
terminate_line(ptr);
|
||||||
|
};*/
|
||||||
|
|
||||||
terminate_line(ptr);
|
terminate_line(ptr);
|
||||||
terminate_line(ptr2);
|
terminate_line(ptr2);
|
||||||
|
@ -263,6 +391,15 @@ void parse_configs(char* filename, int n_conf) {
|
||||||
// Initializing everything //
|
// Initializing everything //
|
||||||
n_configs = n_conf ;
|
n_configs = n_conf ;
|
||||||
|
|
||||||
|
matches = malloc(sizeof(array*)*4);
|
||||||
|
// 4 cardinal directions
|
||||||
|
|
||||||
|
matches[0] = malloc(sizeof(array)*n_conf);
|
||||||
|
matches[1] = malloc(sizeof(array)*n_conf);
|
||||||
|
matches[2] = malloc(sizeof(array)*n_conf);
|
||||||
|
matches[3] = malloc(sizeof(array)*n_conf);
|
||||||
|
// compatibilities, 1 for each template
|
||||||
|
|
||||||
configs = malloc(sizeof(template)*n_conf);
|
configs = malloc(sizeof(template)*n_conf);
|
||||||
// data for each template
|
// data for each template
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
#ifndef BACK_GEN_H
|
#ifndef BACK_GEN_H
|
||||||
#define BACK_GEN_H
|
#define BACK_GEN_H
|
||||||
|
|
||||||
|
void one_debug();
|
||||||
|
|
||||||
bool unpack_coord(uint8_t* lines, int cx, int cy);
|
bool unpack_coord(uint8_t* lines, int cx, int cy);
|
||||||
|
|
||||||
|
bool is_compatible(chunk ch, cardinal dir, int config_id);
|
||||||
|
|
||||||
void generate_chunk(int x, int y, int config_id);
|
void generate_chunk(int x, int y, int config_id);
|
||||||
|
|
||||||
void print_template(int config_id);
|
void print_template(int config_id);
|
||||||
|
|
||||||
void rotateTemplateClockWise(int config_id);
|
void rotateTemplateClockWise(int config_id);
|
||||||
|
|
||||||
|
bool is_compat_one(int cx, int cy, cardinal dir, int idx);
|
||||||
|
|
||||||
void signature(template t);
|
void signature(template t);
|
||||||
|
|
||||||
bool is_compat_with_spins(int cx, int cy, int idx);
|
bool is_compat_with_spins(int cx, int cy, int idx);
|
||||||
|
|
|
@ -43,7 +43,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
/* -------------------------------------------------------- */
|
/* -------------------------------------------------------- */
|
||||||
//one_debug();
|
//one_debug();
|
||||||
parse_configs("templates.txt", 32);
|
parse_configs("templates.txt", 23);
|
||||||
|
|
||||||
initialize(rend);
|
initialize(rend);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ double epsilon_x = 0.0;
|
||||||
double epsilon_y = 0.0;
|
double epsilon_y = 0.0;
|
||||||
|
|
||||||
bool checkCollision() {
|
bool checkCollision() {
|
||||||
return (unpack_coord(gridGet(map, player_cx, player_cy)->chdata.lines, player_x, player_y));
|
return unpack_coord(gridGet(map, player_cx, player_cy)->chdata.lines, player_x, player_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void increment_x(double dx) {
|
void increment_x(double dx) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ extern int __width__ ;
|
||||||
extern int __height__ ;
|
extern int __height__ ;
|
||||||
|
|
||||||
extern template* configs ;
|
extern template* configs ;
|
||||||
|
extern array** matches ; // first length is always 4 (NESW)
|
||||||
extern int n_configs ; // 2nd length
|
extern int n_configs ; // 2nd length
|
||||||
|
|
||||||
extern imgs digits ;
|
extern imgs digits ;
|
||||||
|
|
|
@ -34,15 +34,6 @@
|
||||||
1 1 1 0 0 1 1 1
|
1 1 1 0 0 1 1 1
|
||||||
1 1 1 0 0 1 1 1
|
1 1 1 0 0 1 1 1
|
||||||
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 0 0 0 0 0
|
|
||||||
1 1 1 0 0 0 0 0
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
|
|
||||||
1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1
|
||||||
1 0 0 0 0 0 0 1
|
1 0 0 0 0 0 0 1
|
||||||
1 0 0 0 0 0 0 1
|
1 0 0 0 0 0 0 1
|
||||||
|
@ -61,15 +52,6 @@
|
||||||
1 1 1 0 0 1 1 1
|
1 1 1 0 0 1 1 1
|
||||||
1 1 1 0 0 1 1 1
|
1 1 1 0 0 1 1 1
|
||||||
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
0 0 0 0 0 0 0 0
|
|
||||||
0 0 0 0 0 0 0 0
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
|
|
||||||
1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1
|
||||||
1 0 0 0 0 0 0 1
|
1 0 0 0 0 0 0 1
|
||||||
1 0 0 0 0 0 0 1
|
1 0 0 0 0 0 0 1
|
||||||
|
@ -88,15 +70,6 @@
|
||||||
1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1
|
||||||
1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1
|
||||||
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
0 0 0 0 0 0 0 0
|
|
||||||
0 0 0 0 0 0 0 0
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
|
|
||||||
1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1
|
||||||
1 1 0 0 0 0 1 1
|
1 1 0 0 0 0 1 1
|
||||||
1 1 0 0 0 0 1 1
|
1 1 0 0 0 0 1 1
|
||||||
|
@ -232,60 +205,6 @@
|
||||||
0 0 1 0 0 1 1 1
|
0 0 1 0 0 1 1 1
|
||||||
1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1
|
||||||
|
|
||||||
1 0 1 1 1 1 0 1
|
|
||||||
1 0 0 0 0 0 0 0
|
|
||||||
1 0 1 1 1 1 0 1
|
|
||||||
0 0 1 1 1 1 0 1
|
|
||||||
0 0 1 1 1 1 0 1
|
|
||||||
1 0 1 1 1 1 0 1
|
|
||||||
1 0 0 0 0 0 0 0
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
|
|
||||||
1 0 1 1 1 1 0 1
|
|
||||||
1 0 0 0 0 0 0 0
|
|
||||||
1 0 1 1 1 1 0 1
|
|
||||||
0 0 1 1 1 1 0 1
|
|
||||||
0 0 1 1 1 1 0 1
|
|
||||||
1 0 1 1 1 1 0 1
|
|
||||||
1 0 0 0 0 0 0 0
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
0 0 0 0 0 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
0 0 0 0 0 1 1 1
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
0 0 0 0 0 0 1 1
|
|
||||||
1 1 1 1 1 0 1 1
|
|
||||||
1 1 1 1 1 0 0 0
|
|
||||||
1 1 1 1 1 0 0 0
|
|
||||||
1 1 1 1 1 0 1 1
|
|
||||||
0 0 0 0 0 0 1 1
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
|
|
||||||
1 1 1 0 0 1 1 1
|
|
||||||
1 0 0 0 0 0 0 1
|
|
||||||
1 0 0 0 0 0 0 1
|
|
||||||
1 0 0 0 0 0 0 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
1 1 1 1 1 1 1 1
|
|
||||||
|
|
||||||
$
|
$
|
||||||
|
|
||||||
format is :
|
format is :
|
||||||
|
|
Loading…
Reference in New Issue