Skip to content

Commit

Permalink
Move hash and noise functions into their own namespaces. Make vector …
Browse files Browse the repository at this point in the history
…and matrix compatible with the Container named requirements. Add more common math functions. Upgrade to CMake 3.28
  • Loading branch information
cjhoward committed Dec 9, 2023
1 parent 591ff8b commit 3d03231
Show file tree
Hide file tree
Showing 151 changed files with 6,609 additions and 5,589 deletions.
32 changes: 22 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds prohibited.")
endif()

cmake_minimum_required(VERSION 3.27)
cmake_minimum_required(VERSION 3.28)
include(FetchContent)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

Expand All @@ -30,16 +30,8 @@ if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

add_compile_definitions(
# Set minimum Windows version (Windows XP)
$<$<PLATFORM_ID:Windows>:
WINVER=0x0501
_WIN32_WINNT=0x0501
>
)

# Enable parallel building on MSVC
add_compile_options(
# Enable parallel building on MSVC
$<$<CXX_COMPILER_ID:MSVC>:/MP>
)

Expand All @@ -61,6 +53,7 @@ FetchContent_Declare(cxxopts
FetchContent_Declare(dr_libs
GIT_REPOSITORY https://github.com/mackron/dr_libs.git
GIT_TAG 9eed1be421749ba68a87e5b4c3b10858f8580689 # v0.13.13
GIT_SUBMODULES ""
)
FetchContent_Declare(entt
GIT_REPOSITORY https://github.com/skypjack/entt.git
Expand Down Expand Up @@ -272,6 +265,12 @@ file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS
EXCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/game/platform"
)

# Collect module files
# file(GLOB_RECURSE MODULE_FILES CONFIGURE_DEPENDS
# ${PROJECT_SOURCE_DIR}/src/*.ixx
# ${PROJECT_SOURCE_DIR}/src/*.cxx
# )

if(CMAKE_SYSTEM_NAME MATCHES "Windows")

# Collect Windows-specific source files
Expand Down Expand Up @@ -299,6 +298,12 @@ endif()
# Add executable target
add_executable(${PROJECT_NAME} ${SOURCE_FILES})

# Set executable module files
# target_sources(${PROJECT_NAME}
# PUBLIC
# FILE_SET CXX_MODULES FILES ${MODULE_FILES}
# )

# Set target properties
set_target_properties(${PROJECT_NAME}
PROPERTIES
Expand All @@ -308,6 +313,7 @@ set_target_properties(${PROJECT_NAME}
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)

# Set compile definitions
Expand All @@ -316,6 +322,12 @@ target_compile_definitions(${PROJECT_NAME}
$<$<NOT:$<CONFIG:Debug>>:N>DEBUG
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
_SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING

# Set minimum Windows version (Windows XP)
$<$<PLATFORM_ID:Windows>:
WINVER=0x0501
_WIN32_WINNT=0x0501
>
)

# Set compile options
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"cmakeMinimumRequired":
{
"major": 3,
"minor": 27,
"minor": 28,
"patch": 0
},
"configurePresets":
Expand Down
3 changes: 1 addition & 2 deletions src/engine/ai/navmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#include <engine/ai/navmesh.hpp>
#include <engine/geom/closest-point.hpp>
#include <engine/geom/coordinates.hpp>
#include <engine/math/vector.hpp>
#include <engine/math/quaternion.hpp>
#include <iterator>
#include <engine/debug/log.hpp>

namespace ai {

Expand Down
3 changes: 1 addition & 2 deletions src/engine/ai/navmesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#ifndef ANTKEEPER_AI_NAVMESH_HPP
#define ANTKEEPER_AI_NAVMESH_HPP

#include <engine/math/vector.hpp>
#include <engine/math/se3.hpp>
#include <engine/geom/brep/brep-mesh.hpp>
#include <engine/geom/primitives/point.hpp>
#include <engine/geom/primitives/ray.hpp>
#include <engine/geom/coordinates.hpp>
#include <vector>
#include <engine/math/vector.hpp>

namespace ai {

Expand Down
3 changes: 2 additions & 1 deletion src/engine/ai/steering/behavior/flee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include <engine/ai/steering/behavior/flee.hpp>
#include <engine/math/common.hpp>

namespace ai {
namespace steering {
Expand All @@ -15,7 +16,7 @@ math::fvec3 flee(const agent& agent, const math::fvec3& target)

if (sqr_distance)
{
const float inverse_distance = 1.0f / std::sqrt(sqr_distance);
const float inverse_distance = 1.0f / math::sqrt(sqr_distance);
force = difference * inverse_distance * agent.max_force;
force = agent.velocity - force;
}
Expand Down
3 changes: 2 additions & 1 deletion src/engine/ai/steering/behavior/seek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include <engine/ai/steering/behavior/seek.hpp>
#include <engine/math/common.hpp>

namespace ai {
namespace steering {
Expand All @@ -15,7 +16,7 @@ math::fvec3 seek(const agent& agent, const math::fvec3& target)

if (sqr_distance)
{
const float inverse_distance = 1.0f / std::sqrt(sqr_distance);
const float inverse_distance = 1.0f / math::sqrt(sqr_distance);
force = difference * inverse_distance * agent.max_force;
force -= agent.velocity;
}
Expand Down
17 changes: 9 additions & 8 deletions src/engine/ai/steering/behavior/wander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include <engine/ai/steering/behavior/wander.hpp>
#include <engine/ai/steering/behavior/seek.hpp>
#include <engine/math/random.hpp>
#include <array>
#include <engine/math/common.hpp>
#include <engine/math/quaternion.hpp>

namespace ai {
Expand All @@ -13,7 +14,7 @@ namespace behavior {
math::fvec3 wander_2d(const agent& agent, float noise, float distance, float radius, float& angle)
{
// Shift wander angle
angle += math::random(-noise, noise);
// angle += math::random(-noise, noise);

// Calculate center of wander circle
const math::fvec3 center = agent.position + agent.forward * distance;
Expand All @@ -31,19 +32,19 @@ math::fvec3 wander_2d(const agent& agent, float noise, float distance, float rad
math::fvec3 wander_3d(const agent& agent, float noise, float distance, float radius, float& theta, float& phi)
{
// Shift wander angles
theta += math::random(-noise, noise);
phi += math::random(-noise, noise);
// theta += math::random(-noise, noise);
// phi += math::random(-noise, noise);

// Calculate center of wander sphere
const math::fvec3 center = agent.position + agent.forward * distance;

// Convert spherical coordinates to Cartesian point on wander sphere
const float r_cos_theta = radius * std::cos(theta);
const float r_cos_theta = radius * math::cos(theta);
const math::fvec3 offset =
{
r_cos_theta * std::cos(phi),
r_cos_theta * std::sin(phi),
radius * std::sin(theta)
r_cos_theta * math::cos(phi),
r_cos_theta * math::sin(phi),
radius * math::sin(theta)
};

// Seek toward point on wander sphere
Expand Down
2 changes: 1 addition & 1 deletion src/engine/animation/animation-pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void animation_pose::reset()

relative_transform = rest_pose.get_relative_transform(bone_index);
m_absolute_transforms[bone_index] = rest_pose.get_absolute_transform(bone_index);
m_matrix_palette[bone_index] = bone_matrix_type::identity();
m_matrix_palette[bone_index] = math::identity<bone_matrix_type>;
}
);
}
2 changes: 1 addition & 1 deletion src/engine/animation/ease.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#ifndef ANTKEEPER_EASE_HPP
#define ANTKEEPER_EASE_HPP

#include <engine/math/interpolation.hpp>
#include <engine/math/common.hpp>
#include <cmath>

/**
Expand Down
2 changes: 1 addition & 1 deletion src/engine/animation/locomotion/gait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include <engine/animation/locomotion/gait.hpp>
#include <engine/math/fract.hpp>
#include <engine/math/common.hpp>
#include <cmath>

float gait::phase(float t) const noexcept
Expand Down
2 changes: 1 addition & 1 deletion src/engine/animation/locomotion/step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include <engine/animation/locomotion/step.hpp>
#include <engine/math/fract.hpp>
#include <engine/math/common.hpp>
#include <cmath>

float step::phase(float t) const noexcept
Expand Down
4 changes: 2 additions & 2 deletions src/engine/animation/pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

pose::pose(const skeleton& skeleton):
m_skeleton(&skeleton),
m_relative_transforms(skeleton.get_bone_count(), bone_transform_type::identity()),
m_absolute_transforms(skeleton.get_bone_count(), bone_transform_type::identity())
m_relative_transforms(skeleton.get_bone_count(), math::identity<bone_transform_type>),
m_absolute_transforms(skeleton.get_bone_count(), math::identity<bone_transform_type>)
{}

void pose::update()
Expand Down
2 changes: 1 addition & 1 deletion src/engine/animation/rest-pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

rest_pose::rest_pose(const skeleton& skeleton):
pose(skeleton),
m_inverse_absolute_transforms(skeleton.get_bone_count(), bone_transform_type::identity())
m_inverse_absolute_transforms(skeleton.get_bone_count(), math::identity<bone_transform_type>)
{}

void rest_pose::update(bone_index_type first_index, std::size_t bone_count)
Expand Down
2 changes: 1 addition & 1 deletion src/engine/animation/skeleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <engine/animation/bone.hpp>
#include <engine/animation/rest-pose.hpp>
#include <engine/animation/animation-pose.hpp>
#include <engine/utility/hash/fnv1a.hpp>
#include <engine/hash/fnv1a.hpp>
#include <unordered_map>
#include <vector>
#include <optional>
Expand Down
4 changes: 2 additions & 2 deletions src/engine/app/sdl/sdl-input-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <engine/input/application-events.hpp>
#include <engine/input/input-update-event.hpp>
#include <engine/debug/log.hpp>
#include <engine/math/map.hpp>
#include <engine/math/common.hpp>
#include <SDL2/SDL.h>
#include <stdexcept>

Expand Down Expand Up @@ -181,7 +181,7 @@ void sdl_input_manager::update()
if (auto it = m_gamepad_map.find(event.cdevice.which); it != m_gamepad_map.end())
{
// Map axis position onto `[-1, 1]`.
const float position = math::map
const float position = math::map_range
(
static_cast<float>(event.caxis.value),
static_cast<float>(std::numeric_limits<decltype(event.caxis.value)>::min()),
Expand Down
2 changes: 1 addition & 1 deletion src/engine/color/cat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ constexpr math::mat3<T> von_kries_cone_response =
* @see http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
*/
template <class T>
constexpr math::mat3<T> xyz_scaling_cone_response = math::mat3<T>::identity();
constexpr math::mat3<T> xyz_scaling_cone_response = math::identity<math::mat3<T>>;

/**
* Constructs a chromatic adaptation transform (CAT) matrix.
Expand Down
22 changes: 1 addition & 21 deletions src/engine/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
#ifndef ANTKEEPER_CONFIG_HPP
#define ANTKEEPER_CONFIG_HPP

// Disable trace message logging on release builds
#if defined(NDEBUG)
#define ANTKEEPER_DEBUG_LOG_MIN_MESSAGE_SEVERITY 1
#else
#define ANTKEEPER_DEBUG_LOG_MIN_MESSAGE_SEVERITY 0
#endif

#include <cstddef>
#include <engine/math/vector.hpp>
#include <engine/color/aces.hpp>

/// Global configuration constants.
namespace config {
Expand Down Expand Up @@ -77,19 +70,6 @@ inline constexpr int opengl_min_stencil_size = 0;

/// @}

/// @name Rendering config
/// @{

/**
* Scene-linear color space.
*
* @tparam T Scalar type.
*/
template <class T>
inline constexpr color::rgb_color_space<T> scene_linear_color_space = color::aces_ap1<T>;

/// @}

inline constexpr math::vector<float, 3> global_forward = {0.0f, 0.0f, -1.0f};
inline constexpr math::vector<float, 3> global_up = {0.0f, 1.0f, 0.0f};
inline constexpr math::vector<float, 3> global_right = {1.0f, 0.0f, 0.0f};
Expand Down
Loading

0 comments on commit 3d03231

Please sign in to comment.