mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-12-22 18:39:18 +00:00
Reduce variable scope
This commit is contained in:
parent
3ee20bffc2
commit
80e2382376
5 changed files with 31 additions and 40 deletions
|
@ -51,8 +51,6 @@ static bool is_setup = false; // To control entry and exit
|
|||
* @see GRRLIB_Exit
|
||||
*/
|
||||
int GRRLIB_Init (void) {
|
||||
f32 yscale;
|
||||
u32 xfbHeight;
|
||||
Mtx44 perspective;
|
||||
s8 error_code = 0;
|
||||
|
||||
|
@ -144,8 +142,8 @@ int GRRLIB_Init (void) {
|
|||
}
|
||||
|
||||
// Other GX setup
|
||||
yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
|
||||
xfbHeight = GX_SetDispCopyYScale(yscale);
|
||||
f32 yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
|
||||
u32 xfbHeight = GX_SetDispCopyYScale(yscale);
|
||||
GX_SetDispCopySrc(0, 0, rmode->fbWidth, rmode->efbHeight);
|
||||
GX_SetDispCopyDst(rmode->fbWidth, xfbHeight);
|
||||
GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter);
|
||||
|
|
|
@ -77,18 +77,13 @@ typedef struct tagRGBQUAD {
|
|||
static
|
||||
void RawTo4x4RGBA (const u8 *src, void *dst,
|
||||
const u32 width, const u32 height) {
|
||||
u32 block;
|
||||
u32 i;
|
||||
u8 c;
|
||||
u8 argb;
|
||||
|
||||
u8 *p = (u8*)dst;
|
||||
|
||||
for (block = 0; block < height; block += 4) {
|
||||
for (i = 0; i < width; i += 4) {
|
||||
for (u32 block = 0; block < height; block += 4) {
|
||||
for (u32 i = 0; i < width; i += 4) {
|
||||
// Alpha and Red
|
||||
for (c = 0; c < 4; ++c) {
|
||||
for (argb = 0; argb < 4; ++argb) {
|
||||
for (u8 c = 0; c < 4; ++c) {
|
||||
for (u8 argb = 0; argb < 4; ++argb) {
|
||||
// Alpha pixels
|
||||
*p++ = 255;
|
||||
// Red pixels
|
||||
|
@ -97,8 +92,8 @@ void RawTo4x4RGBA (const u8 *src, void *dst,
|
|||
}
|
||||
|
||||
// Green and Blue
|
||||
for (c = 0; c < 4; ++c) {
|
||||
for (argb = 0; argb < 4; ++argb) {
|
||||
for (u8 c = 0; c < 4; ++c) {
|
||||
for (u8 argb = 0; argb < 4; ++argb) {
|
||||
// Green pixels
|
||||
*p++ = src[(((i + argb) + ((block + c) * width)) * 3) + 1];
|
||||
// Blue pixels
|
||||
|
@ -188,9 +183,8 @@ GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png) {
|
|||
* @return An array of palette. Memory must be deleted.
|
||||
*/
|
||||
static RGBQUAD* GRRLIB_CreatePalette (const u8 *my_bmp, u32 Size) {
|
||||
u32 i = 0;
|
||||
RGBQUAD *Palette = calloc(Size, sizeof(RGBQUAD));
|
||||
for(u32 n=0; n<Size; n++) {
|
||||
for(u32 n=0, i=0; n<Size; n++) {
|
||||
Palette[n].rgbBlue = my_bmp[i];
|
||||
Palette[n].rgbGreen = my_bmp[i+1];
|
||||
Palette[n].rgbRed = my_bmp[i+2];
|
||||
|
@ -203,7 +197,7 @@ static RGBQUAD* GRRLIB_CreatePalette (const u8 *my_bmp, u32 Size) {
|
|||
/**
|
||||
* Load a texture from a buffer.
|
||||
* It only works for the MS-Windows standard format uncompressed (1-bit, 4-bit, 8-bit, 24-bit and 32-bit).
|
||||
* @param my_bmp the Bitmap buffer to load.
|
||||
* @param my_bmp The Bitmap buffer to load.
|
||||
* @return A GRRLIB_texImg structure filled with image information.
|
||||
*/
|
||||
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
|
||||
|
@ -215,9 +209,6 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
|
|||
|
||||
BITMAPFILEHEADER MyBitmapFileHeader;
|
||||
BITMAPINFOHEADER MyBitmapHeader;
|
||||
u16 pal_ref;
|
||||
u32 BufferSize;
|
||||
s32 y, x, i;
|
||||
|
||||
// Fill file header structure
|
||||
MyBitmapFileHeader.bfType = (my_bmp[0] | my_bmp[1]<<8);
|
||||
|
@ -240,14 +231,16 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
|
|||
|
||||
my_texture->data = memalign(32, MyBitmapHeader.biWidth * MyBitmapHeader.biHeight * 4);
|
||||
if (my_texture->data != NULL && MyBitmapFileHeader.bfType == 0x4D42) {
|
||||
u32 BufferSize;
|
||||
s32 i;
|
||||
RGBQUAD *Palette;
|
||||
my_texture->w = MyBitmapHeader.biWidth;
|
||||
my_texture->h = MyBitmapHeader.biHeight;
|
||||
switch(MyBitmapHeader.biBitCount) {
|
||||
case 32: // RGBA images
|
||||
i = 54;
|
||||
for(y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
for(s32 y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(s32 x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
GRRLIB_SetPixelTotexImg(x, y, my_texture,
|
||||
RGBA(my_bmp[i+2], my_bmp[i+1], my_bmp[i], my_bmp[i+3]));
|
||||
i += 4;
|
||||
|
@ -257,8 +250,8 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
|
|||
case 24: // truecolor images
|
||||
BufferSize = (MyBitmapHeader.biWidth % 4);
|
||||
i = 54;
|
||||
for(y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
for(s32 y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(s32 x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
GRRLIB_SetPixelTotexImg(x, y, my_texture,
|
||||
RGBA(my_bmp[i+2], my_bmp[i+1], my_bmp[i], 0xFF));
|
||||
i += 3;
|
||||
|
@ -274,8 +267,8 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
|
|||
BufferSize -= MyBitmapHeader.biWidth;
|
||||
Palette = GRRLIB_CreatePalette(&my_bmp[54], 256);
|
||||
i = 1078; // 54 + (MyBitmapHeader.biBitCount * 4)
|
||||
for(y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
for(s32 y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(s32 x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
GRRLIB_SetPixelTotexImg(x, y, my_texture,
|
||||
RGBA(Palette[my_bmp[i]].rgbRed,
|
||||
Palette[my_bmp[i]].rgbGreen,
|
||||
|
@ -297,9 +290,9 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
|
|||
}
|
||||
Palette = GRRLIB_CreatePalette(&my_bmp[54], 16);
|
||||
i = 118; // 54 + (MyBitmapHeader.biBitCount * 4)
|
||||
for(y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
pal_ref = (my_bmp[i + (x / 2)] >> ((x % 2) ? 0 : 4)) & 0x0F;
|
||||
for(s32 y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(s32 x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
u16 pal_ref = (my_bmp[i + (x / 2)] >> ((x % 2) ? 0 : 4)) & 0x0F;
|
||||
GRRLIB_SetPixelTotexImg(x, y, my_texture,
|
||||
RGBA(Palette[pal_ref].rgbRed,
|
||||
Palette[pal_ref].rgbGreen,
|
||||
|
@ -320,9 +313,9 @@ GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp) {
|
|||
}
|
||||
Palette = GRRLIB_CreatePalette(&my_bmp[54], 2);
|
||||
i = 62; // 54 + (MyBitmapHeader.biBitCount * 4)
|
||||
for(y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
pal_ref = (my_bmp[i + (x / 8)] >> (-x%8+7)) & 0x01;
|
||||
for(s32 y=MyBitmapHeader.biHeight-1; y>=0; y--) {
|
||||
for(s32 x=0; x<MyBitmapHeader.biWidth; x++) {
|
||||
u16 pal_ref = (my_bmp[i + (x / 8)] >> (-x%8+7)) & 0x01;
|
||||
GRRLIB_SetPixelTotexImg(x, y, my_texture,
|
||||
RGBA(Palette[pal_ref].rgbRed,
|
||||
Palette[pal_ref].rgbGreen,
|
||||
|
|
|
@ -51,7 +51,7 @@ void GRRLIB_SetHandle (GRRLIB_texImg *tex, const int x, const int y) {
|
|||
*/
|
||||
INLINE
|
||||
void GRRLIB_SetMidHandle (GRRLIB_texImg *tex, const bool enabled) {
|
||||
if (enabled) {
|
||||
if (enabled == true) {
|
||||
if (tex->tiledtex) {
|
||||
tex->offsetx = (((int)tex->tilew)/2);
|
||||
tex->offsety = (((int)tex->tileh)/2);
|
||||
|
|
|
@ -66,7 +66,7 @@ int main() {
|
|||
WPAD_SetVRes(WPAD_CHAN_0, WinW, WinH);
|
||||
WPAD_IR(WPAD_CHAN_0, &P1Mote);
|
||||
|
||||
// WiiMote IR Viewport Correction
|
||||
// Wii Remote IR Viewport Correction
|
||||
int P1MX = P1Mote.sx - 150;
|
||||
int P1MY = P1Mote.sy - 150;
|
||||
|
||||
|
|
|
@ -69,8 +69,8 @@ int main() {
|
|||
|
||||
// Init GRRLIB & WiiUse
|
||||
GRRLIB_Init();
|
||||
u16 WinW = rmode->fbWidth;
|
||||
u16 WinH = rmode->efbHeight;
|
||||
const u16 WinW = rmode->fbWidth;
|
||||
const u16 WinH = rmode->efbHeight;
|
||||
WPAD_Init();
|
||||
WPAD_SetIdleTimeout( 60 * 10 );
|
||||
WPAD_SetDataFormat( WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR );
|
||||
|
@ -98,7 +98,7 @@ int main() {
|
|||
// Resetting Vars
|
||||
GRRLIB_SetBlend( GRRLIB_BLEND_ALPHA );
|
||||
|
||||
// WiiMote IR Viewport correction
|
||||
// Wii Remote IR Viewport correction
|
||||
const int P1MX = P1Mote.sx - 150;
|
||||
const int P1MY = P1Mote.sy - 150;
|
||||
|
||||
|
@ -127,8 +127,8 @@ int main() {
|
|||
GRRLIB_DrawImg( P1MX, P1MY, GFX_Crosshair, 0, 1, 1, RGBA(255, 255, 255, 255) );
|
||||
|
||||
// Draw Text
|
||||
GRRLIB_Rectangle( 28, 28, 280, 20, RGBA(0, 0, 0, 160), 1 );
|
||||
GRRLIB_Printf ( 32, 32, GFX_Font, 0xFFFFFFFF, 1, "Point your WiiMote on the screen." );
|
||||
GRRLIB_Rectangle( 28, 28, 292, 20, RGBA(0, 0, 0, 160), 1 );
|
||||
GRRLIB_Printf ( 32, 32, GFX_Font, 0xFFFFFFFF, 1, "Point your Wii Remote on the screen." );
|
||||
GRRLIB_Rectangle( 28, 48, 200, 16, RGBA(0, 0, 0, 160), 1 );
|
||||
GRRLIB_Printf ( 32, 48, GFX_Font, 0xFFFFFFFF, 1, "Number of Particle: %d", ParticleList.size() );
|
||||
GRRLIB_Rectangle( 28, 64, 64, 16, RGBA(0, 0, 0, 160), 1 );
|
||||
|
|
Loading…
Reference in a new issue