More cleanup then starting to sort out how to make systems extensible easily.
This commit is contained in:
parent
6a0c9e8d46
commit
cbff127b40
13 changed files with 106 additions and 769 deletions
|
|
@ -52,34 +52,3 @@ TEST_CASE("map placement test", "[map-fail]") {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("map image test", "[map]") {
|
||||
GameDB::init();
|
||||
|
||||
auto& level = GameDB::current_level();
|
||||
Matrix map_tiles = matrix::make(7,7);
|
||||
EntityGrid entity_map;
|
||||
|
||||
auto render = std::make_shared<sf::RenderTexture>();
|
||||
sf::Sprite sprite{render->getTexture()};
|
||||
auto player = level.world->get_the<components::Player>();
|
||||
auto& player_pos = level.world->get<components::Position>(player.entity);
|
||||
auto player_display = level.world->get<components::Tile>(player.entity).display;
|
||||
|
||||
for(matrix::each_row it{level.map->walls()}; it.next();) {
|
||||
player_pos.location.x = it.x;
|
||||
player_pos.location.y = it.y;
|
||||
System::draw_map(map_tiles, entity_map);
|
||||
System::render_map(map_tiles, entity_map, *render, 2, player_display);
|
||||
|
||||
// randomly test about 80% of them
|
||||
if(Random::uniform(0, 100) < 20) break;
|
||||
|
||||
#ifdef TEST_RENDER
|
||||
// confirm we get two different maps
|
||||
auto out_img = render->getTexture().copyToImage();
|
||||
bool worked = out_img.saveToFile(fmt::format("tmp/map_render{}{}.png", it.x, it.y));
|
||||
REQUIRE(worked);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,3 +34,105 @@ TEST_CASE("figure out best rotation direction", "[systems-rotate]") {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
using MovingFunc = std::function<void()>;
|
||||
using CombatFunc = std::function<void(bool)>;
|
||||
using RenderFunc = std::function<void()>;
|
||||
using UpdateFunc = std::function<void()>;
|
||||
using UseFunc = std::function<void()>;
|
||||
using PickupFunc = std::function<void()>;
|
||||
|
||||
struct Engine {
|
||||
std::vector<MovingFunc> $moving;
|
||||
std::vector<CombatFunc> $combat;
|
||||
std::vector<RenderFunc> $render;
|
||||
std::vector<UpdateFunc> $update;
|
||||
std::vector<UseFunc> $use;
|
||||
std::vector<PickupFunc> $pickup;
|
||||
|
||||
void addMoving(MovingFunc action) {
|
||||
$moving.emplace_back(action);
|
||||
}
|
||||
|
||||
void addCombat(CombatFunc action) {
|
||||
$combat.emplace_back(action);
|
||||
}
|
||||
|
||||
void addRender(RenderFunc action) {
|
||||
$render.emplace_back(action);
|
||||
}
|
||||
|
||||
void addUpdate(UpdateFunc action) {
|
||||
$update.emplace_back(action);
|
||||
}
|
||||
|
||||
void addUse(UseFunc action) {
|
||||
$use.emplace_back(action);
|
||||
}
|
||||
|
||||
void addPickup(PickupFunc action) {
|
||||
$pickup.emplace_back(action);
|
||||
}
|
||||
|
||||
void runMoving() {
|
||||
for(auto func : $moving) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
void runCombat(bool attr) {
|
||||
for(auto func : $combat) {
|
||||
func(attr);
|
||||
}
|
||||
}
|
||||
|
||||
void runRender() {
|
||||
for(auto func : $render) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
void runUpdate() {
|
||||
for(auto func : $update) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
void runUse() {
|
||||
for(auto func : $use) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
void runPickup() {
|
||||
for(auto func : $pickup) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void test_system_1() {
|
||||
fmt::println("TEST 1");
|
||||
}
|
||||
|
||||
void test_combat(bool what) {
|
||||
fmt::println("TEST 2: {}", what);
|
||||
}
|
||||
|
||||
TEST_CASE("new system running engine thing", "[systems-engine]") {
|
||||
Engine systems;
|
||||
|
||||
systems.addMoving(test_system_1);
|
||||
systems.addCombat(test_combat);
|
||||
systems.addRender(test_system_1);
|
||||
systems.addUpdate(test_system_1);
|
||||
systems.addUse(test_system_1);
|
||||
systems.addPickup(test_system_1);
|
||||
|
||||
systems.runCombat(false);
|
||||
systems.runMoving();
|
||||
systems.runRender();
|
||||
systems.runUpdate();
|
||||
systems.runUse();
|
||||
systems.runPickup();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue