Compare commits
2 commits
f27b99f929
...
c9a4e27630
Author | SHA1 | Date | |
---|---|---|---|
c9a4e27630 | |||
1962e97cf9 |
2 changed files with 69 additions and 4 deletions
|
@ -1,7 +1,23 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#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));
|
||||
}
|
||||
|
||||
TEST_CASE("Destroy an entity and ensure it no longer exists in the world")
|
||||
{
|
||||
world w;
|
||||
|
||||
auto e = w.make_entity();
|
||||
w.destroy_entity(e);
|
||||
REQUIRE_FALSE(w.is_alive(e));
|
||||
}
|
||||
|
|
53
zecsy.hpp
53
zecsy.hpp
|
@ -1,2 +1,51 @@
|
|||
//oh hi
|
||||
int foo() {}
|
||||
#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();
|
||||
void destroy_entity(entity_id e);
|
||||
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 void world::destroy_entity(entity_id e)
|
||||
{
|
||||
entities_bitset.reset(e);
|
||||
}
|
||||
|
||||
inline bool world::is_alive(entity_id e) const
|
||||
{
|
||||
return entities_bitset.test(e);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue