Skip to content

Commit

Permalink
Merge pull request #134 from adam-ce/main
Browse files Browse the repository at this point in the history
improve wasm release build (LTO, remove markdown and fmt dependencies), add copyright label
  • Loading branch information
adam-ce authored Nov 5, 2024
2 parents 532d218 + eb36db3 commit b19e6c3
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 54 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:

- name: Cache Qt WebAssembly build
id: qt-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: qt_wasm_lite
key: wasm-qt-${{ env.QT_VERSION }}-${{ env.WEBASSEMBLY_VERSION }}
Expand All @@ -240,7 +240,9 @@ jobs:
dest_dir="${{env.QT_WASM_ROOT_DIR}}"
mkdir qt_wasm_build
cd qt_wasm_build
${{env.QT_SRC_CONFIGURE}} -qt-host-path $QT_HOST_PATH -release $(cat ${{env.QT_LITE_CONFIG}}) -prefix "${QT_WASM_ROOT_DIR}/" && cmake --build . --parallel && cmake --install .
${{env.QT_SRC_CONFIGURE}} -qt-host-path $QT_HOST_PATH -release -ltcg $(cat ${{env.QT_LITE_CONFIG}}) -prefix "${QT_WASM_ROOT_DIR}/"
sed -i 's/-flto=thin/-flto/g' ./build.ninja
cmake --build . --parallel && cmake --install .
# Fail if the directory is not created or is empty
[ -d "$QT_WASM_ROOT_DIR" ] && [ "$(ls -A $QT_WASM_ROOT_DIR)" ] || exit 1
Expand Down
35 changes: 20 additions & 15 deletions app/About.qml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Rectangle {
}


Text {
Label {
id: about_text
anchors {
left: logo.left
Expand All @@ -65,26 +65,31 @@ Rectangle {
width: about_root.width - 20
wrapMode: Text.Wrap
onLinkActivated: Qt.openUrlExternally(link)
textFormat: Text.MarkdownText
textFormat: Text.StyledText
linkColor: Material.accentColor
text: qsTr("
This is an open source application. It is **released** under the GNU General Public License (version 3 or any later version). The source code is available on [github.com/AlpineMapsOrg/renderer](https://github.com/AlpineMapsOrg/renderer).
The source of elevation and orthographic photo data is [basemap.at](https://basemap.at),
This is an open source application. It is released under the GNU General Public License (version 3 or any later version).
The source code is available on <a href=\"https://github.com/AlpineMapsOrg/renderer\">github.com/AlpineMapsOrg/renderer</a>.
<br><br>
The source of elevation and orthographic photo data is <a href=\"https://basemap.at/\">basemap.at</a>,
it is licensed under the Open Government Data Austria license (CC-BY 4.0).
The source of POI feature labels is [openstreetmap.org](https://www.openstreetmap.org/copyright),
<br><br>
The source of POI feature labels is <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a>,
it is licensed under the Open Data Commons Open Database License (ODbL) by the OpenStreetMap Foundation (OSMF).
<br>
## Authors:
<h2>Authors:</h2>
Adam Celarek, Lucas Dworschak, Gerald Kimmersdorfer, Jakob Lindner, Patrick Komon, Jakob Maier
<br>
## Impressum:
Adam Celarek\\
Frankenberggasse 8/10\\
1040 Wien\\
Österreich / Austria
E-Mail: [email protected]")
<h2>Impressum:</h2>
Adam Celarek<br>
Frankenberggasse 8/10<br>
1040 Wien<br>
Österreich / Austria<br>
<br>
E-Mail: [email protected]
<br>")
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions app/Map.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,60 @@ Rectangle {
bottomMargin: 8
}
}

Rectangle {
id: copyright_frame
// property string originalText: qsTr("© [OpenStreetMap](https://www.openstreetmap.org/copyright), © [basemap.at](https://basemap.at/)")
property string originalText: qsTr("© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a>, © <a href=\"https://basemap.at/\">basemap.at</a>")
property string placeholderText: qsTr("©")

anchors {
bottom: map_gui.bottom
right: map_gui.right
}
width: copyright.width + 16
height: copyright.height + 4
color: Qt.alpha(Material.backgroundColor, 0.7)
Behavior on width { NumberAnimation { duration: 1000; easing.type: Easing.OutExpo } }

MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true

onClicked: {
delayTimer.stop()
copyright.text = copyright_frame.originalText
}

onExited: {
// Restart the timer when mouse leaves
delayTimer.restart()
}
}

Timer {
id: delayTimer
interval: 8000 // 8 seconds delay
running: true
repeat: false
onTriggered: {
copyright.text = copyright_frame.placeholderText
}
}

Label {
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 8
}
id: copyright
onLinkActivated: Qt.openUrlExternally(link)
textFormat: Text.StyledText

text: copyright_frame.originalText
}
}

}
2 changes: 1 addition & 1 deletion app/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Rectangle {

Rectangle {
id: settings_frame
color: Qt.alpha(Material.backgroundColor, 0.7)
color: Qt.alpha(Material.backgroundColor, 0.9)
clip: true
anchors {
right: settings_root.right
Expand Down
2 changes: 2 additions & 0 deletions misc/qt_lite.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
-no-feature-quick-pathview
-no-feature-texthtmlparser
-no-feature-textodfwriter
-no-feature-textmarkdownwriter
-no-feature-textmarkdownreader
-no-feature-quickcontrols2-windows
-no-feature-quickcontrols2-macos
-no-feature-quickcontrols2-ios
Expand Down
7 changes: 2 additions & 5 deletions nucleus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ project(alpine-renderer-nucleus LANGUAGES CXX)
alp_add_git_repository(stb_slim URL https://github.com/AlpineMapsOrgDependencies/stb_slim.git COMMITISH 547fade2a12793e1bea4733d59646b4f436e25a4)
alp_add_git_repository(radix URL https://github.com/AlpineMapsOrg/radix.git COMMITISH 5718519002b26cdd54030e3ec227d27f46f79a64 NOT_SYSTEM)
alp_add_git_repository(tl_expected URL https://github.com/TartanLlama/expected.git COMMITISH v1.1.0 DO_NOT_ADD_SUBPROJECT)
if (NOT TARGET fmt)
alp_add_git_repository(fmt URL https://github.com/fmtlib/fmt.git COMMITISH 10.1.1)
endif()
alp_add_git_repository(zppbits URL https://github.com/eyalz800/zpp_bits.git COMMITISH v4.4.20 DO_NOT_ADD_SUBPROJECT)
if(ALP_ENABLE_LABELS)
alp_add_git_repository(vector_tiles URL https://github.com/AlpineMapsOrg/vector-tile.git COMMITISH faba88257716c4bc01ebd44d8b8b98f711ecb78c)
Expand Down Expand Up @@ -147,7 +144,7 @@ endif()

target_include_directories(nucleus PUBLIC ${CMAKE_SOURCE_DIR})
# Please keep Qt::Gui outside the nucleus. If you need it optional via a cmake based switch
target_link_libraries(nucleus PUBLIC radix Qt::Core Qt::Network fmt::fmt zppbits tl_expected nucleus_version stb_slim goofy_tc)
target_link_libraries(nucleus PUBLIC radix Qt::Core Qt::Network zppbits tl_expected nucleus_version stb_slim goofy_tc)

qt_add_resources(nucleus "icons"
PREFIX "/map_icons"
Expand All @@ -164,7 +161,7 @@ qt_add_resources(nucleus "height_data"
FILES ${renderer_static_data_SOURCE_DIR}/height_data.atb
)
qt_add_resources(nucleus "nucleus_fonts"
BASE ${alpineapp_fonts_SOURCE_DIR}/SourceSans/
BASE ${alpineapp_fonts_SOURCE_DIR}/
PREFIX "/fonts"
FILES
${alpineapp_fonts_SOURCE_DIR}/Roboto/Roboto-Bold.ttf
Expand Down
51 changes: 25 additions & 26 deletions nucleus/tile/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <QFile>
#include <algorithm>
#include <filesystem>
#include <fmt/format.h>
#include <mutex>
#include <nucleus/utils/lang.h>
#include <shared_mutex>
Expand Down Expand Up @@ -79,8 +78,8 @@ class Cache
const T& peak_at(const tile::Id& id) const;
std::vector<T> purge(unsigned remaining_capacity);

[[nodiscard]] tl::expected<void, std::string> write_to_disk(const std::filesystem::path& path);
[[nodiscard]] tl::expected<void, std::string> read_from_disk(const std::filesystem::path& path);
[[nodiscard]] tl::expected<void, QString> write_to_disk(const std::filesystem::path& path);
[[nodiscard]] tl::expected<void, QString> read_from_disk(const std::filesystem::path& path);

private:
template<typename VisitorFunction>
Expand All @@ -90,7 +89,8 @@ class Cache

static std::filesystem::path tile_path(const std::filesystem::path& base_path, const tile::Id& id)
{
return base_path / fmt::format("{}_{}_{}.alp_tile", id.zoom_level, id.coords.x, id.coords.y);
std::string tile_name = std::to_string(id.zoom_level) + "_" + std::to_string(id.coords.x) + "_" + std::to_string(id.coords.y) + ".alp_tile";
return base_path / tile_name;
}

static std::filesystem::path meta_info_path(const std::filesystem::path& base_path)
Expand Down Expand Up @@ -132,9 +132,9 @@ const T& Cache<T>::peak_at(const tile::Id& id) const
return m_data.at(id).data;
}

template <NamedTile T>
tl::expected<void, std::string> Cache<T>::write_to_disk(const std::filesystem::path& base_path)
template <NamedTile T> tl::expected<void, QString> Cache<T>::write_to_disk(const std::filesystem::path& base_path)
{
const auto unexpected_error = [](const auto& e) { return tl::unexpected(QString::fromStdString(std::make_error_code(e).message())); };
static_assert(SerialisableTile<T>);
std::filesystem::create_directories(base_path);
std::unordered_map<tile::Id, CacheObject, tile::Id::Hasher> data;
Expand All @@ -144,12 +144,11 @@ tl::expected<void, std::string> Cache<T>::write_to_disk(const std::filesystem::p
}
auto locker = std::scoped_lock(m_disk_cached_mutex);

const auto write = [](const auto& bytes, const auto& path) -> tl::expected<void, std::string> {
const auto write = [](const auto& bytes, const auto& path) -> tl::expected<void, QString> {
QFile file(path);
const auto success = file.open(QIODeviceBase::WriteOnly);
if (!success)
return tl::unexpected<std::string>(
fmt::format("Couldn't open file '{}' for writing!", path.string()));
return tl::unexpected<QString>(QString("Couldn't open file '%1' for writing!").arg(QString::fromStdString(path.string())));
file.write(bytes.data(), qint64(bytes.size()));
return {};
};
Expand Down Expand Up @@ -183,12 +182,12 @@ tl::expected<void, std::string> Cache<T>::write_to_disk(const std::filesystem::p
{
const auto r = out(version);
if (failure(r))
return tl::unexpected(std::make_error_code(r).message());
return unexpected_error(r);
}
{
const auto r = out(cache_object.data);
if (failure(r))
return tl::unexpected(std::make_error_code(r).message());
return unexpected_error(r);
}
{
const auto r = write(bytes, tile_path(base_path, id));
Expand All @@ -203,13 +202,13 @@ tl::expected<void, std::string> Cache<T>::write_to_disk(const std::filesystem::p
{
const auto r = out(version);
if (failure(r))
return tl::unexpected(std::make_error_code(r).message());
return unexpected_error(r);
}

{
const auto r = out(m_disk_cached);
if (failure(r))
return tl::unexpected(std::make_error_code(r).message());
return unexpected_error(r);
}

const auto r = write(bytes, meta_info_path(base_path));
Expand All @@ -219,34 +218,34 @@ tl::expected<void, std::string> Cache<T>::write_to_disk(const std::filesystem::p
return {};
}

template <NamedTile T>
tl::expected<void, std::string> Cache<T>::read_from_disk(const std::filesystem::path& base_path)
template <NamedTile T> tl::expected<void, QString> Cache<T>::read_from_disk(const std::filesystem::path& base_path)
{
const auto unexpected_error = [](const auto& e) { return tl::unexpected(QString::fromStdString(std::make_error_code(e).message())); };
auto locker = std::scoped_lock(m_data_mutex, m_disk_cached_mutex);
assert(SerialisableTile<T>);
const auto check_version = [](auto* in, const auto& path) -> tl::expected<void, std::string> {
const auto check_version = [&unexpected_error](auto* in, const auto& path) -> tl::expected<void, QString> {
std::remove_cvref_t<decltype(T::version_information)> version_info = {};
{
const auto r = (*in)(version_info);
if (failure(r))
return tl::unexpected(std::make_error_code(r).message());
return unexpected_error(r);
}
if (version_info != T::version_information) {
version_info[version_info.size() - 1] = 0; // make sure that the string is 0 terminated.

return tl::unexpected(fmt::format("Cache file '{}' has incompatible version! Disk "
"version is '{}', but we expected '{}'.",
path.string(),
version_info.data(),
T::version_information.data()));
return tl::unexpected(QString("Cache file '%1' has incompatible version! Disk "
"version is '%2', but we expected '%3'.")
.arg(QString::fromStdString(path.string()))
.arg(version_info.data())
.arg(T::version_information.data()));
}
return {};
};
const auto read_all = [](const auto& path) -> tl::expected<QByteArray, std::string> {
const auto read_all = [](const auto& path) -> tl::expected<QByteArray, QString> {
QFile file(path);
const auto success = file.open(QIODeviceBase::ReadOnly);
if (!success)
return tl::unexpected(fmt::format("Couldn't open file '{}' for reading!", path.string()));
return tl::unexpected(QString("Couldn't open file '%1' for reading!").arg(QString::fromStdString(path.string())));
return file.readAll();
};
const auto clean_up = [&]() {
Expand Down Expand Up @@ -274,7 +273,7 @@ tl::expected<void, std::string> Cache<T>::read_from_disk(const std::filesystem::
const auto r = in(m_disk_cached);
if (failure(r)) {
clean_up();
return tl::unexpected(std::make_error_code(r).message());
return unexpected_error(r);
}
}
}
Expand Down Expand Up @@ -303,7 +302,7 @@ tl::expected<void, std::string> Cache<T>::read_from_disk(const std::filesystem::
const auto r = in(d.data);
if (failure(r)) {
clean_up();
return tl::unexpected(std::make_error_code(r).message());
return unexpected_error(r);
}
}
d.meta = meta;
Expand Down
6 changes: 2 additions & 4 deletions nucleus/tile/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ void Scheduler::persist_tiles()
.arg(m_ram_cache.n_cached_objects());

if (!r.has_value()) {
qDebug() << QString("Writing tiles to disk into %1 failed: %2. Removing all files.")
.arg(QString::fromStdString(disk_cache_path().string()))
.arg(QString::fromStdString(r.error()));
qDebug() << QString("Writing tiles to disk into %1 failed: %2. Removing all files.").arg(QString::fromStdString(disk_cache_path().string())).arg(r.error());
std::filesystem::remove_all(disk_cache_path());
}
}
Expand Down Expand Up @@ -235,7 +233,7 @@ void Scheduler::read_disk_cache()
if (r.has_value()) {
update_stats();
} else {
qDebug() << QString("Reading tiles from disk cache (%1) failed: \n%2\nRemoving all files.").arg(QString::fromStdString(disk_cache_path().string())).arg(QString::fromStdString(r.error()));
qDebug() << QString("Reading tiles from disk cache (%1) failed: \n%2\nRemoving all files.").arg(QString::fromStdString(disk_cache_path().string())).arg(r.error());
std::filesystem::remove_all(disk_cache_path());
}
}
Expand Down
2 changes: 1 addition & 1 deletion unittests/nucleus/tile_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ TEST_CASE("nucleus/tile/cache")
cache.insert(create_test_tile({ i, { 0, 1 } }));
}
const auto r = cache.write_to_disk(path);
std::string err;
QString err;
if (!r.has_value())
err = r.error();
CHECK(r.has_value());
Expand Down

0 comments on commit b19e6c3

Please sign in to comment.