Properly link flecs library
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#ifndef BASICS_H
|
||||
#define BASICS_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "basics/bake_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
)
|
||||
(.)
|
||||
.|.
|
||||
| |
|
||||
_.--| |--._
|
||||
.-'; ;`-'& ; `&.
|
||||
\ & ; & &_/
|
||||
|"""---...---"""|
|
||||
\ | | | | | | | /
|
||||
`---.|.|.|.---'
|
||||
|
||||
* This file is generated by bake.lang.c for your convenience. Headers of
|
||||
* dependencies will automatically show up in this file. Include bake_config.h
|
||||
* in your main project file. Do not edit! */
|
||||
|
||||
#ifndef BASICS_BAKE_CONFIG_H
|
||||
#define BASICS_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "basics",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"author": "Jane Doe",
|
||||
"description": "A simple hello world flecs application",
|
||||
"use": [
|
||||
"flecs"
|
||||
]
|
||||
}
|
||||
}
|
||||
46
engine/libs/flecs/examples/c/relationships/basics/src/main.c
Normal file
46
engine/libs/flecs/examples/c/relationships/basics/src/main.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <basics.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ecs_world_t *ecs = ecs_init_w_args(argc, argv);
|
||||
|
||||
ECS_TAG(ecs, Eats);
|
||||
|
||||
// Entity used for Grows relationship
|
||||
ecs_entity_t grows = ecs_new_entity(ecs, "Grows");
|
||||
|
||||
// Relationship objects
|
||||
ecs_entity_t apples = ecs_new_entity(ecs, "Apples");
|
||||
ecs_entity_t pears = ecs_new_entity(ecs, "Pears");
|
||||
|
||||
// Create an entity with 3 relationships. Relationships are like regular components,
|
||||
// but combine two types/identifiers into an (relationship, object) pair.
|
||||
ecs_entity_t bob = ecs_new_entity(ecs, "Bob");
|
||||
// Pairs can be constructed from a type and entity
|
||||
ecs_add_pair(ecs, bob, Eats, apples);
|
||||
ecs_add_pair(ecs, bob, Eats, pears);
|
||||
// Pairs can also be constructed from two entity ids
|
||||
ecs_add_pair(ecs, bob, grows, pears);
|
||||
|
||||
// Has can be used with relationships as well
|
||||
printf("Bob eats apples? %d\n", ecs_has_pair(ecs, bob, Eats, apples));
|
||||
|
||||
// Wildcards can be used to match relationships
|
||||
printf("Bob grows food? %d\n", ecs_has_pair(ecs, bob, grows, EcsWildcard));
|
||||
|
||||
// Print the type of the entity. Should output:
|
||||
// (Identifier,Name),(Eats,Apples),(Eats,Pears),(Grows,Pears)
|
||||
char *type_str = ecs_type_str(ecs, ecs_get_type(ecs, bob));
|
||||
printf("Bob's type: [%s]\n", type_str);
|
||||
ecs_os_free(type_str);
|
||||
|
||||
// Get first target of relationship
|
||||
printf("Bob eats %s\n",
|
||||
ecs_get_name(ecs, ecs_get_target(ecs, bob, Eats, 0)));
|
||||
|
||||
// Get second target of relationship
|
||||
printf("Bob also eats %s\n",
|
||||
ecs_get_name(ecs, ecs_get_target(ecs, bob, Eats, 1)));
|
||||
|
||||
return ecs_fini(ecs);
|
||||
}
|
||||
Reference in New Issue
Block a user