Skip to content

Commit

Permalink
add DivRoundClosest function, formatting (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfomin authored Jul 13, 2024
1 parent 80740b0 commit c447781
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/doomtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ typedef byte lighttable_t;

#define arrlen(array) (sizeof(array) / sizeof(*array))

#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
#ifndef BETWEEN
#define BETWEEN(l,u,x) ((l)>(x)?(l):(x)>(u)?(u):(x))
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#define MAX(a, b) (((a) > (b)) ? (a) : (b))

#define BETWEEN(l, u, x) ((l) > (x) ? (l) : (x) > (u) ? (u) : (x))

inline static int DivRoundClosest(const int n, const int d)
{
return ((n < 0) == (d < 0)) ? ((n + d / 2) / d) : ((n - d / 2) / d);
}

#if defined(_MSC_VER) && !defined(__cplusplus)
#define inline __inline
Expand Down
4 changes: 2 additions & 2 deletions src/f_finale.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,13 @@ void F_BunnyScroll (void)

scrolled = 320 - (finalecount-230)/2;

int p1offset = (video.unscaledw - SHORT(p1->width) + 1) / 2;
int p1offset = DivRoundClosest(video.unscaledw - SHORT(p1->width), 2);
if (SHORT(p1->width) == 320)
{
p1offset += (SHORT(p2->width) - 320) / 2;
}

int p2offset = (video.unscaledw - SHORT(p2->width) + 1) / 2;
int p2offset = DivRoundClosest(video.unscaledw - SHORT(p2->width), 2);

if (scrolled <= 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/v_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void V_DrawPatchTRTR(int x, int y, patch_t *patch, byte *outr1, byte *outr2)

void V_DrawPatchFullScreen(patch_t *patch)
{
const int x = (video.unscaledw - SHORT(patch->width)) / 2;
const int x = DivRoundClosest(video.unscaledw - SHORT(patch->width), 2);

patch->leftoffset = 0;
patch->topoffset = 0;
Expand Down

0 comments on commit c447781

Please sign in to comment.