Skip to content

Commit f62c991

Browse files
committed
Add frequency units
1 parent c813da8 commit f62c991

File tree

6 files changed

+142
-0
lines changed

6 files changed

+142
-0
lines changed

flecs.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30510,6 +30510,12 @@ ECS_DECLARE(EcsAngle);
3051030510
ECS_DECLARE(EcsBel);
3051130511
ECS_DECLARE(EcsDeciBel);
3051230512

30513+
ECS_DECLARE(EcsFrequency);
30514+
ECS_DECLARE(EcsHerz);
30515+
ECS_DECLARE(EcsKiloHerz);
30516+
ECS_DECLARE(EcsMegaHerz);
30517+
ECS_DECLARE(EcsGigaHerz);
30518+
3051330519
void FlecsUnitsImport(
3051430520
ecs_world_t *world)
3051530521
{
@@ -31321,6 +31327,47 @@ void FlecsUnitsImport(
3132131327
.kind = EcsF32
3132231328
});
3132331329

31330+
EcsFrequency = ecs_quantity_init(world, &(ecs_entity_desc_t){
31331+
.name = "Frequency" });
31332+
prev_scope = ecs_set_scope(world, EcsFrequency);
31333+
31334+
EcsHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
31335+
.entity = ecs_entity(world, { .name = "Herz" }),
31336+
.quantity = EcsFrequency,
31337+
.symbol = "Hz" });
31338+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
31339+
.entity = EcsHerz,
31340+
.kind = EcsF32
31341+
});
31342+
31343+
EcsKiloHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
31344+
.entity = ecs_entity(world, { .name = "KiloHerz" }),
31345+
.prefix = EcsKilo,
31346+
.base = EcsHerz });
31347+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
31348+
.entity = EcsKiloHerz,
31349+
.kind = EcsF32
31350+
});
31351+
31352+
EcsMegaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
31353+
.entity = ecs_entity(world, { .name = "MegaHerz" }),
31354+
.prefix = EcsMega,
31355+
.base = EcsHerz });
31356+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
31357+
.entity = EcsMegaHerz,
31358+
.kind = EcsF32
31359+
});
31360+
31361+
EcsGigaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
31362+
.entity = ecs_entity(world, { .name = "GigaHerz" }),
31363+
.prefix = EcsGiga,
31364+
.base = EcsHerz });
31365+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
31366+
.entity = EcsGigaHerz,
31367+
.kind = EcsF32
31368+
});
31369+
ecs_set_scope(world, prev_scope);
31370+
3132431371
/* Documentation */
3132531372
#ifdef FLECS_DOC
3132631373
ECS_IMPORT(world, FlecsDoc);

flecs.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11783,6 +11783,12 @@ FLECS_API extern ECS_DECLARE(EcsDegrees);
1178311783
FLECS_API extern ECS_DECLARE(EcsBel);
1178411784
FLECS_API extern ECS_DECLARE(EcsDeciBel);
1178511785

11786+
FLECS_API extern ECS_DECLARE(EcsFrequency);
11787+
FLECS_API extern ECS_DECLARE(EcsHerz);
11788+
FLECS_API extern ECS_DECLARE(EcsKiloHerz);
11789+
FLECS_API extern ECS_DECLARE(EcsMegaHerz);
11790+
FLECS_API extern ECS_DECLARE(EcsGigaHerz);
11791+
1178611792
////////////////////////////////////////////////////////////////////////////////
1178711793
//// Module
1178811794
////////////////////////////////////////////////////////////////////////////////
@@ -15612,6 +15618,7 @@ struct Temperature { };
1561215618
struct Data { };
1561315619
struct DataRate { };
1561415620
struct Angle { };
15621+
struct Frequency { };
1561515622

1561615623

1561715624
////////////////////////////////////////////////////////////////////////////////
@@ -15713,6 +15720,13 @@ struct MegaBytesPerSecond { };
1571315720
struct GigaBytesPerSecond { };
1571415721
};
1571515722

15723+
struct frequency {
15724+
struct Herz { };
15725+
struct KiloHerz { };
15726+
struct MegaHerz { };
15727+
struct GigaHerz { };
15728+
};
15729+
1571615730
struct Percentage { };
1571715731
struct Bel { };
1571815732
struct DeciBel { };
@@ -25122,6 +25136,16 @@ inline units::units(flecs::world& world) {
2512225136
world.entity<datarate::GigaBytesPerSecond>(
2512325137
"::flecs::units::DataRate::GigaBytesPerSecond");
2512425138

25139+
// Initialize datarate units
25140+
world.entity<frequency::Herz>(
25141+
"::flecs::units::Frequency::Herz");
25142+
world.entity<frequency::KiloHerz>(
25143+
"::flecs::units::Frequency::KiloHerz");
25144+
world.entity<frequency::MegaHerz>(
25145+
"::flecs::units::Frequency::MegaHerz");
25146+
world.entity<frequency::GigaHerz>(
25147+
"::flecs::units::Frequency::GigaHerz");
25148+
2512525149
// Initialize angles
2512625150
world.entity<angle::Radians>(
2512725151
"::flecs::units::Angle::Radians");

include/flecs/addons/cpp/mixins/units/decl.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct Temperature { };
5757
struct Data { };
5858
struct DataRate { };
5959
struct Angle { };
60+
struct Frequency { };
6061

6162

6263
////////////////////////////////////////////////////////////////////////////////
@@ -158,6 +159,13 @@ struct MegaBytesPerSecond { };
158159
struct GigaBytesPerSecond { };
159160
};
160161

162+
struct frequency {
163+
struct Herz { };
164+
struct KiloHerz { };
165+
struct MegaHerz { };
166+
struct GigaHerz { };
167+
};
168+
161169
struct Percentage { };
162170
struct Bel { };
163171
struct DeciBel { };

include/flecs/addons/cpp/mixins/units/impl.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ inline units::units(flecs::world& world) {
171171
world.entity<datarate::GigaBytesPerSecond>(
172172
"::flecs::units::DataRate::GigaBytesPerSecond");
173173

174+
// Initialize datarate units
175+
world.entity<frequency::Herz>(
176+
"::flecs::units::Frequency::Herz");
177+
world.entity<frequency::KiloHerz>(
178+
"::flecs::units::Frequency::KiloHerz");
179+
world.entity<frequency::MegaHerz>(
180+
"::flecs::units::Frequency::MegaHerz");
181+
world.entity<frequency::GigaHerz>(
182+
"::flecs::units::Frequency::GigaHerz");
183+
174184
// Initialize angles
175185
world.entity<angle::Radians>(
176186
"::flecs::units::Angle::Radians");

include/flecs/addons/units.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ FLECS_API extern ECS_DECLARE(EcsDegrees);
162162
FLECS_API extern ECS_DECLARE(EcsBel);
163163
FLECS_API extern ECS_DECLARE(EcsDeciBel);
164164

165+
FLECS_API extern ECS_DECLARE(EcsFrequency);
166+
FLECS_API extern ECS_DECLARE(EcsHerz);
167+
FLECS_API extern ECS_DECLARE(EcsKiloHerz);
168+
FLECS_API extern ECS_DECLARE(EcsMegaHerz);
169+
FLECS_API extern ECS_DECLARE(EcsGigaHerz);
170+
165171
////////////////////////////////////////////////////////////////////////////////
166172
//// Module
167173
////////////////////////////////////////////////////////////////////////////////

src/addons/units.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ ECS_DECLARE(EcsAngle);
123123
ECS_DECLARE(EcsBel);
124124
ECS_DECLARE(EcsDeciBel);
125125

126+
ECS_DECLARE(EcsFrequency);
127+
ECS_DECLARE(EcsHerz);
128+
ECS_DECLARE(EcsKiloHerz);
129+
ECS_DECLARE(EcsMegaHerz);
130+
ECS_DECLARE(EcsGigaHerz);
131+
126132
void FlecsUnitsImport(
127133
ecs_world_t *world)
128134
{
@@ -934,6 +940,47 @@ void FlecsUnitsImport(
934940
.kind = EcsF32
935941
});
936942

943+
EcsFrequency = ecs_quantity_init(world, &(ecs_entity_desc_t){
944+
.name = "Frequency" });
945+
prev_scope = ecs_set_scope(world, EcsFrequency);
946+
947+
EcsHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
948+
.entity = ecs_entity(world, { .name = "Herz" }),
949+
.quantity = EcsFrequency,
950+
.symbol = "Hz" });
951+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
952+
.entity = EcsHerz,
953+
.kind = EcsF32
954+
});
955+
956+
EcsKiloHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
957+
.entity = ecs_entity(world, { .name = "KiloHerz" }),
958+
.prefix = EcsKilo,
959+
.base = EcsHerz });
960+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
961+
.entity = EcsKiloHerz,
962+
.kind = EcsF32
963+
});
964+
965+
EcsMegaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
966+
.entity = ecs_entity(world, { .name = "MegaHerz" }),
967+
.prefix = EcsMega,
968+
.base = EcsHerz });
969+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
970+
.entity = EcsMegaHerz,
971+
.kind = EcsF32
972+
});
973+
974+
EcsGigaHerz = ecs_unit_init(world, &(ecs_unit_desc_t){
975+
.entity = ecs_entity(world, { .name = "GigaHerz" }),
976+
.prefix = EcsGiga,
977+
.base = EcsHerz });
978+
ecs_primitive_init(world, &(ecs_primitive_desc_t){
979+
.entity = EcsGigaHerz,
980+
.kind = EcsF32
981+
});
982+
ecs_set_scope(world, prev_scope);
983+
937984
/* Documentation */
938985
#ifdef FLECS_DOC
939986
ECS_IMPORT(world, FlecsDoc);

0 commit comments

Comments
 (0)