Skip to content

Commit

Permalink
Add frequency units
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Nov 24, 2022
1 parent c813da8 commit f62c991
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
47 changes: 47 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30510,6 +30510,12 @@ ECS_DECLARE(EcsAngle);
ECS_DECLARE(EcsBel);
ECS_DECLARE(EcsDeciBel);

ECS_DECLARE(EcsFrequency);
ECS_DECLARE(EcsHerz);
ECS_DECLARE(EcsKiloHerz);
ECS_DECLARE(EcsMegaHerz);
ECS_DECLARE(EcsGigaHerz);

void FlecsUnitsImport(
ecs_world_t *world)
{
Expand Down Expand Up @@ -31321,6 +31327,47 @@ void FlecsUnitsImport(
.kind = EcsF32
});

EcsFrequency = ecs_quantity_init(world, &(ecs_entity_desc_t){
.name = "Frequency" });
prev_scope = ecs_set_scope(world, EcsFrequency);

EcsHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "Herz" }),
.quantity = EcsFrequency,
.symbol = "Hz" });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsHerz,
.kind = EcsF32
});

EcsKiloHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "KiloHerz" }),
.prefix = EcsKilo,
.base = EcsHerz });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsKiloHerz,
.kind = EcsF32
});

EcsMegaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "MegaHerz" }),
.prefix = EcsMega,
.base = EcsHerz });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsMegaHerz,
.kind = EcsF32
});

EcsGigaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "GigaHerz" }),
.prefix = EcsGiga,
.base = EcsHerz });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsGigaHerz,
.kind = EcsF32
});
ecs_set_scope(world, prev_scope);

/* Documentation */
#ifdef FLECS_DOC
ECS_IMPORT(world, FlecsDoc);
Expand Down
24 changes: 24 additions & 0 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11783,6 +11783,12 @@ FLECS_API extern ECS_DECLARE(EcsDegrees);
FLECS_API extern ECS_DECLARE(EcsBel);
FLECS_API extern ECS_DECLARE(EcsDeciBel);

FLECS_API extern ECS_DECLARE(EcsFrequency);
FLECS_API extern ECS_DECLARE(EcsHerz);
FLECS_API extern ECS_DECLARE(EcsKiloHerz);
FLECS_API extern ECS_DECLARE(EcsMegaHerz);
FLECS_API extern ECS_DECLARE(EcsGigaHerz);

////////////////////////////////////////////////////////////////////////////////
//// Module
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -15612,6 +15618,7 @@ struct Temperature { };
struct Data { };
struct DataRate { };
struct Angle { };
struct Frequency { };


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -15713,6 +15720,13 @@ struct MegaBytesPerSecond { };
struct GigaBytesPerSecond { };
};

struct frequency {
struct Herz { };
struct KiloHerz { };
struct MegaHerz { };
struct GigaHerz { };
};

struct Percentage { };
struct Bel { };
struct DeciBel { };
Expand Down Expand Up @@ -25122,6 +25136,16 @@ inline units::units(flecs::world& world) {
world.entity<datarate::GigaBytesPerSecond>(
"::flecs::units::DataRate::GigaBytesPerSecond");

// Initialize datarate units
world.entity<frequency::Herz>(
"::flecs::units::Frequency::Herz");
world.entity<frequency::KiloHerz>(
"::flecs::units::Frequency::KiloHerz");
world.entity<frequency::MegaHerz>(
"::flecs::units::Frequency::MegaHerz");
world.entity<frequency::GigaHerz>(
"::flecs::units::Frequency::GigaHerz");

// Initialize angles
world.entity<angle::Radians>(
"::flecs::units::Angle::Radians");
Expand Down
8 changes: 8 additions & 0 deletions include/flecs/addons/cpp/mixins/units/decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct Temperature { };
struct Data { };
struct DataRate { };
struct Angle { };
struct Frequency { };


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -158,6 +159,13 @@ struct MegaBytesPerSecond { };
struct GigaBytesPerSecond { };
};

struct frequency {
struct Herz { };
struct KiloHerz { };
struct MegaHerz { };
struct GigaHerz { };
};

struct Percentage { };
struct Bel { };
struct DeciBel { };
Expand Down
10 changes: 10 additions & 0 deletions include/flecs/addons/cpp/mixins/units/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ inline units::units(flecs::world& world) {
world.entity<datarate::GigaBytesPerSecond>(
"::flecs::units::DataRate::GigaBytesPerSecond");

// Initialize datarate units
world.entity<frequency::Herz>(
"::flecs::units::Frequency::Herz");
world.entity<frequency::KiloHerz>(
"::flecs::units::Frequency::KiloHerz");
world.entity<frequency::MegaHerz>(
"::flecs::units::Frequency::MegaHerz");
world.entity<frequency::GigaHerz>(
"::flecs::units::Frequency::GigaHerz");

// Initialize angles
world.entity<angle::Radians>(
"::flecs::units::Angle::Radians");
Expand Down
6 changes: 6 additions & 0 deletions include/flecs/addons/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ FLECS_API extern ECS_DECLARE(EcsDegrees);
FLECS_API extern ECS_DECLARE(EcsBel);
FLECS_API extern ECS_DECLARE(EcsDeciBel);

FLECS_API extern ECS_DECLARE(EcsFrequency);
FLECS_API extern ECS_DECLARE(EcsHerz);
FLECS_API extern ECS_DECLARE(EcsKiloHerz);
FLECS_API extern ECS_DECLARE(EcsMegaHerz);
FLECS_API extern ECS_DECLARE(EcsGigaHerz);

////////////////////////////////////////////////////////////////////////////////
//// Module
////////////////////////////////////////////////////////////////////////////////
Expand Down
47 changes: 47 additions & 0 deletions src/addons/units.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ ECS_DECLARE(EcsAngle);
ECS_DECLARE(EcsBel);
ECS_DECLARE(EcsDeciBel);

ECS_DECLARE(EcsFrequency);
ECS_DECLARE(EcsHerz);
ECS_DECLARE(EcsKiloHerz);
ECS_DECLARE(EcsMegaHerz);
ECS_DECLARE(EcsGigaHerz);

void FlecsUnitsImport(
ecs_world_t *world)
{
Expand Down Expand Up @@ -934,6 +940,47 @@ void FlecsUnitsImport(
.kind = EcsF32
});

EcsFrequency = ecs_quantity_init(world, &(ecs_entity_desc_t){
.name = "Frequency" });
prev_scope = ecs_set_scope(world, EcsFrequency);

EcsHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "Herz" }),
.quantity = EcsFrequency,
.symbol = "Hz" });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsHerz,
.kind = EcsF32
});

EcsKiloHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "KiloHerz" }),
.prefix = EcsKilo,
.base = EcsHerz });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsKiloHerz,
.kind = EcsF32
});

EcsMegaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "MegaHerz" }),
.prefix = EcsMega,
.base = EcsHerz });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsMegaHerz,
.kind = EcsF32
});

EcsGigaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
.entity = ecs_entity(world, { .name = "GigaHerz" }),
.prefix = EcsGiga,
.base = EcsHerz });
ecs_primitive_init(world, &(ecs_primitive_desc_t){
.entity = EcsGigaHerz,
.kind = EcsF32
});
ecs_set_scope(world, prev_scope);

/* Documentation */
#ifdef FLECS_DOC
ECS_IMPORT(world, FlecsDoc);
Expand Down

0 comments on commit f62c991

Please sign in to comment.