Skip to content

Commit

Permalink
Update sprite culling to account for possible y offset
Browse files Browse the repository at this point in the history
  • Loading branch information
NicksWorld committed Jan 30, 2025
1 parent 408cef2 commit fd1f5b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
55 changes: 20 additions & 35 deletions SpriteObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,15 +1003,15 @@ void c_sprite::assemble_world_offset(int x, int y, int z, int plateoffset, Tile
pointToScreen((int*)&drawx, (int*)&drawy, drawz);
drawx -= (TILEWIDTH>>1)*ssConfig.scale;

if(((drawx + spritewidth*ssConfig.scale) < 0) || (drawx > ssState.ScreenW) || ((drawy + spriteheight*ssConfig.scale) < 0) || (drawy > ssState.ScreenH)) {
if((drawx + (spritewidth+offset_x)*ssConfig.scale < 0)
|| (drawx + offset_x*ssConfig.scale > ssState.ScreenW)
|| (drawy + (spriteheight + offset_y)*ssConfig.scale < 0)
|| (drawy + (offset_y - WALLHEIGHT)*ssConfig.scale > ssState.ScreenH)) {
return;
}

int sheetx, sheety;
if(platelayout == TILEPLATE) {
sheetx = ((sheetindex+plateoffset+spriteoffset) % SHEET_OBJECTSWIDE) * spritewidth;
sheety = ((sheetindex+plateoffset+spriteoffset) / SHEET_OBJECTSWIDE) * spriteheight;
} else if(platelayout == RAMPBOTTOMPLATE) {
if(platelayout == RAMPBOTTOMPLATE) {
sheetx = SPRITEWIDTH * b->rampindex;
sheety = ((TILETOPHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+plateoffset+spriteoffset))+(TILETOPHEIGHT + FLOORHEIGHT);
} else if(platelayout == RAMPTOPPLATE) {
Expand All @@ -1021,9 +1021,10 @@ void c_sprite::assemble_world_offset(int x, int y, int z, int plateoffset, Tile
sheetx = ((sheetindex+plateoffset+spriteoffset) % SHEET_OBJECTSWIDE) * spritewidth;
sheety = ((sheetindex+plateoffset+spriteoffset) / SHEET_OBJECTSWIDE) * spriteheight;
}

ALLEGRO_COLOR shade_color = shadeAdventureMode(get_color(b), b->fog_of_war, b->designation.bits.outside);
if(chop && ( halftile == HALFPLATECHOP)) {
if(shade_color.a > 0.001f)
if(shade_color.a > 0.001f) {
b->AssembleSprite(
(fileindex >= 0) ? getImgFile(fileindex) : defaultsheet,
premultiply(shade_color),
Expand All @@ -1037,7 +1038,6 @@ void c_sprite::assemble_world_offset(int x, int y, int z, int plateoffset, Tile
(spriteheight-WALL_CUTOFF_HEIGHT)*ssConfig.scale,
0);

if(shade_color.a > 0.001f) {
b->AssembleSprite(
stonesenseState.IMGObjectSheet,
al_map_rgb(255,255,255),
Expand All @@ -1052,34 +1052,19 @@ void c_sprite::assemble_world_offset(int x, int y, int z, int plateoffset, Tile
}
} else if ((chop && (halftile == HALFPLATEYES)) || (!chop && (halftile == HALFPLATENO)) || (!chop && (halftile == HALFPLATECHOP)) || (halftile == HALFPLATEBOTH)) {
if((isoutline == OUTLINENONE) || ((isoutline == OUTLINERIGHT) && (b->depthBorderNorth)) || ((isoutline == OUTLINELEFT) && (b->depthBorderWest)) || ((isoutline == OUTLINEBOTTOM) && (b->depthBorderDown))) {
if(fileindex < 0) {
if(shade_color.a > 0.001f)
b->AssembleSprite(
defaultsheet, premultiply(shade_color),
sheetx * spritescale,
sheety * spritescale,
spritewidth * spritescale,
spriteheight * spritescale,
drawx + (offset_x + offset_user_x)*ssConfig.scale,
drawy + (offset_user_y + (offset_y - WALLHEIGHT))*ssConfig.scale,
spritewidth*ssConfig.scale,
spriteheight*ssConfig.scale,
0);
} else {

if(shade_color.a > 0.001f)
b->AssembleSprite(
getImgFile(fileindex),
premultiply(shade_color),
sheetx * spritescale,
sheety * spritescale,
spritewidth * spritescale,
spriteheight * spritescale,
drawx + (offset_x + offset_user_x)*ssConfig.scale,
drawy + (offset_user_y + (offset_y - WALLHEIGHT))*ssConfig.scale,
spritewidth*ssConfig.scale,
spriteheight*ssConfig.scale,
0);
if(shade_color.a > 0.001f) {
b->AssembleSprite(
fileindex < 0 ? defaultsheet : getImgFile(fileindex),
premultiply(shade_color),
sheetx * spritescale,
sheety * spritescale,
spritewidth * spritescale,
spriteheight * spritescale,
drawx + (offset_x + offset_user_x)*ssConfig.scale,
drawy + (offset_user_y + (offset_y - WALLHEIGHT))*ssConfig.scale,
spritewidth*ssConfig.scale,
spriteheight*ssConfig.scale,
0);
}
}
if(needoutline) {
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Template for new versions:
- `stonesense`: fixed debug performance timers to show milliseconds as intended
- `stonesense`: ``CACHE_IMAGES`` now disables mipmapping, stopping sprites from going transparent
- `stonesense`: fixed issue where depth borders wouldn't be rendered for some walls
- `stonesense`: fixed issue where tiles near the bottom edge would be culled

## Misc Improvements
- `stonesense`: improved the way altars look
Expand Down

0 comments on commit fd1f5b1

Please sign in to comment.