Skip to content

Commit

Permalink
Merge branch 'master' into video_test
Browse files Browse the repository at this point in the history
  • Loading branch information
rfomin committed Feb 21, 2024
2 parents 9865360 + 4b0f729 commit 2b79c7d
Showing 1 changed file with 51 additions and 32 deletions.
83 changes: 51 additions & 32 deletions src/v_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,35 @@ int V_ScaleY(int y)
return y1lookup[y];
}

static void V_ClipRect(vrect_t *rect)
{
// clip to left and top edges
rect->cx1 = rect->x >= 0 ? rect->x : 0;
rect->cy1 = rect->y >= 0 ? rect->y : 0;

// determine right and bottom edges
rect->cx2 = rect->x + rect->w - 1;
rect->cy2 = rect->y + rect->h - 1;

// clip right and bottom edges
if (rect->cx2 >= video.unscaledw)
rect->cx2 = video.unscaledw - 1;
if (rect->cy2 >= SCREENHEIGHT)
rect->cy2 = SCREENHEIGHT - 1;

// determine clipped width and height
rect->cw = rect->cx2 - rect->cx1 + 1;
rect->ch = rect->cy2 - rect->cy1 + 1;
}

static void V_ScaleClippedRect(vrect_t *rect)
{
rect->sx = x1lookup[rect->cx1];
rect->sy = y1lookup[rect->cy1];
rect->sw = x2lookup[rect->cx2] - rect->sx + 1;
rect->sh = y2lookup[rect->cy2] - rect->sy + 1;
}

void V_FillRect(int x, int y, int width, int height, byte color)
{
vrect_t dstrect;
Expand All @@ -641,7 +670,13 @@ void V_FillRect(int x, int y, int width, int height, byte color)
dstrect.w = width;
dstrect.h = height;

V_ScaleRect(&dstrect);
V_ClipRect(&dstrect);

// clipped away completely?
if (dstrect.cw <= 0 || dstrect.ch <= 0)
return;

V_ScaleClippedRect(&dstrect);

byte* dest = V_ADDRESS(dest_screen, dstrect.sx, dstrect.sy);

Expand Down Expand Up @@ -683,13 +718,26 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source,
srcrect.w = width;
srcrect.h = height;

V_ClipRect(&srcrect);

// clipped away completely?
if (srcrect.cw <= 0 || srcrect.ch <= 0)
return;

V_ScaleClippedRect(&srcrect);

dstrect.x = destx;
dstrect.y = desty;
dstrect.w = width;
dstrect.h = height;

V_ScaleRect(&srcrect);
V_ScaleRect(&dstrect);
V_ClipRect(&dstrect);

// clipped away completely?
if (dstrect.cw <= 0 || dstrect.ch <= 0)
return;

V_ScaleClippedRect(&dstrect);

// use the smaller of the two scaled rect widths / heights
usew = (srcrect.sw < dstrect.sw ? srcrect.sw : dstrect.sw);
Expand All @@ -706,35 +754,6 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source,
}
}

static void V_ClipRect(vrect_t *rect)
{
// clip to left and top edges
rect->cx1 = rect->x >= 0 ? rect->x : 0;
rect->cy1 = rect->y >= 0 ? rect->y : 0;

// determine right and bottom edges
rect->cx2 = rect->x + rect->w - 1;
rect->cy2 = rect->y + rect->h - 1;

// clip right and bottom edges
if (rect->cx2 >= video.unscaledw)
rect->cx2 = video.unscaledw - 1;
if (rect->cy2 >= SCREENHEIGHT)
rect->cy2 = SCREENHEIGHT - 1;

// determine clipped width and height
rect->cw = rect->cx2 - rect->cx1 + 1;
rect->ch = rect->cy2 - rect->cy1 + 1;
}

static void V_ScaleClippedRect(vrect_t *rect)
{
rect->sx = x1lookup[rect->cx1];
rect->sy = y1lookup[rect->cy1];
rect->sw = x2lookup[rect->cx2] - rect->sx + 1;
rect->sh = y2lookup[rect->cy2] - rect->sy + 1;
}

//
// V_DrawBlock
//
Expand Down

0 comments on commit 2b79c7d

Please sign in to comment.