Skip to content

Commit

Permalink
feat: rm StramFormat direct deps (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
0-Sacha authored Oct 29, 2024
1 parent 3d3b574 commit 1dc2b79
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 101 deletions.
2 changes: 0 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ cc_test(
name = "LittleECSTests",
srcs = glob([ "Tests/**/*.h", "Tests/**/*.cpp" ], exclude=["Tests/Perf/**"]),
includes = [ "src/" ],
defines = [ "LECS_USE_STREAMFORMAT" ],
copts = select({
"@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"],
"//conditions:default": ["-std=c++20"],
Expand All @@ -34,7 +33,6 @@ cc_test(
name = "LittleECSTestsPerf",
srcs = glob([ "Tests/**/*.h", "Tests/**/*.cpp" ]),
includes = [ "src/" ],
defines = [ "LECS_USE_STREAMFORMAT" ],
copts = select({
"@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"],
"//conditions:default": ["-std=c++20"],
Expand Down
4 changes: 2 additions & 2 deletions Examples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Example of StreamFormat
# Example of LittleECS

### Try thoses examples !

Expand All @@ -21,4 +21,4 @@ Then you can run a program with (example with `//Workflow:Workflow`, see below f

### List Of Examples

- `//Workflow:Workflow`: Workflow using the Internal Logger
- `//Workflow:Workflow`: A classic Workflow
1 change: 0 additions & 1 deletion Examples/Workflow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "Workflow",
srcs = glob([ "*.h", "*.cpp" ]),
defines = [ "LECS_USE_STREAMFORMAT" ],
copts = select({
"@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"],
"//conditions:default": ["-std=c++20"],
Expand Down
77 changes: 35 additions & 42 deletions Examples/Workflow/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "LittleECS/LittleECS.h"

#include "StreamFormat/FLog.h"

StreamFormat::FLog::BasicLogger Logger("Workflow");
Expand All @@ -19,56 +18,53 @@ struct Name
{
std::string Name;
};
// To be able to Format the struct Name

// To be able to format the struct Name
STREAMFORMAT_AUTO_FORMATTER(Name, "{}", value.Name);

int main()
{
/****** The Registry to use ******/
LECS::Registry registry;


/****** Entity Ids (Trivially copiable) ******/
/****** Entity IDs (trivially copiable) ******/
LECS::EntityId alice = registry.CreateEntityId();
LECS::EntityId bob = registry.CreateEntityId();


/****** Add Components ******/
registry.Add<int>(alice, 42);
registry.Add<int>(bob, 7);

/**
* Constructors parameters are Forwarded
* Constructor parameters are forwarded
*/
registry.Add<Name>(alice, "Alice");
registry.Add<Name>(bob, "Bob");


/****** Get Components ******/
std::cout << std::endl;
Logger.Info("Alice's int: {}", registry.Get<int>(alice));
Logger.Info("Bob's int: {}", registry.Get<int>(bob));


/****** ForEachUniqueComponent ******/
std::cout << std::endl;
/**
* To ForEach on a specific Component, use ForEachUniqueComponent.
* It takes an lambda which can contains optionally an `LECS::EntityId` as first parameter, in that case the entityId will be sent to the lambda
* The component you want to loop over is took as an template argument, and the lambda can take the component as:
* To ForEach on a specific component, use ForEachUniqueComponent.
* It takes a lambda which can optionally contain an `LECS::EntityId` as the first parameter; in that case, the EntityId will be sent to the lambda.
* The component you want to loop over is specified as a template argument, and the lambda can take the component as:
* - value <int>
* - const value <const int>
* - const reference <const int&>
* - reference <int&> **Only if the registry is non-const**
*
* It will loop on all entities that have the specified component.
* It will loop over all entities that have the specified component.
*/
Logger.Info("ForEachUniqueComponent (With Entity Id):");
registry.ForEachUniqueComponent<Name>(
[](LECS::EntityId entityId, const Name& name)
{
Logger.Info(" {} -> {}", entityId, name);
}
}
);

std::cout << std::endl;
Expand All @@ -77,14 +73,13 @@ int main()
[](const Name& name)
{
Logger.Info(" {}", name);
}
}
);


/****** Add Custom Components ******/
std::cout << std::endl;
/**
* You can add any Custom Component as any others types. No need for these components to herit from anythings
* You can add any custom component like any other type. These components do not need to inherit from anything.
*/
registry.Add<ABigComponent>(alice);
registry.Add<ASmallComponent>(alice);
Expand All @@ -93,80 +88,78 @@ int main()
/****** ForEachComponents ******/
std::cout << std::endl;
/**
* To ForEach on a multiple components (only one included), use ForEachComponents.
* Like `ForEachUniqueComponent`:
* It takes an lambda which can contains optionally an `LECS::EntityId` as first parameter, in that case the entityId will be send to the lambda
* The component you want to loop over is take as an template argument, and the lambda can take the component as:
* To ForEach on multiple components (only one included), use ForEachComponents.
* Like `ForEachUniqueComponent`, it takes a lambda which can optionally contain an `LECS::EntityId` as the first parameter; in that case, the EntityId will be sent to the lambda.
* The component you want to loop over is specified as a template argument, and the lambda can take the component as:
* - value <int>
* - const value <const int>
* - const reference <const int&>
* - reference <int&> **Only if the registry is non-const**
*
* It will loop on all entities that have **ALL** the specified components.
* It will loop over all entities that have **ALL** the specified components.
*/
Logger.Info("ForEachComponents (Without Entity Id) on <Name, int>:");
registry.ForEachComponents<Name, int>(
[](const Name& name, const int k)
{
Logger.Info(" {} -> {}", name, k);
}
}
);

std::cout << std::endl;
/**
* Here both Alice and Bob have <int> and <ABigComponent>, so they will be both printed
* Here, both Alice and Bob have <int> and <ABigComponent>, so they will both be printed.
*/
Logger.Info("ForEachComponents (With Entity Id) on <Name, int, ABigComponent>:");
Logger.Debug("Both Alice and Bob have <Name> <int> and <ABigComponent>");
Logger.Debug("Both Alice and Bob have <Name>, <int>, and <ABigComponent>");
registry.ForEachComponents<Name, int, ABigComponent>(
[](LECS::EntityId entityId, const Name& name, const int k, const ABigComponent&)
{
Logger.Info(" {} ({}) -> {}", name, entityId, k);
}
}
);

std::cout << std::endl;
/**
* Here only Alice all 3 components required: <ASmallComponent> <int> <ABigComponent> so she will be printed.
* Bob doesn't have a <ASmallComponent> so he will not printed
* Here, only Alice has all three required components: <ASmallComponent>, <int>, <ABigComponent>, so only she will be printed.
* Bob doesn't have an <ASmallComponent>, so he will not be printed.
*/
Logger.Info("ForEachComponents (With Entity Id) on <Name, ASmallComponent, int, ABigComponent> :");
Logger.Debug("Only Alice has <ASmallComponent> so Bob is not printed. Alice does appear since she has all required components");
Logger.Info("ForEachComponents (With Entity Id) on <Name, ASmallComponent, int, ABigComponent>:");
Logger.Debug("Only Alice has <ASmallComponent>, so Bob is not printed. Alice appears since she has all required components");
registry.ForEachComponents<Name, ASmallComponent, int, ABigComponent>(
[](LECS::EntityId entityId, const Name& name, const ASmallComponent&, const int k, const ABigComponent&)
{
Logger.Info(" {} ({}) -> {}", name, entityId, k);
}
}
);

/****** EachEntitiesWith ******/
std::cout << std::endl;
/**
* EachEntitiesWith will loop over ever entities that have all components required (here only <Name>)
* EachEntitiesWith will loop over every entity that has all required components (here only <Name>).
*/
Logger.Info("EachEntitiesWith <Name>:");
for (LECS::EntityId entityId : registry.EachEntitiesWith<Name>())
{
Logger.Info(" {} -> {}", registry.Get<Name>(entityId),
registry.Has<ASmallComponent>(entityId) ? "Has <ASmallComponent>" : "Does NOT has <ASmallComponent>"
registry.Has<ASmallComponent>(entityId) ? "Has <ASmallComponent>" : "Does NOT have <ASmallComponent>"
);
}


/****** Views ******/
std::cout << std::endl;
Logger.Info("Views");

/**
* You can create views on components:
* Here a view on <int> and <ABigComponent>
* It will only be able to view thoses components, any references to another component will end up in 'constraint was not satisfied' error
* Here, a view on <int> and <ABigComponent>.
* It will only be able to view those components; any reference to another component will result in a 'constraint was not satisfied' error.
*/
auto view = registry.View<Name, int>();

/**
* With view, you c=have access to all previous defined For and Each functions
* Except this time you cannot reference components that where not present in the constructor
* With views, you have access to all previously defined For and Each functions,
* but this time you cannot reference components that were not present in the constructor.
*/
Logger.Info("View: Entity with the component <Name>");
for (LECS::EntityId entityId : view.EachEntitiesWith<Name>())
Expand All @@ -178,17 +171,17 @@ int main()
registry.Add<Name>(eve, "Eve");

std::cout << std::endl;
Logger.Info("View doesn't need to be recreated, they are always up to date (After adding Eve):");
Logger.Info("View doesn't need to be recreated; it is always up to date (After adding Eve):");
for (LECS::EntityId entityId : view.EachEntitiesWith<Name>())
{
Logger.Info(" {} ({})", registry.Get<Name>(entityId), entityId);
}

std::cout << std::endl;
/**
* With view, you can use the regular for each loop on components.
* With views, you can use the regular for-each loop on components.
* And use C++17 structural bindings.
* Here Eve will not appear since she doesn't have an <int> component
* Here Eve will not appear since she doesn't have an <int> component.
*/
Logger.Info("Views: EachComponents");
for (const auto& [name, intComponent] : view.EachComponents<Name, int>())
Expand All @@ -199,7 +192,7 @@ int main()
registry.Add<int>(eve, 123);

/**
* Again, no need to recreate the view, a view is always up to date
* Again, no need to recreate the view; a view is always up to date.
*/
std::cout << std::endl;
Logger.Info("View after adding an <int> component to Eve");
Expand All @@ -209,7 +202,7 @@ int main()
}

/**
* To destroy an entity, just use DestroyEntityId
* To destroy an entity, just use DestroyEntityId.
*/
std::cout << std::endl;
registry.DestroyEntityId(bob);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ git clone [email protected]:0-Sacha/LittleECS.git

## Using the Lib
It can be used using [Bazel](https://bazel.build/).
A `cc_library` rule has been created: `@LittleECS//:LittleECS`.
A `cc_library` rule has been created: `@littleecs//:littleecs`.
You need to add the module `littleecs` to your dependencies.

Not Recommended: There is also a [Premake](https://premake.github.io/docs/using-premake) configuration, thought it is deprecated (and run on a wrapper of mine: [PremakeUtilities](https://github.com/0-Sacha/PremakeUtilities)). I keep it for my Game Engine [Blackbird](https://github.com/0-Sacha/Blackbird) which is using `Premake` as Build system.
4 changes: 0 additions & 4 deletions src/LittleECS/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
#define LECS_LOGGER_ENABLE
#endif

#ifdef LECS_USE_STREAMFORMAT
#include "UseStreamFormat.h"
#endif

#ifdef LECS_LOGGER_ENABLE
#define LECS_TRACE(...) // TODO: ?
#define LECS_INFO(...) // TODO: ?
Expand Down
24 changes: 0 additions & 24 deletions src/LittleECS/Core/UseStreamFormat.h

This file was deleted.

12 changes: 0 additions & 12 deletions src/LittleECS/Detail/ComponentId.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,3 @@ namespace LECS
return lhs == rhs.Id;
}
}

namespace StreamFormat::FMT
{
template<typename FormatterContext>
struct FormatterType<LECS::ComponentId, FormatterContext>
{
static void Format(LECS::ComponentId typeId, FormatterContext& context)
{
FormatterType<typename LECS::ComponentId::Type, FormatterContext>::Format(typeId, context);
}
};
}
13 changes: 0 additions & 13 deletions src/LittleECS/Detail/EntityId.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,3 @@ namespace LECS
}
}

#ifdef STREAMFORMAT_FORMATTER_DECLARED
namespace StreamFormat::FMT
{
template<typename FormatterContext>
struct FormatterType<LECS::EntityId, FormatterContext>
{
static void Format(LECS::EntityId typeId, FormatterContext& context)
{
FormatterType<typename LECS::EntityId::Type, FormatterContext>::Format(typeId, context);
}
};
}
#endif

0 comments on commit 1dc2b79

Please sign in to comment.