Use proper types and reduce variables scope

This commit is contained in:
Crayon2000 2022-11-19 14:49:36 -05:00
parent fd9a59a348
commit d3d4ce49b9
5 changed files with 36 additions and 34 deletions

View file

@ -251,14 +251,14 @@ void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 ang
guMtxIdentity(ObjTransformationMtx); guMtxIdentity(ObjTransformationMtx);
if((scalx !=1.0f) || (scaly !=1.0f) || (scalz !=1.0f)) { if((scalx != 1.0f) || (scaly != 1.0f) || (scalz != 1.0f)) {
guMtxIdentity(m); guMtxIdentity(m);
guMtxScaleApply(m, m, scalx, scaly, scalz); guMtxScaleApply(m, m, scalx, scaly, scalz);
guMtxConcat(m, ObjTransformationMtx, ObjTransformationMtx); 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; Mtx rx, ry, rz;
guMtxIdentity(m); guMtxIdentity(m);
guMtxRotAxisDeg(rx, &_GRRaxisx, angx); 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); 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); guMtxIdentity(m);
guMtxTransApply(m, m, posx, posy, posz); 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; f32 sinTheta = 0.0;
for (int i = rings - 1; i >= 0; i--) { for (int i = rings - 1; i >= 0; i--) {
const f32 theta1 = theta + ringDelta; const f32 theta1 = theta + ringDelta;
const f32 cosTheta1 = cos(theta1); const f32 cosTheta1 = cosf(theta1);
const f32 sinTheta1 = sin(theta1); const f32 sinTheta1 = sinf(theta1);
if(filled == true) { if(filled == true) {
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (nsides + 1)); 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; f32 phi = 0.0;
for (int j = nsides; j >= 0; j--) { for (int j = nsides; j >= 0; j--) {
phi += sideDelta; phi += sideDelta;
const f32 cosPhi = cos(phi); const f32 cosPhi = cosf(phi);
const f32 sinPhi = sin(phi); const f32 sinPhi = sinf(phi);
const f32 dist = R + r * cosPhi; const f32 dist = R + r * cosPhi;
GX_Position3f32(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); 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) { void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) {
for(int i = 0; i <= lats; i++) { for(int i = 0; i <= lats; i++) {
const f32 lat0 = M_PI * (-0.5F + (f32) (i - 1) / lats); const f32 lat0 = M_PI * (-0.5F + (f32) (i - 1) / lats);
const f32 z0 = sin(lat0); const f32 z0 = sinf(lat0);
const f32 zr0 = cos(lat0); const f32 zr0 = cosf(lat0);
const f32 lat1 = M_PI * (-0.5F + (f32) i / lats); const f32 lat1 = M_PI * (-0.5F + (f32) i / lats);
const f32 z1 = sin(lat1); const f32 z1 = sinf(lat1);
const f32 zr1 = cos(lat1); const f32 zr1 = cosf(lat1);
if(filled == true) { if(filled == true) {
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (longs + 1)); 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++) { for(int j = 0; j <= longs; j++) {
const f32 lng = 2 * M_PI * (f32) (j - 1) / longs; const f32 lng = 2 * M_PI * (f32) (j - 1) / longs;
const f32 x = cos(lng); const f32 x = cosf(lng);
const f32 y = sin(lng); const f32 y = sinf(lng);
GX_Position3f32(x * zr0 * r, y * zr0 * r, z0 * r); GX_Position3f32(x * zr0 * r, y * zr0 * r, z0 * r);
GX_Normal3f32(x * zr0 * r, y * zr0 * r, z0 * r); GX_Normal3f32(x * zr0 * r, y * zr0 * r, z0 * r);

View file

@ -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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal 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* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
GRRLIB_bytemapFont *fontArray = (struct GRRLIB_bytemapFont *)malloc(sizeof(GRRLIB_bytemapFont)); 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) { 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]; fontArray->version = my_bmf[4];
//u8 lineheight = my_bmf[5]; //u8 lineheight = my_bmf[5];
//short int sizeover = my_bmf[6]; //short int sizeover = my_bmf[6];
@ -48,7 +48,7 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
u8 nbPalette = my_bmf[16]; u8 nbPalette = my_bmf[16];
short int numcolpal = 3 * nbPalette; short int numcolpal = 3 * nbPalette;
fontArray->palette = (u32 *)calloc(nbPalette + 1, sizeof(u32)); 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); 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]; 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); fontArray->nbChar = (my_bmf[j] | my_bmf[j+1]<<8);
memset(fontArray->charDef, 0, 256 * sizeof(GRRLIB_bytemapChar)); memset(fontArray->charDef, 0, 256 * sizeof(GRRLIB_bytemapChar));
j++; j++;
for (i=0; i < fontArray->nbChar; i++) { for (u32 i=0; i < fontArray->nbChar; i++) {
const u8 c = my_bmf[++j]; const u8 c = my_bmf[++j];
fontArray->charDef[c].width = my_bmf[++j]; fontArray->charDef[c].width = my_bmf[++j];
fontArray->charDef[c].height = my_bmf[++j]; fontArray->charDef[c].height = my_bmf[++j];
@ -83,8 +83,11 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
* @param bmf A GRRLIB_bytemapFont structure. * @param bmf A GRRLIB_bytemapFont structure.
*/ */
void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) { void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) {
if (bmf != NULL) { if (bmf == NULL) {
for (u16 i=0; i<256; i++) { return;
}
for (u16 i = 0; i < 256; i++) {
if (bmf->charDef[i].data != NULL) { if (bmf->charDef[i].data != NULL) {
free(bmf->charDef[i].data); free(bmf->charDef[i].data);
} }
@ -92,7 +95,6 @@ void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) {
free(bmf->palette); free(bmf->palette);
free(bmf->name); free(bmf->name);
free(bmf); free(bmf);
}
} }
/** /**
@ -115,7 +117,7 @@ void GRRLIB_InitTileSet (GRRLIB_texImg *tex,
} }
tex->tilestart = tilestart; tex->tilestart = tilestart;
tex->tiledtex = true; tex->tiledtex = true;
tex->ofnormaltexx = 1.0F / tex->nbtilew; tex->ofnormaltexx = 1.0f / tex->nbtilew;
tex->ofnormaltexy = 1.0F / tex->nbtileh; tex->ofnormaltexy = 1.0f / tex->nbtileh;
GRRLIB_SetHandle( tex, 0, 0 ); GRRLIB_SetHandle( tex, 0, 0 );
} }

View file

@ -29,7 +29,7 @@ THE SOFTWARE.
* @param tex A pointer to a texture representing the screen. * @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. * @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) { if(tex == NULL || tex->data == NULL) {
return; return;
} }
@ -60,7 +60,7 @@ void GRRLIB_CompoStart (void) {
* @param posy Top left corner of the grabbed part. * @param posy Top left corner of the grabbed part.
* @param tex A pointer to a texture representing the screen. * @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); GRRLIB_Screen2Texture(posx, posy, tex, GX_TRUE);
if (rmode->aa) { if (rmode->aa) {

View file

@ -364,7 +364,7 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) {
* @param my_size Size of the JPEG buffer to load. * @param my_size Size of the JPEG buffer to load.
* @return A GRRLIB_texImg structure filled with image information. * @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)); GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
if (my_texture == NULL) { if (my_texture == NULL) {

View file

@ -129,9 +129,9 @@ void GRRLIB_Render (void);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_snapshot.c - Create a texture containing a snapshot of a part of the framebuffer // 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_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 // 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_LoadTexture (const u8 *my_img);
GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png); GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png);
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg); 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); GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------