WIP : Boucle de dessin manuelle - x2 en perf

This commit is contained in:
attilavs2 2024-08-02 18:01:59 +02:00
parent 61c4ca9135
commit 89566b20bc
2 changed files with 26 additions and 9 deletions

View file

@ -28,11 +28,11 @@ set(ASSETS
fxconv_declare_assets(${ASSETS} WITH_METADATA) fxconv_declare_assets(${ASSETS} WITH_METADATA)
add_executable(Copy3DEngine ${SOURCES} ${ASSETS}) add_executable(Copy3DEngine ${SOURCES} ${ASSETS})
target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -Ofast -fira-region=all -flto -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math) target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -O2 -g)
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)
target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage,-flto) target_link_options(Copy3DEngine PRIVATE -Wl,--print-memory-usage)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
generate_g3a(TARGET Copy3DEngine OUTPUT "${NAMEOFGAME}.g3a" generate_g3a(TARGET Copy3DEngine OUTPUT "${NAMEOFGAME}.g3a"

View file

@ -186,6 +186,7 @@ void draw_walls(image_t *frame_buffer){
fixed_t perpWallDist; fixed_t perpWallDist;
fixed_t texSize; fixed_t texSize;
int x; int x;
int i;
int mapX; int mapX;
int mapY; int mapY;
int stepX; //what direction to step in x or y-direction (either +1 or -1) int stepX; //what direction to step in x or y-direction (either +1 or -1)
@ -225,11 +226,13 @@ void draw_walls(image_t *frame_buffer){
// stepping further below works. So the values can be computed as below. // stepping further below works. So the values can be computed as below.
// Division through zero is prevented, even though technically that's not // Division through zero is prevented, even though technically that's not
// needed in C++ with IEEE 754 floating point values. // needed in C++ with IEEE 754 floating point values.
// Fcalva : removed the 0 div prevention
rayDirX = rayDirX == 0 ? 1 : rayDirX;
rayDirY = rayDirY == 0 ? 1 : rayDirY;
deltaDistX = abs(fdiv(0xFFFF, rayDirX)); deltaDistX = abs(fdiv(0xFFFF, rayDirX));
deltaDistY = abs(fdiv(0xFFFF, rayDirY)); deltaDistY = abs(fdiv(0xFFFF, rayDirY));
//calculate step and initial sideDist //calculate step and initial sideDist
if (rayDirX < 0) { if (rayDirX < 0) {
stepX = -1; stepX = -1;
@ -285,7 +288,6 @@ void draw_walls(image_t *frame_buffer){
else perpWallDist = (sideDistY - deltaDistY); else perpWallDist = (sideDistY - deltaDistY);
//texturing calculations //texturing calculations
//int texNum = test_map[mapX][mapY] - 1; //a voir plus tard
//calculate value of wallX //calculate value of wallX
fixed_t wallX; //where exactly the wall was hit fixed_t wallX; //where exactly the wall was hit
@ -302,10 +304,10 @@ void draw_walls(image_t *frame_buffer){
lineHeight = f2int(fdiv(fix(viewport_h), perpWallDist)); //Taille en px de la ligne lineHeight = f2int(fdiv(fix(viewport_h), perpWallDist)); //Taille en px de la ligne
if (lineHeight < 1) lineHeight = 1; 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 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 < 0x400) texSize = 0x400; //0x400 = 1/64 * 2^16
if (texSize > 0x3D000) { //0x3D000 = 3.8125 * 2^16, 3.8125 = viewport_h/64 if (texSize > 0x3D000) { //0x3D000 = 3.8125 * 2^16, 3.8125 = viewport_h/64
texSample = fceil(fdiv(fix(viewport_h), texSize)); texSample = fceil(fdiv(fix(viewport_h), texSize));
texSampleY = 32 - (int)texSample * 0.5; texSampleY = 32 - (int)texSample * 0.5;
@ -314,12 +316,27 @@ void draw_walls(image_t *frame_buffer){
texSample = 64; texSample = 64;
texSampleY = 0; texSampleY = 0;
} }
image_t texStripe; image_t texStripe;
texStripe = *image_sub(tex_index[map_test[mapX][mapY]], texX, texSampleY, 1, texSample); texStripe = *image_sub(tex_index[map_test[mapX][mapY]], texX, texSampleY, 1, texSample);
image_scale(&texStripe, 0xFFFF, texSize, &temp); 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, viewport_h/2 - lineHeight/2, &temp);*/
image_t *tex = tex_index[map_test[mapX][mapY]];
int linePos = viewport_h/2 - lineHeight/2;
uint16_t *imgpos = (void*)((uint32_t)tex->data + 2*texX);
texSize = ffloor(texSize);
for(i = linePos; i < linePos + lineHeight;){
for(int j = 0; j <= texSize; j++){
gint_vram[i*396+x] = *imgpos;
i++;
}
imgpos = (void*)((uint32_t)imgpos + tex->stride);
}
} }
} }