Linha de comando: pasta é ignorada com aviso, projeto é aberto
Todo argumento ia para o dlopen como library: abrir o editor com uma pasta (./TinyBlocks.AppDir) dava "dlopen: ... Is a directory". Agora .so é library, pasta é ignorada com um aviso claro e qualquer outro arquivo é aberto como projeto (.json, ou .txt em scratchblocks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2a2d22a64a
commit
bfa17eecea
15 files changed
+9784
-124
No files matched your search
@@ -19,13 +19,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <tinyblocks/tb_json_block.h>
|
||||
|
||||
#define TB_BP_MAX_WS 256
|
||||
#define TB_BP_MAX_WS 65536 /* teto de blocos por aba (o vetor cresce sob demanda) */
|
||||
#define TB_BP_MAX_INPUTS 16
|
||||
#define TB_BP_MAX_TABS 8
|
||||
#define TB_BP_MAX_UBLOCKS 16
|
||||
#define TB_BP_MAX_UBLOCKS 64
|
||||
#define TB_BP_MAX_UPARTS 16
|
||||
#define TB_BP_MAX_USLOTS 8
|
||||
#define TB_BP_MAX_VARS 64
|
||||
#define TB_BP_MAX_VARS 4096
|
||||
#define TB_BP_LIT_CAP 512
|
||||
#define TB_BP_MAX_GROUPS 32
|
||||
|
||||
@@ -59,8 +59,14 @@ typedef struct {
|
||||
} TbBpGroup;
|
||||
|
||||
typedef struct {
|
||||
TbBpBlock blocks[TB_BP_MAX_WS];
|
||||
int top[TB_BP_MAX_WS];
|
||||
/* O indice do bloco e a identidade dele: o vetor pode crescer (realloc)
|
||||
sem invalidar os vinculos, mas nunca compacta. */
|
||||
TbBpBlock* blocks;
|
||||
int blocks_cap; /* slots alocados */
|
||||
int blocks_n; /* maior indice usado + 1 */
|
||||
int blocks_scan; /* dica do proximo slot livre */
|
||||
int* top;
|
||||
int top_cap;
|
||||
int top_n;
|
||||
float ws_sx, ws_sy;
|
||||
char name[48];
|
||||
@@ -114,9 +120,13 @@ void tb_blueprint_clear(TbBlueprint* bp);
|
||||
/* Cria uma aba; devolve o indice ou -1. */
|
||||
int tb_blueprint_add_tab(TbBlueprint* bp, const char* name, bool composite);
|
||||
TbBpTab* tb_blueprint_tab(TbBlueprint* bp, int i);
|
||||
/* Solta o pool de uma TbBpTab isolada (a struct em si e de quem chamou) */
|
||||
void tb_blueprint_tab_free(TbBpTab* t);
|
||||
|
||||
/* Aloca um bloco no pool da aba; devolve o indice ou -1. */
|
||||
int tb_blueprint_alloc_block(TbBpTab* t);
|
||||
/* Garante que o slot i existe (zerado); devolve o bloco ou NULL. */
|
||||
TbBpBlock* tb_blueprint_tab_slot(TbBpTab* t, int i);
|
||||
/* Liga child ao pai na relacao rel (child < 0 desliga). */
|
||||
void tb_blueprint_link(TbBpTab* t, int parent, int rel, int child);
|
||||
void tb_blueprint_top_add(TbBpTab* t, int bi);
|
||||
|
||||
@@ -16,26 +16,54 @@ TbBlueprint* tb_blueprint_new(void) {
|
||||
}
|
||||
|
||||
void tb_blueprint_free(TbBlueprint* bp) {
|
||||
if (!bp) return;
|
||||
for (int i = 0; i < TB_BP_MAX_TABS; i++) {
|
||||
free(bp->tabs[i].blocks);
|
||||
free(bp->tabs[i].top);
|
||||
}
|
||||
free(bp);
|
||||
}
|
||||
|
||||
/* Zera um bloco para o estado "vazio" (sem pai, sem proximo, campos -1) */
|
||||
static void bp_block_init(TbBpBlock* b) {
|
||||
memset(b, 0, sizeof(*b));
|
||||
b->parent = -1;
|
||||
b->prel = TB_BP_REL_NONE;
|
||||
b->next = -1;
|
||||
b->sub[0] = b->sub[1] = b->sub[2] = -1;
|
||||
for (int s = 0; s < TB_BP_MAX_INPUTS; s++) b->args[s] = -1;
|
||||
}
|
||||
|
||||
void tb_blueprint_clear(TbBlueprint* bp) {
|
||||
if (!bp) return;
|
||||
memset(bp, 0, sizeof(*bp));
|
||||
for (int i = 0; i < TB_BP_MAX_TABS; i++) {
|
||||
TbBpTab* t = &bp->tabs[i];
|
||||
t->comp_id = -1;
|
||||
for (int b = 0; b < TB_BP_MAX_WS; b++) {
|
||||
t->blocks[b].parent = -1;
|
||||
t->blocks[b].prel = TB_BP_REL_NONE;
|
||||
t->blocks[b].next = -1;
|
||||
t->blocks[b].sub[0] = t->blocks[b].sub[1] = t->blocks[b].sub[2] = -1;
|
||||
for (int s = 0; s < TB_BP_MAX_INPUTS; s++) t->blocks[b].args[s] = -1;
|
||||
}
|
||||
for (int i = 0; i < TB_BP_MAX_TABS; i++) { /* antes do memset: solta o pool */
|
||||
free(bp->tabs[i].blocks);
|
||||
free(bp->tabs[i].top);
|
||||
}
|
||||
memset(bp, 0, sizeof(*bp));
|
||||
for (int i = 0; i < TB_BP_MAX_TABS; i++) bp->tabs[i].comp_id = -1;
|
||||
for (int u = 0; u < TB_BP_MAX_UBLOCKS; u++) bp->user_blocks[u].tab_idx = -1;
|
||||
}
|
||||
|
||||
/* Garante que o slot i existe (zerado e marcado como usado) */
|
||||
TbBpBlock* tb_blueprint_tab_slot(TbBpTab* t, int i) {
|
||||
if (!t || i < 0 || i >= TB_BP_MAX_WS) return NULL;
|
||||
if (i >= t->blocks_cap) {
|
||||
int nc = t->blocks_cap ? t->blocks_cap : 64;
|
||||
while (nc <= i) nc *= 2;
|
||||
TbBpBlock* p = (TbBpBlock*)realloc(t->blocks, (size_t)nc * sizeof(*p));
|
||||
if (!p) return NULL;
|
||||
for (int k = t->blocks_cap; k < nc; k++) bp_block_init(&p[k]);
|
||||
t->blocks = p;
|
||||
t->blocks_cap = nc;
|
||||
}
|
||||
if (i >= t->blocks_n) t->blocks_n = i + 1;
|
||||
/* slot novo (ou reaproveitado pela serializacao): nasce vazio */
|
||||
if (!t->blocks[i].used) bp_block_init(&t->blocks[i]);
|
||||
for (int s = 0; s < TB_BP_MAX_INPUTS; s++) if (t->blocks[i].args[s] < 0) t->blocks[i].args[s] = -1;
|
||||
return &t->blocks[i];
|
||||
}
|
||||
|
||||
int tb_blueprint_add_tab(TbBlueprint* bp, const char* name, bool composite) {
|
||||
if (!bp || bp->tab_count >= TB_BP_MAX_TABS) return -1;
|
||||
int idx = bp->tab_count++;
|
||||
@@ -45,16 +73,16 @@ int tb_blueprint_add_tab(TbBlueprint* bp, const char* name, bool composite) {
|
||||
t->composite = composite;
|
||||
if (name && name[0]) snprintf(t->name, sizeof(t->name), "%s", name);
|
||||
else snprintf(t->name, sizeof(t->name), "Codigo %d", idx + 1);
|
||||
for (int b = 0; b < TB_BP_MAX_WS; b++) {
|
||||
t->blocks[b].parent = -1;
|
||||
t->blocks[b].prel = TB_BP_REL_NONE;
|
||||
t->blocks[b].next = -1;
|
||||
t->blocks[b].sub[0] = t->blocks[b].sub[1] = t->blocks[b].sub[2] = -1;
|
||||
for (int s = 0; s < TB_BP_MAX_INPUTS; s++) t->blocks[b].args[s] = -1;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
/* Solta o pool de uma TbBpTab isolada (a struct em si e de quem chamou) */
|
||||
void tb_blueprint_tab_free(TbBpTab* t) {
|
||||
if (!t) return;
|
||||
free(t->blocks); t->blocks = NULL; t->blocks_cap = t->blocks_n = t->blocks_scan = 0;
|
||||
free(t->top); t->top = NULL; t->top_cap = t->top_n = 0;
|
||||
}
|
||||
|
||||
TbBpTab* tb_blueprint_tab(TbBlueprint* bp, int i) {
|
||||
if (!bp || i < 0 || i >= bp->tab_count) return NULL;
|
||||
return &bp->tabs[i];
|
||||
@@ -62,30 +90,33 @@ TbBpTab* tb_blueprint_tab(TbBlueprint* bp, int i) {
|
||||
|
||||
int tb_blueprint_alloc_block(TbBpTab* t) {
|
||||
if (!t) return -1;
|
||||
for (int i = 0; i < TB_BP_MAX_WS; i++) {
|
||||
if (t->blocks[i].used) continue;
|
||||
TbBpBlock* b = &t->blocks[i];
|
||||
memset(b, 0, sizeof(*b));
|
||||
/* dica nao anda para tras: alocacao em serie fica O(1) amortizado */
|
||||
int i = t->blocks_scan;
|
||||
while (i < t->blocks_n && t->blocks[i].used) i++;
|
||||
if (i >= t->blocks_n) {
|
||||
if (i >= TB_BP_MAX_WS) return -1;
|
||||
TbBpBlock* b = tb_blueprint_tab_slot(t, i);
|
||||
if (!b) return -1;
|
||||
b->used = true;
|
||||
b->parent = -1;
|
||||
b->prel = TB_BP_REL_NONE;
|
||||
b->next = -1;
|
||||
b->sub[0] = b->sub[1] = b->sub[2] = -1;
|
||||
for (int s = 0; s < TB_BP_MAX_INPUTS; s++) b->args[s] = -1;
|
||||
t->blocks_scan = i + 1;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
TbBpBlock* b = &t->blocks[i];
|
||||
bp_block_init(b);
|
||||
b->used = true;
|
||||
t->blocks_scan = i + 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
void tb_blueprint_link(TbBpTab* t, int parent, int rel, int child) {
|
||||
if (!t || parent < 0 || parent >= TB_BP_MAX_WS) return;
|
||||
if (!t || parent < 0 || parent >= t->blocks_n) return;
|
||||
TbBpBlock* p = &t->blocks[parent];
|
||||
if (rel == TB_BP_REL_NEXT) p->next = child;
|
||||
else if (rel < TB_BP_REL_ARG0) p->sub[rel - TB_BP_REL_SUB0] = child;
|
||||
else p->args[rel - TB_BP_REL_ARG0] = child;
|
||||
if (child >= 0 && child < TB_BP_MAX_WS) {
|
||||
t->blocks[child].parent = parent;
|
||||
t->blocks[child].prel = rel;
|
||||
if (child >= 0) {
|
||||
TbBpBlock* c = tb_blueprint_tab_slot(t, child);
|
||||
if (c) { c->parent = parent; c->prel = rel; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +128,14 @@ void tb_blueprint_top_add(TbBpTab* t, int bi) {
|
||||
t->top_n--;
|
||||
break;
|
||||
}
|
||||
if (t->top_n < TB_BP_MAX_WS) t->top[t->top_n++] = bi;
|
||||
if (t->top_n >= t->top_cap) {
|
||||
int nc = t->top_cap ? t->top_cap * 2 : 32;
|
||||
int* p = (int*)realloc(t->top, (size_t)nc * sizeof(*p));
|
||||
if (!p) return;
|
||||
t->top = p;
|
||||
t->top_cap = nc;
|
||||
}
|
||||
t->top[t->top_n++] = bi;
|
||||
}
|
||||
|
||||
void tb_blueprint_var_set_text(TbBlueprint* bp, const char* name, const char* value) {
|
||||
|
||||
@@ -46,7 +46,7 @@ TinyBlocks_JsonValue* tb_blueprint_to_json(const TbBlueprint* bp) {
|
||||
|
||||
TinyBlocks_JsonValue* jb = tb_json_array();
|
||||
PUT(jt, "blocks", jb);
|
||||
for (int i = 0; i < TB_BP_MAX_WS; i++) {
|
||||
for (int i = 0; i < T->blocks_n; i++) {
|
||||
const TbBpBlock* b = &T->blocks[i];
|
||||
if (!b->used) continue;
|
||||
TinyBlocks_JsonValue* o = tb_json_object();
|
||||
@@ -210,8 +210,8 @@ TbBlueprint* tb_blueprint_from_json(const TinyBlocks_JsonValue* root) {
|
||||
for (uint32_t bi = 0; jb && bi < tb_json_array_length(jb); bi++) {
|
||||
TinyBlocks_JsonValue* o = tb_json_array_get(jb, bi);
|
||||
int i = (int)jget_num(o, "i", -1);
|
||||
if (i >= 0 && i < TB_BP_MAX_WS) {
|
||||
TbBpBlock* b = &T->blocks[i];
|
||||
TbBpBlock* b = tb_blueprint_tab_slot(T, i); /* cresce ate o indice i */
|
||||
if (b) {
|
||||
b->used = true;
|
||||
snprintf(b->type, sizeof(b->type), "%s", jget_str(o, "type", ""));
|
||||
b->x = (float)jget_num(o, "x", 0);
|
||||
@@ -241,10 +241,17 @@ TbBlueprint* tb_blueprint_from_json(const TinyBlocks_JsonValue* root) {
|
||||
|
||||
TinyBlocks_JsonValue* top = tb_json_object_get(jt, "top");
|
||||
T->top_n = 0;
|
||||
for (uint32_t i = 0; top && i < tb_json_array_length(top) && T->top_n < TB_BP_MAX_WS; i++) {
|
||||
for (uint32_t i = 0; top && i < tb_json_array_length(top); i++) {
|
||||
TinyBlocks_JsonValue* e = tb_json_array_get(top, i);
|
||||
T->top[T->top_n++] = e ? (int)tb_json_as_number(e, 0) : 0;
|
||||
int h = e ? (int)tb_json_as_number(e, 0) : 0;
|
||||
tb_json_release(e);
|
||||
if (T->top_n >= T->top_cap) {
|
||||
int nc = T->top_cap ? T->top_cap * 2 : 32;
|
||||
int* p = (int*)realloc(T->top, (size_t)nc * sizeof(*p));
|
||||
if (!p) break;
|
||||
T->top = p; T->top_cap = nc;
|
||||
}
|
||||
T->top[T->top_n++] = h;
|
||||
}
|
||||
tb_json_release(top);
|
||||
|
||||
@@ -412,7 +419,7 @@ static void blueprint_xml(Buf* b, const TbBlueprint* bp) {
|
||||
for (int i = 0; i < T->top_n; i++) { char t[24]; snprintf(t, sizeof(t), "<i>%d</i>", T->top[i]); bs(b, t); }
|
||||
bs(b, "</top>\n");
|
||||
bindent(b, 3); bs(b, "<blocks>\n");
|
||||
for (int i = 0; i < TB_BP_MAX_WS; i++) {
|
||||
for (int i = 0; i < T->blocks_n; i++) {
|
||||
const TbBpBlock* bl = &T->blocks[i];
|
||||
if (!bl->used) continue;
|
||||
bindent(b, 4); bs(b, "<block");
|
||||
@@ -529,7 +536,7 @@ static TinyBlocks_JsonValue* blueprint_csv_tree(const TbBlueprint* bp) {
|
||||
TinyBlocks_JsonValue* arr = tb_json_array();
|
||||
for (int ti = 0; ti < bp->tab_count; ti++) {
|
||||
const TbBpTab* T = &bp->tabs[ti];
|
||||
for (int i = 0; i < TB_BP_MAX_WS; i++) {
|
||||
for (int i = 0; i < T->blocks_n; i++) {
|
||||
const TbBpBlock* b = &T->blocks[i];
|
||||
if (!b->used) continue;
|
||||
TinyBlocks_JsonValue* o = tb_json_object();
|
||||
|
||||
Reference in new issue
Block a user