@@ -150,11 +150,14 @@ def __update_forza_info(self, fdp: ForzaDataPacket):
150150 Args:
151151 fdp (ForzaDataPacket): datapackage
152152 """
153- if self .ordinal != fdp .car_ordinal or self .car_perf != fdp .car_performance_index or self .car_class != fdp .car_class or self .car_drivetrain != fdp .drivetrain_type :
153+ if len ( self . shift_point ) <= 0 or self .ordinal != fdp .car_ordinal or self .car_perf != fdp .car_performance_index or self .car_class != fdp .car_class or self .car_drivetrain != fdp .drivetrain_type :
154154 self .ordinal = fdp .car_ordinal
155155 self .car_perf = fdp .car_performance_index
156156 self .car_class = fdp .car_class
157157 self .car_drivetrain = fdp .drivetrain_type
158+ return self .__try_auto_load_config (fdp )
159+ else :
160+ return True
158161
159162 def __try_auto_load_config (self , fdp : ForzaDataPacket ):
160163 """auto load config while driving
@@ -180,7 +183,7 @@ def __try_auto_load_config(self, fdp: ForzaDataPacket):
180183 if self .__try_loading_config (filename ):
181184 # remove legacy config if necessary
182185 if len (configs ) > 1 :
183- self .__cleanup_legacy_config (configs , filename )
186+ self .__cleanup_legacy_config (configs )
184187
185188 return True
186189 else :
@@ -196,7 +199,7 @@ def __try_auto_load_config(self, fdp: ForzaDataPacket):
196199
197200 # dump to latest config version
198201 helper .dump_config (self )
199- self .__cleanup_legacy_config (configs , '' )
202+ self .__cleanup_legacy_config (configs )
200203 return True
201204 else :
202205 return False
@@ -207,9 +210,16 @@ def __try_auto_load_config(self, fdp: ForzaDataPacket):
207210 finally :
208211 self .logger .debug (f'{ self .__try_auto_load_config .__name__ } ended' )
209212
210- def __cleanup_legacy_config (self , configs , exclude_config ):
213+ def __cleanup_legacy_config (self , configs , latest_version : ConfigVersion = constants .default_config_version ):
214+ """cleanup legacy configs
215+
216+ Args:
217+ configs (list): list of configs
218+ latest_version (ConfigVersion, optional): config version. Defaults to constants.default_config_version.
219+ """
211220 for config in configs :
212- if config != exclude_config :
221+ version = helper .get_config_version (self , config )
222+ if version != latest_version :
213223 try :
214224 self .logger .warning (f'removing legacy config { config } ' )
215225 path = os .path .join (self .config_folder , config )
@@ -254,10 +264,12 @@ def shifting(self, iteration, fdp):
254264
255265 # prepare shifting params
256266 slip = (fdp .tire_slip_ratio_RL + fdp .tire_slip_ratio_RR ) / 2
267+ angle_slip = (fdp .tire_slip_angle_RL + fdp .tire_slip_angle_RR ) / 2
257268 speed = fdp .speed * 3.6
258269 rpm = fdp .current_engine_rpm
259270 accel = fdp .accel
260271 fired = False
272+ self .logger .debug (f'[{ iteration } ] at gear { gear } . rpm { rpm } , speed { speed } , angle slip { angle_slip } , slip { slip } , accel { accel } ' )
261273
262274 # up shift logic
263275 if gear < self .maxGear and accel :
@@ -267,14 +279,14 @@ def shifting(self, iteration, fdp):
267279 # RWD logic
268280 if self .car_drivetrain == 1 :
269281 # at low gear (<= 3)
270- if gear <= 3 and slip >= 0.9 :
271- self .logger .debug (f'[{ iteration } ] up shift triggerred since RWD at gear { gear } . rpm { rpm } , speed { speed } , slip { slip } , accel { accel } ' )
282+ if gear <= 3 and angle_slip >= 1 :
283+ self .logger .debug (f'[{ iteration } ] up shift triggerred since RWD at gear { gear } . rpm { rpm } , speed { speed } , angle slip { angle_slip } , slip { slip } , accel { accel } ' )
272284 gear_helper .up_shift_handle (gear , self )
273285 fired = True
274286 else :
275- fired = self .__up_shift (rpm , target_rpm , speed , target_up_speed , slip , iteration , gear )
287+ fired = self .__up_shift (rpm , target_rpm , speed , target_up_speed , slip , iteration , gear , fdp )
276288 else :
277- fired = self .__up_shift (rpm , target_rpm , speed , target_up_speed , slip , iteration , gear )
289+ fired = self .__up_shift (rpm , target_rpm , speed , target_up_speed , slip , iteration , gear , fdp )
278290
279291 # down shift logic
280292 if not fired and gear > self .minGear :
@@ -285,21 +297,46 @@ def shifting(self, iteration, fdp):
285297 if self .car_drivetrain == 1 :
286298 # don't down shift to gear 1, 2 when RWD
287299 if gear >= 4 :
288- self .__down_shift (speed , target_down_speed , slip , iteration , gear )
300+ self .__down_shift (speed , target_down_speed , slip , iteration , gear , fdp )
289301 else :
290- self .__down_shift (speed , target_down_speed , slip , iteration , gear )
302+ self .__down_shift (speed , target_down_speed , slip , iteration , gear , fdp )
291303
292304 return iteration
293305
294- def __up_shift (self , rpm , target_rpm , speed , target_up_speed , slip , iteration , gear ):
306+ def __up_shift (self , rpm , target_rpm , speed , target_up_speed , slip , iteration , gear , fdp ):
307+ """up shift
308+
309+ Args:
310+ rpm (float): rpm
311+ target_rpm (float): target rpm to up shifting
312+ speed (float): speed
313+ target_up_speed (float): target speed to up shifting
314+ slip (float): total combined slip of rear tires
315+ iteration (int): package iteration
316+ gear (int): current gear
317+ fdp (ForzaPackage): Forza Package
318+
319+ Returns:
320+ _type_: _description_
321+ """
295322 if rpm > target_rpm and slip < 1 and speed > target_up_speed :
296323 self .logger .debug (f'[{ iteration } ] up shift triggerred. rpm > target rmp({ rpm } > { target_rpm } ), speed > target up speed ({ speed } > { target_up_speed } ), slip { slip } ' )
297324 gear_helper .up_shift_handle (gear , self )
298325 return True
299326 else :
300327 return False
301328
302- def __down_shift (self , speed , target_down_speed , slip , iteration , gear ):
329+ def __down_shift (self , speed , target_down_speed , slip , iteration , gear , fdp ):
330+ """down shift
331+
332+ Args:
333+ speed (float): speed
334+ target_down_speed (float): target speed to down shifting
335+ slip (float): total combined slip of rear tires
336+ iteration (int): package iteration
337+ gear (int): current gear
338+ fdp (ForzaPackage): Forza Package
339+ """
303340 if speed < target_down_speed * 0.95 and slip < 1 :
304341 self .logger .debug (f'[{ iteration } ] down shift triggerred. speed < target down speed ({ speed } < { target_down_speed } ), slip { slip } ' )
305342 gear_helper .down_shift_handle (gear , self )
@@ -324,23 +361,16 @@ def run(self, update_tree_func=lambda *args: None, update_car_gui_func=lambda *a
324361 if fdp is None or fdp .car_ordinal <= 0 :
325362 continue
326363
327- update_car_gui_func ( fdp )
364+ self . threadPool . submit ( update_car_gui_func , fdp )
328365
329366 # try to load config if:
330367 # 1. self.shift_point is empty
331368 # or
332369 # 2. fdp.car_ordinal is different from self.ordinal => means car switched
333- if len (self .shift_point ) <= 0 or self .ordinal != fdp .car_ordinal :
334- self .__update_forza_info (fdp )
335- if self .__try_auto_load_config (fdp ):
336- update_tree_func ()
337- continue
338- else :
339- return
340-
341- self .__update_forza_info (fdp )
342- if iteration == - 1 :
343- update_tree_func ()
370+ if not self .__update_forza_info (fdp ):
371+ return
372+ else :
373+ self .threadPool .submit (update_tree_func )
344374
345375 # enable reset car if exp or sp farming is True
346376 if self .farming and fdp .car_ordinal > 0 and fdp .speed < 20 and time .time () - reset_time > 10 :
0 commit comments