Étirage en dehors du viewport fonctionel

This commit is contained in:
attilavs2 2024-08-09 19:19:41 +02:00
parent a5e982b80b
commit 972e52f666
3 changed files with 36 additions and 29 deletions

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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);
}
}