Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Git checkout
uses: actions/checkout@v3
with:
submodules: 'true'
submodules: 'recursive'

- name: run-vcpkg
uses: lukka/run-vcpkg@v11.5
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Git checkout
uses: actions/checkout@v3
with:
submodules: 'true'
submodules: 'recursive'

- name: run-vcpkg
uses: lukka/run-vcpkg@v11.5
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "vendor/imguizmo"]
path = vendor/imguizmo
url = https://github.com/CedricGuillemet/ImGuizmo.git
[submodule "vendor/bgfx"]
path = vendor/bgfx
url = https://github.com/bkaradzic/bgfx.cmake.git
107 changes: 88 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,68 @@
cmake_minimum_required(VERSION 3.18)
project(schism)

option(GLFW_BUILD_DOCS OFF)
option(GLFW_BUILD_EXAMPLES OFF)
option(GLFW_BUILD_TESTS OFF)
project(schism)
# set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)

option(ENABLE_SANITIZER "Enable ASAN/LSAN/UBSAN." OFF)
option(ENABLE_SANITIZER_THREAD "Enable TSAN ()." OFF)
option(USE_CPPCHECK "Enable cppcheck, must have cppcheck in the PATH")
option(USE_CPPCHECK "Enable cppcheck, must have cppcheck in the PATH" OFF)
option(INCLUDE_WARNING "Include all the warning from the compiler")

# Hardcode the architecture to arm64 on macOS
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message("MacOs detected")

set(MACOSX TRUE)
set(CMAKE_OSX_ARCHITECTURES "arm64")
add_compile_definitions(SCHISM_PLATFORM_MAC)

add_compile_definitions(
SCHISM_PLATFORM_MAC
GLFW_EXPOSE_NATIVE_COCOA
GLFW_EXPOSE_NATIVE_NSGL
)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_compile_definitions(SCHISM_PLATFORM_WIN)
message("Windows detected")

add_compile_definitions(
SCHISM_PLATFORM_WINDOWS
GLFW_EXPOSE_NATIVE_WIN32
GLFW_EXPOSE_NATIVE_WGL
)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
message("Linux detected")
add_compile_definitions(SCHISM_PLATFORM_LINUX)

if (NOT DEFINED ENV{XDG_SESSION_TYPE})
# default to x11 if we cannot find the session type
# this is mainly done so it can build in git actions
message("Didn't detect the session type")
add_compile_definitions(
SCHISM_LINUX_X11
GLFW_EXPOSE_NATIVE_X11
GLFW_EXPOSE_NATIVE_GLX
)
elseif ($ENV{XDG_SESSION_TYPE} STREQUAL "x11")
message("X11 deteced, building for x11")
set(GLFW_BUILD_X11 1)
add_compile_definitions(
SCHISM_LINUX_X11
GLFW_EXPOSE_NATIVE_X11
GLFW_EXPOSE_NATIVE_GLX
)
elseif ($ENV{XDG_SESSION_TYPE} STREQUAL "wayland")
message("Wayland detected, building for wayland")
set(SCHISM_LINUX_WAYLAND 1)
set(GLFW_BUILD_WAYLAND 1)
set(BGFX_WITH_WAYLAND TRUE)
add_compile_definitions(
SCHISM_LINUX_WAYLAND
GLFW_EXPOSE_NATIVE_WAYLAND
WL_EGL_PLATFORM
)
list(APPEND VCPKG_MANIFEST_FEATURES "wayland")
else()
message("Cannot detect display protocol, linux")
endif()
endif()

if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
Expand All @@ -31,17 +76,20 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
set(USING_MSVC 1)
endif()

set(CMAKE_CXX_STANDARD 23)

# set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
# find_package(glfw3 CONFIG REQUIRED)
include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)

find_package(glfw3 CONFIG REQUIRED)
if (${GLFW_BUILD_WAYLAND})
message("BUILDING WAYLAND GLFW")
elseif (${GLFW_BUILD_X11})
message("BUILDING X11 GLFW")
endif()

find_package(EnTT CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(bgfx CONFIG REQUIRED)

# this is commented out because there is a bug in imguizmo version 1.83
# using it as a submodule
Expand All @@ -54,14 +102,20 @@ find_package(sol2 CONFIG REQUIRED)
find_package(lua REQUIRED)
find_path(PARALLEL_HASHMAP_INCLUDE_DIRS "parallel_hashmap/btree.h")

set(CMAKE_CXX_STANDARD 20)
add_subdirectory("vendor/bgfx")

if(${ENABLE_SANITIZER})
message("AddressSanitizer has been enabled")
add_compile_options(-fsanitize=address -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak)
if(ENABLE_SANITIZER_THREAD)
add_compile_options(-fsanitize=undefined -fno-sanitize=alignment -fsanitize=enum -fsanitize=thread)
endif()

link_libraries(
-fsanitize=address
-fno-sanitize=alignment -fsanitize=enum -fsanitize=leak
)

if(ENABLE_SANITIZER AND ENABLE_SANITIZER_THREAD)
message(FATAL_ERROR "ENABLE_SANITIZER and ENABLE_SANITIZER_THREAD can not be used together!")
endif()
Expand All @@ -72,7 +126,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(/W4)
elseif(USING_GCC)
add_compile_options(-fdiagnostics-color=always)
add_compile_options(-Wall -Wextra -Wpedantic -Weffc++)
# add_compile_options(-Wall -Wextra -Wpedantic -Weffc++)
elseif(USING_CLANGD)
add_compile_options(-Weverything)
add_compile_options(-fcolor-diagnostics)
Expand All @@ -83,7 +137,7 @@ else()
add_compile_definitions(SC_NODEBUG)
endif()

add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD USE_IMGUI_API)
add_compile_definitions(USE_IMGUI_API STB_IMAGE_IMPLEMENTATION)

include_directories(
vendor/json/include/
Expand All @@ -93,11 +147,12 @@ include_directories(
vendor/imguizmo/
${Stb_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
vendor/bgfx-imgui/
src/
)


file(GLOB GUIZMO_SOURCES vendor/imguizmo/*.cpp)
file(GLOB BGFX_IMGUI vendor/bgfx-imgui/*.cpp)
file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE HEADERS src/*.h)
file(GLOB_RECURSE RESOURCES res/*)
Expand All @@ -117,28 +172,42 @@ add_definitions(-DGLFW_INCLUDE_NONE
add_executable(${PROJECT_NAME}
${SOURCES}
${GUIZMO_SOURCES}
${BGFX_IMGUI}
${PROJECT_CONFIGS})

if (${SCHISM_LINUX_WAYLAND})
target_link_libraries(${PROJECT_NAME} PRIVATE wayland-egl)
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE
asio::asio
EnTT::EnTT
glad::glad
glfw
glm::glm
imgui::imgui
# this is becase the port on vcpkg has a bug so we use a submodule to get it
# imguizmo::imguizmo
OpenAL::OpenAL
spdlog::spdlog
sol2
${LUA_LIBRARIES}
bgfx::bx
bgfx::bgfx
bgfx::bimg
bgfx::bimg_decode
bx
bgfx
bimg
bimg_decode
)

target_include_directories(${PROJECT_NAME} PRIVATE ${PARALLEL_HASHMAP_INCLUDE_DIRS})

# this will have to be moved when we switch to c++ modules and also when
# we switch to different projects for the runtime and the editor
# for now leave it like this
# if we enable pre compiled headers there is a bug that happens with the definition of _OPTIMIZE
# spdlog or to be more exact defines _OPTIMIZE there and when stb image calls simd instructions
# it's selecting the wrong or let's say another function/macro definition that is unable to compiled
# very fucking interesting!
# target_precompile_headers(${PROJECT_NAME} PRIVATE "./src/schism/pch.h")

set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin/)

Expand Down
55 changes: 43 additions & 12 deletions cmake_build.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
#!/bin/bash

build_type="Debug"
refresh=false
rebuild=false
run=false

if [ $# -gt 0 ]; then
on_build_type () {
if echo "$1" | grep -qi "debug"; then
build_type="Debug"
elif echo "$1" | grep -qi "release"; then
build_type="Release"
elif [ "$1" == "--d" ]; then
elif [ "$1" == "-d" ]; then
build_type="Debug"
elif [ "$1" == "--r" ]; then
elif [ "$1" == "-r" ]; then
build_type="Release"
else
build_type="Debug"
fi
else
build_type="Debug"
}

handle_other_args () {
if echo "$1" | grep -qi "refresh"; then
refresh=true
fi

if echo "$1" | grep -qi "rebuild"; then
rebuild=true
fi

if echo "$1" | grep -qi "run"; then
run=true
fi
}

for arg in "$@"
do
on_build_type "$arg"
handle_other_args "$arg"
done

if [ "$rebuild" = true ]; then
rm -rf build
rm -rf bin
fi

if [ ! -d ./build ]; then
if [ ! -d ./build ] || [ "$refresh" = true ]; then
./cmake_generate.sh "$build_type"
fi

if cmake --build build -j $(nproc); then
if cmake --build build -j "$(nproc)"; then
./copy_res.sh
cd bin
./schism
cd ..

if [ $run = true ]; then
echo "Running with build type $build_type"
cd ./bin
./schism
cd ..
fi

else
echo BUILD FAILED
fi

5 changes: 3 additions & 2 deletions cmake_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ fi

# add cmake presets in the future
if [ "$build_type" == "Debug" ]; then
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE="$build_type" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_SANITIZER=1 -DUSE_CPPCHECK=0
cp ./build/compile_commands.json ./
if cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE="$build_type" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_SANITIZER=1 -DUSE_CPPCHECK=0; then
cp ./build/compile_commands.json ./
fi
else
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE="$build_type"
fi
Expand Down
4 changes: 4 additions & 0 deletions imgui.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400

3 changes: 1 addition & 2 deletions src/chess/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Game::Game(
m_State.gameId = e.gameId;
m_Engine.Reset();
});

ListenGameEvent<Net::SuccessfulMove>([this](Net::SuccessfulMove&& e) {
if (e.gameId != m_State.gameId) {
return; // todo:: Handle multiple games
Expand Down Expand Up @@ -143,4 +142,4 @@ void Game::DrawBoard() {
m_BoardRenderer.DrawBoard(m_Engine.GetBoardState(), !m_State.isWhite);
}

} // namespace Chess
} // namespace Chess
2 changes: 1 addition & 1 deletion src/chess/GameClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ void GameClient::HandleRead(size_t length) {
}
}
}
} // namespace Chess
} // namespace Chess
9 changes: 2 additions & 7 deletions src/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

#include <AL/al.h>
#include <AL/alc.h>
#include <chrono>
#include <filesystem>
#include <thread>
#include "chess/Chess.h"
#include "schism/Audio/Source.h"
#include "schism/Audio/WavLoader.h"
#include "schism/Sandbox/SampleScene.h"
#include "schism/System/Log.h"

Expand All @@ -30,11 +25,11 @@ Game::Game() : Application(800, 800, "Chess") {
m_SceneManager.Register<SampleScene>("sample scene");
// m_SceneManager.Register<Chess::Chess>("chess");

ALfloat listenerOri[] = {0.f, 0.f, 1.f, 0.f, 1.f, 0.f};
ALfloat listernetOrientation[] = {0.f, 0.f, 1.f, 0.f, 1.f, 0.f};

alListener3f(AL_POSITION, 0, 0, 1.f);
alListener3f(AL_VELOCITY, 0, 0, 0);
alListenerfv(AL_ORIENTATION, listenerOri);
alListenerfv(AL_ORIENTATION, listernetOrientation);
SC_CORE_INFO("Playing audio!");
m_Ctx->GlobalAssets.Audio.GetHandle("testaudio")->Play();
}
Expand Down
10 changes: 8 additions & 2 deletions src/schism/Audio/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ Source::Source(const std::vector<char>& data, std::uint32_t sampleRate,
}

Ref<Source> Source::Create(std::filesystem::path filePath) {
if (filePath.extension() != ".wav") {
SC_CORE_ERROR(
"At this point we only support wav audio format, unable to load {}",
filePath.string());
}

WavLoader wav(filePath);

if (!wav.Load()) {
SC_CORE_ERROR("Error creating audio source, with file: ",
SC_CORE_ERROR("Error creating audio source, with file: {}",
filePath.string());
return nullptr;
}
auto& header = wav.Header();
auto& data = wav.Data();
SC_CORE_INFO("Wav file loaded!");

return MakeRef<Source>(data, header.sampleRate, header.bitsPerSample,
header.channels);
}
Expand Down
Loading