From 972e52f66656992a3aa718208a6e2606239f5c97 Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Fri, 9 Aug 2024 19:19:41 +0200 Subject: [PATCH] =?UTF-8?q?=C3=89tirage=20en=20dehors=20du=20viewport=20fo?= =?UTF-8?q?nctionel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fixed.h | 10 ++++++++++ src/main.c | 6 +++--- src/moteur.c | 49 +++++++++++++++++++++++-------------------------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/fixed.h b/src/fixed.h index 9cab461..4dc2578 100644 --- a/src/fixed.h +++ b/src/fixed.h @@ -93,3 +93,13 @@ static inline fixed_t fease(fixed_t x) static inline fixed_t fV2d_dotp(V2d u, V2d v){ return fmul(u.x,v.x) + fmul(u.y,v.y); } + +static inline uint16_t mul_color(uint16_t color, fixed_t multpl){ + int r = color & 31; + int g = (color>>5) & 63; + int b = (color>>11) & 31; + r *= multpl; + g *= multpl; + b *= multpl; + return (ffloor(b)<<11) | (ffloor(g)<<5) | r; +} diff --git a/src/main.c b/src/main.c index 3e55dad..8aad888 100644 --- a/src/main.c +++ b/src/main.c @@ -78,8 +78,8 @@ void keys_get(){ } void main_menu(){ - //dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, NAMEOFGAME, -1); - //dtext_opt(198, 120, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "De " AUTHOR, -1); + dtext_opt(198, 100, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Demo 3D", -1); + dtext_opt(198, 120, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "De Fcalva", -1); dtext_opt(198, 150, 0xde85, C_NONE, DTEXT_CENTER, DTEXT_TOP, "Appuyez sur une touche", -1); dupdate(); @@ -121,7 +121,7 @@ int main(){ draw_walls(); - if(first_frame == 1){ + if(first_frame){ main_menu(); } diff --git a/src/moteur.c b/src/moteur.c index 55b107f..17a778d 100644 --- a/src/moteur.c +++ b/src/moteur.c @@ -43,20 +43,20 @@ void move() { int ytemp2; if (keydown(KEY_UP)) { - xtemp1 = f2int(posX + fmul(dirX, moveSpeed)); + xtemp1 = f2int(posX + fmul(dirX, moveSpeed) - 0xF); ytemp1 = f2int(posY); xtemp2 = f2int(posX); - ytemp2 = f2int(posY + fmul(dirY, moveSpeed)); + ytemp2 = f2int(posY + fmul(dirY, moveSpeed) - 0xF); if(map_test[xtemp1][ytemp1] == 0) posX += fmul(dirX, moveSpeed); if(map_test[xtemp2][ytemp2] == 0) posY += fmul(dirY, moveSpeed); } //move backwards if no wall behind you if (keydown(KEY_DOWN)) { - xtemp1 = f2int(posX - fmul(dirX, moveSpeed)); + xtemp1 = f2int(posX - fmul(dirX, moveSpeed) + 0xF); ytemp1 = f2int(posY); xtemp2 = f2int(posX); - ytemp2 = f2int(posY - fmul(dirY, moveSpeed)); + ytemp2 = f2int(posY - fmul(dirY, moveSpeed) + 0xF); if(map_test[xtemp1][ytemp1] == 0) posX -= fmul(dirX, moveSpeed); if(map_test[xtemp2][ytemp2] == 0) posY -= fmul(dirY, moveSpeed); @@ -167,6 +167,20 @@ void load_map(){ spawn_gen(); } +void draw_stripe(image_t *tex, int texSampleY, int texSample, int linePos, fixed_t texSize, int texX, int x){ + fixed_t screenPos = fix(linePos); + uint32_t texDat = (uint32_t)tex->data + 2*texX; + for(int texPos = texSampleY; texPos < 64; texPos++){ + if(screenPos < -texSize) goto noDraw; + for(fixed_t oldPos = screenPos; oldPos < screenPos+texSize; oldPos+=0xFFFF){ + gint_vram[ffloor(oldPos)*396+x] = *(uint16_t*)texDat; + } + noDraw: + screenPos += texSize; + texDat += tex->stride; + } +} + void draw_walls(){ extern fixed_t posX; extern fixed_t posY; @@ -305,40 +319,23 @@ void draw_walls(){ 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; + texSampleY = 32 - texSample/2; } else { texSample = 64; texSampleY = 0; } - /*image_t texStripe; - - texStripe = *image_sub(tex_index[map_test[mapX][mapY]], texX, texSampleY, 1, texSample); - - image_scale(&texStripe, 0xFFFF, texSize, &temp); - image_linear(&texStripe, image_at(frame_buffer, x, viewport_h/2 - lineHeight/2, &temp);*/ + int linePos = viewport_h/2 - lineHeight/2; image_t *tex = tex_index[map_test[mapX][mapY]]; - int linePos = viewport_h/2 - lineHeight/2; - - - 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; - } - screenPos += texSize; - texDat += tex->stride; - } - } + draw_stripe(tex, texSampleY, texSample, linePos, texSize, texX, x); + } }