Code Monkey home page Code Monkey logo

flecs-json's Introduction

This repository has been archived! Use the JSON addon in the Flecs main repository instead.

flecs-json's People

Contributors

arncarveris avatar sandermertens avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

flecs-json's Issues

Example 08_serialize_entity contains undefined function

char *str = ecs_ptr_to_json(world, player);

This function doesn't exist in that form. Theres only

flecs-json/src/main.c

Lines 331 to 335 in 9c64f27

char* ecs_ptr_to_json(
ecs_world_t *world,
ecs_entity_t type,
void* ptr)
{

Also: even when using this version, it would always fail for me with. Example

//...
ecs_entity_t player = ecs_set(world, ecs_set(world, 0,
        Foo, {200,100,1}),
        Bar, {32.0f});

char *str = ecs_ptr_to_json(world, player, 0);
// err : assert(component != 0) ..\flecs\src\entity.c:54: internal error

So, is this example broken? (By the way: I found out that ecs_entity_to_json actually would do what I expect from the example)

Nested structures do not access data correctly

When serializing nested structs, the pointer offsets are not calculated correctly for the nested fields.

Code to reproduce:

#include <flecs.h>
#include <flecs_components_meta.h>
#include <flecs_json.h>

ECS_STRUCT(Position, {
    int32_t x;
    int32_t y;
});

ECS_STRUCT(Color, {
        float r;
        float g;
        float b;
        Position test;
});

void SysPos(ecs_rows_t *rows)
{
    ECS_COLUMN(rows, Position, p, 1);
    ECS_COLUMN(rows, Color, c, 2);

    for (int i = 0; i < rows->count; i++)
    {
        printf("p.x = %d, p.y = %d\n", p[i].x, p[i].y);
        printf("c.r = %f, c.g = %f, c.b = %f, test.x = %d, test.y = %d\n", c[i].r, c[i].g, c[i].b, c[i].test.x, c[i].test.y);
    }
}

int main(void)
{
    ecs_world_t *world = ecs_init();

    ECS_IMPORT(world, FlecsComponentsMeta, 0);

    ECS_META(world, Position);
    ECS_META(world, Color);

    ECS_SYSTEM(world, SysPos, EcsOnUpdate, Position, Color);

    for (int i = 0; i < 2; i++)
    {
        ecs_entity_t e = ecs_new(world, 0);
        ecs_set(world, e, Position, { i, i * 2 });
        Color c;
        c.r = (float)i;
        c.g = c.r*c.r;
        c.b = c.r*c.g;
        c.test.x = i + 100;
        c.test.y = i + 200;
        ecs_set_ptr(world, e, Color, &c);
    }

    ecs_filter_t filter = { . include = ecs_type(Position) };

    char *json = ecs_filter_to_json(world, &filter);
	printf("%s\n", json);

    // to print out values
    ecs_progress(world, 0);

    return ecs_fini(world);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.