fx : dscale_bopti() fonctionel

This commit is contained in:
attilavs2 2024-09-28 22:11:47 +02:00
parent 12df54420b
commit e117e19744
4 changed files with 77 additions and 49 deletions

View file

@ -31,7 +31,7 @@ fxconv_declare_assets(${ASSETS} WITH_METADATA)
add_executable(Copy3DEngine ${SOURCES} ${ASSETS}) add_executable(Copy3DEngine ${SOURCES} ${ASSETS})
#the -I is an ugly hack because lephe won't let us use render-fx.h >:( #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_compile_definitions(Copy3DEngine PRIVATE NAMEOFGAME="${NAMEOFGAME}" AUTHOR="${AUTHOR}")
target_link_libraries(Copy3DEngine Gint::Gint) target_link_libraries(Copy3DEngine Gint::Gint)
target_link_libraries(Copy3DEngine LibProf::LibProf) target_link_libraries(Copy3DEngine LibProf::LibProf)

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
@ -28,7 +29,7 @@
bopti_image_t *tex_index[TINDEX_S]; 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 //Vos images ici
@ -104,16 +105,6 @@ int main(){
dclear(C_WHITE); 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 #if debug
EngineTimers timers; EngineTimers timers;
#endif #endif

View file

@ -1,9 +1,11 @@
// Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3 // Voir README.md pour license précise, par Fcalva 2023-2024 et est sous GPLv3
#include <stdint.h>
#include "map.h" #include "map.h"
#include "moteur.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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,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}, {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},

View file

@ -2,6 +2,7 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -30,7 +31,7 @@ void move() {
fixed_t c_rotSpeed = fix(cos(f2float(rotSpeed))); fixed_t c_rotSpeed = fix(cos(f2float(rotSpeed)));
fixed_t s_rotSpeed = fix(sin(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 planeX;
extern fixed_t planeY; extern fixed_t planeY;
extern fixed_t dirX; extern fixed_t dirX;
@ -98,7 +99,7 @@ void spawn_gen(){
extern fixed_t dirY; extern fixed_t dirY;
extern fixed_t planeX; extern fixed_t planeX;
extern fixed_t planeY; 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 seed, seed_x, seed_y;
int SeedSeed; int SeedSeed;
@ -172,7 +173,7 @@ void load_map(){
#if asm_opti #if asm_opti
#else #else
//Fonction fournie par le grand Lephe :D //Fonction fournie par le grand Lephé :D
inline int __attribute__((always_inline)) inline int __attribute__((always_inline))
get_pixel(bopti_image_t const *img, int u, int v) get_pixel(bopti_image_t const *img, int u, int v)
{ {
@ -191,33 +192,71 @@ inline int __attribute__((always_inline))
uint32_t *light, *dark; uint32_t *light, *dark;
void dscale_bopti(bopti_image_t *tex, fixed_t scale_x, fixed_t scale_y, int x, int y){ //Version simplifiée de gpixel dans gint/src/gray/gpixel.c
fixed_t screen_x = x; //Tout le crédit revient à Lephé
fixed_t screen_y = y; inline void __attribute__((always_inline))
for(fixed_t tex_y = 0; tex_y < fix(tex->height); tex_y+=scale_y){ cust_dpixel(int x, int y, color_t color){
yloop:
;//For clangd which doesn't like the label (?) if(y >= viewport_h)
fixed_t oldy = screen_y; return;
screen_y += scale_y; int offset = (y << 2) + (x >> 5);
if(screen_y >= 64) uint32_t mask = 1 << (~x & 31);
switch(color){
case C_WHITE:
light[offset] &= ~mask;
dark [offset] &= ~mask;
break; break;
for(; oldy < screen_x; oldy += 0xFFFF){
for(fixed_t tex_x = 0; tex_x < fix(tex->width); tex_x+=scale_x){ case C_LIGHT:
fixed_t oldx = screen_x; light[offset] |= mask;
screen_x += scale_x; dark [offset] &= ~mask;
if(screen_x >= 128) break;
goto yloop;
int tpix = get_pixel(tex, tex_x, tex_y); case C_DARK:
for(; oldx < screen_x; oldx += 0xFFFF){ light[offset] &= ~mask;
dpixel(screen_x, screen_y, tpix); dark [offset] |= mask;
} break;
screen_x = oldx;
} case C_BLACK:
} light[offset] |= mask;
screen_y = oldy; 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)) inline void __attribute__((always_inline))
draw_stripe(bopti_image_t *tex, int texSampleY, int linePos, fixed_t texSize, draw_stripe(bopti_image_t *tex, int texSampleY, int linePos, fixed_t texSize,
int texX, int x){ int texX, int x){
@ -228,11 +267,9 @@ inline void __attribute__((always_inline))
fixed_t oldPos = screenPos; fixed_t oldPos = screenPos;
int tpix = get_pixel(tex, texX, texPos); int tpix = get_pixel(tex, texX, texPos);
do{ do{
if(screenPos >= fix(viewport_h))
return;
dpixel(x, ffloor(oldPos), tpix);
oldPos += 0xFFFF; oldPos += 0xFFFF;
} while(oldPos <= screenPos+texSize); cust_dpixel(x, fround(oldPos), tpix);
} while(oldPos < screenPos+texSize);
} }
screenPos += texSize; screenPos += texSize;
} }
@ -251,7 +288,7 @@ void draw_walls(
extern fixed_t planeX; extern fixed_t planeX;
extern fixed_t planeY; extern fixed_t planeY;
extern bopti_image_t *tex_index[TINDEX_S]; 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 cameraX;
fixed_t rayDirX; fixed_t rayDirX;
@ -276,8 +313,8 @@ void draw_walls(
dgray_getvram(&light,&dark); dgray_getvram(&light,&dark);
int v_offset = 0; //(int)(sin(f2int(posX + posY)) * 5); //a raffiner un peu int v_offset = 0;
fixed_t h_offset = 0; //fix(sin(f2int(posX - posY)) * 0.01); fixed_t h_offset = 0;
//struct image_linear_map temp; //struct image_linear_map temp;
@ -409,9 +446,7 @@ void draw_walls(
bopti_image_t *tex = tex_index[map_test[mapX][mapY]]; bopti_image_t *tex = tex_index[map_test[mapX][mapY]];
//dline(x, linePos, x, linePos+lineHeight, color); draw_stripe(tex, texSampleY, linePos,
draw_stripe(tex_index[map_test[mapX][mapY]], texSampleY, linePos,
texSize, texX, x); texSize, texX, x);
#if debug #if debug