mirror of
https://github.com/HarbourMasters/Starship.git
synced 2025-02-02 16:23:57 +03:00
MOD: FPS COUNTER (#216)
* progress * working * move to Play_Draw * remove mods.h include from fox_hud * fix name * __floatundisf needed by GCC * Improve level select * __floatundisf in yaml for GCC * jump directly to level loading in Map_LevelSelect * comments * fix level select * AVOID_UB in audio * stable flags * fix UB in AudioHeap_DiscardSampleCaches co-authored-by: @petrie911 * fox_map fix * move frame counter a few pixels to the right * format * add measurement correction for overclocked N64s
This commit is contained in:
parent
7969da8a9d
commit
1272524325
22
Makefile
22
Makefile
@ -87,7 +87,7 @@ endif
|
|||||||
|
|
||||||
# ditch g3, we aren't using that in GCC
|
# ditch g3, we aren't using that in GCC
|
||||||
ifeq ($(COMPILER),gcc)
|
ifeq ($(COMPILER),gcc)
|
||||||
OPTFLAGS := -Os
|
OPTFLAGS := -Ofast
|
||||||
else
|
else
|
||||||
OPTFLAGS := -O2 -g3
|
OPTFLAGS := -O2 -g3
|
||||||
endif
|
endif
|
||||||
@ -339,12 +339,18 @@ build/src/libultra/os/%.o: OPTFLAGS := -Os
|
|||||||
build/src/libultra/rmon/%.o: OPTFLAGS := -Os
|
build/src/libultra/rmon/%.o: OPTFLAGS := -Os
|
||||||
build/src/libultra/debug/%.o: OPTFLAGS := -Os
|
build/src/libultra/debug/%.o: OPTFLAGS := -Os
|
||||||
build/src/libultra/host/%.o: OPTFLAGS := -Os
|
build/src/libultra/host/%.o: OPTFLAGS := -Os
|
||||||
build/src/audio/audio_load.o: OPTFLAGS := -O2
|
|
||||||
build/src/audio/%.o: OPTFLAGS := -O2 -g
|
|
||||||
|
|
||||||
# per-file flags
|
# per-file flags
|
||||||
build/src/libc_sprintf.o: OPTFLAGS := -Os
|
build/src/audio/audio_load.o: OPTFLAGS := -Os
|
||||||
build/src/libc_math64.o: OPTFLAGS := -Os
|
build/src/audio/audio_heap.o: OPTFLAGS := -Os
|
||||||
|
build/src/audio/audio_effects.o: OPTFLAGS := -Os
|
||||||
|
build/src/audio/audio_general.o: OPTFLAGS := -Os
|
||||||
|
build/src/audio/audio_playback.o: OPTFLAGS := -Os
|
||||||
|
build/src/audio/audio_seqplayer.o: OPTFLAGS := -Os
|
||||||
|
build/src/audio/audio_thread.o: OPTFLAGS := -Os
|
||||||
|
|
||||||
|
build/src/libc_sprintf.o: OPTFLAGS := -Ofast
|
||||||
|
build/src/libc_math64.o: OPTFLAGS := -Ofast
|
||||||
|
|
||||||
build/src/libultra/libc/ldiv.o: OPTFLAGS := -Os
|
build/src/libultra/libc/ldiv.o: OPTFLAGS := -Os
|
||||||
build/src/libultra/libc/string.o: OPTFLAGS := -Os
|
build/src/libultra/libc/string.o: OPTFLAGS := -Os
|
||||||
@ -355,10 +361,10 @@ build/src/libultra/libc/ll.o: OPTFLAGS := -O2
|
|||||||
build/src/libultra/libc/ll.o: MIPS_VERSION := -mips3
|
build/src/libultra/libc/ll.o: MIPS_VERSION := -mips3
|
||||||
|
|
||||||
# cc & asm-processor
|
# cc & asm-processor
|
||||||
build/src/libultra/gu/sqrtf.o: OPTFLAGS := -Os
|
build/src/libultra/gu/sqrtf.o: OPTFLAGS := -Ofast
|
||||||
build/src/libultra/gu/sinf.o: OPTFLAGS := -Os
|
build/src/libultra/gu/sinf.o: OPTFLAGS := -Ofast
|
||||||
build/src/libultra/gu/lookat.o: OPTFLAGS := -Os
|
build/src/libultra/gu/lookat.o: OPTFLAGS := -Os
|
||||||
build/src/libultra/gu/ortho.o: OPTFLAGS := -Os
|
build/src/libultra/gu/ortho.o: OPTFLAGS := -Os
|
||||||
build/src/libultra/gu/perspective.o: OPTFLAGS := -Os
|
build/src/libultra/gu/perspective.o: OPTFLAGS := -Os
|
||||||
build/src/libultra/gu/mtxutil.o: OPTFLAGS := -Os
|
build/src/libultra/gu/mtxutil.o: OPTFLAGS := -Os
|
||||||
build/src/libultra/gu/cosf.o: OPTFLAGS := -Os
|
build/src/libultra/gu/cosf.o: OPTFLAGS := -Os
|
||||||
|
@ -8,17 +8,27 @@
|
|||||||
*/
|
*/
|
||||||
#define MODS_LEVEL_SELECT 0
|
#define MODS_LEVEL_SELECT 0
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sound Effects Jukebox:
|
* Sound Effects Jukebox:
|
||||||
* Ability to play sound effects inside the expert sound menu
|
* Ability to play sound effects inside the expert sound menu
|
||||||
*/
|
*/
|
||||||
#define MODS_SFX_JUKEBOX 0
|
#define MODS_SFX_JUKEBOX 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FPS Counter:
|
||||||
|
* Press L to toggle FPS Display
|
||||||
|
*/
|
||||||
|
#define MODS_FPS_COUNTER 0
|
||||||
|
|
||||||
|
|
||||||
/* ************************* */
|
/* ************************* */
|
||||||
|
|
||||||
#if MODS_LEVEL_SELECT == 1
|
#if MODS_LEVEL_SELECT == 1
|
||||||
void Map_LevelSelect(void);
|
void Map_LevelSelect(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MODS_FPS_COUNTER == 1
|
||||||
|
static void Play_RenderFps(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -688,7 +688,6 @@ void Audio_SetSfxProperties(u8 bankId, u8 entryIndex, u8 channelId) {
|
|||||||
sSfxChannelState[channelId].pan = pan;
|
sSfxChannelState[channelId].pan = pan;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 Audio_UpdateDopplerShift(f32* srcPos, f32* srcVel, f32 soundSpeed, f32* curDopplerShift) {
|
f32 Audio_UpdateDopplerShift(f32* srcPos, f32* srcVel, f32 soundSpeed, f32* curDopplerShift) {
|
||||||
f32 xVel;
|
f32 xVel;
|
||||||
f32 zVel;
|
f32 zVel;
|
||||||
@ -704,6 +703,12 @@ f32 Audio_UpdateDopplerShift(f32* srcPos, f32* srcVel, f32 soundSpeed, f32* curD
|
|||||||
f32 targetDopplerShift;
|
f32 targetDopplerShift;
|
||||||
s32 pad;
|
s32 pad;
|
||||||
|
|
||||||
|
#ifdef AVOID_UB
|
||||||
|
if ((srcPos == NULL) || (srcVel == NULL) || (curDopplerShift == NULL)) {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
xPos = srcPos[0];
|
xPos = srcPos[0];
|
||||||
zPos = srcPos[2];
|
zPos = srcPos[2];
|
||||||
xVel = srcVel[0];
|
xVel = srcVel[0];
|
||||||
@ -2215,7 +2220,11 @@ void Audio_UpdateBlueMarineNoise(u8 playerId) {
|
|||||||
void Audio_UpdatePlayerFreqMod(void) {
|
void Audio_UpdatePlayerFreqMod(void) {
|
||||||
u8 playerId;
|
u8 playerId;
|
||||||
|
|
||||||
|
#ifdef AVOID_UB
|
||||||
|
for (playerId = 0; playerId < gCamCount; playerId++) {
|
||||||
|
#else
|
||||||
for (playerId = 0; playerId < 4; playerId++) {
|
for (playerId = 0; playerId < 4; playerId++) {
|
||||||
|
#endif
|
||||||
switch (sPlayerNoise[playerId].form) {
|
switch (sPlayerNoise[playerId].form) {
|
||||||
case FORM_ARWING:
|
case FORM_ARWING:
|
||||||
Audio_UpdateArwingNoise(playerId);
|
Audio_UpdateArwingNoise(playerId);
|
||||||
|
@ -973,7 +973,7 @@ SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(u32 size) {
|
|||||||
void AudioHeap_DiscardSampleCaches(void) {
|
void AudioHeap_DiscardSampleCaches(void) {
|
||||||
s32 fontId;
|
s32 fontId;
|
||||||
s32 i;
|
s32 i;
|
||||||
s32 numFonts;
|
s32 numFonts = gSoundFontTable->numEntries;
|
||||||
s32 pad;
|
s32 pad;
|
||||||
s32 sampleBankId2;
|
s32 sampleBankId2;
|
||||||
s32 sampleBankId1;
|
s32 sampleBankId1;
|
||||||
@ -983,7 +983,10 @@ void AudioHeap_DiscardSampleCaches(void) {
|
|||||||
Instrument* instrument;
|
Instrument* instrument;
|
||||||
SampleCacheEntry* entry;
|
SampleCacheEntry* entry;
|
||||||
|
|
||||||
numFonts = gSoundFontTable->numEntries;
|
#ifdef AVOID_UB
|
||||||
|
entry = gPersistentSampleCache.entries;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (fontId = 0; fontId < numFonts; fontId++) {
|
for (fontId = 0; fontId < numFonts; fontId++) {
|
||||||
sampleBankId1 = gSoundFontList[fontId].sampleBankId1;
|
sampleBankId1 = gSoundFontList[fontId].sampleBankId1;
|
||||||
sampleBankId2 = gSoundFontList[fontId].sampleBankId2;
|
sampleBankId2 = gSoundFontList[fontId].sampleBankId2;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "mods.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "assets/ast_arwing.h"
|
#include "assets/ast_arwing.h"
|
||||||
#include "assets/ast_allies.h"
|
#include "assets/ast_allies.h"
|
||||||
@ -1722,4 +1723,11 @@ void Play_Draw(void) {
|
|||||||
func_display_80051B30();
|
func_display_80051B30();
|
||||||
sPlayersVisible[gPlayerNum] = 0;
|
sPlayersVisible[gPlayerNum] = 0;
|
||||||
Matrix_Pop(&gGfxMatrix);
|
Matrix_Pop(&gGfxMatrix);
|
||||||
|
#if MODS_FPS_COUNTER == 1
|
||||||
|
Play_RenderFps();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MODS_FPS_COUNTER == 1
|
||||||
|
#include "../mods/fpscounter.c"
|
||||||
|
#endif
|
||||||
|
27
src/libultra/gcc_fix/__floatundisf.c
Normal file
27
src/libultra/gcc_fix/__floatundisf.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifdef COMPILER_GCC
|
||||||
|
|
||||||
|
typedef union DoubleFloatUnion {
|
||||||
|
double d;
|
||||||
|
long long int ll;
|
||||||
|
unsigned long long ull;
|
||||||
|
} DoubleFloatUnion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets float32 from uint64_t.
|
||||||
|
*
|
||||||
|
* https://gcc.gnu.org/onlinedocs/gccint/the-gcc-low-level-runtime-library/routines-for-floating-point-emulation.html#c.__floatundisf
|
||||||
|
*/
|
||||||
|
float __floatundisf(unsigned long long i) {
|
||||||
|
register DoubleFloatUnion dull;
|
||||||
|
register float ret;
|
||||||
|
|
||||||
|
dull.ull = i;
|
||||||
|
__asm__("cvt.s.l %0, %1" : "=f"(ret) : "f"(dull.d));
|
||||||
|
if ((long) i < 0) {
|
||||||
|
// cvt.s.l assumes signed input, adjust output
|
||||||
|
ret += 4294967296.0f; // 2^32
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "mods.h"
|
||||||
|
|
||||||
long long __ull_rshift(unsigned long long left, unsigned long long right) {
|
long long __ull_rshift(unsigned long long left, unsigned long long right) {
|
||||||
return left >> right;
|
return left >> right;
|
||||||
@ -44,3 +45,10 @@ long long __ll_mod(long long left, long long right) {
|
|||||||
long long __ll_rshift(long long left, long long right) {
|
long long __ll_rshift(long long left, long long right) {
|
||||||
return left >> right;
|
return left >> right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IDO FIX
|
||||||
|
#if MODS_FPS_COUNTER == 1
|
||||||
|
float __ull_to_f(unsigned long long u) {
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
47
src/mods/fpscounter.c
Normal file
47
src/mods/fpscounter.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
// SDK states that 1 cycle takes about 21.33 nanoseconds
|
||||||
|
#if 1
|
||||||
|
#define SECONDS_PER_CYCLE 0.00000002133f
|
||||||
|
#else
|
||||||
|
// Use this macro if your N64 CPU is overclocked to 125 Mhz (x2 Multiplier)
|
||||||
|
#define SECONDS_PER_CYCLE 0.000000016f
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define FPS_COUNTER_X_POS 14
|
||||||
|
#define FPS_COUNTER_Y_POS 9
|
||||||
|
|
||||||
|
static OSTime gLastOSTime = 0;
|
||||||
|
static float gFrameTime = 0.0f;
|
||||||
|
static u16 gFrames = 0;
|
||||||
|
static u16 gFPS = 0;
|
||||||
|
static u8 gRenderFPS = false;
|
||||||
|
|
||||||
|
static void CalculateFrameTimeFromOSTime(OSTime diff) {
|
||||||
|
gFrameTime += diff * SECONDS_PER_CYCLE;
|
||||||
|
gFrames++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Play_RenderFps(void) {
|
||||||
|
// Toggle rendering framerate with the L button.
|
||||||
|
if (gControllerPress[0].button & L_TRIG) {
|
||||||
|
gRenderFPS ^= 1;
|
||||||
|
}
|
||||||
|
if (gRenderFPS) {
|
||||||
|
OSTime newTime = osGetTime();
|
||||||
|
CalculateFrameTimeFromOSTime(newTime - gLastOSTime);
|
||||||
|
// If frame time is longer or equal to a second, update FPS counter.
|
||||||
|
if (gFrameTime >= 1.0f) {
|
||||||
|
gFPS = gFrames;
|
||||||
|
gFrames = 0;
|
||||||
|
gFrameTime -= 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Draw */
|
||||||
|
RCP_SetupDL(&gMasterDisp, 0x53);
|
||||||
|
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255);
|
||||||
|
Graphics_DisplaySmallText(FPS_COUNTER_X_POS, FPS_COUNTER_Y_POS, 1.0f, 1.0f, "FPS:");
|
||||||
|
Graphics_DisplaySmallNumber(FPS_COUNTER_X_POS + 35, FPS_COUNTER_Y_POS, gFPS);
|
||||||
|
gLastOSTime = newTime;
|
||||||
|
}
|
||||||
|
}
|
@ -3,13 +3,18 @@
|
|||||||
|
|
||||||
extern PlanetId sPlanetList[15];
|
extern PlanetId sPlanetList[15];
|
||||||
extern PlanetId sCurrentPlanetId;
|
extern PlanetId sCurrentPlanetId;
|
||||||
|
extern s32 D_menu_801B8280;
|
||||||
|
extern s32 D_menu_801CD968;
|
||||||
|
|
||||||
|
void Map_801A61B4(LevelId level);
|
||||||
void Map_801A6368(void);
|
void Map_801A6368(void);
|
||||||
void Map_801A914C(void);
|
void Map_801A914C(void);
|
||||||
|
void Map_801A6628(void);
|
||||||
|
|
||||||
void Map_LevelSelect(void) {
|
void Map_LevelSelect(void) {
|
||||||
static char* sLevelSelectPlanetNames[] = {
|
static char* sLevelSelectPlanetNames[] = {
|
||||||
"CORNERIA", "METEO", "TITANIA", "SECTOR X", "AQUAS", "BOLSE", "VENOM", "FORTUNA",
|
"METEO", "AREA 6", "BOLSE", "SECTOR Z", "SECTOR X", "SECTOR Y", "KATINA", "MACBETH",
|
||||||
"AREA 6", "MACBETH", "SECTOR Z", "ZONESS", "KATINA", "SECTOR Y", "SOLAR",
|
"ZONESS", "CORNERIA", "TITANIA", "AQUAS", "FORTUNA", "VENOM", "SOLAR",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (gControllerPress[0].button & L_JPAD) {
|
if (gControllerPress[0].button & L_JPAD) {
|
||||||
@ -33,10 +38,19 @@ void Map_LevelSelect(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
|
if ((sCurrentPlanetId >= 0) && (sCurrentPlanetId < PLANET_MAX)) {
|
||||||
|
RCP_SetupDL(&gMasterDisp, 0x53);
|
||||||
|
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255);
|
||||||
|
|
||||||
RCP_SetupDL(&gMasterDisp, 0x53);
|
Graphics_DisplaySmallText(20, 200, 1.0f, 1.0f, "PLANET:");
|
||||||
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255);
|
Graphics_DisplaySmallText(80, 200, 1.0f, 1.0f, sLevelSelectPlanetNames[sCurrentPlanetId]);
|
||||||
|
}
|
||||||
|
|
||||||
Graphics_DisplaySmallText(20, 200, 1.0f, 1.0f, "PLANET:");
|
// Bypass briefing
|
||||||
Graphics_DisplaySmallText(80, 200, 1.0f, 1.0f, sLevelSelectPlanetNames[gCurrentPlanet]);
|
if (gControllerPress[0].button & A_BUTTON) {
|
||||||
|
Map_801A61B4(gCurrentLevel);
|
||||||
|
D_menu_801B8280 = 0;
|
||||||
|
D_menu_801CD968 = 0;
|
||||||
|
Map_801A6628();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2539,7 +2539,7 @@ void Map_801A1C14(void) {
|
|||||||
D_menu_801CD964 = 1;
|
D_menu_801CD964 = 1;
|
||||||
D_menu_801CD96C = 1;
|
D_menu_801CD96C = 1;
|
||||||
// clang-format off
|
// clang-format off
|
||||||
for (i = 0; i < 15; i++) {D_menu_801CD900[i] = 0;}
|
for (i = 0; i < 15; i++) { D_menu_801CD900[i] = 0; }
|
||||||
// clang-format on
|
// clang-format on
|
||||||
D_menu_801CD970 = 0;
|
D_menu_801CD970 = 0;
|
||||||
|
|
||||||
@ -2557,7 +2557,7 @@ void Map_801A1C14(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Map_801A2304(void) {
|
bool Map_801A2304(void) {
|
||||||
s32 ret = false;
|
bool ret = false;
|
||||||
f32 sp28;
|
f32 sp28;
|
||||||
f32 sp24;
|
f32 sp24;
|
||||||
f32 sp20;
|
f32 sp20;
|
||||||
|
@ -47,6 +47,9 @@
|
|||||||
- [0x206B0, c, libc_math64]
|
- [0x206B0, c, libc_math64]
|
||||||
- [0x20A60, hasm, libc_math64_fp]
|
- [0x20A60, hasm, libc_math64_fp]
|
||||||
|
|
||||||
|
# GCC
|
||||||
|
- [auto, c, libultra/gcc_fix/__floatundisf]
|
||||||
|
|
||||||
# Libultra
|
# Libultra
|
||||||
- [0x20BC0, c, libultra/io/controller]
|
- [0x20BC0, c, libultra/io/controller]
|
||||||
- [0x20F80, c, libultra/io/contreaddata]
|
- [0x20F80, c, libultra/io/contreaddata]
|
||||||
|
Loading…
Reference in New Issue
Block a user