This repository has been archived! Use the JSON addon in the Flecs main repository instead.
flecs-hub / flecs-json Goto Github PK
View Code? Open in Web Editor NEWArchived!
License: MIT License
Archived!
License: MIT License
This repository has been archived! Use the JSON addon in the Flecs main repository instead.
This function doesn't exist in that form. Theres only
Lines 331 to 335 in 9c64f27
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)
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);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.