@@ -24,8 +24,8 @@ pub struct GuiState
2424 handle : HANDLE ,
2525 offset : u64 ,
2626
27- handle_timer : i8 ,
28- memory_read_timer : i8 ,
27+ update_timer : i8 ,
28+ timer_ticks : i8 ,
2929
3030 graph : Graph ,
3131 rank : u8 ,
@@ -38,6 +38,8 @@ struct Save
3838 window_size : ( u32 , u32 ) ,
3939 // window_pos: (u32, u32),
4040
41+ timer_ticks : i8 ,
42+
4143 //rank graph
4244 rank_window_pos : ( f32 , f32 ) ,
4345 rank_window_width : f32 ,
@@ -48,6 +50,27 @@ struct Save
4850 aspect : f32 ,
4951}
5052
53+ impl Default for Save
54+ {
55+ fn default ( ) -> Self
56+ {
57+ Self
58+ {
59+ window_size : ( 1024 , 768 ) ,
60+
61+ timer_ticks : 100 ,
62+
63+ rank_window_pos : ( 20.0 , 20.0 ) ,
64+ rank_window_width : 450.0 ,
65+ data_points : 240 ,
66+ color_r : ( 0 , 255 ) ,
67+ color_g : ( 255 , 0 ) ,
68+ color_b : ( 0 , 0 ) ,
69+ aspect : 3.7 ,
70+ }
71+ }
72+ }
73+
5174struct Graph
5275{
5376 default_window_pos : ( f32 , f32 ) ,
@@ -67,18 +90,7 @@ fn main()
6790 }
6891 else
6992 {
70- Save
71- {
72- window_size : ( 1024 , 768 ) ,
73-
74- rank_window_pos : ( 20.0 , 20.0 ) ,
75- rank_window_width : 450.0 ,
76- data_points : 240 ,
77- color_r : ( 0 , 255 ) ,
78- color_g : ( 255 , 0 ) ,
79- color_b : ( 0 , 0 ) ,
80- aspect : 3.7 ,
81- }
93+ Save :: default ( )
8294 } ;
8395
8496 let el = EventLoop :: new ( ) ;
@@ -93,8 +105,8 @@ fn main()
93105 handle : HANDLE :: default ( ) ,
94106 offset : 0 ,
95107
96- handle_timer : 0 ,
97- memory_read_timer : 0 ,
108+ update_timer : 0 ,
109+ timer_ticks : save . timer_ticks ,
98110
99111 graph : Graph
100112 {
@@ -116,22 +128,30 @@ fn main()
116128
117129 el. run ( move |event, _, control_flow|
118130 {
119- * control_flow = ControlFlow :: Poll ;
131+ * control_flow = ControlFlow :: WaitUntil ( std :: time :: Instant :: now ( ) + std :: time :: Duration :: from_millis ( 2 ) ) ;
120132
121133 egui_glutin:: event_handling ( event, control_flow, & mut egui_state, & gui_state) ;
122134
123135 let current_time = std:: time:: Instant :: now ( ) ;
124136 frame_time += current_time - last_time;
125137 last_time = current_time;
126138
127- while frame_time >= std:: time:: Duration :: from_micros ( 33333 )
139+ let time = 20000 ;
140+
141+ while frame_time >= std:: time:: Duration :: from_micros ( time)
128142 {
129- frame_time -= std:: time:: Duration :: from_micros ( 33333 ) ;
143+ frame_time -= std:: time:: Duration :: from_micros ( time ) ;
130144
131- match gui_state. current_game
145+ gui_state. update_timer -= 1 ;
146+ if gui_state. update_timer < 0
132147 {
133- Some ( _) => update ( & mut gui_state) ,
134- None => find_game ( & mut gui_state) ,
148+ gui_state. update_timer = gui_state. timer_ticks ;
149+
150+ match gui_state. current_game
151+ {
152+ Some ( _) => update ( & mut gui_state) ,
153+ None => find_game ( & mut gui_state) ,
154+ }
135155 }
136156
137157 egui_state. ctx . begin_frame ( egui_state. raw_input . take ( ) ) ;
@@ -156,13 +176,6 @@ fn main()
156176
157177fn find_game ( gui_state : & mut GuiState )
158178{
159- if gui_state. handle_timer > 0
160- {
161- gui_state. handle_timer -= 1 ;
162- return ;
163- }
164- gui_state. handle_timer = 30 ;
165-
166179 let mut emu_info = None ;
167180
168181 let ( pid_list, pid_count) = enum_processes ( ) ;
@@ -255,8 +268,6 @@ fn find_game(gui_state: &mut GuiState)
255268
256269fn get_game_name ( handle : & HANDLE , info : & MODULEINFO , emu : & game_data:: Emulator ) -> Option < game_data:: Games >
257270{
258- let mut raw_str = [ 0 ; 22 ] ;
259-
260271 let game_name_offset = match emu
261272 {
262273 game_data:: Emulator :: Bsnes => 0xB151E8 as * const c_void ,
@@ -269,6 +280,8 @@ fn get_game_name(handle: &HANDLE, info: &MODULEINFO, emu: &game_data::Emulator)
269280 }
270281 } ;
271282
283+ let mut raw_str = [ 0 ; 22 ] ;
284+
272285 unsafe
273286 {
274287 let p_raw_str = raw_str. as_mut_ptr ( ) as * mut _ as * mut c_void ;
@@ -321,13 +334,6 @@ fn get_mame_offset(handle: &HANDLE, dll_base: u64, offset_list: Vec<u64>) -> u64
321334
322335fn update ( gui_state : & mut GuiState )
323336{
324- if gui_state. memory_read_timer > 0
325- {
326- gui_state. memory_read_timer -= 1 ;
327- return ;
328- }
329- gui_state. memory_read_timer = 60 ; //30 = 1s
330-
331337 //check if game window is closed. not perfect as user can load other game without closing the emulator
332338 //todo: check for string again probably
333339 let mut exit_code = 0 ;
@@ -461,12 +467,26 @@ fn create_ui(ctx: &mut Context, gui_state: &mut GuiState)
461467 gui_state. graph . default_window_pos = ( pos. min . x , pos. min . y ) ;
462468 gui_state. graph . default_window_width = pos. max . x ;
463469 }
464- else
470+
471+ egui:: Window :: new ( "Game data reader" ) . show ( ctx, |ui|
465472 {
466- egui :: Window :: new ( "Game data reader" ) . show ( ctx , |ui|
473+ ui . horizontal ( |ui|
467474 {
468- ui. label ( "Searching for supported games..." ) ;
469- ui. label ( "Once a game has been found, data will be shown automatically!" ) ;
475+ ui. add
476+ (
477+ egui:: DragValue :: new ( & mut gui_state. timer_ticks )
478+ . speed ( 0.23 )
479+ . clamp_range ( 5 ..= 125 )
480+ . prefix ( "Ticks/update: " )
481+ ) ;
482+
483+ ui. label ( format ! ( "({:.2} updates/sec)" , 50.0 / gui_state. timer_ticks as f32 ) ) ;
470484 } ) ;
471- }
485+
486+ if gui_state. current_game . is_none ( )
487+ {
488+ ui. label ( "\n Searching for supported games..." ) ;
489+ ui. label ( "Once a game has been found, data will be shown automatically!" ) ;
490+ }
491+ } ) ;
472492}
0 commit comments