Skip to content

Commit

Permalink
Merge pull request #367 from FlyAndNotDown/master
Browse files Browse the repository at this point in the history
Feat: Misc Update
  • Loading branch information
FlyAndNotDown authored Oct 13, 2024
2 parents a4d78d8 + 6d401d9 commit 7134cc0
Show file tree
Hide file tree
Showing 42 changed files with 3,296 additions and 1,077 deletions.
1 change: 1 addition & 0 deletions CMake/Common.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_UNITY_BUILD ON)

option(BUILD_EDITOR "Build Explosion editor" ON)
option(CI "Build in CI" OFF)
Expand Down
2 changes: 1 addition & 1 deletion Editor/Source/Include/Editor/EditorModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Editor {
class EditorModule final : public Runtime::IGameModule {
public:
void OnUnload() override;
Core::ModuleType Type() const override;
::Core::ModuleType Type() const override;
Runtime::Engine* CreateEngine(const Runtime::EngineInitParams&) override;

private:
Expand Down
4 changes: 2 additions & 2 deletions Editor/Source/Src/EditorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Editor {
engine.Reset();
}

Core::ModuleType EditorModule::Type() const
::Core::ModuleType EditorModule::Type() const
{
return Core::ModuleType::mStatic;
return ::Core::ModuleType::mStatic;
}

Runtime::Engine* EditorModule::CreateEngine(const Runtime::EngineInitParams& inParams)
Expand Down
2 changes: 1 addition & 1 deletion Editor/Source/Src/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Editor {

std::filesystem::path Resource::Path() const
{
return Core::Paths::EngineRes() / file;
return ::Core::Paths::EngineRes() / file;
}

std::string Resource::String() const
Expand Down
1 change: 0 additions & 1 deletion Editor/Source/Src/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Editor {
Theme::Theme()
// TODO
: colorPrimary()
, colorSecondary()
, colorBackground(0x24, 0x29, 0x2f)
Expand Down
16 changes: 11 additions & 5 deletions Engine/Source/Common/Include/Common/Concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <set>
#include <map>

namespace Common::Internal {
template <typename T> concept BaseEqualComparable = requires(const T& lhs, const T& rhs) { { lhs == rhs } -> std::same_as<bool>; };
namespace Common {
template <typename T> concept BaseEqualComparable = requires(const T& lhs, const T& rhs) { { lhs == rhs } -> std::same_as<bool>; { lhs != rhs } -> std::same_as<bool>; };
template <typename T> struct EqualComparableTest { static constexpr bool value = BaseEqualComparable<T>; };
}

Expand All @@ -28,19 +28,25 @@ namespace Common {
template <typename T> concept CppUnsigned = std::is_unsigned_v<T>;
template <typename T> concept CppArithmetic = std::is_arithmetic_v<T>;
template <typename T> concept CppArithmeticNonBool = CppArithmetic<T> && !CppBool<T>;
template <typename T> concept CppFundamental = std::is_fundamental_v<T>;
template <typename T> concept CppClass = std::is_class_v<T>;
template <typename T> concept CppVoid = std::is_void_v<T>;
template <typename T> concept CppUnion = std::is_union_v<T>;
template <typename T> concept CppArray = std::is_array_v<T>;
template <typename T> concept CppEnum = std::is_enum_v<T>;
template <typename T> concept CppFunction = std::is_function_v<T>;
template <typename T> concept CppInvocable = std::is_invocable_v<T>;
template <typename T> concept CppConst = std::is_const_v<T>;
template <typename T> concept CppPointer = std::is_pointer_v<T>;
template <typename T> concept CppConstPointer = CppPointer<T> && CppConst<std::remove_pointer_t<T>>;
template <typename T> concept CppRef = std::is_reference_v<T>;
template <typename T> concept CppNotRef = !std::is_reference_v<T>;
template <typename T> concept CppLValueRef = std::is_lvalue_reference_v<T>;
template <typename T> concept CppLValueConstRef = CppLValueRef<T> && CppConst<std::remove_reference_t<T>>;
template <typename T> concept CppRValueRef = std::is_rvalue_reference_v<T>;
template <typename T> concept CppConst = std::is_const_v<T>;
template <typename T> concept CppLValueRefOrPtr = CppLValueRef<T> || CppPointer<T>;
template <typename T> concept CppVolatile = std::is_volatile_v<T>;
template <typename T> concept CppPolymorphic = std::is_polymorphic_v<T>;
template <typename T> concept CppCopyConstructible = std::is_copy_constructible_v<T>;
template <typename T> concept CppMoveConstructible = std::is_move_constructible_v<T>;
template <typename T> concept CppCopyAssignable = std::is_copy_assignable_v<T>;
Expand All @@ -51,10 +57,10 @@ namespace Common {
template <uint8_t N, typename... T> concept ArgsNumLessEqual = sizeof...(T) <= N;
template <uint8_t N, typename... T> concept ArgsNumGreaterEqual = sizeof...(T) >= N;
template <typename C, typename B> concept DerivedFrom = std::is_base_of_v<B, C>;
template <typename T> concept EqualComparable = Internal::EqualComparableTest<T>::value;
template <typename T> concept EqualComparable = EqualComparableTest<T>::value;
}

namespace Common::Internal {
namespace Common {
// some types can perform operator== compare, but it requires element type also support operator== compare, so we test it further
template <typename T> struct EqualComparableTest<std::optional<T>> { static constexpr bool value = BaseEqualComparable<T>; };
template <typename T> struct EqualComparableTest<std::vector<T>> { static constexpr bool value = BaseEqualComparable<T>; };
Expand Down
37 changes: 37 additions & 0 deletions Engine/Source/Common/Include/Common/Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <array>

#include <Common/Debug.h>
#include <Common/Concepts.h>

namespace Common {
class VectorUtils {
Expand Down Expand Up @@ -109,6 +110,8 @@ namespace Common {
T& operator[](size_t inIndex);
const T& operator[](size_t inIndex) const;
explicit operator bool() const;
template <size_t N2> bool operator==(const InplaceVector<T, N2>& inRhs) const;
std::vector<T> ToVector() const;
Iter Begin();
ConstIter Begin() const;
Iter End();
Expand Down Expand Up @@ -141,6 +144,13 @@ namespace Common {
};
}

namespace Common { // NOLINT
template <typename T, size_t N>
struct EqualComparableTest<InplaceVector<T, N>> {
static constexpr bool value = BaseEqualComparable<T>;
};
}

namespace Common {
template <typename T>
typename std::vector<T>::iterator VectorUtils::SwapWithLastAndDelete(std::vector<T>& vector, const typename std::vector<T>::iterator& iterator)
Expand Down Expand Up @@ -638,6 +648,33 @@ namespace Common {
return !Empty();
}

template <typename T, size_t N>
template <size_t N2>
bool InplaceVector<T, N>::operator==(const InplaceVector<T, N2>& inRhs) const
{
if (Size() != inRhs.Size()) {
return false;
}
for (auto i = 0; i < Size(); i++) {
if (At(i) != inRhs.At(i)) {
return false;
}
}
return true;
}

template <typename T, size_t N>
std::vector<T> InplaceVector<T, N>::ToVector() const
{
std::vector<T> result;
result.reserve(Size());

for (auto i = 0; i < Size(); i++) {
result.emplace_back(At(i));
}
return result;
}

template <typename T, size_t N>
typename InplaceVector<T, N>::Iter InplaceVector<T, N>::Begin()
{
Expand Down
8 changes: 5 additions & 3 deletions Engine/Source/Common/Include/Common/Math/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ namespace Common { // NOLINT
static std::string ToString(const Box<T>& inValue)
{
return fmt::format(
"{min={}, max={}}",
"{}min={}, max={}{}",
"{",
StringConverter<Vec<T, 3>>::ToString(inValue.min),
StringConverter<Vec<T, 3>>::ToString(inValue.max));
StringConverter<Vec<T, 3>>::ToString(inValue.max),
"}");
}
};

template <JsonSerializable T>
struct JsonSerializer<T> {
struct JsonSerializer<Box<T>> {
static void JsonSerialize(rapidjson::Value& outJsonValue, rapidjson::Document::AllocatorType& inAllocator, const Box<T>& inValue)
{
rapidjson::Value minJson;
Expand Down
4 changes: 2 additions & 2 deletions Engine/Source/Common/Include/Common/Math/Half.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace Common {
JsonSerializer<float>::JsonSerialize(outJsonValue, inAllocator, inValue.value);
}

static void JsonDeserialize(rapidjson::Value& inJsonValue, Internal::FullFloat<E>& outValue)
static void JsonDeserialize(const rapidjson::Value& inJsonValue, Internal::FullFloat<E>& outValue)
{
JsonSerializer<float>::JsonDeserialize(inJsonValue, outValue.value);
}
Expand All @@ -148,7 +148,7 @@ namespace Common {
JsonSerializer<float>::JsonSerialize(outJsonValue, inAllocator, inValue.AsFloat());
}

static void JsonDeserialize(rapidjson::Value& inJsonValue, HalfFloat<E>& outValue)
static void JsonDeserialize(const rapidjson::Value& inJsonValue, HalfFloat<E>& outValue)
{
float fltValue;
JsonSerializer<float>::JsonDeserialize(inJsonValue, fltValue);
Expand Down
17 changes: 12 additions & 5 deletions Engine/Source/Common/Include/Common/Math/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,18 @@ namespace Common { // NOLINT
struct StringConverter<Mat<T, R, C>> {
static std::string ToString(const Mat<T, R, C>& inValue)
{
return fmt::format("{row0={}, row1={}, row2={}, row3={}}",
StringConverter<Vec<T, C>>::ToString(inValue.Row(0)),
StringConverter<Vec<T, C>>::ToString(inValue.Row(1)),
StringConverter<Vec<T, C>>::ToString(inValue.Row(2)),
StringConverter<Vec<T, C>>::ToString(inValue.Row(3)));
std::stringstream stream;
stream << "(";
for (auto i = 0; i < R; i++) {
for (auto j = 0; j < C; j++) {
stream << StringConverter<T>::ToString(inValue.At(i, j));
if (i * C + j != R * C - 1) {
stream << ", ";
}
}
}
stream << ")";
return stream.str();
}
};

Expand Down
62 changes: 58 additions & 4 deletions Engine/Source/Common/Include/Common/Math/Projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ namespace Common {
static std::string ToString(const ReversedZOrthogonalProjection<T>& inValue)
{
return fmt::format(
"{width={}, height={}, near={}, far={}}",
"{}width={}, height={}, near={}, far={}{}",
"{",
StringConverter<T>::ToString(inValue.width),
StringConverter<T>::ToString(inValue.height),
StringConverter<T>::ToString(inValue.nearPlane),
StringConverter<std::optional<T>>::ToString(inValue.farPlane));
StringConverter<std::optional<T>>::ToString(inValue.farPlane),
"}");
}
};

Expand All @@ -125,12 +127,14 @@ namespace Common {
static std::string ToString(const ReversedZPerspectiveProjection<T>& inValue)
{
return fmt::format(
"{fov={}, width={}, height={}, near={}, far={}}",
"{}fov={}, width={}, height={}, near={}, far={}{}",
"{",
StringConverter<T>::ToString(inValue.fov),
StringConverter<T>::ToString(inValue.width),
StringConverter<T>::ToString(inValue.height),
StringConverter<T>::ToString(inValue.nearPlane),
StringConverter<std::optional<T>>::ToString(inValue.farPlane));
StringConverter<std::optional<T>>::ToString(inValue.farPlane),
"}");
}
};

Expand Down Expand Up @@ -176,6 +180,56 @@ namespace Common {
}
}
};

template <JsonSerializable T>
struct JsonSerializer<ReversedZPerspectiveProjection<T>> {
static void JsonSerialize(rapidjson::Value& outJsonValue, rapidjson::Document::AllocatorType& inAllocator, const ReversedZPerspectiveProjection<T>& inValue)
{
rapidjson::Value fovJson;
JsonSerializer<T>::JsonSerialize(fovJson, inAllocator, inValue.fov);

rapidjson::Value widthJson;
JsonSerializer<T>::JsonSerialize(widthJson, inAllocator, inValue.width);

rapidjson::Value heightJson;
JsonSerializer<T>::JsonSerialize(heightJson, inAllocator, inValue.height);

rapidjson::Value nearJson;
JsonSerializer<T>::JsonSerialize(nearJson, inAllocator, inValue.nearPlane);

rapidjson::Value farJson;
JsonSerializer<std::optional<T>>::JsonSerialize(farJson, inAllocator, inValue.farPlane);

outJsonValue.SetObject();
outJsonValue.AddMember("fov", fovJson, inAllocator);
outJsonValue.AddMember("width", widthJson, inAllocator);
outJsonValue.AddMember("height", heightJson, inAllocator);
outJsonValue.AddMember("near", nearJson, inAllocator);
outJsonValue.AddMember("far", farJson, inAllocator);
}

static void JsonDeserialize(const rapidjson::Value& inJsonValue, ReversedZPerspectiveProjection<T>& outValue)
{
if (!inJsonValue.IsObject()) {
return;
}
if (inJsonValue.HasMember("fov")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["fov"], outValue.fov);
}
if (inJsonValue.HasMember("width")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["width"], outValue.width);
}
if (inJsonValue.HasMember("height")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["height"], outValue.height);
}
if (inJsonValue.HasMember("near")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["near"], outValue.nearPlane);
}
if (inJsonValue.HasMember("far")) {
JsonSerializer<std::optional<T>>::JsonDeserialize(inJsonValue["far"], outValue.farPlane);
}
}
};
}

namespace Common {
Expand Down
Loading

0 comments on commit 7134cc0

Please sign in to comment.