Optimize TimeJump

This commit is contained in:
kamel5 2020-01-06 12:51:49 +01:00
parent 2e4a43133e
commit 6540e21444
4 changed files with 43 additions and 41 deletions

View File

@ -8,7 +8,7 @@
#include "fontmanager.h" #include "fontmanager.h"
#include "imagecache.h" #include "imagecache.h"
enum { enum eTimeFormat {
e12Hours, e12Hours,
e24Hours e24Hours
}; };

View File

@ -3,6 +3,14 @@
#include "config.h" #include "config.h"
#include "timemanager.h" #include "timemanager.h"
cTimeManager::cTimeManager(void) {
if (config.displayMode == eVertical) {
displaySeconds = (geoManager.osdHeight - geoManager.statusHeaderHeight - geoManager.channelHeaderHeight - geoManager.channelGroupsHeight - geoManager.footerHeight) / geoManager.minutePixel * 60;
} else if (config.displayMode == eHorizontal) {
displaySeconds = (geoManager.osdWidth - geoManager.channelHeaderWidth - geoManager.channelGroupsWidth) / geoManager.minutePixel * 60;
}
}
cTimeManager::~cTimeManager(void) { cTimeManager::~cTimeManager(void) {
} }
@ -18,40 +26,32 @@ void cTimeManager::Now() {
t = time(0); t = time(0);
tStart = t; tStart = t;
tStart = GetRounded(); tStart = GetRounded();
if (config.displayMode == eVertical) { tEnd = tStart + displaySeconds;
tEnd = tStart + (geoManager.osdHeight - geoManager.statusHeaderHeight - geoManager.channelHeaderHeight - geoManager.channelGroupsHeight - geoManager.footerHeight)/geoManager.minutePixel*60;
} else if (config.displayMode == eHorizontal) {
tEnd = tStart + (geoManager.osdWidth - geoManager.channelHeaderWidth - geoManager.channelGroupsWidth)/geoManager.minutePixel*60;
}
} }
void cTimeManager::AddStep(int step) { void cTimeManager::AddStep(int step) {
tStart += step*60; tStart += step * 60;
tEnd += step*60; tEnd = tStart + displaySeconds;
} }
bool cTimeManager::DelStep(int step) { void cTimeManager::DelStep(int step) {
if ((tStart - step*60)+30*60 < t) { if ((tStart - step * 60) + 30 * 60 < t) {
return true; Now();
} else {
tStart -= step * 60;
tEnd = tStart + displaySeconds;
} }
tStart -= step*60;
tEnd -= step*60;
return false;
} }
void cTimeManager::SetTime(time_t newTime) { void cTimeManager::SetTime(time_t newTime) {
tStart = newTime; tStart = newTime;
if (config.displayMode == eVertical) { tEnd = tStart + displaySeconds;
tEnd = tStart + (geoManager.osdHeight - geoManager.statusHeaderHeight - geoManager.channelHeaderHeight - geoManager.channelGroupsHeight - geoManager.footerHeight)/geoManager.minutePixel*60;
} else if (config.displayMode == eHorizontal) {
tEnd = tStart + (geoManager.osdWidth - geoManager.channelHeaderWidth - geoManager.channelGroupsWidth)/geoManager.minutePixel*60;
}
} }
time_t cTimeManager::getPrevPrimetime(time_t current) { time_t cTimeManager::getPrevPrimetime(time_t current) {
tm *st = localtime(&current); tm *st = localtime(&current);
if (st->tm_hour < 21) { if (st->tm_hour < 21) {
current -= 24 * 60* 60; current -= 24 * 60 * 60;
st = localtime(&current); st = localtime(&current);
} }
st->tm_hour = 20; st->tm_hour = 20;
@ -63,7 +63,7 @@ time_t cTimeManager::getPrevPrimetime(time_t current) {
time_t cTimeManager::getNextPrimetime(time_t current){ time_t cTimeManager::getNextPrimetime(time_t current){
tm *st = localtime(&current); tm *st = localtime(&current);
if (st->tm_hour > 19) { if (st->tm_hour > 19) {
current += 24 * 60* 60; current += 24 * 60 * 60;
st = localtime(&current); st = localtime(&current);
} }
st->tm_hour = 20; st->tm_hour = 20;

View File

@ -2,6 +2,7 @@
#define __TVGUIDE_TIMEMANAGER_H #define __TVGUIDE_TIMEMANAGER_H
#include <vdr/tools.h> #include <vdr/tools.h>
#include "config.h"
// --- cTimeManager ------------------------------------------------------------- // --- cTimeManager -------------------------------------------------------------
@ -10,14 +11,16 @@ class cTimeManager {
time_t t; time_t t;
time_t tStart; time_t tStart;
time_t tEnd; time_t tEnd;
int displaySeconds;
eTimeFormat timeFormat;
public: public:
cTimeManager(){}; cTimeManager();
virtual ~cTimeManager(void); virtual ~cTimeManager(void);
static cString printTime(time_t displayTime); static cString printTime(time_t displayTime);
void Now(); void Now();
time_t GetNow() { return t; }; time_t GetNow() { return t; };
void AddStep(int step); void AddStep(int step);
bool DelStep(int step); void DelStep(int step);
void SetTime(time_t newTime); void SetTime(time_t newTime);
time_t Get() {return t;}; time_t Get() {return t;};
time_t GetStart() {return tStart;}; time_t GetStart() {return tStart;};
@ -31,6 +34,7 @@ class cTimeManager {
int GetTimelineOffset(); int GetTimelineOffset();
time_t GetRounded(); time_t GetRounded();
bool NowVisible(void); bool NowVisible(void);
int GetDisplaySeconds(void) { return displaySeconds; };
void debug(); void debug();
}; };

View File

@ -410,9 +410,7 @@ void cTvGuideOsd::timeBack() {
} }
void cTvGuideOsd::ScrollBack() { void cTvGuideOsd::ScrollBack() {
bool tooFarInPast = timeManager->DelStep(config.stepMinutes); timeManager->DelStep(config.stepMinutes);
if (tooFarInPast)
return;
if (config.useHWAccel) { if (config.useHWAccel) {
drawGridsTimeJump(); drawGridsTimeJump();
timeLine->drawDateViewer(); timeLine->drawDateViewer();
@ -640,24 +638,20 @@ void cTvGuideOsd::processNumKey(int numKey) {
void cTvGuideOsd::TimeJump(int mode) { void cTvGuideOsd::TimeJump(int mode) {
switch (mode) { switch (mode) {
case 1: { case 1: {
bool tooFarInPast = timeManager->DelStep(config.bigStepHours*60); timeManager->DelStep(config.bigStepHours * 60);
if (tooFarInPast) }
return;
}
break; break;
case 3: { case 3: {
timeManager->AddStep(config.bigStepHours*60); timeManager->AddStep(config.bigStepHours * 60);
} }
break; break;
case 4: { case 4: {
bool tooFarInPast = timeManager->DelStep(config.hugeStepHours*60); timeManager->DelStep(config.hugeStepHours * 60);
if (tooFarInPast) }
return;
}
break; break;
case 6: { case 6: {
timeManager->AddStep(config.hugeStepHours*60); timeManager->AddStep(config.hugeStepHours * 60);
} }
break; break;
case 7: { case 7: {
cTimeManager primeChecker; cTimeManager primeChecker;
@ -666,13 +660,13 @@ void cTvGuideOsd::TimeJump(int mode) {
if (primeChecker.tooFarInPast(prevPrime)) if (primeChecker.tooFarInPast(prevPrime))
return; return;
timeManager->SetTime(prevPrime); timeManager->SetTime(prevPrime);
} }
break; break;
case 9: { case 9: {
cTimeManager primeChecker; cTimeManager primeChecker;
time_t nextPrime = primeChecker.getNextPrimetime(timeManager->GetStart()); time_t nextPrime = primeChecker.getNextPrimetime(timeManager->GetStart());
timeManager->SetTime(nextPrime); timeManager->SetTime(nextPrime);
} }
break; break;
default: default:
return; return;
@ -783,8 +777,12 @@ eOSState cTvGuideOsd::ProcessKey(eKeys Key) {
case kYellow: processKeyYellow(); break; case kYellow: processKeyYellow(); break;
case kBlue: state = processKeyBlue(&alreadyUnlocked); break; case kBlue: state = processKeyBlue(&alreadyUnlocked); break;
case kOk: state = processKeyOk(&alreadyUnlocked); break; case kOk: state = processKeyOk(&alreadyUnlocked); break;
case kBack: state=osEnd; break; case kBack: state = osEnd; break;
case k0 ... k9: processNumKey(Key - k0); break; case k0 ... k9: processNumKey(Key - k0); break;
case kFastRew: TimeJump(1); break; // Doesnt work, if used from timeshiftmode
case kFastFwd: TimeJump(3); break;
case kPrev: TimeJump(4); break;
case kNext: TimeJump(6); break;
case kNone: if (channelJumper) CheckTimeout(); break; case kNone: if (channelJumper) CheckTimeout(); break;
default: break; default: break;
} }