Skip to content

Commit

Permalink
flow support assets
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 15, 2021
1 parent 722c98c commit 76b8806
Show file tree
Hide file tree
Showing 22 changed files with 639 additions and 407 deletions.
128 changes: 126 additions & 2 deletions src/eez/flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,139 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>

#include <eez/flow.h>
#include <eez/flow_defs_v3.h>

#include <eez/gui/assets.h>
using namespace eez::gui;

namespace eez {
namespace flow {

void run() {
static Assets *g_assets;

static const unsigned QUEUE_SIZE = 100;
static struct {
unsigned flowIndex;
unsigned componentIndex;
} g_queue[QUEUE_SIZE];
static unsigned g_queueHead;
static unsigned g_queueTail;
static bool g_queueIsFull = false;

void addToQueue(unsigned flowIndex, unsigned componentIndex) {
g_queue[g_queueTail].flowIndex = flowIndex;
g_queue[g_queueTail].componentIndex = componentIndex;

g_queueTail = (g_queueTail + 1) % QUEUE_SIZE;

if (g_queueHead == g_queueTail) {
g_queueIsFull = true;
}
}

bool removeFromQueue(unsigned &flowIndex, unsigned &componentIndex) {
if (g_queueHead == g_queueTail && !g_queueIsFull) {
return false;
}

flowIndex = g_queue[g_queueHead].flowIndex;
componentIndex = g_queue[g_queueHead].componentIndex;

g_queueHead = (g_queueHead + 1) % QUEUE_SIZE;
g_queueIsFull = false;

return true;
}

bool allInputsDefined(FlowDefinition &flowDefinition, unsigned flowIndex, unsigned componentIndex) {
auto &flow = flowDefinition.flows.first[flowIndex];
auto &component = flow.components.first[componentIndex];

for (unsigned inputIndex = 0; inputIndex < component.inputs.count; inputIndex++) {
auto &componentInput = component.inputs.first[inputIndex];

auto valueIndex = componentInput.values.first[0].valueIndex;

auto &value = flowDefinition.flowValues.first[valueIndex];
if (value.header.type == FLOW_VALUE_TYPE_UNDEFINED) {
return false;
}
}

return true;
}

unsigned start(Assets *assets) {
FlowDefinition &flowDefinition = *assets->flowDefinition;
if (flowDefinition.flows.count == 0) {
return 0;
}

g_assets = assets;

unsigned flowIndex = 0;

const Flow &flow = flowDefinition.flows.first[flowIndex];
for (unsigned componentIndex = 0; componentIndex < flow.components.count; componentIndex++) {
if (allInputsDefined(flowDefinition, flowIndex, componentIndex)) {
addToQueue(flowIndex, componentIndex);
}
}

return 1;
}

void executeComponent(FlowDefinition &flowDefinition, unsigned flowIndex, unsigned componentIndex) {
printf("Execute component %d\n", componentIndex);
}

void tick(unsigned flowHandle) {
if (flowHandle != 1) {
return;
}

Assets *assets = g_assets;
FlowDefinition &flowDefinition = *assets->flowDefinition;

unsigned flowIndex;
unsigned componentIndex;
if (removeFromQueue(flowIndex, componentIndex)) {
executeComponent(flowDefinition, flowIndex, componentIndex);
}
}


void dumpFlow(FlowDefinition &flowDefinition) {
// printf("Flows:\n");
// for (unsigned i = 0; i < flowDefinition.flows.count; i++) {
// printf("\t%d:\n", i);
// const Flow &flow = flowDefinition.flows.first[i];
// for (unsigned j = 0; j < flow.components.count; j++) {
// const Component &component = flow.components.first[j];
// printf("\t\t%d\n", j);
// printf("\t\t\tType: %d\n", (int)component.type);

// printf("\t\t\tInputs:\n");
// for (unsigned k = 0; k < component.inputs.count; k++) {
// const ComponentInput &componentInput = component.inputs.first[k];
// printf("\t\t\t\t%d\n", componentInput.values.count);
// }

// printf("\t\t\tOutputs:\n");
// for (unsigned k = 0; k < component.outputs.count; k++) {
// const ComponentOutput &componentOutput = component.outputs.first[k];
// printf("\t\t\t\t%d\n", componentOutput.connections.count);
// }
// }
// }

// printf("Values:\n");
// for (unsigned i = 0; i < flowDefinition.flowValues.count; i++) {
// const FlowValue &flowValue = flowDefinition.flowValues.first[i];
// printf("\t%d: %d\n", i, (int)flowValue.header.type);
// }
}

} // namespace flow
Expand Down
52 changes: 3 additions & 49 deletions src/eez/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,13 @@

#pragma once

#include <stdint.h>
#include <eez/gui/assets_ptr.h>
#include <eez/gui/assets.h>

namespace eez {

namespace gui {
struct Assets;
}

namespace flow {

template <typename T>
struct List {
uint32_t count;
AssetsPtr<T> first;
};

struct ComponentInput {
uint8_t count;
uint16_t valueIndex[255];
};

struct Connection {
uint16_t targetComponentIndex;
uint8_t targetInputIndex;
};

struct ComponentOutput {
uint8_t count;
Connection connections[255];
};

struct Component {
uint16_t type;
List<ComponentInput> inputs;
List<ComponentOutput> outputs;
AssetsPtr<const void> specific;
};

struct Flow {
List<const Component> flows;
};

struct Value {
uint8_t type;
};

struct FlowDefinition {
List<const Flow> flows;
List<Value> values;
};

void run();
unsigned start(eez::gui::Assets *assets);
void tick(unsigned flowHandle);

} // flow
} // eez
4 changes: 2 additions & 2 deletions src/eez/gui/app_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ bool AppContext::canExecuteActionWhenTouchedOutsideOfActivePage(int pageId, int
void AppContext::onPageTouch(const WidgetCursor &foundWidget, Event &touchEvent) {
int activePageId = getActivePageId();
if (activePageId != PAGE_ID_NONE && !isPageInternal(activePageId)) {
const Widget *page = getPageWidget(activePageId);
const PageWidget *pageSpecific = GET_WIDGET_PROPERTY(page, specific, const PageWidget *);
auto page = getPageWidget(activePageId);
auto pageSpecific = GET_WIDGET_PROPERTY(page, specific, const PageWidget *);
if ((pageSpecific->flags & CLOSE_PAGE_IF_TOUCHED_OUTSIDE_FLAG) != 0) {
if (!pointInsideRect(touchEvent.x, touchEvent.y, foundWidget.appContext->rect.x + page->x, foundWidget.appContext->rect.y + page->y, page->w, page->h)) {
int activePageId = getActivePageId();
Expand Down
Loading

0 comments on commit 76b8806

Please sign in to comment.