Move warp time subwarp speed calculation to separate cache as well

This commit is contained in:
DarkPhoenix
2019-07-04 11:40:38 +03:00
parent 193fcc60d8
commit 15b6a848e8
3 changed files with 29 additions and 16 deletions

View File

@@ -207,5 +207,17 @@ class FitGraph(metaclass=ABCMeta):
current += step
class FitDataCache:
def __init__(self):
self._data = {}
def clear(self, fitID):
if fitID is None:
self._data.clear()
elif fitID in self._data:
del self._data[fitID]
# noinspection PyUnresolvedReferences
from gui.builtinGraphs import *

View File

@@ -23,18 +23,10 @@ from copy import copy
from eos.utils.float import floatUnerr
from eos.utils.spoolSupport import SpoolType, SpoolOptions
from eos.utils.stats import DmgTypes
from gui.builtinGraphs.base import FitDataCache
class TimeCache:
def __init__(self):
self._data = {}
def clear(self, fitID):
if fitID is None:
self._data.clear()
elif fitID in self._data:
del self._data[fitID]
class TimeCache(FitDataCache):
def getData(self, fitID, cacheType):
return self._data[fitID][cacheType]

View File

@@ -21,7 +21,7 @@
import math
from eos.const import FittingModuleState
from .base import FitGraph, XDef, YDef, Input
from .base import FitGraph, XDef, YDef, Input, FitDataCache
AU_METERS = 149597870700
@@ -29,6 +29,13 @@ AU_METERS = 149597870700
class FitWarpTimeGraph(FitGraph):
def __init__(self):
super().__init__()
self._subspeedCache = SubwarpSpeedCache()
def _clearInternalCache(self, fitID):
self._subspeedCache.clear(fitID)
# UI stuff
name = 'Warp Time'
xDefs = [
@@ -53,7 +60,7 @@ class FitWarpTimeGraph(FitGraph):
def _distance2time(self, mainInput, miscInputs, fit, tgt):
xs = []
ys = []
subwarpSpeed = self.__getSubwarpSpeed(fit)
subwarpSpeed = self._subspeedCache.getSubwarpSpeed(fit)
warpSpeed = fit.warpSpeed
for distance in self._iterLinear(mainInput[1]):
time = calculate_time_in_warp(max_subwarp_speed=subwarpSpeed, max_warp_speed=warpSpeed, warp_dist=distance)
@@ -64,10 +71,12 @@ class FitWarpTimeGraph(FitGraph):
_getters = {
('distance', 'time'): _distance2time}
# Cache generation
def __getSubwarpSpeed(self, fit):
class SubwarpSpeedCache(FitDataCache):
def getSubwarpSpeed(self, fit):
try:
subwarpSpeed = self._calcCache[fit.ID]
subwarpSpeed = self._data[fit.ID]
except KeyError:
modStates = {}
for mod in fit.modules:
@@ -97,7 +106,7 @@ class FitWarpTimeGraph(FitGraph):
fighter.active = False
fit.calculateModifiedAttributes()
subwarpSpeed = fit.ship.getModifiedItemAttr('maxVelocity')
self._calcCache[fit.ID] = subwarpSpeed
self._data[fit.ID] = subwarpSpeed
for projInfo, state in projFitStates.items():
projInfo.active = state
for mod, state in modStates.items():