Skip to content

Commit

Permalink
Various (unsuccessful) attempts to reduce object file size.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Oct 13, 2023
1 parent b513b73 commit a97f50c
Show file tree
Hide file tree
Showing 15 changed files with 2,414 additions and 3,029 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ node_modules
extern/build-helper.sh
Documentation/Reference
extern/build-linux
extern/build-android
8 changes: 8 additions & 0 deletions Source/CesiumRuntime/CesiumRuntime.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,13 @@ public CesiumRuntime(ReadOnlyTargetRules Target) : base(Target)
PrivatePCHHeaderFile = "Private/PCH.h";
CppStandard = CppStandardVersion.Cpp17;
bEnableExceptions = true;

// if (Target.Platform == UnrealTargetPlatform.Linux)
// {
// Type type = Target.GetType();
// FieldInfo innerField = type.GetField("Inner", BindingFlags.Instance | BindingFlags.NonPublic);
// TargetRules inner = (TargetRules)innerField.GetValue(Target);
// inner.AdditionalCompilerArguments += " -ftime-trace -v";
// }
}
}
283 changes: 283 additions & 0 deletions Source/CesiumRuntime/Private/CesiumMetadataConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,286 @@ CesiumMetadataValueTypeToTrueType(FCesiumMetadataValueType ValueType) {

return ECesiumMetadataTrueType_DEPRECATED::None_DEPRECATED;
}

//bool CesiumMetadataConversions<bool, std::string_view>::convert(
// const std::string_view& from,
// bool defaultValue) noexcept {
// FString f(from.size(), from.data());
//
// if (f.Compare("1", ESearchCase::IgnoreCase) == 0 ||
// f.Compare("true", ESearchCase::IgnoreCase) == 0 ||
// f.Compare("yes", ESearchCase::IgnoreCase) == 0) {
// return true;
// }
//
// if (f.Compare("0", ESearchCase::IgnoreCase) == 0 ||
// f.Compare("false", ESearchCase::IgnoreCase) == 0 ||
// f.Compare("no", ESearchCase::IgnoreCase) == 0) {
// return false;
// }
//
// return defaultValue;
//}
//
//template <typename TTo, typename TFrom>
//TTo CesiumMetadataConversions<
// TTo,
// TFrom,
// std::enable_if_t<
// CesiumGltf::IsMetadataInteger<TTo>::value &&
// CesiumGltf::IsMetadataInteger<TFrom>::value &&
// !std::is_same_v<TTo, TFrom>>>::
// convert(TFrom from, TTo defaultValue) noexcept {
// return CesiumUtility::losslessNarrowOrDefault(from, defaultValue);
//}
//
//template struct CesiumMetadataConversions<int8_t, uint8_t, void>;
//template struct CesiumMetadataConversions<int8_t, int16_t, void>;
//template struct CesiumMetadataConversions<int8_t, uint16_t, void>;
//template struct CesiumMetadataConversions<int8_t, int32_t, void>;
//template struct CesiumMetadataConversions<int8_t, uint32_t, void>;
//template struct CesiumMetadataConversions<int8_t, int64_t, void>;
//template struct CesiumMetadataConversions<int8_t, uint64_t, void>;
//
//template struct CesiumMetadataConversions<uint8_t, int8_t, void>;
//template struct CesiumMetadataConversions<uint8_t, int16_t, void>;
//template struct CesiumMetadataConversions<uint8_t, uint16_t, void>;
//template struct CesiumMetadataConversions<uint8_t, int32_t, void>;
//template struct CesiumMetadataConversions<uint8_t, uint32_t, void>;
//template struct CesiumMetadataConversions<uint8_t, int64_t, void>;
//template struct CesiumMetadataConversions<uint8_t, uint64_t, void>;
//
//template struct CesiumMetadataConversions<int16_t, int8_t, void>;
//template struct CesiumMetadataConversions<int16_t, uint8_t, void>;
//template struct CesiumMetadataConversions<int16_t, uint16_t, void>;
//template struct CesiumMetadataConversions<int16_t, int32_t, void>;
//template struct CesiumMetadataConversions<int16_t, uint32_t, void>;
//template struct CesiumMetadataConversions<int16_t, int64_t, void>;
//template struct CesiumMetadataConversions<int16_t, uint64_t, void>;
//
//template struct CesiumMetadataConversions<uint16_t, int8_t, void>;
//template struct CesiumMetadataConversions<uint16_t, uint8_t, void>;
//template struct CesiumMetadataConversions<uint16_t, int16_t, void>;
//template struct CesiumMetadataConversions<uint16_t, int32_t, void>;
//template struct CesiumMetadataConversions<uint16_t, uint32_t, void>;
//template struct CesiumMetadataConversions<uint16_t, int64_t, void>;
//template struct CesiumMetadataConversions<uint16_t, uint64_t, void>;
//
//template struct CesiumMetadataConversions<int32_t, int8_t, void>;
//template struct CesiumMetadataConversions<int32_t, uint8_t, void>;
//template struct CesiumMetadataConversions<int32_t, int16_t, void>;
//template struct CesiumMetadataConversions<int32_t, uint16_t, void>;
//template struct CesiumMetadataConversions<int32_t, uint32_t, void>;
//template struct CesiumMetadataConversions<int32_t, int64_t, void>;
//template struct CesiumMetadataConversions<int32_t, uint64_t, void>;
//
//template struct CesiumMetadataConversions<uint32_t, int8_t, void>;
//template struct CesiumMetadataConversions<uint32_t, uint8_t, void>;
//template struct CesiumMetadataConversions<uint32_t, int16_t, void>;
//template struct CesiumMetadataConversions<uint32_t, uint16_t, void>;
//template struct CesiumMetadataConversions<uint32_t, int32_t, void>;
//template struct CesiumMetadataConversions<uint32_t, int64_t, void>;
//template struct CesiumMetadataConversions<uint32_t, uint64_t, void>;
//
//template struct CesiumMetadataConversions<int64_t, int8_t, void>;
//template struct CesiumMetadataConversions<int64_t, uint8_t, void>;
//template struct CesiumMetadataConversions<int64_t, int16_t, void>;
//template struct CesiumMetadataConversions<int64_t, uint16_t, void>;
//template struct CesiumMetadataConversions<int64_t, int32_t, void>;
//template struct CesiumMetadataConversions<int64_t, uint32_t, void>;
//template struct CesiumMetadataConversions<int64_t, uint64_t, void>;
//
//template struct CesiumMetadataConversions<uint64_t, int8_t, void>;
//template struct CesiumMetadataConversions<uint64_t, uint8_t, void>;
//template struct CesiumMetadataConversions<uint64_t, int16_t, void>;
//template struct CesiumMetadataConversions<uint64_t, uint16_t, void>;
//template struct CesiumMetadataConversions<uint64_t, int32_t, void>;
//template struct CesiumMetadataConversions<uint64_t, uint32_t, void>;
//template struct CesiumMetadataConversions<uint64_t, int64_t, void>;
//
//template <typename TTo, typename TFrom>
//TTo CesiumMetadataConversions<
// TTo,
// TFrom,
// std::enable_if_t<
// CesiumGltf::IsMetadataInteger<TTo>::value &&
// CesiumGltf::IsMetadataFloating<TFrom>::value>>::
// convert(TFrom from, TTo defaultValue) noexcept {
// if (double(std::numeric_limits<TTo>::max()) < from ||
// double(std::numeric_limits<TTo>::lowest()) > from) {
// // Floating-point number is outside the range of this integer type.
// return defaultValue;
// }
//
// return static_cast<TTo>(from);
//}
//
//template struct CesiumMetadataConversions<int8_t, float, void>;
//template struct CesiumMetadataConversions<uint8_t, float, void>;
//template struct CesiumMetadataConversions<int16_t, float, void>;
//template struct CesiumMetadataConversions<uint16_t, float, void>;
//template struct CesiumMetadataConversions<int32_t, float, void>;
//template struct CesiumMetadataConversions<uint32_t, float, void>;
//template struct CesiumMetadataConversions<int64_t, float, void>;
//template struct CesiumMetadataConversions<uint64_t, float, void>;
//
//template struct CesiumMetadataConversions<int8_t, double, void>;
//template struct CesiumMetadataConversions<uint8_t, double, void>;
//template struct CesiumMetadataConversions<int16_t, double, void>;
//template struct CesiumMetadataConversions<uint16_t, double, void>;
//template struct CesiumMetadataConversions<int32_t, double, void>;
//template struct CesiumMetadataConversions<uint32_t, double, void>;
//template struct CesiumMetadataConversions<int64_t, double, void>;
//template struct CesiumMetadataConversions<uint64_t, double, void>;
//
//template <typename TTo>
//TTo CesiumMetadataConversions<
// TTo,
// std::string_view,
// std::enable_if_t<
// CesiumGltf::IsMetadataInteger<TTo>::value && std::is_signed_v<TTo>>>::
// convert(const std::string_view& from, TTo defaultValue) noexcept {
// // Amazingly, C++ has no* string parsing functions that work with strings
// // that might not be null-terminated. So we have to copy to a std::string
// // (which _is_ guaranteed to be null terminated) before parsing.
// // * except std::from_chars, but compiler/library support for the
// // floating-point version of that method is spotty at best.
// std::string temp(from);
//
// char* pLastUsed;
// int64_t parsedValue = std::strtoll(temp.c_str(), &pLastUsed, 10);
// if (pLastUsed == temp.c_str() + temp.size()) {
// // Successfully parsed the entire string as an integer of this type.
// return CesiumUtility::losslessNarrowOrDefault(parsedValue, defaultValue);
// }
//
// // Failed to parse as an integer. Maybe we can parse as a double and
// // truncate it?
// double parsedDouble = std::strtod(temp.c_str(), &pLastUsed);
// if (pLastUsed == temp.c_str() + temp.size()) {
// // Successfully parsed the entire string as a double.
// // Convert it to an integer if we can.
// double truncated = glm::trunc(parsedDouble);
//
// int64_t asInteger = static_cast<int64_t>(truncated);
// double roundTrip = static_cast<double>(asInteger);
// if (roundTrip == truncated) {
// return CesiumUtility::losslessNarrowOrDefault(asInteger, defaultValue);
// }
// }
//
// return defaultValue;
//}
//
//template struct CesiumMetadataConversions<int8_t, std::string_view, void>;
//template struct CesiumMetadataConversions<int16_t, std::string_view, void>;
//template struct CesiumMetadataConversions<int32_t, std::string_view, void>;
//template struct CesiumMetadataConversions<int64_t, std::string_view, void>;
//
//template <typename TTo>
//TTo CesiumMetadataConversions<
// TTo,
// std::string_view,
// std::enable_if_t<
// CesiumGltf::IsMetadataInteger<TTo>::value && !std::is_signed_v<TTo>>>::
// convert(const std::string_view& from, TTo defaultValue) noexcept {
// // Amazingly, C++ has no* string parsing functions that work with strings
// // that might not be null-terminated. So we have to copy to a std::string
// // (which _is_ guaranteed to be null terminated) before parsing.
// // * except std::from_chars, but compiler/library support for the
// // floating-point version of that method is spotty at best.
// std::string temp(from);
//
// char* pLastUsed;
// uint64_t parsedValue = std::strtoull(temp.c_str(), &pLastUsed, 10);
// if (pLastUsed == temp.c_str() + temp.size()) {
// // Successfully parsed the entire string as an integer of this type.
// return CesiumUtility::losslessNarrowOrDefault(parsedValue, defaultValue);
// }
//
// // Failed to parse as an integer. Maybe we can parse as a double and
// // truncate it?
// double parsedDouble = std::strtod(temp.c_str(), &pLastUsed);
// if (pLastUsed == temp.c_str() + temp.size()) {
// // Successfully parsed the entire string as a double.
// // Convert it to an integer if we can.
// double truncated = glm::trunc(parsedDouble);
//
// uint64_t asInteger = static_cast<uint64_t>(truncated);
// double roundTrip = static_cast<double>(asInteger);
// if (roundTrip == truncated) {
// return CesiumUtility::losslessNarrowOrDefault(asInteger, defaultValue);
// }
// }
//
// return defaultValue;
//}
//
//template struct CesiumMetadataConversions<uint8_t, std::string_view, void>;
//template struct CesiumMetadataConversions<uint16_t, std::string_view, void>;
//template struct CesiumMetadataConversions<uint32_t, std::string_view, void>;
//template struct CesiumMetadataConversions<uint64_t, std::string_view, void>;
//
//float CesiumMetadataConversions<float, std::string_view>::convert(
// const std::string_view& from,
// float defaultValue) noexcept {
// // Amazingly, C++ has no* string parsing functions that work with strings
// // that might not be null-terminated. So we have to copy to a std::string
// // (which _is_ guaranteed to be null terminated) before parsing.
// // * except std::from_chars, but compiler/library support for the
// // floating-point version of that method is spotty at best.
// std::string temp(from);
//
// char* pLastUsed;
// float parsedValue = std::strtof(temp.c_str(), &pLastUsed);
// if (pLastUsed == temp.c_str() + temp.size() && !std::isinf(parsedValue)) {
// // Successfully parsed the entire string as a float.
// return parsedValue;
// }
// return defaultValue;
//}
//
//double CesiumMetadataConversions<double, std::string_view>::convert(
// const std::string_view& from,
// double defaultValue) noexcept {
// // Amazingly, C++ has no* string parsing functions that work with strings
// // that might not be null-terminated. So we have to copy to a std::string
// // (which _is_ guaranteed to be null terminated) before parsing.
// // * except std::from_chars, but compiler/library support for the
// // floating-point version of that method is spotty at best.
// std::string temp(from);
//
// char* pLastUsed;
// double parsedValue = std::strtod(temp.c_str(), &pLastUsed);
// if (pLastUsed == temp.c_str() + temp.size() && !std::isinf(parsedValue)) {
// // Successfully parsed the entire string as a double.
// return parsedValue;
// }
// return defaultValue;
//}
//
//FString CesiumMetadataConversions<FString, bool>::convert(
// bool from,
// const FString& defaultValue) noexcept {
// return from ? "true" : "false";
//}
//
//template <typename TFrom>
//FString CesiumMetadataConversions<
// FString,
// TFrom,
// std::enable_if_t<CesiumGltf::IsMetadataScalar<TFrom>::value>>::
// convert(TFrom from, const FString& defaultValue) noexcept {
// return FString(std::to_string(from).c_str());
//}
//
//template struct CesiumMetadataConversions<FString, int8_t, void>;
//template struct CesiumMetadataConversions<FString, uint8_t, void>;
//template struct CesiumMetadataConversions<FString, int16_t, void>;
//template struct CesiumMetadataConversions<FString, uint16_t, void>;
//template struct CesiumMetadataConversions<FString, int32_t, void>;
//template struct CesiumMetadataConversions<FString, uint32_t, void>;
//template struct CesiumMetadataConversions<FString, int64_t, void>;
//template struct CesiumMetadataConversions<FString, uint64_t, void>;
//template struct CesiumMetadataConversions<FString, float, void>;
//template struct CesiumMetadataConversions<FString, double, void>;
17 changes: 11 additions & 6 deletions Source/CesiumRuntime/Private/CesiumMetadataValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ FString UCesiumMetadataValueBlueprintLibrary::GetString(
FCesiumPropertyArray UCesiumMetadataValueBlueprintLibrary::GetArray(
UPARAM(ref) const FCesiumMetadataValue& Value) {
return mpark::visit(
[](auto value) -> FCesiumPropertyArray {
if constexpr (CesiumGltf::IsMetadataArray<decltype(value)>::value) {
[](const auto& value) -> FCesiumPropertyArray {
if constexpr (CesiumGltf::IsMetadataArray<std::remove_cv_t<
std::remove_reference_t<decltype(value)>>>::value) {
return FCesiumPropertyArray(value);
}
return FCesiumPropertyArray();
Expand All @@ -148,15 +149,19 @@ bool UCesiumMetadataValueBlueprintLibrary::IsEmpty(
return mpark::holds_alternative<mpark::monostate>(Value._value);
}

FCesiumMetadataValue::FCesiumMetadataValue() noexcept
: _value(mpark::monostate{}), _valueType() {}

template <typename TTo>
/*static*/ TTo FCesiumMetadataValue::convertTo(
const ValueType& Value,
const TTo& DefaultValue) noexcept {
return mpark::visit(
[DefaultValue](auto value) {
return CesiumMetadataConversions<TTo, decltype(value)>::convert(
value,
DefaultValue);
[&DefaultValue](const auto& value) noexcept {
return CesiumMetadataConversions<
TTo,
std::remove_cv_t<std::remove_reference_t<decltype(value)>>>::
convert(value, DefaultValue);
},
Value);
}
Expand Down
26 changes: 26 additions & 0 deletions Source/CesiumRuntime/Private/CesiumMetadataValueType.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020-2023 CesiumGS, Inc. and Contributors

#include "CesiumMetadataValueType.h"

FCesiumMetadataValueType::FCesiumMetadataValueType() noexcept
: Type(ECesiumMetadataType::Invalid),
ComponentType(ECesiumMetadataComponentType::None),
bIsArray(false) {}

FCesiumMetadataValueType::FCesiumMetadataValueType(
ECesiumMetadataType InType,
ECesiumMetadataComponentType InComponentType,
bool IsArray) noexcept
: Type(InType), ComponentType(InComponentType), bIsArray(IsArray) {}

bool FCesiumMetadataValueType::operator==(
const FCesiumMetadataValueType& ValueType) const noexcept {
return Type == ValueType.Type && ComponentType == ValueType.ComponentType &&
bIsArray == ValueType.bIsArray;
}

bool FCesiumMetadataValueType::operator!=(
const FCesiumMetadataValueType& ValueType) const noexcept {
return Type != ValueType.Type || ComponentType != ValueType.ComponentType ||
bIsArray != ValueType.bIsArray;
}
20 changes: 20 additions & 0 deletions Source/CesiumRuntime/Private/CesiumPropertyArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2020-2023 CesiumGS, Inc. and Contributors

#include "CesiumPropertyArray.h"

FCesiumPropertyArray::FCesiumPropertyArray() noexcept
: _value(), _elementType() {}

FCesiumPropertyArray::FCesiumPropertyArray(
const FCesiumPropertyArray& rhs) noexcept = default;

FCesiumPropertyArray::FCesiumPropertyArray(
FCesiumPropertyArray&& rhs) noexcept = default;

FCesiumPropertyArray& FCesiumPropertyArray::operator=(
const FCesiumPropertyArray& rhs) noexcept = default;

FCesiumPropertyArray&
FCesiumPropertyArray::operator=(FCesiumPropertyArray&& rhs) noexcept = default;

FCesiumPropertyArray::~FCesiumPropertyArray() noexcept = default;
Loading

0 comments on commit a97f50c

Please sign in to comment.