Skip to content

Commit

Permalink
demo: Add ldjam56
Browse files Browse the repository at this point in the history
In preparation for ldjam56, allocate a dedicated space for it. While at
it, get rid of the global and private asset repository and replace it
with ldjam56-local asset repository that's unburdened of legacy assets
of questionable licensing.

Signed-off-by: Alexander Shishkin <[email protected]>
  • Loading branch information
virtuoso committed Oct 4, 2024
1 parent 3b7f414 commit dd026fe
Show file tree
Hide file tree
Showing 8 changed files with 809 additions and 25 deletions.
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[submodule "ode"]
path = ode
url = [email protected]/virtuoso/ode.git
[submodule "asset"]
path = asset
url = [email protected]/virtuoso/clap-assets.git
branch = main
[submodule "demo/ldjam56/asset"]
path = demo/ldjam56/asset
url = [email protected]:virtuoso/ldjam56-asset.git
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ set(ODE_INCLUDE "${ODE_ROOT}/include")

# add_subdirectory(ode)
add_subdirectory(core)
add_subdirectory(demo/ldjam52)
# add_subdirectory(demo/ldjam52)
add_subdirectory(demo/ldjam56)

if (NOT (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten"))
add_subdirectory(tools/server)
Expand Down
1 change: 0 additions & 1 deletion asset
Submodule asset deleted from ac970f
20 changes: 1 addition & 19 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ cd compile-time
cmake -B build/rel -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build/rel
cd ..
mkdir -p asset/glsl
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/model
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/ui
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/glyph
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/contrast
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/hblur
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/vblur
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/debug
compile-time/build/rel/preprocess_shaders -t glsl -o asset/glsl/ shaders/terrain
mkdir -p asset/glsl-es
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/model
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/ui
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/glyph
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/contrast
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/hblur
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/vblur
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/debug
compile-time/build/rel/preprocess_shaders -t glsl-es -o asset/glsl-es/ shaders/terrain

cmake --build build/rel $VERBOSE $OPTS
cmake --build build/test $VERBOSE $OPTS
Expand All @@ -45,5 +27,5 @@ if [ -n "$www_dir" ]; then
fi

#cp build/emrel/core/onehandclap.{data,html,js,wasm} /var/www/html/cclap
build/debug/core/server --restart
build/debug/tools/server/server --restart

152 changes: 152 additions & 0 deletions demo/ldjam56/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
set(CMAKE_C_STANDARD 11)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

get_filename_component(PARENT_DIR ${clap_SOURCE_DIR} DIRECTORY)
set(ENGINE_INCLUDE "${PARENT_DIR}/clap/core" "${clap_BINARY_DIR}/core")
set(ASSET_DIR "${CMAKE_CURRENT_SOURCE_DIR}/asset")
message("### asset dir ${ASSET_DIR} include dir ${ENGINE_INCLUDE}")

get_directory_property(CONFIG_GLES
DIRECTORY "${CMAKE_SOURCE_DIR}/core"
DEFINITION CONFIG_GLES)
if (CONFIG_GLES)
set(SHADER_TYPE "glsl-es")
else ()
set(SHADER_TYPE "glsl")
endif ()

set(SHADER_DIR "${ASSET_DIR}/${SHADER_TYPE}")
set(SHADER_SOURCE_DIR "${PARENT_DIR}/clap/shaders")
set(SHADER_PREPROCESSOR "${PARENT_DIR}/clap/compile-time/build/rel/preprocess_shaders")
set(SHADERS "ui"
"glyph"
"model"
"contrast"
"debug"
"hblur"
"vblur"
"terrain"
)

add_custom_target(make-shader-output-dir
COMMAND ${CMAKE_COMMAND} -E make_directory "${SHADER_DIR}"
)

SET(SHADER_SRCS "")
SET(SHADER_OUTS "")
FOREACH(s ${SHADERS})
LIST(APPEND SHADER_SRCS "${SHADER_SOURCE_DIR}/${s}.vert" "${SHADER_SOURCE_DIR}/${s}.frag")
LIST(APPEND SHADER_OUTS "${SHADER_DIR}/${s}.vert" "${SHADER_DIR}/${s}.frag")
add_custom_command(
OUTPUT "${SHADER_DIR}/${s}.vert" "${SHADER_DIR}/${s}.frag"
DEPENDS make-shader-output-dir "${SHADER_SOURCE_DIR}/${s}.vert" "${SHADER_SOURCE_DIR}/${s}.frag"
COMMAND "${SHADER_PREPROCESSOR}"
ARGS -t ${SHADER_TYPE} -o ${SHADER_DIR}/ ${SHADER_SOURCE_DIR}/${s}
)
ENDFOREACH()

add_custom_target(preprocess_shaders
DEPENDS ${SHADER_OUTS}
COMMENT "Preprocessing shaders"
)

set(ASSETS "${SHADER_OUTS}"
"${ASSET_DIR}/scene.json")

message("### assets ${ASSETS}")

if ((${CMAKE_SYSTEM_NAME} MATCHES "Emscripten"))
set(FREETYPE_LIBRARIES "-s USE_FREETYPE=1")
set(PNG_LIBRARY "-s USE_LIBPNG=1")
set(VORBISFILE_LIBRARY "-s USE_VORBIS=1")
set(OPENGL_LIBRARIES "-s USE_WEBGL2=1 -s FULL_ES3=1")
set(EXTRA_LIBRARIES "-lidbfs.js"
"-s WASM=1"
"-s EXIT_RUNTIME=1"
"-s ALLOW_MEMORY_GROWTH"
"-s INITIAL_MEMORY=134217728"
# "-s INITIAL_MEMORY=536870912"
"-s MAX_WEBGL_VERSION=2"
"-s ASSERTIONS=1"
"-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$ccall"
"-s BINARYEN_EXTRA_PASSES=--one-caller-inline-max-function-size=19307"
# "-flto"
"--shell-file=${CMAKE_CURRENT_SOURCE_DIR}/shell_clap.html"
"--preload-file=${ASSET_DIR}@/asset"
# "--use-preload-cache"
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") # -flto
set(CMAKE_EXECUTABLE_SUFFIX ".html")
else ()
set(OpenGL_GL_PREFERENCE "LEGACY")
find_package(glfw3)
find_package(GLEW)
find_package(OpenGL)
find_package(PNG)
find_package(Freetype)
find_package(OpenAL)
find_library(VORBISFILE_LIBRARY
NAMES vorbisfile VorbisFile VORBISFILE
PATHS
ENV VORBISDIR
ENV OGGDIR
ENV SDLSOUNDDIR
ENV SDLDIR
/opt
PATH_SUFFIXES
lib
)
set(GLEW_LIBRARIES GLEW::GLEW)
# set(EXTRA_LIBRARIES m pthread stdc++)
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG_LIBRARIES "-fsanitize=address")
else ()
set(DEBUG_LIBRARIES "")
endif ()

message("### GLEW: ${GLEW_LIBRARIES}")

if ((${CMAKE_SYSTEM_NAME} MATCHES "Emscripten"))
set(ENGINE_BIN index) # because index.html
else ()
set(ENGINE_BIN ldjam56)
endif ()

set(ENGINE_MAIN onehandclap.c)
set(ENGINE_LIB libonehandclap)

add_executable(${ENGINE_BIN} ${ENGINE_MAIN})
add_dependencies(${ENGINE_BIN} ${ENGINE_LIB} meshoptimizer preprocess_shaders)
target_include_directories(${ENGINE_BIN} PRIVATE ${ENGINE_INCLUDE} ${ODE_INCLUDE})
set_target_properties(${ENGINE_BIN} PROPERTIES LINK_DEPENDS "${ASSETS}")
target_link_libraries(${ENGINE_BIN} ${FREETYPE_LIBRARIES} glfw ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES})
target_link_libraries(${ENGINE_BIN} ${PNG_LIBRARY} ${OPENAL_LIBRARY} ${VORBISFILE_LIBRARY})
target_link_libraries(${ENGINE_BIN} ${ODE_LIBRARY} meshoptimizer)
target_link_libraries(${ENGINE_BIN} ${EXTRA_LIBRARIES})
target_link_libraries(${ENGINE_BIN} ${ENGINE_LIB})

if ((${CMAKE_SYSTEM_NAME} MATCHES "Emscripten"))
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
install(TARGETS ${ENGINE_BIN} DESTINATION clapdbg)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.wasm DESTINATION clapdbg)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.data DESTINATION clapdbg)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.js DESTINATION clapdbg)
else ()
if (CLAP_BUILD_FINAL)
install(TARGETS ${ENGINE_BIN} DESTINATION clap)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.wasm DESTINATION clap)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.data DESTINATION clap)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.js DESTINATION clap)
else ()
install(TARGETS ${ENGINE_BIN} DESTINATION claptest)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.wasm DESTINATION claptest)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.data DESTINATION claptest)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ENGINE_BIN}.js DESTINATION claptest)
endif ()
endif ()
else ()
install(TARGETS ${ENGINE_BIN} DESTINATION bin)
endif ()
1 change: 1 addition & 0 deletions demo/ldjam56/asset
Submodule asset added at e43482
Loading

0 comments on commit dd026fe

Please sign in to comment.