Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine/render/geometry/ocean_fft.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "render/geometry/ocean_fft.h"

#include <cmath>
#include <cstring>
#include <random>
#include <vector>

Expand Down
33 changes: 7 additions & 26 deletions engine/ui/splash.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include "ui/splash.h"

#include <unistd.h>

#include <cstdio>
#include <cstddef>
#include <cstring>
#include <filesystem>
#include <string>
#include <system_error>

#include <ugui/core/color.h>
Expand All @@ -33,9 +29,8 @@ namespace fs = std::filesystem;
constexpr f32 kLogoHeightFraction = 0.26f;
constexpr f32 kLogoWidthFraction = 0.52f;

// ultragui's TextEngine opens fonts by path (FT_New_Face), and rx ships Roboto
// inside rx_fonts.rxp, so the bytes have no path of their own. Mirror them into
// one file under the temp dir; Shutdown removes it again.
// rx ships Roboto inside rx_fonts.rxp, so the face has no path of its own and
// is handed to ultragui as bytes (LoadFontMemory, which keeps its own copy).
constexpr const char* kFontAsset = "fonts://roboto/Roboto-Medium.ttf";

// A font on the machine, for a tree whose rx_fonts.rxp was never packed. The
Expand Down Expand Up @@ -159,20 +154,11 @@ bool Splash::Initialize(Window& window, render::Renderer& renderer, asset::Vfs&

bool Splash::LoadFont(asset::Vfs& vfs) {
if (std::optional<base::Vector<u8>> bytes = vfs.Read(kFontAsset)) {
std::error_code ec;
fs::path path = fs::temp_directory_path(ec) /
("rx-splash-" + std::to_string(::getpid()) + ".ttf");
if (!ec) {
if (std::FILE* f = std::fopen(path.c_str(), "wb")) {
const std::size_t written = std::fwrite(bytes->data(), 1, bytes->size(), f);
std::fclose(f);
if (written == bytes->size()) {
font_cache_path_ = path.string();
ui_->set_default_font(ui_->LoadFont(font_cache_path_.c_str()));
return true;
}
fs::remove(path, ec);
}
const ugui::FontHandle font = ui_->LoadFontMemory(
reinterpret_cast<const char*>(bytes->data()), bytes->size());
if (font != ugui::kInvalidFont) {
ui_->set_default_font(font);
return true;
}
}
if (const char* system = SystemFont()) {
Expand Down Expand Up @@ -370,11 +356,6 @@ void Splash::Shutdown() {
park_.reset(); // before ui_: ScopedActive restores in reverse order
ui_.reset();
}
if (!font_cache_path_.empty()) {
std::error_code ec;
fs::remove(font_cache_path_, ec);
font_cache_path_.clear();
}
draw_data_ = nullptr;
ready_ = false;
}
Expand Down
3 changes: 0 additions & 3 deletions engine/ui/splash.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define RX_UI_SPLASH_H_

#include <optional>
#include <string>

#include <ugui/ui_context.h>

Expand Down Expand Up @@ -103,8 +102,6 @@ class RX_UI_EXPORT Splash {
// canvas. BuildDocument measures the draw box from it, so the two cannot
// drift apart without the wordmark stretching to cover the difference.
f32 logo_aspect_ = 1.0f;
// Deleted in Shutdown; empty when the font came from the system instead.
std::string font_cache_path_;

f32 total_seconds_ = kDefaultSeconds;
f32 elapsed_ = 0.0f;
Expand Down