added new template + fixed bug where some chunks would be mirrored

This commit is contained in:
Alexandre 2024-08-25 12:18:10 +02:00
parent 5d80d12382
commit faa2eccb2d
8 changed files with 487 additions and 14 deletions

View File

@ -4,8 +4,11 @@ LFLAGS = -lSDL2 -lSDL2_image -lm -lncurses
all: bin/back all: bin/back
test: bin/back test0: bin/back
bin/back bin/back templates.txt 47
test1: bin/back
bin/back templates_lv2.txt 49
bin/back: obj/main.o obj/generation.o obj/display.o obj/base.o obj/hash.o obj/move.o bin/back: obj/main.o obj/generation.o obj/display.o obj/base.o obj/hash.o obj/move.o
mkdir -p bin mkdir -p bin

BIN
bin/back

Binary file not shown.

View File

@ -99,6 +99,17 @@ int line_count(char* filename) {
return (n+1); return (n+1);
} }
int str_to_int(char* s) {
int res = 0 ;
int i = 0 ;
while(s[i] != '\0' && is_an_integer(s[i])) {
res *= 10 ;
res += (int)s[i] - 48 ;
i++;
};
return res;
}
int get_integer(FILE* ptr) { int get_integer(FILE* ptr) {
char c = fgetc(ptr); char c = fgetc(ptr);

View File

@ -25,6 +25,8 @@ double distance_pt(int x1, int x2, int y1, int y2);
int line_count(char* filename); int line_count(char* filename);
int str_to_int(char* s);
int get_integer(FILE* ptr); int get_integer(FILE* ptr);
int get_integer_plus_align(FILE* ptr, FILE* ptr2); int get_integer_plus_align(FILE* ptr, FILE* ptr2);

View File

@ -139,9 +139,6 @@ 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) {
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++) {
@ -150,13 +147,16 @@ void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax,
int cux2 = 50*(8*ch->chx + j+1); int cux2 = 50*(8*ch->chx + j+1);
int cuy2 = 50*(8*ch->chy + i+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(cur%2 == 1) { if(cur%2 == 1) {
int nxmin = to_int((to_double(cux) - to_double(xmin)) * to_double(__width__)) / (to_double(xmax) - to_double(xmin)) ; int nxmin = to_int((to_double(cux) - to_double(xmin)) * to_double(__width__)) / (to_double(xmax) - to_double(xmin)) ;
int nymin = to_int((to_double(cuy) - to_double(ymin)) * to_double(__height__)) / (to_double(ymax) - to_double(ymin)) ; int nymin = to_int((to_double(cuy) - to_double(ymin)) * to_double(__height__)) / (to_double(ymax) - to_double(ymin)) ;
int nxmin2 = to_int((to_double(cux2) - to_double(xmin)) * to_double(__width__)) / (to_double(xmax) - to_double(xmin)) ; int nxmin2 = to_int((to_double(cux2) - to_double(xmin)) * to_double(__width__)) / (to_double(xmax) - to_double(xmin)) ;
int nymin2 = to_int((to_double(cuy2) - to_double(ymin)) * to_double(__height__)) / (to_double(ymax) - to_double(ymin)) ; int nymin2 = to_int((to_double(cuy2) - to_double(ymin)) * to_double(__height__)) / (to_double(ymax) - to_double(ymin)) ;
placeRectToRenderer(renderer, nxmin, nymin, nxmin2 - nxmin, nymin2 - nymin, 255, 255, 255, SDL_ALPHA_OPAQUE); if(abs(ch->chx + ch->chy)%2 == 0) {
placeRectToRenderer(renderer, nxmin, nymin, nxmin2 - nxmin, nymin2 - nymin, 255, 192, 192, SDL_ALPHA_OPAQUE);
} else {
placeRectToRenderer(renderer, nxmin, nymin, nxmin2 - nxmin, nymin2 - nymin, 192, 192, 255, SDL_ALPHA_OPAQUE);
}
}; };
cur = cur / 2 ; cur = cur / 2 ;
} }

View File

@ -215,7 +215,8 @@ void generate_chunk_all(int cx, int cy) {
} }
} }
}; };
//printf("\ngenerating %d\n", idx); //printf("generating %d at (%d, %d)...\n", idx, cx, cy);
//print_template(idx);
generate_chunk(cx, cy, idx); generate_chunk(cx, cy, idx);
} }
@ -250,10 +251,10 @@ void parse_one(FILE* ptr, FILE* ptr2, int index) {
configs[index].lines[i] *= 2 ; configs[index].lines[i] *= 2 ;
configs[index].lines[i] += xres ; configs[index].lines[i] += xres ;
if(j == 0) { if(j == 7) {
configs[index].westsig *= 2; configs[index].westsig *= 2;
configs[index].westsig += xres; configs[index].westsig += xres;
} else if(j == 7) { } else if(j == 0) {
configs[index].eastsig *= 2; configs[index].eastsig *= 2;
configs[index].eastsig += xres; configs[index].eastsig += xres;
} }

View File

@ -19,6 +19,15 @@
#include "move.h" #include "move.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
if(argc != 3) {
fprintf(stderr, "usage : bin/back <template_pool> <n_templates>\n");
exit(1);
};
char* filename = argv[1];
int length = str_to_int(argv[2]);
srand(time(NULL)); srand(time(NULL));
//-------------------------------------------------------------------------------// //-------------------------------------------------------------------------------//
@ -43,13 +52,16 @@ int main(int argc, char** argv) {
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */
//one_debug(); //one_debug();
parse_configs("templates.txt", 47); parse_configs(filename, length);
initialize(rend); initialize(rend);
//print_template(1); int temp = render_distance ;
//rotateTemplateClockWise(1); for(int i = 1; i <= temp; i++) {
//print_template(1); printf("%d/%d\n", i, temp);
render_distance = i ;
drawMapToRenderer(rend, -300 * 250/zoom + to_int(50 * (8*player_cx + player_x + εx)), 300 * 250/zoom + to_int(50 * (8*player_cx + player_x + εx)), -300 * 250/zoom + to_int(50 * (8*player_cy + player_y + εy)), 300 * 250/zoom + to_int(50 * (8*player_cy + player_y + εy)));
};
moveFunctionMaster(rend); moveFunctionMaster(rend);
@ -61,5 +73,7 @@ int main(int argc, char** argv) {
SDL_DestroyWindow(win); SDL_DestroyWindow(win);
SDL_Quit(); SDL_Quit();
/* -------------------------------------------------------- */
return 0; return 0;
} }

442
templates_lv2.txt Normal file
View File

@ -0,0 +1,442 @@
1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 1
1 0 1 1 1 1 0 1
1 0 1 0 0 1 0 1
1 0 1 0 0 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 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 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 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 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
1 1 1 1 1 1 1 1
1 1 1 1 1 1 0 0
1 1 1 1 1 1 0 1
1 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
1 1 1 1 1 1 1 1
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 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 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 0 1 1 1 1 0 1
1 1 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