@@ -28,14 +28,12 @@ class SimInfoAPI(rF2data.SimInfo):
2828 rf2_pid_counter = 0 # Counter to check if running
2929 rf2_running = False
3030
31- def __init__ (self , input_pid ):
31+ def __init__ (self , input_pid = "" ):
3232 rF2data .SimInfo .__init__ (self , input_pid )
3333 self .versionCheckMsg = self .versionCheck ()
3434 self .__find_rf2_pid ()
35+
3536 self .players_index = 99
36- self .players_status = 0
37- self .LastTele = copy .deepcopy (self .Rf2Tele )
38- self .LastScor = copy .deepcopy (self .Rf2Scor )
3937 self .data_updating = False
4038 print ("sharedmemory mapping started" )
4139
@@ -137,11 +135,18 @@ def dataVerified(input_data):
137135
138136 def __infoUpdate (self ):
139137 """ Update synced player data """
140- players_mid = 0
138+ players_mid = 0 # player mID
139+ last_version_update = 0 # store last data version update
140+ re_version_update = 0 # store restarted data version update
141+ mmap_restarted = True # whether has restarted memory mapping
142+ check_counter = 0 # counter for data version update check
143+ restore_counter = 0 # counter for restoring mmap data to default
141144
142145 while self .data_updating :
143146 data_scor = copy .deepcopy (self .Rf2Scor ) # use deepcopy to avoid data interruption
144147 data_tele = copy .deepcopy (self .Rf2Tele )
148+ self .LastExt = copy .deepcopy (self .Rf2Ext )
149+ self .LastFfb = copy .deepcopy (self .Rf2Ffb )
145150
146151 # Only update if data verified and player index found
147152 if self .dataVerified (data_scor ) and self .__playerVerified (data_scor ):
@@ -151,7 +156,31 @@ def __infoUpdate(self):
151156 # Only update if data verified and player mID matches
152157 if self .dataVerified (data_tele ) and data_tele .mVehicles [self .players_index ].mID == players_mid :
153158 self .LastTele = copy .deepcopy (data_tele ) # use deepcopy to update synced telemetry data
154- self .players_status = self .LastTele .mVehicles [self .players_index ].mIgnitionStarter # update player status
159+
160+ # Start checking data version update status
161+ check_counter += 1
162+
163+ if check_counter > 70 : # active after around 1 seconds
164+ if not mmap_restarted and last_version_update > 0 and last_version_update == self .LastScor .mVersionUpdateEnd :
165+ self .reset_mmap ()
166+ mmap_restarted = True
167+ re_version_update = self .LastScor .mVersionUpdateEnd
168+ print (f"sharedmemory mapping restarted - version:{ last_version_update } " )
169+ last_version_update = self .LastScor .mVersionUpdateEnd
170+ check_counter = 0 # reset counter
171+
172+ if mmap_restarted :
173+ if re_version_update != self .LastScor .mVersionUpdateEnd :
174+ mmap_restarted = False
175+ restore_counter = 0 # reset counter
176+ elif restore_counter < 71 :
177+ restore_counter += 1
178+
179+ if restore_counter == 70 : # active after around 1 seconds
180+ self .set_default_mmap ()
181+ print ("sharedmemory mapping data reset to default" )
182+
183+ #print(f"c1:{check_counter:03.0f} c2:{restore_counter:03.0f} now:{self.LastScor.mVersionUpdateEnd:07.0f} last:{last_version_update:07.0f} re:{re_version_update:07.0f} {mmap_restarted}", end="\r")
155184
156185 time .sleep (0.01 )
157186 else :
@@ -245,9 +274,7 @@ def isAiDriving(self):
245274 # didn't work self.Rf2Ext.mPhysics.mAIControl
246275
247276 def driverName (self ):
248- """
249- Get the player's name
250- """
277+ """ Get the player's name """
251278 return Cbytestring2Python (
252279 self .Rf2Scor .mVehicles [self .__playersDriverNum ()].mDriverName )
253280
@@ -260,33 +287,10 @@ def playersVehicleScoring(self):
260287 return self .Rf2Scor .mVehicles [self .__playersDriverNum ()]
261288
262289 def vehicleName (self ):
263- """
264- Get the vehicle's name
265- """
290+ """ Get the vehicle's name """
266291 return Cbytestring2Python (
267292 self .Rf2Scor .mVehicles [self .__playersDriverNum ()].mVehicleName )
268293
269- def closeSimInfo (self ):
270- # This didn't help with the errors
271- try :
272- # Unassign those objects first
273- self .Rf2Tele = None
274- self .Rf2Scor = None
275- self .Rf2Ext = None
276- self .Rf2Ffb = None
277- # Close shared memory mapping
278- self ._rf2_tele .close ()
279- self ._rf2_scor .close ()
280- self ._rf2_ext .close ()
281- self ._rf2_ffb .close ()
282- print ("sharedmemory mapping closed" )
283- except BufferError : # "cannot close exported pointers exist"
284- print ("BufferError" )
285- pass
286-
287- def __del__ (self ):
288- self .close ()
289-
290294
291295def Cbytestring2Python (bytestring ):
292296 """
0 commit comments