mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-12-25 11:29:19 +00:00
Use proper types and reduce variables scope
This commit is contained in:
parent
fd9a59a348
commit
d3d4ce49b9
5 changed files with 36 additions and 34 deletions
|
@ -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);
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue