mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-20 14:25:40 +00:00
Cleanup add brace (#6545)
* Add braces after if conditions
* More add braces after if conditions
* Add braces after while() conditions
* Fix compilation because of macro being modified
* Add braces to for loop
* Add braces after if/goto
* Move comments up
* Remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements
* More remove extra () in the 'return ...;' statements after merge
* Fix inconsistent patterns are xxx == NULL vs !xxx
* More "{}" for "if() break;" and "if() continue;"
* More "{}" after if() short statement
* More "{}" after "if () return;" statement
* More fix inconsistent patterns are xxx == NULL vs !xxx
* Revert some modificaion on SDL_RLEaccel.c
* SDL_RLEaccel: no short statement
* Cleanup 'if' where the bracket is in a new line
* Cleanup 'while' where the bracket is in a new line
* Cleanup 'for' where the bracket is in a new line
* Cleanup 'else' where the bracket is in a new line
(cherry picked from commit 6a2200823c to reduce conflicts merging between SDL2 and SDL3)
This commit is contained in:
committed by
Sam Lantinga
parent
0739d237ad
commit
fb0ce375f0
@@ -219,7 +219,7 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
{
|
||||
SDL_Rect clipped;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
|
||||
int status = 0;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
|
||||
break;
|
||||
}
|
||||
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
if (!dst->format->Amask) {
|
||||
func = SDL_BlendFillRect_RGB;
|
||||
} else {
|
||||
|
||||
@@ -808,12 +808,12 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
{
|
||||
BlendLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateBlendLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
|
||||
}
|
||||
|
||||
@@ -837,12 +837,12 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
SDL_bool draw_end;
|
||||
BlendLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
|
||||
}
|
||||
|
||||
func = SDL_CalculateBlendLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ int
|
||||
SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
|
||||
int status = 0;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
break;
|
||||
}
|
||||
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
if (!dst->format->Amask) {
|
||||
func = SDL_BlendPoint_RGB;
|
||||
} else {
|
||||
|
||||
@@ -143,12 +143,12 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
|
||||
{
|
||||
DrawLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
|
||||
}
|
||||
|
||||
@@ -172,12 +172,12 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
SDL_bool draw_end;
|
||||
DrawLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawLines(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
int
|
||||
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
|
||||
{
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
int i;
|
||||
int x, y;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawPoints(): dst");
|
||||
}
|
||||
|
||||
|
||||
@@ -142,8 +142,9 @@ SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
int row;
|
||||
size_t length;
|
||||
|
||||
if(SDL_MUSTLOCK(surface))
|
||||
if (SDL_MUSTLOCK(surface)) {
|
||||
SDL_LockSurface(surface);
|
||||
}
|
||||
src = (Uint8 *) pixels;
|
||||
dst = (Uint8 *) surface->pixels +
|
||||
rect->y * surface->pitch +
|
||||
@@ -154,8 +155,9 @@ SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
src += pitch;
|
||||
dst += surface->pitch;
|
||||
}
|
||||
if(SDL_MUSTLOCK(surface))
|
||||
if (SDL_MUSTLOCK(surface)) {
|
||||
SDL_UnlockSurface(surface);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -207,7 +209,7 @@ SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP
|
||||
SDL_Point *verts = (SDL_Point *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Point), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -227,7 +229,7 @@ SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRe
|
||||
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Rect), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -249,7 +251,7 @@ SW_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * text
|
||||
{
|
||||
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (SDL_Rect), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -284,7 +286,7 @@ SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * te
|
||||
{
|
||||
CopyExData *verts = (CopyExData *) SDL_AllocateRenderVertices(renderer, sizeof (CopyExData), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -340,7 +342,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
||||
int blitRequired = SDL_FALSE;
|
||||
int isOpaque = SDL_FALSE;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -559,7 +561,7 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
||||
int sz = texture ? sizeof (GeometryCopyData) : sizeof (GeometryFillData);
|
||||
|
||||
verts = (void *) SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -684,7 +686,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
||||
SDL_Surface *surface = SW_ActivateRenderer(renderer);
|
||||
SW_DrawStateCache drawstate;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -960,7 +962,7 @@ SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
Uint32 src_format;
|
||||
void *src_pixels;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -988,7 +990,7 @@ SW_RenderPresent(SDL_Renderer * renderer)
|
||||
{
|
||||
SDL_Window *window = renderer->window;
|
||||
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return SDL_UpdateWindowSurface(window);
|
||||
@@ -1017,19 +1019,19 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
|
||||
SDL_Renderer *renderer;
|
||||
SW_RenderData *data;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
SDL_InvalidParamError("surface");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
|
||||
if (!data) {
|
||||
if (data == NULL) {
|
||||
SW_DestroyRenderer(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
@@ -1075,7 +1077,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
|
||||
/* Set the vsync hint based on our flags, if it's not already set */
|
||||
hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
|
||||
if (!hint || !*hint) {
|
||||
if (hint == NULL || !*hint) {
|
||||
no_hint_set = SDL_TRUE;
|
||||
} else {
|
||||
no_hint_set = SDL_FALSE;
|
||||
@@ -1092,7 +1094,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "");
|
||||
}
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return SW_CreateRendererForSurface(surface);
|
||||
|
||||
@@ -152,10 +152,13 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
|
||||
{
|
||||
/* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
|
||||
int angle90 = (int)(angle/90);
|
||||
if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
|
||||
if (angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
|
||||
angle90 %= 4;
|
||||
if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
if(angle90 & 1) {
|
||||
if (angle90 < 0) {
|
||||
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
}
|
||||
|
||||
if (angle90 & 1) {
|
||||
rect_dest->w = height;
|
||||
rect_dest->h = width;
|
||||
*cangle = 0;
|
||||
@@ -284,8 +287,12 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
for (x = 0; x < dst->w; x++) {
|
||||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if (flipx) dx = sw - dx;
|
||||
if (flipy) dy = sh - dy;
|
||||
if (flipx) {
|
||||
dx = sw - dx;
|
||||
}
|
||||
if (flipy) {
|
||||
dy = sh - dy;
|
||||
}
|
||||
if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
|
||||
int ex, ey;
|
||||
int t1, t2;
|
||||
@@ -341,8 +348,12 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
|
||||
if(flipx) dx = sw - dx;
|
||||
if(flipy) dy = sh - dy;
|
||||
if (flipx) {
|
||||
dx = sw - dx;
|
||||
}
|
||||
if (flipy) {
|
||||
dy = sh - dy;
|
||||
}
|
||||
*pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx);
|
||||
}
|
||||
sdx += icos;
|
||||
@@ -411,8 +422,12 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int
|
||||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
|
||||
if (flipx) dx = sw - dx;
|
||||
if (flipy) dy = sh- dy;
|
||||
if (flipx) {
|
||||
dx = sw - dx;
|
||||
}
|
||||
if (flipy) {
|
||||
dy = sh - dy;
|
||||
}
|
||||
*pc = *((tColorY *)src->pixels + src->pitch * dy + dx);
|
||||
}
|
||||
sdx += icos;
|
||||
@@ -463,8 +478,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
||||
double sangleinv, cangleinv;
|
||||
|
||||
/* Sanity check */
|
||||
if (src == NULL)
|
||||
if (src == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (SDL_HasColorKey(src)) {
|
||||
if (SDL_GetColorKey(src, &colorkey) == 0) {
|
||||
@@ -473,8 +489,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
||||
}
|
||||
/* This function requires a 32-bit surface or 8-bit surface with a colorkey */
|
||||
is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
|
||||
if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
|
||||
if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Calculate target factors from sine/cosine and zoom */
|
||||
sangleinv = sangle*65536.0;
|
||||
@@ -501,8 +518,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
||||
}
|
||||
|
||||
/* Check target */
|
||||
if (rz_dst == NULL)
|
||||
if (rz_dst == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Adjust for guard rows */
|
||||
rz_dst->h = rect_dest->h;
|
||||
@@ -542,14 +560,17 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
||||
angle90 = (int)(angle/90);
|
||||
if (angle90 == angle/90) {
|
||||
angle90 %= 4;
|
||||
if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
if (angle90 < 0) {
|
||||
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
}
|
||||
|
||||
} else {
|
||||
angle90 = -1;
|
||||
}
|
||||
|
||||
if (is8bit) {
|
||||
/* Call the 8-bit transformation routine to do the rotation */
|
||||
if(angle90 >= 0) {
|
||||
if (angle90 >= 0) {
|
||||
transformSurfaceY90(src, rz_dst, angle90, flipx, flipy);
|
||||
} else {
|
||||
transformSurfaceY(src, rz_dst, (int)sangleinv, (int)cangleinv,
|
||||
|
||||
@@ -520,14 +520,26 @@ int SDL_SW_BlitTriangle(
|
||||
maxx = srcrect.x + srcrect.w;
|
||||
maxy = srcrect.y + srcrect.h;
|
||||
if (srcrect.w > 0) {
|
||||
if (s0->x == maxx) s0->x--;
|
||||
if (s1->x == maxx) s1->x--;
|
||||
if (s2->x == maxx) s2->x--;
|
||||
if (s0->x == maxx) {
|
||||
s0->x--;
|
||||
}
|
||||
if (s1->x == maxx) {
|
||||
s1->x--;
|
||||
}
|
||||
if (s2->x == maxx) {
|
||||
s2->x--;
|
||||
}
|
||||
}
|
||||
if (srcrect.h > 0) {
|
||||
if (s0->y == maxy) s0->y--;
|
||||
if (s1->y == maxy) s1->y--;
|
||||
if (s2->y == maxy) s2->y--;
|
||||
if (s0->y == maxy) {
|
||||
s0->y--;
|
||||
}
|
||||
if (s1->y == maxy) {
|
||||
s1->y--;
|
||||
}
|
||||
if (s2->y == maxy) {
|
||||
s2->y--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user