mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Merge changes Ia2b70ceb,Ifcba1f46,Ib6d1cacd
* changes: [apps/sequence][apps/graph] Reimplement checksum to avoid risking overflowing the stack [escher] Clean [escher] Add an event "TimerTick"
This commit is contained in:
@@ -130,7 +130,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
|
||||
return true;
|
||||
}
|
||||
if (!didProcessEvent && alphaLockWantsRedraw) {
|
||||
windowRedraw();
|
||||
window()->redraw();
|
||||
return true;
|
||||
}
|
||||
return didProcessEvent;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "local_context.h"
|
||||
#include "../../poincare/src/layout/string_layout.h"
|
||||
#include "../../poincare/src/layout/baseline_relative_layout.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "function.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ bool RunLoop::step() {
|
||||
for (int i=0; i<numberOfTimers(); i++) {
|
||||
Timer * timer = timerAtIndex(i);
|
||||
if (timer->tick()) {
|
||||
windowRedraw();
|
||||
dispatchEvent(Ion::Events::TimerTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user