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

The Big Refactor #583

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
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
17 changes: 13 additions & 4 deletions .github/workflows/build-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,24 @@ jobs:
id: build
run: |
${{ matrix.c }} ${{ matrix.cxx }} ${{ matrix.vulkan }} cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }}
cmake --build build --config ${{ matrix.configuration }} --target Engine Interop Samples Engine_Tests -j
cmake --build build --config ${{ matrix.configuration }} -j

- name: Test NovelRT - ${{ matrix.configuration }}
if: steps.build.outcome == 'success'
if: false && steps.build.outcome == 'success'
id: test
run: |
cd build/tests/NovelRT.Tests
ctest --output-on-failure -C ${{ matrix.configuration }}

- name: Install NovelRT - ${{ matrix.configuration }}
run: |
cmake --install build --prefix inst ${{ contains(matrix.configuration, 'Release') && '--strip' || '' }} --config ${{ matrix.configuration }}

- name: Upload Artifacts - ${{ matrix.configuration }}
uses: actions/upload-artifact@v3
with:
name: NovelRT_${{ matrix.os }}_${{ matrix.configuration }}
path: inst

Documentation:
name: Doxygen - Ubuntu
runs-on: ubuntu-latest
Expand Down
187 changes: 22 additions & 165 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,178 +5,35 @@ cmake_policy(SET CMP0083 NEW) # control generation of PIE
cmake_policy(SET CMP0091 NEW) # MSVC runtime library flags
cmake_policy(SET CMP0135 NEW) # ExternalProject_Add respects timestamps

# Hacky hack hack for Windows
# Needs to be set before project is called. -__-
# We require windows SDK version: v10.0.22621 due to the D3D12 enum values
# we want only being available from this version onwards.
if(WIN32)
set(CMAKE_SYSTEM_VERSION 10.0.22621.0)
endif()

project(NovelRT
VERSION 1.0.0 #MVP Version
DESCRIPTION "NovelRT game engine"
HOMEPAGE_URL "https://novelrt.dev"
LANGUAGES C CXX
VERSION 1.0.0
DESCRIPTION "NovelRT Game Engine"
HOMEPAGE_URL "https://novelrt.dev/"
LANGUAGES CXX
)

include(CheckPIESupported)
check_pie_supported()

#
# Set the proper backend target for NovelRT
#
set(NOVELRT_TARGET_OPTIONS "Win32" "Linux" "macOS")
set(NOVELRT_TARGET_OPTIONS "${NOVELRT_TARGET_OPTIONS}" CACHE INTERNAL "List of valid platforms for NovelRT")
if(NOT DEFINED NOVELRT_TARGET)
message(STATUS "No backend specified - setting default based on detected OS.")
if(WIN32)
set(NOVELRT_TARGET "Win32" CACHE STRING "")
elseif(APPLE)
set(NOVELRT_TARGET "macOS" CACHE STRING "")
elseif(UNIX)
set(NOVELRT_TARGET "Linux" CACHE STRING "")
else()
set(NOVELRT_TARGET "Unknown" CACHE STRING "")
endif()
endif()

#
# Prepend so that our FindVulkan gets picked up first when needed
#
list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

#
# Defining options
#
option(NOVELRT_FETCH_DEPENDENCIES "Fetch and build NovelRT dependencies instead of providing system-based ones" ON)
option(NOVELRT_BUILD_SAMPLES "Build NovelRT samples" ON)
option(NOVELRT_BUILD_DOCUMENTATION "Build NovelRT documentation" OFF)
option(NOVELRT_BUILD_TESTS "Build NovelRT tests" ON)
option(NOVELRT_BUILD_INTEROP "Build NovelRT's Interop library" ON)
option(NOVELRT_VERBOSE_BUILD "Build NovelRT using verbose output" OFF)
option(NOVELRT_INSTALL "Generate installation targets" ON)
option(NOVELRT_USE_STD_SPAN "Alias \"NovelRT::Utilities::Misc:Span\" to \"std::span\" instead of \"gsl::span\"." OFF)
option(NOVELRT_BUILD_DEPS_WITH_MAX_CPU "Use all available CPU processing power when scaffolding/building the NovelRT internal dependences" OFF)

#
# Dependency Version Constraints
#
set(NOVELRT_DOXYGEN_VERSION "1.8.17" CACHE STRING "Doxygen version")
set(NOVELRT_FLAC_VERSION "1.3.4" CACHE STRING "FLAC version")
set(NOVELRT_GLFW_VERSION "3.3.7" CACHE STRING "GLFW3 version")
set(NOVELRT_GSL_VERSION "4.0.0" CACHE STRING "Microsoft.GSL version")
set(NOVELRT_ONETBB_VERSION "2021.5.0" CACHE STRING "OneTBB version")
set(NOVELRT_OPENAL_VERSION "1.21.1" CACHE STRING "OpenAL version")
set(NOVELRT_OGG_VERSION "1.3.5" CACHE STRING "Ogg version")
set(NOVELRT_OPUS_VERSION "1.3.1" CACHE STRING "Opus version")
set(NOVELRT_PNG_VERSION "1.6.35" CACHE STRING "PNG version")
set(NOVELRT_SNDFILE_VERSION "1.1.0" CACHE STRING "SndFile version")
set(NOVELRT_SPDLOG_VERSION "1.10.0" CACHE STRING "spdlog version")
set(NOVELRT_VORBIS_VERSION "1.3.7" CACHE STRING "Vorbis version")
set(NOVELRT_VULKAN_VERSION "1.3.231" CACHE STRING "Vulkan version")

#
# Alias "NovelRT::Utilities::Misc:Span" to "std::span" instead of "gsl::span".
# If enabled, you need to make sure you current configuration supports "std::span".
#
if(NOVELRT_USE_STD_SPAN)
add_compile_definitions(NOVELRT_USE_STD_SPAN=true)
endif()

#
# Setup Debug Output
#
if(NOVELRT_VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(VERBOSE TRUE)
message(VERBOSE "NovelRT - Target Link Libs:")
message(VERBOSE ${NOVELRT_ENGINE_LINK_LIBS})
message(VERBOSE "NovelRT - Target Compile Definitions:")
message(VERBOSE ${NOVELRT_TARGET_COMPILE_DEFS})
message(VERBOSE "NovelRT - Target Compile Options:")
message(VERBOSE ${NOVELRT_TARGET_COMPILE_OPTIONS})
endif()


#
# Documentation Generation target
#
if(NOVELRT_BUILD_DOCUMENTATION)
find_package(Doxygen ${NOVELRT_DOXYGEN_VERSION}
COMPONENTS dot
)
if(DOXYGEN_FOUND)
add_subdirectory(doxygen)
endif()
endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

find_package(Vulkan ${NOVElRT_VULKAN_VERSION} REQUIRED
OPTIONAL_COMPONENTS MoltenVK)
if(APPLE AND NOT Vulkan_MoltenVK_FOUND)
message(SEND_ERROR "Could not find MoltenVK, which is required for graphics support")
endif()

#
# Add subdirectories
#
add_subdirectory(thirdparty)
add_subdirectory(resources)
add_subdirectory(src)

if(NOVELRT_BUILD_SAMPLES)
add_subdirectory(samples)
endif()

if(NOVELRT_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()


#
# Install files other than the libraries themselves
# Targets' CMakeLists contains respective installations
#
if(NOVELRT_INSTALL)
install(
EXPORT NovelRT
EXPORT_LINK_INTERFACE_LIBRARIES
NAMESPACE NovelRT::
DESTINATION lib
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/NovelRTConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)

#Moved to main CMakeLists as headers should always be distributed for now
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/NovelRT/
DESTINATION include/NovelRT
FILES_MATCHING PATTERN "*.h"
)
list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

if(NOVELRT_BUILD_INTEROP)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/NovelRT.Interop/
DESTINATION include/NovelRT.Interop
FILES_MATCHING PATTERN "*.h"
)
endif()
enable_testing()
add_subdirectory(core)

if(NOVELRT_DEPS_INSTALLED)
install(
DIRECTORY ${NOVELRT_DEPS_PATH}/lib/
DESTINATION lib
PATTERN "*gtest*" EXCLUDE
)
install(
DIRECTORY ${NOVELRT_DEPS_PATH}/include/
DESTINATION include
PATTERN "gtest" EXCLUDE
)
install(
DIRECTORY ${NOVELRT_DEPS_PATH}/share/
DESTINATION share
PATTERN "doc" EXCLUDE
PATTERN "man" EXCLUDE
)
endif()
endif()
install(
EXPORT NovelRTConfig
NAMESPACE NovelRT::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/NovelRT
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/NovelRTConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/NovelRT
)
61 changes: 61 additions & 0 deletions cmake/GenerateCombinedHeader.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
set(_gch_default_file_template "${CMAKE_CURRENT_LIST_DIR}/GenerateCombinedHeader.h.in" CACHE INTERNAL "")

function(generate_combined_header)
cmake_parse_arguments(
PARSE_ARGV 0
_gch
"INSTALL"
"TARGET;FILE_NAME;FILE_TEMPLATE;DESTINATION"
"HEADER_SETS"
)

if(NOT _gch_FILE_NAME)
set(_gch_FILE_NAME "$<TARGET_NAME:${_gch_TARGET}>.hpp")
endif()

if(NOT _gch_FILE_TEMPLATE)
set(_gch_FILE_TEMPLATE "${_gch_default_file_template}")
endif()

foreach(_set IN LISTS _gch_HEADER_SETS)
get_target_property(_basedirs ${_gch_TARGET} "HEADER_DIRS_${_set}")
get_target_property(_files ${_gch_TARGET} "HEADER_SET_${_set}")
foreach(_file IN LISTS _files)
set(_relpath "${_file}")
foreach(_dir IN LISTS _basedirs)
file(RELATIVE_PATH _test "${_dir}" "${_file}")
string(LENGTH "${_test}" _testlen)
string(LENGTH "${_relpath}" _rellen)
if(_testlen LESS _rellen)
set(_relpath "${_test}")
endif()
endforeach()
list(APPEND _include_snippets "#include <${_relpath}>")
endforeach()
endforeach()

string(MAKE_C_IDENTIFIER "${_gch_FILE_NAME}" _macro)
string(TOUPPER "${_macro}" _macro)
list(JOIN _include_snippets "\n" _include_snippet)

set(GENERATE_COMBINED_HEADER_INCLUDE_GUARD "#ifndef ${_macro}\n#define ${_macro}")
set(GENERATE_COMBINED_HEADER_INCLUDE_GUARD_END "#endif // !${_macro}")
set(GENERATE_COMBINED_HEADER_INCLUDES "${_include_snippet}")

configure_file(
"${_gch_FILE_TEMPLATE}"
"${_gch_FILE_NAME}.in"
)
file(GENERATE
OUTPUT "${_gch_FILE_NAME}"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/${_gch_FILE_NAME}.in"
TARGET "${_gch_TARGET}"
)

if(_gch_INSTALL)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${_gch_FILE_NAME}"
DESTINATION "${_gch_DESTINATION}"
)
endif()
endfunction()
5 changes: 5 additions & 0 deletions cmake/GenerateCombinedHeader.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@GENERATE_COMBINED_HEADER_INCLUDE_GUARD@

@GENERATE_COMBINED_HEADER_INCLUDES@

@GENERATE_COMBINED_HEADER_INCLUDE_GUARD_END@
6 changes: 6 additions & 0 deletions common/CombinedHeader.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

@GENERATE_COMBINED_HEADER_INCLUDES@
14 changes: 5 additions & 9 deletions src/NovelRT/Atom.cpp → core/Atom.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#include <NovelRT/Atom.h>
#ifndef __TBB_PREVIEW_MUTEXES
#define __TBB_PREVIEW_MUTEXES 1
#endif
#include <NovelRT/Exceptions/Exceptions.h>
#include <mutex>
#include <oneapi/tbb/mutex.h>
#include <unordered_map>

#include <NovelRT/Core/Atom.hpp>
#include <NovelRT/Core/Exceptions/InvalidOperationException.hpp>

namespace NovelRT
{

Atom Atom::GetNextEcsPrimitiveInfoConfigurationId() noexcept
{
static std::atomic_uintptr_t _nextEcsPrimitiveInfoConfigurationId(0);
Expand Down Expand Up @@ -76,9 +72,9 @@ namespace NovelRT

AtomFactory& AtomFactoryDatabase::GetFactory(const std::string& factoryName) noexcept
{
static tbb::mutex _mutex;
//static tbb::mutex _mutex;
static std::unordered_map<std::string, AtomFactory> _factories;
std::scoped_lock lock(_mutex);
//std::scoped_lock lock(_mutex);
auto it = _factories.find(factoryName);

if (it == _factories.end())
Expand Down
Loading