#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace entt::literals; TEST(tilemap_render_task_test, it) { MM::Engine engine; auto& sdl_ss = engine.addService(); ASSERT_TRUE(engine.enableService()); sdl_ss.createGLWindow("tilemap_render_task_test", 1280, 720); engine.addService(); ASSERT_TRUE(engine.enableService()); bool provide_ret = engine.provide(); ASSERT_TRUE(provide_ret); auto& scene = engine.tryService()->getScene(); auto& cam = scene.ctx().emplace(); cam.translation = {2.f, -2.f, 0.f}; cam.horizontalViewPortSize = 20.f; cam.setOrthographic(); cam.updateView(); engine.addService(nullptr, "tilemap_render_task_test"); ASSERT_TRUE(engine.enableService()); auto& rs = engine.addService(); ASSERT_TRUE(engine.enableService()); rs.addRenderTask(engine); scene.on_construct().connect<&entt::registry::emplace_or_replace>(); scene.on_construct().connect<&entt::registry::emplace_or_replace>(); scene.on_construct().connect<&entt::registry::emplace_or_replace>(); scene.on_construct().connect<&entt::registry::emplace_or_replace>(); // fun // "useless" in this example scene.on_update().connect<&entt::registry::emplace_or_replace>(); scene.on_update().connect<&entt::registry::emplace_or_replace>(); scene.on_update().connect<&entt::registry::emplace_or_replace>(); auto& org = scene.ctx().emplace(); org.emplace("position3d_from_2d"); org.emplace("transform3d_translate"); org.emplace("transform_clear_dirty"); // HACK: instead you would switch to this scene engine.getService().updateOrganizerVertices(scene); auto& rm_t = MM::ResourceManager::ref(); { auto e = scene.create(); scene.emplace(e); auto& tm = scene.emplace(e); auto& slayer = tm.sprite_layer.emplace_back(); // fill sprite sheet { slayer.sprite_sheet.tile_count.x = 1; slayer.sprite_sheet.tile_count.y = 1; //slayer.sprite_sheet.tex = rm_t.get("default"_hs); slayer.sprite_sheet.tex = rm_t.get("errig"_hs); } // fill tiles { std::vector temp_map { 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, }; uint32_t width = 5; uint32_t height = 5; for (uint32_t y = 0; y < height; y++) { for (uint32_t x = 0; x < width; x++) { if (temp_map[y*width + x] != 0) { auto& tile = slayer.map.emplace_back(); tile.pos[0] = x; tile.pos[1] = y; tile.sprite_sheet_index = temp_map[y*width + x] - 1; } } } slayer.syncMapBuffer(); // send to opengl } } engine.run(); } int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }