Culling en WIP

This commit is contained in:
attilavs2 2023-12-13 18:28:09 +01:00
parent 8829c3cc1a
commit 7e5683f2e7
5 changed files with 30 additions and 18 deletions

Binary file not shown.

View File

@ -26,7 +26,7 @@
#define screen_h 224
#define viewport_w 396
#define viewport_h 224
#define max_dist 0x100000 //en tuiles << 16, actuellement 32
#define max_dist fix(16) //en tuiles
#define max_sprite_dist 0x140000 //en tuiles << 16, 20
#define max_sprite_search 24

View File

@ -44,7 +44,7 @@ void keys_get(Game *game){
pollevent();
uint8_t keydowns = rc_keydown(RCKEY_UP) | rc_keydown(RCKEY_DOWN) << 1 | rc_keydown(RCKEY_LEFT) << 2
| rc_keydown(RCKEY_RIGHT) << 3 | rc_keydown(RCKEY_JUMP);
| rc_keydown(RCKEY_RIGHT) << 3 | rc_keydown(RCKEY_JUMP) << 4;
move(game, keydowns);
@ -125,7 +125,7 @@ void keys_get(Game *game){
uint8_t keydowns = rc_keydown(RCKEY_UP) || rc_keydown(RCKEY_DOWN) << 1 || rc_keydown(RCKEY_LEFT) << 2
|| rc_keydown(RCKEY_RIGHT) << 3;
|| rc_keydown(RCKEY_RIGHT) << 3 |;
move(game, keydowns);

View File

@ -41,6 +41,7 @@ ShooterMap ShooterLevel0 = {0,0,0,0,0,0,
{{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,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,0,0,0,0,1},
{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,0,0,0,0,1},
{1,0,0,1,1,1,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},
{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,0,0,0,0,1},
{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,0,0,0,0,1},
{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,0,0,0,0,1},
@ -64,9 +65,8 @@ ShooterMap ShooterLevel0 = {0,0,0,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,0,0,0,0,1},
{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,0,0,0,0,1},
{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,0,0,0,0,1},
{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,0,0,0,0,1},
{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,0,0,0,0,1},
{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,0,0,0,0,1},
{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,1,0,1,0,0,1},
{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,1,1,0,1,0,1},
{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,0,0,0,0,1},
{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,0,0,0,0,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}

View File

@ -105,11 +105,14 @@ void move(Game *game, uint8_t keys) {
player->plane.x = (fmul(player->plane.x, c_rotSpeed)-1) - (fmul(player->plane.y, s_rotSpeed) - 1);
player->plane.y = (fmul(oldPlaneX, s_rotSpeed)+1) + (fmul(player->plane.y, c_rotSpeed) + 1);
}
if(keys & 0b100000) {
//Jump
if(keys & 0b10000) {
if(on_solid_ground(shooterLevel, player->pos) > 0){
player->velocity.z = moveSpeed;
jumped = 1;
dprint(1,150,C_BLACK,"jumped");
}
dprint(1,140,C_BLACK,"tried to jump");
}
temp.x = ffloor(player->pos.x + fmul(player->velocity.x, sFrameTime));
@ -119,20 +122,20 @@ void move(Game *game, uint8_t keys) {
fpos.y = ffloor(player->pos.y);
fpos.z = ffloor(player->pos.z);
//player->velocity.x -= fmul(player->velocity.x, fmul(0x4000, fsq(player->velocity.x)));
//player->velocity.y -= fmul(player->velocity.y, fmul(0x4000, fsq(player->velocity.x)));
player->velocity.x -= fmul(player->velocity.x, fmul(0x5000, fsq(player->velocity.x)));
player->velocity.y -= fmul(player->velocity.y, fmul(0x5000, fsq(player->velocity.x)));
if(shooterLevel->wall[fpos.z][temp.x][fpos.y] == 0) player->pos.x = player->pos.x + fmul(player->velocity.x, sFrameTime);
else player->velocity.x = 0;
if(shooterLevel->wall[fpos.z][fpos.x][temp.y] == 0) player->pos.y = player->pos.y + fmul(player->velocity.y, sFrameTime);
else player->velocity.y = 0;
if((on_solid_ground(shooterLevel, (Vector3d){player->pos.x, player->pos.y, temp.z}) > 0
/*if((on_solid_ground(shooterLevel, (Vector3d){player->pos.x, player->pos.y, temp.z}) > 0
|| bumps_head(shooterLevel, (Vector3d){player->pos.x, player->pos.y, temp.z}) < 1)&&
jumped < 1) {
player->velocity.z = 0;
}
else player->velocity.z -= 2*fmul(G, sFrameTime); //Gravité
else player->velocity.z -= 2*fmul(G, sFrameTime);*/ //Gravité
if (player->dir.x > 0xFFFF) player->dir.x = 0xFFFF;
if (player->dir.y > 0xFFFF) player->dir.y = 0xFFFF;
@ -196,6 +199,10 @@ void draw_walls(Game *game, image_t *vram){
for(x = 0; x < viewport_w; x++) {
prof_enter(rayscat);
int occl1 = viewport_h / 2;
int occl2 = viewport_h / 2;
int toccl1, toccl2;
debug_func();
//calculate ray position and direction
@ -293,23 +300,26 @@ void draw_walls(Game *game, image_t *vram){
if (lineHeight < 1) lineHeight = 1;
if (lineHeight > viewport_h-1) lineHeight = viewport_h-1;
int glinePos = viewport_h/2 - lineHeight/2;
fixed_t texSize = fix(lineHeight) / tsize; //taille proportionelle de la ligne a la tex
for(i = 0; i < map_d; i++){
if(walls[i] < 1) continue;
int zOffset = player->pos.z-fix(i);
int zOffset = player->pos.z - fix(i);
// The reasoning here is to offset the wall slice vertically from the center of the screen,
// depending on the offset between the wall and the player
int linePos = viewport_h/2 - lineHeight/2 + fround(zOffset*lineHeight);
int linePos = glinePos + fround(zOffset*lineHeight);
if(linePos < occl1) toccl1 = linePos;
else continue;
if(linePos+lineHeight > occl2) toccl2 = linePos;
else continue;
if(linePos >= viewport_h) continue;
//Then adjust the slice size based on distance
//Simplification is possible
int fLineHeight = 1;//fround(lineHeight * fdiv(perpWallDist, fix2DNorm((Vector2d){perpWallDist, zOffset})));
if(linePos+lineHeight < 1) continue;
uint8_t tex = 0; //ShooterLevel->wall[mapX][mapY][i];
@ -341,11 +351,13 @@ void draw_walls(Game *game, image_t *vram){
case 2 : {color = C_BSKY; break;}
}
gint_dvline(linePos, linePos+fLineHeight, x, color);
gint_dvline(linePos, linePos+1, x, color);
//prof_leave(img_drw);
//prof_enter(rayscat);
}
//occl1 = toccl1;
//occl2 = toccl2;
}
}
//jump to next map square, either in x-direction, or in y-direction