From f2669d8a5715a3878ba6969e834854c456dd40cf Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Sun, 3 Dec 2023 12:13:09 +0100 Subject: [PATCH] =?UTF-8?q?Optimisations=20compilateur=20et=20petites=20am?= =?UTF-8?q?=C3=A9liorations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 ++-- src/main.c | 6 ++---- src/map_test.c | 4 ++-- src/moteur.c | 24 ++++++++++-------------- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65a6fb6..46d80ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,10 +23,10 @@ set(ASSETS fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA) add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) -target_compile_options(myaddin PRIVATE -Wall -Wextra -O3 -fira-region=all ) +target_compile_options(myaddin PRIVATE -Wall -Wextra -Ofast -fira-region=all -flto -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math) target_link_libraries(myaddin Gint::Gint ) target_link_libraries(myaddin LibProf::LibProf) -target_link_options(myaddin PRIVATE -Wl,--print-memory-usage) +target_link_options(myaddin PRIVATE -Wl,--print-memory-usage,-flto) if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) generate_g3a(TARGET myaddin OUTPUT "Maze3D.g3a" diff --git a/src/main.c b/src/main.c index 98bd03e..db1dd60 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ #include #include -#define USB +//#define USB #ifdef USB #include @@ -18,7 +18,7 @@ #include "moteur.h" #include "map_test.h" -//====== Maze3D V0.2 ===== +//====== Maze3D V0.3 ===== // Git du moteur : https://github.com/attilavs2/Raycaster_G90 // Git du jeu : https://gitea.planet-casio.com/Fcalva/Maze3D // @@ -141,8 +141,6 @@ int main(){ drect(0, 0, 395, 112, 0x9dbd); drect(0,112, 395, 243, 0xc4c9); - image_clear(frame_buffer); - draw_walls(&buisson0, &briques0, &sky_tex, &WXOR_tex, &D_tex, frame_buffer); if(first_frame == 1) main_menu(); diff --git a/src/map_test.c b/src/map_test.c index 47cc90d..54c6266 100644 --- a/src/map_test.c +++ b/src/map_test.c @@ -8,7 +8,7 @@ char map_test[map_w][map_h] = { {1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,1,0,0,0,1,1,0,1,1,0,0,0,0,1,0,0,0,1,1,2,1,1,1,1,1,1,0,0,0,1,0,1,1,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3}, {1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,0,1,1,0,0,1,0,1,0,0,0,1,0,0,1,0,0,1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3}, {1,0,1,0,1,1,1,0,0,0,2,0,0,0,1,1,0,1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,0,1,0,0,0,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3}, - {1,0,1,0,1,0,1,0,0,0,2,0,0,0,0,0,1,0,0,1,1,1,1,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-}; \ No newline at end of file +}; diff --git a/src/moteur.c b/src/moteur.c index 44a0646..ed10bbe 100644 --- a/src/moteur.c +++ b/src/moteur.c @@ -5,6 +5,7 @@ #include #include +#include #include "fixed.h" @@ -132,10 +133,10 @@ void spawn_gen(){ srand(SeedSeed); - while(true){ + while(1){ seed = rand() * 0.5 + rand() * 0.5; - seed_x = seed & 0b00000000000000000000000001111111; - seed_y = (seed >> 8) & 0b00000000000000000000000000111111; + seed_x = seed & 0b1111111; + seed_y = (seed >> 8) & 0b111111; if (seed_x < map_w && seed_y < map_h && (seed_x < 111 && seed_y > 15)){ if(map_test[seed_x][seed_y] == 0){ break; @@ -144,7 +145,7 @@ void spawn_gen(){ } fixed_t start_dirX, start_dirY; - int dirSeed = (seed >> 9) & 0b00000000000000000000000000000011 ; + int dirSeed = (seed >> 9) & 0b11 ; switch(dirSeed){ case 0: { start_dirX = 0x0; @@ -204,7 +205,6 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, extern fixed_t planeY; extern char map_test[map_w][map_h]; - unsigned short color; fixed_t cameraX; fixed_t rayDirX; fixed_t rayDirY; @@ -219,7 +219,6 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, int mapY; int stepX; //what direction to step in x or y-direction (either +1 or -1) int stepY; - int hit = 0; //was there a wall hit? int side; //was a NS or a EW wall hit? int lineHeight; int texX; @@ -232,7 +231,7 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, struct image_linear_map temp; for(x = 0; x < viewport_w; x++) { - + //calculate ray position and direction cameraX = fdiv(fix(x*2), fix(viewport_w)) - 0xFFFF + h_offset; //x-coordinate in camera space @@ -286,12 +285,10 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, while(true) { //Check if the ray is out of range/bounds if (sideDistX >= max_dist || sideDistY >= max_dist || mapX < 0 || mapY < 0 || mapX >= map_w || mapY >= map_h) { - hit = 0; break; } //Otherwise check if ray has hit a wall - else if (map_test[mapX][mapY] != 0) { - hit = 1; + else if (map_test[mapX][mapY] > 0) { break; } //jump to next map square, either in x-direction, or in y-direction @@ -336,20 +333,19 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, lineHeight = f2int(fdiv(fix(viewport_h), perpWallDist)); //Taille en px de la ligne if (lineHeight < 1) lineHeight = 1; - if (lineHeight > viewport_h) lineHeight = viewport_h - 1; + //if (lineHeight > viewport_h) lineHeight = viewport_h - 1; fixed_t texSize = fix(lineHeight) / 64; //taille proportionelle de la ligne a la tex if (texSize < 0x400) texSize = 0x400; //0x400 = 1/64 * 2^16 if (texSize > 0x3D000) { //0x3D000 = 3.8125 * 2^16, 3.8125 = viewport_h/64 texSample = fceil(fdiv(fix(viewport_h), texSize)); - texSampleY = 32 - (int)texSample * 0.5 + 1; + texSampleY = 32 - (int)texSample * 0.5; } else { texSample = 64; texSampleY = 0; } - image_t texStripe; image_clear(&texStripe); @@ -362,6 +358,6 @@ void draw_walls(image_t *tex_1, image_t *tex_2, image_t *tex_3, image_t *tex_4, } image_scale(&texStripe, 0xFFFF, texSize, &temp); - image_linear(&texStripe, image_at(frame_buffer, x, (int)(viewport_h * 0.5 - lineHeight * 0.5) + v_offset), &temp); + image_linear(&texStripe, image_at(frame_buffer, x, (int)(viewport_h * 0.5 - lineHeight * 0.5) + v_offset), &temp); } }