Skip to content

Commit

Permalink
Fix even more build issues
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Semphris committed Jun 17, 2024
1 parent 390137b commit 42c777c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 17 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ include(ExternalProject)
include(CheckCXXCompilerFlag)
include(CheckSymbolExists)

option(SUPERTUX_IPO "Use interprocedural optimisation (Takes more RAM at compilation, gives smaller and faster builds)" ON)
if(EMSCRIPTEN)
# 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)"
# Seems to be a known issue: https://github.com/emscripten-core/emscripten/issues/20275
option(SUPERTUX_IPO "Use interprocedural optimisation (Takes more RAM at compilation, gives smaller and faster builds)" OFF)
else()
option(SUPERTUX_IPO "Use interprocedural optimisation (Takes more RAM at compilation, gives smaller and faster builds)" ON)
endif()
if(SUPERTUX_IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT result)
Expand Down
28 changes: 12 additions & 16 deletions src/editor/scroller_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
#include "video/video_system.hpp"
#include "video/viewport.hpp"

namespace {

#ifdef _MSC_VER
#undef SIZE
#endif
namespace CONSTS {

const float TOPLEFT = 16;
const float MIDDLE = 48;
Expand All @@ -50,34 +46,34 @@ EditorScrollerWidget::EditorScrollerWidget(Editor& editor) :
bool
EditorScrollerWidget::can_scroll() const
{
return m_scrolling && m_mouse_pos.x < SIZE && m_mouse_pos.y < SIZE;
return m_scrolling && m_mouse_pos.x < CONSTS::SIZE && m_mouse_pos.y < CONSTS::SIZE;
}

void
EditorScrollerWidget::draw(DrawingContext& context)
{
if (!rendered) return;

context.color().draw_filled_rect(Rectf(Vector(0, 0), Vector(SIZE, SIZE)),
context.color().draw_filled_rect(Rectf(Vector(0, 0), Vector(CONSTS::SIZE, CONSTS::SIZE)),
Color(0.9f, 0.9f, 1.0f, 0.6f),
MIDDLE, LAYER_GUI-10);
CONSTS::MIDDLE, LAYER_GUI-10);
context.color().draw_filled_rect(Rectf(Vector(40, 40), Vector(56, 56)),
Color(0.9f, 0.9f, 1.0f, 0.6f),
8, LAYER_GUI-20);
if (can_scroll()) {
draw_arrow(context, m_mouse_pos);
}

draw_arrow(context, Vector(TOPLEFT, MIDDLE));
draw_arrow(context, Vector(BOTTOMRIGHT, MIDDLE));
draw_arrow(context, Vector(MIDDLE, TOPLEFT));
draw_arrow(context, Vector(MIDDLE, BOTTOMRIGHT));
draw_arrow(context, Vector(CONSTS::TOPLEFT, CONSTS::MIDDLE));
draw_arrow(context, Vector(CONSTS::BOTTOMRIGHT, CONSTS::MIDDLE));
draw_arrow(context, Vector(CONSTS::MIDDLE, CONSTS::TOPLEFT));
draw_arrow(context, Vector(CONSTS::MIDDLE, CONSTS::BOTTOMRIGHT));
}

void
EditorScrollerWidget::draw_arrow(DrawingContext& context, const Vector& pos)
{
Vector dir = pos - Vector(MIDDLE, MIDDLE);
Vector dir = pos - Vector(CONSTS::MIDDLE, CONSTS::MIDDLE);
if (dir.x != 0 || dir.y != 0) {
// draw a triangle
dir = glm::normalize(dir) * 8.0f;
Expand Down Expand Up @@ -109,7 +105,7 @@ EditorScrollerWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
if (button.button == SDL_BUTTON_LEFT) {
if (!rendered) return false;

if (m_mouse_pos.x < SIZE && m_mouse_pos.y < SIZE) {
if (m_mouse_pos.x < CONSTS::SIZE && m_mouse_pos.y < CONSTS::SIZE) {
m_scrolling = true;
return true;
} else {
Expand All @@ -126,8 +122,8 @@ EditorScrollerWidget::on_mouse_motion(const SDL_MouseMotionEvent& motion)
if (!rendered) return false;

m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(motion.x, motion.y);
if (m_mouse_pos.x < SIZE && m_mouse_pos.y < SIZE) {
m_scrolling_vec = m_mouse_pos - Vector(MIDDLE, MIDDLE);
if (m_mouse_pos.x < CONSTS::SIZE && m_mouse_pos.y < CONSTS::SIZE) {
m_scrolling_vec = m_mouse_pos - Vector(CONSTS::MIDDLE, CONSTS::MIDDLE);
if (m_scrolling_vec.x != 0 || m_scrolling_vec.y != 0) {
float norm = glm::length(m_scrolling_vec);
m_scrolling_vec *= powf(static_cast<float>(M_E), norm / 16.0f - 1.0f);
Expand Down
79 changes: 79 additions & 0 deletions src/port/emscripten.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SuperTux
// Copyright (C) 2021 A. Semphris <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "port/emscripten.hpp"

#ifdef __EMSCRIPTEN__

extern "C" {

EMSCRIPTEN_KEEPALIVE // This is probably not useful, I just want ppl to know it exists
void
set_resolution(int w, int h)
{
VideoSystem::current()->on_resize(w, h);
MenuManager::instance().on_window_resize();
}

EMSCRIPTEN_KEEPALIVE // Same as above
void
save_config()
{
g_config->save();
}

void
onDownloadProgress(int id, int loaded, int total)
{
AddonManager::current()->onDownloadProgress(id, loaded, total);
}

void
onDownloadFinished(int id)
{
AddonManager::current()->onDownloadFinished(id);
}

void
onDownloadError(int id)
{
AddonManager::current()->onDownloadError(id);
}

void
onDownloadAborted(int id)
{
AddonManager::current()->onDownloadAborted(id);
}

const char*
getExceptionMessage(intptr_t address)
{
return reinterpret_cast<std::exception*>(address)->what();
}

} // extern "C"

void
init_emscripten()
{
EM_ASM({
if (window.supertux_onready)
window.supertux_onready();
}, 0); // EM_ASM is a variadic macro and Clang requires at least 1 value for the variadic argument
}

#endif

0 comments on commit 42c777c

Please sign in to comment.