diff --git a/CMakeLists.txt b/CMakeLists.txt index b1fd0a5..d51f140 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ fxconv_declare_assets(${ASSETS} WITH_METADATA) add_executable(Copy3DEngine ${SOURCES} ${ASSETS}) #the -I is an ugly hack because lephe won't let us use render-fx.h >:( -target_compile_options(Copy3DEngine PRIVATE -flto -Wall -Wextra -Ofast -I "$ENV{HOME}/.local/share/giteapc/Lephenixnoir/gint/src/render-fx/") +target_compile_options(Copy3DEngine PRIVATE -flto -Wall -Wextra -O2 -I "$ENV{HOME}/.local/share/giteapc/Lephenixnoir/gint/src/render-fx/") target_compile_definitions(Copy3DEngine PRIVATE NAMEOFGAME="${NAMEOFGAME}" AUTHOR="${AUTHOR}") target_link_libraries(Copy3DEngine Gint::Gint) target_link_libraries(Copy3DEngine LibProf::LibProf) diff --git a/src/main.c b/src/main.c index 021a627..9a444e2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -28,7 +29,7 @@ bopti_image_t *tex_index[TINDEX_S]; -extern char map_test[map_w][map_h]; +extern uint8_t map_test[map_w][map_h]; //Vos images ici @@ -104,16 +105,6 @@ int main(){ dclear(C_WHITE); - dscale_bopti(&briques0, fix(2), fix(2), 0, 0); - - /*dimage(0,0,tex_index[0]); - dimage(32,0,tex_index[1]); - dimage(64,0,tex_index[2]); - dimage(96,0,tex_index[3]);*/ - - dupdate(); - getkey(); - #if debug EngineTimers timers; #endif diff --git a/src/map.c b/src/map.c index bc8c9f6..12d3cc1 100644 --- a/src/map.c +++ b/src/map.c @@ -1,9 +1,11 @@ // Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3 +#include + #include "map.h" #include "moteur.h" -char __attribute__((section(".rodata"))) map_test[map_w][map_h] = { +uint8_t __attribute__((section(".rodata"))) map_test[map_w][map_h] = { {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,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, {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,1,0,1,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,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,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,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,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,1,0,1,1,1,0,1,0,1,1,0,1,0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,1,0,2,0,2,0,0,2,0,0,0,0,2,0,0,2,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3}, diff --git a/src/moteur.c b/src/moteur.c index 785e5bf..31fed2d 100644 --- a/src/moteur.c +++ b/src/moteur.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -30,7 +31,7 @@ void move() { fixed_t c_rotSpeed = fix(cos(f2float(rotSpeed))); fixed_t s_rotSpeed = fix(sin(f2float(rotSpeed))); - extern char map_test[map_w][map_h]; + extern uint8_t map_test[map_w][map_h]; extern fixed_t planeX; extern fixed_t planeY; extern fixed_t dirX; @@ -98,7 +99,7 @@ void spawn_gen(){ extern fixed_t dirY; extern fixed_t planeX; extern fixed_t planeY; - extern char map_test[map_w][map_h]; + extern uint8_t map_test[map_w][map_h]; int seed, seed_x, seed_y; int SeedSeed; @@ -172,7 +173,7 @@ void load_map(){ #if asm_opti #else -//Fonction fournie par le grand Lephe :D +//Fonction fournie par le grand Lephé :D inline int __attribute__((always_inline)) get_pixel(bopti_image_t const *img, int u, int v) { @@ -191,33 +192,71 @@ inline int __attribute__((always_inline)) uint32_t *light, *dark; -void dscale_bopti(bopti_image_t *tex, fixed_t scale_x, fixed_t scale_y, int x, int y){ - fixed_t screen_x = x; - fixed_t screen_y = y; - for(fixed_t tex_y = 0; tex_y < fix(tex->height); tex_y+=scale_y){ - yloop: - ;//For clangd which doesn't like the label (?) - fixed_t oldy = screen_y; - screen_y += scale_y; - if(screen_y >= 64) +//Version simplifiée de gpixel dans gint/src/gray/gpixel.c +//Tout le crédit revient à Lephé +inline void __attribute__((always_inline)) + cust_dpixel(int x, int y, color_t color){ + + if(y >= viewport_h) + return; + int offset = (y << 2) + (x >> 5); + uint32_t mask = 1 << (~x & 31); + + switch(color){ + case C_WHITE: + light[offset] &= ~mask; + dark [offset] &= ~mask; break; - for(; oldy < screen_x; oldy += 0xFFFF){ - for(fixed_t tex_x = 0; tex_x < fix(tex->width); tex_x+=scale_x){ - fixed_t oldx = screen_x; - screen_x += scale_x; - if(screen_x >= 128) - goto yloop; - int tpix = get_pixel(tex, tex_x, tex_y); - for(; oldx < screen_x; oldx += 0xFFFF){ - dpixel(screen_x, screen_y, tpix); - } - screen_x = oldx; - } - } - screen_y = oldy; + + case C_LIGHT: + light[offset] |= mask; + dark [offset] &= ~mask; + break; + + case C_DARK: + light[offset] &= ~mask; + dark [offset] |= mask; + break; + + case C_BLACK: + light[offset] |= mask; + dark [offset] |= mask; + break; + default: break; } } +void dscale_bopti(bopti_image_t *tex, fixed_t scale_x, fixed_t scale_y, int x, int y){ + dgray_getvram(&light,&dark); + + fixed_t screen_y = fix(y); + fixed_t tex_y = 0; + do{ + fixed_t oldy = screen_y; + if(screen_y < 0 || screen_y+scale_x > viewport_h) + return; + do{ + fixed_t screen_x = fix(x); + fixed_t tex_x = 0; + do{ + fixed_t oldx = screen_x; + int tpix = get_pixel(tex, tex_x, tex_y); + if(screen_x < 0 || screen_x+scale_x > viewport_w) + return; + do{ + cust_dpixel(ffloor(oldx), ffloor(oldy), tpix); + oldx += 0xFFFF; + } while(oldx < screen_x+scale_x); + screen_x += scale_x; + tex_x++; + } while(tex_x < tex->width); + oldy += 0xFFFF; + } while(oldy < screen_y+scale_y); + screen_y += scale_y; + tex_y++; + } while(tex_y < tex->height); +} + inline void __attribute__((always_inline)) draw_stripe(bopti_image_t *tex, int texSampleY, int linePos, fixed_t texSize, int texX, int x){ @@ -228,11 +267,9 @@ inline void __attribute__((always_inline)) fixed_t oldPos = screenPos; int tpix = get_pixel(tex, texX, texPos); do{ - if(screenPos >= fix(viewport_h)) - return; - dpixel(x, ffloor(oldPos), tpix); oldPos += 0xFFFF; - } while(oldPos <= screenPos+texSize); + cust_dpixel(x, fround(oldPos), tpix); + } while(oldPos < screenPos+texSize); } screenPos += texSize; } @@ -251,7 +288,7 @@ void draw_walls( extern fixed_t planeX; extern fixed_t planeY; extern bopti_image_t *tex_index[TINDEX_S]; - extern char map_test[map_w][map_h]; + extern uint8_t map_test[map_w][map_h]; fixed_t cameraX; fixed_t rayDirX; @@ -276,8 +313,8 @@ void draw_walls( dgray_getvram(&light,&dark); - int v_offset = 0; //(int)(sin(f2int(posX + posY)) * 5); //a raffiner un peu - fixed_t h_offset = 0; //fix(sin(f2int(posX - posY)) * 0.01); + int v_offset = 0; + fixed_t h_offset = 0; //struct image_linear_map temp; @@ -409,9 +446,7 @@ void draw_walls( bopti_image_t *tex = tex_index[map_test[mapX][mapY]]; - //dline(x, linePos, x, linePos+lineHeight, color); - - draw_stripe(tex_index[map_test[mapX][mapY]], texSampleY, linePos, + draw_stripe(tex, texSampleY, linePos, texSize, texX, x); #if debug