Fonction de dessin custom fonctionelle

This commit is contained in:
attilavs2 2024-08-09 18:40:08 +02:00
parent 89566b20bc
commit a5e982b80b
5 changed files with 24 additions and 14 deletions

View file

@ -28,7 +28,7 @@ set(ASSETS
fxconv_declare_assets(${ASSETS} WITH_METADATA)
add_executable(Copy3DEngine ${SOURCES} ${ASSETS})
target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -O2 -g)
target_compile_options(Copy3DEngine PRIVATE -Wall -Wextra -Ofast)
target_compile_definitions(Copy3DEngine PRIVATE NAMEOFGAME="${NAMEOFGAME}" AUTHOR="${AUTHOR}")
target_link_libraries(Copy3DEngine Gint::Gint)
target_link_libraries(Copy3DEngine LibProf::LibProf)

View file

@ -9,6 +9,10 @@
typedef int32_t fixed_t;
/* Standard arithmetic. */
typedef struct {
int32_t x ,y;
} V2d;
static inline fixed_t fmul(fixed_t left, fixed_t right)
{
/* Generally optimized by the compiler to use dmuls.l and xtrct */
@ -85,3 +89,7 @@ static inline fixed_t fease(fixed_t x)
return fix(1) - 2 * fmul(x, x);
}
}
static inline fixed_t fV2d_dotp(V2d u, V2d v){
return fmul(u.x,v.x) + fmul(u.y,v.y);
}

View file

@ -119,7 +119,7 @@ int main(){
dma_memset((void*)((uint32_t)gint_vram + viewport_w*viewport_h),
0xc4c9c4c9, viewport_w*viewport_h);
draw_walls(frame_buffer);
draw_walls();
if(first_frame == 1){
main_menu();

View file

@ -11,6 +11,7 @@
#include "fixed.h"
#include "gint/display-cg.h"
#include "moteur.h"
#include "map.h"
@ -166,7 +167,7 @@ void load_map(){
spawn_gen();
}
void draw_walls(image_t *frame_buffer){
void draw_walls(){
extern fixed_t posX;
extern fixed_t posY;
extern fixed_t dirX;
@ -307,7 +308,7 @@ void draw_walls(image_t *frame_buffer){
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 < 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;
@ -317,7 +318,7 @@ void draw_walls(image_t *frame_buffer){
texSampleY = 0;
}
image_t texStripe;
/*image_t texStripe;
texStripe = *image_sub(tex_index[map_test[mapX][mapY]], texX, texSampleY, 1, texSample);
@ -327,16 +328,17 @@ void draw_walls(image_t *frame_buffer){
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++;
int maxpos = (linePos + lineHeight) > viewport_h ? viewport_h:(linePos + lineHeight);
fixed_t screenPos = fix(linePos);
uint32_t texDat = (uint32_t)tex->data + 2*texX;
for(int texPos = texSampleY; texPos < texSample; texPos++){
for(fixed_t oldPos = screenPos; oldPos < screenPos+texSize; oldPos+=0xFFFF){
gint_vram[ffloor(oldPos)*396+x] =*(uint16_t*)texDat;
}
imgpos = (void*)((uint32_t)imgpos + tex->stride);
screenPos += texSize;
texDat += tex->stride;
}
}
}

View file

@ -10,13 +10,13 @@
#define screen_h 224
#define viewport_w 396
#define viewport_h 224
#define max_dist 0x1FFFFF //en tuiles << 16, actuellement 32
#define max_dist fix(32) //en tuiles << 16, actuellement 32
#define TINDEX_S 256
void load_map();
void end_screen();
void draw_walls(image_t *frame_buffer);
void draw_walls();
void move();
#endif /* moteur */