Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- # Copyright (C) 2015 - Murilo Faria
- # Version: 1.0.5
- #TODO:
- #CHECK THE ZIPPED PY FOR UPDATES
- import os
- import sys
- import configparser
- import ac
- import acsys
- import datetime
- import win32con
- from time import clock, localtime, strftime
- import platform
- if platform.architecture()[0] == "64bit":
- sysdir=os.path.dirname(__file__)+'/stdlib64'
- else:
- sysdir=os.path.dirname(__file__)+'/stdlib'
- sys.path.insert(0, sysdir)
- os.environ['PATH'] = os.environ['PATH'] + ";."
- import ctypes
- from ctypes import wintypes
- #from sim_info import info
- import sim_info
- import threading
- windowx = 110
- windowy = windowx * 0.4181818181818182
- scale_mult = windowx/110
- windowsscale = 2.3913
- compound = None #tyre compound
- #labels = {}
- appWindow = 0
- startTracking = False
- lastPOT = 0.0 # "POS0.00"
- dic = {}
- lastTime = 0.0
- lastClock = 0.0
- lastLapTime = 0.0
- lastRealTime = 0.0
- TimeOfLastOff = 0.0
- recentDelta = 0.0
- pitOffset = 0.0
- bSetOffset = 0
- lastF10Click = 0
- deltaStringFormat = "%.2f"
- trend = 0
- alpha = 1.0
- backgroundOpacity = 1.0
- drawBorderVar = 1
- fullSpeed = 0
- prevDelta = 0.0
- InitialPosition = 0
- Range = 0.06 # originaly 0.001, but this would ultimately depend on the length of the track
- SettingsINI = 'apps\python\EsoticDelta\settings.ini'
- AdjustIntensity = 1
- ResetDuringPit = 0
- ResetDuringQualification = 1
- ResetDuringPractice = 1
- HideIcon = 1
- ResetOnCompoundSwitch = 1
- UsePitOffset = 1
- LastStatus = 0
- LastSession = 0
- LapValid = 1
- displayLabel = 0
- ShowLapTimeDelay = 4000.0 #time (in milliseconds) to show the last lap time
- allowedtyresout = 4 #default to not tracking valid laps
- veritcalAdjust = -3 #ADD TO INI?
- MinKPH = 0
- MaxKPH = 0
- #reset camera while pitting? DONE WITH THE PIT_STOP.INI
- #Camera = 0
- #CameraTrigger = 0
- #CameraChanger = 1 #configini.getboolean('UI', 'pitcamerachanger')
- LapTimesOnly = 0 #add this to the INI? Make a "settings" Interface?
- key_listener = 0
- useHotkey = 1
- colors = {
- "white" : [255, 255, 255],
- "yellow" : [255, 255, 0],
- "green" : [2, 221, 20],
- "red" : [252, 35, 35],
- "purple" : [255,0,255],
- "aqua" : [0,255,255],
- "violet" : [255,150,255],
- "blue" : [0,0,255],
- "orange" : [255,140,0]
- }
- ##### Create Custom Class (code from RevHunter) #####
- class Label:
- def __init__(self,appWindow,text = ""):
- self.label = ac.addLabel(appWindow, " ")
- self.labelText = text
- self.labelSize = {"width" : 0, "height" : 0}
- self.labelPosition = {"xpos" : 0, "ypos" : 0}
- self.labelFontSize = 12
- self.labelFontAlign = "left"
- self.labelFontColor = {"red" : 1, "green" : 1, "blue" : 1, "alpha" : 0}
- def setText(self, text):
- self.labelText = text
- ac.setText(self.label, self.labelText)
- return self
- def setSize(self, width, height):
- self.labelSize["width"] = width
- self.labelSize["height"] = height
- ac.setSize(self.label, self.labelSize["width"], self.labelSize["height"])
- return self
- def setPosition(self, xposition, yposition):
- self.labelPosition["xposition"] = xposition
- self.labelPosition["yposition"] = yposition
- ac.setPosition(self.label, self.labelPosition["xposition"],self.labelPosition["yposition"])
- return self
- def setFontSize(self, fontSize):
- self.labelFontSize = fontSize
- ac.setFontSize(self.label, self.labelFontSize)
- return self
- def setFontAlign(self, fontAlign = "left"):
- self.labelFontAlign = fontAlign
- ac.setFontAlignment(self.label, self.labelFontAlign)
- return self
- def setFontColor(self, red, green, blue, alpha):
- self.labelFontColor["red"] = red
- self.labelFontColor["green"] = green
- self.labelFontColor["blue"] = blue
- self.labelFontColor["alpha"] = alpha
- ac.setFontColor(self.label, self.labelFontColor["red"],self.labelFontColor["green"],self.labelFontColor["blue"],self.labelFontColor["alpha"])
- return self
- def acMain(ac_version):
- global appWindow, HideIcon, displayLabel, key_listener
- ReadSettings()
- appWindow = ac.newApp("EsoticDelta")
- ac.setSize(appWindow, windowx, windowy)
- #createLabel("deltaLabel", "+0.00", -47, 0, 30)
- displayLabel = Label(appWindow).setSize(0,0).setPosition((windowx / 2),(windowy*0.0) + veritcalAdjust).setFontSize(30*scale_mult).setFontAlign("center").setText(formatDelta(0.0, deltaStringFormat)) #.setFontColor(*rgb(colors["green"], 1.0)
- if HideIcon == 1:
- ac.setIconPosition(appWindow, 0, -9000)
- ac.setTitle(appWindow, "")
- if useHotkey == 1:
- ConsoleLog("PD Before Key Listener")
- key_listener = threading.Thread(target=listen_key)
- key_listener.daemon = True
- key_listener.start()
- ConsoleLog("PD After Key Listener")
- return "EsoticDelta"
- #def createLabel(name, text, x, y, font_size):
- # global app, labels
- # label = ac.addLabel(app, name)
- # ac.setText(label, text)
- # ac.setPosition(label, x, y)
- # ac.setFontSize(label, font_size)
- # ac.setFontAlignment(label, "center")
- # #ac.setBackgroundOpacity(label, 1.0)
- # labels[name] = label
- def timeToMinSecMsecTuple(t):
- mins = t // (60*1000)
- secs = (t - 60*1000*mins) // 1000
- msecs = (t - 60*1000*mins - secs*1000)
- return (mins, secs, msecs)
- def formatTime(t):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- time = "%02d:%02d.%03d" % (mins, secs, msecs)
- return time
- def formatLapTime(t):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- msecs = msecs / 100
- time = "%01d:%02d.%1d" % (mins, secs, msecs)
- return time
- def formatLapTime3Digits(t):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- #msecs = msecs / 100
- time = "%01d:%02d.%03d" % (mins, secs, msecs)
- return time
- def ConsoleLog(message):
- ac.console(message)
- ac.log(message)
- def getDelta(posOnTrack, lapTime, LapValid):
- global lastPOT, lastLapTime, lastRealTime, dic
- delta = 0.00
- message = "POT = %.4f, lapTime = %s, LapValid = %d" % (posOnTrack, formatTime(lapTime), LapValid)
- #ac.console(message)
- #ac.log(message)
- if True:
- #4 digits of precision, updated precision below in interpolation
- smallestDiff = 0.0001
- potAttr = "POT%.4f"%(posOnTrack)
- deltaAttr = "DLT%.4f"%(posOnTrack)
- lastPOTKey = "POT%.4f"%(lastPOT)
- else:
- #3 digits of precision
- smallestDiff = 0.001
- potAttr = "POT%.3f"%(posOnTrack)
- deltaAttr = "DLT%.3f"%(posOnTrack)
- lastPOTKey = "POT%.3f"%(lastPOT)
- #ac.log("100")
- deltaRealTime = 0.0
- if lastLapTime == lapTime:
- #ac.log("110")
- #assume AC is not updating lapTime effectively?
- if lastRealTime != 0.0:
- #ac.log("120")
- deltaRealTime = clock() - lastRealTime
- #ac.log("130")
- message = "deltaRealTime = %s" % (formatDelta(deltaRealTime, deltaStringFormat))
- #ac.log("140")
- #ac.console(message)
- else:
- #set this everytime lapTime is properly updated
- #ac.log("150")
- lastRealTime = clock()
- if lastLapTime != lapTime or deltaRealTime > 0.0:
- #ac.log("200")
- #only process if POT is newer? would need floats
- if potAttr != lastPOTKey:
- #ac.log("300")
- bestPOTTime = dic.get(potAttr, lapTime + deltaRealTime)
- #ac.log("310")
- #this should adjust for lack of timing updates in replays
- currPOTTime = lapTime + deltaRealTime
- #ac.log("320")
- delta = currPOTTime - bestPOTTime
- message = "bestPOTTime = %s, currPOTTime = %s, delta = %s" % (formatTime(bestPOTTime), formatTime(currPOTTime), formatDelta(delta, deltaStringFormat))
- #ac.console(message)
- #ac.log(message)
- #write this regardless, cuz we might need it soon
- dic[deltaAttr] = delta
- #get dic to lowest valid value possible
- if LapValid == 1:
- if dic.get(potAttr, 0) == 0:
- message = "zero, " + potAttr + " = " + formatTime(currPOTTime)
- #message = "zero, " + potAttr + message
- message = message + " at " + str(datetime.datetime.now())
- #ac.log(message)
- #ac.console(message)
- #ac.log(message)
- dic[potAttr] = currPOTTime
- elif currPOTTime < bestPOTTime: #dic.get(potAttr, 0):
- dic[potAttr] = currPOTTime
- message = "best, " + potAttr + " = " + formatTime(currPOTTime)
- #ac.log(message)
- #ac.console(message)
- if round(lastPOT + smallestDiff, 4) < round(posOnTrack, 4):
- #interpolate/calc all the values between lastPOT and posOnTrack
- message = "calc %.4f < %.4f" % (lastPOT + smallestDiff, posOnTrack)
- #ac.console(message)
- #ac.log(message)
- tmpPOT = lastPOT
- tmpTime = lastLapTime # dic.get(lastPOTKey, currPOTTime) # bestPOTTime
- message = "tmpPOT = %.4f, tmpTime = %s" % (tmpPOT, formatTime(tmpTime))
- #ac.log(message)
- #time delta is CurrentPOT - LastPOT / ((CurrentPot - LastPOT) / smallestDiff)
- #THIS CALCULATION MAY BE OFF, or may need more precision for the tight variances we're dealing with
- #need to dump some log files to inspect the logic that is happening at high speed
- intDenom = int((posOnTrack - lastPOT) / smallestDiff) * 1.0
- message = "intDenom = %d" % intDenom
- #ac.log(message)
- #ac.console(message)
- timeSlice = 0.0
- #convert the times to floats and then do the division?
- numLapTime = formatDeltaNumOnly(currPOTTime)
- numTmpTime = formatDeltaNumOnly(tmpTime)
- message = "numLapTime = %.4f, numTmpTime = %.4f" % (numLapTime, numTmpTime)
- #ac.log(message)
- timeSlice = (numLapTime - numTmpTime) / intDenom
- strSlice = "%.4f" % timeSlice
- message = "strSlice = " + strSlice
- #ac.log(message)
- #time values are in milliseconds
- timeSlice = timeSlice * 1000
- tmpPOT = tmpPOT + smallestDiff
- message = "tmpPOT = %.4f, posOnTrack = %.4f" % (tmpPOT, posOnTrack)
- #ac.log(message)
- while round(tmpPOT, 4) < round(posOnTrack, 4):
- #interpolate
- message = "int %.4f < %.4f" % (tmpPOT, posOnTrack)
- #ac.console(message)
- #ac.log(message)
- tmpTime = tmpTime + timeSlice
- tmpPotAttr = "POT%.4f"%(tmpPOT)
- deltaAttr = "DLT%.4f"%(tmpPOT)
- #dic[deltaAttr] is only for loading a previously calculated delta on consecutive calls with same POT
- #dic[deltaAttr] = delta
- if tmpPotAttr != potAttr:
- if dic.get(tmpPotAttr, 0) == 0:
- message = "zint, " + tmpPotAttr + " = " + formatTime(tmpTime)
- #ac.log(message)
- #ac.console(message)
- dic[tmpPotAttr] = tmpTime
- elif currPOTTime < bestPOTTime: #dic.get(potAttr, 0):
- message = "bint, " + tmpPotAttr + " = " + formatTime(tmpTime)
- #ac.log(message)
- #ac.console(message)
- dic[tmpPotAttr] = tmpTime
- tmpPOT = tmpPOT + smallestDiff
- else:
- delta = dic.get(deltaAttr, 0)
- #ac.console("100")
- #ac.log("100")
- message = "Retrieved delta from dic = %s" % (formatDelta(delta, "%.2f"))
- #ac.console(message)
- #ac.log(message)
- #only set this if lap times are different
- lastPOT = posOnTrack
- else:
- deltaAttr = "DLT%.4f"%(lastPOT)
- if deltaAttr in dic:
- delta = dic[deltaAttr]
- message = "Retrieved delta from dic = %s" % (formatDelta(delta, "%.2f"))
- #ac.log(message)
- #set this all the time?
- lastLapTime = lapTime
- return delta
- def formatSplit(t):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- if mins > 0:
- secs = (mins * 60) + secs
- return "%02d.%03d" % (secs, msecs)
- def formatDiff(t):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- if mins > 0:
- secs = (mins * 60) + secs
- if t < 0:
- pre = "-"
- else:
- pre = "+"
- return pre + "%01d.%03d" % (secs, msecs)
- def formatDelta(t, format):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- if mins > 0:
- secs = (mins * 60) + secs
- if t < 0:
- pre = "-"
- else:
- pre = "+"
- time = secs + (msecs / 1000.0)
- #return pre + "%01d.%02d" % (secs, msecs)
- #return pre + "%.2f" % time
- return pre + format % time
- def formatDeltaNumOnly(t):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- if mins > 0:
- secs = (mins * 60) + secs
- time = secs + (msecs / 1000.0)
- if t < 0:
- time = time * -1
- #return pre + "%01d.%02d" % (secs, msecs)
- return time
- def formatDeltaNumOnlyHundreths(t):
- mins, secs, msecs = timeToMinSecMsecTuple(abs(t))
- if mins > 0:
- secs = (mins * 60) + secs
- time = secs + (msecs / 1000.0)
- if t < 0:
- time = time * -1
- return "%01d.%02d" % (secs, msecs)
- #return time
- def rgb(color, a = 1.0, bg = False):
- r = color[0] / 255
- g = color[1] / 255
- b = color[2] / 255
- if bg == False:
- return r, g, b, a
- else:
- return r, g, b
- def WriteSettings():
- global SettingsINI #, AdjustIntensity, ResetDuringPit, HideIcon, ResetOnCompoundSwitch, windowx, deltaStringFormat
- try:
- section = 'SETTINGS'
- SettingsConfig = configparser.ConfigParser()
- if os.path.isfile(SettingsINI):
- SettingsConfig.read(SettingsINI)
- else:
- ac.console("EsoticDelta writing new settings.ini")
- if not SettingsConfig.has_section(section):
- SettingsConfig.add_section(section)
- SettingsConfig.set(section,'AdjustIntensity','%d' % AdjustIntensity)
- SettingsConfig.set(section,'ResetDuringPit','%d' % ResetDuringPit)
- SettingsConfig.set(section,'ResetDuringPractice','%d' % ResetDuringPractice)
- SettingsConfig.set(section,'ResetDuringQualification','%d' % ResetDuringQualification)
- SettingsConfig.set(section,'HideIcon','%d' % HideIcon)
- SettingsConfig.set(section,'AppWidth','%d' % windowx)
- SettingsConfig.set(section,'ShowLapTimeDelay','%0.1f' % ShowLapTimeDelay)
- SettingsConfig.set(section,'ThreeDigitPrecision','0')
- SettingsConfig.set(section,'backgroundOpacity', '%0.1f' % backgroundOpacity)
- SettingsConfig.set(section,'drawBorder','%d' % drawBorderVar)
- SettingsConfig.set(section,'fullSpeed','%d' % fullSpeed)
- SettingsConfig.set(section,'allowedtyresout', '%d' % allowedtyresout)
- #UsePitOffset
- SettingsConfig.set(section,'UsePitOffset','%d' % UsePitOffset)
- SettingsConfig.set(section,'usehotkey', '%d' % useHotkey)
- with open(SettingsINI, 'w') as configfile:
- configfile.write(';Set Values to 1 to turn them on, 0 to turn them off.' + '\n')
- configfile.write(';AdjustIntensity toggles showing brighter/dimmer for trending.' + '\n')
- configfile.write(';ResetDuringPit toggles resetting delta during pit stop regardless of tire change.' + '\n')
- configfile.write(';ResetDuringQualification toggles resetting delta during qualification pit stops regardless of tire change. This is a qualifier for ResetDuringPit, which must be enabled for this to have any effect.' + '\n')
- configfile.write(';ResetDuringPractice toggles resetting delta during practice pit stops regardless of tire change. This is a qualifier for ResetDuringPit, which must be enabled for this to have any effect.' + '\n')
- configfile.write(';UsePitOffset toggles an adjustment to the lap time to try to make deltas when exiting the pits more relevant. Work in Progress.' + '\n')
- configfile.write(';HideIcon hides AC icon.' + '\n')
- configfile.write(';Default AppWidth is 110. Change this value to resize the app larger/smaller.' + '\n')
- configfile.write(';Default ShowLapTimeDelay is 4000.0 milliseconds, set it to 0.0 to disable it.' + '\n')
- configfile.write(';ThreeDigitPrecision toggles showing 2 or 3 digits after the decimal.' + '\n')
- configfile.write(';Default backgroundOpacity is 1.0, but you can set it anywhere from 0.0 (transparent) to 1.0 (fully opaque).' + '\n')
- configfile.write(';drawBorder toggles drawing the app border.' + '\n')
- configfile.write(';fullSpeed toggles showing delta at full speed or every .1 seconds.' + '\n')
- configfile.write(';allowedtyresout controls detecting off-lap incidents. set to 4 to disable tracking valid laps (the default), or 1, 2, or 3 to enable.' + '\n')
- configfile.write(';UseHotkey enables the F10 hotkey to clear the current values.' + '\n')
- SettingsConfig.write(configfile)
- return 1
- except:
- exc_type, exc_value, exc_traceback = sys.exc_info()
- ac.console('WriteSettings Error (logged to file)')
- ac.log(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
- def ReadSettings():
- global SettingsINI, AdjustIntensity, ResetDuringPit, ResetDuringPractice, ResetDuringQualification, UsePitOffset, HideIcon, ResetOnCompoundSwitch, ShowLapTimeDelay
- global deltaStringFormat, backgroundOpacity, drawBorderVar, fullSpeed, allowedtyresout
- global windowx, windowy, scale_mult, useHotkey
- try:
- if os.path.isfile(SettingsINI):
- section = 'SETTINGS'
- SettingsConfig = configparser.ConfigParser()
- SettingsConfig.read(SettingsINI)
- boolWriteSettings = False
- if SettingsConfig.has_option(section, 'AdjustIntensity'):
- AdjustIntensity = SettingsConfig.getint(section, 'AdjustIntensity')
- else:
- boolWriteSettings = True
- if SettingsConfig.has_option(section, 'ResetDuringPit'):
- ResetDuringPit = SettingsConfig.getint(section, 'ResetDuringPit')
- else:
- boolWriteSettings = True
- if SettingsConfig.has_option(section, 'ResetDuringPractice'):
- ResetDuringPractice = SettingsConfig.getint(section, 'ResetDuringPractice')
- else:
- boolWriteSettings = True
- if SettingsConfig.has_option(section, 'ResetDuringQualification'):
- ResetDuringQualification = SettingsConfig.getint(section, 'ResetDuringQualification')
- else:
- boolWriteSettings = True
- #UsePitOffset
- if SettingsConfig.has_option(section, 'UsePitOffset'):
- UsePitOffset = SettingsConfig.getint(section, 'UsePitOffset')
- else:
- boolWriteSettings = True
- if SettingsConfig.has_option(section, 'HideIcon'):
- HideIcon = SettingsConfig.getint(section, 'HideIcon')
- else:
- boolWriteSettings = True
- if SettingsConfig.has_option(section, 'ResetOnCompoundSwitch'):
- ResetOnCompoundSwitch = SettingsConfig.getint(section, 'ResetOnCompoundSwitch')
- else:
- boolWriteSettings = True
- if SettingsConfig.has_option(section, 'AppWidth'):
- windowx = SettingsConfig.getint(section, 'AppWidth')
- else:
- boolWriteSettings = True
- #this sets the aspect for the window
- windowy = windowx * 0.4181818181818182
- #windowsx is 110 by default, so this sets the multiplier for all screen elements
- scale_mult = windowx/110
- #override these values? per car?
- if SettingsConfig.has_option(section, 'AppHeight'):
- windowy = SettingsConfig.getint(section, 'AppHeight')
- if SettingsConfig.has_option(section, 'FontScale'):
- scale_mult = SettingsConfig.getfloat(section, 'FontScale')
- #ShowLapTimeDelay
- if SettingsConfig.has_option(section, 'ShowLapTimeDelay'):
- ShowLapTimeDelay = SettingsConfig.getfloat(section, 'ShowLapTimeDelay')
- else:
- boolWriteSettings = True
- #backgroundOpacity
- if SettingsConfig.has_option(section, 'backgroundOpacity'):
- backgroundOpacity = SettingsConfig.getfloat(section, 'backgroundOpacity')
- else:
- boolWriteSettings = True
- #drawBorderVar
- if SettingsConfig.has_option(section, 'drawBorder'):
- drawBorderVar = SettingsConfig.getint(section, 'drawBorder')
- else:
- boolWriteSettings = True
- #fullSpeed
- if SettingsConfig.has_option(section, 'fullSpeed'):
- fullSpeed = SettingsConfig.getint(section, 'fullSpeed')
- else:
- boolWriteSettings = True
- if SettingsConfig.has_option(section, 'ThreeDigitPrecision'):
- ThreeDigitPrecision = SettingsConfig.getint(section, 'ThreeDigitPrecision')
- if ThreeDigitPrecision == 1:
- deltaStringFormat = "%.3f"
- else:
- boolWriteSettings = True
- #allowedtyresout
- if SettingsConfig.has_option(section, 'allowedtyresout'):
- allowedtyresout = SettingsConfig.getint(section, 'allowedtyresout')
- else:
- boolWriteSettings = True
- #useHotkey
- if SettingsConfig.has_option(section, 'useHotkey'):
- useHotkey = SettingsConfig.getint(section, 'useHotkey')
- else:
- boolWriteSettings = True
- if boolWriteSettings == True:
- ac.console("EsoticDelta new settings found, writing new settings.ini")
- WriteSettings()
- else:
- ac.console("EsoticDelta Unable to read settings.ini, using default values")
- WriteSettings()
- except:
- exc_type, exc_value, exc_traceback = sys.exc_info()
- ac.console('ReadSettings Error (logged to file)')
- ac.log(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
- def acUpdate(deltaT):
- global displayLabel, startTracking, appWindow, compound, lastTime, prevDelta, trend, alpha, InitialPosition, dic, Range, LastStatus, LastSession, LapValid, lastClock, MinKPH, MaxKPH, TimeOfLastOff, recentDelta, pitOffset, bSetOffset, lastF10Click
- #, Camera, CameraTrigger, CameraChanger
- try:
- sim_info_obj = sim_info.SimInfo()
- ac.setBackgroundOpacity(appWindow, backgroundOpacity)
- ac.drawBorder(appWindow, drawBorderVar)
- bIsQually = False
- if sim_info_obj.graphics.session == 1:
- bIsQually = True
- bIsPractice = False
- if sim_info_obj.graphics.session == 0:
- bIsPractice = True
- if sim_info_obj.graphics.status != LastStatus or sim_info_obj.graphics.session != LastSession:
- #ac.console("status or session changed, startTracking = 0")
- #THIS IS JUST COMMENTED OUT FOR THE DEMO, SHOULD BE ON FOR DISTRIBUTION
- startTracking = False
- #ac.console("REVERT TO NORMAL")
- LastStatus = sim_info_obj.graphics.status
- LastSession = sim_info_obj.graphics.session
- if sim_info_obj.graphics.status == 2 or sim_info_obj.graphics.status == 1:
- #tmpcompound = str(sim_info_obj.graphics.tyreCompound)
- tmpcompound = ac.getCarTyreCompound(0)
- if not compound == tmpcompound and ResetOnCompoundSwitch == 1:
- #clear the vars
- dic.clear()
- compound = tmpcompound
- #normalizedSplinePosition = round(sim_info_obj.graphics.normalizedCarPosition, 4)
- normalizedSplinePosition = ac.getCarState(0,acsys.CS.NormalizedSplinePosition)
- currentTime = sim_info_obj.graphics.iCurrentTime
- if lastF10Click > 0:
- if abs(currentTime - lastF10Click) > 1000:
- #ConsoleLog("Timeout Clearing lastF10Click")
- lastF10Click = 0
- #if sim_info.info.physics.numberOfTyresOut > 2
- numTyresOut = sim_info_obj.physics.numberOfTyresOut
- if numTyresOut > allowedtyresout:
- #this should be zero in a perfect world
- LapValid = 0
- if numTyresOut > 3:
- TimeOfLastOff = currentTime
- #ConsoleLog("TimeOfLastOff %.2f"%(TimeOfLastOff))
- if ((currentTime - TimeOfLastOff) > 5000.0) or currentTime < 1000.0:
- TimeOfLastOff = 0.0
- #carDamage
- #dmgFront, dmgBack, dmgLeft, dmgRight, dmgMax = sim_info_obj.physics.carDamage
- #message = "Damage Front %.4f, Back %.4f, Left %.4f, Right %.4f, Max %.4f" % (dmgFront, dmgBack, dmgLeft, dmgRight, dmgMax)
- #ac.console(message)
- #if replay use clock() instead of iCurrentTime? playback speed?
- #position = "P%.4f"%(normalizedSplinePosition)
- #deltaLabel = labels["deltaLabel"]
- #ac.setText(deltaLabel, position)
- Speed = ac.getCarState(0,acsys.CS.SpeedKMH)
- inPit = sim_info_obj.graphics.isInPit
- #if inPit == True and CameraTrigger == 0 and CameraChanger == 1:
- # Camera = ac.getCameraMode()
- # CameraTrigger = 1
- #if inPit == False:
- # CameraTrigger = 0
- inPit = ac.isCarInPitline(0)
- #track when we cross the "start/finish" (actually cross over from 0.9999 to 0.0000)
- if lastPOT > 0.9 and normalizedSplinePosition < 0.1:
- #turn this off for now
- #ConsoleLog("MinKPH = %d, MaxKPH = %d"%(MinKPH, MaxKPH))
- MinKPH = Speed
- MaxKPH = Speed
- if inPit == False:
- pitOffset = 0.0
- #bSetOffset = 1
- else:
- if Speed < MinKPH:
- MinKPH = Speed
- if Speed > MaxKPH:
- MaxKPH = Speed
- #LapInvalidated
- #LapInvalidated = ac.getCarState(0,acsys.CS.LapInvalidated)
- #PerformanceMeter = ac.getCarState(0, acsys.CS.PerformanceMeter)
- #message = "numTyresOut = %d" % numTyresOut
- #message = message + " at " + str(datetime.datetime.now())
- #ac.console(message)
- #message = "Speed = %d" % Speed
- #ac.console(message)
- #message = "LapInvalidated = %d" % LapInvalidated
- #ac.console(message)
- #message = "LapInvalidated = %.4f" % LapInvalidated
- #ac.console(message)
- ##position = "D%.4f"%(normalizedSplinePosition)
- #message = "PerformanceMeter = %.4f" % PerformanceMeter
- #ac.console(message)
- if InitialPosition == 0:
- InitialPosition = normalizedSplinePosition
- #move these towards the .5 instead of the 0.1 and .99 range
- if InitialPosition > 0.5:
- InitialPosition = InitialPosition - .5
- else:
- InitialPosition = InitialPosition + .5
- Position = 0.0
- if normalizedSplinePosition > 0.5:
- Position = normalizedSplinePosition - 0.5
- else:
- Position = normalizedSplinePosition + .5
- #reset every time in the pits?
- if ResetDuringPit == 1 and not (bIsQually == True and ResetDuringQualification == 0) and not (bIsPractice == True and ResetDuringPractice == 0):
- if ((InitialPosition-Range < Position < InitialPosition+Range) or inPit) and (Speed < 0.1):
- dic.clear()
- if normalizedSplinePosition < 0.01:
- startTracking = True
- LapValid = 1
- #if inPit:
- # return True
- # startTracking = False
- if inPit == True and Speed < 1.0 and UsePitOffset == 1:
- #if we're in the pit lane and not moving (pit stall, probably)
- #pitOffset = currentTime
- bSetOffset = 1
- if startTracking and not inPit:
- #position = "D%.4f"%(normalizedSplinePosition)
- delta = getDelta(normalizedSplinePosition, currentTime, LapValid)
- #are we using an offset?
- if bSetOffset == 1:
- pitOffset = delta
- bSetOffset = 0
- if pitOffset != 0.0:
- delta = delta - pitOffset
- strDelta = formatDelta(delta, deltaStringFormat)
- numDelta = round(formatDeltaNumOnly(delta), 2)
- #do this based off systemtime, not race time?
- #use systemtime to help calc race time?
- strCurrTime = formatDelta(currentTime, "%.1f")
- strLastTime = formatDelta(lastTime, "%.1f")
- currentClock = 0.0
- if sim_info_obj.graphics.status == 1:
- currentClock = clock()
- strCurrTime = "%.1f" % currentClock
- strLastTime = "%.1f" % lastClock
- #message = "strCurrTime = %s, strLastTime = %s" % (strCurrTime, strLastTime)
- #ac.log(message)
- #only update this 10 times a second
- #time not as accurate in replay, but fine in live
- if strCurrTime != strLastTime or fullSpeed == 1:
- lastClock = clock()
- alpha = 1
- if AdjustIntensity == 1:
- if prevDelta < numDelta:
- trend = trend + 1
- elif prevDelta > numDelta:
- trend = trend - 1
- prevDelta = numDelta
- if trend < 0:
- trend = 0
- if trend > 3:
- trend = 3
- if trend == 0:
- #0 means our times are improving
- alpha = 1.0
- elif trend == 3:
- #3 means our times are getting worse
- alpha = 0.7
- #example for updated a label
- #gear_display.setText("%d" % current_gear).setFontColor(1,0,0,1)
- #ac.setTitle(app, position)
- if LapValid == 0 or (TimeOfLastOff > 0.0 and ((currentTime - TimeOfLastOff) < 5000.0)):
- displayLabel.setFontColor(*rgb(colors["purple"], alpha))
- #ac.setFontColor(displayLabel, *rgb(colors["purple"], alpha))
- elif numDelta >= 0.5:
- displayLabel.setFontColor(*rgb(colors["red"], alpha))
- #ac.setFontColor(displayLabel, *rgb(colors["red"], alpha))
- elif numDelta >= 0.25:
- displayLabel.setFontColor(*rgb(colors["orange"], alpha))
- #ac.setFontColor(displayLabel, *rgb(colors["orange"], alpha))
- elif numDelta > 0.0:
- displayLabel.setFontColor(*rgb(colors["yellow"], alpha))
- #ac.setFontColor(displayLabel, *rgb(colors["yellow"], alpha))
- elif numDelta < -0.5:
- displayLabel.setFontColor(*rgb(colors["white"], alpha))
- elif numDelta < -0.25:
- displayLabel.setFontColor(*rgb(colors["aqua"], alpha))
- else:
- displayLabel.setFontColor(*rgb(colors["green"], alpha))
- #ac.setFontColor(displayLabel, *rgb(colors["green"], alpha))
- #ac.setFontSize(displayLabel, 30*scale_mult)
- #will this work?
- if True: # LapValid == 1:
- displayLabel.setText(strDelta)
- #ac.setText(displayLabel, strDelta)
- else:
- displayLabel.setFontColor(*rgb(colors["green"], 1.0))
- displayLabel.setText(formatDelta(0.0, deltaStringFormat))
- #ac.setText(displayLabel, "+0.00")
- lastTime = currentTime
- else:
- displayLabel.setFontColor(*rgb(colors["blue"], 1.0))
- displayLabel.setText(formatDelta(0.0, deltaStringFormat))
- if False:
- #we're going to use the brake value to track 2nd order delta
- brake = ac.getCarState(0, acsys.CS.Brake)
- if brake > 0.7:
- recentDelta = delta
- else:
- #display the difference in delta and recentDelta?
- recentDelta = recentDelta
- #do this last?
- if ShowLapTimeDelay > 0.0:
- LastLap = ac.getCarState(0,acsys.CS.LastLap)
- if LastLap > 0:
- if currentTime < ShowLapTimeDelay:
- #ac.setFontSize(displayLabel, 24)
- displayLabel.setFontColor(*rgb(colors["white"], 1.0))
- #ac.setFontColor(displayLabel, *rgb(colors["white"], 1.0))
- strLastLap = formatLapTime3Digits(LastLap)
- displayLabel.setText(strLastLap)
- #ac.setText(displayLabel, strLastLap)
- elif LapTimesOnly == 1:
- displayLabel.setText("--:--")
- if LapValid == 0 or (TimeOfLastOff > 0.0 and ((currentTime - TimeOfLastOff) < 5000.0)):
- displayLabel.setFontColor(*rgb(colors["purple"], alpha))
- else:
- displayLabel.setFontColor(*rgb(colors["blue"], 1.0))
- #if CameraChanger == 1 and CameraTrigger == 1:
- # if ac.getCameraMode() == 5:
- # ac.setCameraMode(Camera)
- # CameraTrigger = 0
- except:
- exc_type, exc_value, exc_traceback = sys.exc_info()
- ac.console('EsoticDelta Update Error (logged to file)')
- ac.log(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
- def hotkey_offset():
- global bSetOffset , lastF10Click , compound , startTracking, lastPOT, lastLapTime, lastRealTime, lastClock , pitOffset , lastTime, recentDelta , prevDelta
- ConsoleLog("PD hotkey_offset Called")
- bSetOffset = 1
- sim_info_obj = sim_info.SimInfo()
- currentTime = sim_info_obj.graphics.iCurrentTime
- if lastF10Click > 0:
- if currentTime - lastF10Click < 1000:
- #ConsoleLog("Double Click Detected lastF10Click")
- #this is a double click detection, so clear all the vars
- dic.clear()
- compound = None
- bSetOffset = 0
- startTracking = False
- lastPOT = 0
- lastLapTime = 0
- lastRealTime = 0
- lastClock = 0.0
- pitOffset = 0.0
- lastTime = 0.0
- recentDelta = 0.0
- prevDelta = 0.0
- elif currentTime - lastF10Click > 1000:
- #ConsoleLog("Clearing lastF10Click")
- lastF10Click = 0
- else:
- #ConsoleLog("Setting lastF10Click")
- lastF10Click = currentTime
- def listen_key():
- byref = ctypes.byref
- user32 = ctypes.windll.user32
- ConsoleLog("PD Key Listener")
- HOTKEYS = {
- 1: (win32con.VK_F10, None),
- }
- def handle_f10():
- hotkey_offset()
- #hotkey_preset()
- HOTKEY_ACTIONS = {
- 1: handle_f10,
- }
- for id, (vk, modifiers) in HOTKEYS.items():
- user32.RegisterHotKey(None, id, modifiers, vk)
- try:
- msg = wintypes.MSG()
- while user32.GetMessageA(byref(msg), None, 0, 0) != 0:
- if msg.message == win32con.WM_HOTKEY:
- action_to_take = HOTKEY_ACTIONS.get (msg.wParam)
- if action_to_take:
- action_to_take()
- user32.TranslateMessage(byref(msg))
- user32.DispatchMessageA(byref(msg))
- finally:
- for id in HOTKEYS.keys():
- user32.UnregisterHotKey(None, id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement