1
1
import os
2
+ import time
3
+ from datetime import datetime
2
4
3
5
import eel
4
6
from PyQt5 .QtCore import QSettings
5
7
from PyQt5 .QtWidgets import QApplication , QFileDialog
6
8
from pip ._internal import main as pipmain
9
+ from rlbot .utils import rate_limiter
10
+ from rlbot .utils .logging_utils import get_logger
11
+ from rlbot .utils .structures .game_interface import GameInterface
12
+ from rlbot .utils .structures import game_data_struct
7
13
from rlbot .parsing .bot_config_bundle import get_bot_config_bundle , BotConfigBundle
8
14
from rlbot .parsing .directory_scanner import scan_directory_for_bot_configs
9
15
from rlbot .parsing .match_settings_config_parser import map_types , game_mode_types , \
20
26
settings = QSettings ('rlbotgui' , 'preferences' )
21
27
22
28
29
+ game_tick_packet = None
30
+
31
+ GAME_TICK_PACKET_REFRESHES_PER_SECOND = 120 # 2*60. https://en.wikipedia.org/wiki/Nyquist_rate
32
+
33
+ class GameTickReader :
34
+ def __init__ (self ):
35
+ self .logger = get_logger ('packet reader' )
36
+ self .game_interface = GameInterface (self .logger )
37
+ self .game_interface .inject_dll ()
38
+ self .game_interface .load_interface ()
39
+ self .game_tick_packet = game_data_struct .GameTickPacket ()
40
+
41
+
42
+ # self.rate_limit = rate_limiter.RateLimiter(GAME_TICK_PACKET_REFRESHES_PER_SECOND)
43
+ self .last_call_real_time = datetime .now () # When we last called the Agent
44
+
45
+ def get_packet (self ):
46
+
47
+ now = datetime .now ()
48
+ # self.rate_limit.acquire(now - self.last_call_real_time)
49
+ self .last_call_real_time = now
50
+
51
+ self .pull_data_from_game ()
52
+ return self .game_tick_packet
53
+
54
+ def pull_data_from_game (self ):
55
+ self .game_interface .update_live_data_packet (self .game_tick_packet )
56
+
57
+
23
58
@eel .expose
24
59
def start_match (bot_list , match_settings ):
25
60
eel .spawn (start_match_helper , bot_list , match_settings )
@@ -185,6 +220,21 @@ def begin_python_bot(bot_name):
185
220
return {'bots' : load_bundle (config_file )}
186
221
187
222
223
+ def as_jsonifyable (obj ):
224
+ if isinstance (obj , (int , float , str )):
225
+ return obj
226
+ elif isinstance (obj , list ):
227
+ return list (map (as_jsonifyable , obj ))
228
+ else :
229
+ return {attr : as_jsonifyable (getattr (obj , attr )) for attr in dir (obj ) if not attr .startswith ("_" )}
230
+
231
+
232
+ @eel .expose
233
+ def get_game_tick_packet ():
234
+ obj = as_jsonifyable (game_tick_packet )
235
+ return obj
236
+
237
+
188
238
should_quit = False
189
239
190
240
@@ -198,13 +248,15 @@ def on_websocket_close(page, sockets):
198
248
199
249
200
250
def is_chrome_installed ():
201
- return eel .browsers .chr .get_instance_path () is not None
251
+ return eel .browsers .chm .get_instance_path () is not None
202
252
203
253
204
254
def start ():
205
255
gui_folder = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'gui' )
206
256
eel .init (gui_folder )
207
257
258
+ packet_reader = GameTickReader ()
259
+
208
260
options = {}
209
261
if not is_chrome_installed ():
210
262
options = {'mode' : 'system-default' } # Use the system default browser if the user doesn't have chrome.
@@ -216,5 +268,7 @@ def start():
216
268
disable_cache = True )
217
269
218
270
while not should_quit :
271
+ global game_tick_packet
272
+ game_tick_packet = packet_reader .get_packet ()
219
273
do_infinite_loop_content ()
220
274
eel .sleep (1.0 )
0 commit comments