2025-02-14 21:35:40 +03:00
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include <bitset>
|
|
|
|
#include <numeric>
|
|
|
|
|
|
|
|
#ifndef MAX_ZECSY_ENTITIES
|
|
|
|
#define MAX_ZECSY_ENTITIES 65536
|
|
|
|
#endif // !MAX_ZECSY_ENTITIES
|
|
|
|
|
|
|
|
|
|
|
|
namespace zecsy
|
|
|
|
{
|
|
|
|
using entity_id = uint64_t;
|
|
|
|
|
|
|
|
class world final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
world() = default;
|
|
|
|
world(const world &) = default;
|
|
|
|
world(world &&) = default;
|
|
|
|
world &operator=(const world &) = default;
|
|
|
|
world &operator=(world &&) = default;
|
|
|
|
|
|
|
|
entity_id make_entity();
|
2025-02-14 21:41:36 +03:00
|
|
|
void destroy_entity(entity_id e);
|
2025-02-14 21:35:40 +03:00
|
|
|
bool is_alive(entity_id e) const;
|
|
|
|
private:
|
|
|
|
std::bitset<MAX_ZECSY_ENTITIES> entities_bitset;
|
|
|
|
entity_id entity_counter = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline entity_id world::make_entity()
|
|
|
|
{
|
2025-02-14 21:47:16 +03:00
|
|
|
auto id = ++entity_counter;
|
2025-02-14 21:35:40 +03:00
|
|
|
entities_bitset.set(id);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2025-02-14 21:41:36 +03:00
|
|
|
inline void world::destroy_entity(entity_id e)
|
|
|
|
{
|
|
|
|
entities_bitset.reset(e);
|
|
|
|
}
|
|
|
|
|
2025-02-14 21:35:40 +03:00
|
|
|
inline bool world::is_alive(entity_id e) const
|
|
|
|
{
|
|
|
|
return entities_bitset.test(e);
|
|
|
|
}
|
|
|
|
};
|