Skip to content

Commit

Permalink
Fixed: Dummy example build + stack allocator on MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
richardbiely committed Jul 16, 2024
1 parent 6c37ef1 commit 0f5a940
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/gaia/mem/stack_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace gaia {
core::call_ctor_raw_n(pData, cnt);

// Allocation start offset
m_posPrev = addrAllocInfo - addrBuff;
m_posPrev = (uint32_t)(addrAllocInfo - addrBuff);
// Point to the next free space (not necessary alligned yet)
m_pos = m_posPrev + pInfo->off + sizeT * cnt;

Expand Down
6 changes: 6 additions & 0 deletions src/dummy/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,17 @@ void test0() {
auto q1 = w.query().all<Position>();
const auto c1 = q1.count();
GAIA_ASSERT(c1 == 2);
(void)c1;

auto q2 = w.query().all<dummy::Position>();
const auto c2 = q2.count();
GAIA_ASSERT(c2 == 3);
(void)c2;

auto q3 = w.query().no<Position>();
const auto c3 = q3.count();
GAIA_ASSERT(c3 > 0); // It's going to be a bunch
(void)c3;
}
}

Expand All @@ -354,6 +357,7 @@ void test1() {
auto q = w.query().add({ecs::QueryOp::All, ecs::QueryAccess::None, ecs::Pair(eats, ecs::All)});
const auto cnt = q.count();
GAIA_ASSERT(cnt == 3);
(void)cnt;

uint32_t i = 0;
q.each([&](ecs::Entity entity) {
Expand All @@ -362,6 +366,7 @@ void test1() {
const bool isWolf = entity == wolf;
const bool is = isRabbit || isHare || isWolf;
GAIA_ASSERT(is);
(void)is;
++i;
});
GAIA_ASSERT(i == cnt);
Expand Down Expand Up @@ -463,6 +468,7 @@ void test5() {
w.del(e);
const bool isEntityValid = w.valid(e);
GAIA_ASSERT(!isEntityValid);
(void)isEntityValid;
};

GAIA_FOR(N) create(i);
Expand Down
2 changes: 1 addition & 1 deletion src/perf/duel/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,13 @@ void BM_NonECS(picobench::state& state) {
}
{
GAIA_PROF_SCOPE(calc_alive);
uint32_t aliveUnits = 0;
for (auto& u: units) {
if (u->isAlive())
++aliveUnits;
}
}
}
(void)aliveUnits;

units[0]->updatePosition_verify();
units[0]->handleGroundCollision_verify();
Expand Down
27 changes: 14 additions & 13 deletions src/test/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2877,9 +2877,8 @@ TEST_CASE("Query - QueryResult complex") {
}

TEST_CASE("Relationship") {
TestWorld twld;

SECTION("Simple") {
TestWorld twld;
auto wolf = wld.add();
auto rabbit = wld.add();
auto carrot = wld.add();
Expand Down Expand Up @@ -2935,6 +2934,7 @@ TEST_CASE("Relationship") {
}

SECTION("Simple - bulk") {
TestWorld twld;
auto wolf = wld.add();
auto rabbit = wld.add();
auto carrot = wld.add();
Expand Down Expand Up @@ -2978,6 +2978,7 @@ TEST_CASE("Relationship") {
}

SECTION("Intermediate") {
TestWorld twld;
auto wolf = wld.add();
auto hare = wld.add();
auto rabbit = wld.add();
Expand Down Expand Up @@ -3096,7 +3097,7 @@ TEST_CASE("Relationship") {
REQUIRE(cnt == 0);

uint32_t i = 0;
q.each([&](ecs::Iter& it) {
q.each([&]([[maybe_unused]] ecs::Iter& it) {
++i;
});
REQUIRE(i == 0);
Expand All @@ -3107,7 +3108,7 @@ TEST_CASE("Relationship") {
REQUIRE(cnt == 1);

uint32_t i = 0;
q.each([&](ecs::Iter& it) {
q.each([&]([[maybe_unused]] ecs::Iter& it) {
++i;
});
REQUIRE(i == 1);
Expand Down Expand Up @@ -6846,23 +6847,23 @@ TEST_CASE("StackAllocator") {

auto* pPos = a.alloc<Position>(10);
GAIA_FOR(10) {
pPos[i].x = i;
pPos[i].y = i + 1;
pPos[i].z = i + 2;
pPos[i].x = (float)i;
pPos[i].y = (float)i + 1.f;
pPos[i].z = (float)i + 2.f;
}
a.free(pPos, 10);
pPos = a.alloc<Position>(10);
GAIA_FOR(10) {
REQUIRE(pPos[i].x == i);
REQUIRE(pPos[i].y == i + 1);
REQUIRE(pPos[i].z == i + 2);
REQUIRE(pPos[i].x == (float)i);
REQUIRE(pPos[i].y == (float)i + 1.f);
REQUIRE(pPos[i].z == (float)i + 2.f);
}

auto* pPosN = a.alloc<PositionNonTrivial>(3);
GAIA_FOR(3) {
REQUIRE(pPosN[i].x == 1);
REQUIRE(pPosN[i].y == 2);
REQUIRE(pPosN[i].z == 3);
REQUIRE(pPosN[i].x == 1.f);
REQUIRE(pPosN[i].y == 2.f);
REQUIRE(pPosN[i].z == 3.f);
}

// Alloc and release some more objects
Expand Down

0 comments on commit 0f5a940

Please sign in to comment.