Skip to content

Commit 7a2692a

Browse files
authored
Merge pull request #162 from OpenBrickProtocolFoundation/serenity-os-support
Add support for Serenity OS
2 parents 009b3d5 + fd0f72e commit 7a2692a

File tree

11 files changed

+126
-6
lines changed

11 files changed

+126
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It is written in [OOP](https://en.wikipedia.org/wiki/Object-oriented_programming
99

1010
## Platform support
1111

12-
This officially supports Linux, Windows, MacOS, Android, Nintendo Switch and Nintendo 3DS.
12+
This officially supports Linux, Windows, MacOS, Android, Serenity OS, Nintendo Switch and Nintendo 3DS.
1313

1414
Why these? Because it was fun to port the application to those platforms 😋
1515

docs/develop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ For concrete instructions, see the list below:
1010

1111
[linux](linux.md)
1212

13+
## Serenity OS
14+
15+
[serenity](serenity.md)
16+
17+
1318
## Windows
1419

1520
[windows](windows.md)

docs/serenity.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Serenity OS build
2+
3+
## How to build
4+
5+
To add this to the serenity OS system, you have to build the port for it.
6+
7+
8+
Copy `platforms/serenity/package.sh` to `Ports/oopetris/package.sh`, create the directory `Ports/oopetris/` and add the file to it.
9+
10+
Then just `cd` into the directory and run the `package.sh`, like with all other Serenity OS ports.
11+
12+
13+
## NOTE
14+
15+
We don't have a CI for this port, so please report errors, if you find some.

platforms/serenity/package.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env -S bash ../.port_include.sh
2+
port='oopetris'
3+
version='0.5.6'
4+
files=(
5+
"git+https://github.com/OpenBrickProtocolFoundation/oopetris#${version}"
6+
)
7+
useconfigure='true'
8+
configopts=(
9+
'--cross-file'
10+
"${SERENITY_BUILD_DIR}/meson-cross-file.txt"
11+
"-Dbuildtype=release"
12+
)
13+
depends=(
14+
'SDL2'
15+
'SDL2_image'
16+
'SDL2_mixer'
17+
'SDL2_ttf'
18+
'nlohmann-json'
19+
)
20+
21+
configure() {
22+
run meson setup _build "${configopts[@]}"
23+
}
24+
25+
build() {
26+
run meson compile -C _build
27+
}
28+
29+
install() {
30+
export DESTDIR="${SERENITY_INSTALL_ROOT}"
31+
run meson install -C _build
32+
}

src/executables/game/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace {
9292

9393

9494
try {
95-
#if defined(__ANDROID__) or defined(__CONSOLE__)
95+
#if defined(__ANDROID__) or defined(__CONSOLE__) or defined(__SERENITY__)
9696
window = std::make_shared<Window>(window_name, WindowPosition::Centered);
9797
#else
9898
[[maybe_unused]] static constexpr int width = 1280;

src/executables/game/parser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ helper::expected<CommandLineArguments, std::string> helper::parse_args(const std
4141
spdlog::error("invalid value for target fps ({}), using default value instead (VSYNC)", fps.value());
4242
}
4343
}
44+
#if defined(__SERENITY__)
45+
// serenity OS can#t handle vsync very well (Since it's inside qemu), so setting the target_fps value to 60 per default
46+
if (not result.target_fps.has_value()) {
47+
result.target_fps = 60;
48+
}
49+
#endif
50+
4451

4552
const auto level = parser.get<CommandLineArguments::Level>("--level");
4653
if (level <= 30) {
@@ -56,7 +63,6 @@ helper::expected<CommandLineArguments, std::string> helper::parse_args(const std
5663
result.silent = parser.get<bool>("--silent");
5764

5865
return result;
59-
6066
} catch (const std::exception& error) {
6167
return helper::unexpected<std::string>{ error.what() };
6268
}

src/graphics/renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Renderer::Renderer(const Window& window, const VSync v_sync)
1010
window.get_sdl_window(),
1111
-1,
1212
(v_sync == VSync::Enabled ? SDL_RENDERER_PRESENTVSYNC : 0) | SDL_RENDERER_TARGETTEXTURE
13-
#if defined(__3DS__)
13+
#if defined(__3DS__) || defined(__SERENITY__)
1414
| SDL_RENDERER_SOFTWARE
1515
#else
1616
| SDL_RENDERER_ACCELERATED

src/helper/graphic_utils.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ std::vector<std::string> utils::supported_features() {
4848
throw std::runtime_error{ "Failed to get flatpak data directory (XDG_DATA_HOME)" };
4949
}
5050

51-
return std::filesystem::path{ data_home };
51+
return std::filesystem::path{ data_home } / "share" / constants::program_name;
5252
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
5353
char* pref_path = SDL_GetPrefPath(constants::author, constants::program_name);
5454
if (!pref_path) {
@@ -58,6 +58,33 @@ std::vector<std::string> utils::supported_features() {
5858
#else
5959
#error "unrecognized installer build"
6060
#endif
61+
#elif defined(INSTALL_FILES)
62+
#if !defined(INSTALL_LOCATION)
63+
#error "missing 'INSTALL_LOCATION' define"
64+
#endif
65+
66+
#if defined(__SERENITY__)
67+
68+
69+
// this is a read write location in the serenityos case build, see https://docs.flatpak.org/en/latest/conventions.html
70+
const char* data_home = std::getenv("HOME");
71+
if (data_home == nullptr) {
72+
throw std::runtime_error{ "Failed to get flatpak data directory (XDG_DATA_HOME)" };
73+
}
74+
75+
return std::filesystem::path{ data_home } / "share" / constants::program_name;
76+
77+
#else
78+
79+
#define STRINGIFY(a) STRINGIFY_HELPER_(a) //NOLINT(cppcoreguidelines-macro-usage)
80+
#define STRINGIFY_HELPER_(a) #a
81+
82+
return std::filesystem::path{ STRINGIFY(INSTALL_LOCATION) } / "share" / constants::program_name;
83+
84+
85+
#undef STRINGIFY
86+
#undef STRINGIFY_HELPER_
87+
#endif
6188
#else
6289
// this is only used in local build for debugging, when compiling in release mode the path is real path where the app can store many things without interfering with other things (eg. AppData\Roaming\... on Windows or .local/share/... on Linux )
6390
return std::filesystem::path{ "." };
@@ -86,7 +113,23 @@ std::vector<std::string> utils::supported_features() {
86113
#else
87114
#error "unrecognized installer build"
88115
#endif
116+
#elif defined(INSTALL_FILES)
117+
#if !defined(INSTALL_LOCATION)
118+
#error "missing 'INSTALL_LOCATION' define"
119+
#endif
120+
121+
#define STRINGIFY(a) STRINGIFY_HELPER_(a) //NOLINT(cppcoreguidelines-macro-usage)
122+
#define STRINGIFY_HELPER_(a) #a
123+
124+
return std::filesystem::path{ STRINGIFY(INSTALL_LOCATION) } / "share" / "oopetris" / "assets";
125+
126+
127+
#undef STRINGIFY
128+
#undef STRINGIFY_HELPER_
129+
89130
#else
131+
132+
90133
return std::filesystem::path{ "assets" };
91134
#endif
92135
}

src/helper/platform.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
#include "platform.hpp"
33

4+
#include <core/helper/utils.hpp>
5+
46
#if defined(__CONSOLE__)
57
#include "helper/console_helpers.hpp"
68
#include "input/console_buttons.hpp"
@@ -51,6 +53,8 @@ namespace {
5153
return "Windows";
5254
#elif defined(__APPLE__)
5355
return "MacOS";
56+
#elif defined(__SERENITY__)
57+
return "Serenity OS";
5458
#else
5559
#error "Unsupported platform"
5660
#endif
@@ -71,6 +75,9 @@ namespace {
7175
auto result = console::open_url(url);
7276
spdlog::info("Returned string from url open was: {}", result);
7377
return true;
78+
#elif defined(__SERENITY__)
79+
UNUSED(url);
80+
return false;
7481
#else
7582
//TODO(Totto): this is dangerous, if we supply user input, so use SDL_OpenURL preferably
7683

src/libs/core/helper/date.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ helper::expected<date::ISO8601Date, std::string> date::ISO8601Date::from_string(
3232

3333
std::tm tm = {};
3434

35-
#if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
35+
#if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) \
36+
|| defined(__SERENITY__)
3637

3738

3839
std::istringstream input_stream{ input };

0 commit comments

Comments
 (0)