Skip to content

Commit

Permalink
Add comments to fwd_declare_component example
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 19, 2023
1 parent a016e60 commit dfcf0db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions examples/c/entities/fwd_declare_component/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// component id, but this variable is scoped to the function only. When trying
// to access the component from another function, this typically causes errors
// that look like this:
// "FLECS__EComponentName" is undefined
// "FLECS_IDComponentNameID" is undefined
//
// Forward declaring a component will make the component id available from other
// functions, which fixes this error.
Expand All @@ -17,9 +17,19 @@ typedef struct {
} Position;

// The forward declaration of the component id variable. This variable will have
// the name FLECS__EPosition, to ensure its name won't conflict with the type.
// the name FLECS_IDPositionID, to ensure its name won't conflict with the type.
ECS_COMPONENT_DECLARE(Position);

// When you want forward declare a component from a header, make sure to use the
// extern keyword to prevent multiple definitions of the same variable:
//
// In the header:
// extern ECS_COMPONENT_DECLARE(Position);
//
// In *one* of the source files:
// ECS_COMPONENT_DECLARE(Position);


// To forward declare entities created with ECS_ENTITY, ECS_TAG or ECS_PREFAB,
// use ECS_DECLARE.
ECS_DECLARE(Wizard);
Expand Down
4 changes: 2 additions & 2 deletions examples/cpp/queries/find_entity/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <iostream>

struct Position {
double x, y;
int x, y;
};

int main() {
Expand All @@ -16,7 +16,7 @@ int main() {

// Find the entity for which Position.x is 20
flecs::entity e = q.find([](Position& p) {
return p.x == 20.0;
return p.x == 20;
});

if (e) {
Expand Down

0 comments on commit dfcf0db

Please sign in to comment.