I have a test now that can generate a map image so I'll make it look nice there before bringing the code into the game.
This commit is contained in:
parent
cfefffe1cc
commit
2c011079a8
7 changed files with 103 additions and 50 deletions
6
Makefile
6
Makefile
|
@ -34,7 +34,7 @@ tracy_build:
|
|||
meson compile -j 10 -C builddir
|
||||
|
||||
test: build
|
||||
./builddir/runtests
|
||||
./builddir/runtests "[map-sprite]"
|
||||
|
||||
run: build test
|
||||
ifeq '$(OS)' 'Windows_NT'
|
||||
|
@ -45,7 +45,7 @@ else
|
|||
endif
|
||||
|
||||
debug: build
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/icongen
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/zedcaster
|
||||
|
||||
debug_run: build
|
||||
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/zedcaster
|
||||
|
@ -57,7 +57,7 @@ clean:
|
|||
meson compile --clean -C builddir
|
||||
|
||||
debug_test: build
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e
|
||||
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[map-sprite]"
|
||||
|
||||
win_installer:
|
||||
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'
|
||||
|
|
|
@ -8,121 +8,121 @@
|
|||
{
|
||||
"centered": false,
|
||||
"display": 35,
|
||||
"x": 128,
|
||||
"x": 64,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 10398,
|
||||
"x": 256,
|
||||
"x": 128,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 35,
|
||||
"x": 192,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 35,
|
||||
"x": 256,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 8820,
|
||||
"x": 320,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 9608,
|
||||
"x": 384,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 35,
|
||||
"x": 512,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 8820,
|
||||
"x": 640,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 9608,
|
||||
"x": 768,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": false,
|
||||
"display": 35,
|
||||
"x": 896,
|
||||
"x": 448,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 1003,
|
||||
"x": 1024,
|
||||
"x": 512,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 3848,
|
||||
"x": 1152,
|
||||
"x": 576,
|
||||
"y": 0
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 85,
|
||||
"x": 0,
|
||||
"y": 128
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 8687,
|
||||
"x": 128,
|
||||
"y": 128
|
||||
"x": 64,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 10949,
|
||||
"x": 256,
|
||||
"y": 128
|
||||
"x": 128,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 8793,
|
||||
"x": 384,
|
||||
"y": 128
|
||||
"x": 192,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 95,
|
||||
"x": 512,
|
||||
"y": 128
|
||||
"x": 256,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 1898,
|
||||
"x": 640,
|
||||
"y": 128
|
||||
"x": 320,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 2189,
|
||||
"x": 768,
|
||||
"y": 128
|
||||
"x": 384,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 2189,
|
||||
"x": 896,
|
||||
"y": 128
|
||||
"x": 448,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 42603,
|
||||
"x": 1024,
|
||||
"y": 128
|
||||
"x": 512,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 2220,
|
||||
"x": 1152,
|
||||
"y": 128
|
||||
"x": 576,
|
||||
"y": 64
|
||||
},
|
||||
{
|
||||
"centered": true,
|
||||
"display": 1218,
|
||||
"x": 0,
|
||||
"y": 256
|
||||
"y": 128
|
||||
}
|
||||
]
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 5.5 KiB |
|
@ -411,7 +411,7 @@ void System::plan_motion(World& world, Position move_to) {
|
|||
* This one is called inside the MapViewUI very often so
|
||||
* just avoid GameMap unlike the others.
|
||||
*/
|
||||
std::wstring System::draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir) {
|
||||
std::wstring System::draw_map(GameLevel& level, size_t view_x, size_t view_y, int compass_dir) {
|
||||
World &world = *level.world;
|
||||
Map &map = *level.map;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace System {
|
|||
void init_positions(World &world, SpatialMap &collider);
|
||||
void device(World &world, Entity actor, Entity item);
|
||||
void plan_motion(World& world, Position move_to);
|
||||
std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir);
|
||||
std::wstring draw_map(GameLevel& level, size_t view_x, size_t view_y, int compass_dir);
|
||||
Entity spawn_item(World& world, const string& name);
|
||||
bool drop_item(GameLevel& level, Entity item);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ json load_test_data(const string &fname) {
|
|||
}
|
||||
|
||||
TEST_CASE("camera control", "[map]") {
|
||||
textures::init();
|
||||
components::init();
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
|
@ -33,6 +34,7 @@ TEST_CASE("camera control", "[map]") {
|
|||
}
|
||||
|
||||
TEST_CASE("map placement test", "[map:placement]") {
|
||||
textures::init();
|
||||
components::init();
|
||||
for(int i = 0; i < 20; i++) {
|
||||
LevelManager levels;
|
||||
|
@ -51,6 +53,7 @@ TEST_CASE("map placement test", "[map:placement]") {
|
|||
}
|
||||
|
||||
TEST_CASE("dijkstra algo test", "[map]") {
|
||||
textures::init();
|
||||
json data = load_test_data("./tests/dijkstra.json");
|
||||
|
||||
for(auto &test : data) {
|
||||
|
@ -76,3 +79,53 @@ TEST_CASE("dijkstra algo test", "[map]") {
|
|||
// FIX ME: REQUIRE(paths == expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("map image test", "[map-sprite]") {
|
||||
components::init();
|
||||
textures::init();
|
||||
LevelManager levels;
|
||||
GameLevel level = levels.current();
|
||||
auto &walls = level.map->tiles();
|
||||
auto &tile_set = textures::get_map_tile_set();
|
||||
|
||||
sf::Vector2i size{64,64};
|
||||
matrix::dump("TILES?", walls);
|
||||
|
||||
std::unordered_map<wchar_t, sf::Vector2i> sprite_coord;
|
||||
|
||||
Config config("./assets/map_tiles.json");
|
||||
json& tiles = config.json();
|
||||
|
||||
for(auto tile : tiles) {
|
||||
sf::Vector2i coords{tile["x"], tile["y"]};
|
||||
sprite_coord.insert_or_assign(tile["display"], coords);
|
||||
}
|
||||
|
||||
sf::Vector2u dim{
|
||||
(unsigned int)matrix::width(walls) * size.x,
|
||||
(unsigned int)matrix::height(walls) * size.y};
|
||||
|
||||
sf::RenderTexture render{dim};
|
||||
render.clear({50,50,50,255});
|
||||
|
||||
sf::Texture map_sprites{"./assets/map_tiles.png"};
|
||||
|
||||
for(matrix::each_row it{walls}; it.next();) {
|
||||
size_t tid = walls[it.y][it.x];
|
||||
wchar_t display = tile_set[tid];
|
||||
REQUIRE(sprite_coord.contains(display));
|
||||
|
||||
auto coords = sprite_coord.at(display);
|
||||
sf::IntRect square{coords, size};
|
||||
sf::Sprite sprite{map_sprites, square};
|
||||
sprite.setColor({150,150,150,255});
|
||||
sprite.setPosition({float(it.x) * float(size.x), float(it.y) * float(size.y)});
|
||||
render.draw(sprite);
|
||||
}
|
||||
|
||||
render.display();
|
||||
sf::Image out_img = render.getTexture().copyToImage();
|
||||
bool worked = out_img.saveToFile("map_test.png");
|
||||
REQUIRE(worked);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace fs = std::filesystem;
|
||||
constexpr const int TILE_COUNT=10;
|
||||
constexpr const sf::Color DEFAULT_COLOR{255, 255, 255, 255};
|
||||
constexpr const size_t DEFAULT_DIM=128;
|
||||
constexpr const size_t DEFAULT_DIM=64;
|
||||
|
||||
using namespace shiterator;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue