Make entity and verify its existence
This commit is contained in:
parent
f27b99f929
commit
1962e97cf9
2 changed files with 54 additions and 4 deletions
|
@ -1,7 +1,14 @@
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_all.hpp>
|
||||||
|
#include "../zecsy.hpp"
|
||||||
|
|
||||||
TEST_CASE("dumb")
|
using namespace zecsy;
|
||||||
|
|
||||||
|
TEST_CASE("Create a single entity and verify its existence")
|
||||||
{
|
{
|
||||||
REQUIRE(true);
|
world w;
|
||||||
|
|
||||||
|
auto e = w.make_entity();
|
||||||
|
REQUIRE(w.is_alive(e));
|
||||||
}
|
}
|
||||||
|
|
47
zecsy.hpp
47
zecsy.hpp
|
@ -1,2 +1,45 @@
|
||||||
//oh hi
|
#pragma once
|
||||||
int foo() {}
|
#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();
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
auto id = entity_counter;
|
||||||
|
entities_bitset.set(id);
|
||||||
|
|
||||||
|
entity_counter++;
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool world::is_alive(entity_id e) const
|
||||||
|
{
|
||||||
|
return entities_bitset.test(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue