Skip to content

Commit 4266aaa

Browse files
committed
Add threading for web version
1 parent 2290f3f commit 4266aaa

6 files changed

Lines changed: 25 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ project ("complex-plotter")
55
set(CMAKE_CXX_STANDARD 20)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8+
if (EMSCRIPTEN)
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
10+
endif()
11+
812
if (MSVC)
913
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
1014
endif()

src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,20 @@ if(EMSCRIPTEN)
103103
-sALLOW_MEMORY_GROWTH=1
104104
-fexceptions
105105
-sASSERTIONS=1
106-
-sEXPORTED_RUNTIME_METHODS=[ccall])
106+
-sEXPORTED_RUNTIME_METHODS=[ccall]
107+
-pthread
108+
-sUSE_PTHREADS=1
109+
-sPTHREAD_POOL_SIZE=8
110+
)
107111
target_compile_options(complex-plotter PRIVATE "-s" "USE_GLFW=3" "-fexceptions")
108112
set_target_properties(complex-plotter PROPERTIES SUFFIX ".js")
109113
add_custom_command(TARGET complex-plotter POST_BUILD
110114
COMMAND ${CMAKE_COMMAND} -E copy
111115
"${CMAKE_CURRENT_SOURCE_DIR}/index.html"
112116
"${CMAKE_CURRENT_BINARY_DIR}/index.html"
117+
COMMAND ${CMAKE_COMMAND} -E copy
118+
"${CMAKE_CURRENT_SOURCE_DIR}/coi-serviceworker.min.js"
119+
"${CMAKE_CURRENT_BINARY_DIR}/coi-serviceworker.min.js"
113120
COMMENT "Copying custom index.html to build directory..."
114121
)
115122
endif()

src/coi-serviceworker.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/graphics/ui.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,18 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
400400
}
401401
if (UI::CollapsingHeader("Arbitrary Precision Mode")) {
402402
ImGui::TextWrapped("Renders the current view using CPU-based arbitrary precision math. Required for extreme zoom levels.");
403+
#ifdef __EMSCRIPTEN__
404+
ImGui::TextDisabled("This feature is best suited for the desktop version.");
405+
#endif
403406
ImGui::Spacing();
404407

405408
static std::string ui_shift_x = "0.0";
406409
static std::string ui_shift_y = "0.0";
407410
static std::string ui_range = "4.0";
408411

409412
if (UI::Button("Configure Deep Render")) {
410-
view_state.hp_width = 700;
411-
view_state.hp_height = 700;
413+
view_state.hp_width = 600;
414+
view_state.hp_height = 600;
412415
ui_range = std::to_string(view_state.range);
413416
ui_shift_x = std::to_string(view_state.shift.x);
414417
ui_shift_y = std::to_string(view_state.shift.y);

src/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4+
<script src="coi-serviceworker.min.js"></script>
45
<meta charset="UTF-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1.0">
67
<title>Complex Plotter</title>
@@ -55,7 +56,7 @@
5556

5657
<div id="loading-overlay">
5758
<div class="spinner"></div>
58-
<h2>Loading!...</h2>
59+
<h2>Loading...</h2>
5960
</div>
6061

6162
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>

src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ unsigned int stack_tbo_buffer, stack_tbo_texture;
5353
unsigned int constants_tbo_buffer, constants_tbo_texture;
5454

5555

56+
5657
struct AppContext {
5758
GLFWwindow* window;
5859
ViewState* view_state;
@@ -211,7 +212,9 @@ void main_loop_step(AppContext* ctx) {
211212
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
212213
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
213214
}
214-
int user_thread_limit = 8;
215+
int user_thread_limit = 16;
216+
217+
215218

216219
std::fill(ctx->view_state->hp_cpu_buffer.begin(), ctx->view_state->hp_cpu_buffer.end(), 30);
217220

0 commit comments

Comments
 (0)