nngn
Loading...
Searching...
No Matches
entity.h
Go to the documentation of this file.
1#ifndef NNGN_ENTITY_H
2#define NNGN_ENTITY_H
3
4#include <array>
5#include <memory>
6#include <string_view>
7#include <vector>
8
9#include "math/hash.h"
10#include "math/vec3.h"
11#include "utils/flags.h"
12#include "utils/static_vector.h"
13#include "utils/utils.h"
14
15namespace nngn {
16 struct Renderer;
17}
18
19struct Entity {
20 enum Flag : std::uintptr_t {
21 ALIVE = 1u << 0, POS_UPDATED = 1u << 1,
22 };
23 nngn::vec3 p = {0, 0, 0};
26 bool pos_updated() const { return this->flags.is_set(Flag::POS_UPDATED); }
27 void set_pos(nngn::vec3 p);
29};
30
31class Entities {
33 std::vector<std::array<char, 32>> names = {}, tags = {};
34 std::vector<nngn::Hash> name_hashes = {}, tag_hashes = {};
35public:
36 size_t max() const { return this->v.capacity(); }
37 size_t n() const { return this->v.size(); }
38 void set_max(std::size_t n);
39 Entity *add();
40 void remove(Entity *e) { this->v.erase(e); }
46 std::span<const char, 32> name(const Entity &e) const;
47 std::span<const char, 32> tag(const Entity &e) const;
48 nngn::Hash name_hash(const Entity &e) const;
49 nngn::Hash tag_hash(const Entity &e) const;
50 void set_name(Entity *e, std::string_view s);
51 void set_tag(Entity *e, std::string_view s);
52 void clear_flags();
53};
54
55#endif
Definition: entity.h:31
std::vector< nngn::Hash > name_hashes
Definition: entity.h:34
std::vector< std::array< char, 32 > > names
Definition: entity.h:33
std::vector< std::array< char, 32 > > tags
Definition: entity.h:33
std::vector< nngn::Hash > tag_hashes
Definition: entity.h:34
void clear_flags()
Definition: entity.cpp:109
size_t max() const
Definition: entity.h:36
void set_name(Entity *e, std::string_view s)
Definition: entity.cpp:101
nngn::static_vector< Entity > v
Definition: entity.h:32
void set_max(std::size_t n)
Definition: entity.cpp:63
size_t n() const
Definition: entity.h:37
nngn::Hash tag_hash(const Entity &e) const
Definition: entity.cpp:97
std::span< const char, 32 > tag(const Entity &e) const
Definition: entity.cpp:89
void remove(Entity *e)
Definition: entity.h:40
void set_tag(Entity *e, std::string_view s)
Definition: entity.cpp:105
nngn::Hash name_hash(const Entity &e) const
Definition: entity.cpp:93
Entity * add()
Definition: entity.cpp:71
Fixed-size vector with an embedded free list.
Definition: static_vector.h:21
std::size_t size(void) const
Calculates the true size (excluding the entries in the free list).
Definition: static_vector.h:87
void erase(T *p)
Removes element p from the vector.
Definition: static_vector.h:123
Definition: debug.h:45
Definition: debug.h:13
name
Definition: old_man.lua:1
Definition: entity.h:19
void set_renderer(nngn::Renderer *p)
Definition: entity.cpp:56
void set_pos(nngn::vec3 p)
Definition: entity.cpp:50
nngn::Renderer * renderer
Definition: entity.h:25
nngn::Flags< Flag > flags
Definition: entity.h:24
Flag
Definition: entity.h:20
@ ALIVE
Definition: entity.h:21
@ POS_UPDATED
Definition: entity.h:21
bool pos_updated() const
Definition: entity.h:26
nngn::vec3 p
Definition: entity.h:23
Wrapper for a small unsigned integral representing flags.
Definition: flags.h:18
constexpr bool is_set(AT a) const
Definition: flags.h:45
Definition: renderers.h:15
e
Definition: math.lua:4
std::chrono::seconds s
Definition: timing.cpp:6
#define NNGN_EXPOSE_ITERATOR(n, m)
Definition: utils.h:67