No entity_id reusage yet
This commit is contained in:
parent
4e3ae245b8
commit
f1f965a284
1 changed files with 7 additions and 6 deletions
13
zecsy.hpp
13
zecsy.hpp
|
@ -2,7 +2,7 @@
|
|||
#include <cstdint>
|
||||
#include <bitset>
|
||||
#include <format>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
#ifndef MAX_ZECSY_ENTITIES
|
||||
#define MAX_ZECSY_ENTITIES 65536
|
||||
|
@ -44,7 +44,7 @@ namespace zecsy
|
|||
void destroy_entity(entity_id e);
|
||||
bool is_alive(entity_id e) const;
|
||||
private:
|
||||
std::bitset<MAX_ZECSY_ENTITIES> entities_bitset;
|
||||
std::bitset<MAX_ZECSY_ENTITIES + 1> entities_bitset;
|
||||
entity_id entity_counter = 0;
|
||||
};
|
||||
|
||||
|
@ -65,11 +65,12 @@ namespace zecsy
|
|||
|
||||
inline entity world::make_entity()
|
||||
{
|
||||
auto id = (++entity_counter)%MAX_ZECSY_ENTITIES;
|
||||
if(is_alive(id))
|
||||
auto id = ++entity_counter;
|
||||
|
||||
if(id > MAX_ZECSY_ENTITIES)
|
||||
{
|
||||
throw std::runtime_error(std::format("entity_id #{} already in use,"
|
||||
" can't make a new entity", id));
|
||||
throw std::runtime_error(std::format("Entity id {} exceeds "
|
||||
"MAX_ZECSY_ENTITIES ({})", id, MAX_ZECSY_ENTITIES));
|
||||
}
|
||||
|
||||
entities_bitset.set(id);
|
||||
|
|
Loading…
Reference in a new issue