BROKEN: Big refactoring happening, so it compiles but game does not run and the tests fail.
This commit is contained in:
parent
96efc990c1
commit
9e91c71125
25 changed files with 128 additions and 526 deletions
|
@ -234,8 +234,8 @@ TEST_CASE("test serialization with nlohmann::json", "[ecs-serialize]") {
|
|||
DinkyECS::Entity ent1 = world.entity();
|
||||
DinkyECS::Entity ent2 = world.entity();
|
||||
|
||||
DinkyECS::configure(world, component_map, ent1, data);
|
||||
DinkyECS::configure(world, component_map, ent2, data);
|
||||
DinkyECS::configure(component_map, world, ent1, data);
|
||||
DinkyECS::configure(component_map, world, ent2, data);
|
||||
|
||||
world.query<Position, Motion>([&](const auto ent, auto &pos, auto &motion) {
|
||||
fmt::println("entity: {}; position={},{} and motion={},{} motion.random={}",
|
||||
|
|
|
@ -15,15 +15,18 @@ using std::string;
|
|||
using namespace components;
|
||||
|
||||
|
||||
DinkyECS::Entity add_items(DinkyECS::World &world, GameConfig &config) {
|
||||
DinkyECS::Entity add_items(DinkyECS::ComponentMap component_map, DinkyECS::World &world, GameConfig &config) {
|
||||
auto sword = world.entity();
|
||||
json& item_data = config.items["SWORD_RUSTY"];
|
||||
world.set<InventoryItem>(sword, {item_data["inventory_count"], item_data});
|
||||
components::configure(world, sword, item_data);
|
||||
DinkyECS::configure(component_map, world, sword, item_data);
|
||||
return sword;
|
||||
}
|
||||
|
||||
TEST_CASE("basic inventory test", "[inventory]") {
|
||||
// BUG: rewrite this
|
||||
REQUIRE(true == false);
|
||||
/*
|
||||
DinkyECS::World world;
|
||||
save::load_configs(world);
|
||||
auto& config = world.get_the<GameConfig>();
|
||||
|
@ -68,4 +71,5 @@ TEST_CASE("basic inventory test", "[inventory]") {
|
|||
|
||||
inventory.erase_item(0);
|
||||
REQUIRE(inventory.count() == 0);
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include "map.hpp"
|
||||
#include "worldbuilder.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "lights.hpp"
|
||||
#include "point.hpp"
|
||||
|
||||
using namespace lighting;
|
||||
|
||||
TEST_CASE("lighting a map works", "[lighting]") {
|
||||
Map map(20,23);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_map();
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &map = *level.map;
|
||||
|
||||
Point light1, light2;
|
||||
|
||||
REQUIRE(map.place_entity(0, light1));
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include "map.hpp"
|
||||
#include "worldbuilder.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using namespace nlohmann;
|
||||
|
@ -15,9 +15,9 @@ json load_test_data(const string &fname) {
|
|||
}
|
||||
|
||||
TEST_CASE("camera control", "[map]") {
|
||||
Map map(20, 20);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_map();
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &map = *level.map;
|
||||
|
||||
Point center = map.center_camera({10,10}, 5, 5);
|
||||
|
||||
|
@ -32,11 +32,10 @@ TEST_CASE("camera control", "[map]") {
|
|||
|
||||
TEST_CASE("map placement test", "[map:placement]") {
|
||||
for(int i = 0; i < 50; i++) {
|
||||
size_t width = Random::uniform<size_t>(9, 21);
|
||||
size_t height = Random::uniform<size_t>(13, 25);
|
||||
Map map(width, height);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_rooms();
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &map = *level.map;
|
||||
|
||||
map.invert_space();
|
||||
|
||||
for(size_t rnum = 0; rnum < map.room_count(); rnum++) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "config.hpp"
|
||||
#include "matrix.hpp"
|
||||
#include "rand.hpp"
|
||||
#include "worldbuilder.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
|
||||
|
@ -13,6 +13,12 @@ using namespace fmt;
|
|||
using std::string;
|
||||
using matrix::Matrix;
|
||||
|
||||
shared_ptr<Map> make_map() {
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
return level.map;
|
||||
}
|
||||
|
||||
TEST_CASE("basic matrix iterator", "[matrix:basic]") {
|
||||
std::ifstream infile("./tests/dijkstra.json");
|
||||
json data = json::parse(infile);
|
||||
|
@ -252,20 +258,18 @@ TEST_CASE("prototype circle algorithm", "[matrix:circle]") {
|
|||
TEST_CASE("viewport iterator", "[matrix:viewport]") {
|
||||
size_t width = Random::uniform<size_t>(20, 22);
|
||||
size_t height = Random::uniform<size_t>(21, 25);
|
||||
Map map(width,height);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_map();
|
||||
shared_ptr<Map> map = make_map();
|
||||
|
||||
size_t view_width = width/2;
|
||||
size_t view_height = height/2;
|
||||
Point player;
|
||||
REQUIRE(map.place_entity(1, player));
|
||||
Point start = map.center_camera(player, view_width, view_height);
|
||||
REQUIRE(map->place_entity(1, player));
|
||||
Point start = map->center_camera(player, view_width, view_height);
|
||||
|
||||
size_t end_x = std::min(view_width, map.width() - start.x);
|
||||
size_t end_y = std::min(view_height, map.height() - start.y);
|
||||
size_t end_x = std::min(view_width, map->width() - start.x);
|
||||
size_t end_y = std::min(view_height, map->height() - start.y);
|
||||
|
||||
matrix::viewport it{map.walls(), start, int(view_width), int(view_height)};
|
||||
matrix::viewport it{map->walls(), start, int(view_width), int(view_height)};
|
||||
|
||||
for(size_t y = 0; y < end_y; ++y) {
|
||||
for(size_t x = 0; x < end_x && it.next(); ++x) {
|
||||
|
@ -276,25 +280,21 @@ TEST_CASE("viewport iterator", "[matrix:viewport]") {
|
|||
|
||||
TEST_CASE("random rectangle", "[matrix:rando_rect]") {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
size_t width = Random::uniform<size_t>(9, 21);
|
||||
size_t height = Random::uniform<size_t>(13, 25);
|
||||
Map map(width, height);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_rooms();
|
||||
map.invert_space();
|
||||
auto wall_copy = map.walls();
|
||||
shared_ptr<Map> map = make_map();
|
||||
map->invert_space();
|
||||
auto wall_copy = map->walls();
|
||||
|
||||
for(size_t rnum = 0; rnum < map.room_count(); rnum++) {
|
||||
Room &room = map.room(rnum);
|
||||
for(size_t rnum = 0; rnum < map->room_count(); rnum++) {
|
||||
Room &room = map->room(rnum);
|
||||
Point pos;
|
||||
|
||||
for(matrix::rando_rect it{map.walls(), room.x, room.y, room.width, room.height}; it.next();)
|
||||
for(matrix::rando_rect it{map->walls(), room.x, room.y, room.width, room.height}; it.next();)
|
||||
{
|
||||
if(map.iswall(it.x, it.y)) {
|
||||
matrix::dump("BAD RECTANGLE SPOT", map.walls(), it.x, it.y);
|
||||
if(map->iswall(it.x, it.y)) {
|
||||
matrix::dump("BAD RECTANGLE SPOT", map->walls(), it.x, it.y);
|
||||
}
|
||||
|
||||
REQUIRE(!map.iswall(it.x, it.y));
|
||||
REQUIRE(!map->iswall(it.x, it.y));
|
||||
REQUIRE(size_t(it.x) >= room.x);
|
||||
REQUIRE(size_t(it.y) >= room.y);
|
||||
REQUIRE(size_t(it.x) <= room.x + room.width);
|
||||
|
@ -310,25 +310,21 @@ TEST_CASE("random rectangle", "[matrix:rando_rect]") {
|
|||
|
||||
TEST_CASE("standard rectangle", "[matrix:rectangle]") {
|
||||
for(int i = 0; i < 20; i++) {
|
||||
size_t width = Random::uniform<size_t>(9, 21);
|
||||
size_t height = Random::uniform<size_t>(13, 25);
|
||||
Map map(width, height);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_rooms();
|
||||
map.invert_space();
|
||||
auto wall_copy = map.walls();
|
||||
shared_ptr<Map> map = make_map();
|
||||
map->invert_space();
|
||||
auto wall_copy = map->walls();
|
||||
|
||||
for(size_t rnum = 0; rnum < map.room_count(); rnum++) {
|
||||
Room &room = map.room(rnum);
|
||||
for(size_t rnum = 0; rnum < map->room_count(); rnum++) {
|
||||
Room &room = map->room(rnum);
|
||||
Point pos;
|
||||
|
||||
for(matrix::rectangle it{map.walls(), room.x, room.y, room.width, room.height}; it.next();)
|
||||
for(matrix::rectangle it{map->walls(), room.x, room.y, room.width, room.height}; it.next();)
|
||||
{
|
||||
if(map.iswall(it.x, it.y)) {
|
||||
matrix::dump("BAD RECTANGLE SPOT", map.walls(), it.x, it.y);
|
||||
if(map->iswall(it.x, it.y)) {
|
||||
matrix::dump("BAD RECTANGLE SPOT", map->walls(), it.x, it.y);
|
||||
}
|
||||
|
||||
REQUIRE(!map.iswall(it.x, it.y));
|
||||
REQUIRE(!map->iswall(it.x, it.y));
|
||||
REQUIRE(size_t(it.x) >= room.x);
|
||||
REQUIRE(size_t(it.y) >= room.y);
|
||||
REQUIRE(size_t(it.x) <= room.x + room.width);
|
||||
|
|
|
@ -14,47 +14,8 @@ using namespace fmt;
|
|||
using std::string;
|
||||
using namespace components;
|
||||
|
||||
|
||||
enum class Item : char {
|
||||
RADAR = 'R',
|
||||
TRAP = 'T',
|
||||
ORE = 'O'
|
||||
};
|
||||
|
||||
struct Pixel {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
DEFINE_SERIALIZABLE(Pixel, x, y);
|
||||
};
|
||||
|
||||
struct Robot {
|
||||
Pixel point;
|
||||
std::wstring name;
|
||||
std::optional<Item> item;
|
||||
|
||||
DEFINE_SERIALIZABLE(Robot, point, name, item);
|
||||
};
|
||||
|
||||
|
||||
TEST_CASE("test using tser for serialization", "[config]") {
|
||||
auto robot = Robot{ Pixel{3,4}, L"BIG NAME", Item::RADAR};
|
||||
|
||||
tser::BinaryArchive archive;
|
||||
archive.save(robot);
|
||||
std::string_view archive_view = archive.get_buffer();
|
||||
|
||||
tser::BinaryArchive archive2(0);
|
||||
archive2.initialize(archive_view);
|
||||
auto loadedRobot = archive2.load<Robot>();
|
||||
|
||||
REQUIRE(loadedRobot.point.x == robot.point.x);
|
||||
REQUIRE(loadedRobot.point.y == robot.point.y);
|
||||
REQUIRE(loadedRobot.name == robot.name);
|
||||
REQUIRE(loadedRobot.item == robot.item);
|
||||
}
|
||||
|
||||
TEST_CASE("basic save a world", "[save]") {
|
||||
/*
|
||||
DinkyECS::World world;
|
||||
Map map(20, 20);
|
||||
WorldBuilder builder(map);
|
||||
|
@ -100,4 +61,5 @@ TEST_CASE("basic save a world", "[save]") {
|
|||
|
||||
Inventory &inv = world.get<Inventory>(player.entity);
|
||||
REQUIRE(inv.gold == 102);
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include "map.hpp"
|
||||
#include "worldbuilder.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
#include "tilemap.hpp"
|
||||
#include "config.hpp"
|
||||
#include "rand.hpp"
|
||||
|
@ -10,12 +10,9 @@ using namespace fmt;
|
|||
using std::string;
|
||||
|
||||
TEST_CASE("tilemap can load tiles and make a map", "[tilemap]") {
|
||||
size_t width = Random::uniform<size_t>(10, 25);
|
||||
size_t height = Random::uniform<size_t>(10, 33);
|
||||
|
||||
Map map(width,height);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_map();
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &map = *level.map;
|
||||
|
||||
TileMap tiles(map.width(), map.height());
|
||||
auto& walls = map.walls();
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include "map.hpp"
|
||||
#include "worldbuilder.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using namespace nlohmann;
|
||||
using std::string;
|
||||
|
||||
TEST_CASE("bsp algo test", "[builder]") {
|
||||
Map map(31, 20);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_map();
|
||||
}
|
||||
|
||||
TEST_CASE("pathing", "[builder]") {
|
||||
Map map(23, 14);
|
||||
WorldBuilder builder(map);
|
||||
builder.generate_map();
|
||||
|
||||
matrix::dump("WALLS", map.$walls, 0,0);
|
||||
println("wall at 0,0=={}", map.$walls[0][0]);
|
||||
|
||||
for(matrix::each_cell it{map.$walls}; it.next();) {
|
||||
if(map.$walls[it.y][it.x] == WALL_VALUE) {
|
||||
REQUIRE(map.iswall(it.x, it.y) == true);
|
||||
REQUIRE(map.can_move({it.x, it.y}) == false);
|
||||
} else {
|
||||
REQUIRE(map.iswall(it.x, it.y) == false);
|
||||
REQUIRE(map.can_move({it.x, it.y}) == true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue