Skip to content

Commit 42c777c

Browse files
author
Semphris
committed
Fix even more build issues
- The MSVC bug from the parent commit wasn't a macro, apparently - Forgot to commit src/port/emscripten.cpp - Emscripten doesn't support LTO very well, disable it for now
1 parent 390137b commit 42c777c

File tree

3 files changed

+98
-17
lines changed

3 files changed

+98
-17
lines changed

CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ include(ExternalProject)
6464
include(CheckCXXCompilerFlag)
6565
include(CheckSymbolExists)
6666

67-
option(SUPERTUX_IPO "Use interprocedural optimisation (Takes more RAM at compilation, gives smaller and faster builds)" ON)
67+
if(EMSCRIPTEN)
68+
# FIXME: As of writing, Emscripten fails with "wasm-ld: error: /path/to/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libc.a(fileno.o): attempt to add bitcode file after LTO (fileno)"
69+
# Seems to be a known issue: https://github.com/emscripten-core/emscripten/issues/20275
70+
option(SUPERTUX_IPO "Use interprocedural optimisation (Takes more RAM at compilation, gives smaller and faster builds)" OFF)
71+
else()
72+
option(SUPERTUX_IPO "Use interprocedural optimisation (Takes more RAM at compilation, gives smaller and faster builds)" ON)
73+
endif()
6874
if(SUPERTUX_IPO)
6975
include(CheckIPOSupported)
7076
check_ipo_supported(RESULT result)

src/editor/scroller_widget.cpp

+12-16
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
#include "video/video_system.hpp"
2525
#include "video/viewport.hpp"
2626

27-
namespace {
28-
29-
#ifdef _MSC_VER
30-
#undef SIZE
31-
#endif
27+
namespace CONSTS {
3228

3329
const float TOPLEFT = 16;
3430
const float MIDDLE = 48;
@@ -50,34 +46,34 @@ EditorScrollerWidget::EditorScrollerWidget(Editor& editor) :
5046
bool
5147
EditorScrollerWidget::can_scroll() const
5248
{
53-
return m_scrolling && m_mouse_pos.x < SIZE && m_mouse_pos.y < SIZE;
49+
return m_scrolling && m_mouse_pos.x < CONSTS::SIZE && m_mouse_pos.y < CONSTS::SIZE;
5450
}
5551

5652
void
5753
EditorScrollerWidget::draw(DrawingContext& context)
5854
{
5955
if (!rendered) return;
6056

61-
context.color().draw_filled_rect(Rectf(Vector(0, 0), Vector(SIZE, SIZE)),
57+
context.color().draw_filled_rect(Rectf(Vector(0, 0), Vector(CONSTS::SIZE, CONSTS::SIZE)),
6258
Color(0.9f, 0.9f, 1.0f, 0.6f),
63-
MIDDLE, LAYER_GUI-10);
59+
CONSTS::MIDDLE, LAYER_GUI-10);
6460
context.color().draw_filled_rect(Rectf(Vector(40, 40), Vector(56, 56)),
6561
Color(0.9f, 0.9f, 1.0f, 0.6f),
6662
8, LAYER_GUI-20);
6763
if (can_scroll()) {
6864
draw_arrow(context, m_mouse_pos);
6965
}
7066

71-
draw_arrow(context, Vector(TOPLEFT, MIDDLE));
72-
draw_arrow(context, Vector(BOTTOMRIGHT, MIDDLE));
73-
draw_arrow(context, Vector(MIDDLE, TOPLEFT));
74-
draw_arrow(context, Vector(MIDDLE, BOTTOMRIGHT));
67+
draw_arrow(context, Vector(CONSTS::TOPLEFT, CONSTS::MIDDLE));
68+
draw_arrow(context, Vector(CONSTS::BOTTOMRIGHT, CONSTS::MIDDLE));
69+
draw_arrow(context, Vector(CONSTS::MIDDLE, CONSTS::TOPLEFT));
70+
draw_arrow(context, Vector(CONSTS::MIDDLE, CONSTS::BOTTOMRIGHT));
7571
}
7672

7773
void
7874
EditorScrollerWidget::draw_arrow(DrawingContext& context, const Vector& pos)
7975
{
80-
Vector dir = pos - Vector(MIDDLE, MIDDLE);
76+
Vector dir = pos - Vector(CONSTS::MIDDLE, CONSTS::MIDDLE);
8177
if (dir.x != 0 || dir.y != 0) {
8278
// draw a triangle
8379
dir = glm::normalize(dir) * 8.0f;
@@ -109,7 +105,7 @@ EditorScrollerWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
109105
if (button.button == SDL_BUTTON_LEFT) {
110106
if (!rendered) return false;
111107

112-
if (m_mouse_pos.x < SIZE && m_mouse_pos.y < SIZE) {
108+
if (m_mouse_pos.x < CONSTS::SIZE && m_mouse_pos.y < CONSTS::SIZE) {
113109
m_scrolling = true;
114110
return true;
115111
} else {
@@ -126,8 +122,8 @@ EditorScrollerWidget::on_mouse_motion(const SDL_MouseMotionEvent& motion)
126122
if (!rendered) return false;
127123

128124
m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(motion.x, motion.y);
129-
if (m_mouse_pos.x < SIZE && m_mouse_pos.y < SIZE) {
130-
m_scrolling_vec = m_mouse_pos - Vector(MIDDLE, MIDDLE);
125+
if (m_mouse_pos.x < CONSTS::SIZE && m_mouse_pos.y < CONSTS::SIZE) {
126+
m_scrolling_vec = m_mouse_pos - Vector(CONSTS::MIDDLE, CONSTS::MIDDLE);
131127
if (m_scrolling_vec.x != 0 || m_scrolling_vec.y != 0) {
132128
float norm = glm::length(m_scrolling_vec);
133129
m_scrolling_vec *= powf(static_cast<float>(M_E), norm / 16.0f - 1.0f);

src/port/emscripten.cpp

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// SuperTux
2+
// Copyright (C) 2021 A. Semphris <[email protected]>
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "port/emscripten.hpp"
18+
19+
#ifdef __EMSCRIPTEN__
20+
21+
extern "C" {
22+
23+
EMSCRIPTEN_KEEPALIVE // This is probably not useful, I just want ppl to know it exists
24+
void
25+
set_resolution(int w, int h)
26+
{
27+
VideoSystem::current()->on_resize(w, h);
28+
MenuManager::instance().on_window_resize();
29+
}
30+
31+
EMSCRIPTEN_KEEPALIVE // Same as above
32+
void
33+
save_config()
34+
{
35+
g_config->save();
36+
}
37+
38+
void
39+
onDownloadProgress(int id, int loaded, int total)
40+
{
41+
AddonManager::current()->onDownloadProgress(id, loaded, total);
42+
}
43+
44+
void
45+
onDownloadFinished(int id)
46+
{
47+
AddonManager::current()->onDownloadFinished(id);
48+
}
49+
50+
void
51+
onDownloadError(int id)
52+
{
53+
AddonManager::current()->onDownloadError(id);
54+
}
55+
56+
void
57+
onDownloadAborted(int id)
58+
{
59+
AddonManager::current()->onDownloadAborted(id);
60+
}
61+
62+
const char*
63+
getExceptionMessage(intptr_t address)
64+
{
65+
return reinterpret_cast<std::exception*>(address)->what();
66+
}
67+
68+
} // extern "C"
69+
70+
void
71+
init_emscripten()
72+
{
73+
EM_ASM({
74+
if (window.supertux_onready)
75+
window.supertux_onready();
76+
}, 0); // EM_ASM is a variadic macro and Clang requires at least 1 value for the variadic argument
77+
}
78+
79+
#endif

0 commit comments

Comments
 (0)