implement scrap and ship skeleton

This commit is contained in:
2026-04-20 07:32:18 +02:00
parent bf29cc40e3
commit 411be72a5c
14 changed files with 646 additions and 3 deletions

83
src/test/ScrapTest.cpp Normal file
View File

@@ -0,0 +1,83 @@
#include "catch.hpp"
#include <QVector2D>
#include "EntityId.h"
#include "Scrap.h"
#include "ScrapSystem.h"
// ---------------------------------------------------------------------------
// Spawn
// ---------------------------------------------------------------------------
TEST_CASE("ScrapSystem: spawn returns a findable scrap with correct fields", "[scrap]")
{
EntityId nextId = 1;
ScrapSystem ss([&nextId]() { return nextId++; });
const EntityId id = ss.spawn(QVector2D(3.0f, 4.0f), 5, 100);
const Scrap* s = ss.findScrap(id);
REQUIRE(s != nullptr);
REQUIRE(s->amount == 5);
REQUIRE(s->despawnAt == 100);
}
// ---------------------------------------------------------------------------
// Despawn timing
// ---------------------------------------------------------------------------
TEST_CASE("ScrapSystem: scrap still present one tick before despawnAt", "[scrap]")
{
EntityId nextId = 1;
ScrapSystem ss([&nextId]() { return nextId++; });
const EntityId id = ss.spawn(QVector2D(0.0f, 0.0f), 1, 50);
ss.tickDespawn(49);
REQUIRE(ss.findScrap(id) != nullptr);
}
TEST_CASE("ScrapSystem: scrap removed at despawnAt tick", "[scrap]")
{
EntityId nextId = 1;
ScrapSystem ss([&nextId]() { return nextId++; });
const EntityId id = ss.spawn(QVector2D(0.0f, 0.0f), 1, 50);
ss.tickDespawn(50);
REQUIRE(ss.findScrap(id) == nullptr);
}
// ---------------------------------------------------------------------------
// Selective removal
// ---------------------------------------------------------------------------
TEST_CASE("ScrapSystem: tickDespawn removes only expired scraps", "[scrap]")
{
EntityId nextId = 1;
ScrapSystem ss([&nextId]() { return nextId++; });
const EntityId earlyId = ss.spawn(QVector2D(0.0f, 0.0f), 1, 30);
const EntityId lateId = ss.spawn(QVector2D(1.0f, 0.0f), 2, 60);
ss.tickDespawn(30);
REQUIRE(ss.findScrap(earlyId) == nullptr);
REQUIRE(ss.findScrap(lateId) != nullptr);
}
// ---------------------------------------------------------------------------
// Entity ids
// ---------------------------------------------------------------------------
TEST_CASE("ScrapSystem: spawned scraps receive strictly increasing entity ids", "[scrap]")
{
EntityId nextId = 1;
ScrapSystem ss([&nextId]() { return nextId++; });
const EntityId id1 = ss.spawn(QVector2D(0.0f, 0.0f), 1, 100);
const EntityId id2 = ss.spawn(QVector2D(1.0f, 0.0f), 2, 200);
REQUIRE(id2 > id1);
}