AlwaysBreakTemplateDeclarations

This commit is contained in:
NukeBird 2025-02-13 19:56:57 +03:00
parent d89827046a
commit 336e5a5733
4 changed files with 28 additions and 14 deletions

View file

@ -2,3 +2,4 @@ BasedOnStyle: LLVM
BreakBeforeBraces: Allman
AccessModifierOffset: -4
IndentWidth: 4
AlwaysBreakTemplateDeclarations: Yes

View file

@ -58,28 +58,33 @@ struct World
$constants.push_back(entity);
}
template <typename Comp> EntityMap &entity_map_for()
template <typename Comp>
EntityMap &entity_map_for()
{
return $components[std::type_index(typeid(Comp))];
}
template <typename Comp> EventQueue &queue_map_for()
template <typename Comp>
EventQueue &queue_map_for()
{
return $events[std::type_index(typeid(Comp))];
}
template <typename Comp> void remove(Entity ent)
template <typename Comp>
void remove(Entity ent)
{
EntityMap &map = entity_map_for<Comp>();
map.erase(ent);
}
template <typename Comp> void set_the(Comp val)
template <typename Comp>
void set_the(Comp val)
{
$facts.insert_or_assign(std::type_index(typeid(Comp)), val);
}
template <typename Comp> Comp &get_the()
template <typename Comp>
Comp &get_the()
{
auto comp_id = std::type_index(typeid(Comp));
dbc::check($facts.contains(comp_id),
@ -92,19 +97,22 @@ struct World
return std::any_cast<Comp &>(res);
}
template <typename Comp> bool has_the()
template <typename Comp>
bool has_the()
{
auto comp_id = std::type_index(typeid(Comp));
return $facts.contains(comp_id);
}
template <typename Comp> void set(Entity ent, Comp val)
template <typename Comp>
void set(Entity ent, Comp val)
{
EntityMap &map = entity_map_for<Comp>();
map.insert_or_assign(ent, val);
}
template <typename Comp> Comp &get(Entity ent)
template <typename Comp>
Comp &get(Entity ent)
{
EntityMap &map = entity_map_for<Comp>();
// use .at for bounds checking
@ -112,7 +120,8 @@ struct World
return std::any_cast<Comp &>(res);
}
template <typename Comp> bool has(Entity ent)
template <typename Comp>
bool has(Entity ent)
{
EntityMap &map = entity_map_for<Comp>();
return map.contains(ent);
@ -146,13 +155,15 @@ struct World
}
}
template <typename Comp> void send(Comp event, Entity entity, std::any data)
template <typename Comp>
void send(Comp event, Entity entity, std::any data)
{
EventQueue &queue = queue_map_for<Comp>();
queue.push({event, entity, data});
}
template <typename Comp> Event recv()
template <typename Comp>
Event recv()
{
EventQueue &queue = queue_map_for<Comp>();
Event evt = queue.front();
@ -160,7 +171,8 @@ struct World
return evt;
}
template <typename Comp> bool has_event()
template <typename Comp>
bool has_event()
{
EventQueue &queue = queue_map_for<Comp>();
return !queue.empty();

View file

@ -14,7 +14,8 @@ struct Point
typedef std::vector<Point> PointList;
template <> struct std::hash<Point>
template <>
struct std::hash<Point>
{
size_t operator()(const Point &p) const
{