From 67ab9e9829efda4165352cd475e9287bc70c27a3 Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Mon, 9 Feb 2009 04:35:17 +0000 Subject: [PATCH] [CHG] Pre-calculating stuff in GRRLIB_BMFX_Scatter [CHG] Showing FPS on the template --- README.TXT | 6 +++--- template/source/GRRLIB/GRRLIB.c | 28 +++++++++++++--------------- template/source/main.c | 27 ++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/README.TXT b/README.TXT index 7d6be9c..2da62bb 100644 --- a/README.TXT +++ b/README.TXT @@ -54,9 +54,9 @@ ChangeLog : * GRRLIB_GetPixelFromtexImg and GRRLIB_SetPixelTotexImg -* GRRLIB_CreateEmptyTexture and GRRLIB_FlushTex - -* New Bitmap FX: GRRLIB_BMFX_GrayScale +* GRRLIB_CreateEmptyTexture and GRRLIB_FlushTex + +* New Bitmap FX: GRRLIB_BMFX_GrayScale and GRRLIB_BMFX_Scatter * add GRRLIB_Exit to free the memory allocated by GRRLIB diff --git a/template/source/GRRLIB/GRRLIB.c b/template/source/GRRLIB/GRRLIB.c index 10633b0..cda2954 100644 --- a/template/source/GRRLIB/GRRLIB.c +++ b/template/source/GRRLIB/GRRLIB.c @@ -515,17 +515,14 @@ void GRRLIB_FlushTex(GRRLIB_texImg tex) */ void GRRLIB_BMFX_GrayScale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { unsigned int x, y; - u8 r, g, b, gray; + u8 gray; u32 color; for(y=0; y>24) & 0xFF; - g = (color>>16) & 0xFF; - r = (color>>8) & 0xFF; - gray = ((r*77 + g*150 + b*28) / (255)); + gray = ((((color>>8) & 0xFF)*77 + ((color>>16) & 0xFF)*150 + ((color>>24) & 0xFF)*28) / (255)); GRRLIB_SetPixelTotexImg(x, y, texdest, ((gray << 24) | (gray << 16) | (gray << 8) | (color & 0xFF))); @@ -542,20 +539,21 @@ void GRRLIB_BMFX_GrayScale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { */ void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { unsigned int x, y; - int val1,val2,val3,val4; + int val1, val2, val3, val4; + int factorx2 = factor*2; - for(y=0;y= texsrc.w) && (x + val1 <0) && (y + val2 >= texsrc.h) && (y + val2 <0)){ + if((val1 >= texsrc.w) && (val1 <0) && (val2 >= texsrc.h) && (val2 <0)) { } - else{ - val3=GRRLIB_GetPixelFromtexImg(x,y,texsrc); - val4=GRRLIB_GetPixelFromtexImg(x+val1,y+val2,texsrc); + else { + val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc); + val4 = GRRLIB_GetPixelFromtexImg(val1, val2, texsrc); GRRLIB_SetPixelTotexImg(x, y, texdest, val4); - GRRLIB_SetPixelTotexImg(x+val1, y+val2, texdest, val3); + GRRLIB_SetPixelTotexImg(val1, val2, texdest, val3); } } } diff --git a/template/source/main.c b/template/source/main.c index f46d241..1754945 100644 --- a/template/source/main.c +++ b/template/source/main.c @@ -8,8 +8,8 @@ ============================================*/ #include "GRRLIB/GRRLIB.h" +#include // needed for gettime and ticks_to_millisecs #include - #include #include @@ -51,10 +51,12 @@ #define GRRLIB_WHITE 0xFFFFFFFF Mtx GXmodelView2D; +static u8 CalculateFrameRate(); int main() { int left = 0, top = 0, page = 0, frame = TILE_DOWN + 1; unsigned int wait = TILE_DELAY, direction = TILE_DOWN, direction_new = TILE_DOWN; + u8 FPS = 0; ir_t ir1; u32 wpaddown, wpadheld; @@ -87,8 +89,6 @@ int main() { GRRLIB_texImg tex_BMfont5 = GRRLIB_LoadTexturePNG(BMfont5); GRRLIB_InitTileSet(&tex_BMfont5, 8, 16, 0); - - while(1) { WPAD_SetVRes(0, 640, 480); WPAD_ScanPads(); @@ -163,7 +163,9 @@ int main() { GRRLIB_Printf(left, top+350, tex_BMfont3, 0XFFFFFF50, 1, "TEXT WITH ALPHA"); GRRLIB_Printf(left, top+400, tex_BMfont5, GRRLIB_LIME, 1, "This font has the 128 ASCII characters"); } + GRRLIB_Printf(500, 27, tex_BMfont5, GRRLIB_WHITE, 1, "Current FPS: %d", FPS); GRRLIB_Render(); + FPS = CalculateFrameRate(); if(wpaddown & WPAD_BUTTON_HOME) { exit(0); @@ -221,3 +223,22 @@ int main() { free(tex_BMfont5.data); return 0; } + +/** + * This function calculates the number of frames we render each second. + * @return The number of frames per second. + */ +static u8 CalculateFrameRate() { + static u8 frameCount = 0; + static u32 lastTime; + static u8 FPS = 0; + u32 currentTime = ticks_to_millisecs(gettime()); + + frameCount++; + if(currentTime - lastTime > 1000) { + lastTime = currentTime; + FPS = frameCount; + frameCount = 0; + } + return FPS; +}