implemented ALL config at the cost of my sanity, or what's left of it
This commit is contained in:
parent
09d8cd50a7
commit
878e9d6540
|
@ -6,6 +6,8 @@
|
|||
"sdl_image.h": "c",
|
||||
"sdl.h": "c",
|
||||
"base.h": "c",
|
||||
"limits": "c"
|
||||
"limits": "c",
|
||||
"move.h": "c",
|
||||
"stdbool.h": "c"
|
||||
}
|
||||
}
|
30
src/base.c
30
src/base.c
|
@ -168,6 +168,36 @@ bool arr_mem(array arr, int elt) {
|
|||
return false;
|
||||
}
|
||||
|
||||
cardinal rotateClockWise(cardinal dir) {
|
||||
return ((cardinal)((int)dir+1)%4);
|
||||
}
|
||||
|
||||
cardinal rotateCounterWise(cardinal dir) {
|
||||
return ((cardinal)((int)dir+3)%4);
|
||||
}
|
||||
|
||||
void indent(array* arr, int i) {
|
||||
for(int j = i; j < arr->len -1; j++) {
|
||||
arr->arr[j] = arr->arr[j+1];
|
||||
}
|
||||
arr->len -= 1 ;
|
||||
}
|
||||
|
||||
void append(array* arr, int elt) {
|
||||
arr->arr[arr->len] = elt ;
|
||||
arr->len += 1 ;
|
||||
}
|
||||
|
||||
void pop(array* arr, int elt) {
|
||||
int abort = 1 ;
|
||||
for(int i = 0; i < arr->len * abort; i++) {
|
||||
if(arr->arr[i] == elt) {
|
||||
abort = 0 ;
|
||||
indent(arr, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------ //
|
||||
|
||||
void import_digits(SDL_Renderer* renderer) {
|
||||
|
|
10
src/base.h
10
src/base.h
|
@ -35,6 +35,16 @@ void terminate_line(FILE* ptr);
|
|||
|
||||
bool arr_mem(array arr, int elt);
|
||||
|
||||
cardinal rotateClockWise(cardinal dir);
|
||||
|
||||
cardinal rotateCounterWise(cardinal dir);
|
||||
|
||||
void indent(array* arr, int i);
|
||||
|
||||
void append(array* arr, int elt);
|
||||
|
||||
void pop(array* arr, int elt);
|
||||
|
||||
void import_digits(SDL_Renderer* renderer);
|
||||
|
||||
void import_letters(SDL_Renderer* renderer);
|
||||
|
|
|
@ -136,16 +136,19 @@ 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) {
|
||||
if(ch.draw_id != draw_par) {
|
||||
ch.draw_id = draw_par ;
|
||||
void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax, int di) {
|
||||
if(ch->draw_id != draw_par) {
|
||||
ch->draw_id = draw_par ;
|
||||
//printf("[DDDDD] chunk (%d, %d) has signature : \n", ch.chx, ch.chy);
|
||||
//signature(ch.chdata);
|
||||
//printf("\n");
|
||||
for(int i = 0; i < 8; i++) {
|
||||
uint8_t cur = ch.chdata.lines[i] ;
|
||||
uint8_t cur = ch->chdata.lines[i] ;
|
||||
for(int j = 0; j < 8; j++) {
|
||||
int cux = 50*(8*ch.chx + i);
|
||||
int cuy = 50*(8*ch.chy + j);
|
||||
int cux2 = 50*(8*ch.chx + i+1);
|
||||
int cuy2 = 50*(8*ch.chy + j+1);
|
||||
int cux = 50*(8*ch->chx + j);
|
||||
int cuy = 50*(8*ch->chy + i);
|
||||
int cux2 = 50*(8*ch->chx + j+1);
|
||||
int cuy2 = 50*(8*ch->chy + i+1);
|
||||
if(true) {
|
||||
//if(cux - 50/zoom > xmin || cux - 50/zoom < xmax || cuy > ymin || cuy < ymax) {
|
||||
if(cur%2 == 1) {
|
||||
|
@ -163,42 +166,26 @@ void drawChunkToRenderer(SDL_Renderer* renderer, chunk ch, int xmin, int xmax, i
|
|||
}
|
||||
|
||||
void drawHashToRenderer(SDL_Renderer* renderer, int chx, int chy, int xmin, int xmax, int ymin, int ymax, int dist) {
|
||||
//printf("[DEBUG]%d / %d\n", dist, render_distance);
|
||||
if(dist < render_distance) {
|
||||
//printf("[DEBUG] drawing chunk (%d, %d)\n", chx, chy);
|
||||
chunk* todraw = gridGet(map, chx, chy) ;
|
||||
if(todraw == NULL) {
|
||||
fprintf(stderr, "NO\n");
|
||||
exit(1);
|
||||
};
|
||||
drawChunkToRenderer(renderer, *todraw, xmin, xmax, ymin, ymax);
|
||||
//printf("[DEBUG] drawn chunk (%d, %d)\n", chx, chy);
|
||||
drawChunkToRenderer(renderer, todraw, xmin, xmax, ymin, ymax, dist);
|
||||
|
||||
if(!gridMem(map, chx+1, chy)) {
|
||||
//printf("[DEBUG] (%d, %d) from (%d, %d)\n", chx+1, chy, chx, chy);
|
||||
//select_config(*gridGet(map, chx, chy), EAST);
|
||||
if(dist != render_distance -1 && !gridMem(map, chx+1, chy)) {
|
||||
generate_chunk_all(chx+1, chy);
|
||||
//printf("[DEBUG] done\n");
|
||||
};
|
||||
if(!gridMem(map, chx-1, chy)) {
|
||||
//printf("[DEBUG] (%d, %d) from (%d, %d)\n", chx-1, chy, chx, chy);
|
||||
//select_config(*gridGet(map, chx, chy), WEST);
|
||||
if(dist != render_distance -1 && !gridMem(map, chx-1, chy)) {
|
||||
generate_chunk_all(chx-1, chy);
|
||||
//printf("[DEBUG] done\n");
|
||||
};
|
||||
if(!gridMem(map, chx, chy+1)) {
|
||||
//printf("[DEBUG] (%d, %d) from (%d, %d)\n", chx, chy+1, chx, chy);
|
||||
//select_config(*gridGet(map, chx, chy), SOUTH);
|
||||
if(dist != render_distance -1 && !gridMem(map, chx, chy+1)) {
|
||||
generate_chunk_all(chx, chy+1);
|
||||
//printf("[DEBUG] done\n");
|
||||
};
|
||||
if(!gridMem(map, chx, chy-1)) {
|
||||
//printf("[DEBUG] (%d, %d) from (%d, %d)\n", chx, chy-1, chx, chy);
|
||||
//select_config(*gridGet(map, chx, chy), NORTH);
|
||||
if(dist != render_distance -1 && !gridMem(map, chx, chy-1)) {
|
||||
generate_chunk_all(chx, chy-1);
|
||||
//printf("[DEBUG] done\n");
|
||||
};
|
||||
//printf("[DEBUG] recursive (%d, %d)\n", chx, chy);
|
||||
|
||||
drawHashToRenderer(renderer, chx+1, chy, xmin, xmax, ymin, ymax, dist+1);
|
||||
drawHashToRenderer(renderer, chx-1, chy, xmin, xmax, ymin, ymax, dist+1);
|
||||
|
|
|
@ -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 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);
|
||||
|
||||
|
|
290
src/generation.c
290
src/generation.c
|
@ -22,9 +22,9 @@ Grid map ;
|
|||
|
||||
template* configs ;
|
||||
array** matches ;
|
||||
int n_configs = 2;
|
||||
int n_configs = 18;
|
||||
|
||||
int render_distance = 3 ;
|
||||
int render_distance = 4 ;
|
||||
|
||||
int player_x = 4;
|
||||
int player_y = 4;
|
||||
|
@ -32,7 +32,7 @@ int player_y = 4;
|
|||
int player_cx = 0;
|
||||
int player_cy = 0;
|
||||
|
||||
int zoom = 250 ;
|
||||
int zoom = 75 ;
|
||||
int draw_par = 1;
|
||||
|
||||
int __width__ = 1200 ;
|
||||
|
@ -41,6 +41,8 @@ int __height__ = 800 ;
|
|||
imgs digits ;
|
||||
imgs letters ;
|
||||
|
||||
template full ;
|
||||
|
||||
// ------------------------------------------------------------------------ //
|
||||
|
||||
void one_debug() {
|
||||
|
@ -92,81 +94,265 @@ bool is_compatible(chunk ch, cardinal dir, int config_id) {
|
|||
return arr_mem(matches[(int)dir][ch.chdata.id], config_id);
|
||||
}
|
||||
|
||||
void generate_chunk(int x, int y, int config_id) {
|
||||
template copy(template src) {
|
||||
template new ;
|
||||
new.id = src.id ;
|
||||
new.eastsig = src.eastsig;
|
||||
new.westsig = src.westsig;
|
||||
new.lines = malloc(sizeof(uint8_t)*8);
|
||||
for(int i = 0; i < 8; i++) {
|
||||
new.lines[i] = src.lines[i];
|
||||
};
|
||||
return new;
|
||||
}
|
||||
|
||||
void generate_chunk(int x, int y, int config_id) {
|
||||
chunk* new = malloc(sizeof(chunk)) ;
|
||||
new->chx = x ;
|
||||
new->chy = y ;
|
||||
new->draw_id = draw_par - 2;
|
||||
new->chdata = configs[config_id];
|
||||
//printf(" inserting\n");
|
||||
if(config_id >= 0) {
|
||||
new->chdata = copy(configs[config_id]);
|
||||
} else {
|
||||
new->chdata = copy(full) ;
|
||||
};
|
||||
//printf("inserting chunk (%d, %d)[%d]\n", new->chx, new->chy, new->draw_id);
|
||||
gridInsert(map, x, y, new);
|
||||
}
|
||||
|
||||
void select_config(chunk ch, cardinal dir) {
|
||||
//printf(" in\n");
|
||||
int i = 1 + (rand()%n_configs);
|
||||
int idx = 0 ;
|
||||
//printf("init : %d\n", i);
|
||||
while(i > 0) {
|
||||
//printf(" current : %d | %d\n", i, idx);
|
||||
if(is_compatible(ch, dir, idx)) {
|
||||
i -= 1;
|
||||
if(i != 0) {
|
||||
idx = (idx+1)%n_configs;
|
||||
void print_template(int config_id) {
|
||||
for(int i = 0; i < 8; i++) {
|
||||
uint8_t rem = configs[config_id].lines[i];
|
||||
for(int j = 0; j < 8; j++) {
|
||||
if(rem%2 == 1) {
|
||||
printf("X ");
|
||||
} else {
|
||||
printf(" ");
|
||||
};
|
||||
//printf(" pass\n");
|
||||
} else {
|
||||
idx = (idx+1)%n_configs;
|
||||
//printf(" smash\n");
|
||||
rem = rem/2 ;
|
||||
};
|
||||
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");
|
||||
}
|
||||
|
||||
void rotateTemplateClockWise(int config_id) {
|
||||
// 1st line become last column ... last line become 1st column
|
||||
uint8_t* new = malloc(sizeof(uint8_t)*8);
|
||||
|
||||
configs[config_id].westsig = configs[config_id].lines[7];
|
||||
configs[config_id].eastsig = configs[config_id].lines[0];
|
||||
|
||||
for(int i = 0; i < 8; i++) {
|
||||
new[i] = configs[config_id].lines[i];
|
||||
configs[config_id].lines[i] = 0;
|
||||
};
|
||||
for(int i = 0; i < 8; i++) {
|
||||
uint8_t rem = new[i];
|
||||
for(int j = 0; j < 8; j++) {
|
||||
configs[config_id].lines[j] *= 2 ;
|
||||
configs[config_id].lines[j] += rem%2 ;
|
||||
rem = rem / 2 ;
|
||||
}
|
||||
};
|
||||
//printf("chosen : %d\n\n", idx);
|
||||
if(dir == NORTH) {
|
||||
generate_chunk(ch.chx, ch.chy - 1, idx);
|
||||
} else if(dir == SOUTH) {
|
||||
generate_chunk(ch.chx, ch.chy + 1, idx);
|
||||
} else if(dir == EAST) {
|
||||
generate_chunk(ch.chx + 1, ch.chy, idx);
|
||||
} else {
|
||||
generate_chunk(ch.chx - 1, ch.chy, idx);
|
||||
};
|
||||
//printf(" out\n");
|
||||
|
||||
if(config_id >= 9 ) {
|
||||
//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);
|
||||
}
|
||||
|
||||
bool is_compat_one(int cx, int cy, cardinal dir, int idx) {
|
||||
if(!gridMem(map, cx, cy)) {
|
||||
if(idx == -1 || !gridMem(map, cx, cy)) {
|
||||
return true;
|
||||
};
|
||||
return is_compatible(*gridGet(map, cx, cy), dir, idx);
|
||||
}
|
||||
|
||||
void generate_chunk_all(int cx, int cy) {
|
||||
int i = 1 + (rand()%n_configs);
|
||||
int idx = 0 ;
|
||||
while(i > 0) {
|
||||
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)) {
|
||||
i -= 1;
|
||||
if(i != 0) {
|
||||
idx = (idx+1)%n_configs;
|
||||
bool is_compat_sig_north(int cx, int cy, int idx) {
|
||||
chunk* cp = gridGet(map, cx, cy-1);
|
||||
if(cp == NULL) {
|
||||
return true;
|
||||
} else {
|
||||
return cp->chdata.lines[7] == configs[idx].lines[0];
|
||||
}
|
||||
}
|
||||
bool is_compat_sig_south(int cx, int cy, int idx) {
|
||||
chunk* cp = gridGet(map, cx, cy+1);
|
||||
if(cp == NULL) {
|
||||
return true;
|
||||
} else {
|
||||
return cp->chdata.lines[0] == configs[idx].lines[7];
|
||||
}
|
||||
}
|
||||
bool is_compat_sig_east(int cx, int cy, int idx) {
|
||||
chunk* cp = gridGet(map, cx+1, cy);
|
||||
if(cp == NULL) {
|
||||
return true;
|
||||
} else {
|
||||
return cp->chdata.westsig == configs[idx].eastsig;
|
||||
}
|
||||
}
|
||||
bool is_compat_sig_west(int cx, int cy, int idx) {
|
||||
chunk* cp = gridGet(map, cx-1, cy);
|
||||
if(cp == NULL) {
|
||||
return true;
|
||||
} else {
|
||||
return cp->chdata.eastsig == configs[idx].westsig;
|
||||
}
|
||||
}
|
||||
|
||||
void signature(template t) {
|
||||
printf("[NORTH] %d\n", t.lines[0]);
|
||||
printf("[EAST] %d\n", t.eastsig);
|
||||
printf("[SOUTH] %d\n", t.lines[7]);
|
||||
printf("[WEST] %d\n\n", t.westsig);
|
||||
}
|
||||
|
||||
bool is_compat_with_spins(int cx, int cy, int idx) {
|
||||
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)) {
|
||||
|
||||
/*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 ;
|
||||
} else {
|
||||
idx = (idx+1)%n_configs;
|
||||
rotateTemplateClockWise(idx);
|
||||
}
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_compat_with_spins_uno(int cx, int cy, int 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)) {
|
||||
return true ;
|
||||
} else {
|
||||
rotateTemplateClockWise(idx);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void generate_chunk_all(int cx, int cy) {
|
||||
int i = 1 + (rand()%(4*n_configs));
|
||||
int idx = 0 ;
|
||||
int turn = 0 ;
|
||||
int k = 0 ;
|
||||
while(i > 0) {
|
||||
if(turn > 8*n_configs) {
|
||||
i = 0 ;
|
||||
idx = 0 ;
|
||||
printf("failed\n");
|
||||
} else {
|
||||
if(is_compat_with_spins_uno(cx, cy, idx)) {
|
||||
i -= 1;
|
||||
if(i != 0) {
|
||||
if(k == 3) {
|
||||
idx = (idx+1)%n_configs;
|
||||
k = 0 ;
|
||||
} else {
|
||||
k++ ;
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if(k == 3) {
|
||||
idx = (idx+1)%n_configs;
|
||||
turn += 1;
|
||||
k = 0 ;
|
||||
} else {
|
||||
k++ ;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
//printf("\ngenerating %d\n", idx);
|
||||
generate_chunk(cx, cy, idx);
|
||||
}
|
||||
|
||||
void initialize(SDL_Renderer* renderer) {
|
||||
map = newGrid();
|
||||
|
||||
import_letters(renderer);
|
||||
import_digits(renderer);
|
||||
generate_chunk(0, 0, rand()%n_configs);
|
||||
|
||||
full.lines = malloc(sizeof(uint8_t)*8);
|
||||
for(int i = 0; i < 8; i++) {
|
||||
full.lines[i] = 255 ;
|
||||
};
|
||||
full.id = -1 ;
|
||||
|
||||
generate_chunk(0, 0, 1);
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
freeGrid(map);
|
||||
|
||||
free_digits(digits);
|
||||
free_digits(letters);
|
||||
|
||||
free(full.lines);
|
||||
}
|
||||
|
||||
void parse_one(FILE* ptr, FILE* ptr2, int index) {
|
||||
|
@ -175,19 +361,27 @@ void parse_one(FILE* ptr, FILE* ptr2, int index) {
|
|||
int xres = get_integer_plus_align(ptr, ptr2);
|
||||
configs[index].lines[i] *= 2 ;
|
||||
configs[index].lines[i] += xres ;
|
||||
|
||||
if(j == 0) {
|
||||
configs[index].westsig *= 2;
|
||||
configs[index].westsig += xres;
|
||||
} else if(j == 7) {
|
||||
configs[index].eastsig *= 2;
|
||||
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)*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++) {
|
||||
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(ptr2);
|
||||
|
@ -211,6 +405,8 @@ void parse_configs(char* filename, int n_conf) {
|
|||
|
||||
for(int i = 0; i < n_conf; i++) {
|
||||
configs[i].id = i;
|
||||
configs[i].eastsig = 0 ;
|
||||
configs[i].westsig = 0 ;
|
||||
configs[i].lines = malloc(sizeof(uint8_t)*8);
|
||||
for(int j = 0; j < 8; j++) {
|
||||
configs[i].lines[j] = 0;
|
||||
|
|
|
@ -9,10 +9,16 @@ bool is_compatible(chunk ch, cardinal dir, int config_id);
|
|||
|
||||
void generate_chunk(int x, int y, int config_id);
|
||||
|
||||
void select_config(chunk ch, cardinal dir);
|
||||
void print_template(int config_id);
|
||||
|
||||
void rotateTemplateClockWise(int config_id);
|
||||
|
||||
bool is_compat_one(int cx, int cy, cardinal dir, int idx);
|
||||
|
||||
void signature(template t);
|
||||
|
||||
bool is_compat_with_spins(int cx, int cy, int idx);
|
||||
|
||||
void generate_chunk_all(int cx, int cy);
|
||||
|
||||
void initialize(SDL_Renderer* renderer);
|
||||
|
|
22
src/hash.c
22
src/hash.c
|
@ -45,7 +45,7 @@ void freeGrid(Grid grid) {
|
|||
free(grid);
|
||||
}
|
||||
|
||||
void subGridInsert(Grid grid, int hash, chunk* elt) {
|
||||
void subGridInsert(Grid grid, int hash, chunk* elt, int x, int y) {
|
||||
int index = hash % grid->capacity;
|
||||
//printf(" inserting at index [%d]", index);
|
||||
List* data = grid->data;
|
||||
|
@ -53,6 +53,8 @@ void subGridInsert(Grid grid, int hash, chunk* elt) {
|
|||
//printf(" <-->\n");
|
||||
List list = malloc(sizeof(struct List));
|
||||
list->hash = hash;
|
||||
list->x = x;
|
||||
list->y = y;
|
||||
list->elt = elt;
|
||||
list->next = NULL;
|
||||
grid->size++;
|
||||
|
@ -64,11 +66,13 @@ void subGridInsert(Grid grid, int hash, chunk* elt) {
|
|||
list = list->next;
|
||||
};
|
||||
//printf(" <>\n");
|
||||
if (list->hash == hash) {
|
||||
if (list->x == x && list->y == y) {
|
||||
list->elt = elt;
|
||||
} else {
|
||||
List nex = malloc(sizeof(struct List));
|
||||
nex->hash = hash;
|
||||
nex->x = x;
|
||||
nex->y = y;
|
||||
nex->elt = elt;
|
||||
nex->next = NULL;
|
||||
list->next = nex;
|
||||
|
@ -82,7 +86,7 @@ void gridInsert(Grid grid, int x, int z, chunk* elt) {
|
|||
grid->size = 0;
|
||||
grid->capacity *= 2;
|
||||
|
||||
//printf("resizing\n");
|
||||
printf("resizing\n");
|
||||
|
||||
List* old_data = grid->data;
|
||||
grid->data = malloc(sizeof(List) * grid->capacity);;
|
||||
|
@ -92,21 +96,21 @@ void gridInsert(Grid grid, int x, int z, chunk* elt) {
|
|||
for (int i = 0; i < grid->capacity/2; i++) {
|
||||
List list = old_data[i];
|
||||
while (list != NULL) {
|
||||
subGridInsert(grid, list->hash, list->elt);
|
||||
subGridInsert(grid, list->hash, list->elt, list->x, list->y);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int hash = generate_hash(x, z);
|
||||
subGridInsert(grid, hash, elt);
|
||||
subGridInsert(grid, hash, elt, x, z);
|
||||
}
|
||||
|
||||
chunk* gridGet(Grid grid, int x, int z) {
|
||||
int hash = generate_hash(x, z);
|
||||
int index = hash % grid->capacity;
|
||||
List list = grid->data[index];
|
||||
while (list != NULL && list->hash != hash) {
|
||||
while (list != NULL && (list->x != x || list->y != z)) {
|
||||
list = list->next;
|
||||
}
|
||||
if (list == NULL) {
|
||||
|
@ -119,7 +123,7 @@ bool gridMem(Grid grid, int x, int z) {
|
|||
int hash = generate_hash(x, z);
|
||||
int index = hash % grid->capacity;
|
||||
List list = grid->data[index];
|
||||
while (list != NULL && list->hash != hash) {
|
||||
while (list != NULL && (list->x != x || list->y != z)) {
|
||||
list = list->next;
|
||||
}
|
||||
if (list == NULL) {
|
||||
|
@ -153,9 +157,9 @@ chunk* gridRemove(Grid grid, int x, int z) {
|
|||
|
||||
Grid newGrid() {
|
||||
Grid grid = malloc(sizeof(struct Grid));
|
||||
grid->data = malloc(sizeof(List) * 8);
|
||||
grid->data = malloc(sizeof(List) * 800);
|
||||
grid->size = 0;
|
||||
grid->capacity = 8;
|
||||
grid->capacity = 800;
|
||||
grid->loadFactor = 0.75;
|
||||
for (int i = 0; i < grid->capacity; i++) {
|
||||
grid->data[i] = NULL;
|
||||
|
|
|
@ -7,13 +7,16 @@
|
|||
typedef struct template {
|
||||
uint8_t id ;
|
||||
uint8_t* lines ; // len = 8
|
||||
|
||||
uint8_t eastsig ;
|
||||
uint8_t westsig ;
|
||||
} template ;
|
||||
|
||||
typedef struct chunk {
|
||||
int16_t chx ;
|
||||
int16_t chy ;
|
||||
|
||||
uint8_t draw_id ;
|
||||
int draw_id ;
|
||||
|
||||
template chdata ;
|
||||
} chunk ;
|
||||
|
@ -22,6 +25,8 @@ typedef struct chunk {
|
|||
|
||||
typedef struct List {
|
||||
int hash;
|
||||
int x;
|
||||
int y;
|
||||
chunk* elt;
|
||||
struct List* next;
|
||||
} *List;
|
||||
|
|
|
@ -43,10 +43,14 @@ int main(int argc, char** argv) {
|
|||
|
||||
/* -------------------------------------------------------- */
|
||||
//one_debug();
|
||||
parse_configs("templates.txt", 2);
|
||||
parse_configs("templates.txt", 23);
|
||||
|
||||
initialize(rend);
|
||||
|
||||
//print_template(1);
|
||||
//rotateTemplateClockWise(1);
|
||||
//print_template(1);
|
||||
|
||||
moveFunctionMaster(rend);
|
||||
|
||||
destroy();
|
||||
|
|
|
@ -69,7 +69,7 @@ void increment_y(double dy) {
|
|||
bool moveRequest(double dx, double dy) {
|
||||
increment_x(dx);
|
||||
increment_y(dy);
|
||||
if(checkCollision()) {
|
||||
if(false && checkCollision()) {
|
||||
increment_x(-dx);
|
||||
increment_y(-dy);
|
||||
return false;
|
||||
|
@ -110,7 +110,7 @@ void moveControl(bool* halt) {
|
|||
*halt = true;
|
||||
break;
|
||||
case SDLK_m:
|
||||
zoom = max(100, zoom-25);
|
||||
zoom = max(25, zoom-25);
|
||||
break;
|
||||
case SDLK_p:
|
||||
zoom = min(2250, zoom+25);
|
||||
|
@ -133,6 +133,7 @@ void moveFunctionMaster(SDL_Renderer* renderer) {
|
|||
drawNumberToRenderer(renderer, digits, to_int(epsilon_x*100), 2 * __width__ / 3, 10, 50, 70, 0);
|
||||
drawNumberToRenderer(renderer, digits, to_int(epsilon_y*100), 2 * __width__ / 3, 80, 50, 70, 0);
|
||||
updateRenderer(renderer);
|
||||
draw_par += 1 ;
|
||||
usleep(20000);
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ typedef struct array {
|
|||
int len ;
|
||||
} array ;
|
||||
|
||||
typedef enum cardinal {NORTH, SOUTH, EAST, WEST} cardinal ;
|
||||
typedef enum cardinal {NORTH, EAST, SOUTH, WEST} cardinal ;
|
||||
|
||||
extern Grid map ;
|
||||
|
||||
|
@ -46,23 +46,6 @@ extern int n_configs ; // 2nd length
|
|||
extern imgs digits ;
|
||||
extern imgs letters ;
|
||||
|
||||
/* example
|
||||
[
|
||||
[
|
||||
[1, 3], [0], [3], [2] <-- this 1 means "config 1 can be placed above a chunk with config 0"
|
||||
],
|
||||
[
|
||||
[1], [0], [3], [0, 2] <-- this (1st) 0 means "config 0 can be placed below a chunk with config 1"
|
||||
],
|
||||
[
|
||||
[1], [], [], []
|
||||
],
|
||||
[
|
||||
[1], [0], [], []
|
||||
]
|
||||
]
|
||||
*/
|
||||
|
||||
// chunk is 8x8 and (0, 0) is at top left
|
||||
extern template full ;
|
||||
|
||||
#endif
|
211
templates.txt
211
templates.txt
|
@ -1,28 +1,209 @@
|
|||
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 1 1 0 0 1 1 1
|
||||
1 1 1 0 0 1 1 1
|
||||
0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 1 1 0 0 1 1 1
|
||||
[0,1,]
|
||||
[0,1,]
|
||||
[0,1,]
|
||||
[0,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 0 0 0 0 0 0 1
|
||||
1 1 1 0 0 1 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0
|
||||
1 0 1 0 0 1 1 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 1 1 0 0 1 1 1
|
||||
[0,1,]
|
||||
[0,1,]
|
||||
[1,0,]
|
||||
[1,0,]
|
||||
|
||||
1 1 1 0 0 1 1 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 1 1 0 0 1
|
||||
0 0 1 1 1 1 0 0
|
||||
0 0 1 1 1 1 0 0
|
||||
1 0 0 1 1 0 0 1
|
||||
1 0 0 0 0 0 0 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 0 0 0 0 0 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 0 0 0 0 0
|
||||
1 0 0 0 0 0 0 0
|
||||
1 0 0 0 0 1 1 1
|
||||
1 0 0 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 0 0 0 0 0 0 1
|
||||
1 0 0 0 0 0 0 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 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 0 0 0 0 1 1
|
||||
1 1 0 0 0 0 1 1
|
||||
0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0
|
||||
1 1 0 0 0 0 1 1
|
||||
1 1 0 0 0 0 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
|
||||
1 0 0 0 0 0 1 1
|
||||
1 0 0 1 1 0 0 0
|
||||
1 0 0 1 1 0 0 0
|
||||
1 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
|
||||
0 0 0 1 0 0 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 0 0 1 0 0
|
||||
1 0 0 0 0 1 0 0
|
||||
1 0 0 0 0 0 0 1
|
||||
0 0 0 1 0 0 0 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
|
||||
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
|
||||
1 1 1 1 1 1 1 1
|
||||
|
||||
1 0 1 1 1 1 0 1
|
||||
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 0 0 1 1 1
|
||||
0 0 0 0 0 0 0 0
|
||||
1 0 1 1 1 1 0 1
|
||||
|
||||
1 1 1 0 0 1 1 1
|
||||
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
|
||||
0 0 0 0 0 0 0 0
|
||||
1 1 1 0 0 1 1 1
|
||||
|
||||
1 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 1 1 1 1 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 1 1 1 1 1 0 1
|
||||
0 0 0 0 0 0 0 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 0 0 0 0 0 1 1
|
||||
1 0 0 0 0 0 1 1
|
||||
1 0 0 0 0 0 1 1
|
||||
1 0 0 0 0 0 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 0 0 0 0 1 1
|
||||
0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0
|
||||
1 0 1 1 1 1 0 1
|
||||
1 0 1 1 1 1 0 1
|
||||
1 0 1 1 1 1 0 1
|
||||
|
||||
1 0 1 1 1 1 0 1
|
||||
1 0 1 1 1 1 0 1
|
||||
1 0 1 1 1 1 0 1
|
||||
0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 0 0
|
||||
1 0 1 1 1 1 0 1
|
||||
1 0 1 1 1 1 0 1
|
||||
1 0 1 1 1 1 0 1
|
||||
|
||||
1 1 1 0 0 1 1 1
|
||||
0 0 1 0 0 1 0 0
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 1 1 0 0 1
|
||||
1 0 0 1 1 0 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
0 0 1 0 0 1 0 0
|
||||
1 1 1 1 1 1 1 1
|
||||
|
||||
1 1 1 0 0 1 1 1
|
||||
0 0 1 0 0 1 0 0
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 1 1 0 0 1
|
||||
1 0 0 1 1 0 0 1
|
||||
1 0 0 0 0 0 0 1
|
||||
0 0 1 0 0 1 0 0
|
||||
1 1 1 0 0 1 1 1
|
||||
|
||||
1 1 1 0 0 1 1 1
|
||||
0 0 1 0 0 1 1 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 1 1 0 0 0
|
||||
1 0 0 1 1 0 0 0
|
||||
1 0 0 0 0 0 0 1
|
||||
0 0 1 0 0 1 1 1
|
||||
1 1 1 0 0 1 1 1
|
||||
|
||||
1 1 1 1 1 1 1 1
|
||||
0 0 1 0 0 1 1 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 1 1 0 0 0
|
||||
1 0 0 1 1 0 0 0
|
||||
1 0 0 0 0 0 0 1
|
||||
0 0 1 0 0 1 1 1
|
||||
1 1 1 0 0 1 1 1
|
||||
|
||||
1 1 1 0 0 1 1 1
|
||||
0 0 1 0 0 1 1 1
|
||||
1 0 0 0 0 0 0 1
|
||||
1 0 0 1 1 0 0 0
|
||||
1 0 0 1 1 0 0 0
|
||||
1 0 0 0 0 0 0 1
|
||||
0 0 1 0 0 1 1 1
|
||||
1 1 1 1 1 1 1 1
|
||||
|
||||
$
|
||||
|
||||
|
@ -30,6 +211,6 @@ format is :
|
|||
eight lines with eight 0s and 1s in each
|
||||
four lists separated with a \n containing compatibilities with other configs
|
||||
WARNING : do NOT forget the commas (1 for each)(otherwise seg fault will await...)
|
||||
order is NORTH SOUTH EAST WEST
|
||||
order is NORTH EAST SOUTH WEST
|
||||
|
||||
separate two templates with \n\n
|
Loading…
Reference in New Issue