diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 255c90133..e01d26fc6 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -130,7 +130,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) { return true; } if (!didProcessEvent && alphaLockWantsRedraw) { - windowRedraw(); + window()->redraw(); return true; } return didProcessEvent; diff --git a/apps/graph/cartesian_function_store.cpp b/apps/graph/cartesian_function_store.cpp index 087fcb3a8..7c74dacea 100644 --- a/apps/graph/cartesian_function_store.cpp +++ b/apps/graph/cartesian_function_store.cpp @@ -18,13 +18,13 @@ CartesianFunctionStore::CartesianFunctionStore() : } uint32_t CartesianFunctionStore::storeChecksum() { - size_t dataLengthInBytes = k_maxNumberOfFunctions*TextField::maxBufferSize()*sizeof(char); + size_t dataLengthInBytes = k_maxNumberOfFunctions*sizeof(uint32_t); assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4 - char data[k_maxNumberOfFunctions*TextField::maxBufferSize()] = {}; + uint32_t checksums[k_maxNumberOfFunctions]; for (int i = 0; i < k_maxNumberOfFunctions; i++) { - strlcpy(data+i*TextField::maxBufferSize(), m_functions[i].text(), TextField::maxBufferSize()); + checksums[i] = m_functions[i].checksum(); } - return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2); + return Ion::crc32((uint32_t *)checksums, dataLengthInBytes>>2); } CartesianFunction * CartesianFunctionStore::functionAtIndex(int i) { diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index a8a7e348e..cb4470ea6 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -2,6 +2,7 @@ #include "local_context.h" #include "../../poincare/src/layout/string_layout.h" #include "../../poincare/src/layout/baseline_relative_layout.h" +#include #include using namespace Shared; @@ -81,6 +82,16 @@ Sequence& Sequence::operator=(const Sequence& other) { return *this; } +uint32_t Sequence::checksum() { + size_t dataLengthInBytes = 3*TextField::maxBufferSize()*sizeof(char); + assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4 + char data[3*TextField::maxBufferSize()] = {}; + strlcpy(data, text(), TextField::maxBufferSize()); + strlcpy(data+TextField::maxBufferSize(), firstInitialConditionText(), TextField::maxBufferSize()); + strlcpy(data+2*TextField::maxBufferSize(), secondInitialConditionText(), TextField::maxBufferSize()); + return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2); +} + const char * Sequence::firstInitialConditionText() { return m_firstInitialConditionText; } diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index 09563df98..e794192b4 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -18,6 +18,7 @@ public: Sequence& operator=(Sequence&& other) = delete; Sequence(const Sequence& other) = delete; Sequence(Sequence&& other) = delete; + uint32_t checksum() override; Type type(); void setType(Type type); const char * firstInitialConditionText(); diff --git a/apps/sequence/sequence_store.cpp b/apps/sequence/sequence_store.cpp index 7a107baf7..991d30762 100644 --- a/apps/sequence/sequence_store.cpp +++ b/apps/sequence/sequence_store.cpp @@ -11,15 +11,13 @@ constexpr KDColor SequenceStore::k_defaultColors[k_maxNumberOfSequences]; constexpr const char * SequenceStore::k_sequenceNames[k_maxNumberOfSequences]; uint32_t SequenceStore::storeChecksum() { - size_t dataLengthInBytes = k_maxNumberOfSequences*3*TextField::maxBufferSize()*sizeof(char); + size_t dataLengthInBytes = k_maxNumberOfSequences*sizeof(uint32_t); assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4 - char data[3*k_maxNumberOfSequences*TextField::maxBufferSize()] = {}; + uint32_t checksums[k_maxNumberOfSequences]; for (int i = 0; i < k_maxNumberOfSequences; i++) { - strlcpy(data+i*3*TextField::maxBufferSize(), m_sequences[i].text(), TextField::maxBufferSize()); - strlcpy(data+i*3*TextField::maxBufferSize()+TextField::maxBufferSize(), m_sequences[i].firstInitialConditionText(), TextField::maxBufferSize()); - strlcpy(data+i*3*TextField::maxBufferSize()+2*TextField::maxBufferSize(), m_sequences[i].secondInitialConditionText(), TextField::maxBufferSize()); + checksums[i] = m_sequences[i].checksum(); } - return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2); + return Ion::crc32((uint32_t *)checksums, dataLengthInBytes>>2); } Sequence * SequenceStore::functionAtIndex(int i) { diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index 354ba28f9..c53c70e88 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -1,6 +1,7 @@ #include "function.h" #include #include +#include using namespace Poincare; @@ -25,6 +26,14 @@ Function& Function::operator=(const Function& other) { return *this; } +uint32_t Function::checksum() { + size_t dataLengthInBytes = TextField::maxBufferSize()*sizeof(char); + assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4 + char data[TextField::maxBufferSize()] = {}; + strlcpy(data, m_text, TextField::maxBufferSize()); + return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2); +} + void Function::setContent(const char * c) { strlcpy(m_text, c, sizeof(m_text)); if (m_layout != nullptr) { diff --git a/apps/shared/function.h b/apps/shared/function.h index cdf64bc4c..1483d28a0 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -15,6 +15,7 @@ public: Function& operator=(Function&& other) = delete; Function(const Function& other) = delete; Function(Function&& other) = delete; + virtual uint32_t checksum(); const char * text() const; const char * name() const; KDColor color() const { return m_color; } diff --git a/escher/include/escher/container.h b/escher/include/escher/container.h index 8412274ff..e1e4f299c 100644 --- a/escher/include/escher/container.h +++ b/escher/include/escher/container.h @@ -29,7 +29,6 @@ public: virtual void switchTo(App::Snapshot * snapshot); protected: virtual Window * window() = 0; - void windowRedraw() override; private: void step(); App * m_activeApp; diff --git a/escher/include/escher/run_loop.h b/escher/include/escher/run_loop.h index 81bc7b1fd..83f9396d6 100644 --- a/escher/include/escher/run_loop.h +++ b/escher/include/escher/run_loop.h @@ -9,7 +9,6 @@ public: RunLoop(); void run(); protected: - virtual void windowRedraw() = 0; virtual bool dispatchEvent(Ion::Events::Event e) = 0; virtual int numberOfTimers(); virtual Timer * timerAtIndex(int i); diff --git a/escher/src/container.cpp b/escher/src/container.cpp index 2314eda06..8e8347902 100644 --- a/escher/src/container.cpp +++ b/escher/src/container.cpp @@ -20,11 +20,10 @@ void Container::switchTo(App::Snapshot * snapshot) { if (m_activeApp) { m_activeApp->willBecomeInactive(); m_activeApp->snapshot()->pack(m_activeApp); + m_activeApp = nullptr; } if (snapshot) { m_activeApp = snapshot->unpack(this); - } else { - m_activeApp = nullptr; } if (m_activeApp) { m_activeApp->didBecomeActive(window()); @@ -36,8 +35,8 @@ App * Container::activeApp() { } bool Container::dispatchEvent(Ion::Events::Event event) { - if (m_activeApp->processEvent(event)) { - windowRedraw(); + if (event == Ion::Events::TimerTick || m_activeApp->processEvent(event)) { + window()->redraw(); return true; } return false; @@ -49,6 +48,3 @@ void Container::run() { RunLoop::run(); } -void Container::windowRedraw() { - window()->redraw(); -} diff --git a/escher/src/run_loop.cpp b/escher/src/run_loop.cpp index 2231f34ed..6c14ced8f 100644 --- a/escher/src/run_loop.cpp +++ b/escher/src/run_loop.cpp @@ -49,7 +49,7 @@ bool RunLoop::step() { for (int i=0; itick()) { - windowRedraw(); + dispatchEvent(Ion::Events::TimerTick); } } } diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index f652098bf..effbe1abb 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -200,6 +200,7 @@ constexpr Event UpperZ = Event::ShiftAlphaKey(Keyboard::Key::H4); constexpr Event None = Event::Special(0); constexpr Event Termination = Event::Special(1); +constexpr Event TimerTick = Event::Special(2); } }