diff --git a/Makefile b/Makefile index f77cad8..3b547e0 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,20 @@ LFLAGS = -lSDL2 -lSDL2_image -lm -lncurses all: bin/back +test-1: bin/back + bin/back templates_lv0.txt 27 0 + test0: bin/back - bin/back templates.txt 47 + bin/back templates.txt 47 1 test1: bin/back - bin/back templates_lv1.txt 14 + bin/back templates_lv1.txt 14 1 test2: bin/back - bin/back templates_lv2.txt 52 + bin/back templates_lv2.txt 52 1 test3: bin/back - bin/back templates_lv3.txt 33 + bin/back templates_lv3.txt 33 1 bin/back: obj/main.o obj/generation.o obj/display.o obj/base.o obj/hash.o obj/move.o mkdir -p bin diff --git a/bin/back b/bin/back index f27538c..3d7bfca 100755 Binary files a/bin/back and b/bin/back differ diff --git a/src/display.c b/src/display.c index ff17c0c..8b8fc32 100644 --- a/src/display.c +++ b/src/display.c @@ -146,24 +146,18 @@ void drawChunkToRenderer(SDL_Renderer* renderer, chunk* ch, int xmin, int xmax, 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(cur%2 == 1) { - 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 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)) ; - 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 ; - } + 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 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)) ; + bool x = abs(ch->chx + ch->chy)%2 == 0 ; + placeRectToRenderer(renderer, nxmin, nymin, nxmin2 - nxmin, nymin2 - nymin, 255-64*(1-x), 192, 255-64*x, SDL_ALPHA_OPAQUE/(1+3*(cur%2 == 0))); + cur = cur / 2 ; } } } } +// branchless goes brrr void drawHashToRenderer(SDL_Renderer* renderer, int chx, int chy, int xmin, int xmax, int ymin, int ymax, int distx, int disty) { if(distx < render_distance && disty < render_distance) { diff --git a/src/generation.c b/src/generation.c index e538418..822313b 100644 --- a/src/generation.c +++ b/src/generation.c @@ -209,6 +209,7 @@ void generate_chunk_all(int cx, int cy) { if(is_compat_with_spins_uno(cx, cy, idx)) { i -= 1; if(i != 0) { + rotateTemplateClockWise(idx); if(k == 3) { idx = (idx+1)%n_configs; k = 0 ; @@ -230,10 +231,7 @@ void generate_chunk_all(int cx, int cy) { } } }; - //printf("generating %d at (%d, %d)...\n", idx, cx, cy); - //print_template(idx); int R = rand()%emptyChance; - //printf("%d/%d\n", R, emptyChance); if(R != 0) { generate_chunk(cx, cy, idx); } else { @@ -346,7 +344,7 @@ void parse_configs(char* filename, int n_conf) { configs[i].id = i; configs[i].eastsig = 0 ; configs[i].westsig = 0 ; - configs[i].checkCompat = true ; + configs[i].checkCompat = doCheck ; configs[i].lines = malloc(sizeof(uint8_t)*8); for(int j = 0; j < 8; j++) { configs[i].lines[j] = 0; @@ -357,7 +355,18 @@ void parse_configs(char* filename, int n_conf) { FILE* ptr = fopen(filename, "r"); FILE* ptr2 = fopen(filename, "r"); + // one pointer for data + // one pointer for counting + for(int k = 0; k < n_conf; k++) { parse_one(ptr, ptr2, k); } +} + +void change_configs(char* new_filename, int n_conf) { + for(int i = 0; i < n_conf; i++) { + free(configs[i].lines); + } + free(configs); + parse_configs(new_filename, n_conf); } \ No newline at end of file diff --git a/src/generation.h b/src/generation.h index 4b635b2..3e0bcb6 100644 --- a/src/generation.h +++ b/src/generation.h @@ -23,4 +23,6 @@ void destroy(); void parse_configs(char* filename, int n_conf); +void change_configs(char* new_filename, int n_conf); + #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 98bedf3..c75287f 100644 --- a/src/main.c +++ b/src/main.c @@ -18,15 +18,18 @@ #include "generation.h" #include "move.h" +bool doCheck ; + int main(int argc, char** argv) { - if(argc != 3) { - fprintf(stderr, "usage : bin/back \n"); + if(argc != 4) { + fprintf(stderr, "usage : bin/back \n"); exit(1); }; char* filename = argv[1]; int length = str_to_int(argv[2]); + doCheck = (bool)((int)argv[3][0] - 48); srand(time(NULL)); diff --git a/src/move.c b/src/move.c index 4133680..b956f2e 100644 --- a/src/move.c +++ b/src/move.c @@ -174,6 +174,7 @@ void moveControl(bool* halt) { void moveFunctionMaster(SDL_Renderer* renderer) { bool halt = false ; while(!halt) { + //clock_t start = clock(); moveControl(&halt); resetRenderer(renderer); drawMapToRenderer(renderer, -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))); @@ -185,6 +186,8 @@ void moveFunctionMaster(SDL_Renderer* renderer) { drawNumberToRenderer(renderer, digits, to_int(εy*100), 2 * __width__ / 3, 80, 50, 70, 0); updateRenderer(renderer); draw_par += 1 ; + //clock_t end = clock(); + //printf("Time(ms) : %f | FPS : %d\n", 1000.0f * (float)(end - start) / CLOCKS_PER_SEC, (int)(CLOCKS_PER_SEC / (float)(end - start))); usleep(20000); } } \ No newline at end of file diff --git a/src/structure.h b/src/structure.h index b210eb6..05bfae3 100644 --- a/src/structure.h +++ b/src/structure.h @@ -15,6 +15,8 @@ typedef enum cardinal {NORTH, EAST, SOUTH, WEST} cardinal ; extern Grid map ; +extern bool doCheck ; + extern int emptyChance ; extern int sizeIncreaseChance ; diff --git a/templates_lv0.txt b/templates_lv0.txt new file mode 100644 index 0000000..b2a62fe --- /dev/null +++ b/templates_lv0.txt @@ -0,0 +1,244 @@ +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 + +0 0 0 0 0 0 1 0 +0 0 0 0 0 0 1 0 +0 1 1 1 1 1 1 0 +0 0 0 0 1 0 0 0 +0 0 0 0 1 0 0 0 +0 0 0 0 1 0 0 0 +0 0 0 0 1 0 0 0 +0 0 0 0 0 0 0 0 + +0 0 0 0 0 0 0 0 +1 1 1 1 1 1 1 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 1 1 1 1 1 1 1 +0 0 0 0 0 0 0 0 + +0 1 0 0 0 0 0 0 +0 1 0 0 0 0 0 0 +0 1 1 1 1 1 1 0 +0 0 0 0 1 0 0 0 +0 0 0 0 1 0 0 0 +0 0 0 0 1 0 0 0 +0 0 0 1 1 0 0 0 +0 0 0 0 0 0 0 0 + +0 0 0 0 0 0 1 0 +0 0 0 0 0 0 1 0 +0 1 1 1 1 1 1 0 +0 0 1 0 0 0 0 0 +0 0 1 0 0 0 0 0 +0 0 1 0 0 0 0 0 +0 0 1 0 0 0 0 0 +0 0 0 0 0 0 0 0 + +0 0 0 0 0 0 1 0 +0 0 0 0 0 0 1 0 +0 1 1 1 1 1 1 0 +0 0 0 0 0 0 1 0 +0 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