Example #1
0
def updateSharedMemory():
    global sharedMem
    sharedmem = sharedMem.getsharedmem()
    sharedmem.numVehicles = ac.getCarsCount()
    sharedmem.focusVehicle = ac.getFocusedCar()

    #now we'll build the slots, so we later know every single (possible) car
    carIds = range(0, ac.getCarsCount(), 1)
    for carId in carIds:
        #first we'll check wether there is a car for this id; as soon it returns -1
        #it's over
        if str(ac.getCarName(carId)) == '-1':
            break
        else:
            sharedmem.vehicleInfo[carId].carId = carId
            sharedmem.vehicleInfo[carId].driverName = ac.getDriverName(carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].carModel = ac.getCarName(carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].speedMS = ac.getCarState(carId, acsys.CS.SpeedMS)
            sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState(carId, acsys.CS.BestLap)
            sharedmem.vehicleInfo[carId].lapCount = ac.getCarState(carId, acsys.CS.LapCount)
            sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState(carId, acsys.CS.LapInvalidated)
            sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState(carId, acsys.CS.LapTime)
            sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState(carId, acsys.CS.LastLap)
            sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState(carId, acsys.CS.WorldPosition)
            sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline(carId)
            sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId)
            sharedmem.vehicleInfo[carId].carLeaderboardPosition = ac.getCarLeaderboardPosition(carId)
            sharedmem.vehicleInfo[carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(carId)
            sharedmem.vehicleInfo[carId].spLineLength=  ac.getCarState(carId, acsys.CS.NormalizedSplinePosition) 
            sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId)
Example #2
0
    def update(self, delta: float):
        for c in range(0, self._server.cars):
            if ac.isCarInPit(c) or not ac.isConnected(c):
                continue

            lap = ac.getCarState(c, acsys.CS.LapCount)
            pos = ac.getCarState(c, acsys.CS.NormalizedSplinePosition)
            invalid = ac.getCarState(
                c, acsys.CS.LapInvalidated) and self._valid[c]
            sec = int(pos * 3)
            #msec = int(pos * 12)

            if lap != self._lap_index[c]:
                self._valid[c] = True
                self._start_lap_time[c] = time() * 1000
                best_lap = ac.getCarState(c, acsys.CS.BestLap)
                if not invalid and best_lap > 0:
                    if best_lap < self._gb_lap_time:
                        self._gb_lap_time = best_lap
                        self._pb_lap_time[c] = best_lap
                    elif best_lap < self._pb_lap_time[c]:
                        self._pb_lap_time[c] = best_lap

                self._lap_index[c] = lap

            self._current_lap_time[c] = time() * 1000 - self._start_lap_time[c]

            if sec > 0:
                self._current_sector_time[c][sec] = self._current_lap_time[
                    c] - sum(self._current_sector_time[c][:sec])
            else:
                self._current_sector_time[c][sec] = self._current_lap_time[c]

            if sec != self._sector_index[c]:
                last_sec = self._sector_index[c]

                if not invalid and self._current_sector_time[c][last_sec] > 0:
                    if self._current_sector_time[c][
                            last_sec] < self._gb_sector_time[last_sec]:
                        self._gb_sector_time[
                            last_sec] = self._current_sector_time[c][last_sec]
                        self._pb_sector_time[c][
                            last_sec] = self._current_sector_time[c][last_sec]
                    elif self._current_sector_time[c][
                            last_sec] < self._pb_sector_time[c][last_sec]:
                        self._pb_sector_time[c][
                            last_sec] = self._current_sector_time[c][last_sec]

                self._sector_index[c] = sec
Example #3
0
def updateSharedMemory():
    global sharedMem
    sharedmem = sharedMem.getsharedmem()
    sharedmem.numVehicles = ac.getCarsCount()
    sharedmem.focusVehicle = ac.getFocusedCar()
    #now we'll build the slots, so we later know every single (possible) car
    carIds = range(0, ac.getCarsCount(), 1)
    for carId in carIds:
        #first we'll check wether there is a car for this id; as soon it returns -1
        #it's over
        if str(ac.getCarName(carId)) == '-1':
            break
        else:
            sharedmem.vehicleInfo[carId].carId = carId
            sharedmem.vehicleInfo[carId].driverName = ac.getDriverName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].carModel = ac.getCarName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].speedMS = ac.getCarState(
                carId, acsys.CS.SpeedMS)
            sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState(
                carId, acsys.CS.BestLap)
            sharedmem.vehicleInfo[carId].lapCount = ac.getCarState(
                carId, acsys.CS.LapCount)
            sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState(
                carId, acsys.CS.LapInvalidated)
            sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState(
                carId, acsys.CS.LapTime)
            sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState(
                carId, acsys.CS.LastLap)
            sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState(
                carId, acsys.CS.WorldPosition)
            sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline(
                carId)
            sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId)
            sharedmem.vehicleInfo[
                carId].carLeaderboardPosition = ac.getCarLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[
                carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[carId].spLineLength = ac.getCarState(
                carId, acsys.CS.NormalizedSplinePosition)
            sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId)
            sharedmem.vehicleInfo[carId].finishStatus = ac.getCarState(
                carId, acsys.CS.RaceFinished)
Example #4
0
def build_driver_list():
    """Builds list of cars that drove through joker"""
    global driver_list, polygon

    # Get number of cars
    car_amount = ac.getCarsCount()

    # Iterate through cars
    for i in range(0, car_amount):
        driver_name = ac.getDriverName(i)
        if driver_name not in driver_list:
            inpitbox = ac.isCarInPit(i)
            isconnected = ac.isConnected(i)
            if not inpitbox and isconnected:
                crds = ac.getCarState(i, acsys.CS.WorldPosition)
                inside_joker = inside_polygon(crds[0], crds[2], polygon)
                if inside_joker:
                    driver_list.append(driver_name)
                    lap = ac.getCarState(i, acsys.CS.LapCount)
                    send_chat_message(driver_name, lap)
 def __init__(self, carId):
     self.carId = carId  # ID - номер машины в списке
     self.driverName = ac.getDriverName(carId)  # имя игрока
     self.carName = getCarName(ac.getCarName(carId))  # машина
     # TODO: брать название машины из конфигов: например, вместо ks_bmw_m235i_racing будет BMW M235i Racing
     self.lapsCompleted = 0  # завершено кругов
     self.lastLap = ac.getCarState(
         self.carId,
         acsys.CS.LastLap)  # время последнего пройденного круга в мс
     self.bestLap = ac.getCarState(
         self.carId, acsys.CS.BestLap)  # время лучшего круга сессии в мс
     self.qualifiedTime = 0  # время, поставленное в квалификации (сохраняется для сортировки пилотов на старте)
     self.totalTime = 0  # суммарное время кругов (время гонки, в остальных сессиях не имеет смысла)
     self.totalDistance = 0  # суммарная дистанция (для сортировки в гонке)
     self.isInPitlane = ac.isCarInPitlane(carId)  # машина на пит-лейне
     self.isInPit = ac.isCarInPit(carId)  # машина в боксах
     self.lapPostTime = 0  # момент времени (по session_time), когда было поставлено время в практике/квалификации
     self.connected = False
     self.leaderboardPosition = 0
     self.realTimeLeaderboardPosition = 0
     self.isTimedRace = 0  # гонка ограничена временем, а не кругами
     self.hasExtraLap = 0  # дополнительный круг в гонке по времени
     self.isFinished = 0  # гонщик завершил сессию
 def updateTiming(self):
     """
     Рядовое обновление данных
     """
     for car in self.carList:
         if car is not None:
             postLogMessage('ac.isConnected(' + str(car.carId) + ') : ' +
                            str(ac.isConnected(car.carId)))
             car.connected = ac.isConnected(car.carId) == 1
             if not car.connected:  # отключённые машины не обновляем
                 continue
             # Если количество кругов, пройденных пилотом, в игре больше, чем в структуре car, обновляем данные по кругам
             newLapsCompleted = ac.getCarState(car.carId, acsys.CS.LapCount)
             if car.lapsCompleted < newLapsCompleted:
                 postLogMessage('car' + str(car.carId) +
                                ' per-lap timing update')
                 # Покруговые обновления
                 car.lapsCompleted = newLapsCompleted
                 car.lastLap = ac.getCarState(car.carId, acsys.CS.LastLap)
                 car.bestLap = ac.getCarState(car.carId, acsys.CS.BestLap)
                 car.totalTime += car.lastLap
                 car.lapPostTime = self.session_time
                 car.isFinished = ac.getCarState(car.carId,
                                                 acsys.CS.RaceFinished)
                 # postLogMessage('Per-lap update OK')
             # Постоянные обновления
             # postLogMessage('Per-iterval update')
             car.totalDistance = car.lapsCompleted + ac.getCarState(
                 car.carId, acsys.CS.NormalizedSplinePosition)
             car.isInPitlane = ac.isCarInPitlane(car.carId)
             car.isInPit = ac.isCarInPit(car.carId)
             car.leaderboardPosition = ac.getCarLeaderboardPosition(
                 car.carId)
             car.realTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(
                 car.carId)
             car.isFinished = ac.getCarState(car.carId,
                                             acsys.CS.RaceFinished)
def acUpdate(deltaT):
    # TIMERS
    global timer0, timer1, timer2

    # VARIABLES
    global totalDrivers
    global drivers
    global fastest_lap

    global race_started, replay_started, quali_started

    global qualify_session_time

    global replay_file
    global replay_data

    # Widgets
    global leaderboardWindow, driverWidget, driverComparisonWidget

    # LABELS
    global leaderboard
    global lapCountTimerLabel, leaderboardBaseLabel, leaderboardInfoBackgroundLabel, leaderboardBackgroundLabel
    global flagLabel

    # ============================
    # UPDATE TIMERS
    timer0 += deltaT
    timer1 += deltaT
    timer2 += deltaT
    # ============================

    # ================================================================
    #                            RACES
    # ================================================================
    if info.graphics.session == 2:

        # 10 times per second
        if timer2 > 0.1:
            timer2 = 0

            # =============================
            # SAVE SPLIT TIMES
            for d in drivers:
                if ac.isConnected(d.id) == 0: continue
                current_split = d.get_split_id(ac.getCarState(d.id, acsys.CS.NormalizedSplinePosition))
                if d.current_split != current_split: # save split time at each split of the track
                    d.split_times[current_split-1] = time.time()
                    d.current_split = current_split

        # 3 times per second
        if timer1 > 0.3:
            # CHECK RACE RESTART
            if race_started and info.graphics.completedLaps == 0 and info.graphics.iCurrentTime == 0:
                race_started = False

            # CHECK RACE START
            if not race_started and info.graphics.iCurrentTime > 0:
                # RESET THINGS
                fastest_lap = MAX_LAP_TIME
                LeaderboardRow.FASTEST_LAP_ID = -1
                for row in leaderboard: # clean the fastest lap marker
                    row.mark_fastest_lap()
                # in case we are coming from a qualify
                ac.setFontColor(lapCountTimerLabel, 0.86, 0.86, 0.86, 1)
                ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_RACE)
                ac.setVisible(lapCountTimerLabel, 1)

                race_started = True
                quali_started = False
                for d in drivers:
                    d.starting_position = ac.getCarLeaderboardPosition(d.id)
                    d.tyre = ac.getCarTyreCompound(d.id)
                    d.pits = 0
                replay_file = setup_replay_file(drivers, info.graphics.numberOfLaps) # save starting info on the drivers

            # ============================
            # POSITION UPDATE
            for i in range(totalDrivers):
                pos = ac.getCarRealTimeLeaderboardPosition(i)
                connected = ac.isConnected(i)
                if connected == 0: # mark unconnected drivers
                    leaderboard[pos].mark_out()
                    drivers[i].out = True
                else:
                    leaderboard[pos].mark_in()
                    drivers[i].out = False
                leaderboard[pos].update_name(i)

                # OVERTAKE
                if pos != drivers[i].position: # there was an overtake
                    drivers[i].timer = FC.OVERTAKE_POSITION_LABEL_TIMER # set timer
                    if pos < drivers[i].position:
                        leaderboard[pos].mark_green_position()
                    elif pos > drivers[i].position:
                        leaderboard[pos].mark_red_position()
                elif drivers[i].timer <= 0:
                    leaderboard[pos].mark_white_position()
                else:
                    drivers[i].timer -= timer1
                drivers[i].position = pos
                # END OVERTAKE

            # ============================
            # FASTEST LAP BANNER TIMER
            if fastest_lap_banner.timer > 0:
                fastest_lap_banner.timer -= timer1
                fastest_lap_banner.hide()

            # ============================
            # FLAGS
            if info.graphics.flag == 1:
                ac.setBackgroundTexture(flagLabel, FC.BLUE_FLAG)
                ac.setVisible(flagLabel, 1)
            elif info.graphics.flag == 2:
                ac.setBackgroundTexture(flagLabel, FC.YELLOW_FLAG)
                ac.setVisible(flagLabel, 1)
            elif info.graphics.flag == 5:
                ac.setBackgroundTexture(flagLabel, FC.CHECKERED_FLAG)
                ac.setVisible(flagLabel, 1)
            elif info.graphics.flag == 0:
                ac.setVisible(flagLabel, 0)

            timer1 = 0

        # Once per second
        if timer0 > 1:
            timer0 = 0
            ac.setBackgroundOpacity(leaderboardWindow, 0)
            ac.setBackgroundOpacity(driverWidget.window, 0)
            ac.setBackgroundOpacity(driverComparisonWidget.window, 0)
            ac.setBackgroundOpacity(fastest_lap_banner.window, 0)

            # ============================
            # SERVER LAP
            for i in range(totalDrivers):
                drivers[i].current_lap = ac.getCarState(i, acsys.CS.LapCount)
            lc = max((drivers[i].current_lap for i in range(totalDrivers))) + 1
            if lc >= info.graphics.numberOfLaps:
                ac.setVisible(lapCountTimerLabel, 0)
                ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_FINAL_LAP)
            else:
                ac.setText(lapCountTimerLabel, "%d / %d" % (lc, info.graphics.numberOfLaps))

            # ===========================
            # CALCULATE TIME DIFERENCES
            dPosition = sorted(drivers, key=lambda x: x.position)
            if LeaderboardRow.update_type == INFO_TYPE.GAPS:
                for i in range(1, len(dPosition)):
                    driver_ahead, driver = dPosition[i-1], dPosition[i]
                    timeDiff = driver.split_times[driver.current_split - 1] - driver_ahead.split_times[driver.current_split - 1]
                    if timeDiff < 0: continue # ignore these times, happens on overtakes
                    if driver.position > totalDrivers: continue # might try to update before it is possible
                    driver.timeDiff = timeDiff
                    if timeDiff > 60:
                        leaderboard[driver.position].update_time("+1 MIN")
                    else:
                        leaderboard[driver.position].update_time("+" + time_to_string(timeDiff*1000))
                leaderboard[0].update_time("Interval") # Force it
            elif LeaderboardRow.update_type == INFO_TYPE.POSITIONS:
                for d in dPosition:
                    posDiff = d.starting_position - d.position - 1
                    leaderboard[d.position].update_positions(posDiff)

            # ============================
            # MARK FASTEST LAP
            if lc > FC.FASTEST_LAP_STARTING_LAP:
                for d in drivers:
                    lap = ac.getCarState(d.id, acsys.CS.BestLap)
                    if lap != 0 and lap < fastest_lap:
                        fastest_lap = lap
                        fastest_lap_banner.show(lap, ac.getDriverName(d.id))
                        LeaderboardRow.FASTEST_LAP_ID = d.id
                        if replay_file:
                            write_fastest_lap(replay_file, info.graphics.completedLaps, info.graphics.iCurrentTime, d, fastest_lap)
                for row in leaderboard:
                    row.mark_fastest_lap()

            # ============================
            # PITS MARKER
            for row in leaderboard:
                if ac.isCarInPitline(row.driverId) == 1:
                    row.mark_enter_pits()
                    drivers[row.driverId].tyre = ac.getCarTyreCompound(row.driverId) # maybe will change tyre
                else:
                    row.mark_left_pits()
                if time.time() - drivers[row.driverId].pit_time > 20 and ac.isCarInPit(row.driverId):
                    drivers[row.driverId].pits += 1
                    drivers[row.driverId].pit_time = time.time()

            # ============================
            # CHANGE CAR FOCUS AND DRIVER WIDGET
            if race_started:
                id = ac.getFocusedCar()
                if drivers[id].position <= totalDrivers: # in case it wasnt updated yet
                    driverWidget.show(id, drivers[id].position, drivers[id].starting_position, drivers[id].tyre, drivers[id].pits)
                    if drivers[id].position == 0:
                        driverComparisonWidget.hide()
                    else:
                        for d in drivers: # find driver ahead
                            if d.position == drivers[id].position - 1:
                                driverComparisonWidget.show(d.id, d.position, id, drivers[id].position, drivers[id].timeDiff*1000)
                                break
            else:
                driverWidget.hide()
                driverComparisonWidget.hide()

            # ========================================================
            # SAVE DRIVER STATUS IN A FILE TO LOAD ON REPLAY
            if replay_file:
                write_driver_info(replay_file, info.graphics.completedLaps, info.graphics.iCurrentTime, drivers)
            # ========================================================


    # ================================================================
    #                        QUALIFY / PRACTICE
    # ================================================================
    elif info.graphics.session == 1 or (info.graphics.session == 0 and info.graphics.status != 1):

        # 3 times per second
        if timer1 > 0.3:
            # =============================================
            # QUALIFY RESTART
            if quali_started and qualify_session_time - info.graphics.sessionTimeLeft < 1:
                quali_started = False

            # =============================================
            # QUALIFY START
            if not quali_started:
                ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_QUALI)
                if (info.graphics.session == 0 and info.graphics.status != 0):
                    ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_PRACTICE)
                ac.setFontColor(lapCountTimerLabel, 0.86, 0.86, 0.86, 1)
                qualify_session_time = info.graphics.sessionTimeLeft
                fastest_lap = MAX_LAP_TIME
                LeaderboardRow.FASTEST_LAP_ID = -1
                quali_started = True
                race_started = False

            # =============================================
            # SAVE BEST LAPS FOR EACH DRIVER
            for i in range(totalDrivers):
                lap = ac.getCarState(i, acsys.CS.BestLap)
                if lap != 0:
                    drivers[i].best_lap = lap
                if lap != 0 and lap < fastest_lap:
                    fastest_lap = lap
                    fastest_lap_banner.show(lap, ac.getDriverName(i))

                # MARK IN/OUT DRIVERS
                connected = ac.isConnected(i)
                if connected == 0: # mark unconnected drivers
                    drivers[i].out = True
                else:
                    drivers[i].out = False
                
            # =============================================
            # MANAGE LEADERBOARD

            # Sorting: sort drivers by this order 1. in or out drivers, 2. best lap, 3. driver id
            dPosition = sorted(drivers, key=lambda d: (d.out, d.best_lap, d.id))

            for i in range(totalDrivers):
                if dPosition[i].out:
                    leaderboard[i].mark_out()
                else:
                    leaderboard[i].mark_in()

                leaderboard[i].update_name(dPosition[i].id)
                if dPosition[i].best_lap == MAX_LAP_TIME:
                    leaderboard[i].update_time("NO TIME")
                elif i == 0:
                    leaderboard[i].update_time(time_to_string(dPosition[i].best_lap))
                else:
                    timeDiff = dPosition[i].best_lap - dPosition[0].best_lap
                    if timeDiff > 60000:
                        leaderboard[i].update_time("+1 MIN")
                    else:
                        leaderboard[i].update_time("+" + time_to_string(timeDiff))

                # OVERTAKES
                if i != dPosition[i].position: # there was an overtake on this driver
                    dPosition[i].timer = FC.OVERTAKE_POSITION_LABEL_TIMER
                    if i < dPosition[i].position:
                        leaderboard[i].mark_green_position()
                    elif i > dPosition[i].position:
                        leaderboard[i].mark_red_position()
                elif dPosition[i].timer <= 0:
                    leaderboard[i].mark_white_position()
                else:
                    dPosition[i].timer -= timer1
                dPosition[i].position = i
                # END OVERTAKE

            # ============================
            # FASTEST LAP BANNER TIMER
            if fastest_lap_banner.timer > 0:
                fastest_lap_banner.timer -= timer1
                fastest_lap_banner.hide()

            timer1 = 0

        # Once per second
        if timer0 > 1:
            timer0 = 0
            ac.setBackgroundOpacity(leaderboardWindow, 0)
            ac.setBackgroundOpacity(driverWidget.window, 0)
            ac.setBackgroundOpacity(driverComparisonWidget.window, 0)
            ac.setBackgroundOpacity(fastest_lap_banner.window, 0)

            if quali_started:
                if info.graphics.sessionTimeLeft < 0:
                    ac.setText(lapCountTimerLabel, "0:00")
                else:
                    timeText = time_to_string(info.graphics.sessionTimeLeft)[:-4]
                    ac.setText(lapCountTimerLabel, "0:00"[:-len(timeText)] + timeText)
                if info.graphics.sessionTimeLeft < qualify_session_time / 5:
                    ac.setFontColor(lapCountTimerLabel, 1,0,0,1)

            driverWidget.hide()
            driverComparisonWidget.hide()


    # ================================================================
    #                            REPLAYS
    # ================================================================
    elif info.graphics.status == 1:

        # three times per second
        if timer1 > 0.3:
            if not replay_started:
                if info.graphics.iCurrentTime > 0:
                    replay_data = load_replay_file(drivers)
                    replay_started = True

            # ============================
            # FASTEST LAP BANNER TIMER
            if fastest_lap_banner.timer > 0:
                fastest_lap_banner.timer -= timer1
                fastest_lap_banner.hide()

            # ============================
            # GET DATA FOR THIS UPDATE
            if replay_data:
                new_positions = lookup_data(info.graphics.completedLaps, info.graphics.iCurrentTime, replay_data, drivers)

                # ============================
                # POSITION UPDATE
                for i in range(totalDrivers):
                    pos = new_positions[i]
                    if drivers[i].out: # mark unconnected drivers
                        leaderboard[pos].mark_out()
                    else:
                        leaderboard[pos].mark_in()
                    leaderboard[pos].update_name(i)

                    # OVERTAKE
                    if pos != drivers[i].position: # there was an overtake
                        drivers[i].timer = FC.OVERTAKE_POSITION_LABEL_TIMER # set timer
                        if pos < drivers[i].position:
                            leaderboard[pos].mark_green_position()
                        elif pos > drivers[i].position:
                            leaderboard[pos].mark_red_position()
                    elif drivers[i].timer <= 0:
                        leaderboard[pos].mark_white_position()
                    else:
                        drivers[i].timer -= timer1
                    drivers[i].position = pos
                    # END OVERTAKE

            timer1 = 0

        # Once per second
        if timer0 > 1:
            timer0 = 0
            ac.setBackgroundOpacity(leaderboardWindow, 0)
            ac.setBackgroundOpacity(driverWidget.window, 0)
            ac.setBackgroundOpacity(driverComparisonWidget.window, 0)
            ac.setBackgroundOpacity(fastest_lap_banner.window, 0)

            # ============================
            # GET FASTEST LAP UPDATE
            if replay_data:
                fl_data = lookup_fastest_lap(info.graphics.completedLaps, info.graphics.iCurrentTime, replay_data)
                if fl_data:
                    display_time = FC.FASTEST_LAP_DISPLAY_TIME - (info.graphics.iCurrentTime - fl_data[0]) / 1000
                    fastest_lap_banner.show(fl_data[2], ac.getDriverName(fl_data[1]), timer=display_time) # display only for the time left

            # ============================
            # SERVER LAP
            if replay_data:
                lc = max((drivers[i].current_lap for i in range(totalDrivers))) + 1
                if lc >= replay_data['nLaps']:
                    ac.setVisible(lapCountTimerLabel, 0)
                    ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_FINAL_LAP)
                else:
                    ac.setText(lapCountTimerLabel, "%d / %d" % (lc, replay_data['nLaps']))
                    ac.setVisible(lapCountTimerLabel, 1)
                    ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_RACE)

            # ============================
            # PITS MARKER
            for row in leaderboard:
                if ac.isCarInPitline(row.driverId) == 1:
                    row.mark_enter_pits()
                else:
                    row.mark_left_pits()

            # ============================
            # DRIVER WIDGET UPDATE
            if replay_started:
                id = ac.getFocusedCar()
                if drivers[id].position <= totalDrivers: # in case it wasnt updated yet
                    driverWidget.show(id, drivers[id].position, drivers[id].starting_position, drivers[id].tyre, drivers[id].pits)
                    if drivers[id].position == 0:
                        driverComparisonWidget.hide()
                    else:
                        for d in drivers: # find driver ahead
                            if d.position == drivers[id].position - 1:
                                driverComparisonWidget.show(d.id, d.position, id, drivers[id].position, drivers[id].timeDiff*1000)
                                break
            else:
                driverWidget.hide()
                driverComparisonWidget.hide()

            # ============================
            # UPDATE TIMES
            if replay_data:
                for row in leaderboard:
                    if LeaderboardRow.update_type == INFO_TYPE.GAPS:
                        row.update_time("+" + time_to_string(drivers[row.driverId].timeDiff*1000))
                        if row.row == 0:
                            row.update_time("Interval") # Force it
                    elif LeaderboardRow.update_type == INFO_TYPE.POSITIONS:
                        posDiff = drivers[row.driverId].starting_position - drivers[row.driverId].position - 1
                        row.update_positions(posDiff)
Example #8
0
    def on_update(self, sim_info):
        self.session.setValue(sim_info.graphics.session)
        session_time_left = sim_info.graphics.sessionTimeLeft
        sim_info_status = sim_info.graphics.status
        if sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0:
            self.session.setValue(-1)
            self.session.setValue(sim_info.graphics.session)
        self.manage_window()
        if self.carsCount == 0:
            self.carsCount = ac.getCarsCount()
        for x in range(self.carsCount):
            c = ac.getCarState(x, acsys.CS.SpeedKMH)
            if self.useMPH:
                mph = ac.getCarState(x, acsys.CS.SpeedMPH)
            if x == 0 and self.topSpeed.value < c:
                self.userTopSpeed.setValue(c)
                if self.useMPH:
                    self.userTopSpeedMPH.setValue(mph)
                self.userTrap = ac.getCarState(
                    x, acsys.CS.NormalizedSplinePosition)

            if self.relyOnEveryOne and self.topSpeed.value < c \
                    and ac.getCarState(x, acsys.CS.DriveTrainSpeed) > c / 10 \
                    and ac.getCarState(x, acsys.CS.Gas) > 0.9 \
                    and ac.getCarState(x, acsys.CS.RPM) > 2000:
                if c > 500:
                    self.relyOnEveryOne = False
                    self.topSpeed.setValue(self.userTopSpeed.value)
                    if self.useMPH:
                        self.topSpeedMPH.setValue(self.userTopSpeedMPH.value)
                    self.trap = self.userTrap
                    # ac.console("stop rely")
                else:
                    self.topSpeed.setValue(c)
                    if self.useMPH:
                        self.topSpeedMPH.setValue(mph)
                    self.trap = ac.getCarState(
                        x, acsys.CS.NormalizedSplinePosition)
            elif not self.relyOnEveryOne and x == 0 and self.topSpeed.value < c:
                self.topSpeed.setValue(c)
                if self.useMPH:
                    self.topSpeedMPH.setValue(mph)
                self.trap = ac.getCarState(x,
                                           acsys.CS.NormalizedSplinePosition)

        self.current_vehicle.setValue(ac.getFocusedCar())
        self.SpeedKMH.setValue(
            ac.getCarState(self.current_vehicle.value, acsys.CS.SpeedKMH))
        if self.useMPH:
            self.SpeedMPH.setValue(
                ac.getCarState(self.current_vehicle.value, acsys.CS.SpeedMPH))
        lap_count = ac.getCarState(self.current_vehicle.value,
                                   acsys.CS.LapCount)

        if self.curTopSpeed.value < self.SpeedKMH.value:
            self.curTopSpeed.setValue(self.SpeedKMH.value)
            if self.useMPH:
                self.curTopSpeedMPH.setValue(self.SpeedMPH.value)
        if self.current_vehicle.value == 0 and sim_info.physics.numberOfTyresOut >= 4:
            self.lastLapInvalidated = lap_count
        self.animate()

        if sim_info_status == 2:  # Live
            is_in_pit = (bool(ac.isCarInPitline(self.current_vehicle.value))
                         or bool(ac.isCarInPit(self.current_vehicle.value)))
            if is_in_pit:
                self.lastLapInvalidated = lap_count
            position = ac.getCarState(self.current_vehicle.value,
                                      acsys.CS.NormalizedSplinePosition)
            if self.curTopSpeed.value < 500 and self.lastLapShown < lap_count \
                    and self.lastLapInvalidated < lap_count and self.widget_visible.value == 0 \
                    and position + 0.06 > self.trap > position - 0.08 \
                    and self.SpeedKMH.value < self.SpeedKMH.old - 0.6:
                # show and set timer 0.3
                self.lastLapShown = lap_count
                self.widget_visible.setValue(1)
                if self.useMPH:
                    speed_text = "%.1f mph | %.1f mph" % (
                        self.curTopSpeedMPH.value, self.topSpeedMPH.value)
                else:
                    speed_text = "%.1f kph | %.1f kph" % (
                        self.curTopSpeed.value, self.topSpeed.value)
                self.time_start = session_time_left - 800
                self.time_end = session_time_left - 14800
                self.lbl_time_txt.setText(speed_text)  #  , hidden=True)
                self.lbl_title.set(y=self.row_height.value).show()
                self.lbl_title_txt.set(y=self.row_height.value +
                                       Font.get_font_x_offset()).show()
            elif self.time_start != 0 and self.time_start > session_time_left > self.time_end:
                self.lbl_title.set(y=0, animated=True).show()
                self.lbl_title_txt.set(y=0 + Font.get_font_x_offset(),
                                       animated=True).show()
                self.lbl_time.show()
                self.lbl_time_txt.show()
                self.lbl_border.show()
            elif self.time_end == 0 or session_time_left < self.time_end:
                self.reset_visibility()
                self.widget_visible.setValue(0)
                self.time_start = 0
                self.time_end = 0
                if self.widget_visible.hasChanged():
                    self.curTopSpeed.setValue(0)
                    self.curTopSpeedMPH.setValue(0)
            # else:
            #   self.reset_visibility()
        elif sim_info_status == 1:
            self.reset_visibility()
Example #9
0
File: acdelta.py Project: Nrde/ACTV
    def on_update(self, sim_info):
        if self.__class__.configChanged:
            self.save_cfg()
            self.__class__.configChanged = False
        if not self.deltaLoaded:
            thread_load = threading.Thread(target=self.load_delta)
            thread_load.daemon = True
            thread_load.start()
        if self.__class__.resetPressed:
            self.referenceLapTime.setValue(0)
            self.referenceLapTime_session.setValue(0)
            self.referenceLap = []
            self.referenceLap_session = []
            self.__class__.resetPressed = False
        self.session.setValue(sim_info.graphics.session)
        self.manage_window()
        self.lbl_delta.animate()
        self.lbl_session_delta.animate()
        self.lbl_lap.animate()
        sim_info_status = sim_info.graphics.status
        if sim_info_status == 2:  # LIVE
            session_time_left = sim_info.graphics.sessionTimeLeft
            if math.isinf(session_time_left):
                self.reset_data()
            elif self.session.value == 2 and sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0:
                self.reset_data()
            elif bool(ac.isCarInPitline(0)) or bool(ac.isCarInPit(0)):
                self.reset_data()
            self.spline.setValue(
                round(ac.getCarState(0, acsys.CS.NormalizedSplinePosition), 3))

            if self.lastLapIsValid and sim_info.physics.numberOfTyresOut >= 4:
                self.lastLapIsValid = False

            if self.spline.hasChanged():
                self.laptime.setValue(
                    round(ac.getCarState(0, acsys.CS.LapTime), 3))
                self.lastLapTime.setValue(ac.getCarState(0, acsys.CS.LastLap))
                gap = self.get_performance_gap(self.spline.value,
                                               self.laptime.value)
                if gap != False:
                    self.performance.setValue(gap)
                gap = self.get_performance_session_gap(self.spline.value,
                                                       self.laptime.value)
                if gap != False:
                    self.performance_session.setValue(gap)
                # new lap
                if self.lastLapTime.hasChanged():
                    if (
                            self.referenceLapTime.value == 0
                            or self.lastLapTime.value <
                            self.referenceLapTime.value
                    ) and self.lastLapIsValid and self.lastLapTime.value > 0 and self.lapCount < ac.getCarState(
                            0, acsys.CS.LapCount):
                        self.referenceLapTime.setValue(self.lastLapTime.value)
                        self.referenceLapTime_session.setValue(
                            self.lastLapTime.value)

                        self.referenceLap_session = self.referenceLap = list(
                            self.currentLap)
                        if len(self.referenceLap) > 2000:  # 2laps in
                            ac.console("too many laps in reference----")
                            ac.log("too many laps in reference----")
                            how_much = math.floor(
                                len(self.referenceLap) / 1000)
                            del self.referenceLap[0:math.floor(
                                len(self.referenceLap) / how_much)]
                            self.referenceLap_session = self.referenceLap

                        thread_save = threading.Thread(target=self.save_delta)
                        thread_save.daemon = True
                        thread_save.start()
                        # make it green for 5 sec
                        self.highlight_end = sim_info.graphics.sessionTimeLeft - 6000
                        self.lbl_lap.setColor(Colors.green(), True)
                    elif (
                            self.referenceLapTime.value == 0
                            or self.lastLapTime.value <
                            self.referenceLapTime_session.value
                    ) and self.lastLapIsValid and self.lastLapTime.value > 0 and self.lapCount < ac.getCarState(
                            0, acsys.CS.LapCount):
                        self.referenceLapTime_session.setValue(
                            self.lastLapTime.value)
                        self.referenceLap_session = list(self.currentLap)
                        if len(self.referenceLap_session) > 2000:  # 2laps in
                            ac.console(
                                "too many laps in referenceLap_session----")
                            ac.log("too many laps in referenceLap_session----")
                            how_much = math.floor(
                                len(self.referenceLap_session) / 1000)
                            del self.referenceLap_session[0:math.floor(
                                len(self.referenceLap_session) / how_much)]

                    self.currentLap = []
                    self.lapCount = ac.getCarState(0, acsys.CS.LapCount)
                    self.lastLapIsValid = True

                self.currentLap.append(
                    raceGaps(self.spline.value, self.laptime.value))

            # update graphics
            if not math.isinf(session_time_left):
                self.TimeLeftUpdate.setValue(int(session_time_left / 500))
            if self.TimeLeftUpdate.hasChanged():
                if self.performance.hasChanged():
                    time_prefix = ""
                    color = Colors.white()
                    if self.performance.value > 0:
                        time_prefix = "+"
                        if self.lastLapIsValid:
                            color = Colors.yellow()
                        else:
                            color = Colors.red()
                    elif self.performance.value < 0:
                        time_prefix = "-"
                        if self.lastLapIsValid:
                            color = Colors.green()
                        else:
                            color = Colors.orange()
                    else:
                        if not self.lastLapIsValid:
                            color = Colors.red()
                    self.lbl_delta.setText(time_prefix + self.time_splitting(abs(self.performance.value), "yes"))\
                        .setColor(color, True)
                if self.performance_session.hasChanged():
                    if self.referenceLapTime.value != self.referenceLapTime_session.value and (
                            self.laptime.value >= 8000
                            or self.lastLapTime.value == 0):
                        time_prefix = ""
                        color = Colors.white()
                        if self.performance_session.value > 0:
                            time_prefix = "+"
                            if self.lastLapIsValid:
                                color = Colors.yellow()
                            else:
                                color = Colors.red()
                        elif self.performance_session.value < 0:
                            time_prefix = "-"
                            if self.lastLapIsValid:
                                color = Colors.green()
                            else:
                                color = Colors.orange()
                        else:
                            if not self.lastLapIsValid:
                                color = Colors.red()
                        self.lbl_session_delta.setText(time_prefix + self.time_splitting(abs(self.performance_session.value), "yes"))\
                            .setColor(color, True)
                    else:
                        # showlastlap
                        color = Colors.white()
                        #if not self.lastLapIsValid:
                        #    color = Colors.red()
                        self.lbl_session_delta.setText(
                            "L: " +
                            self.time_splitting(self.lastLapTime.value, "yes")
                        ).setColor(color, True)

            if self.referenceLapTime.hasChanged():
                self.lbl_lap.setText(
                    self.time_splitting(self.referenceLapTime.value, "yes"))
            if self.highlight_end == 0 or session_time_left < self.highlight_end:
                self.lbl_lap.setColor(Colors.white(), True)
Example #10
0
 def isInPit(car=0):
     return ac.isCarInPitline(car) or ac.isCarInPit(car)
Example #11
0
File: acinfo.py Project: prunn/ACTV
 def onUpdate(self, sim_info, fl):
     self.session.setValue(sim_info.graphics.session)
     self.manageWindow()
     self.animate()
     if self.carsCount==0:
         self.carsCount = ac.getCarsCount()
     sessionTimeLeft=sim_info.graphics.sessionTimeLeft
     sim_info_status=sim_info.graphics.status
     self.currentVehicule.setValue(ac.getFocusedCar())        
     backupLaptime=0
     backupLastLapInPits=0
     if len(self.lapTimesArray) < self.carsCount:
         for x in range(self.carsCount):
             c = ac.getCarState(x,acsys.CS.LapCount)
             self.driversLap.append(Value(c))
             self.lapTimesArray.append(lapTimeStart(c,sessionTimeLeft,0)) 
     else:
         for x in range(self.carsCount):
             c = ac.getCarState(x,acsys.CS.LapCount)
             self.driversLap[x].setValue(c)
             if self.driversLap[x].hasChanged():
                 self.lapTimesArray[x].lap=self.driversLap[x].value
                 self.lapTimesArray[x].time=sessionTimeLeft
             if bool(ac.isCarInPitline(x)) or bool(ac.isCarInPit(x)):
                 self.lapTimesArray[x].lastpit=c
             if x == self.currentVehicule.value:
                 backupLaptime=self.lapTimesArray[x].time-sessionTimeLeft
                 self.lastLapStart = self.lapTimesArray[x].time
                 backupLastLapInPits = self.lapTimesArray[x].lastpit
     
                         
     currentVehiculeChanged=self.currentVehicule.hasChanged()
                 
     if currentVehiculeChanged or (self.fastestLapBorderActive and sessionTimeLeft < self.visible_end-2000):
         self.fastestLapBorderActive = False
         car = ac.getCarName(self.currentVehicule.value)        
         self.lbl_border.setBgColor(Colors.colorFromCar(car))           
         
     if sim_info_status == 2:
         #LIVE
         strOffset = "  "
         #self.nameOffset=14
         if self.session.value != 2 :
             #NOT RACE
             #qtime 
             self.fastestLap.setValue(fl)         
             bestlap = ac.getCarState(self.currentVehicule.value,acsys.CS.BestLap)
             isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value)))
             LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount)
             if self.lastLap != LapCount:
                 self.lastLap = LapCount
                 self.firstLapStarted=False
                 if self.currentVehicule.value==0:
                     self.lastLapStart = sessionTimeLeft
             curLapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
             if curLapTime == 0 and backupLaptime > 0 and self.minLapCount > 0:
                 curLapTime = backupLaptime
             if curLapTime > 0:
                 self.firstLapStarted=True
             #if self.minLapCount == 0 and self.firstLapStarted and ((self.lastLapTime > curLapTime and curLapTime < 1000) or self.lastLapStart==10000):
             #    self.lastLapStart = sessionTimeLeft                  
             self.lastLapTime = curLapTime
                               
             if isInPit :
                 self.lastLapInPit = LapCount
                 self.lastTimeInPit = sessionTimeLeft
             if self.currentVehicule.value==0 and sim_info.physics.numberOfTyresOut >= 4 and self.lapCanBeInvalidated:
                 self.lastLapInvalidated = LapCount
             if isInPit and self.minLapCount == 0:
                 self.lastLapInvalidated = -1
             if self.sectorCount < 0:
                 self.sectorCount = sim_info.static.sectorCount    
             
             if self.fastestLap.value > 0:
                 for x in range(self.carsCount): 
                     c = ac.getCarState(x,acsys.CS.BestLap)
                     if self.fastestLap2.value == 0 or (c > 0 and c < self.fastestLap2.value):               
                         self.fastestLap2.setValue(c)
                         self.fastestLapSectors = ac.getLastSplits(x)
             else:
                 self.fastestLapSectors = [0,0,0,0,0,0]
                         
             #lapInvalidated = bool(ac.getCarState(0, acsys.CS.LapInvalidated))
             lapInvalidated = bool(self.lastLapInvalidated==LapCount)
             if currentVehiculeChanged or self.lbl_driver_name_text.value=="":
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
             #sector_delay = 5000
             # live or info      
             #ac.console("("+str(self.lastLapInPit)+" < "+str(LapCount)+" or "+str(self.minLapCount)+"==0) and not "+str(lapInvalidated)+" and ("+str(self.lastTimeInPit)+"==0 or "+str(self.lastTimeInPit)+" > "+str(self.lastLapStart)+")")            
             if ((self.lastLapStart < 0 and self.minLapCount > 0) or (self.minLapCount == 0 and lapInvalidated)) and self.session.value != 0:                    
                 self.lbl_driver_name_visible.setValue(0)
                 self.lbl_timing_visible.setValue(0)  
                 self.lbl_split.hideText()  
                 self.info_position.hide()
                 self.info_position_lead.hide()          
             elif (self.lastLapInPit < LapCount or self.minLapCount==0) and not lapInvalidated and (self.lastTimeInPit==0 or self.lastTimeInPit > self.lastLapStart or self.minLapCount==0) :
                 
                 if self.currentVehicule.value == 0:
                     sector = sim_info.graphics.currentSectorIndex
                 else:
                     sector = self.getSector()
                 
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_timing_visible.setValue(1)  
                 
                 #lapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
                 if self.currentVehicule.value == 0:
                     lastLap = sim_info.graphics.iLastTime
                 else: 
                     lastLap=0                       
                     lastSplits = ac.getLastSplits(self.currentVehicule.value)
                     for c in lastSplits:
                         lastLap+=c
                     if lastLap==0:
                         lastLap=ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap)
                         
                 
                 traite=False
                 cur_splits = ac.getCurrentSplits(self.currentVehicule.value)
                 timeSplit=0
                 fastestSplit=0
                 i=0
                 showSplit=False
                 for c in cur_splits: 
                     if c > 0:
                         timeSplit+=c 
                         fastestSplit+=self.fastestLapSectors[i]
                         i+=1
                 fastestSplit_fin=fastestSplit
                 if i < self.sectorCount:
                     fastestSplit_fin+=self.fastestLapSectors[i]
                      
                 #Situation
                 for s in range(0,self.sectorCount):                    
                     if self.fastestLap.value > 0 and curLapTime > fastestSplit_fin - self.sector_delay:
                         #LAST_SECONDS_OF_SECTOR_X, sector == s and
                         self.info_position.hide() 
                         self.nameOffset=self.rowHeight*14/36 #14
                         if self.sectorCount-1 == sector:
                             #LAST_SECONDS_OF_SECTOR_LAP,
                             self.lbl_split.setText(self.time_splitting(self.fastestLap.value,"yes")).setColor(Colors.white()).showText()
                             self.info_position_lead.show() 
                             
                             showSplit=True
                         elif fastestSplit_fin > 0:
                             self.lbl_split.setText(self.time_splitting(fastestSplit_fin,"yes")).setColor(Colors.white()).showText()
                             self.info_position_lead.show() 
                             showSplit=True
                         break
                     if sector == s + 1 and s + 1 <= self.sectorCount and curLapTime - timeSplit <= self.sector_delay and fastestSplit > 0 :
                         #SECTOR_X_FINISHED_BEGIN_SECTOR_Y    
                         self.nameOffset=self.rowHeight*14/36 #14            
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(timeSplit,"yes")) 
                         if fastestSplit < timeSplit:
                             self.lbl_split.setText("+"+self.time_splitting(timeSplit-fastestSplit,"yes")).setColor(Colors.yellow()).showText()
                         else:
                             self.lbl_split.setText("-"+self.time_splitting(fastestSplit-timeSplit,"yes")).setColor(Colors.green()).showText()
                         self.info_position_lead.show() 
                         self.info_position.hide()
                         traite=True
                         break
                 
                 if not traite:
                     if self.sectorCount-1 == sector and self.fastestLap.value > 0 and curLapTime > self.fastestLap.value - self.sector_delay:
                         #LAST_SECONDS_OF_SECTOR_LAP,
                         self.nameOffset=self.rowHeight*14/36 #14
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime)) 
                         self.info_position.hide()
                         #self.lbl_split.setText(self.time_splitting(self.fastestLap,"yes") + strOffset).setVisible(1)
                     elif self.lastLapInvalidated!=LapCount-1 and ((self.lastLapInPit!=LapCount-1 and sector == 0) or (self.minLapCount==0)) and curLapTime <= self.sector_delay and lastLap > 0:
                         #LAP_FINISHED_BEGIN_NEW_LAP,                       
                         pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                         if pos == -1:
                             pos = self.getStandingsPosition(self.currentVehicule.value)                                
             
                         if pos > 1:
                             self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(0.8)
                         else:
                             self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(0.8)
                         self.info_position.setText(str(pos))
                         self.info_position.show()
                         
                         self.nameOffset=self.rowHeight*49/36 #49
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(lastLap,"yes")) 
                         if self.fastestLap.value < lastLap:
                             self.lbl_split.setText("+"+self.time_splitting(lastLap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()
                         else:                            
                             self.lbl_split.setText("-"+self.time_splitting(self.getBestLap()-lastLap,"yes")).setColor(Colors.green()).showText()
                         self.info_position_lead.show() 
                         
                     else:
                         #OTHER
                         self.nameOffset=self.rowHeight*14/36 #14
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime))  
                         self.info_position.hide()
                         if not showSplit:
                             self.lbl_split.hideText()
                             self.info_position_lead.hide()
                 self.fastestLap.changed=False
             else :                    
                 self.info_position_lead.hide()                     
                 normalizedSplinePosition = ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition)
                 if normalizedSplinePosition <= 0.001:
                     normalizedSplinePosition=1
                 if sessionTimeLeft > 0 and self.minLapCount==1 and normalizedSplinePosition > 0.95 and not isInPit :          
                     self.lbl_driver_name_visible.setValue(1)
                     self.nameOffset=self.rowHeight*14/36 #14
                     self.lbl_timing_visible.setValue(1)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()
                     self.lbl_timing_text.setValue(strOffset + "0.0") 
                     
                 elif lapInvalidated and self.lastLapInPit < LapCount and self.minLapCount > 0 :
                     self.lbl_driver_name_visible.setValue(0)
                     self.lbl_timing_visible.setValue(0)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()  
                 elif bestlap > 0 :             
                     self.lbl_driver_name_visible.setValue(1)
                     self.lbl_timing_visible.setValue(1)  
                      
                     if self.fastestLap.value < bestlap:
                         self.lbl_split.setText("+"+self.time_splitting(bestlap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()                           
                     else:                            
                         self.lbl_split.hideText()
                     
                     self.lbl_timing_text.setValue(strOffset + self.time_splitting(bestlap,"yes")) 
                                         
                     self.nameOffset=self.rowHeight*49/36 #49
                     #pos = sim_info.graphics.position
                     pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                     if pos == -1:
                         pos = self.getStandingsPosition(self.currentVehicule.value) 
                     if pos > 1:
                         self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
                     else:
                         self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
                     self.info_position.setText(str(pos)).show()   
                     self.lbl_position_text.setValue(str(pos))                
                         
                 elif isInPit :     
                     self.lbl_driver_name_visible.setValue(0)
                     self.lbl_timing_visible.setValue(0)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()
                 else :
                     self.nameOffset=self.rowHeight*14/36 #14
                     self.lbl_driver_name_visible.setValue(1)
                     self.lbl_timing_visible.setValue(1)
                     if self.currentVehicule.value==0:
                         self.lbl_timing_text.setValue(strOffset + self.format_tire(sim_info.graphics.tyreCompound))
                     else:
                         self.lbl_timing_text.setValue(strOffset + "Out Lap")
                     self.lbl_split.hideText()
                     self.info_position.hide() 
                  
             if curLapTime <= self.sector_delay and ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap) > 0 and backupLastLapInPits + 1 < ac.getCarState(x,acsys.CS.LapCount) and sessionTimeLeft < 0:
                 self.nameOffset=self.rowHeight*49/36 #49
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_timing_visible.setValue(1)
                 self.lbl_split.showText()
                 self.info_position.show() 
                 #time vis
             self.visibilityQualif()
                 
         else:
             ################ Race ################
             self.info_position_lead.hide() 
             self.lbl_split.hideText()
             #fastest lap
             completed=0
             for x in range(self.carsCount): 
                 c = ac.getCarState(x,acsys.CS.LapCount)
                 if c > completed:
                     completed=c
             if completed <=1:
                 self.race_fastest_lap.setValue(0)
             else:
                 for i in range(self.carsCount): 
                     bl=ac.getCarState(i,acsys.CS.BestLap)
                     l = ac.getCarState(i,acsys.CS.LapCount)
                     if bl > 0 and l > self.minLapCount and (self.race_fastest_lap.value == 0 or bl < self.race_fastest_lap.value):
                         self.race_fastest_lap.setValue(bl)
                         self.race_fastest_lap_driver.setValue(i)
                     
             if self.race_fastest_lap.hasChanged() and self.race_fastest_lap.value > 0:
                 self.fastestLapBorderActive = True
                 car = ac.getCarName(self.race_fastest_lap_driver.value)        
                 self.lbl_border.setBgColor(Colors.colorFromCar(car))            
                 self.visible_end = sessionTimeLeft - 8000
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.race_fastest_lap_driver.value)))
                 self.nameOffset=self.rowHeight*14/36 #14
                 self.lbl_timing_text.setValue(strOffset + "Fastest Lap")
                 self.lbl_timing_visible.setValue(1)
                 self.info_position.hide() 
                 self.lbl_fastest_split.setText(self.time_splitting(self.race_fastest_lap.value,"yes")).showText()
                 
             elif currentVehiculeChanged:  
                 #driver info                  
                 self.visible_end = sessionTimeLeft - 8000
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
                 self.nameOffset=self.rowHeight*49/36 #49
                 #pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                 pos = ac.getCarRealTimeLeaderboardPosition(self.currentVehicule.value) + 1
                 if pos > 1:
                     self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
                 else:
                     self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
                 self.info_position.setText(str(pos)).show() 
                 self.lbl_timing_visible.setValue(0)
                 self.lbl_fastest_split.hideText()
             elif self.visible_end == 0 or sessionTimeLeft < self.visible_end or sessionTimeLeft > 1800000:
                 self.lbl_driver_name_visible.setValue(0)
                 self.info_position.hide()
                 self.lbl_timing_visible.setValue(0)
                 self.lbl_fastest_split.hideText()
                 
             self.visibilityRace()
                 
     elif sim_info_status == 1 and self.session.value != 2:
         #Replay Qualif
         strOffset = "  "
         showSplit=False
         LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount)
         curLapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
         isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value)))
         if currentVehiculeChanged or self.lbl_driver_name_text.value=="":
             self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
         if isInPit:
             self.lbl_driver_name_visible.setValue(0)
             self.lbl_timing_visible.setValue(0)  
             self.lbl_split.hideText()  
             self.info_position.hide()
         elif curLapTime <= self.sector_delay and LapCount > 1:
             #show last lap
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             if self.currentVehicule.value == 0:
                 lastLap = sim_info.graphics.iLastTime
             else: 
                 lastLap=0                       
                 lastSplits = ac.getLastSplits(self.currentVehicule.value)
                 for c in lastSplits:
                     lastLap+=c
                 if lastLap==0:
                     lastLap=ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap)
             pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
             if pos == -1:
                 pos = self.getStandingsPosition(self.currentVehicule.value)                                
 
             if pos > 1:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(0.8)
             else:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(0.8)
             self.info_position.setText(str(pos))
             self.info_position.show()
             self.nameOffset=self.rowHeight*49/36 #49
             self.lbl_timing_text.setValue(strOffset + self.time_splitting(lastLap,"yes")) 
             if self.fastestLap.value < lastLap:
                 self.lbl_split.setText("+"+self.time_splitting(lastLap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()
             else:                            
                 self.lbl_split.setText("-"+self.time_splitting(self.fastestLap.old-lastLap,"yes")).setColor(Colors.green()).showText()
             self.info_position_lead.show()
             self.fastestLap.changed=False
         elif LapCount > self.minLapCount:
             #showTiming
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             self.info_position_lead.hide() 
             self.nameOffset=self.rowHeight*14/36 #14
             self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime))  
             self.info_position.hide()
             if not showSplit:
                 self.lbl_split.hideText()
                 self.info_position_lead.hide()
         else:
             #showTireInfo
             self.info_position_lead.hide() 
             self.nameOffset=self.rowHeight*14/36 #14
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             if self.currentVehicule.value==0:
                 self.lbl_timing_text.setValue(strOffset + self.format_tire(sim_info.graphics.tyreCompound))
             else:
                 self.lbl_timing_text.setValue(strOffset + "Out Lap")
             self.lbl_split.hideText()
             self.info_position.hide()            
         
         self.visibilityQualif()
             
             
         
     elif sim_info_status == 1 and self.session.value == 2:
         #Replay Race
         todo=1
         '''
         if currentVehiculeChanged:
             self.visible_end = sessionTimeLeft - 8000
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
             self.nameOffset=self.rowHeight*49/36 #49
             pos = ac.getCarRealTimeLeaderboardPosition(self.currentVehicule.value) + 1
             if pos > 1:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
             else:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
             self.info_position.setText(str(pos)).show() 
             self.lbl_timing_visible.setValue(0)
             self.lbl_fastest_split.hideText()
             
             if self.lbl_driver_name_visible.hasChanged():         
                 if self.lbl_driver_name_visible.value == 0:
                     self.lbl_driver_name.hide()
                     self.lbl_border.hide()
                 else:
                     self.lbl_driver_name.show()
                     self.lbl_border.show()
                 
             if self.lbl_timing_visible.hasChanged():         
                 if self.lbl_timing_visible.value == 0:
                     self.lbl_timing.hide()
                 else:
                     self.lbl_timing.show()
                     
             if self.lbl_driver_name_text.hasChanged():
                 self.lbl_driver_name.setText(self.lbl_driver_name_text.value)  
             if self.lbl_timing_text.hasChanged():
                 self.lbl_timing.setText(self.lbl_timing_text.value,hidden=bool(self.lbl_timing_height < 30)) 
         '''
     else:
         #REPLAY
         self.resetVisibility()
Example #12
0
    def onUpdate(self, sim_info):
        if self.__class__.configChanged:
            self.saveCFG()
            self.__class__.configChanged = False
        if not self.deltaLoaded:
            thread_load = threading.Thread(target=self.loadDelta)
            thread_load.daemon = True
            thread_load.start()
        if self.__class__.resetPressed:
            self.referenceLapTime.setValue(0)
            self.referenceLap = []
            self.__class__.resetPressed = False
        self.session.setValue(sim_info.graphics.session)
        self.manageWindow()
        self.lbl_delta.animate()
        self.lbl_lap.animate()
        sim_info_status = sim_info.graphics.status
        if sim_info_status == 2:  # LIVE
            sessionTimeLeft = sim_info.graphics.sessionTimeLeft
            if math.isinf(
                sessionTimeLeft
            ):  # or (sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0):
                self.resetData()
            elif self.session.value == 2 and sessionTimeLeft > 1800000:
                self.resetData()
            elif bool(ac.isCarInPitline(0)) or bool(ac.isCarInPit(0)):
                self.resetData()
            self.spline.setValue(round(ac.getCarState(0, acsys.CS.NormalizedSplinePosition), 3))

            if self.lastLapIsValid and sim_info.physics.numberOfTyresOut >= 4:
                self.lastLapIsValid = False

            if self.spline.hasChanged():
                self.laptime.setValue(round(ac.getCarState(0, acsys.CS.LapTime), 3))
                self.lastLapTime.setValue(ac.getCarState(0, acsys.CS.LastLap))
                gap = self.getPerformanceGap(self.spline.value, self.laptime.value)
                if gap != False:
                    self.performance.setValue(gap)
                # new lap
                if self.lastLapTime.hasChanged():
                    # ac.console("newlap----")(self.laptime.old > self.laptime.value) or
                    # ac.console("lastLap=currentLap---waiting " + str(self.laptime.old) + ":" + str(self.laptime.value))
                    # ac.log(str(time.time()) +" lastLap=currentLap---waiting " + str(self.laptime.old) + ":" + str(self.laptime.value))
                    if (
                        (self.referenceLapTime.value == 0 or self.lastLapTime.value < self.referenceLapTime.value)
                        and self.lastLapIsValid
                        and self.lastLapTime.value > 0
                        and self.lapCount < ac.getCarState(0, acsys.CS.LapCount)
                    ):
                        self.referenceLapTime.setValue(self.lastLapTime.value)
                        # self.referenceLap=list(self.lastLap)
                        self.referenceLap = list(self.currentLap)
                        if len(self.referenceLap) > 2000:  # 2laps in
                            ac.console("too many laps in reference----")
                            ac.log("too many laps in reference----")
                            how_much = math.floor(len(self.referenceLap) / 1000)
                            del self.referenceLap[0 : math.floor(len(self.referenceLap) / how_much)]
                        # self.referenceLap=self.lastLap#self.lastLap=list(self.currentLap)
                        # ac.log(str(time.time()) +" referenceLap=lastlap --- lets save")
                        # ac.console("referenceLap=lastlap --- lets save")
                        thread_save = threading.Thread(target=self.saveDelta)
                        thread_save.daemon = True
                        thread_save.start()
                        # make it green for 5 sec
                        self.highlight_end = sim_info.graphics.sessionTimeLeft - 6000
                        self.lbl_lap.setColor(Colors.green(), True)
                    # else:
                    #    ac.log(str(time.time()) +" dismissed")
                    # self.lastLap=self.currentLap
                    self.currentLap = []
                    self.lapCount = ac.getCarState(0, acsys.CS.LapCount)
                    self.lastLapIsValid = True

                self.currentLap.append(raceGaps(self.spline.value, self.laptime.value))
                # ac.console("--currentLap : " + str(len(self.currentLap)) + " --lastLap : " + str(len(self.lastLap)) + " --referenceLap : " + str(len(self.referenceLap)))

            # update graphics
            if not math.isinf(sessionTimeLeft):
                self.TimeLeftUpdate.setValue(int(sessionTimeLeft / 500))
            if self.TimeLeftUpdate.hasChanged():
                if self.performance.hasChanged():
                    time_prefix = ""
                    color = Colors.white()
                    if self.performance.value > 0:
                        time_prefix = "+"
                        if self.lastLapIsValid:
                            color = Colors.yellow()
                        else:
                            color = Colors.red()
                    elif self.performance.value < 0:
                        time_prefix = "-"
                        if self.lastLapIsValid:
                            color = Colors.green()
                        else:
                            color = Colors.orange()
                    else:
                        if not self.lastLapIsValid:
                            color = Colors.red()
                    self.lbl_delta.setText(
                        time_prefix + self.time_splitting(abs(self.performance.value), "yes")
                    ).setColor(color, True)

            if self.referenceLapTime.hasChanged():
                self.lbl_lap.setText(self.time_splitting(self.referenceLapTime.value, "yes"))
            if self.highlight_end == 0 or sessionTimeLeft < self.highlight_end:
                self.lbl_lap.setColor(Colors.white(), True)
Example #13
0
 def in_pit(self):
     return ac.isCarInPit(self._player)
Example #14
0
def acUpdate(deltaT):
    global l_lapcount, l_speed, lapcount, targetfile, tick, speed, clap_top_speed, llap_top_speed, tspeed_session, q, sessionid, fuel, currentLapTime, lapInvalidated, session, carInPit, carInPitLane

    if tick.tack(
            deltaT
    ):  #does not bother CPU with unnecessary updates, basically exits the update function call if time is less than value specified in ticker()
        return
    if info.graphics.status != 2:  # AC_LIVE = 2, exits update if paused, replay or off
        return

    session_type = info.graphics.session
    currentLapTime = ac.getCarState(0, acsys.CS.LapTime)
    lapInvalidated = ac.getCarState(0, acsys.CS.LapInvalidated)
    carInPitLane = ac.isCarInPitlane(0)
    carInPit = ac.isCarInPit(0)
    fuel = round(info.physics.fuel, 3)
    cgH = info.physics.cgHeight
    fRH, rRH = info.physics.rideHeight
    psiFL, psiFR, psiRL, psiRR = ac.getCarState(0, acsys.CS.DynamicPressure)
    stfl, stfr, strl, strr = info.physics.suspensionTravel
    slflN, slfrN, slrlN, slrrN = info.physics.wheelLoad
    wFL, wFR, wRL, wRR = info.physics.tyreWear
    ctFL, ctFR, ctRL, ctRR = info.physics.tyreCoreTemperature
    laps = ac.getCarState(0, acsys.CS.LapCount) + 1
    speed = round(ac.getCarState(0, acsys.CS.SpeedMPH), 2)
    ac.setText(l_speed, "Speed: {} MPH".format(speed))
    ac.setText(l_fuel, "Fuel Level: {} L".format(fuel))
    q.query(
        qconnection.MessageType.SYNC,
        '`{t} insert (.z.P; {st}; {l}; {iPL}; {iP}; {ltms}; {linv}; \
                                         {s}; {f}; {frh}; {rrh}; {cgrh}; \
                                         {pFL}; {pFR}; {pRL}; {pRR}; {ctfl}; {ctfr}; {ctrl}; {ctrr}; \
                                         {wfl}; {wfr}; {wrl}; {wrr}; {sTfl}; {sTfr}; {sTrl}; {sTrr}; \
                                         {sLfl}; {sLfr}; {sLrl}; {sLrr})'.
        format(st=session_type,
               t=sessionid,
               l=laps,
               iPL=carInPitLane,
               iP=carInPit,
               ltms=currentLapTime,
               linv=lapInvalidated,
               s=speed,
               f=fuel,
               frh=fRH,
               rrh=rRH,
               cgrh=cgH,
               pFL=psiFL,
               pFR=psiFR,
               pRL=psiRL,
               pRR=psiRR,
               ctfl=ctFL,
               ctfr=ctFR,
               ctrl=ctRL,
               ctrr=ctRR,
               wfl=wFL,
               wfr=wFR,
               wrl=wRL,
               wrr=wRR,
               sTfl=stfl,
               sTfr=stfr,
               sTrr=strr,
               sTrl=strl,
               sLfl=slflN,
               sLfr=slfrN,
               sLrr=slrrN,
               sLrl=slrlN))

    if speed > clap_top_speed:
        clap_top_speed = speed
        ac.setText(l_tspeed_clap,
                   "Current Lap Top Speed: {} MPH".format(clap_top_speed))

    if speed > tspeed_session:
        tspeed_session = speed
        ac.setText(l_tspeed_session,
                   "Session Top Speed: {} MPH".format(tspeed_session))

    if laps > lapcount:
        lapcount = laps
        llap_top_speed = clap_top_speed
        clap_top_speed = 0
        ac.setText(l_lapcount, "Lap: {}".format(
            lapcount))  #updates the label in the App Window defined on acMain
        ac.setText(l_tspeed_llap,
                   "Last Lap Top Speed: {} MPH".format(llap_top_speed))

    if session_type == -1:
        ac.setText(l_session_type, "Session Type: {}".format('Unknown'))
    else:
        ac.setText(l_session_type,
                   "Session Type: {}".format(session[session_type]))
Example #15
0
def updateSharedMemory():
    global sharedMem
    global packetID

    sharedmem = sharedMem.getsharedmem()
    sharedmem.packetID = -1
    sharedmem.numVehicles = ac.getCarsCount()
    sharedmem.focusVehicle = ac.getFocusedCar()

    carIds = range(0, ac.getCarsCount(), 1)

    for carId in carIds:
        if str(ac.getCarName(carId)) == '-1':
            break
        else:
            sharedmem.vehicleInfo[carId].carId = carId
            sharedmem.vehicleInfo[carId].driverName = ac.getDriverName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].carModel = ac.getCarName(
                carId).encode('utf-8')
            sharedmem.vehicleInfo[carId].speedMS = ac.getCarState(
                carId, acsys.CS.SpeedMS)
            sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState(
                carId, acsys.CS.BestLap)
            sharedmem.vehicleInfo[carId].lapCount = ac.getCarState(
                carId, acsys.CS.LapCount)
            sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState(
                carId, acsys.CS.LapInvalidated)
            sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState(
                carId, acsys.CS.LapTime)
            sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState(
                carId, acsys.CS.LastLap)
            sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState(
                carId, acsys.CS.WorldPosition)
            sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline(
                carId)
            sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId)
            sharedmem.vehicleInfo[
                carId].carLeaderboardPosition = ac.getCarLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[
                carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(
                    carId)
            sharedmem.vehicleInfo[carId].splinePosition = ac.getCarState(
                carId, acsys.CS.NormalizedSplinePosition)
            sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId)

            if libInit == 1 and carId == 0:
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    0] = funcGetSuspensionDamage(carId, 0)
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    1] = funcGetSuspensionDamage(carId, 1)
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    2] = funcGetSuspensionDamage(carId, 2)
                sharedmem.vehicleInfo[carId].suspensionDamage[
                    3] = funcGetSuspensionDamage(carId, 3)
                sharedmem.vehicleInfo[
                    carId].engineLifeLeft = funcGetEngineLifeLeft(carId)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    0] = funcGetTyreInflation(carId, 0)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    1] = funcGetTyreInflation(carId, 1)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    2] = funcGetTyreInflation(carId, 2)
                sharedmem.vehicleInfo[carId].tyreInflation[
                    3] = funcGetTyreInflation(carId, 3)

    packetID = packetID + 1
    sharedmem.packetID = packetID
Example #16
0
    def on_update(self, sim_info, standings, game_data):
        session_time_left = game_data.sessionTimeLeft
        sim_info_status = game_data.status
        self.standings = standings
        if self.is_multiplayer:
            self.numCars = 0
        for i in range(self.cars_count):
            if ac.isConnected(i) > 0:
                if self.is_multiplayer:
                    self.numCars += 1
                self.drivers_lap_count[i].setValue(
                    ac.getCarState(i, acsys.CS.LapCount))
                if self.last_lap_start[i] == -1 and session_time_left != 0:
                    self.last_lap_start[i] = session_time_left
                if self.drivers_lap_count[i].hasChanged(
                ) and session_time_left != 0:
                    self.last_lap_start[i] = session_time_left
                    # if PB save delta
                    if ac.getCarState(i, acsys.CS.LastLap) <= ac.getCarState(
                            i, acsys.CS.BestLap):
                        self.reference_lap_time_others[i] = list(
                            self.current_lap_others[i])
                        if len(self.reference_lap_time_others[i]
                               ) > 2000:  # 2laps in
                            how_much = math.floor(
                                len(self.reference_lap_time_others[i]) / 1000)
                            del self.reference_lap_time_others[i][0:math.floor(
                                len(self.reference_lap_time_others[i]) /
                                how_much)]
                    # reset
                    self.current_lap_others[i] = []
                # Deltas
                self.spline_others[i].setValue(
                    round(ac.getCarState(i, acsys.CS.NormalizedSplinePosition),
                          3))
                if self.is_touristenfahrten and self.spline_others[
                        i].value == 0.953:
                    self.last_lap_start[i] = session_time_left
                    self.current_lap_others[i] = []
                if ac.isCarInPit(i) or ac.isCarInPitline(i):
                    self.current_lap_others[i] = []
                if self.spline_others[i].hasChanged(
                ) and session_time_left != 0:
                    self.current_lap_others[i].append(
                        raceGaps(self.spline_others[i].value,
                                 self.last_lap_start[i] - session_time_left))

        if not self.deltaLoaded and Configuration.save_delta:
            thread_load = threading.Thread(target=self.load_delta)
            thread_load.daemon = True
            thread_load.start()
        if self.__class__.resetPressed:
            self.referenceLapTime.setValue(0)
            self.referenceLap = []
            self.lastLapTime.setValue(0)
            self.spline.setValue(0)
            self.__class__.resetPressed = False
        if self.__class__.importPressed:
            self.referenceLap = self.reference_lap_time_others[
                self.currentVehicle.value]
            self.referenceLapTime.setValue(
                ac.getCarState(self.currentVehicle.value, acsys.CS.BestLap))
            '''
            self.lastLapTime.setValue(0)
            self.spline.setValue(0)
            '''
            self.__class__.importPressed = False
        self.session.setValue(game_data.session)
        self.manage_window(game_data)
        self.animate()
        self.currentVehicle.setValue(game_data.focusedCar)
        self.current_car_class.setValue(
            self.get_class_id(self.currentVehicle.value))
        if self.currentVehicle.hasChanged(
        ) or self.current_car_class.hasChanged():
            # number, curtime...
            if Configuration.names == 1:
                self.lbl_name_text.setText(
                    self.format_name_tlc2(
                        ac.getDriverName(self.currentVehicle.value)))
            else:
                self.lbl_name_text.setText(
                    self.format_name_tlc(
                        ac.getDriverName(self.currentVehicle.value)))
            self.lbl_number_text.setText(self.get_driver_number())
            #car_name=ac.getCarName(self.currentVehicle.value)
            self.lbl_number_bg.set(background=Colors.color_for_car_class(
                self.current_car_class.value),
                                   init=True)
            self.lbl_number_text.set(color=Colors.txt_color_for_car_class(
                self.current_car_class.value),
                                     init=True)
            self.performance_display = 0
        completed_laps = ac.getCarState(self.currentVehicle.value,
                                        acsys.CS.LapCount)
        self.lbl_laps_completed_text.setText(str(completed_laps))
        self.lbl_laps_completed_text_shadow.setText(str(completed_laps))
        if completed_laps > 1:
            self.lbl_laps_text.setText("LAPS")
            self.lbl_laps_text_shadow.setText("LAPS")
        else:
            self.lbl_laps_text.setText("LAP")
            self.lbl_laps_text_shadow.setText("LAP")

        if sim_info_status == 2:  # LIVE
            if session_time_left == 0 or game_data.beforeRaceStart:
                self.reset_data()
                self.reset_others()
                if not Configuration.save_delta:
                    self.referenceLapTime.setValue(0)
                    self.referenceLap = []
                    self.lastLapTime.setValue(0)
                    self.spline.setValue(0)
            elif self.currentVehicle.value == 0 and bool(
                    ac.isCarInPitline(0)) or bool(ac.isCarInPit(0)):
                self.reset_data()
            self.spline.setValue(
                round(
                    ac.getCarState(self.currentVehicle.value,
                                   acsys.CS.NormalizedSplinePosition), 3))
            #Current lap time
            if self.currentVehicle.value != 0 and self.last_lap_start[
                    self.currentVehicle.
                    value] != -1 and session_time_left != 0:
                self.lbl_current_time_text.setText(
                    self.time_splitting_full(
                        self.last_lap_start[self.currentVehicle.value] -
                        session_time_left))
            else:
                self.lbl_current_time_text.setText(
                    self.time_splitting_full(
                        ac.getCarState(self.currentVehicle.value,
                                       acsys.CS.LapTime)))
            if self.currentVehicle.value == 0 and not self.lastLapIsValid:
                self.lbl_current_time_text.set(color=Colors.red(),
                                               animated=True)
            else:
                self.lbl_current_time_text.set(color=Colors.white(),
                                               animated=True)

            if self.currentVehicle.value == 0 and self.lastLapIsValid and sim_info.physics.numberOfTyresOut >= 4:
                self.lastLapIsValid = False

            if self.spline.hasChanged():
                if self.currentVehicle.value == 0:
                    self.laptime.setValue(
                        round(
                            ac.getCarState(self.currentVehicle.value,
                                           acsys.CS.LapTime), 3))
                    self.lastLapTime.setValue(
                        ac.getCarState(self.currentVehicle.value,
                                       acsys.CS.LastLap))
                    gap = self.get_performance_gap(self.spline.value,
                                                   self.laptime.value)
                    if gap != False:
                        self.performance.setValue(gap)
                    if self.lastLapTime.value > 0:
                        self.lbl_last_time_text.setText(
                            self.time_splitting(self.lastLapTime.value, "yes"))
                    else:
                        self.lbl_last_time_text.setText("--:--.---")
                    # new lap
                    if self.lastLapTime.hasChanged():
                        if (
                                self.referenceLapTime.value == 0
                                or self.lastLapTime.value <
                                self.referenceLapTime.value
                        ) and self.lastLapIsValid and self.lastLapTime.value > 0 and self.lapCount < ac.getCarState(
                                0, acsys.CS.LapCount):
                            #if self.lastLapTime.value > 0:
                            #    self.lbl_last_time_text.setText(self.time_splitting(self.lastLapTime.value, "yes"))
                            #else:
                            #    self.lbl_last_time_text.setText("--:--.---")
                            self.referenceLapTime.setValue(
                                self.lastLapTime.value)
                            self.referenceLap = list(self.currentLap)
                            if len(self.referenceLap) > 2000:  # 2laps in
                                ac.console("too many laps in reference----")
                                ac.log("too many laps in reference----")
                                how_much = math.floor(
                                    len(self.referenceLap) / 1000)
                                del self.referenceLap[0:math.floor(
                                    len(self.referenceLap) / how_much)]
                            if self.currentVehicle.value == 0 and Configuration.save_delta and len(
                                    self.referenceLap) > 20:
                                thread_save = threading.Thread(
                                    target=self.save_delta)
                                thread_save.daemon = True
                                thread_save.start()

                        self.currentLap = []
                        self.lapCount = ac.getCarState(
                            self.currentVehicle.value, acsys.CS.LapCount)
                        self.lastLapIsValid = True

                    self.currentLap.append(
                        raceGaps(self.spline.value, self.laptime.value))

                    self.best_lap_time = self.referenceLapTime.value
                    self.performance_display = self.performance.value
                else:
                    gap = self.get_performance_gap(
                        self.spline.value,
                        self.last_lap_start[self.currentVehicle.value] -
                        session_time_left)
                    if gap != False:
                        self.performance_display = gap
                    #else:
                    #    self.performance_display = ac.getCarState(self.currentVehicle.value, acsys.CS.PerformanceMeter)
                    self.best_lap_time = ac.getCarState(
                        self.currentVehicle.value, acsys.CS.BestLap)
                    last_lap = ac.getCarState(self.currentVehicle.value,
                                              acsys.CS.LastLap)
                    if last_lap > 0:
                        self.lbl_last_time_text.setText(
                            self.time_splitting(last_lap, "yes"))
                    else:
                        self.lbl_last_time_text.setText("--:--.---")

            #update rate
            self.TimeLeftUpdate.setValue(int(session_time_left / 500))
            if self.TimeLeftUpdate.hasChanged():
                # update graphics

                # position
                if self.session.value != 2:
                    pos = self.get_standings_position(
                        self.currentVehicle.value)
                else:
                    pos = self.get_race_standings_position(
                        self.currentVehicle.value)
                if pos > self.numCars:
                    pos = self.numCars

                if Colors.multiCarsClasses:
                    # Position in class
                    pos_class = self.get_race_standings_position_in_class(
                        self.currentVehicle.value)
                    self.lbl_position_text.setText(str(pos_class[0]))
                    self.lbl_position_text_shadow.setText(str(pos_class[0]))
                    self.lbl_position_total_text.setText("/{0}".format(
                        pos_class[1]))
                    self.lbl_position_total_text_shadow.setText("/{0}".format(
                        pos_class[1]))
                    # Position in overall
                    self.lbl_position_text_multi.setText(str(pos)).show()
                    self.lbl_position_text_multi_shadow.setText(
                        str(pos)).show()
                    self.lbl_position_total_text_multi.setText("/{0}".format(
                        self.numCars)).show()
                    self.lbl_position_total_text_multi_shadow.setText(
                        "/{0}".format(self.numCars)).show()
                else:
                    # Position in overall
                    self.lbl_position_text.setText(str(pos))
                    self.lbl_position_text_shadow.setText(str(pos))
                    self.lbl_position_total_text.setText("/{0}".format(
                        self.numCars))
                    self.lbl_position_total_text_shadow.setText("/{0}".format(
                        self.numCars))
                    self.lbl_position_text_multi.hide()
                    self.lbl_position_text_multi_shadow.hide()
                    self.lbl_position_total_text_multi.hide()
                    self.lbl_position_total_text_multi_shadow.hide()

                # flags
                flag = game_data.flag
                if flag == 1:
                    # AC_BLUE_FLAG Flag
                    self.lbl_flag.set(background=Colors.blue_flag()).show()
                elif flag == 2:
                    # AC_YELLOW_FLAG Flag
                    self.lbl_flag.set(background=Colors.
                                      timer_border_yellow_flag_bg()).show()
                    self.last_yellow_flag_end = session_time_left
                elif flag == 3 or flag == 6:
                    # AC_BLACK_FLAG,AC_PENALTY_FLAG
                    self.lbl_flag.set(background=Colors.black()).show()
                elif flag == 4:
                    # AC_WHITE_FLAG
                    self.lbl_flag.set(background=Colors.white(bg=True)).show()
                elif ac.getCarState(self.currentVehicle.value,
                                    acsys.CS.RaceFinished) == 1:  #flag == 5
                    # AC_CHECKERED_FLAG
                    self.lbl_flag.set(background=Colors.flag_finish()).show()
                elif self.last_yellow_flag_end != False and self.last_yellow_flag_end - 4000 <= session_time_left:
                    # Green flag
                    self.lbl_flag.set(
                        background=Colors.timer_border_bg()).show()
                else:
                    self.lbl_flag.hide()

                if self.best_lap_time > 0:
                    self.lbl_best_time_text.setText(
                        self.time_splitting(self.best_lap_time, "yes"))
                else:
                    self.lbl_best_time_text.setText("--:--.---")
                if self.best_lap_time > 0:  # and self.currentVehicle.value == 0
                    time_prefix = "+"
                    color = Colors.delta_neutral()
                    if self.performance_display >= 10:
                        time_prefix = "+"
                        color = Colors.delta_positive()
                    elif self.performance_display <= -10:
                        time_prefix = "-"
                        color = Colors.delta_negative()
                    self.lbl_delta_bg.set(background=color, animated=True)
                    txt_delta = time_prefix + self.time_splitting_delta(
                        abs(self.performance_display))
                    self.lbl_delta_text.set(
                        font_size=self.font_size +
                        self.rowHeight.value * 3 / 38 -
                        ((len(txt_delta) - 5) * self.rowHeight.value * 4 / 38),
                        animated=True).setText(txt_delta)
                    if self.performance_display < self.best_lap_time:
                        self.lbl_prediction_time_text.setText(
                            self.time_splitting(
                                self.best_lap_time + self.performance_display,
                                "yes"))
                    else:
                        self.lbl_prediction_time_text.setText("--:--.---")
                else:
                    self.lbl_delta_bg.set(background=Colors.delta_neutral(),
                                          animated=True)
                    self.lbl_delta_text.set(font_size=self.font_size +
                                            self.rowHeight.value * 4 / 38,
                                            animated=True).setText("-.--")
                    self.lbl_prediction_time_text.setText("--:--.---")
Example #17
0
 def isInPitBox(car=0):
     return ac.isCarInPit(car)
Example #18
0
 def onUpdate(self, sim_info):   
     self.session.setValue(sim_info.graphics.session)  
     sessionTimeLeft=sim_info.graphics.sessionTimeLeft
     sim_info_status=sim_info.graphics.status
     if (sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0) or sessionTimeLeft >= 1800000:  
         self.resetVisibility() 
         self.time_end = 0
     self.manageWindow()
     if self.carsCount==0:
         self.carsCount = ac.getCarsCount()
     for x in range(self.carsCount):
         c = ac.getCarState(x,acsys.CS.SpeedKMH)
         if x==0 and self.topSpeed.value < c:
             self.userTopSpeed.setValue(c)
             self.userTrap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition)
             
         if self.relyOnEveryOne and self.topSpeed.value < c and ac.getCarState(x,acsys.CS.DriveTrainSpeed) > c/10 and ac.getCarState(x,acsys.CS.Gas) > 0.9 and ac.getCarState(x,acsys.CS.RPM) > 2000:
             if c > 500:
                 self.relyOnEveryOne=False
                 self.topSpeed.setValue(self.userTopSpeed.value)
                 self.trap = self.userTrap 
                 #ac.console("stop rely")
                 #ac.log("stop rely")
             else:
                 self.topSpeed.setValue(c)
                 #ac.console(str(c) + "-"+str(x)+"-rpm:"+str(ac.getCarState(x,acsys.CS.RPM))+"-Gas:"+str(ac.getCarState(x,acsys.CS.Gas))+"-Gear:"+str(ac.getCarState(x,acsys.CS.Gear))+"-DriveTrainSpeed:"+str(ac.getCarState(x,acsys.CS.DriveTrainSpeed))) 
                 self.trap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition) 
         elif not self.relyOnEveryOne and x == 0 and self.topSpeed.value < c:
             self.topSpeed.setValue(c)
             self.trap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition)      
     
     self.currentVehicule.setValue(ac.getFocusedCar())     
     self.SpeedKMH.setValue(ac.getCarState(self.currentVehicule.value,acsys.CS.SpeedKMH))
     self.SpeedMPH.setValue(ac.getCarState(self.currentVehicule.value,acsys.CS.SpeedMPH))
     LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount)                   
     
     if self.curTopSpeed.value < self.SpeedKMH.value:
         self.curTopSpeed.setValue(self.SpeedKMH.value) 
         self.curTopSpeedMPH.setValue(self.SpeedMPH.value)         
     if self.currentVehicule.value==0 and sim_info.physics.numberOfTyresOut >= 4 and self.lapCanBeInvalidated:
         self.lastLapInvalidated = LapCount
     self.animate()
     
     if sim_info_status == 2:
         if self.session.value <= 2  :                
             #Qual-Practise every time
             #isInPit = self.currentVehicule.value==0 and bool(sim_info.physics.pitLimiterOn)
             isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value)))
                                   
             if isInPit :
                 self.lastLapInPit = LapCount
             
             if self.lastLapInPit < LapCount and self.curTopSpeed.value < 500 and self.lastLapShown < LapCount and self.lastLapInvalidated < LapCount and self.widget_visible.value == 0 and self.trap < ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition) + 0.06 and self.trap > ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition) - 0.08 and self.SpeedKMH.value < self.SpeedKMH.old - 0.6:
                 
                 #show and set timer 0.3
                 self.lastLapShown=LapCount
                 self.widget_visible.setValue(1)
                 if self.useMPH:
                     self.speedText="%.1f mph"%(self.curTopSpeedMPH.value)
                 else:
                     self.speedText="%.1f kph"%(self.curTopSpeed.value)
                 self.time_end = sessionTimeLeft - 9000
                 self.lbl_title.setText("S",hidden=True)
                 self.lbl_time.setText(self.speedText,hidden=True)
                 self.lbl_time.show()
                 self.lbl_border.show()
                 self.lbl_title.show()
             elif self.time_end == 0 or sessionTimeLeft < self.time_end:
                 self.lbl_time.hide()
                 self.lbl_border.hide()
                 self.lbl_title.hide()
                 self.widget_visible.setValue(0)
                 self.time_end=0
                 if self.widget_visible.hasChanged():                        
                     self.curTopSpeed.setValue(0)                      
                     self.curTopSpeedMPH.setValue(0)                   
            
         else:       
             self.resetVisibility()     
                 
     elif sim_info_status == 1:  
         self.resetVisibility()