9. Grid Graforge Nodes

9.1. Gridstate

9.1.1. Gridstate Graforge Node

9.1.1.1. Gridstate Node Function

<<grid_function_declarations>>=
static int node_gridstate(gf_node *node, monolith_page *pg);
<<grid_functions>>=
<<gridstate_node_functions>>
static int node_gridstate(gf_node *node, monolith_page *pg)
{
    gf_node_cables_alloc(node, 3);
    gf_node_set_block(node, 2);
    gf_node_set_data(node, pg);
    gf_node_set_destroy(node, gridstate_destroy);
    gf_node_set_compute(node, gridstate_compute);
    /* TODO: "pin" page here */
    return GF_OK;
}
9.1.1.2. Gridstate Compute

<<gridstate_node_functions>>=
static void gridstate_compute(gf_node *node)
{
    int blksize;
    int s;
    GFFLT s_x, s_y, s_out;
    gf_cable *x, *y, *out;
    monolith_page *pg;
    page_grid_d *grid;

    blksize = gf_node_blksize(node);
    gf_node_get_cable(node, 0, &x);
    gf_node_get_cable(node, 1, &y);
    gf_node_get_cable(node, 2, &out);
    pg = gf_node_get_data(node);
    grid = monolith_page_data_get(pg);

    for(s = 0; s < blksize; s++) {
        s_x = gf_cable_get(x, s);
        s_y = gf_cable_get(y, s);
        s_out = monolith_page_mstate_get(grid->mstate, (int)s_x, (int)s_y);
        gf_cable_set(out, s, s_out);
    }
}
9.1.1.3. Gridstate Destroy

<<gridstate_node_functions>>=
static void gridstate_destroy(gf_node *node)
{
    /* TODO: "unpin" page here */
    gf_node_cables_free(node);
}

9.1.2. Gridstate Runt Word

<<grid_runt_keywords>>=
monolith_runt_keyword(m, "gridstate", 9, rproc_gridstate, m);
<<grid_runt_functions>>=
static runt_int rproc_gridstate(runt_vm *vm, runt_ptr p)
{
    monolith_d *m;
    runt_int rc;
    rgf_param x;
    rgf_param y;
    const char *name;
    runt_stacklet *s;
    runt_stacklet *out;
    monolith_page *pg;
    gf_patch *patch;
    gf_node *node;

    m = runt_to_cptr(p);
    rc = runt_ppop(vm, &s);
    RUNT_ERROR_CHECK(rc);

    name = runt_to_string(s->p);

    rc = rgf_get_param(vm, &y);
    RUNT_ERROR_CHECK(rc);

    rc = rgf_get_param(vm, &x);
    RUNT_ERROR_CHECK(rc);

    rc = runt_ppush(vm, &out);
    RUNT_ERROR_CHECK(rc);

    rc = runt_monolith_lookup_page(vm, m, name,
                                   "grid",
                                   is_grid, &pg);
    RUNT_ERROR_CHECK(rc);

    patch = monolith_graforge_get(m);

    rc = gf_patch_new_node(patch, &node);
    GF_RUNT_ERROR_CHECK(rc);

    node_gridstate(node, pg);

    rgf_set_param(vm, node, &x, 0);
    rgf_set_param(vm, node, &y, 1);
    rgf_push_output(vm, node, out, 2);

    return RUNT_OK;
}



prev | home | next