From d3d4ce49b9ba1570d152a747d76f67b9090ec2ca Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Sat, 19 Nov 2022 14:49:36 -0500 Subject: [PATCH] Use proper types and reduce variables scope --- GRRLIB/GRRLIB/GRRLIB_3D.c | 26 ++++++++++++------------ GRRLIB/GRRLIB/GRRLIB_bmf.c | 32 ++++++++++++++++-------------- GRRLIB/GRRLIB/GRRLIB_snapshot.c | 4 ++-- GRRLIB/GRRLIB/GRRLIB_texEdit.c | 2 +- GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h | 6 +++--- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB_3D.c b/GRRLIB/GRRLIB/GRRLIB_3D.c index c181282..331438d 100644 --- a/GRRLIB/GRRLIB/GRRLIB_3D.c +++ b/GRRLIB/GRRLIB/GRRLIB_3D.c @@ -251,14 +251,14 @@ void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 ang guMtxIdentity(ObjTransformationMtx); - if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)) { + if((scalx != 1.0f) || (scaly != 1.0f) || (scalz != 1.0f)) { guMtxIdentity(m); guMtxScaleApply(m, m, scalx, scaly, scalz); guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); } - if((angx !=0.0f) || (angy !=0.0f) || (angz !=0.0f)) { + if((angx != 0.0f) || (angy != 0.0f) || (angz != 0.0f)) { Mtx rx, ry, rz; guMtxIdentity(m); guMtxRotAxisDeg(rx, &_GRRaxisx, angx); @@ -270,7 +270,7 @@ void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 ang guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); } - if((posx !=0.0f) || (posy !=0.0f) || (posz !=0.0f)) { + if((posx != 0.0f) || (posy != 0.0f) || (posz != 0.0f)) { guMtxIdentity(m); guMtxTransApply(m, m, posx, posy, posz); @@ -383,8 +383,8 @@ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) f32 sinTheta = 0.0; for (int i = rings - 1; i >= 0; i--) { const f32 theta1 = theta + ringDelta; - const f32 cosTheta1 = cos(theta1); - const f32 sinTheta1 = sin(theta1); + const f32 cosTheta1 = cosf(theta1); + const f32 sinTheta1 = sinf(theta1); if(filled == true) { GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (nsides + 1)); } @@ -394,8 +394,8 @@ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) f32 phi = 0.0; for (int j = nsides; j >= 0; j--) { phi += sideDelta; - const f32 cosPhi = cos(phi); - const f32 sinPhi = sin(phi); + const f32 cosPhi = cosf(phi); + const f32 sinPhi = sinf(phi); const f32 dist = R + r * cosPhi; GX_Position3f32(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); @@ -423,12 +423,12 @@ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) { for(int i = 0; i <= lats; i++) { const f32 lat0 = M_PI * (-0.5F + (f32) (i - 1) / lats); - const f32 z0 = sin(lat0); - const f32 zr0 = cos(lat0); + const f32 z0 = sinf(lat0); + const f32 zr0 = cosf(lat0); const f32 lat1 = M_PI * (-0.5F + (f32) i / lats); - const f32 z1 = sin(lat1); - const f32 zr1 = cos(lat1); + const f32 z1 = sinf(lat1); + const f32 zr1 = cosf(lat1); if(filled == true) { GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (longs + 1)); @@ -438,8 +438,8 @@ void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) { } for(int j = 0; j <= longs; j++) { const f32 lng = 2 * M_PI * (f32) (j - 1) / longs; - const f32 x = cos(lng); - const f32 y = sin(lng); + const f32 x = cosf(lng); + const f32 y = sinf(lng); GX_Position3f32(x * zr0 * r, y * zr0 * r, z0 * r); GX_Normal3f32(x * zr0 * r, y * zr0 * r, z0 * r); diff --git a/GRRLIB/GRRLIB/GRRLIB_bmf.c b/GRRLIB/GRRLIB/GRRLIB_bmf.c index e89ab44..28210d1 100644 --- a/GRRLIB/GRRLIB/GRRLIB_bmf.c +++ b/GRRLIB/GRRLIB/GRRLIB_bmf.c @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------------ -Copyright (c) 2009-2020 The GRRLIB Team +Copyright (c) 2009-2022 The GRRLIB Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -34,9 +34,9 @@ THE SOFTWARE. */ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) { GRRLIB_bytemapFont *fontArray = (struct GRRLIB_bytemapFont *)malloc(sizeof(GRRLIB_bytemapFont)); - u32 i, j = 1; if (fontArray != NULL && my_bmf[0]==0xE1 && my_bmf[1]==0xE6 && my_bmf[2]==0xD5 && my_bmf[3]==0x1A) { + u32 j = 1; fontArray->version = my_bmf[4]; //u8 lineheight = my_bmf[5]; //short int sizeover = my_bmf[6]; @@ -48,7 +48,7 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) { u8 nbPalette = my_bmf[16]; short int numcolpal = 3 * nbPalette; fontArray->palette = (u32 *)calloc(nbPalette + 1, sizeof(u32)); - for (i=0; i < numcolpal; i+=3) { + for (u32 i=0; i < numcolpal; i+=3) { fontArray->palette[j++] = ((((my_bmf[i+17]<<2)+3)<<24) | (((my_bmf[i+18]<<2)+3)<<16) | (((my_bmf[i+19]<<2)+3)<<8) | 0xFF); } j = my_bmf[17 + numcolpal]; @@ -58,7 +58,7 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) { fontArray->nbChar = (my_bmf[j] | my_bmf[j+1]<<8); memset(fontArray->charDef, 0, 256 * sizeof(GRRLIB_bytemapChar)); j++; - for (i=0; i < fontArray->nbChar; i++) { + for (u32 i=0; i < fontArray->nbChar; i++) { const u8 c = my_bmf[++j]; fontArray->charDef[c].width = my_bmf[++j]; fontArray->charDef[c].height = my_bmf[++j]; @@ -83,16 +83,18 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) { * @param bmf A GRRLIB_bytemapFont structure. */ void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) { - if (bmf != NULL) { - for (u16 i=0; i<256; i++) { - if (bmf->charDef[i].data != NULL) { - free(bmf->charDef[i].data); - } - } - free(bmf->palette); - free(bmf->name); - free(bmf); + if (bmf == NULL) { + return; } + + for (u16 i = 0; i < 256; i++) { + if (bmf->charDef[i].data != NULL) { + free(bmf->charDef[i].data); + } + } + free(bmf->palette); + free(bmf->name); + free(bmf); } /** @@ -115,7 +117,7 @@ void GRRLIB_InitTileSet (GRRLIB_texImg *tex, } tex->tilestart = tilestart; tex->tiledtex = true; - tex->ofnormaltexx = 1.0F / tex->nbtilew; - tex->ofnormaltexy = 1.0F / tex->nbtileh; + tex->ofnormaltexx = 1.0f / tex->nbtilew; + tex->ofnormaltexy = 1.0f / tex->nbtileh; GRRLIB_SetHandle( tex, 0, 0 ); } diff --git a/GRRLIB/GRRLIB/GRRLIB_snapshot.c b/GRRLIB/GRRLIB/GRRLIB_snapshot.c index f5570ce..a90babe 100644 --- a/GRRLIB/GRRLIB/GRRLIB_snapshot.c +++ b/GRRLIB/GRRLIB/GRRLIB_snapshot.c @@ -29,7 +29,7 @@ THE SOFTWARE. * @param tex A pointer to a texture representing the screen. * @param clear When this flag is set to @c true, the screen is cleared after copy. */ -void GRRLIB_Screen2Texture (int posx, int posy, GRRLIB_texImg *tex, bool clear) { +void GRRLIB_Screen2Texture (u16 posx, u16 posy, GRRLIB_texImg *tex, bool clear) { if(tex == NULL || tex->data == NULL) { return; } @@ -60,7 +60,7 @@ void GRRLIB_CompoStart (void) { * @param posy Top left corner of the grabbed part. * @param tex A pointer to a texture representing the screen. */ -void GRRLIB_CompoEnd(int posx, int posy, GRRLIB_texImg *tex) { +void GRRLIB_CompoEnd(u16 posx, u16 posy, GRRLIB_texImg *tex) { GRRLIB_Screen2Texture(posx, posy, tex, GX_TRUE); if (rmode->aa) { diff --git a/GRRLIB/GRRLIB/GRRLIB_texEdit.c b/GRRLIB/GRRLIB/GRRLIB_texEdit.c index a22d068..c0a8472 100644 --- a/GRRLIB/GRRLIB/GRRLIB_texEdit.c +++ b/GRRLIB/GRRLIB/GRRLIB_texEdit.c @@ -364,7 +364,7 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) { * @param my_size Size of the JPEG buffer to load. * @return A GRRLIB_texImg structure filled with image information. */ -GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int my_size) { +GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size) { GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg)); if (my_texture == NULL) { diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h index 355b2ab..f832a71 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h @@ -129,9 +129,9 @@ void GRRLIB_Render (void); //------------------------------------------------------------------------------ // GRRLIB_snapshot.c - Create a texture containing a snapshot of a part of the framebuffer -void GRRLIB_Screen2Texture (int posx, int posy, GRRLIB_texImg *tex, bool clear); +void GRRLIB_Screen2Texture (u16 posx, u16 posy, GRRLIB_texImg *tex, bool clear); void GRRLIB_CompoStart (void); -void GRRLIB_CompoEnd(int posx, int posy, GRRLIB_texImg *tex); +void GRRLIB_CompoEnd(u16 posx, u16 posy, GRRLIB_texImg *tex); //------------------------------------------------------------------------------ // GRRLIB_texEdit.c - Modifying the content of a texture @@ -139,7 +139,7 @@ GRRLIB_texImg* GRRLIB_CreateEmptyTexture (const u32 width, const u32 height); GRRLIB_texImg* GRRLIB_LoadTexture (const u8 *my_img); GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png); GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg); -GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int my_size); +GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size); GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp); //------------------------------------------------------------------------------