more rooms

This commit is contained in:
Alexandre 2024-08-23 15:51:08 +02:00
parent ff4fb37e3a
commit 1b3e0eab80
8 changed files with 24 additions and 150 deletions

BIN
bin/back

Binary file not shown.

View File

@ -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, int di) {
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 ;
//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");
exit(1);
};
drawChunkToRenderer(renderer, todraw, xmin, xmax, ymin, ymax, dist);
drawChunkToRenderer(renderer, todraw, xmin, xmax, ymin, ymax);
if(dist != render_distance -1 && !gridMem(map, chx+1, chy)) {
generate_chunk_all(chx+1, chy);

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 drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax, int di);
void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, int ymin, int ymax);
void drawHashToRenderer(SDL_Renderer* renderer, int chx, int chy, int xmin, int xmax, int ymin, int ymax, int dist);

View File

@ -45,55 +45,10 @@ 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) {
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 new ;
new.id = src.id ;
@ -132,14 +87,7 @@ void print_template(int config_id) {
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");
}
@ -167,47 +115,9 @@ void rotateTemplateClockWise(int 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);
}
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) {
chunk* cp = gridGet(map, cx, cy-1);
if(cp == NULL) {
@ -250,34 +160,7 @@ void signature(template t) {
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);
@ -370,18 +253,7 @@ void parse_one(FILE* ptr, FILE* ptr2, int index) {
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(ptr2);
@ -391,15 +263,6 @@ void parse_configs(char* filename, int n_conf) {
// Initializing everything //
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);
// data for each template

View File

@ -1,20 +1,14 @@
#ifndef BACK_GEN_H
#define BACK_GEN_H
void one_debug();
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 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);

View File

@ -43,7 +43,7 @@ int main(int argc, char** argv) {
/* -------------------------------------------------------- */
//one_debug();
parse_configs("templates.txt", 30);
parse_configs("templates.txt", 32);
initialize(rend);

View File

@ -40,7 +40,6 @@ extern int __width__ ;
extern int __height__ ;
extern template* configs ;
extern array** matches ; // first length is always 4 (NESW)
extern int n_configs ; // 2nd length
extern imgs digits ;

View File

@ -268,6 +268,24 @@
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 :