Skip to content

Commit d37bff8

Browse files
committed
feat: fps display
Signed-off-by: Lessica <82flex@gmail.com>
1 parent 2744f8f commit d37bff8

15 files changed

Lines changed: 237 additions & 46 deletions

Resources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundlePackageType</key>
2222
<string>APPL</string>
2323
<key>CFBundleShortVersionString</key>
24-
<string>1.12.1</string>
24+
<string>2.0</string>
2525
<key>CFBundleSignature</key>
2626
<string>????</string>
2727
<key>CFBundleURLTypes</key>

Resources/en.lproj/Localizable.strings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@
7373
/* No comment provided by engineer. */
7474
"Dismiss" = "Dismiss";
7575

76+
/* No comment provided by engineer. */
77+
"Display Mode" = "Display Mode";
78+
7679
/* No comment provided by engineer. */
7780
"Exit HUD" = "Exit HUD";
7881

7982
/* No comment provided by engineer. */
8083
"Follow" = "Follow";
8184

85+
/* No comment provided by engineer. */
86+
"FPS" = "FPS";
87+
8288
/* No comment provided by engineer. */
8389
"Hide" = "Hide";
8490

@@ -133,6 +139,9 @@
133139
/* No comment provided by engineer. */
134140
"Size" = "Size";
135141

142+
/* No comment provided by engineer. */
143+
"Speed" = "Speed";
144+
136145
/* No comment provided by engineer. */
137146
"Standard" = "Standard";
138147

Resources/es.lproj/Localizable.strings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@
7373
/* No comment provided by engineer. */
7474
"Dismiss" = "Descartar";
7575

76+
/* No comment provided by engineer. */
77+
"Display Mode" = "Modo de pantalla";
78+
7679
/* No comment provided by engineer. */
7780
"Exit HUD" = "Cerrar HUD";
7881

7982
/* No comment provided by engineer. */
8083
"Follow" = "Habilitado";
8184

85+
/* No comment provided by engineer. */
86+
"FPS" = "FPS";
87+
8288
/* No comment provided by engineer. */
8389
"Hide" = "Oculto";
8490

@@ -133,6 +139,9 @@
133139
/* No comment provided by engineer. */
134140
"Size" = "Tamaño";
135141

142+
/* No comment provided by engineer. */
143+
"Speed" = "Velocidad";
144+
136145
/* No comment provided by engineer. */
137146
"Standard" = "Estándar";
138147

Resources/zh-Hans.lproj/Localizable.strings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@
7373
/* No comment provided by engineer. */
7474
"Dismiss" = "关闭";
7575

76+
/* No comment provided by engineer. */
77+
"Display Mode" = "显示模式";
78+
7679
/* No comment provided by engineer. */
7780
"Exit HUD" = "关闭悬浮窗";
7881

7982
/* No comment provided by engineer. */
8083
"Follow" = "跟随";
8184

85+
/* No comment provided by engineer. */
86+
"FPS" = "FPS";
87+
8288
/* No comment provided by engineer. */
8389
"Hide" = "隐藏";
8490

@@ -133,6 +139,9 @@
133139
/* No comment provided by engineer. */
134140
"Size" = "尺寸";
135141

142+
/* No comment provided by engineer. */
143+
"Speed" = "网速";
144+
136145
/* No comment provided by engineer. */
137146
"Standard" = "标准";
138147

TrollSpeed.xcodeproj/project.pbxproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@
642642
CODE_SIGN_ENTITLEMENTS = supports/entitlements.plist;
643643
CODE_SIGN_IDENTITY = "-";
644644
CODE_SIGN_STYLE = Manual;
645+
CURRENT_PROJECT_VERSION = 13;
645646
DEVELOPMENT_TEAM = "-";
646647
GCC_PRECOMPILE_PREFIX_HEADER = YES;
647648
GCC_PREFIX_HEADER = "supports/hudapp-prefix.pch";
@@ -663,7 +664,7 @@
663664
"$(inherited)",
664665
"$(PROJECT_DIR)/libraries",
665666
);
666-
MARKETING_VERSION = 1.12.1;
667+
MARKETING_VERSION = 2.0;
667668
PRODUCT_BUNDLE_IDENTIFIER = ch.xxtou.hudapp;
668669
PRODUCT_NAME = TrollSpeed;
669670
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -686,6 +687,7 @@
686687
CODE_SIGN_ENTITLEMENTS = supports/entitlements.plist;
687688
CODE_SIGN_IDENTITY = "-";
688689
CODE_SIGN_STYLE = Manual;
690+
CURRENT_PROJECT_VERSION = 13;
689691
DEVELOPMENT_TEAM = "-";
690692
GCC_PRECOMPILE_PREFIX_HEADER = YES;
691693
GCC_PREFIX_HEADER = "supports/hudapp-prefix.pch";
@@ -707,7 +709,7 @@
707709
"$(inherited)",
708710
"$(PROJECT_DIR)/libraries",
709711
);
710-
MARKETING_VERSION = 1.12.1;
712+
MARKETING_VERSION = 2.0;
711713
PRODUCT_BUNDLE_IDENTIFIER = ch.xxtou.hudapp;
712714
PRODUCT_NAME = TrollSpeed;
713715
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -779,7 +781,7 @@
779781
HEADER_SEARCH_PATHS = $THEOS/vendor/include;
780782
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
781783
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
782-
MARKETING_VERSION = 1.12.1;
784+
MARKETING_VERSION = 2.0;
783785
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
784786
MTL_FAST_MATH = YES;
785787
ONLY_ACTIVE_ARCH = YES;
@@ -841,7 +843,7 @@
841843
HEADER_SEARCH_PATHS = $THEOS/vendor/include;
842844
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
843845
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
844-
MARKETING_VERSION = 1.12.1;
846+
MARKETING_VERSION = 2.0;
845847
MTL_ENABLE_DEBUG_INFO = NO;
846848
MTL_FAST_MATH = YES;
847849
PRODUCT_MODULE_NAME = TrollSpeed;
@@ -862,6 +864,7 @@
862864
CODE_SIGN_ENTITLEMENTS = supports/entitlements.plist;
863865
CODE_SIGN_IDENTITY = "-";
864866
CODE_SIGN_STYLE = Manual;
867+
CURRENT_PROJECT_VERSION = 13;
865868
DEVELOPMENT_TEAM = "-";
866869
GCC_PRECOMPILE_PREFIX_HEADER = YES;
867870
GCC_PREFIX_HEADER = "supports/hudapp-prefix.pch";
@@ -883,7 +886,7 @@
883886
"$(inherited)",
884887
"$(PROJECT_DIR)/libraries",
885888
);
886-
MARKETING_VERSION = 1.12.1;
889+
MARKETING_VERSION = 2.0;
887890
PRODUCT_BUNDLE_IDENTIFIER = ch.xxtou.hudapp;
888891
PRODUCT_NAME = TrollSpeed;
889892
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -907,6 +910,7 @@
907910
CODE_SIGN_ENTITLEMENTS = supports/entitlements.plist;
908911
CODE_SIGN_IDENTITY = "-";
909912
CODE_SIGN_STYLE = Manual;
913+
CURRENT_PROJECT_VERSION = 13;
910914
DEVELOPMENT_TEAM = "-";
911915
GCC_PRECOMPILE_PREFIX_HEADER = YES;
912916
GCC_PREFIX_HEADER = "supports/hudapp-prefix.pch";
@@ -928,7 +932,7 @@
928932
"$(inherited)",
929933
"$(PROJECT_DIR)/libraries",
930934
);
931-
MARKETING_VERSION = 1.12.1;
935+
MARKETING_VERSION = 2.0;
932936
PRODUCT_BUNDLE_IDENTIFIER = ch.xxtou.hudapp;
933937
PRODUCT_NAME = TrollSpeed;
934938
PROVISIONING_PROFILE_SPECIFIER = "";

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ VERSION=${VERSION#v}
1515
xcodebuild clean build archive \
1616
-scheme TrollSpeed \
1717
-project TrollSpeed.xcodeproj \
18+
-configuration Release \
1819
-sdk iphoneos \
1920
-destination 'generic/platform=iOS' \
2021
-archivePath TrollSpeed \

layout/DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ch.xxtou.hudapp.jb
22
Name: TrollSpeed JB
3-
Version: 1.12.1
3+
Version: 2.0-13
44
Section: Tweaks
55
Depends: firmware (>= 14.0)
66
Architecture: iphoneos-arm

sources/HUDRootViewController.mm

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
#import "HUDBackdropLabel.h"
1818
#import "TrollSpeed-Swift.h"
1919

20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
CFIndex CARenderServerGetDirtyFrameCount(void *);
24+
#ifdef __cplusplus
25+
}
26+
#endif
27+
2028
#pragma mark -
2129

2230
#import "FBSOrientationUpdate.h"
@@ -29,6 +37,9 @@
2937
#define NOTIFY_UI_LOCKSTATE "com.apple.springboard.lockstate"
3038
#define NOTIFY_LS_APP_CHANGED "com.apple.LaunchServices.ApplicationsChanged"
3139

40+
static BOOL needsBaselineReset = YES;
41+
static BOOL needsFPSBaselineReset = YES;
42+
3243
static void LaunchServicesApplicationStateChanged
3344
(CFNotificationCenterRef center,
3445
void *observer,
@@ -78,6 +89,8 @@
7889

7990
if (!isLocked)
8091
{
92+
needsBaselineReset = YES;
93+
needsFPSBaselineReset = YES;
8194
[rootViewController.view setHidden:NO];
8295
[rootViewController resetLoopTimer];
8396
}
@@ -116,6 +129,7 @@
116129
static uint8_t HUD_SHOW_SECOND_SPEED_IN_NEW_LINE = 0;
117130
static const char *HUD_UPLOAD_PREFIX = "";
118131
static const char *HUD_DOWNLOAD_PREFIX = "";
132+
static uint8_t HUD_DISPLAY_MODE = 0; // 0=Speed, 1=FPS
119133

120134
typedef struct {
121135
uint64_t inputBytes;
@@ -310,6 +324,7 @@ static UpDownBytes getUpDownBytes()
310324

311325
static BOOL shouldUpdateSpeedLabel;
312326
static uint64_t prevOutputBytes = 0, prevInputBytes = 0;
327+
static CFIndex prevDirtyFrameCount = 0;
313328
static NSAttributedString *attributedUploadPrefix = nil;
314329
static NSAttributedString *attributedDownloadPrefix = nil;
315330
static NSAttributedString *attributedInlineSeparator = nil;
@@ -335,6 +350,15 @@ static UpDownBytes getUpDownBytes()
335350
uint64_t upDiff;
336351
uint64_t downDiff;
337352

353+
if (needsBaselineReset && !isFocused)
354+
{
355+
prevOutputBytes = upDownBytes.outputBytes;
356+
prevInputBytes = upDownBytes.inputBytes;
357+
needsBaselineReset = NO;
358+
shouldUpdateSpeedLabel = NO;
359+
return nil;
360+
}
361+
338362
if (isFocused)
339363
{
340364
upDiff = upDownBytes.outputBytes;
@@ -413,6 +437,44 @@ static UpDownBytes getUpDownBytes()
413437
}
414438
}
415439

440+
static NSAttributedString *formattedFPSAttributedString(BOOL isFocused)
441+
{
442+
@autoreleasepool
443+
{
444+
CFIndex dirtyFrameCount = CARenderServerGetDirtyFrameCount(NULL);
445+
446+
if (needsFPSBaselineReset)
447+
{
448+
prevDirtyFrameCount = dirtyFrameCount;
449+
needsFPSBaselineReset = NO;
450+
shouldUpdateSpeedLabel = YES;
451+
452+
NSString *fpsString = @"0 FPS";
453+
return [[NSAttributedString alloc] initWithString:fpsString attributes:@{
454+
NSFontAttributeName: [UIFont monospacedDigitSystemFontOfSize:HUD_FONT_SIZE weight:HUD_FONT_WEIGHT]
455+
}];
456+
}
457+
458+
CFIndex frameDiff = dirtyFrameCount - prevDirtyFrameCount;
459+
prevDirtyFrameCount = dirtyFrameCount;
460+
461+
if (frameDiff < 0) frameDiff = 0;
462+
463+
double fps = (double)frameDiff / UPDATE_INTERVAL;
464+
double maxFPS = (double)[UIScreen mainScreen].maximumFramesPerSecond;
465+
if (fps > maxFPS) fps = maxFPS;
466+
467+
shouldUpdateSpeedLabel = YES;
468+
469+
NSString *fpsString = [NSString stringWithFormat:@"%.0f FPS", fps];
470+
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:fpsString attributes:@{
471+
NSFontAttributeName: [UIFont monospacedDigitSystemFontOfSize:HUD_FONT_SIZE weight:HUD_FONT_WEIGHT]
472+
}];
473+
474+
return attributedString;
475+
}
476+
}
477+
416478
#pragma mark - HUDRootViewController
417479

418480
@interface HUDRootViewController (Troll)
@@ -548,8 +610,14 @@ - (void)reloadUserDefaults
548610
[_containerView setupContainerAsDisplayContentInScreenshots];
549611
}
550612

613+
BOOL displayMode = [self displayMode];
614+
HUD_DISPLAY_MODE = displayMode;
615+
551616
prevInputBytes = 0;
552617
prevOutputBytes = 0;
618+
needsBaselineReset = YES;
619+
prevDirtyFrameCount = 0;
620+
needsFPSBaselineReset = YES;
553621
attributedUploadPrefix = nil;
554622
attributedDownloadPrefix = nil;
555623

@@ -601,6 +669,13 @@ - (BOOL)singleLineMode
601669
return mode != nil ? [mode boolValue] : NO;
602670
}
603671

672+
- (BOOL)displayMode
673+
{
674+
[self loadUserDefaults:NO];
675+
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyDisplayMode];
676+
return mode != nil ? [mode boolValue] : NO;
677+
}
678+
604679
- (BOOL)usesBitrate
605680
{
606681
[self loadUserDefaults:NO];
@@ -759,7 +834,12 @@ - (void)dealloc
759834
- (void)updateSpeedLabel
760835
{
761836
log_debug(OS_LOG_DEFAULT, "updateSpeedLabel");
762-
NSAttributedString *attributedText = formattedAttributedString(_isFocused);
837+
NSAttributedString *attributedText;
838+
if (HUD_DISPLAY_MODE == 1) {
839+
attributedText = formattedFPSAttributedString(_isFocused);
840+
} else {
841+
attributedText = formattedAttributedString(_isFocused);
842+
}
763843
if (attributedText) {
764844
[_speedLabel setAttributedText:attributedText];
765845
}

sources/RootViewController.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,20 @@ - (void)setHideAtSnapshot:(BOOL)hideAtSnapshot
505505
[self saveUserDefaults];
506506
}
507507

508+
- (BOOL)displayMode
509+
{
510+
[self loadUserDefaults:NO];
511+
NSNumber *mode = [_userDefaults objectForKey:HUDUserDefaultsKeyDisplayMode];
512+
return mode != nil ? [mode boolValue] : NO;
513+
}
514+
515+
- (void)setDisplayMode:(BOOL)displayMode
516+
{
517+
[self loadUserDefaults:NO];
518+
[_userDefaults setObject:@(displayMode) forKey:HUDUserDefaultsKeyDisplayMode];
519+
[self saveUserDefaults];
520+
}
521+
508522
- (void)reloadMainButtonState
509523
{
510524
_isRemoteHUDActive = [self isHUDEnabled];

0 commit comments

Comments
 (0)