Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser WebAssembly Port #5106

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6309935
get all dependencies to build with emscripten
ading2210 May 28, 2024
73a33e0
allow cmake configuration to succeed
ading2210 May 28, 2024
0830eb1
fix sdl compile errors
ading2210 May 28, 2024
379f052
get it building and linking properly
ading2210 May 28, 2024
5a1d9a1
create html file for launching the game
ading2210 May 28, 2024
2a108ac
load game data from tar.gz file
ading2210 May 29, 2024
4a175e1
set compile flags for debug builds
ading2210 May 29, 2024
f1b1038
compile with exception support and bundle assets
ading2210 May 29, 2024
4da4be0
the game runs! still some webgl issues though
ading2210 May 30, 2024
d89050e
fix some scaling problems and re-enable controller support
ading2210 May 30, 2024
becfaa3
try to get gles3 working
ading2210 May 30, 2024
92635ab
add idb cache for data and assets
ading2210 May 30, 2024
59da74c
force legacy graphics for now
ading2210 May 30, 2024
0a9e828
working audio
ading2210 May 30, 2024
74e4f35
remove useless sleeps, add persistent config
ading2210 May 30, 2024
1e86e18
split assets into 20mb chunks
ading2210 May 30, 2024
ca123ec
Merge branch 'master' into wasm
ading2210 May 30, 2024
b8a53b9
add readme to wasm port
ading2210 May 30, 2024
bc45f60
new web interface and loading progress
ading2210 May 31, 2024
b16cb52
compress assets better
ading2210 Jun 26, 2024
885ee29
fix compilation issues on newest emsdk
ading2210 Sep 11, 2024
6d49afb
Merge branch 'master' into wasm (does not run yet)
ading2210 Sep 11, 2024
e50c523
fix crash with memory access out of bounds in tracks and gp screen
ading2210 Sep 11, 2024
5831bc4
Merge remote-tracking branch 'upstream/master' into wasm
ading2210 Dec 3, 2024
1e26980
Revert "fix crash with memory access out of bounds in tracks and gp s…
ading2210 Dec 3, 2024
06fee78
disable outdated opengl warning
ading2210 Dec 3, 2024
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ CMakeFiles/
stk-editor/
.vscode/
tags.*
wasm/build/
wasm/prefix/
wasm/emsdk/
wasm/web/game

# clangd
.cache/
Expand Down
61 changes: 58 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,62 @@ if(IOS)
include(cmake/XcodeHelper.cmake)
endif()

if(EMSCRIPTEN)
#note: cmake fails the first few times you run it then works fine without changing anything
#i have no idea why this happens

set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/wasm/prefix/")

set(JPEG_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include")
set(JPEG_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libjpeg.a")

set(PNG_PNG_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include/")
set(PNG_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libpng16.a")

set(ZLIB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include")
set(ZLIB_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libz.a")

set(HARFBUZZ_INCLUDEDIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include/")
set(HARFBUZZ_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libharfbuzz.a")

set(CURL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include/")
set(CURL_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libcurl.a")

set(OPENSSL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include/")
set(OPENSSL_CRYPTO_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libssl.a")

set(OGGVORBIS_OGG_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include/")
set(OGGVORBIS_VORBIS_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/wasm/prefix/include/")
set(OGGVORBIS_OGG_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libogg.a")
set(OGGVORBIS_VORBISFILE_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libvorbisfile.a")
set(OGGVORBIS_VORBIS_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/prefix/lib/libvorbis.a")

set(PTHREAD_LIBRARY "${CMAKE_SOURCE_DIR}/wasm/emsdk/upstream")

set(USE_WIIUSE 0)
set(USE_DNS_C 1)
set(USE_GLES2 1)
set(NO_SHADERC on)
add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
add_definitions(-DNO_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
add_definitions(-DNO_IRR_COMPILE_WITH_DIRECT3D_9_)
add_definitions(-DNO_IRR_COMPILE_WITH_VULKAN_)
add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
add_definitions(-D_IRR_COMPILE_WITH_OGLES2_)
add_definitions(-DDISABLE_RPC)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -sUSE_SDL=2 -fwasm-exceptions -sSUPPORT_LONGJMP=wasm -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -sUSE_SDL=2 -fwasm-exceptions -sSUPPORT_LONGJMP=wasm -pthread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_SOURCE_DIR}/wasm/prefix/lib/ -sENVIRONMENT=web,worker -lidbfs.js -lwebsocket.js -sASSERTIONS=1 -sSTACK_SIZE=30000000 -sMIN_WEBGL_VERSION=2 -sFULL_ES2 -sFULL_ES3 -sGL_FFP_ONLY -sUSE_SDL_MIXER=2 -lopenal -sINITIAL_MEMORY=768MB -sWASM_BIGINT -lcrypto -fwasm-exceptions")

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --profiling")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()

endif()

if(APPLE AND NOT IOS)
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
set(ARCHFLAGS "arm64")
Expand Down Expand Up @@ -331,7 +387,7 @@ else()
MESSAGE(STATUS "Use system libmcpp: ${MCPP_LIBRARY}")
endif()

if (NOT SERVER_ONLY)
if (NOT SERVER_ONLY AND NOT EMSCRIPTEN)
# SDL2
find_library(SDL2_LIBRARY NAMES SDL2 libSDL2)
find_path(SDL2_INCLUDEDIR NAMES SDL.h PATH_SUFFIXES SDL2 include/SDL2 include PATHS)
Expand Down Expand Up @@ -633,7 +689,7 @@ int main() {
return 0;
}
" NO_LIBATOMIC_NEEDED)
if (NOT NO_LIBATOMIC_NEEDED)
if (NOT NO_LIBATOMIC_NEEDED AND NOT EMSCRIPTEN)
target_link_libraries(supertuxkart atomic)
endif()

Expand Down Expand Up @@ -866,7 +922,6 @@ if(MINGW)
endif()
endif()


# Find LibGamerzilla library or build it if missing
if (NOT APPLE)
include(FindPkgConfig)
Expand Down
4 changes: 3 additions & 1 deletion lib/angelscript/projects/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ endif()

# Don't override the default library output path to avoid conflicts when building for multiple target platforms
#set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../lib)
target_link_libraries(${ANGELSCRIPT_LIBRARY_NAME} Threads::Threads)
if(NOT EMSCRIPTEN)
target_link_libraries(${ANGELSCRIPT_LIBRARY_NAME} Threads::Threads)
endif()

set_target_properties(${ANGELSCRIPT_LIBRARY_NAME} PROPERTIES VERSION ${PROJECT_VERSION})

Expand Down
2 changes: 1 addition & 1 deletion lib/enet/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <poll.h>
#endif

#ifndef HAS_SOCKLEN_T
#if !defined(HAS_SOCKLEN_T) && !defined(__EMSCRIPTEN__)
typedef int socklen_t;
#endif

Expand Down
10 changes: 6 additions & 4 deletions lib/graphics_engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ include_directories("${PROJECT_SOURCE_DIR}/lib/graphics_utils")
include_directories("${PROJECT_SOURCE_DIR}/lib/irrlicht/include")
include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
find_path(SDL2_INCLUDEDIR NAMES SDL.h PATH_SUFFIXES SDL2 include/SDL2 include PATHS)
if (NOT SDL2_INCLUDEDIR)
message(FATAL_ERROR "SDL2 not found.")
else()
include_directories("${SDL2_INCLUDEDIR}")
if (NOT EMSCRIPTEN)
if (NOT SDL2_INCLUDEDIR)
message(FATAL_ERROR "SDL2 not found.")
else()
include_directories("${SDL2_INCLUDEDIR}")
endif()
endif()

if(APPLE AND NOT DLOPEN_MOLTENVK)
Expand Down
4 changes: 4 additions & 0 deletions lib/graphics_engine/include/ge_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ namespace irr

namespace GE
{
#ifdef _IRR_COMPILE_WITH_VULKAN_
class GEVulkanDriver;
#endif
struct GEConfig
{
bool m_disable_npot_texture;
Expand All @@ -34,7 +36,9 @@ float m_render_scale;
void setVideoDriver(irr::video::IVideoDriver* driver);
void setShaderFolder(const std::string& path);
irr::video::IVideoDriver* getDriver();
#ifdef _IRR_COMPILE_WITH_VULKAN_
GE::GEVulkanDriver* getVKDriver();
#endif
const std::string& getShaderFolder();
GEConfig* getGEConfig();
void deinit();
Expand Down
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_compressor_astc_4x4.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_compressor_astc_4x4.hpp"

#include "ge_main.hpp"
Expand Down Expand Up @@ -135,3 +137,5 @@ GECompressorASTC4x4::GECompressorASTC4x4(uint8_t* texture, unsigned channels,
} // GECompressorASTC4x4

}

#endif
2 changes: 2 additions & 0 deletions lib/graphics_engine/src/ge_gl_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ GEGLTexture::GEGLTexture(const std::string& name, unsigned int size,
m_size = m_orig_size;

bool texture_swizzle = false;
#ifndef __EMSCRIPTEN__
if (m_driver_type == video::EDT_OGLES2)
{
int gl_major_version = 0;
Expand All @@ -74,6 +75,7 @@ GEGLTexture::GEGLTexture(const std::string& name, unsigned int size,
texture_swizzle = irr::video::useCoreContext &&
GE::hasGLExtension("GL_ARB_texture_swizzle");
}
#endif

if (single_channel && texture_swizzle)
m_single_channel = true;
Expand Down
6 changes: 6 additions & 0 deletions lib/graphics_engine/src/ge_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ irr::video::IVideoDriver* getDriver()
return g_driver;
}

#ifdef _IRR_COMPILE_WITH_VULKAN_
GE::GEVulkanDriver* getVKDriver()
{
return dynamic_cast<GE::GEVulkanDriver*>(g_driver);
}
#endif

GEConfig* getGEConfig()
{
Expand Down Expand Up @@ -133,6 +135,8 @@ void mathPlaneFrustumf(float* out, const irr::core::matrix4& pvm)
mathPlaneNormf(&out[5 * 4]);
}

#ifdef _IRR_COMPILE_WITH_VULKAN_

irr::scene::IAnimatedMesh* convertIrrlichtMeshToSPM(irr::scene::IMesh* mesh)
{
GESPM* spm = new GESPM();
Expand Down Expand Up @@ -172,5 +176,7 @@ irr::scene::IAnimatedMesh* convertIrrlichtMeshToSPM(irr::scene::IMesh* mesh)
spm->finalize();
return spm;
}
#endif

}

4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_spm_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_spm_buffer.hpp"

#include "ge_main.hpp"
Expand Down Expand Up @@ -117,3 +119,5 @@ void GESPMBuffer::setTCoords(u32 i, const core::vector2df& tcoords)
} // setTCoords

}

#endif
6 changes: 6 additions & 0 deletions lib/graphics_engine/src/ge_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ irr::video::ITexture* createTexture(const std::string& path,
case video::EDT_DIRECT3D9:
return new GEDX9Texture(path, image_mani);
#endif
#ifdef _IRR_COMPILE_WITH_VULKAN_
case video::EDT_VULKAN:
return new GEVulkanTexture(path, image_mani);
#endif
default:
return NULL;
}
Expand All @@ -121,8 +123,10 @@ irr::video::ITexture* createTexture(video::IImage* img,
case video::EDT_DIRECT3D9:
return new GEDX9Texture(img, name);
#endif
#ifdef _IRR_COMPILE_WITH_VULKAN_
case video::EDT_VULKAN:
return new GEVulkanTexture(img, name);
#endif
default:
return NULL;
}
Expand All @@ -141,8 +145,10 @@ irr::video::ITexture* createFontTexture(const std::string& name,
case video::EDT_DIRECT3D9:
return new GEDX9Texture(name, size);
#endif
#ifdef _IRR_COMPILE_WITH_VULKAN_
case video::EDT_VULKAN:
return new GEVulkanTexture(name, size, single_channel);
#endif
default:
return NULL;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_2d_renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_2d_renderer.hpp"

#include "ge_main.hpp"
Expand Down Expand Up @@ -439,3 +441,5 @@ void GEVulkan2dRenderer::addVerticesIndices(irr::video::S3DVertex* vertices,
} // addVerticesIndices

}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_array_texture.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_array_texture.hpp"

#include "ge_main.hpp"
Expand Down Expand Up @@ -259,3 +261,5 @@ void GEVulkanArrayTexture::reloadInternal(const std::vector<io::path>& list,
} // reloadInternal

}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_billboard_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_billboard_buffer.hpp"

#include "ge_main.hpp"
Expand All @@ -15,3 +17,5 @@ GEVulkanBillboardBuffer::GEVulkanBillboardBuffer(
} // GEVulkanBillboardBuffer

}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_camera_scene_node.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_camera_scene_node.hpp"

#include "ge_main.hpp"
Expand Down Expand Up @@ -68,3 +70,5 @@ irr::core::matrix4 GEVulkanCameraSceneNode::getPVM() const
} // getPVM

}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_command_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_command_loader.hpp"

#include "ge_vulkan_driver.hpp"
Expand Down Expand Up @@ -264,3 +266,5 @@ void GEVulkanCommandLoader::waitIdle()
} // waitIdle

}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_depth_texture.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include <stdexcept>

#include "ge_vulkan_depth_texture.hpp"
Expand Down Expand Up @@ -39,3 +41,5 @@ GEVulkanDepthTexture::GEVulkanDepthTexture(GEVulkanDriver* vk,
} // GEVulkanDepthTexture

}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_draw_call.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_draw_call.hpp"

#include "ge_culling_tool.hpp"
Expand Down Expand Up @@ -1769,3 +1771,5 @@ void GEVulkanDrawCall::updateDataDescriptorSets(GEVulkanDriver* vk)
}
} // updateDataDescriptor
}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_driver.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_driver.hpp"

#include "ge_compressor_astc_4x4.hpp"
Expand Down Expand Up @@ -2641,3 +2643,5 @@ extern "C" JNIEXPORT void JNICALL pauseRenderingJNI(JNIEnv* env, jclass cls)
#endif

#endif

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_dynamic_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_dynamic_buffer.hpp"

#include "ge_vulkan_driver.hpp"
Expand Down Expand Up @@ -222,3 +224,5 @@ VkBuffer GEVulkanDynamicBuffer::getCurrentBuffer() const
} // getCurrentBuffer

}

#endif
4 changes: 4 additions & 0 deletions lib/graphics_engine/src/ge_vulkan_dynamic_spm_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_

#include "ge_vulkan_dynamic_spm_buffer.hpp"

#include "ge_main.hpp"
Expand Down Expand Up @@ -130,3 +132,5 @@ void GEVulkanDynamicSPMBuffer::setDirtyOffset(irr::u32 offset,
} // setDirtyOffset

} // end namespace GE

#endif
Loading