Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaked VDP_showFPS(), VDP_showCPULoad(), BMP_showFPS(), Added VDP_drawTextBGFill() #373

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion inc/bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,12 @@ void BMP_clearTextLine(u16 y);
*
* \param float_display
* If this value is true (!= 0) the frame rate is displayed as float (else it's integer).
* \param x
* X coordinate (in tile).
* \param y
* y coordinate (in tile).
*/
void BMP_showFPS(u16 float_display);
void BMP_showFPS(u16 float_display, u16 x, u16 y);

/**
* \brief
Expand Down
13 changes: 11 additions & 2 deletions inc/vdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1102,22 +1102,31 @@ u16 VDP_getAdjustedVCounter(void);
*
* \param asFloat
* Display in float number format.
* \param x
* X coordinate (in tile).
* \param y
* y coordinate (in tile).
*
* This function actually display the number of time it was called in the last second.<br>
* i.e: for benchmarking you should call this method only once per frame update.
*
* \see #SYS_getFPS(..)
*/
void VDP_showFPS(u16 asFloat);
void VDP_showFPS(u16 asFloat, u16 x, u16 y);
/**
* \brief
* Display the estimated CPU load (in %).
*
* \param x
* X coordinate (in tile).
* \param y
* y coordinate (in tile).
*
* This function actually display an estimation of the CPU load (in %) for the last frame.
*
* \see #SYS_getCPULoad()
*/
void VDP_showCPULoad(void);
void VDP_showCPULoad(u16 x, u16 y);


#endif // _VDP_H_
30 changes: 30 additions & 0 deletions inc/vdp_bg.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,36 @@ void VDP_clearTextLineBG(VDPPlane plane, u16 y);
*/
void VDP_drawText(const char* str, u16 x, u16 y);

/**
* \brief
* Draw text in specified plane and clear remaining unused space.<br>
* If the new line is shorter than the one previously drawn in this place, the old characters will be removed.<br>
* This function works significantly faster than calling VDP_clearText() and then VDP_drawText().
* It is suitable when a lot of updating information needs to be displayed on the screen.
*
* \param plane
* Plane where we want to draw text.<br>
* Accepted values are:<br>
* - BG_A<br>
* - BG_B<br>
* - WINDOW<br>
* \param str
* String to draw. For correct operation, it must not exceed 40 characters.
* \param x
* X position (in tile).
* \param y
* y position (in tile).
* \param len
* Fixed string length. For correct operation, it must not exceed 40 characters.
*
* \see VDP_drawText(..)
* \see VDP_clearText(..)
* \see VDP_setTextPalette(..)
* \see VDP_setTextPriority(..)
* \see VDP_setTextPlane(..)
*/
void VDP_drawTextBGFill(VDPPlane plane, const char* str, u16 x, u16 y, u16 len);

/**
* \brief
* Draw text and clear remaining unused space.<br>
Expand Down
4 changes: 2 additions & 2 deletions sample/benchmark/src/bmp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ u16 executeBMPTest(u16 *scores)
end = getTimeAsFix32(FALSE);
time += end - start;
j += j >> 5;
BMP_showFPS(FALSE);
BMP_showFPS(FALSE, 1, 1);
BMP_flip(FALSE);
}
for(j = 127; j >= 32; j--)
Expand All @@ -671,7 +671,7 @@ u16 executeBMPTest(u16 *scores)
end = getTimeAsFix32(FALSE);
time += end - start;
j -= j >> 5;
BMP_showFPS(FALSE);
BMP_showFPS(FALSE, 1, 1);
BMP_flip(FALSE);
}
}
Expand Down
12 changes: 6 additions & 6 deletions sample/benchmark/src/spr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ static u16 executePartic(u16 time, u16 numPartic, u16 preloadedTiles, u16 reallo
// update sprites
SPR_update();

VDP_showFPS(FALSE);
VDP_showCPULoad();
VDP_showFPS(FALSE, 1, 1);
VDP_showCPULoad(1, 2);
SYS_doVBlankProcess();
cpuLoad = SYS_getCPULoad();

Expand Down Expand Up @@ -1181,8 +1181,8 @@ static u16 executeDonut(u16 time, u16 preloadedTiles)
// update sprites
SPR_update();

VDP_showFPS(FALSE);
VDP_showCPULoad();
VDP_showFPS(FALSE, 1, 1);
VDP_showCPULoad(1, 2);

SYS_doVBlankProcess();
cpuLoad = SYS_getCPULoad();
Expand Down Expand Up @@ -1310,8 +1310,8 @@ static u16 execute(u16 time, u16 numSpr)
// update sprites
SPR_update();

VDP_showFPS(FALSE);
VDP_showCPULoad();
VDP_showFPS(FALSE, 1, 1);
VDP_showCPULoad(1, 2);
SYS_doVBlankProcess();
cpuLoad = SYS_getCPULoad();

Expand Down
2 changes: 1 addition & 1 deletion sample/bitmap/cube 3D/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main()

// ensure previous flip buffer request has been started
// BMP_waitWhileFlipRequestPending();
BMP_showFPS(1);
BMP_showFPS(TRUE, 1, 1);

BMP_clear();

Expand Down
2 changes: 1 addition & 1 deletion sample/bitmap/partic/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int main(bool hard)
BMP_waitWhileFlipRequestPending();

// can now draw text
BMP_showFPS(0);
BMP_showFPS(FALSE, 1, 1);

// display particul number
intToStr(numpartic, str, 1);
Expand Down
2 changes: 1 addition & 1 deletion sample/demo/starfield-donut/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void fastStarFieldFX()
SPR_update();

// SYS_disableInts();
// VDP_showFPS(FALSE);
// VDP_showFPS(FALSE, 1, 1);
// SYS_enableInts();

//VDP_waitVSync();
Expand Down
2 changes: 1 addition & 1 deletion sample/snd/xgm-player/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ int main()
if (bgEnabled) updateBGScroll();

// SYS_disableInts();
// VDP_showFPS(FALSE);
// VDP_showFPS(FALSE, 1, 1);
// SYS_enableInts();

// VDP_setBackgroundColor(3);
Expand Down
13 changes: 6 additions & 7 deletions src/bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,23 @@ void BMP_clearTextLine(u16 y)
}


void BMP_showFPS(u16 float_display)
void BMP_showFPS(u16 float_display, u16 x, u16 y)
{
char str[16];
const u16 y = GET_YOFFSET + 1;
y = GET_YOFFSET + y;

if (float_display)
{
fix32ToStr(SYS_getFPSAsFloat(), str, 1);
VDP_clearTextBG(bmp_plan, 2, y, 5);
// display FPS
VDP_drawTextBGFill(bmp_plan, str, x, y, 4);
}
else
{
uintToStr(SYS_getFPS(), str, 1);
VDP_clearTextBG(bmp_plan, 2, y, 2);
// display FPS
VDP_drawTextBGFill(bmp_plan, str, x, y, 2);
}

// display FPS
VDP_drawTextBG(bmp_plan, str, 1, y);
}


Expand Down
18 changes: 8 additions & 10 deletions src/vdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,35 +993,33 @@ u16 VDP_getAdjustedVCounter()
}


void VDP_showFPS(u16 asFloat)
void VDP_showFPS(u16 asFloat, u16 x, u16 y)
{
char str[16];

if (asFloat)
{
fix32ToStr(SYS_getFPSAsFloat(), str, 1);
VDP_clearText(2, 1, 5);
// display FPS
VDP_drawTextFill(str, x, y, 4);
}
else
{
uintToStr(SYS_getFPS(), str, 1);
VDP_clearText(2, 1, 2);
// display FPS
VDP_drawTextFill(str, x, y, 2);
}

// display FPS
VDP_drawText(str, 1, 1);
}

void VDP_showCPULoad()
void VDP_showCPULoad(u16 x, u16 y)
{
char str[16];

uintToStr(SYS_getCPULoad(), str, 1);
strcat(str, "%");

VDP_clearText(2, 2, 4);
// display FPS
VDP_drawText(str, 1, 2);
// display CPU load
VDP_drawTextFill(str, x, y, 4);
}


Expand Down
9 changes: 7 additions & 2 deletions src/vdp_bg.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void VDP_drawText(const char* str, u16 x, u16 y)
VDP_drawTextBG(text_plan, str, x, y);
}

void VDP_drawTextFill(const char* str, u16 x, u16 y, u16 len)
void VDP_drawTextBGFill(VDPPlane plane, const char* str, u16 x, u16 y, u16 len)
{
char fixedStr[len + 1];
char* dst = fixedStr;
Expand All @@ -405,7 +405,12 @@ void VDP_drawTextFill(const char* str, u16 x, u16 y, u16 len)
// set back terminator char
*dst = '\0';

VDP_drawText(fixedStr, x, y);
VDP_drawTextBG(plane, fixedStr, x, y);
}

void VDP_drawTextFill(const char* str, u16 x, u16 y, u16 len)
{
VDP_drawTextBGFill(text_plan, str, x, y, len);
}

void VDP_clearText(u16 x, u16 y, u16 w)
Expand Down