implemented ALL config at the cost of my sanity, or what's left of it

This commit is contained in:
Alexandre 2024-08-23 13:57:43 +02:00
parent 09d8cd50a7
commit 878e9d6540
14 changed files with 535 additions and 126 deletions

View File

@ -6,6 +6,8 @@
"sdl_image.h": "c", "sdl_image.h": "c",
"sdl.h": "c", "sdl.h": "c",
"base.h": "c", "base.h": "c",
"limits": "c" "limits": "c",
"move.h": "c",
"stdbool.h": "c"
} }
} }

BIN
bin/back

Binary file not shown.

View File

@ -168,6 +168,36 @@ bool arr_mem(array arr, int elt) {
return false; 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) { void import_digits(SDL_Renderer* renderer) {

View File

@ -35,6 +35,16 @@ void terminate_line(FILE* ptr);
bool arr_mem(array arr, int elt); 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_digits(SDL_Renderer* renderer);
void import_letters(SDL_Renderer* renderer); void import_letters(SDL_Renderer* renderer);

View File

@ -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) { 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);
//signature(ch.chdata);
//printf("\n");
for(int i = 0; i < 8; i++) { 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++) { for(int j = 0; j < 8; j++) {
int cux = 50*(8*ch.chx + i); int cux = 50*(8*ch->chx + j);
int cuy = 50*(8*ch.chy + j); int cuy = 50*(8*ch->chy + i);
int cux2 = 50*(8*ch.chx + i+1); int cux2 = 50*(8*ch->chx + j+1);
int cuy2 = 50*(8*ch.chy + j+1); int cuy2 = 50*(8*ch->chy + i+1);
if(true) { if(true) {
//if(cux - 50/zoom > xmin || cux - 50/zoom < xmax || cuy > ymin || cuy < ymax) { //if(cux - 50/zoom > xmin || cux - 50/zoom < xmax || cuy > ymin || cuy < ymax) {
if(cur%2 == 1) { 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) { 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) { if(dist < render_distance) {
//printf("[DEBUG] drawing chunk (%d, %d)\n", chx, chy);
chunk* todraw = gridGet(map, chx, chy) ; chunk* todraw = gridGet(map, chx, chy) ;
if(todraw == NULL) { if(todraw == NULL) {
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);
//printf("[DEBUG] drawn chunk (%d, %d)\n", chx, chy);
if(!gridMem(map, chx+1, chy)) { if(dist != render_distance -1 && !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);
generate_chunk_all(chx+1, chy); generate_chunk_all(chx+1, chy);
//printf("[DEBUG] done\n");
}; };
if(!gridMem(map, chx-1, chy)) { if(dist != render_distance -1 && !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);
generate_chunk_all(chx-1, chy); generate_chunk_all(chx-1, chy);
//printf("[DEBUG] done\n");
}; };
if(!gridMem(map, chx, chy+1)) { if(dist != render_distance -1 && !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);
generate_chunk_all(chx, chy+1); generate_chunk_all(chx, chy+1);
//printf("[DEBUG] done\n");
}; };
if(!gridMem(map, chx, chy-1)) { if(dist != render_distance -1 && !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);
generate_chunk_all(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);
drawHashToRenderer(renderer, chx-1, chy, xmin, xmax, ymin, ymax, dist+1); drawHashToRenderer(renderer, chx-1, chy, xmin, xmax, ymin, ymax, dist+1);

View File

@ -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);

View File

@ -22,9 +22,9 @@ Grid map ;
template* configs ; template* configs ;
array** matches ; array** matches ;
int n_configs = 2; int n_configs = 18;
int render_distance = 3 ; int render_distance = 4 ;
int player_x = 4; int player_x = 4;
int player_y = 4; int player_y = 4;
@ -32,7 +32,7 @@ int player_y = 4;
int player_cx = 0; int player_cx = 0;
int player_cy = 0; int player_cy = 0;
int zoom = 250 ; int zoom = 75 ;
int draw_par = 1; int draw_par = 1;
int __width__ = 1200 ; int __width__ = 1200 ;
@ -41,6 +41,8 @@ int __height__ = 800 ;
imgs digits ; imgs digits ;
imgs letters ; imgs letters ;
template full ;
// ------------------------------------------------------------------------ // // ------------------------------------------------------------------------ //
void one_debug() { 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); return arr_mem(matches[(int)dir][ch.chdata.id], 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) { void generate_chunk(int x, int y, int config_id) {
chunk* new = malloc(sizeof(chunk)) ; chunk* new = malloc(sizeof(chunk)) ;
new->chx = x ; new->chx = x ;
new->chy = y ; new->chy = y ;
new->draw_id = draw_par - 2; new->draw_id = draw_par - 2;
new->chdata = configs[config_id]; if(config_id >= 0) {
//printf(" inserting\n"); 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); gridInsert(map, x, y, new);
} }
void select_config(chunk ch, cardinal dir) { void print_template(int config_id) {
//printf(" in\n"); for(int i = 0; i < 8; i++) {
int i = 1 + (rand()%n_configs); uint8_t rem = configs[config_id].lines[i];
int idx = 0 ; for(int j = 0; j < 8; j++) {
//printf("init : %d\n", i); if(rem%2 == 1) {
while(i > 0) { printf("X ");
//printf(" current : %d | %d\n", i, idx);
if(is_compatible(ch, dir, idx)) {
i -= 1;
if(i != 0) {
idx = (idx+1)%n_configs;
};
//printf(" pass\n");
} else { } else {
idx = (idx+1)%n_configs; printf(" ");
//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) { if(config_id >= 9 ) {
generate_chunk(ch.chx, ch.chy - 1, idx); //print_template(config_id);
} else if(dir == SOUTH) { }
generate_chunk(ch.chx, ch.chy + 1, idx);
} else if(dir == EAST) { if(false) {
generate_chunk(ch.chx + 1, ch.chy, idx); int* temp = matches[0][config_id].arr;
} else { int len0 = matches[0][config_id].len;
generate_chunk(ch.chx - 1, ch.chy, idx);
}; matches[0][config_id].arr = matches[1][config_id].arr;
//printf(" out\n"); 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) { 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 true;
}; };
return is_compatible(*gridGet(map, cx, cy), dir, idx); return is_compatible(*gridGet(map, cx, cy), dir, idx);
} }
void generate_chunk_all(int cx, int cy) { bool is_compat_sig_north(int cx, int cy, int idx) {
int i = 1 + (rand()%n_configs); chunk* cp = gridGet(map, cx, cy-1);
int idx = 0 ; if(cp == NULL) {
while(i > 0) { return true;
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;
}
} else { } else {
idx = (idx+1)%n_configs; 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 {
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); generate_chunk(cx, cy, idx);
} }
void initialize(SDL_Renderer* renderer) { void initialize(SDL_Renderer* renderer) {
map = newGrid(); map = newGrid();
import_letters(renderer); import_letters(renderer);
import_digits(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() { void destroy() {
freeGrid(map); freeGrid(map);
free_digits(digits); free_digits(digits);
free_digits(letters); free_digits(letters);
free(full.lines);
} }
void parse_one(FILE* ptr, FILE* ptr2, int index) { 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); int xres = get_integer_plus_align(ptr, ptr2);
configs[index].lines[i] *= 2 ; configs[index].lines[i] *= 2 ;
configs[index].lines[i] += xres ; 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++) { for(int i = 0; i < 4; i++) {
int len = count_char_in_line(ptr2, ','); int len = count_char_in_line(ptr2, ',');
matches[i][index].len = len ; 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 '[' 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); int read = get_integer(ptr);
matches[i][index].arr[j] = read ; matches[i][index].arr[j] = read ;
}; };
terminate_line(ptr); terminate_line(ptr);
}; };*/
terminate_line(ptr); terminate_line(ptr);
terminate_line(ptr2); terminate_line(ptr2);
@ -211,6 +405,8 @@ void parse_configs(char* filename, int n_conf) {
for(int i = 0; i < n_conf; i++) { for(int i = 0; i < n_conf; i++) {
configs[i].id = i; configs[i].id = i;
configs[i].eastsig = 0 ;
configs[i].westsig = 0 ;
configs[i].lines = malloc(sizeof(uint8_t)*8); configs[i].lines = malloc(sizeof(uint8_t)*8);
for(int j = 0; j < 8; j++) { for(int j = 0; j < 8; j++) {
configs[i].lines[j] = 0; configs[i].lines[j] = 0;

View File

@ -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 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); 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 generate_chunk_all(int cx, int cy);
void initialize(SDL_Renderer* renderer); void initialize(SDL_Renderer* renderer);

View File

@ -45,7 +45,7 @@ void freeGrid(Grid grid) {
free(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; int index = hash % grid->capacity;
//printf(" inserting at index [%d]", index); //printf(" inserting at index [%d]", index);
List* data = grid->data; List* data = grid->data;
@ -53,6 +53,8 @@ void subGridInsert(Grid grid, int hash, chunk* elt) {
//printf(" <-->\n"); //printf(" <-->\n");
List list = malloc(sizeof(struct List)); List list = malloc(sizeof(struct List));
list->hash = hash; list->hash = hash;
list->x = x;
list->y = y;
list->elt = elt; list->elt = elt;
list->next = NULL; list->next = NULL;
grid->size++; grid->size++;
@ -64,11 +66,13 @@ void subGridInsert(Grid grid, int hash, chunk* elt) {
list = list->next; list = list->next;
}; };
//printf(" <>\n"); //printf(" <>\n");
if (list->hash == hash) { if (list->x == x && list->y == y) {
list->elt = elt; list->elt = elt;
} else { } else {
List nex = malloc(sizeof(struct List)); List nex = malloc(sizeof(struct List));
nex->hash = hash; nex->hash = hash;
nex->x = x;
nex->y = y;
nex->elt = elt; nex->elt = elt;
nex->next = NULL; nex->next = NULL;
list->next = nex; list->next = nex;
@ -82,7 +86,7 @@ void gridInsert(Grid grid, int x, int z, chunk* elt) {
grid->size = 0; grid->size = 0;
grid->capacity *= 2; grid->capacity *= 2;
//printf("resizing\n"); printf("resizing\n");
List* old_data = grid->data; List* old_data = grid->data;
grid->data = malloc(sizeof(List) * grid->capacity);; 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++) { for (int i = 0; i < grid->capacity/2; i++) {
List list = old_data[i]; List list = old_data[i];
while (list != NULL) { while (list != NULL) {
subGridInsert(grid, list->hash, list->elt); subGridInsert(grid, list->hash, list->elt, list->x, list->y);
list = list->next; list = list->next;
} }
} }
}; };
int hash = generate_hash(x, z); int hash = generate_hash(x, z);
subGridInsert(grid, hash, elt); subGridInsert(grid, hash, elt, x, z);
} }
chunk* gridGet(Grid grid, int x, int z) { chunk* gridGet(Grid grid, int x, int z) {
int hash = generate_hash(x, z); int hash = generate_hash(x, z);
int index = hash % grid->capacity; int index = hash % grid->capacity;
List list = grid->data[index]; List list = grid->data[index];
while (list != NULL && list->hash != hash) { while (list != NULL && (list->x != x || list->y != z)) {
list = list->next; list = list->next;
} }
if (list == NULL) { if (list == NULL) {
@ -119,7 +123,7 @@ bool gridMem(Grid grid, int x, int z) {
int hash = generate_hash(x, z); int hash = generate_hash(x, z);
int index = hash % grid->capacity; int index = hash % grid->capacity;
List list = grid->data[index]; List list = grid->data[index];
while (list != NULL && list->hash != hash) { while (list != NULL && (list->x != x || list->y != z)) {
list = list->next; list = list->next;
} }
if (list == NULL) { if (list == NULL) {
@ -153,9 +157,9 @@ chunk* gridRemove(Grid grid, int x, int z) {
Grid newGrid() { Grid newGrid() {
Grid grid = malloc(sizeof(struct Grid)); Grid grid = malloc(sizeof(struct Grid));
grid->data = malloc(sizeof(List) * 8); grid->data = malloc(sizeof(List) * 800);
grid->size = 0; grid->size = 0;
grid->capacity = 8; grid->capacity = 800;
grid->loadFactor = 0.75; grid->loadFactor = 0.75;
for (int i = 0; i < grid->capacity; i++) { for (int i = 0; i < grid->capacity; i++) {
grid->data[i] = NULL; grid->data[i] = NULL;

View File

@ -7,13 +7,16 @@
typedef struct template { typedef struct template {
uint8_t id ; uint8_t id ;
uint8_t* lines ; // len = 8 uint8_t* lines ; // len = 8
uint8_t eastsig ;
uint8_t westsig ;
} template ; } template ;
typedef struct chunk { typedef struct chunk {
int16_t chx ; int16_t chx ;
int16_t chy ; int16_t chy ;
uint8_t draw_id ; int draw_id ;
template chdata ; template chdata ;
} chunk ; } chunk ;
@ -22,6 +25,8 @@ typedef struct chunk {
typedef struct List { typedef struct List {
int hash; int hash;
int x;
int y;
chunk* elt; chunk* elt;
struct List* next; struct List* next;
} *List; } *List;

View File

@ -43,10 +43,14 @@ int main(int argc, char** argv) {
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */
//one_debug(); //one_debug();
parse_configs("templates.txt", 2); parse_configs("templates.txt", 23);
initialize(rend); initialize(rend);
//print_template(1);
//rotateTemplateClockWise(1);
//print_template(1);
moveFunctionMaster(rend); moveFunctionMaster(rend);
destroy(); destroy();

View File

@ -69,7 +69,7 @@ void increment_y(double dy) {
bool moveRequest(double dx, double dy) { bool moveRequest(double dx, double dy) {
increment_x(dx); increment_x(dx);
increment_y(dy); increment_y(dy);
if(checkCollision()) { if(false && checkCollision()) {
increment_x(-dx); increment_x(-dx);
increment_y(-dy); increment_y(-dy);
return false; return false;
@ -110,7 +110,7 @@ void moveControl(bool* halt) {
*halt = true; *halt = true;
break; break;
case SDLK_m: case SDLK_m:
zoom = max(100, zoom-25); zoom = max(25, zoom-25);
break; break;
case SDLK_p: case SDLK_p:
zoom = min(2250, zoom+25); 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_x*100), 2 * __width__ / 3, 10, 50, 70, 0);
drawNumberToRenderer(renderer, digits, to_int(epsilon_y*100), 2 * __width__ / 3, 80, 50, 70, 0); drawNumberToRenderer(renderer, digits, to_int(epsilon_y*100), 2 * __width__ / 3, 80, 50, 70, 0);
updateRenderer(renderer); updateRenderer(renderer);
draw_par += 1 ;
usleep(20000); usleep(20000);
} }
} }

View File

@ -11,7 +11,7 @@ typedef struct array {
int len ; int len ;
} array ; } array ;
typedef enum cardinal {NORTH, SOUTH, EAST, WEST} cardinal ; typedef enum cardinal {NORTH, EAST, SOUTH, WEST} cardinal ;
extern Grid map ; extern Grid map ;
@ -46,23 +46,6 @@ extern int n_configs ; // 2nd length
extern imgs digits ; extern imgs digits ;
extern imgs letters ; extern imgs letters ;
/* example extern template full ;
[
[
[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"
],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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 eight lines with eight 0s and 1s in each
four lists separated with a \n containing compatibilities with other configs 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...) 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 separate two templates with \n\n