Advertisement
theblackshibe

Untitled

May 26th, 2023
1,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Maid from "@rbxts/maid";
  2. import Roact from "@rbxts/roact";
  3. import Hooks from "@rbxts/roact-hooks";
  4. import { RunService } from "@rbxts/services";
  5. import { Timer } from "shared/class/Timer";
  6. import { viewProps } from "../router/types";
  7. import { STYLE_TEXT_BODY } from "../util/ui_style";
  8.  
  9. const FpsCounter: Hooks.FC<viewProps> = ({ client_settings }, { useValue, useEffect }): Roact.Element => {
  10.     let temp_avg_fps = useValue(0);
  11.     let fps = Roact.createBinding(1 / temp_avg_fps.value);
  12.     let avg_fps = Roact.createBinding(temp_avg_fps.value);
  13.     let visible = Roact.createBinding(client_settings.user_reflection.client_fps_counter.value);
  14.  
  15.     useEffect(() => {
  16.         let maid = new Maid();
  17.         let fps_avg_check_time = tick() + 1;
  18.  
  19.         maid.GiveTask(
  20.             RunService.RenderStepped.Connect((delta_time) => {
  21.                 fps[1](1 / delta_time);
  22.                 temp_avg_fps.value += 1;
  23.                 if (tick() > fps_avg_check_time) {
  24.                     fps_avg_check_time = tick() + 1;
  25.                     avg_fps[1](temp_avg_fps.value);
  26.                     temp_avg_fps.value = 0;
  27.                 }
  28.             })
  29.         );
  30.  
  31.         maid.GiveTask(
  32.             client_settings.user_reflection.client_fps_counter.changed.Connect((value) => {
  33.                 visible[1](value);
  34.             })
  35.         );
  36.  
  37.         return () => maid.DoCleaning();
  38.     });
  39.  
  40.     return (
  41.         <frame
  42.             AutomaticSize={"XY"}
  43.             BackgroundTransparency={1}
  44.             AnchorPoint={new Vector2(1, 0)}
  45.             Position={new UDim2(1, -10, 0, 10)}
  46.             Visible={visible[0]}
  47.             ZIndex={1000}
  48.         >
  49.             <uilistlayout HorizontalAlignment={"Right"} />
  50.             <textlabel
  51.                 {...STYLE_TEXT_BODY}
  52.                 BackgroundTransparency={1}
  53.                 AutomaticSize={"X"}
  54.                 TextXAlignment={"Left"}
  55.                 Size={new UDim2(0, 0, 0, 14)}
  56.                 TextColor3={new Color3(0.35, 1, 0.35)}
  57.                 Text={fps[0].map((value) => `fps: ${tostring(math.floor(value))}`)}
  58.             />
  59.             <textlabel
  60.                 {...STYLE_TEXT_BODY}
  61.                 BackgroundTransparency={1}
  62.                 AutomaticSize={"X"}
  63.                 TextXAlignment={"Left"}
  64.                 Size={new UDim2(0, 0, 0, 14)}
  65.                 TextColor3={new Color3(0.35, 1, 0.35)}
  66.                 Text={avg_fps[0].map((value) => `avg. fps: ${tostring(math.floor(value))}`)}
  67.             />
  68.         </frame>
  69.     );
  70. };
  71.  
  72. export = new Hooks(Roact)(FpsCounter);
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement