From 9ccee73baca0fd7ecb95c90cb983133b737c6c55 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 20 Oct 2015 20:46:28 -0700 Subject: Release v1.0.0 --- Common/Android/gcc_Debug.h | 199 +++ Common/Android/gcc_Release.h | 380 ++++++ Common/build/Windows/Android/gcc_Debug.h | 199 +++ Common/build/Windows/Android/gcc_Release.h | 380 ++++++ Common/build/Windows/Common-Debug.vgdbsettings | 76 ++ Common/build/Windows/Common-Release.vgdbsettings | 76 ++ Common/build/Windows/Common.props | 10 + Common/build/Windows/Common.vcxproj | 200 +++ Common/build/Windows/Common.vcxproj.filters | 34 + Common/build/Windows/EngineRoot.props | 14 + Common/build/Windows/jni/Android.mk | 27 + Common/build/Windows/jni/Application.mk | 7 + .../Common.Shared/Common.Shared.vcxitems | 54 + .../Common.Shared/Common.Shared.vcxitems.filters | 105 ++ .../Common.Windows/Common.Windows.vcxproj | 205 +++ .../Common.Windows/Common.Windows.vcxproj.filters | 5 + .../Common.WindowsPhone.vcxproj | 144 +++ .../Common.WindowsPhone.vcxproj.filters | 5 + Common/build/WindowsStore/EngineRoot.props | 14 + Common/include/BasicFileStream.h | 66 + Common/include/BasicTypes.h | 52 + Common/include/DataBlobImpl.h | 58 + Common/include/DebugUtilities.h | 66 + Common/include/Errors.h | 67 + Common/include/FileWrapper.h | 91 ++ Common/include/FormatMessage.h | 44 + Common/include/HashUtils.h | 195 +++ Common/include/InterfaceID.h | 50 + Common/include/LockHelper.h | 133 ++ Common/include/ObjectBase.h | 83 ++ Common/include/RefCntAutoPtr.h | 391 ++++++ Common/include/RefCountedObjectImpl.h | 332 +++++ Common/include/StringTools.h | 75 ++ Common/include/Timer.h | 41 + Common/include/UniqueIdentifier.h | 79 ++ Common/include/ValidatedCast.h | 33 + Common/include/pch.h | 35 + Common/interface/AdvancedMath.h | 127 ++ Common/interface/BasicMath.h | 1344 ++++++++++++++++++++ Common/interface/ComPtr.h | 43 + Common/interface/DataBlob.h | 53 + Common/interface/FileStream.h | 58 + Common/interface/Object.h | 79 ++ Common/interface/ReferenceCounters.h | 115 ++ Common/make/AppCommon.mk | 11 + Common/src/BasicFileStream.cpp | 61 + Common/src/DataBlobImpl.cpp | 52 + Common/src/Timer.cpp | 58 + Common/src/pch.cpp | 31 + 49 files changed, 6057 insertions(+) create mode 100644 Common/Android/gcc_Debug.h create mode 100644 Common/Android/gcc_Release.h create mode 100644 Common/build/Windows/Android/gcc_Debug.h create mode 100644 Common/build/Windows/Android/gcc_Release.h create mode 100644 Common/build/Windows/Common-Debug.vgdbsettings create mode 100644 Common/build/Windows/Common-Release.vgdbsettings create mode 100644 Common/build/Windows/Common.props create mode 100644 Common/build/Windows/Common.vcxproj create mode 100644 Common/build/Windows/Common.vcxproj.filters create mode 100644 Common/build/Windows/EngineRoot.props create mode 100644 Common/build/Windows/jni/Android.mk create mode 100644 Common/build/Windows/jni/Application.mk create mode 100644 Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems create mode 100644 Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems.filters create mode 100644 Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj create mode 100644 Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj.filters create mode 100644 Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj create mode 100644 Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj.filters create mode 100644 Common/build/WindowsStore/EngineRoot.props create mode 100644 Common/include/BasicFileStream.h create mode 100644 Common/include/BasicTypes.h create mode 100644 Common/include/DataBlobImpl.h create mode 100644 Common/include/DebugUtilities.h create mode 100644 Common/include/Errors.h create mode 100644 Common/include/FileWrapper.h create mode 100644 Common/include/FormatMessage.h create mode 100644 Common/include/HashUtils.h create mode 100644 Common/include/InterfaceID.h create mode 100644 Common/include/LockHelper.h create mode 100644 Common/include/ObjectBase.h create mode 100644 Common/include/RefCntAutoPtr.h create mode 100644 Common/include/RefCountedObjectImpl.h create mode 100644 Common/include/StringTools.h create mode 100644 Common/include/Timer.h create mode 100644 Common/include/UniqueIdentifier.h create mode 100644 Common/include/ValidatedCast.h create mode 100644 Common/include/pch.h create mode 100644 Common/interface/AdvancedMath.h create mode 100644 Common/interface/BasicMath.h create mode 100644 Common/interface/ComPtr.h create mode 100644 Common/interface/DataBlob.h create mode 100644 Common/interface/FileStream.h create mode 100644 Common/interface/Object.h create mode 100644 Common/interface/ReferenceCounters.h create mode 100644 Common/make/AppCommon.mk create mode 100644 Common/src/BasicFileStream.cpp create mode 100644 Common/src/DataBlobImpl.cpp create mode 100644 Common/src/Timer.cpp create mode 100644 Common/src/pch.cpp (limited to 'Common') diff --git a/Common/Android/gcc_Debug.h b/Common/Android/gcc_Debug.h new file mode 100644 index 00000000..b46f53e0 --- /dev/null +++ b/Common/Android/gcc_Debug.h @@ -0,0 +1,199 @@ +/* + This file is only used by IntelliSense (VisualStudio code suggestion system) + DO NOT INCLUDE THIS FILE FROM YOUR ACTUAL SOURCE FILES. + This file lists the preprocessor macros extracted from your GCC. + It is needed for IntelliSense to parse other header files correctly. +*/ +#ifdef _MSC_VER +#define _GNU_SOURCE 1 +#define __ANDROID__ 1 +#define __APCS_32__ 1 +#define __ARMEL__ 1 +#define __ARM_ARCH 7 +#define __ARM_ARCH_7A__ 1 +#define __ARM_ARCH_PROFILE A +#define __ARM_EABI__ 1 +#define __ARM_PCS 1 +#define __ARM_VFPV3__ 1 +#define __ATOMIC_ACQUIRE 2 +#define __ATOMIC_ACQ_REL 4 +#define __ATOMIC_CONSUME 1 +#define __ATOMIC_RELAXED 0 +#define __ATOMIC_RELEASE 3 +#define __ATOMIC_SEQ_CST 5 +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __CHAR16_TYPE__ unsigned short +#define __CHAR32_TYPE__ unsigned int +#define __CHAR_BIT__ 8 +#define __CHAR_UNSIGNED__ 1 +#define __CONSTANT_CFSTRINGS__ 1 +#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 +#define __DBL_DIG__ 15 +#define __DBL_EPSILON__ 2.2204460492503131e-16 +#define __DBL_HAS_DENORM__ 1 +#define __DBL_HAS_INFINITY__ 1 +#define __DBL_HAS_QUIET_NAN__ 1 +#define __DBL_MANT_DIG__ 53 +#define __DBL_MAX_10_EXP__ 308 +#define __DBL_MAX_EXP__ 1024 +#define __DBL_MAX__ 1.7976931348623157e+308 +#define __DBL_MIN_10_EXP__ (-307) +#define __DBL_MIN_EXP__ (-1021) +#define __DBL_MIN__ 2.2250738585072014e-308 +#define __DECIMAL_DIG__ 17 +#define __DEPRECATED 1 +#define __ELF__ 1 +#define __EXCEPTIONS 1 +#define __FINITE_MATH_ONLY__ 0 +#define __FLT_DENORM_MIN__ 1.40129846e-45F +#define __FLT_DIG__ 6 +#define __FLT_EPSILON__ 1.19209290e-7F +#define __FLT_EVAL_METHOD__ 0 +#define __FLT_HAS_DENORM__ 1 +#define __FLT_HAS_INFINITY__ 1 +#define __FLT_HAS_QUIET_NAN__ 1 +#define __FLT_MANT_DIG__ 24 +#define __FLT_MAX_10_EXP__ 38 +#define __FLT_MAX_EXP__ 128 +#define __FLT_MAX__ 3.40282347e+38F +#define __FLT_MIN_10_EXP__ (-37) +#define __FLT_MIN_EXP__ (-125) +#define __FLT_MIN__ 1.17549435e-38F +#define __FLT_RADIX__ 2 +#define __GCC_ATOMIC_BOOL_LOCK_FREE 2 +#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 +#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 +#define __GCC_ATOMIC_CHAR_LOCK_FREE 2 +#define __GCC_ATOMIC_INT_LOCK_FREE 2 +#define __GCC_ATOMIC_LLONG_LOCK_FREE 2 +#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 +#define __GNUC_GNU_INLINE__ 1 +#define __GNUC_MINOR__ 2 +#define __GNUC_PATCHLEVEL__ 1 +#define __GNUC__ 4 +#define __GNUG__ 4 +#define __GXX_ABI_VERSION 1002 +#define __GXX_EXPERIMENTAL_CXX0X__ 1 +#define __GXX_RTTI 1 +#define __GXX_WEAK__ 1 +#define __INT16_TYPE__ short +#define __INT32_TYPE__ int +#define __INT64_C_SUFFIX__ LL +#define __INT64_TYPE__ long long int +#define __INT8_TYPE__ char +#define __INTMAX_MAX__ 9223372036854775807LL +#define __INTMAX_TYPE__ long long int +#define __INTMAX_WIDTH__ 64 +#define __INTPTR_TYPE__ long int +#define __INTPTR_WIDTH__ 32 +#define __INT_MAX__ 2147483647 +#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L +#define __LDBL_DIG__ 15 +#define __LDBL_EPSILON__ 2.2204460492503131e-16L +#define __LDBL_HAS_DENORM__ 1 +#define __LDBL_HAS_INFINITY__ 1 +#define __LDBL_HAS_QUIET_NAN__ 1 +#define __LDBL_MANT_DIG__ 53 +#define __LDBL_MAX_10_EXP__ 308 +#define __LDBL_MAX_EXP__ 1024 +#define __LDBL_MAX__ 1.7976931348623157e+308L +#define __LDBL_MIN_10_EXP__ (-307) +#define __LDBL_MIN_EXP__ (-1021) +#define __LDBL_MIN__ 2.2250738585072014e-308L +#define __LITTLE_ENDIAN__ 1 +#define __LONG_LONG_MAX__ 9223372036854775807LL +#define __LONG_MAX__ 2147483647L +#define __NO_INLINE__ 1 +#define __ORDER_BIG_ENDIAN__ 4321 +#define __ORDER_LITTLE_ENDIAN__ 1234 +#define __ORDER_PDP_ENDIAN__ 3412 +#define __PIC__ 1 +#define __POINTER_WIDTH__ 32 +#define __PRAGMA_REDEFINE_EXTNAME 1 +#define __PTRDIFF_TYPE__ int +#define __PTRDIFF_WIDTH__ 32 +#define __REGISTER_PREFIX__ +#define __SCHAR_MAX__ 127 +#define __SHRT_MAX__ 32767 +#define __SIG_ATOMIC_WIDTH__ 32 +#define __SIZEOF_DOUBLE__ 8 +#define __SIZEOF_FLOAT__ 4 +#define __SIZEOF_INT__ 4 +#define __SIZEOF_LONG_DOUBLE__ 8 +#define __SIZEOF_LONG_LONG__ 8 +#define __SIZEOF_LONG__ 4 +#define __SIZEOF_POINTER__ 4 +#define __SIZEOF_PTRDIFF_T__ 4 +#define __SIZEOF_SHORT__ 2 +#define __SIZEOF_SIZE_T__ 4 +#define __SIZEOF_WCHAR_T__ 4 +#define __SIZEOF_WINT_T__ 4 +#define __SIZE_MAX__ 4294967295U +#define __SIZE_TYPE__ unsigned int +#define __SIZE_WIDTH__ 32 +#define __SSP__ 1 +#define __STDC_HOSTED__ 1 +#define __STDC_UTF_16__ 1 +#define __STDC_UTF_32__ 1 +#define __STDC__ 1 +#define __STRICT_ANSI__ 1 +#define __THUMB_INTERWORK__ 1 +#define __UINTMAX_TYPE__ long long unsigned int +#define __USER_LABEL_PREFIX__ +#define __VERSION__ "4.2.1 Compatible Clang 3.4 (https://bitbucket.org/loganchien/clang c34bb12af3af42f671296cdb978b34b931062d2a) (https://bitbucket.org/loganchien/llvm d09f2eff406d17c86d51db7660bd374cf092e6ed)" +#define __VFP_FP__ 1 +#define __WCHAR_MAX__ 4294967295U +#define __WCHAR_TYPE__ unsigned int +#define __WCHAR_UNSIGNED__ 1 +#define __WCHAR_WIDTH__ 32 +#define __WINT_TYPE__ unsigned int +#define __WINT_UNSIGNED__ 1 +#define __WINT_WIDTH__ 32 +#define __arm 1 +#define __arm__ 1 +#define __clang__ 1 +#define __clang_major__ 3 +#define __clang_minor__ 4 +#define __clang_patchlevel__ 0 +#define __clang_version__ "3.4 (https://bitbucket.org/loganchien/clang c34bb12af3af42f671296cdb978b34b931062d2a) (https://bitbucket.org/loganchien/llvm d09f2eff406d17c86d51db7660bd374cf092e6ed)" +#define __cplusplus 201103L +#define __cpp_attributes 200809 +#define __cpp_constexpr 200704 +#define __cpp_decltype 200707 +#define __cpp_lambdas 200907 +#define __cpp_raw_strings 200710 +#define __cpp_rvalue_references 200610 +#define __cpp_static_assert 200410 +#define __cpp_unicode_characters 200704 +#define __cpp_unicode_literals 200710 +#define __cpp_user_defined_literals 200809 +#define __cpp_variadic_templates 200704 +#define __gnu_linux__ 1 +#define __linux 1 +#define __linux__ 1 +#define __llvm__ 1 +#define __pic__ 1 +#define __private_extern__ extern +#define __unix 1 +#define __unix__ 1 +#define ANDROID +#endif + +// --- Include directories begin --- // +//C:/Android/ndk/platforms/android-3/arch-arm/usr/include +//C:/Users/eayusov/Documents/Sandbox/Common/Android/jni/../../include +//C:\Android\ndk\toolchains\llvm-3.4\prebuilt\windows\bin\..\lib\clang\3.4\include +// --- Library directories end --- // + + +// --- Library directories begin --- // +// --- Library directories begin --- // + diff --git a/Common/Android/gcc_Release.h b/Common/Android/gcc_Release.h new file mode 100644 index 00000000..6ca2abab --- /dev/null +++ b/Common/Android/gcc_Release.h @@ -0,0 +1,380 @@ +/* + This file is only used by IntelliSense (VisualStudio code suggestion system) + DO NOT INCLUDE THIS FILE FROM YOUR ACTUAL SOURCE FILES. + This file lists the preprocessor macros extracted from your GCC. + It is needed for IntelliSense to parse other header files correctly. +*/ +#ifdef _MSC_VER +#define __DBL_MIN_EXP__ (-1021) +#define __HQ_FBIT__ 15 +#define __UINT_LEAST16_MAX__ 65535 +#define __ARM_SIZEOF_WCHAR_T 32 +#define __ATOMIC_ACQUIRE 2 +#define __SFRACT_IBIT__ 0 +#define __FLT_MIN__ 1.1754943508222875e-38F +#define __UFRACT_MAX__ 0XFFFFP-16UR +#define __UINT_LEAST8_TYPE__ unsigned char +#define __DQ_FBIT__ 63 +#define __ARM_FEATURE_SAT 1 +#define __ULFRACT_FBIT__ 32 +#define __SACCUM_EPSILON__ 0x1P-7HK +#define __CHAR_BIT__ 8 +#define __USQ_IBIT__ 0 +#define __UINT8_MAX__ 255 +#define __ACCUM_FBIT__ 15 +#define __ANDROID__ 1 +#define __WINT_MAX__ 4294967295U +#define __USFRACT_FBIT__ 8 +#define __ORDER_LITTLE_ENDIAN__ 1234 +#define __SIZE_MAX__ 4294967295U +#define __ARM_ARCH_ISA_ARM 1 +#define __WCHAR_MAX__ 4294967295U +#define __LACCUM_IBIT__ 32 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 +#define __DBL_DENORM_MIN__ double(4.9406564584124654e-324L) +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 +#define __GCC_ATOMIC_CHAR_LOCK_FREE 2 +#define __FLT_EVAL_METHOD__ 0 +#define __unix__ 1 +#define __LLACCUM_MAX__ 0X7FFFFFFFFFFFFFFFP-31LLK +#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 +#define __FRACT_FBIT__ 15 +#define __UINT_FAST64_MAX__ 18446744073709551615ULL +#define __SIG_ATOMIC_TYPE__ int +#define __UACCUM_FBIT__ 16 +#define __DBL_MIN_10_EXP__ (-307) +#define __FINITE_MATH_ONLY__ 0 +#define __ARMEL__ 1 +#define __ARM_FEATURE_UNALIGNED 1 +#define __LFRACT_IBIT__ 0 +#define __GNUC_PATCHLEVEL__ 0 +#define __LFRACT_MAX__ 0X7FFFFFFFP-31LR +#define __UINT_FAST8_MAX__ 255 +#define __DEC64_MAX_EXP__ 385 +#define __UINT_LEAST64_MAX__ 18446744073709551615ULL +#define __SA_FBIT__ 15 +#define __SHRT_MAX__ 32767 +#define __LDBL_MAX__ 1.7976931348623157e+308L +#define __FRACT_MAX__ 0X7FFFP-15R +#define __UFRACT_FBIT__ 16 +#define __ARM_FP 12 +#define __UFRACT_MIN__ 0.0UR +#define __UINT_LEAST8_MAX__ 255 +#define __GCC_ATOMIC_BOOL_LOCK_FREE 2 +#define __UINTMAX_TYPE__ long long unsigned int +#define __LLFRACT_EPSILON__ 0x1P-63LLR +#define __linux 1 +#define __DEC32_EPSILON__ 1E-6DF +#define __CHAR_UNSIGNED__ 1 +#define __UINT32_MAX__ 4294967295U +#define __GXX_EXPERIMENTAL_CXX0X__ 1 +#define __ULFRACT_MAX__ 0XFFFFFFFFP-32ULR +#define __TA_IBIT__ 64 +#define __LDBL_MAX_EXP__ 1024 +#define __WINT_MIN__ 0U +#define __linux__ 1 +#define __ULLFRACT_MIN__ 0.0ULLR +#define __SCHAR_MAX__ 127 +#define __WCHAR_MIN__ 0U +#define __DBL_DIG__ 15 +#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +#define __LLACCUM_MIN__ (-0X1P31LLK-0X1P31LLK) +#define __SIZEOF_INT__ 4 +#define __SIZEOF_POINTER__ 4 +#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 +#define __USACCUM_IBIT__ 8 +#define __USER_LABEL_PREFIX__ +#define __STDC_HOSTED__ 1 +#define __LDBL_HAS_INFINITY__ 1 +#define __LFRACT_MIN__ (-0.5LR-0.5LR) +#define __HA_IBIT__ 8 +#define __ARM_NEON_FP 4 +#define __TQ_IBIT__ 0 +#define __FLT_EPSILON__ 1.1920928955078125e-7F +#define __APCS_32__ 1 +#define __GXX_WEAK__ 1 +#define __USFRACT_IBIT__ 0 +#define __LDBL_MIN__ 2.2250738585072014e-308L +#define __FRACT_MIN__ (-0.5R-0.5R) +#define __DEC32_MAX__ 9.999999E96DF +#define __DA_IBIT__ 32 +#define __ARM_SIZEOF_MINIMAL_ENUM 4 +#define __INT32_MAX__ 2147483647 +#define __UQQ_FBIT__ 8 +#define __SIZEOF_LONG__ 4 +#define __UACCUM_MAX__ 0XFFFFFFFFP-16UK +#define __DECIMAL_DIG__ 17 +#define __LFRACT_EPSILON__ 0x1P-31LR +#define __ULFRACT_MIN__ 0.0ULR +#define __LDBL_HAS_QUIET_NAN__ 1 +#define __ULACCUM_IBIT__ 32 +#define __UACCUM_EPSILON__ 0x1P-16UK +#define __GNUC__ 4 +#define __ULLACCUM_MAX__ 0XFFFFFFFFFFFFFFFFP-32ULLK +#define __GXX_RTTI 1 +#define __HQ_IBIT__ 0 +#define __FLT_HAS_DENORM__ 1 +#define __SIZEOF_LONG_DOUBLE__ 8 +#define __BIGGEST_ALIGNMENT__ 8 +#define __GNUC_STDC_INLINE__ 1 +#define __DQ_IBIT__ 0 +#define __DBL_MAX__ double(1.7976931348623157e+308L) +#define __ULFRACT_IBIT__ 0 +#define __INT_FAST32_MAX__ 2147483647 +#define __DBL_HAS_INFINITY__ 1 +#define __INT64_MAX__ 9223372036854775807LL +#define __ACCUM_IBIT__ 16 +#define __DEC32_MIN_EXP__ (-94) +#define __THUMB_INTERWORK__ 1 +#define __LACCUM_MAX__ 0X7FFFFFFFFFFFFFFFP-31LK +#define __INT_FAST16_TYPE__ int +#define __STRICT_ANSI__ 1 +#define __LDBL_HAS_DENORM__ 1 +#define __ARM_FEATURE_LDREX 15 +#define __cplusplus 201103L +#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL +#define __INT_LEAST32_MAX__ 2147483647 +#define __ARM_PCS 1 +#define __DEC32_MIN__ 1E-95DF +#define __ACCUM_MAX__ 0X7FFFFFFFP-15K +#define __DEPRECATED 1 +#define __DBL_MAX_EXP__ 1024 +#define __USACCUM_EPSILON__ 0x1P-8UHK +#define __DEC128_EPSILON__ 1E-33DL +#define __SFRACT_MAX__ 0X7FP-7HR +#define __FRACT_IBIT__ 0 +#define __PTRDIFF_MAX__ 2147483647 +#define __UACCUM_MIN__ 0.0UK +#define __UACCUM_IBIT__ 16 +#define __GNUG__ 4 +#define __LONG_LONG_MAX__ 9223372036854775807LL +#define __SIZEOF_SIZE_T__ 4 +#define __ULACCUM_MAX__ 0XFFFFFFFFFFFFFFFFP-32ULK +#define __SIZEOF_WINT_T__ 4 +#define __SA_IBIT__ 16 +#define __ULLACCUM_MIN__ 0.0ULLK +#define __GXX_ABI_VERSION 1002 +#define __UTA_FBIT__ 64 +#define __FLT_MIN_EXP__ (-125) +#define __USFRACT_MAX__ 0XFFP-8UHR +#define __UFRACT_IBIT__ 0 +#define __ARM_FEATURE_QBIT 1 +#define __INT_FAST64_TYPE__ long long int +#define __DBL_MIN__ double(2.2250738585072014e-308L) +#define __FLT_MIN_10_EXP__ (-37) +#define __LACCUM_MIN__ (-0X1P31LK-0X1P31LK) +#define __ULLACCUM_FBIT__ 32 +#define __GXX_TYPEINFO_EQUALITY_INLINE 0 +#define __ULLFRACT_EPSILON__ 0x1P-64ULLR +#define __DEC128_MIN__ 1E-6143DL +#define __REGISTER_PREFIX__ +#define __UINT16_MAX__ 65535 +#define __DBL_HAS_DENORM__ 1 +#define __ACCUM_MIN__ (-0X1P15K-0X1P15K) +#define __SQ_IBIT__ 0 +#define __UINT8_TYPE__ unsigned char +#define __UHA_FBIT__ 8 +#define __NO_INLINE__ 1 +#define __SFRACT_MIN__ (-0.5HR-0.5HR) +#define __UTQ_FBIT__ 128 +#define __FLT_MANT_DIG__ 24 +#define __VERSION__ "4.8" +#define __ULLFRACT_FBIT__ 64 +#define __FRACT_EPSILON__ 0x1P-15R +#define __ULACCUM_MIN__ 0.0ULK +#define __UDA_FBIT__ 32 +#define __LLACCUM_EPSILON__ 0x1P-31LLK +#define __GCC_ATOMIC_INT_LOCK_FREE 2 +#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __USFRACT_MIN__ 0.0UHR +#define __ULLACCUM_IBIT__ 32 +#define __UQQ_IBIT__ 0 +#define __DEC64_EPSILON__ 1E-15DD +#define __ORDER_PDP_ENDIAN__ 3412 +#define __DEC128_MIN_EXP__ (-6142) +#define __UHQ_FBIT__ 16 +#define __LLACCUM_FBIT__ 31 +#define __INT_FAST32_TYPE__ int +#define __UINT_LEAST16_TYPE__ short unsigned int +#define __INT16_MAX__ 32767 +#define __SIZE_TYPE__ unsigned int +#define __UINT64_MAX__ 18446744073709551615ULL +#define __UDQ_FBIT__ 64 +#define __INT8_TYPE__ signed char +#define __ELF__ 1 +#define __ULFRACT_EPSILON__ 0x1P-32ULR +#define __LLFRACT_FBIT__ 63 +#define __FLT_RADIX__ 2 +#define __INT_LEAST16_TYPE__ short int +#define __ARM_ARCH_PROFILE 65 +#define __LDBL_EPSILON__ 2.2204460492503131e-16L +#define __SACCUM_MAX__ 0X7FFFP-7HK +#define __SIG_ATOMIC_MAX__ 2147483647 +#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +#define __VFP_FP__ 1 +#define __SIZEOF_PTRDIFF_T__ 4 +#define __LACCUM_EPSILON__ 0x1P-31LK +#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF +#define __INT_FAST16_MAX__ 2147483647 +#define __UINT_FAST32_MAX__ 4294967295U +#define __UINT_LEAST64_TYPE__ long long unsigned int +#define __USACCUM_MAX__ 0XFFFFP-8UHK +#define __SFRACT_EPSILON__ 0x1P-7HR +#define __FLT_HAS_QUIET_NAN__ 1 +#define __FLT_MAX_10_EXP__ 38 +#define __LONG_MAX__ 2147483647L +#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL +#define __FLT_HAS_INFINITY__ 1 +#define __unix 1 +#define __USA_FBIT__ 16 +#define __UINT_FAST16_TYPE__ unsigned int +#define __DEC64_MAX__ 9.999999999999999E384DD +#define __CHAR16_TYPE__ short unsigned int +#define __PRAGMA_REDEFINE_EXTNAME 1 +#define __INT_LEAST16_MAX__ 32767 +#define __DEC64_MANT_DIG__ 16 +#define __UINT_LEAST32_MAX__ 4294967295U +#define __SACCUM_FBIT__ 7 +#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +#define __INT_LEAST64_TYPE__ long long int +#define __ARM_FEATURE_CLZ 1 +#define __INT16_TYPE__ short int +#define __INT_LEAST8_TYPE__ signed char +#define __SQ_FBIT__ 31 +#define __DEC32_MAX_EXP__ 97 +#define __ARM_ARCH_ISA_THUMB 2 +#define __INT_FAST8_MAX__ 127 +#define __ARM_ARCH 7 +#define __INTPTR_MAX__ 2147483647 +#define __QQ_FBIT__ 7 +#define __UTA_IBIT__ 64 +#define __EXCEPTIONS 1 +#define __LDBL_MANT_DIG__ 53 +#define __SFRACT_FBIT__ 7 +#define __SACCUM_MIN__ (-0X1P7HK-0X1P7HK) +#define __DBL_HAS_QUIET_NAN__ 1 +#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1) +#define __INTPTR_TYPE__ int +#define __UINT16_TYPE__ short unsigned int +#define __WCHAR_TYPE__ unsigned int +#define __SIZEOF_FLOAT__ 4 +#define __USQ_FBIT__ 32 +#define __pic__ 1 +#define __UINTPTR_MAX__ 4294967295U +#define __DEC64_MIN_EXP__ (-382) +#define __INT_FAST64_MAX__ 9223372036854775807LL +#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +#define __FLT_DIG__ 6 +#define __UINT_FAST64_TYPE__ long long unsigned int +#define __INT_MAX__ 2147483647 +#define __LACCUM_FBIT__ 31 +#define __USACCUM_MIN__ 0.0UHK +#define __UHA_IBIT__ 8 +#define __INT64_TYPE__ long long int +#define __FLT_MAX_EXP__ 128 +#define __UTQ_IBIT__ 0 +#define __DBL_MANT_DIG__ 53 +#define __INT_LEAST64_MAX__ 9223372036854775807LL +#define __DEC64_MIN__ 1E-383DD +#define __WINT_TYPE__ unsigned int +#define __UINT_LEAST32_TYPE__ unsigned int +#define __SIZEOF_SHORT__ 2 +#define __ULLFRACT_IBIT__ 0 +#define __LDBL_MIN_EXP__ (-1021) +#define __arm__ 1 +#define __UDA_IBIT__ 32 +#define __INT_LEAST8_MAX__ 127 +#define __SSP__ 1 +#define __LFRACT_FBIT__ 31 +#define __WCHAR_UNSIGNED__ 1 +#define __ARM_ARCH_7A__ 1 +#define __LDBL_MAX_10_EXP__ 308 +#define __ATOMIC_RELAXED 0 +#define __DBL_EPSILON__ double(2.2204460492503131e-16L) +#define __ARM_FEATURE_SIMD32 1 +#define __INT_LEAST32_TYPE__ int +#define __SIZEOF_WCHAR_T__ 4 +#define __UINT64_TYPE__ long long unsigned int +#define __LLFRACT_MAX__ 0X7FFFFFFFFFFFFFFFP-63LLR +#define __TQ_FBIT__ 127 +#define __INT_FAST8_TYPE__ signed char +#define __ULLACCUM_EPSILON__ 0x1P-32ULLK +#define __UHQ_IBIT__ 0 +#define __LLACCUM_IBIT__ 32 +#define __DBL_DECIMAL_DIG__ 17 +#define __DEC_EVAL_METHOD__ 2 +#define __TA_FBIT__ 63 +#define __UDQ_IBIT__ 0 +#define __ORDER_BIG_ENDIAN__ 4321 +#define __ACCUM_EPSILON__ 0x1P-15K +#define __INTMAX_MAX__ 9223372036854775807LL +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __FLT_DENORM_MIN__ 1.4012984643248171e-45F +#define __LLFRACT_IBIT__ 0 +#define __INT8_MAX__ 127 +#define __PIC__ 1 +#define __UINT_FAST32_TYPE__ unsigned int +#define __CHAR32_TYPE__ unsigned int +#define __FLT_MAX__ 3.4028234663852886e+38F +#define __USACCUM_FBIT__ 8 +#define __INT32_TYPE__ int +#define __SIZEOF_DOUBLE__ 8 +#define __UFRACT_EPSILON__ 0x1P-16UR +#define __INTMAX_TYPE__ long long int +#define __DEC128_MAX_EXP__ 6145 +#define __ATOMIC_CONSUME 1 +#define __GNUC_MINOR__ 8 +#define __UINTMAX_MAX__ 18446744073709551615ULL +#define __DEC32_MANT_DIG__ 7 +#define __HA_FBIT__ 7 +#define __DBL_MAX_10_EXP__ 308 +#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L +#define __STDC__ 1 +#define __PTRDIFF_TYPE__ int +#define __LLFRACT_MIN__ (-0.5LLR-0.5LLR) +#define __ATOMIC_SEQ_CST 5 +#define __DA_FBIT__ 31 +#define __UINT32_TYPE__ unsigned int +#define __UINTPTR_TYPE__ unsigned int +#define __USA_IBIT__ 16 +#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD +#define __ARM_EABI__ 1 +#define __DEC128_MANT_DIG__ 34 +#define __LDBL_MIN_10_EXP__ (-307) +#define __SIZEOF_LONG_LONG__ 8 +#define __ULACCUM_EPSILON__ 0x1P-32ULK +#define __SACCUM_IBIT__ 8 +#define __GCC_ATOMIC_LLONG_LOCK_FREE 2 +#define __LDBL_DIG__ 15 +#define __FLT_DECIMAL_DIG__ 9 +#define __UINT_FAST16_MAX__ 4294967295U +#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +#define __ULLFRACT_MAX__ 0XFFFFFFFFFFFFFFFFP-64ULLR +#define __UINT_FAST8_TYPE__ unsigned char +#define _GNU_SOURCE 1 +#define __USFRACT_EPSILON__ 0x1P-8UHR +#define __ULACCUM_FBIT__ 32 +#define __ARM_FEATURE_DSP 1 +#define __QQ_IBIT__ 0 +#define __ATOMIC_ACQ_REL 4 +#define __ATOMIC_RELEASE 3 +#define ANDROID +#endif + +// --- Include directories begin --- // +//C:/Android/ndk/platforms/android-3/arch-arm/usr/include +//C:\Android\ndk\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\bin\../lib/gcc/arm-linux-androideabi/4.8/include +//C:\Android\ndk\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\bin\../lib/gcc/arm-linux-androideabi/4.8/include-fixed +// --- Library directories end --- // + + +// --- Library directories begin --- // +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/armv7-a/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/lib/armv7-a/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/lib/ +// --- Library directories begin --- // + diff --git a/Common/build/Windows/Android/gcc_Debug.h b/Common/build/Windows/Android/gcc_Debug.h new file mode 100644 index 00000000..b46f53e0 --- /dev/null +++ b/Common/build/Windows/Android/gcc_Debug.h @@ -0,0 +1,199 @@ +/* + This file is only used by IntelliSense (VisualStudio code suggestion system) + DO NOT INCLUDE THIS FILE FROM YOUR ACTUAL SOURCE FILES. + This file lists the preprocessor macros extracted from your GCC. + It is needed for IntelliSense to parse other header files correctly. +*/ +#ifdef _MSC_VER +#define _GNU_SOURCE 1 +#define __ANDROID__ 1 +#define __APCS_32__ 1 +#define __ARMEL__ 1 +#define __ARM_ARCH 7 +#define __ARM_ARCH_7A__ 1 +#define __ARM_ARCH_PROFILE A +#define __ARM_EABI__ 1 +#define __ARM_PCS 1 +#define __ARM_VFPV3__ 1 +#define __ATOMIC_ACQUIRE 2 +#define __ATOMIC_ACQ_REL 4 +#define __ATOMIC_CONSUME 1 +#define __ATOMIC_RELAXED 0 +#define __ATOMIC_RELEASE 3 +#define __ATOMIC_SEQ_CST 5 +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __CHAR16_TYPE__ unsigned short +#define __CHAR32_TYPE__ unsigned int +#define __CHAR_BIT__ 8 +#define __CHAR_UNSIGNED__ 1 +#define __CONSTANT_CFSTRINGS__ 1 +#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 +#define __DBL_DIG__ 15 +#define __DBL_EPSILON__ 2.2204460492503131e-16 +#define __DBL_HAS_DENORM__ 1 +#define __DBL_HAS_INFINITY__ 1 +#define __DBL_HAS_QUIET_NAN__ 1 +#define __DBL_MANT_DIG__ 53 +#define __DBL_MAX_10_EXP__ 308 +#define __DBL_MAX_EXP__ 1024 +#define __DBL_MAX__ 1.7976931348623157e+308 +#define __DBL_MIN_10_EXP__ (-307) +#define __DBL_MIN_EXP__ (-1021) +#define __DBL_MIN__ 2.2250738585072014e-308 +#define __DECIMAL_DIG__ 17 +#define __DEPRECATED 1 +#define __ELF__ 1 +#define __EXCEPTIONS 1 +#define __FINITE_MATH_ONLY__ 0 +#define __FLT_DENORM_MIN__ 1.40129846e-45F +#define __FLT_DIG__ 6 +#define __FLT_EPSILON__ 1.19209290e-7F +#define __FLT_EVAL_METHOD__ 0 +#define __FLT_HAS_DENORM__ 1 +#define __FLT_HAS_INFINITY__ 1 +#define __FLT_HAS_QUIET_NAN__ 1 +#define __FLT_MANT_DIG__ 24 +#define __FLT_MAX_10_EXP__ 38 +#define __FLT_MAX_EXP__ 128 +#define __FLT_MAX__ 3.40282347e+38F +#define __FLT_MIN_10_EXP__ (-37) +#define __FLT_MIN_EXP__ (-125) +#define __FLT_MIN__ 1.17549435e-38F +#define __FLT_RADIX__ 2 +#define __GCC_ATOMIC_BOOL_LOCK_FREE 2 +#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 +#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 +#define __GCC_ATOMIC_CHAR_LOCK_FREE 2 +#define __GCC_ATOMIC_INT_LOCK_FREE 2 +#define __GCC_ATOMIC_LLONG_LOCK_FREE 2 +#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 +#define __GNUC_GNU_INLINE__ 1 +#define __GNUC_MINOR__ 2 +#define __GNUC_PATCHLEVEL__ 1 +#define __GNUC__ 4 +#define __GNUG__ 4 +#define __GXX_ABI_VERSION 1002 +#define __GXX_EXPERIMENTAL_CXX0X__ 1 +#define __GXX_RTTI 1 +#define __GXX_WEAK__ 1 +#define __INT16_TYPE__ short +#define __INT32_TYPE__ int +#define __INT64_C_SUFFIX__ LL +#define __INT64_TYPE__ long long int +#define __INT8_TYPE__ char +#define __INTMAX_MAX__ 9223372036854775807LL +#define __INTMAX_TYPE__ long long int +#define __INTMAX_WIDTH__ 64 +#define __INTPTR_TYPE__ long int +#define __INTPTR_WIDTH__ 32 +#define __INT_MAX__ 2147483647 +#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L +#define __LDBL_DIG__ 15 +#define __LDBL_EPSILON__ 2.2204460492503131e-16L +#define __LDBL_HAS_DENORM__ 1 +#define __LDBL_HAS_INFINITY__ 1 +#define __LDBL_HAS_QUIET_NAN__ 1 +#define __LDBL_MANT_DIG__ 53 +#define __LDBL_MAX_10_EXP__ 308 +#define __LDBL_MAX_EXP__ 1024 +#define __LDBL_MAX__ 1.7976931348623157e+308L +#define __LDBL_MIN_10_EXP__ (-307) +#define __LDBL_MIN_EXP__ (-1021) +#define __LDBL_MIN__ 2.2250738585072014e-308L +#define __LITTLE_ENDIAN__ 1 +#define __LONG_LONG_MAX__ 9223372036854775807LL +#define __LONG_MAX__ 2147483647L +#define __NO_INLINE__ 1 +#define __ORDER_BIG_ENDIAN__ 4321 +#define __ORDER_LITTLE_ENDIAN__ 1234 +#define __ORDER_PDP_ENDIAN__ 3412 +#define __PIC__ 1 +#define __POINTER_WIDTH__ 32 +#define __PRAGMA_REDEFINE_EXTNAME 1 +#define __PTRDIFF_TYPE__ int +#define __PTRDIFF_WIDTH__ 32 +#define __REGISTER_PREFIX__ +#define __SCHAR_MAX__ 127 +#define __SHRT_MAX__ 32767 +#define __SIG_ATOMIC_WIDTH__ 32 +#define __SIZEOF_DOUBLE__ 8 +#define __SIZEOF_FLOAT__ 4 +#define __SIZEOF_INT__ 4 +#define __SIZEOF_LONG_DOUBLE__ 8 +#define __SIZEOF_LONG_LONG__ 8 +#define __SIZEOF_LONG__ 4 +#define __SIZEOF_POINTER__ 4 +#define __SIZEOF_PTRDIFF_T__ 4 +#define __SIZEOF_SHORT__ 2 +#define __SIZEOF_SIZE_T__ 4 +#define __SIZEOF_WCHAR_T__ 4 +#define __SIZEOF_WINT_T__ 4 +#define __SIZE_MAX__ 4294967295U +#define __SIZE_TYPE__ unsigned int +#define __SIZE_WIDTH__ 32 +#define __SSP__ 1 +#define __STDC_HOSTED__ 1 +#define __STDC_UTF_16__ 1 +#define __STDC_UTF_32__ 1 +#define __STDC__ 1 +#define __STRICT_ANSI__ 1 +#define __THUMB_INTERWORK__ 1 +#define __UINTMAX_TYPE__ long long unsigned int +#define __USER_LABEL_PREFIX__ +#define __VERSION__ "4.2.1 Compatible Clang 3.4 (https://bitbucket.org/loganchien/clang c34bb12af3af42f671296cdb978b34b931062d2a) (https://bitbucket.org/loganchien/llvm d09f2eff406d17c86d51db7660bd374cf092e6ed)" +#define __VFP_FP__ 1 +#define __WCHAR_MAX__ 4294967295U +#define __WCHAR_TYPE__ unsigned int +#define __WCHAR_UNSIGNED__ 1 +#define __WCHAR_WIDTH__ 32 +#define __WINT_TYPE__ unsigned int +#define __WINT_UNSIGNED__ 1 +#define __WINT_WIDTH__ 32 +#define __arm 1 +#define __arm__ 1 +#define __clang__ 1 +#define __clang_major__ 3 +#define __clang_minor__ 4 +#define __clang_patchlevel__ 0 +#define __clang_version__ "3.4 (https://bitbucket.org/loganchien/clang c34bb12af3af42f671296cdb978b34b931062d2a) (https://bitbucket.org/loganchien/llvm d09f2eff406d17c86d51db7660bd374cf092e6ed)" +#define __cplusplus 201103L +#define __cpp_attributes 200809 +#define __cpp_constexpr 200704 +#define __cpp_decltype 200707 +#define __cpp_lambdas 200907 +#define __cpp_raw_strings 200710 +#define __cpp_rvalue_references 200610 +#define __cpp_static_assert 200410 +#define __cpp_unicode_characters 200704 +#define __cpp_unicode_literals 200710 +#define __cpp_user_defined_literals 200809 +#define __cpp_variadic_templates 200704 +#define __gnu_linux__ 1 +#define __linux 1 +#define __linux__ 1 +#define __llvm__ 1 +#define __pic__ 1 +#define __private_extern__ extern +#define __unix 1 +#define __unix__ 1 +#define ANDROID +#endif + +// --- Include directories begin --- // +//C:/Android/ndk/platforms/android-3/arch-arm/usr/include +//C:/Users/eayusov/Documents/Sandbox/Common/Android/jni/../../include +//C:\Android\ndk\toolchains\llvm-3.4\prebuilt\windows\bin\..\lib\clang\3.4\include +// --- Library directories end --- // + + +// --- Library directories begin --- // +// --- Library directories begin --- // + diff --git a/Common/build/Windows/Android/gcc_Release.h b/Common/build/Windows/Android/gcc_Release.h new file mode 100644 index 00000000..6ca2abab --- /dev/null +++ b/Common/build/Windows/Android/gcc_Release.h @@ -0,0 +1,380 @@ +/* + This file is only used by IntelliSense (VisualStudio code suggestion system) + DO NOT INCLUDE THIS FILE FROM YOUR ACTUAL SOURCE FILES. + This file lists the preprocessor macros extracted from your GCC. + It is needed for IntelliSense to parse other header files correctly. +*/ +#ifdef _MSC_VER +#define __DBL_MIN_EXP__ (-1021) +#define __HQ_FBIT__ 15 +#define __UINT_LEAST16_MAX__ 65535 +#define __ARM_SIZEOF_WCHAR_T 32 +#define __ATOMIC_ACQUIRE 2 +#define __SFRACT_IBIT__ 0 +#define __FLT_MIN__ 1.1754943508222875e-38F +#define __UFRACT_MAX__ 0XFFFFP-16UR +#define __UINT_LEAST8_TYPE__ unsigned char +#define __DQ_FBIT__ 63 +#define __ARM_FEATURE_SAT 1 +#define __ULFRACT_FBIT__ 32 +#define __SACCUM_EPSILON__ 0x1P-7HK +#define __CHAR_BIT__ 8 +#define __USQ_IBIT__ 0 +#define __UINT8_MAX__ 255 +#define __ACCUM_FBIT__ 15 +#define __ANDROID__ 1 +#define __WINT_MAX__ 4294967295U +#define __USFRACT_FBIT__ 8 +#define __ORDER_LITTLE_ENDIAN__ 1234 +#define __SIZE_MAX__ 4294967295U +#define __ARM_ARCH_ISA_ARM 1 +#define __WCHAR_MAX__ 4294967295U +#define __LACCUM_IBIT__ 32 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 +#define __DBL_DENORM_MIN__ double(4.9406564584124654e-324L) +#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 +#define __GCC_ATOMIC_CHAR_LOCK_FREE 2 +#define __FLT_EVAL_METHOD__ 0 +#define __unix__ 1 +#define __LLACCUM_MAX__ 0X7FFFFFFFFFFFFFFFP-31LLK +#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 +#define __FRACT_FBIT__ 15 +#define __UINT_FAST64_MAX__ 18446744073709551615ULL +#define __SIG_ATOMIC_TYPE__ int +#define __UACCUM_FBIT__ 16 +#define __DBL_MIN_10_EXP__ (-307) +#define __FINITE_MATH_ONLY__ 0 +#define __ARMEL__ 1 +#define __ARM_FEATURE_UNALIGNED 1 +#define __LFRACT_IBIT__ 0 +#define __GNUC_PATCHLEVEL__ 0 +#define __LFRACT_MAX__ 0X7FFFFFFFP-31LR +#define __UINT_FAST8_MAX__ 255 +#define __DEC64_MAX_EXP__ 385 +#define __UINT_LEAST64_MAX__ 18446744073709551615ULL +#define __SA_FBIT__ 15 +#define __SHRT_MAX__ 32767 +#define __LDBL_MAX__ 1.7976931348623157e+308L +#define __FRACT_MAX__ 0X7FFFP-15R +#define __UFRACT_FBIT__ 16 +#define __ARM_FP 12 +#define __UFRACT_MIN__ 0.0UR +#define __UINT_LEAST8_MAX__ 255 +#define __GCC_ATOMIC_BOOL_LOCK_FREE 2 +#define __UINTMAX_TYPE__ long long unsigned int +#define __LLFRACT_EPSILON__ 0x1P-63LLR +#define __linux 1 +#define __DEC32_EPSILON__ 1E-6DF +#define __CHAR_UNSIGNED__ 1 +#define __UINT32_MAX__ 4294967295U +#define __GXX_EXPERIMENTAL_CXX0X__ 1 +#define __ULFRACT_MAX__ 0XFFFFFFFFP-32ULR +#define __TA_IBIT__ 64 +#define __LDBL_MAX_EXP__ 1024 +#define __WINT_MIN__ 0U +#define __linux__ 1 +#define __ULLFRACT_MIN__ 0.0ULLR +#define __SCHAR_MAX__ 127 +#define __WCHAR_MIN__ 0U +#define __DBL_DIG__ 15 +#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +#define __LLACCUM_MIN__ (-0X1P31LLK-0X1P31LLK) +#define __SIZEOF_INT__ 4 +#define __SIZEOF_POINTER__ 4 +#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 +#define __USACCUM_IBIT__ 8 +#define __USER_LABEL_PREFIX__ +#define __STDC_HOSTED__ 1 +#define __LDBL_HAS_INFINITY__ 1 +#define __LFRACT_MIN__ (-0.5LR-0.5LR) +#define __HA_IBIT__ 8 +#define __ARM_NEON_FP 4 +#define __TQ_IBIT__ 0 +#define __FLT_EPSILON__ 1.1920928955078125e-7F +#define __APCS_32__ 1 +#define __GXX_WEAK__ 1 +#define __USFRACT_IBIT__ 0 +#define __LDBL_MIN__ 2.2250738585072014e-308L +#define __FRACT_MIN__ (-0.5R-0.5R) +#define __DEC32_MAX__ 9.999999E96DF +#define __DA_IBIT__ 32 +#define __ARM_SIZEOF_MINIMAL_ENUM 4 +#define __INT32_MAX__ 2147483647 +#define __UQQ_FBIT__ 8 +#define __SIZEOF_LONG__ 4 +#define __UACCUM_MAX__ 0XFFFFFFFFP-16UK +#define __DECIMAL_DIG__ 17 +#define __LFRACT_EPSILON__ 0x1P-31LR +#define __ULFRACT_MIN__ 0.0ULR +#define __LDBL_HAS_QUIET_NAN__ 1 +#define __ULACCUM_IBIT__ 32 +#define __UACCUM_EPSILON__ 0x1P-16UK +#define __GNUC__ 4 +#define __ULLACCUM_MAX__ 0XFFFFFFFFFFFFFFFFP-32ULLK +#define __GXX_RTTI 1 +#define __HQ_IBIT__ 0 +#define __FLT_HAS_DENORM__ 1 +#define __SIZEOF_LONG_DOUBLE__ 8 +#define __BIGGEST_ALIGNMENT__ 8 +#define __GNUC_STDC_INLINE__ 1 +#define __DQ_IBIT__ 0 +#define __DBL_MAX__ double(1.7976931348623157e+308L) +#define __ULFRACT_IBIT__ 0 +#define __INT_FAST32_MAX__ 2147483647 +#define __DBL_HAS_INFINITY__ 1 +#define __INT64_MAX__ 9223372036854775807LL +#define __ACCUM_IBIT__ 16 +#define __DEC32_MIN_EXP__ (-94) +#define __THUMB_INTERWORK__ 1 +#define __LACCUM_MAX__ 0X7FFFFFFFFFFFFFFFP-31LK +#define __INT_FAST16_TYPE__ int +#define __STRICT_ANSI__ 1 +#define __LDBL_HAS_DENORM__ 1 +#define __ARM_FEATURE_LDREX 15 +#define __cplusplus 201103L +#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL +#define __INT_LEAST32_MAX__ 2147483647 +#define __ARM_PCS 1 +#define __DEC32_MIN__ 1E-95DF +#define __ACCUM_MAX__ 0X7FFFFFFFP-15K +#define __DEPRECATED 1 +#define __DBL_MAX_EXP__ 1024 +#define __USACCUM_EPSILON__ 0x1P-8UHK +#define __DEC128_EPSILON__ 1E-33DL +#define __SFRACT_MAX__ 0X7FP-7HR +#define __FRACT_IBIT__ 0 +#define __PTRDIFF_MAX__ 2147483647 +#define __UACCUM_MIN__ 0.0UK +#define __UACCUM_IBIT__ 16 +#define __GNUG__ 4 +#define __LONG_LONG_MAX__ 9223372036854775807LL +#define __SIZEOF_SIZE_T__ 4 +#define __ULACCUM_MAX__ 0XFFFFFFFFFFFFFFFFP-32ULK +#define __SIZEOF_WINT_T__ 4 +#define __SA_IBIT__ 16 +#define __ULLACCUM_MIN__ 0.0ULLK +#define __GXX_ABI_VERSION 1002 +#define __UTA_FBIT__ 64 +#define __FLT_MIN_EXP__ (-125) +#define __USFRACT_MAX__ 0XFFP-8UHR +#define __UFRACT_IBIT__ 0 +#define __ARM_FEATURE_QBIT 1 +#define __INT_FAST64_TYPE__ long long int +#define __DBL_MIN__ double(2.2250738585072014e-308L) +#define __FLT_MIN_10_EXP__ (-37) +#define __LACCUM_MIN__ (-0X1P31LK-0X1P31LK) +#define __ULLACCUM_FBIT__ 32 +#define __GXX_TYPEINFO_EQUALITY_INLINE 0 +#define __ULLFRACT_EPSILON__ 0x1P-64ULLR +#define __DEC128_MIN__ 1E-6143DL +#define __REGISTER_PREFIX__ +#define __UINT16_MAX__ 65535 +#define __DBL_HAS_DENORM__ 1 +#define __ACCUM_MIN__ (-0X1P15K-0X1P15K) +#define __SQ_IBIT__ 0 +#define __UINT8_TYPE__ unsigned char +#define __UHA_FBIT__ 8 +#define __NO_INLINE__ 1 +#define __SFRACT_MIN__ (-0.5HR-0.5HR) +#define __UTQ_FBIT__ 128 +#define __FLT_MANT_DIG__ 24 +#define __VERSION__ "4.8" +#define __ULLFRACT_FBIT__ 64 +#define __FRACT_EPSILON__ 0x1P-15R +#define __ULACCUM_MIN__ 0.0ULK +#define __UDA_FBIT__ 32 +#define __LLACCUM_EPSILON__ 0x1P-31LLK +#define __GCC_ATOMIC_INT_LOCK_FREE 2 +#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __USFRACT_MIN__ 0.0UHR +#define __ULLACCUM_IBIT__ 32 +#define __UQQ_IBIT__ 0 +#define __DEC64_EPSILON__ 1E-15DD +#define __ORDER_PDP_ENDIAN__ 3412 +#define __DEC128_MIN_EXP__ (-6142) +#define __UHQ_FBIT__ 16 +#define __LLACCUM_FBIT__ 31 +#define __INT_FAST32_TYPE__ int +#define __UINT_LEAST16_TYPE__ short unsigned int +#define __INT16_MAX__ 32767 +#define __SIZE_TYPE__ unsigned int +#define __UINT64_MAX__ 18446744073709551615ULL +#define __UDQ_FBIT__ 64 +#define __INT8_TYPE__ signed char +#define __ELF__ 1 +#define __ULFRACT_EPSILON__ 0x1P-32ULR +#define __LLFRACT_FBIT__ 63 +#define __FLT_RADIX__ 2 +#define __INT_LEAST16_TYPE__ short int +#define __ARM_ARCH_PROFILE 65 +#define __LDBL_EPSILON__ 2.2204460492503131e-16L +#define __SACCUM_MAX__ 0X7FFFP-7HK +#define __SIG_ATOMIC_MAX__ 2147483647 +#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +#define __VFP_FP__ 1 +#define __SIZEOF_PTRDIFF_T__ 4 +#define __LACCUM_EPSILON__ 0x1P-31LK +#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF +#define __INT_FAST16_MAX__ 2147483647 +#define __UINT_FAST32_MAX__ 4294967295U +#define __UINT_LEAST64_TYPE__ long long unsigned int +#define __USACCUM_MAX__ 0XFFFFP-8UHK +#define __SFRACT_EPSILON__ 0x1P-7HR +#define __FLT_HAS_QUIET_NAN__ 1 +#define __FLT_MAX_10_EXP__ 38 +#define __LONG_MAX__ 2147483647L +#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL +#define __FLT_HAS_INFINITY__ 1 +#define __unix 1 +#define __USA_FBIT__ 16 +#define __UINT_FAST16_TYPE__ unsigned int +#define __DEC64_MAX__ 9.999999999999999E384DD +#define __CHAR16_TYPE__ short unsigned int +#define __PRAGMA_REDEFINE_EXTNAME 1 +#define __INT_LEAST16_MAX__ 32767 +#define __DEC64_MANT_DIG__ 16 +#define __UINT_LEAST32_MAX__ 4294967295U +#define __SACCUM_FBIT__ 7 +#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +#define __INT_LEAST64_TYPE__ long long int +#define __ARM_FEATURE_CLZ 1 +#define __INT16_TYPE__ short int +#define __INT_LEAST8_TYPE__ signed char +#define __SQ_FBIT__ 31 +#define __DEC32_MAX_EXP__ 97 +#define __ARM_ARCH_ISA_THUMB 2 +#define __INT_FAST8_MAX__ 127 +#define __ARM_ARCH 7 +#define __INTPTR_MAX__ 2147483647 +#define __QQ_FBIT__ 7 +#define __UTA_IBIT__ 64 +#define __EXCEPTIONS 1 +#define __LDBL_MANT_DIG__ 53 +#define __SFRACT_FBIT__ 7 +#define __SACCUM_MIN__ (-0X1P7HK-0X1P7HK) +#define __DBL_HAS_QUIET_NAN__ 1 +#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1) +#define __INTPTR_TYPE__ int +#define __UINT16_TYPE__ short unsigned int +#define __WCHAR_TYPE__ unsigned int +#define __SIZEOF_FLOAT__ 4 +#define __USQ_FBIT__ 32 +#define __pic__ 1 +#define __UINTPTR_MAX__ 4294967295U +#define __DEC64_MIN_EXP__ (-382) +#define __INT_FAST64_MAX__ 9223372036854775807LL +#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +#define __FLT_DIG__ 6 +#define __UINT_FAST64_TYPE__ long long unsigned int +#define __INT_MAX__ 2147483647 +#define __LACCUM_FBIT__ 31 +#define __USACCUM_MIN__ 0.0UHK +#define __UHA_IBIT__ 8 +#define __INT64_TYPE__ long long int +#define __FLT_MAX_EXP__ 128 +#define __UTQ_IBIT__ 0 +#define __DBL_MANT_DIG__ 53 +#define __INT_LEAST64_MAX__ 9223372036854775807LL +#define __DEC64_MIN__ 1E-383DD +#define __WINT_TYPE__ unsigned int +#define __UINT_LEAST32_TYPE__ unsigned int +#define __SIZEOF_SHORT__ 2 +#define __ULLFRACT_IBIT__ 0 +#define __LDBL_MIN_EXP__ (-1021) +#define __arm__ 1 +#define __UDA_IBIT__ 32 +#define __INT_LEAST8_MAX__ 127 +#define __SSP__ 1 +#define __LFRACT_FBIT__ 31 +#define __WCHAR_UNSIGNED__ 1 +#define __ARM_ARCH_7A__ 1 +#define __LDBL_MAX_10_EXP__ 308 +#define __ATOMIC_RELAXED 0 +#define __DBL_EPSILON__ double(2.2204460492503131e-16L) +#define __ARM_FEATURE_SIMD32 1 +#define __INT_LEAST32_TYPE__ int +#define __SIZEOF_WCHAR_T__ 4 +#define __UINT64_TYPE__ long long unsigned int +#define __LLFRACT_MAX__ 0X7FFFFFFFFFFFFFFFP-63LLR +#define __TQ_FBIT__ 127 +#define __INT_FAST8_TYPE__ signed char +#define __ULLACCUM_EPSILON__ 0x1P-32ULLK +#define __UHQ_IBIT__ 0 +#define __LLACCUM_IBIT__ 32 +#define __DBL_DECIMAL_DIG__ 17 +#define __DEC_EVAL_METHOD__ 2 +#define __TA_FBIT__ 63 +#define __UDQ_IBIT__ 0 +#define __ORDER_BIG_ENDIAN__ 4321 +#define __ACCUM_EPSILON__ 0x1P-15K +#define __INTMAX_MAX__ 9223372036854775807LL +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __FLT_DENORM_MIN__ 1.4012984643248171e-45F +#define __LLFRACT_IBIT__ 0 +#define __INT8_MAX__ 127 +#define __PIC__ 1 +#define __UINT_FAST32_TYPE__ unsigned int +#define __CHAR32_TYPE__ unsigned int +#define __FLT_MAX__ 3.4028234663852886e+38F +#define __USACCUM_FBIT__ 8 +#define __INT32_TYPE__ int +#define __SIZEOF_DOUBLE__ 8 +#define __UFRACT_EPSILON__ 0x1P-16UR +#define __INTMAX_TYPE__ long long int +#define __DEC128_MAX_EXP__ 6145 +#define __ATOMIC_CONSUME 1 +#define __GNUC_MINOR__ 8 +#define __UINTMAX_MAX__ 18446744073709551615ULL +#define __DEC32_MANT_DIG__ 7 +#define __HA_FBIT__ 7 +#define __DBL_MAX_10_EXP__ 308 +#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L +#define __STDC__ 1 +#define __PTRDIFF_TYPE__ int +#define __LLFRACT_MIN__ (-0.5LLR-0.5LLR) +#define __ATOMIC_SEQ_CST 5 +#define __DA_FBIT__ 31 +#define __UINT32_TYPE__ unsigned int +#define __UINTPTR_TYPE__ unsigned int +#define __USA_IBIT__ 16 +#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD +#define __ARM_EABI__ 1 +#define __DEC128_MANT_DIG__ 34 +#define __LDBL_MIN_10_EXP__ (-307) +#define __SIZEOF_LONG_LONG__ 8 +#define __ULACCUM_EPSILON__ 0x1P-32ULK +#define __SACCUM_IBIT__ 8 +#define __GCC_ATOMIC_LLONG_LOCK_FREE 2 +#define __LDBL_DIG__ 15 +#define __FLT_DECIMAL_DIG__ 9 +#define __UINT_FAST16_MAX__ 4294967295U +#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +#define __ULLFRACT_MAX__ 0XFFFFFFFFFFFFFFFFP-64ULLR +#define __UINT_FAST8_TYPE__ unsigned char +#define _GNU_SOURCE 1 +#define __USFRACT_EPSILON__ 0x1P-8UHR +#define __ULACCUM_FBIT__ 32 +#define __ARM_FEATURE_DSP 1 +#define __QQ_IBIT__ 0 +#define __ATOMIC_ACQ_REL 4 +#define __ATOMIC_RELEASE 3 +#define ANDROID +#endif + +// --- Include directories begin --- // +//C:/Android/ndk/platforms/android-3/arch-arm/usr/include +//C:\Android\ndk\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\bin\../lib/gcc/arm-linux-androideabi/4.8/include +//C:\Android\ndk\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\bin\../lib/gcc/arm-linux-androideabi/4.8/include-fixed +// --- Library directories end --- // + + +// --- Library directories begin --- // +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/armv7-a/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/lib/armv7-a/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/ +//C:/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/lib/ +// --- Library directories begin --- // + diff --git a/Common/build/Windows/Common-Debug.vgdbsettings b/Common/build/Windows/Common-Debug.vgdbsettings new file mode 100644 index 00000000..3f5b24b1 --- /dev/null +++ b/Common/build/Windows/Common-Debug.vgdbsettings @@ -0,0 +1,76 @@ + + + Debug + + + + MinGWWindowsSlash + + $(ProjectDir) + + + android-19 + true + true + bin;obj + false + false + + + + + + false + false + true + false + false + false + false + true + false + KillApp + + false + false + false + false + false + false + false + false + + false + false + main + true + + + false + false + 5039 + 5039 + 10000 + 0 + false + Ask + true + true + + + + + + + + + + + Default + + + + true + + + \ No newline at end of file diff --git a/Common/build/Windows/Common-Release.vgdbsettings b/Common/build/Windows/Common-Release.vgdbsettings new file mode 100644 index 00000000..669691f2 --- /dev/null +++ b/Common/build/Windows/Common-Release.vgdbsettings @@ -0,0 +1,76 @@ + + + Release + + + + MinGWWindowsSlash + + $(ProjectDir) + + + android-19 + false + true + bin;obj + false + false + + + + + + false + false + true + false + false + false + false + true + false + KillApp + + false + false + false + false + false + false + false + false + + false + false + main + true + + + false + false + 5039 + 5039 + 10000 + 0 + false + Ask + true + true + + + + + + + + + + + Default + + + + true + + + \ No newline at end of file diff --git a/Common/build/Windows/Common.props b/Common/build/Windows/Common.props new file mode 100644 index 00000000..ad29ccfc --- /dev/null +++ b/Common/build/Windows/Common.props @@ -0,0 +1,10 @@ + + + + + + $(EngineRoot)\Common\include;$(EngineRoot)\Platforms\interface;$(EngineRoot)\Common\interface;$(VC_IncludePath);$(WindowsSDK_IncludePath) + + + + \ No newline at end of file diff --git a/Common/build/Windows/Common.vcxproj b/Common/build/Windows/Common.vcxproj new file mode 100644 index 00000000..2d71da17 --- /dev/null +++ b/Common/build/Windows/Common.vcxproj @@ -0,0 +1,200 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + {7380F7E6-315F-4B4E-92EB-E6AEEE865298} + Win32Proj + Common + + + + StaticLibrary + true + Unicode + v140 + + + StaticLibrary + true + Unicode + v140 + + + StaticLibrary + false + true + Unicode + v140 + + + StaticLibrary + false + true + Unicode + v140 + + + v120 + Makefile + + + v120 + Makefile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(ProjectDir)\Android\gcc_Debug.h;$(NMakeForcedIncludes) + + + $(ProjectDir)\Android\gcc_Release.h;$(NMakeForcedIncludes) + + + + Level3 + Disabled + WIN32;_LIB;%(PreprocessorDefinitions) + + + Windows + true + + + + + Level3 + Disabled + WIN32;_LIB;%(PreprocessorDefinitions) + + + Windows + true + + + MachineX64 + + + + + Level3 + MaxSpeed + true + true + WIN32;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + Level3 + MaxSpeed + true + true + WIN32;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + MachineX64 + + + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + + + + + + + + + \ No newline at end of file diff --git a/Common/build/Windows/Common.vcxproj.filters b/Common/build/Windows/Common.vcxproj.filters new file mode 100644 index 00000000..f8faf086 --- /dev/null +++ b/Common/build/Windows/Common.vcxproj.filters @@ -0,0 +1,34 @@ + + + + + {4866efaf-48ac-439f-9a2c-8b8ec11cace8} + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + android_src + + + android_src + + + android_src + + + + + jni + + + jni + + + jni + + + \ No newline at end of file diff --git a/Common/build/Windows/EngineRoot.props b/Common/build/Windows/EngineRoot.props new file mode 100644 index 00000000..afee36ca --- /dev/null +++ b/Common/build/Windows/EngineRoot.props @@ -0,0 +1,14 @@ + + + + + ..\..\.. + + + + + + $(EngineRoot) + + + \ No newline at end of file diff --git a/Common/build/Windows/jni/Android.mk b/Common/build/Windows/jni/Android.mk new file mode 100644 index 00000000..1699a5c3 --- /dev/null +++ b/Common/build/Windows/jni/Android.mk @@ -0,0 +1,27 @@ +# Android NDK project makefile autogenerated by Premake + +# Preamble +DEPENDENCY_PATH := $(call my-dir) +LOCAL_PATH := $(abspath $(DEPENDENCY_PATH)) +include $(CLEAR_VARS) + + +# Project configuration +LOCAL_MODULE := Common +LOCAL_CFLAGS := -std=c++11 +LOCAL_CPP_FEATURES := exceptions +LOCAL_STATIC_LIBRARIES += ndk_helper native_app_glue + +# Include paths +PROJECT_ROOT := $(LOCAL_PATH)/../../.. +SOLUTION_ROOT := $(PROJECT_ROOT)/.. +LOCAL_C_INCLUDES := $(PROJECT_ROOT)/include $(PROJECT_ROOT)/interface $(SOLUTION_ROOT)/Platforms/interface + +# Source files +#VisualGDBAndroid: AutoUpdateSourcesInNextLine +LOCAL_SRC_FILES := ../../../src/BasicFileStream.cpp ../../../src/DataBlobImpl.cpp ../../../src/Timer.cpp + +include $(BUILD_STATIC_LIBRARY) + +$(call import-module,android/ndk_helper) +$(call import-module,android/native_app_glue) diff --git a/Common/build/Windows/jni/Application.mk b/Common/build/Windows/jni/Application.mk new file mode 100644 index 00000000..65194f02 --- /dev/null +++ b/Common/build/Windows/jni/Application.mk @@ -0,0 +1,7 @@ +# Generated by VisualGDB + +DEPENDENCY_PATH := $(call my-dir) +LOCAL_PATH := $(abspath $(DEPENDENCY_PATH)) +include $(LOCAL_PATH)/../../../make/AppCommon.mk + +APP_MODULES := Common \ No newline at end of file diff --git a/Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems b/Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems new file mode 100644 index 00000000..625b3fab --- /dev/null +++ b/Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems @@ -0,0 +1,54 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {d716bf4d-094b-47d7-9137-a01c690c3616} + Common + Common.Shared + 248F659F-DAC5-46E8-AC09-60EC9FC95053 + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + + + + \ No newline at end of file diff --git a/Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems.filters b/Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems.filters new file mode 100644 index 00000000..fd2552f3 --- /dev/null +++ b/Common/build/WindowsStore/Common.Shared/Common.Shared.vcxitems.filters @@ -0,0 +1,105 @@ + + + + + {ead2d246-9a64-4464-b0aa-593b59ef6c6c} + + + {c24fd6ae-babf-4fe7-a0af-93c5ef12ba32} + + + {bf40c456-a95e-4513-9842-fef2d752825a} + + + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + interface + + + interface + + + include + + + interface + + + include + + + include + + + interface + + + include + + + include + + + include + + + include + + + include + + + + + src + + + src + + + src + + + src + + + \ No newline at end of file diff --git a/Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj b/Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj new file mode 100644 index 00000000..e0326fe8 --- /dev/null +++ b/Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj @@ -0,0 +1,205 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + {4f9e9c58-6840-4f2f-a456-dd039fc790a4} + Common + en-US + 12.0 + true + Windows Store + 8.1 + CodeSharingStaticLibrary + + + + StaticLibrary + true + v120 + + + StaticLibrary + true + v120 + + + StaticLibrary + true + v120 + + + StaticLibrary + false + true + v120 + + + StaticLibrary + false + true + v120 + + + StaticLibrary + false + true + v120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + false + + + false + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + + \ No newline at end of file diff --git a/Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj.filters b/Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj.filters new file mode 100644 index 00000000..a7761ab0 --- /dev/null +++ b/Common/build/WindowsStore/Common.Windows/Common.Windows.vcxproj.filters @@ -0,0 +1,5 @@ + + + + + diff --git a/Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj b/Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj new file mode 100644 index 00000000..c1456120 --- /dev/null +++ b/Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj @@ -0,0 +1,144 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Release + ARM + + + Release + Win32 + + + + {8b4477c9-e00b-48ce-bd60-ed694593cd85} + Common + en-US + 12.0 + true + Windows Phone + 8.1 + CodeSharingStaticLibrary + + + + StaticLibrary + true + v120_wp81 + + + StaticLibrary + true + v120_wp81 + + + StaticLibrary + false + true + v120_wp81 + + + StaticLibrary + false + true + v120_wp81 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + Use + false + true + + + Console + false + false + + + + + + \ No newline at end of file diff --git a/Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj.filters b/Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj.filters new file mode 100644 index 00000000..a7761ab0 --- /dev/null +++ b/Common/build/WindowsStore/Common.WindowsPhone/Common.WindowsPhone.vcxproj.filters @@ -0,0 +1,5 @@ + + + + + diff --git a/Common/build/WindowsStore/EngineRoot.props b/Common/build/WindowsStore/EngineRoot.props new file mode 100644 index 00000000..c2337431 --- /dev/null +++ b/Common/build/WindowsStore/EngineRoot.props @@ -0,0 +1,14 @@ + + + + + ..\..\..\.. + + + + + + $(EngineRoot) + + + \ No newline at end of file diff --git a/Common/include/BasicFileStream.h b/Common/include/BasicFileStream.h new file mode 100644 index 00000000..85f685a5 --- /dev/null +++ b/Common/include/BasicFileStream.h @@ -0,0 +1,66 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the Diligent::BasicFileStream class + +#include "FileStream.h" +#include "ObjectBase.h" +#include "RefCountedObjectImpl.h" +#include "FileWrapper.h" +#include "DataBlob.h" + +namespace Diligent +{ + +/// Basic file stream implementation +class BasicFileStream : public ObjectBase +{ +public: + typedef ObjectBase TBase; + + BasicFileStream(const Diligent::Char *Path, + EFileAccessMode Access = EFileAccessMode::Read); + + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; + + /// Reads data from the stream + virtual void Read( Diligent::IDataBlob *pData )override; + + /// Reads data from the stream + virtual bool Read( void *Data, size_t BufferSize )override; + + /// Writes data to the stream + virtual bool Write( const void *Data, size_t Size )override; + + virtual size_t GetSize()override; + + virtual bool IsValid()override; + +private: + Diligent::FileWrapper m_FileWrpr; +}; + +} diff --git a/Common/include/BasicTypes.h b/Common/include/BasicTypes.h new file mode 100644 index 00000000..7d3bea3d --- /dev/null +++ b/Common/include/BasicTypes.h @@ -0,0 +1,52 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include +#include + +namespace Diligent +{ + typedef float Float32; + + typedef int64_t Int64; + typedef int32_t Int32; + typedef int16_t Int16; + typedef int8_t Int8; + + typedef uint64_t Uint64; + typedef uint32_t Uint32; + typedef uint16_t Uint16; + typedef uint8_t Uint8; + + typedef size_t SizeType; + typedef void* PVoid; + + typedef bool Bool; + static const Bool False = false; + static const Bool True = true; + + typedef char Char; + typedef std::basic_string String; +} diff --git a/Common/include/DataBlobImpl.h b/Common/include/DataBlobImpl.h new file mode 100644 index 00000000..d9441588 --- /dev/null +++ b/Common/include/DataBlobImpl.h @@ -0,0 +1,58 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation for the IDataBlob interface + +#include "DataBlob.h" +#include "BasicTypes.h" +#include "ObjectBase.h" +#include + +namespace Diligent +{ + +/// Base interface for a file stream +class DataBlobImpl : public Diligent::ObjectBase +{ +public: + typedef Diligent::ObjectBase TBase; + + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; + + /// Sets the size of the internal data buffer + virtual void Resize( size_t NewSize )override; + + /// Returns the size of the internal data buffer + virtual size_t GetSize()override; + + /// Returns the pointer to the internal data buffer + virtual void* GetDataPtr()override; + +private: + std::vector m_DataBuff; +}; + +} diff --git a/Common/include/DebugUtilities.h b/Common/include/DebugUtilities.h new file mode 100644 index 00000000..d57fd06b --- /dev/null +++ b/Common/include/DebugUtilities.h @@ -0,0 +1,66 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "FormatMessage.h" +#include "PlatformDebug.h" + +#ifdef _DEBUG + +// This function is only requried to ensure that Message argument passed to the macro +// is actually string and not something else +inline void EnsureStr( const char* ){} +# define VERIFY(Expr, Message, ...)\ + { \ + if( !(Expr) ) \ + { \ + Diligent::MsgStream ms; \ + Diligent::FormatMsg( ms, Message, ##__VA_ARGS__);\ + PlatformDebug::AssertionFailed( ms.str().c_str(), __FUNCTION__, __FILE__, __LINE__); \ + } \ + EnsureStr(Message); \ + } +# define UNEXPECTED(Message, ...) { VERIFY(false, Message, ##__VA_ARGS__); } +# define UNSUPPORTED(Message, ...) { VERIFY(false, Message, ##__VA_ARGS__); } + +# define VERIFY_EXPR(Expr) VERIFY(Expr, "Debug exression failed:\n", #Expr) + + +template +void CheckDynamicType( SrcType *pSrcPtr ) +{ + VERIFY( pSrcPtr == nullptr || dynamic_cast (pSrcPtr) != nullptr, "Dynamic type cast failed!" ); +} +# define CHECK_DYNAMIC_TYPE(DstType, pSrcPtr) CheckDynamicType(pSrcPtr) + + +#else + +# define CHECK_DYNAMIC_TYPE(...){} +# define VERIFY(...){} +# define UNEXPECTED(...){} +# define UNSUPPORTED(...){} +# define VERIFY_EXPR(...){} + +#endif diff --git a/Common/include/Errors.h b/Common/include/Errors.h new file mode 100644 index 00000000..658adb0e --- /dev/null +++ b/Common/include/Errors.h @@ -0,0 +1,67 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include + +#include "PlatformDebug.h" +#include "FormatMessage.h" +#include "FileSystem.h" + +template +void LogError( const char *strFunctionName, const char *strFullFilePath, int Line, const FirstArgType& first, const RestArgsType&... RestArgs ) +{ + std::string FileName; + FileSystem::SplitFilePath( strFullFilePath, nullptr, &FileName ); + Diligent::MsgStream ss; + ss << "The following error occured in the " << strFunctionName << "() function (" << FileName << ", line " << Line << "):\n"; + Diligent::FormatMsg( ss, first, RestArgs... ); + auto strFullMessage = ss.str(); + PlatformDebug::OutputDebugMessage( bThrowException ? PlatformDebug::DebugMessageSeverity::FatalError : PlatformDebug::DebugMessageSeverity::Error, strFullMessage.c_str() ); + if( bThrowException ) + { + throw std::runtime_error( strFullMessage ); + } +} + +#define LOG_ERROR(...)\ +{ \ + LogError(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ +} + +#define LOG_ERROR_AND_THROW(...) \ +{ \ + LogError(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ +} + +#define LOG_DEBUG_MESSAGE(Severity, ...) \ +{ \ + Diligent::MsgStream ss; \ + Diligent::FormatMsg( ss, ##__VA_ARGS__ ); \ + PlatformDebug::OutputDebugMessage( Severity, ss.str().c_str() ); \ +} + +#define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(PlatformDebug::DebugMessageSeverity::Error, ##__VA_ARGS__) +#define LOG_WARNING_MESSAGE(...) LOG_DEBUG_MESSAGE(PlatformDebug::DebugMessageSeverity::Warning, ##__VA_ARGS__) +#define LOG_INFO_MESSAGE(...) LOG_DEBUG_MESSAGE(PlatformDebug::DebugMessageSeverity::Info, ##__VA_ARGS__) diff --git a/Common/include/FileWrapper.h b/Common/include/FileWrapper.h new file mode 100644 index 00000000..85851d89 --- /dev/null +++ b/Common/include/FileWrapper.h @@ -0,0 +1,91 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "FileSystem.h" +#include "Errors.h" +#include "DebugUtilities.h" + +namespace Diligent +{ + +class FileWrapper +{ +public: + FileWrapper( ) : + m_pFile(nullptr) + {} + + FileWrapper( const Diligent::Char *Path, + EFileAccessMode Access = EFileAccessMode::Read) : + m_pFile( nullptr ) + { + FileOpenAttribs OpenAttribs(Path, Access); + Open(OpenAttribs); + } + + ~FileWrapper() + { + Close(); + } + + void Open(const FileOpenAttribs& OpenAttribs) + { + VERIFY( !m_pFile, "Another file already attached" ); + Close(); + m_pFile = FileSystem::OpenFile( OpenAttribs ); + } + + CFile *Detach() + { + CFile *pFile = m_pFile; + m_pFile = NULL; + return pFile; + } + + void Attach(CFile *pFile) + { + VERIFY(!m_pFile, "Another file already attached"); + Close(); + m_pFile = pFile; + } + + void Close() + { + if( m_pFile ) + FileSystem::ReleaseFile(m_pFile); + m_pFile = nullptr; + } + + operator CFile*(){return m_pFile;} + CFile* operator->(){return m_pFile;} + +private: + FileWrapper(const FileWrapper&); + const FileWrapper& operator=(const FileWrapper&); + + CFile *m_pFile; +}; + +} diff --git a/Common/include/FormatMessage.h b/Common/include/FormatMessage.h new file mode 100644 index 00000000..a20435ae --- /dev/null +++ b/Common/include/FormatMessage.h @@ -0,0 +1,44 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include + +namespace Diligent +{ + typedef std::stringstream MsgStream; + + template + void FormatMsg( SSType &ss, const ArgType& Arg ) + { + ss << Arg; + } + + template + void FormatMsg( SSType &ss, const FirstArgType& FirstArg, const RestArgsType&... RestArgs ) + { + FormatMsg( ss, FirstArg ); + FormatMsg( ss, RestArgs... ); // recursive call using pack expansion syntax + } +} \ No newline at end of file diff --git a/Common/include/HashUtils.h b/Common/include/HashUtils.h new file mode 100644 index 00000000..03cf54b6 --- /dev/null +++ b/Common/include/HashUtils.h @@ -0,0 +1,195 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include +#include + +#define LOG_HASH_CONFLICTS 1 + +namespace Diligent +{ + // http://www.boost.org/doc/libs/1_35_0/doc/html/hash/combine.html + template + void HashCombine(std::size_t &Seed, const T& Val) + { + Seed ^= std::hash()(Val) + 0x9e3779b9 + (Seed << 6) + (Seed >> 2); + } + + template + void HashCombine( std::size_t &Seed, const FirstArgType& FirstArg, const RestArgsType&... RestArgs ) + { + HashCombine( Seed, FirstArg ); + HashCombine( Seed, RestArgs... ); // recursive call using pack expansion syntax + } + + template + std::size_t ComputeHash( const ArgsType&... Args ) + { + std::size_t Seed = 0; + HashCombine( Seed, Args... ); + return Seed; + } + + template + struct CStringHash + { + size_t operator()( const CharType *str ) const + { + // http://www.cse.yorku.ca/~oz/hash.html + std::size_t Seed = 0; + while( size_t Ch = *(str++) ) + Seed = Seed * 65599 + Ch; + return Seed; + } + }; + + template + struct CStringCompare + { + bool operator()( const Char *str1, const Char *str2 )const + { + UNSUPPORTED( "Template specialization is not implemented" ) + return false; + } + }; + + template<> + struct CStringCompare + { + bool operator()( const Char *str1, const Char *str2 )const + { + return strcmp( str1, str2 ) == 0; + } + }; + + /// This helper structure is intended to facilitate using strings as a + /// hash table key. It provides constructors that can make a copy of the + /// source string or just keep pointer to it, which enables searching in + /// the hash using raw const Char* pointers. + struct HashMapStringKey + { + public: + // This constructor can perform implicit const Char* -> HashMapStringKey + // conversion without copying the string + HashMapStringKey(const Char* Str, bool bMakeCopy = false) : + StrPtr(nullptr), + Hash(0) + { + VERIFY( Str, "String pointer cannot be null" ); + if( bMakeCopy ) + { + MakeCopy( Str ); + } + else + { + StrPtr = Str; + } + } + + explicit // Make this constructor explicit to avoid unintentional string copies + HashMapStringKey(const String &Str) : + StrPtr( nullptr ), + Hash(0) + { + MakeCopy( Str.c_str() ); + } + + HashMapStringKey(HashMapStringKey &&Key) : + StringBuff( std::move(Key.StringBuff) ), + StrPtr( std::move(Key.StrPtr) ), + Hash(0) + { + Key.StrPtr = nullptr; + Key.Hash = 0; + } + + // Disable copy constuctor and assignments. The struct is designed + // to be initialized at creation time only + HashMapStringKey( const HashMapStringKey& ) = delete; + HashMapStringKey& operator = ( const HashMapStringKey& ) = delete; + HashMapStringKey& operator = ( HashMapStringKey&& ) = delete; + + // Comparison operator + bool operator == (const HashMapStringKey& RHS)const + { + if( StrPtr == RHS.StrPtr ) + return true; + + // Hash member might not have been initialized + if( (Hash != 0 && RHS.Hash !=0 && Hash != RHS.Hash) || StrPtr == nullptr || RHS.StrPtr == nullptr ) + return false; + + bool IsEqual = strcmp( StrPtr, RHS.StrPtr ) == 0; + +#if LOG_HASH_CONFLICTS + if( Hash != 0 && RHS.Hash !=0 && Hash == RHS.Hash && !IsEqual ) + { + LOG_WARNING_MESSAGE("Unequal strings \"", StrPtr, "\" and \"", RHS.StrPtr, "\" hashed to the same bucket. " + "You may want to use better hash function. You may disable this warning by defining LOG_HASH_CONFLICTS to 0"); + } +#endif + return IsEqual; + } + + size_t GetHash()const + { + if( Hash == 0 ) + Hash = CStringHash()(StrPtr); + + return Hash; + } + + const Char* GetStr()const{ return StrPtr; } + + private: + void MakeCopy( const Char* Str ) + { + auto LenWithZeroTerm = strlen( Str ) + 1; + StringBuff.reset( new char[ LenWithZeroTerm ] ); + memcpy( StringBuff.get(), Str, LenWithZeroTerm ); + StrPtr = StringBuff.get(); + } + + // !!! WARNING !!! + // We can't use String to store the buffer, because String default + // constructor always allocates memory even when the string is empty, + // nor can we use vector for the same reason + std::unique_ptr< Char[] > StringBuff; // Must be declared first + const Char* StrPtr;// Must be declared after StringBuff + mutable size_t Hash; + }; +} + +namespace std +{ + template<> + struct hash + { + size_t operator()( const Diligent::HashMapStringKey &Key ) const + { + return Key.GetHash(); + } + }; +} diff --git a/Common/include/InterfaceID.h b/Common/include/InterfaceID.h new file mode 100644 index 00000000..ce426b5e --- /dev/null +++ b/Common/include/InterfaceID.h @@ -0,0 +1,50 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "BasicTypes.h" + +/// Unique identification structures +namespace Diligent +{ + /// Describes unique identifier + struct INTERFACE_ID + { + Diligent::Uint32 Data1; + Diligent::Uint16 Data2; + Diligent::Uint16 Data3; + Diligent::Uint8 Data4[8]; + + bool operator == (const INTERFACE_ID& rhs)const + { + return Data1 == rhs.Data1 && + Data2 == rhs.Data2 && + Data3 == rhs.Data3 && + memcmp(Data4, rhs.Data4, sizeof(Data4)) == 0; + } + }; + + /// Unknown interface + static const INTERFACE_ID IID_Unknown = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }; +} diff --git a/Common/include/LockHelper.h b/Common/include/LockHelper.h new file mode 100644 index 00000000..5f27aad3 --- /dev/null +++ b/Common/include/LockHelper.h @@ -0,0 +1,133 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "Atomics.h" + +namespace ThreadingTools +{ + +class LockFlag +{ +public: + enum {LOCK_FLAG_UNLOCKED = 0, LOCK_FLAG_LOCKED = 1}; + LockFlag(Atomics::Long InitFlag = LOCK_FLAG_UNLOCKED) + { + m_Flag.store(InitFlag); + } + + operator Atomics::Long()const{return m_Flag;} + +private: + friend class LockHelper; + Atomics::AtomicLong m_Flag; +}; + +class LockHelper +{ +public: + + LockHelper() : + m_pLockFlag(nullptr) + { + } + LockHelper(LockFlag &LockFlag) : + m_pLockFlag(nullptr) + { + Lock(LockFlag); + } + + LockHelper( LockHelper &&LockHelper ) : + m_pLockFlag( std::move(LockHelper.m_pLockFlag) ) + { + LockHelper.m_pLockFlag = nullptr; + } + + const LockHelper& operator = (LockHelper &&LockHelper) + { + m_pLockFlag = std::move( LockHelper.m_pLockFlag ); + LockHelper.m_pLockFlag = nullptr; + return *this; + } + + ~LockHelper() + { + Unlock(); + } + + static bool UnsafeTryLock(LockFlag &LockFlag) + { + return Atomics::AtomicCompareExchange( LockFlag.m_Flag, + static_cast( LockFlag::LOCK_FLAG_LOCKED ), + static_cast( LockFlag::LOCK_FLAG_UNLOCKED) ) == LockFlag::LOCK_FLAG_UNLOCKED; + } + + bool TryLock(LockFlag &LockFlag) + { + if( UnsafeTryLock( LockFlag) ) + { + m_pLockFlag = &LockFlag; + return true; + } + else + return false; + } + + static void UnsafeLock(LockFlag &LockFlag) + { + while( !UnsafeTryLock( LockFlag ) ) + /*Sleep(5)*/ + // TODO + ; + } + + void Lock(LockFlag &LockFlag) + { + VERIFY( m_pLockFlag == NULL, "Object already locked" ); + // Wait for the flag to become unlocked and lock it + while( !TryLock( LockFlag ) ) + /*Sleep(5)*/ + // TODO + ; + } + + static void UnsafeUnlock(LockFlag &LockFlag) + { + LockFlag.m_Flag = LockFlag::LOCK_FLAG_UNLOCKED; + } + + void Unlock() + { + if( m_pLockFlag ) + UnsafeUnlock(*m_pLockFlag); + m_pLockFlag = NULL; + } + +private: + LockFlag *m_pLockFlag; + LockHelper( const LockHelper &LockHelper ); + const LockHelper& operator = ( const LockHelper &LockHelper ); +}; + +} diff --git a/Common/include/ObjectBase.h b/Common/include/ObjectBase.h new file mode 100644 index 00000000..c7de28c8 --- /dev/null +++ b/Common/include/ObjectBase.h @@ -0,0 +1,83 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the Diligent::ObjectBase template class + +#include "Object.h" +#include "RefCountedObjectImpl.h" + +namespace Diligent +{ + + +#define IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName) \ +{ \ + if( ppInterface == nullptr ) \ + return; \ + if( IID == InterfaceID ) \ + { \ + *ppInterface = this; \ + (*ppInterface)->AddRef(); \ + } \ + else \ + { \ + ParentClassName::QueryInterface( IID, ppInterface ); \ + } \ +} + +#define IMPLEMENT_QUERY_INTERFACE(ClassName, InterfaceID, ParentClassName) \ + void ClassName :: QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface) \ + IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName) + +#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName) \ + virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface) \ + IMPLEMENT_QUERY_INTERFACE_BODY(InterfaceID, ParentClassName) + + +/// Template class implementing base functionality for an object +template +class ObjectBase : public RefCountedObject +{ +public: + ObjectBase(IObject *pOwner = nullptr) : + RefCountedObject( pOwner ) + {} + + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) + { + if( ppInterface == nullptr ) + return; + + *ppInterface = nullptr; + if( IID == Diligent::IID_Unknown ) + { + *ppInterface = this; + (*ppInterface)->AddRef(); + } + } +}; + +} diff --git a/Common/include/RefCntAutoPtr.h b/Common/include/RefCntAutoPtr.h new file mode 100644 index 00000000..7df6f246 --- /dev/null +++ b/Common/include/RefCntAutoPtr.h @@ -0,0 +1,391 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "DebugUtilities.h" +#include "LockHelper.h" +#include "Atomics.h" +#include "ValidatedCast.h" +#include "ReferenceCounters.h" +#include "Object.h" + +namespace Diligent +{ + + +template +class RefCntWeakPtr; + +// The main advantage of RefCntAutoPtr over the std::shared_ptr is that you can +// attach the same raw pointer to different smart pointers. +// +// For instance, the following code will crash since p will be released twice: +// +// auto *p = new char; +// std::shared_ptr pTmp1(p); +// std::shared_ptr pTmp2(p); +// ... + +// This code, in contrast, works perfectly fine: +// +// ObjectBase *pRawPtr(new ObjectBase); +// RefCntAutoPtr pSmartPtr1(pRawPtr); +// RefCntAutoPtr pSmartPtr2(pRawPtr); +// ... + +// Other advantage is that weak pointers remain valid until the +// object is alive, even if all smart pointers were destroyed: +// +// RefCntWeakPtr pWeakPtr(pSmartPtr1); +// pSmartPtr1.Release(); +// auto pSmartPtr3 = pWeakPtr.Lock(); +// .. + +// Weak pointers can also be attached directly to the object: +// RefCntWeakPtr pWeakPtr(pRawPtr); +// + +template +class DefaultBlockAddRefRelease : public T +{ +private: + // Note that the null pointer constant nullptr or any other value of type std::nullptr_t + // cannot be converted to a pointer with reinterpret_cast: implicit conversion or + // static_cast should be used for this purpose. + virtual decltype( static_cast(nullptr)->AddRef() ) AddRef()override = 0; + virtual decltype( static_cast(nullptr)->Release() ) Release()override = 0; +}; + +template class BlockAddRefRelease = DefaultBlockAddRefRelease> +class RefCntAutoPtr +{ +public: + explicit RefCntAutoPtr(T *pObj = nullptr) : + m_pObject(pObj) + { + if( m_pObject ) + m_pObject->AddRef(); + } + + RefCntAutoPtr(const RefCntAutoPtr &AutoPtr) : + m_pObject(AutoPtr.m_pObject) + { + if(m_pObject) + m_pObject->AddRef(); + } + + RefCntAutoPtr(RefCntAutoPtr &&AutoPtr) : + m_pObject(std::move(AutoPtr.m_pObject)) + { + //Make sure original pointer has no references to the object + AutoPtr.m_pObject = nullptr; + } + + ~RefCntAutoPtr() + { + Release(); + } + + void swap(RefCntAutoPtr &AutoPtr) + { + std::swap(m_pObject, AutoPtr.m_pObject); + } + + void Attach(T *pObj) + { + Release(); + m_pObject = pObj; + } + + T* Detach() + { + T* pObj = m_pObject; + m_pObject = nullptr; + return pObj; + } + + void Release() + { + if( m_pObject ) + { + m_pObject->Release(); + m_pObject = nullptr; + } + } + + RefCntAutoPtr& operator = (T *pObj) + { + if( static_cast(*this) == pObj ) + return *this; + + return operator= (RefCntAutoPtr(pObj)); + } + + RefCntAutoPtr& operator = (const RefCntAutoPtr &AutoPtr) + { + if( *this == AutoPtr ) + return *this; + + Release(); + m_pObject = AutoPtr.m_pObject; + if(m_pObject) + m_pObject->AddRef(); + + return *this; + } + + RefCntAutoPtr& operator = (RefCntAutoPtr &&AutoPtr) + { + if( *this == AutoPtr ) + return *this; + + Release(); + m_pObject = std::move( AutoPtr.m_pObject ); + //Make sure original pointer has no references to the object + AutoPtr.m_pObject = nullptr; + return *this; + } + + // All the access functions do not require locking reference counters pointer because if it is valid, + // the smart pointer holds strong reference to the object and it thus cannot be released by + // ohter thread + bool operator ! () const{return m_pObject == nullptr;} + operator bool () const{return m_pObject != nullptr;} + bool operator == (const RefCntAutoPtr& Ptr)const{return m_pObject == Ptr.m_pObject;} + bool operator != (const RefCntAutoPtr& Ptr)const{return m_pObject != Ptr.m_pObject;} + bool operator < (const RefCntAutoPtr& Ptr)const{return static_cast(*this) < static_cast(Ptr);} + + T& operator * () { return *m_pObject; } + const T& operator * ()const { return *m_pObject; } + + T* RawPtr() { return m_pObject; } + const T* RawPtr()const{ return m_pObject; } + + operator T* () { return RawPtr(); } + operator const T* ()const { return RawPtr(); } + + + BlockAddRefRelease* operator -> () { return static_cast*> (m_pObject); } + const BlockAddRefRelease* operator -> ()const{ return static_cast*> (m_pObject); } + +private: + // Note that the DoublePtrHelper is a private class, and can be created only by RefCntWeakPtr + // Thus if no special effort is made, the lifetime of the instances of this class cannot be + // longer than the lifetime of the creating object + class DoublePtrHelper + { + public: + DoublePtrHelper(RefCntAutoPtr &AutoPtr) : + NewRawPtr( static_cast(AutoPtr) ), + m_pAutoPtr( std::addressof(AutoPtr) ) + { + } + + DoublePtrHelper(DoublePtrHelper&& Helper) : + NewRawPtr(Helper.NewRawPtr), + m_pAutoPtr(Helper.m_pAutoPtr) + { + Helper.m_pAutoPtr = nullptr; + Helper.NewRawPtr = nullptr; + } + + ~DoublePtrHelper() + { + if( m_pAutoPtr && static_cast(*m_pAutoPtr) != NewRawPtr ) + { + m_pAutoPtr->Attach(NewRawPtr); + } + } + + T*& operator*(){return NewRawPtr;} + const T* operator*()const{return NewRawPtr;} + + operator T**(){return &NewRawPtr;} + operator const T**()const{return &NewRawPtr;} + private: + T *NewRawPtr; + RefCntAutoPtr *m_pAutoPtr; + DoublePtrHelper(const DoublePtrHelper&); + DoublePtrHelper& operator = (const DoublePtrHelper&); + DoublePtrHelper& operator = (DoublePtrHelper&&); + }; + +public: + DoublePtrHelper operator& () + { + return DoublePtrHelper(*this); + } + + const DoublePtrHelper operator& ()const + { + return DoublePtrHelper(*this); + } + +private: + T *m_pObject; +}; + +/// Implementation of weak pointers +template +class RefCntWeakPtr +{ +public: + explicit RefCntWeakPtr(T *pObj = nullptr) : + m_pObject(pObj), + m_pRefCounters(nullptr) + { + if( m_pObject ) + { + m_pRefCounters = m_pObject->GetReferenceCounters(); + m_pRefCounters->AddWeakRef(); + } + } + + ~RefCntWeakPtr() + { + Release(); + } + + RefCntWeakPtr(const RefCntWeakPtr& WeakPtr) : + m_pObject(WeakPtr.m_pObject), + m_pRefCounters(WeakPtr.m_pRefCounters) + { + if( m_pRefCounters ) + m_pRefCounters->AddWeakRef(); + } + + RefCntWeakPtr(RefCntWeakPtr&& WeakPtr) : + m_pObject(std::move(WeakPtr.m_pObject)), + m_pRefCounters(std::move(WeakPtr.m_pRefCounters)) + { + WeakPtr.m_pRefCounters = nullptr; + WeakPtr.m_pObject = nullptr; + } + + explicit RefCntWeakPtr(RefCntAutoPtr& AutoPtr) : + m_pObject( static_cast(AutoPtr) ), + m_pRefCounters(AutoPtr ? AutoPtr->GetReferenceCounters() : nullptr) + { + if( m_pRefCounters ) + m_pRefCounters->AddWeakRef(); + } + + RefCntWeakPtr& operator = (const RefCntWeakPtr& WeakPtr) + { + if( *this == WeakPtr ) + return *this; + + Release(); + m_pObject = WeakPtr.m_pObject; + m_pRefCounters = WeakPtr.m_pRefCounters; + if( m_pRefCounters ) + m_pRefCounters->AddWeakRef(); + return *this; + } + + RefCntWeakPtr& operator = (T *pObj) + { + return operator= (RefCntWeakPtr(pObj)); + } + + RefCntWeakPtr& operator = (RefCntWeakPtr&& WeakPtr) + { + if( *this == WeakPtr ) + return *this; + + Release(); + m_pObject = std::move(WeakPtr.m_pObject); + m_pRefCounters = std::move(WeakPtr.m_pRefCounters); + WeakPtr.m_pRefCounters = nullptr; + WeakPtr.m_pObject = nullptr; + return *this; + } + + RefCntWeakPtr& operator = (RefCntAutoPtr& AutoPtr) + { + Release(); + m_pObject = static_cast( AutoPtr ); + m_pRefCounters = m_pObject ? m_pObject->GetReferenceCounters() : nullptr; + if( m_pRefCounters ) + m_pRefCounters->AddWeakRef(); + return *this; + } + + void Release() + { + if( m_pRefCounters ) + m_pRefCounters->ReleaseWeakRef(); + m_pRefCounters = nullptr; + m_pObject = nullptr; + } + + /// \note This method may not be reliable in a multithreaded environment. + /// However, when false is returned, the strong pointer created from + /// this weak pointer will reliably be empty. + bool IsValid() + { + return m_pObject != nullptr && m_pRefCounters != nullptr && m_pRefCounters->GetNumStrongRefs() > 0; + } + + /// Obtains a strong reference to the object + RefCntAutoPtr Lock() + { + RefCntAutoPtr spObj; + if( m_pRefCounters ) + { + // Try to obtain pointer to the owner object. + // spOwner is only used to keep the object + // alive while obtaining strong reference from + // the raw pointer m_pObject + RefCntAutoPtr spOwner; + m_pRefCounters->GetObject( &spOwner ); + if( spOwner ) + { + // If owner is alive, we can use our RAW pointer to + // create strong reference + spObj = m_pObject; + } + else + { + // Owner object has been destroyed. There is no reason + // to keep this weak reference anymore + Release(); + } + } + return spObj; + } + + bool operator == (const RefCntWeakPtr& Ptr)const{return m_pRefCounters == Ptr.m_pRefCounters;} + bool operator != (const RefCntWeakPtr& Ptr)const{return m_pRefCounters != Ptr.m_pRefCounters;} + +protected: + Diligent::IReferenceCounters *m_pRefCounters; + // We need to store raw pointer to object itself, + // because if the object is owned by another object, + // m_pRefCounters->GetObject( &pObj ) will return + // pointer to owner, which is not what we need. + T *m_pObject; +}; + +} diff --git a/Common/include/RefCountedObjectImpl.h b/Common/include/RefCountedObjectImpl.h new file mode 100644 index 00000000..dc5f7233 --- /dev/null +++ b/Common/include/RefCountedObjectImpl.h @@ -0,0 +1,332 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the template base class for reference counting objects + +#include "Object.h" +#include "Atomics.h" +#include "DebugUtilities.h" +#include "LockHelper.h" +#include "ValidatedCast.h" + +namespace Diligent +{ + +/// Base class for reference counting objects +template +class RefCountedObject : public Base +{ +public: + RefCountedObject(IObject *pOwner = nullptr) : + m_pRefCounters(nullptr) + { + if( pOwner ) + { + auto *pRefCounters = pOwner->GetReferenceCounters(); + VERIFY(pRefCounters, "Reference counters are not initialized in the owner object"); + m_pRefCounters = ValidatedCast( pRefCounters ); + } + else + { + m_pRefCounters = RefCountersImpl::Create(this); + } + }; + + virtual ~RefCountedObject() + { + // WARNING! m_pRefCounters pointer might be expired in scenarios like this: + // + // A ==sp==> B ---wp---> A + // + // RefCounters_A.ReleaseStrongRef(){ // NumStrongRef == 0, NumWeakRef == 1 + // delete A{ + // A.~dtor(){ + // B.~dtor(){ + // wpA.ReleaseWeakRef(){ // NumStrongRef == 0, NumWeakRef == 0 + // delete RefCounters_A; + // ... + // VERIFY( m_pRefCounters->GetNumStrongRefs() == 0 // Access violation! + + // This also may happen if one thread is executing ReleaseStrongRef(), while + // another one is simultaneously running ReleaseWeakRef(). + + //VERIFY( m_pRefCounters->GetNumStrongRefs() == 0, + // "There remain strong references to the object being destroyed" ); + }; + + virtual IReferenceCounters* GetReferenceCounters()const override + { + return m_pRefCounters; + } + + virtual Atomics::Long AddRef()override + { + return m_pRefCounters->AddStrongRef(); + } + + virtual Atomics::Long Release()override + { + return m_pRefCounters->ReleaseStrongRef(); + } + + +private: + + class RefCountersImpl : public IReferenceCounters + { + public: + static RefCountersImpl* Create( RefCountedObject *pOwner ) + { + return new RefCountersImpl( pOwner ); + } + + virtual Atomics::Long AddStrongRef()override + { + VERIFY( m_pObject, "Attempting to increment strong reference counter for a destroyed object!" ); + return Atomics::AtomicIncrement(m_lNumStrongReferences); + } + + virtual Atomics::Long ReleaseStrongRef()override + { + // If the object is about to be destroyed, we must assure that no other + // thread is accessing the ENTIRE REFERENCE COUNTERS OBJECT at the same time. + // (Protecting only the pointer is not sufficient!) + // The problem may arise if a weak pointer in some other thread is trying to + // obtain access to the object. + // The safest way is to always protect the entire function: + ThreadingTools::LockHelper Lock(m_LockFlag); + + // It is unsafe to not always lock. + // For instance, locking if there is only one strong reference left + // if( m_lNumStrongReferences == 1 ) + // Lock.Lock( m_LockFlag ); + // may fail. Suppose the following scenario: + // + // This thread | Another thread + // | 1. Start releasing another strong + // | reference to this object + // 1. Read m_lNumStrongReferences==2 | 2. Read m_lNumStrongReferences==2 + // No lock acquired | 3. Decrement the counter, + // | m_lNumStrongReferences==1 + // 2. Decrement the counter, | + // m_lNumStrongReferences==0, | + // and the object will be | + // destroyed without locking | + + + // Likewise locking if there is at least one weak reference + // if( m_lNumWeakReferences > 0 ) + // Lock.Lock( m_LockFlag ); + // may also fail. Suppose the following scenario: + // + // This thread | Another thread + // | + // 1. Read m_lNumWeakReferences==0 | 1. Start creating weak reference + // No lock acquired | from another strong reference object + // | 2. Call AddWeakRef(), + // | m_lNumWeakReferences==1 + // | 3. Call Release() on the original strong + // | referenceo bject, m_lNumStrongReferences==1 + // | 4. Start creating another strong reference + // | from the weak pointer, acquired lock and + // | read m_pObject + // 2. Destroy the object | + // | 5. Attempt to create strong reference from + // | invalidated pointer + + // Both situations are unlikely to happen. However, they show that + // conditional locking is not safe. There might be other more probable + // situations + auto RefCount = Atomics::AtomicDecrement(m_lNumStrongReferences); + VERIFY( RefCount >= 0, "Inconsistent call to ReleaseStrongRef()" ); + if( RefCount == 0 ) + { + // Locking the object here is also not safe as antoher thread + // may be running GetObject(). If it obtains the lock first, it will + // get the pointer to the object which will then be destroyed by this + // thread + + VERIFY(m_pObject, "Object pointer is null, which means it has already been destroyed"); + // There are no more STRONG references to the object and it is about to be + // destroyed. There could be weak references, so reference counters + // can remain alive after the object itself is destroyed. + + // Note that since reference counters are locked, no weak pointers can access + // m_pObject while the object is being deleted. + + // We cannot destroy the object while reference counters are locked as this will + // cause a deadlock in cases like this: + // + // A ==sp==> B ---wp---> A + // + // RefCounters_A.Lock(); + // delete A{ + // A.~dtor(){ + // B.~dtor(){ + // wpA.ReleaseWeakRef(){ + // RefCounters_A.Lock(); // Deadlock + // + + // So we store the pointer to the object and destory it after unlocking the + // reference counters + auto *pObj = m_pObject; + + // In a multithreaded environment, reference counters object may + // be destroyed at any time while m_pObject->~dtor() is running. + // NOTE: m_pObject may not be the only object referencing m_pRefCounters. + // All objects that are owned by m_pObject will point to the same + // reference counters object. + m_pObject->m_pRefCounters = nullptr; + + // Note that this is the only place where m_pObject member can be modified + // after the reference counters object has been created + m_pObject = nullptr; + // The object is now detached from the reference counters and it is if + // it was destroyed since no one can obtain access to it. + + // It is essentially important to check the number of weak references + // while the object is locked. Otherwise reference counters object + // may be destroyed twice if ReleaseWeakRef() is executed by other thread: + // + // This thread | Another thread - ReleaseWeakRef() + // | + // 1. Decrement m_lNumStrongReferences,| 1. Decrement m_lNumWeakReferences, + // m_lNumStrongReferences==0 | m_lNumWeakReferences == 0 + // | + // 2. Destroy the object | 2. Destroy the object + // + bool bDestroyThis = m_lNumWeakReferences == 0; + + // We must explicitly unlock the object now to avoid deadlocks. Also, + // if this is deleted, this->m_LockFlag will expire, which will cause + // Lock.~LockHelper() to crash + Lock.Unlock(); + + // Destroy referenced object + delete pObj; + + // Note that this may be destroyed here already, + // see comments in ~RefCountedObject() + if( bDestroyThis ) + delete this; + } + + return RefCount; + } + + virtual Atomics::Long AddWeakRef()override + { + return Atomics::AtomicIncrement(m_lNumWeakReferences); + } + + virtual Atomics::Long ReleaseWeakRef()override + { + ThreadingTools::LockHelper Lock(m_LockFlag); + // It is essentially important to check the number of references + // while the object is locked. Otherwise reference counters object + // may be destroyed twice if ReleaseStrongRef() is executed by other + // thread. + auto NumWeakReferences = Atomics::AtomicDecrement(m_lNumWeakReferences); + VERIFY( NumWeakReferences >= 0, "Inconsistent call to ReleaseWeakRef()" ); + if( NumWeakReferences == 0 && m_lNumStrongReferences == 0 ) + { + // There are no more references to the ref counters object. + // We can safely unlock it and destroy. + // If we do not unlock it, this->m_LockFlag will expire, + // which will cause Lock.~LockHelper() to crash. + Lock.Unlock(); + delete this; + } + return NumWeakReferences; + } + + virtual void GetObject( class IObject **ppObject )override + { + // We need to lock the object before accessing it to prevent + // deletion of the referenced object in another thread. + // The thread which is about to delete the object locks it and + // decrements the reference counter only after it gets exclusive access. + // So if we obtain mutex first, we will increase the reference counter + // before the other thread decrements it. Thus the object will not + // be deleted. + ThreadingTools::LockHelper Lock(m_LockFlag); + if( m_pObject ) + { + // QueryInterface() must not lock the object, or a deadlock happens. + // The only other two methods that lock the object are ReleaseStrongRef() + // and ReleaseWeakRef(), which are never called by QueryInterface() + m_pObject->QueryInterface(Diligent::IID_Unknown, ppObject); + } + } + + virtual Atomics::Long GetNumStrongRefs()const override + { + return m_lNumStrongReferences; + } + + virtual Atomics::Long GetNumWeakRefs()const override + { + return m_lNumWeakReferences; + } + + private: + RefCountersImpl(RefCountedObject *pOwner) : + m_pObject(pOwner) + { + VERIFY(m_pObject, "Owner must not be null"); + m_lNumStrongReferences = 0; + m_lNumWeakReferences = 0; + } + + ~RefCountersImpl() + { + VERIFY( m_lNumStrongReferences == 0 && m_lNumWeakReferences == 0, + "There exist outstanding references to the object being destroyed" ); + } + + // No copies/moves + RefCountersImpl(const RefCountersImpl&); + RefCountersImpl(RefCountersImpl&&); + RefCountersImpl& operator = (const RefCountersImpl&); + RefCountersImpl& operator = (RefCountersImpl&&); + + // It is crucially important that the type of the pointer + // is RefCountedObject and not IObject, since the latter + // does not have virtual dtor. + RefCountedObject *m_pObject; + Atomics::AtomicLong m_lNumStrongReferences; + Atomics::AtomicLong m_lNumWeakReferences; + ThreadingTools::LockFlag m_LockFlag; + }; + + // Reference counters pointer cannot be of type RefCountersImpl*, + // because when an owner pointer is provided to RefCountedObject(), + // the type of pOwner->GetReferenceCounters() may not be convertible + // to RefCountedObject::RefCountersImpl*. + IReferenceCounters *m_pRefCounters; +}; + +} diff --git a/Common/include/StringTools.h b/Common/include/StringTools.h new file mode 100644 index 00000000..687eeef8 --- /dev/null +++ b/Common/include/StringTools.h @@ -0,0 +1,75 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include +#include +#include + +namespace Diligent +{ + +inline std::string NarrowString(const std::wstring &WideStr) +{ + std::string NarrowStr; + const std::ctype& ctfacet = std::use_facet< std::ctype >( std::wstringstream().getloc() ) ; + for( std::wstring::const_iterator CurrWChar = WideStr.begin(); + CurrWChar != WideStr.end(); + CurrWChar++ ) + NarrowStr.push_back( ctfacet.narrow( *CurrWChar, 0 ) ); + + return NarrowStr; +} + +inline std::wstring WidenString(const std::string &Str) +{ + std::wstring WideStr; + const std::ctype& ctfacet = std::use_facet< std::ctype >( std::wstringstream().getloc() ) ; + for( std::string::const_iterator CurrChar = Str.begin(); + CurrChar != Str.end(); + CurrChar++ ) + WideStr.push_back( ctfacet.widen( *CurrChar ) ); + + return WideStr; +} + +inline int StrCmpNoCase(const char* Str1, const char* Str2, size_t NumChars) +{ +#ifdef PLATFORM_ANDROID +# define _strnicmp strncasecmp +#endif + + return _strnicmp( Str1, Str2, NumChars ); +} + +inline int StrCmpNoCase(const char* Str1, const char* Str2) +{ +#ifdef PLATFORM_ANDROID +# define _stricmp strcasecmp +#endif + + return _stricmp( Str1, Str2 ); +} + +} diff --git a/Common/include/Timer.h b/Common/include/Timer.h new file mode 100644 index 00000000..5e3dfe54 --- /dev/null +++ b/Common/include/Timer.h @@ -0,0 +1,41 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include + +namespace Diligent +{ + class Timer + { + public: + Timer(); + void Restart(); + double GetElapsedTime()const; + float GetElapsedTimef()const; + + private: + std::chrono::high_resolution_clock::time_point m_StartTime; + }; +} diff --git a/Common/include/UniqueIdentifier.h b/Common/include/UniqueIdentifier.h new file mode 100644 index 00000000..e4fd7159 --- /dev/null +++ b/Common/include/UniqueIdentifier.h @@ -0,0 +1,79 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "Atomics.h" + +namespace Diligent +{ + typedef Atomics::Long UniqueIdentifier; + + // Template switch is used to have distinct counters + // for unrelated groups of objects + template + class UniqueIdHelper + { + public: + UniqueIdHelper() : + m_ID(0), + m_bIsInitialized( false ) + {} + + UniqueIdHelper( UniqueIdHelper&& RHS) : + m_ID( RHS.m_ID ), + m_bIsInitialized( RHS.m_bIsInitialized ) + { + RHS.m_ID = 0; + RHS.m_bIsInitialized = false; + } + + const UniqueIdHelper& operator = (UniqueIdHelper&& RHS) + { + m_ID = RHS.m_ID; + m_bIsInitialized = RHS.m_bIsInitialized; + RHS.m_ID = 0; + RHS.m_bIsInitialized = false; + + return *this; + } + + UniqueIdentifier GetID()const + { + if( !m_bIsInitialized ) + { + static Atomics::AtomicLong sm_GlobalCounter; + m_ID = Atomics::AtomicIncrement(sm_GlobalCounter); + m_bIsInitialized = true; + } + return m_ID; + } + + private: + UniqueIdHelper( const UniqueIdHelper& ); + const UniqueIdHelper& operator = ( const UniqueIdHelper& ); + + mutable UniqueIdentifier m_ID; + mutable bool m_bIsInitialized; + }; +} diff --git a/Common/include/ValidatedCast.h b/Common/include/ValidatedCast.h new file mode 100644 index 00000000..916148c4 --- /dev/null +++ b/Common/include/ValidatedCast.h @@ -0,0 +1,33 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "DebugUtilities.h" + +template +DstType* ValidatedCast( SrcType *Ptr ) +{ + CHECK_DYNAMIC_TYPE( DstType, Ptr ); + return static_cast( Ptr ); +} diff --git a/Common/include/pch.h b/Common/include/pch.h new file mode 100644 index 00000000..8b5e042b --- /dev/null +++ b/Common/include/pch.h @@ -0,0 +1,35 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "PlatformDefinitions.h" +#include "BasicTypes.h" +#include "Errors.h" +#include "FileWrapper.h" +#include "RefCntAutoPtr.h" \ No newline at end of file diff --git a/Common/interface/AdvancedMath.h b/Common/interface/AdvancedMath.h new file mode 100644 index 00000000..c4af54ad --- /dev/null +++ b/Common/interface/AdvancedMath.h @@ -0,0 +1,127 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "BasicMath.h" + +// Structure describing a plane +struct Plane3D +{ + float3 Normal; + float Distance; //Distance from the coordinate system origin to the plane along the normal direction +}; + +struct ViewFrustum +{ + Plane3D LeftPlane, RightPlane, BottomPlane, TopPlane, NearPlane, FarPlane; +}; + +// For OpenGL, matrix is still considered row-major. The only difference is that +// near clip plane is at -1, not 0. +inline void ExtractViewFrustumPlanesFromMatrix(const float4x4 &Matrix, ViewFrustum &ViewFrustum, bool bIsDirectX) +{ + // For more details, see Gribb G., Hartmann K., "Fast Extraction of Viewing Frustum Planes from the + // World-View-Projection Matrix" (the paper is available at + // http://gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf) + + // Left clipping plane + ViewFrustum.LeftPlane.Normal.x = Matrix._14 + Matrix._11; + ViewFrustum.LeftPlane.Normal.y = Matrix._24 + Matrix._21; + ViewFrustum.LeftPlane.Normal.z = Matrix._34 + Matrix._31; + ViewFrustum.LeftPlane.Distance = Matrix._44 + Matrix._41; + + // Right clipping plane + ViewFrustum.RightPlane.Normal.x = Matrix._14 - Matrix._11; + ViewFrustum.RightPlane.Normal.y = Matrix._24 - Matrix._21; + ViewFrustum.RightPlane.Normal.z = Matrix._34 - Matrix._31; + ViewFrustum.RightPlane.Distance = Matrix._44 - Matrix._41; + + // Top clipping plane + ViewFrustum.TopPlane.Normal.x = Matrix._14 - Matrix._12; + ViewFrustum.TopPlane.Normal.y = Matrix._24 - Matrix._22; + ViewFrustum.TopPlane.Normal.z = Matrix._34 - Matrix._32; + ViewFrustum.TopPlane.Distance = Matrix._44 - Matrix._42; + + // Bottom clipping plane + ViewFrustum.BottomPlane.Normal.x = Matrix._14 + Matrix._12; + ViewFrustum.BottomPlane.Normal.y = Matrix._24 + Matrix._22; + ViewFrustum.BottomPlane.Normal.z = Matrix._34 + Matrix._32; + ViewFrustum.BottomPlane.Distance = Matrix._44 + Matrix._42; + + // Near clipping plane + if( bIsDirectX ) + { + // 0 <= z <= w + ViewFrustum.NearPlane.Normal.x = Matrix._13; + ViewFrustum.NearPlane.Normal.y = Matrix._23; + ViewFrustum.NearPlane.Normal.z = Matrix._33; + ViewFrustum.NearPlane.Distance = Matrix._43; + } + else + { + // -w <= z <= w + ViewFrustum.NearPlane.Normal.x = Matrix._14 + Matrix._13; + ViewFrustum.NearPlane.Normal.y = Matrix._24 + Matrix._23; + ViewFrustum.NearPlane.Normal.z = Matrix._34 + Matrix._33; + ViewFrustum.NearPlane.Distance = Matrix._44 + Matrix._43; + } + + // Far clipping plane + ViewFrustum.FarPlane.Normal.x = Matrix._14 - Matrix._13; + ViewFrustum.FarPlane.Normal.y = Matrix._24 - Matrix._23; + ViewFrustum.FarPlane.Normal.z = Matrix._34 - Matrix._33; + ViewFrustum.FarPlane.Distance = Matrix._44 - Matrix._43; +} + + + +struct BoundBox +{ + float fMinX, fMaxX, fMinY, fMaxY, fMinZ, fMaxZ; +}; + +// Tests if bounding box is visible by the camera +inline bool IBoxVisible(const ViewFrustum &ViewFrustum, const BoundBox &Box) +{ + Plane3D *pPlanes = (Plane3D *)&ViewFrustum; + // If bounding box is "behind" some plane, then it is invisible + // Otherwise it is treated as visible + for(int iViewFrustumPlane = 0; iViewFrustumPlane < 6; iViewFrustumPlane++) + { + Plane3D *pCurrPlane = pPlanes + iViewFrustumPlane; + float3 *pCurrNormal = &pCurrPlane->Normal; + float3 MaxPoint; + + MaxPoint.x = (pCurrNormal->x > 0) ? Box.fMaxX : Box.fMinX; + MaxPoint.y = (pCurrNormal->y > 0) ? Box.fMaxY : Box.fMinY; + MaxPoint.z = (pCurrNormal->z > 0) ? Box.fMaxZ : Box.fMinZ; + + float DMax = dot( MaxPoint, *pCurrNormal ) + pCurrPlane->Distance; + + if( DMax < 0 ) + return false; + } + + return true; +} diff --git a/Common/interface/BasicMath.h b/Common/interface/BasicMath.h new file mode 100644 index 00000000..95b35974 --- /dev/null +++ b/Common/interface/BasicMath.h @@ -0,0 +1,1344 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +//// PARTICULAR PURPOSE. +//// +//// Copyright (c) Microsoft Corporation. All rights reserved + +#pragma once + +#include "DebugUtilities.h" + +#define _USE_MATH_DEFINES +#include + +// This header defines math and matrix helper functions and structures used +// by DirectX SDK samples. + +// Common Constants + +#define PI_F 3.1415927f + +// Template Vector & Matrix Classes +template struct Matrix4x4; +template struct Vector4; + +template struct Vector2 +{ + union + { + struct + { + T x; + T y; + }; + struct + { + T r; + T g; + }; + struct + { + T u; + T v; + }; + }; + + + Vector2 operator-(const Vector2 &right)const + { + return Vector2(x - right.x, y - right.y); + } + + Vector2& operator-=(const Vector2 &right) + { + x -= right.x; + y -= right.y; + return *this; + } + + Vector2 operator-()const + { + return Vector2(-x, -y); + } + + Vector2 operator+(const Vector2 &right)const + { + return Vector2(x + right.x, y + right.y); + } + + Vector2& operator+=(const Vector2 &right) + { + x += right.x; + y += right.y; + return *this; + } + + Vector2 operator*(T s)const + { + return Vector2(x * s, y * s); + } + + Vector2 operator*(const Vector2 &right)const + { + return Vector2(x * right.x, y * right.y); + } + + Vector2& operator*=( const Vector2 &right) + { + x *= right.x; + y *= right.y; + return *this; + } + + Vector2& operator*=( T s) + { + x *= s; + y *= s; + return *this; + } + + Vector2 operator/(const Vector2 &right)const + { + return Vector2(x / right.x, y / right.y); + } + + Vector2& operator/=( const Vector2 &right) + { + x /= right.x; + y /= right.y; + return *this; + } + + Vector2 operator/(T s)const + { + return Vector2(x / s, y / s); + } + + Vector2& operator/=( T s) + { + x /= s; + y /= s; + return *this; + } + + bool operator == (const Vector2 &right)const + { + return x == right.x && y == right.y; + } + + bool operator != (const Vector2 &right)const + { + return !(*this == right); + } + + Vector2 operator < ( const Vector2 &right )const + { + return Vector2(x < right.x ? static_cast(1) : static_cast(0), + y < right.y ? static_cast(1) : static_cast(0)); + } + + Vector2 operator > ( const Vector2 &right )const + { + return Vector2(x > right.x ? static_cast(1) : static_cast(0), + y > right.y ? static_cast(1) : static_cast(0)); + } + + Vector2 operator <= ( const Vector2 &right )const + { + return Vector2(x <= right.x ? static_cast(1) : static_cast(0), + y <= right.y ? static_cast(1) : static_cast(0)); + } + + Vector2 operator >= ( const Vector2 &right )const + { + return Vector2(x >= right.x ? static_cast(1) : static_cast(0), + y >= right.y ? static_cast(1) : static_cast(0)); + } + + T& operator[](size_t index) + { + return reinterpret_cast(this)[index]; + } + + const T& operator[](size_t index)const + { + return reinterpret_cast(this)[index]; + } + + explicit + Vector2(T _x = 0, T _y = 0) : x(_x), y(_y) { } +}; + +template +Vector2 operator*(T s, const Vector2 &a) +{ + return a * s; +} + + +template struct Vector3 +{ + union + { + struct + { + T x; + T y; + T z; + }; + struct + { + T r; + T g; + T b; + }; + struct + { + T u; + T v; + T w; + }; + }; + + + Vector3 operator-( const Vector3 &right )const + { + return Vector3(x - right.x, y - right.y, z - right.z); + } + + Vector3 operator-()const + { + return Vector3(-x, -y, -z); + } + + Vector3& operator-=(const Vector3 &right) + { + x -= right.x; + y -= right.y; + z -= right.z; + return *this; + } + + Vector3 operator+( const Vector3 &right )const + { + return Vector3(x + right.x, y + right.y, z + right.z); + } + + Vector3& operator+=(const Vector3 &right) + { + x += right.x; + y += right.y; + z += right.z; + return *this; + } + + Vector3 operator*( T s )const + { + return Vector3(x * s, y * s, z * s); + } + + Vector3& operator*=( T s) + { + x *= s; + y *= s; + z *= s; + return *this; + } + + Vector3 operator*( const Vector3 &right )const + { + return Vector3(x * right.x, y * right.y, z * right.z); + } + + Vector3 operator* (const Matrix4x4& m)const + { + Vector4 out4 = Vector4(x, y, z, 1) * m; + return Vector3(out4.x / out4.w, out4.y / out4.w, out4.z / out4.w) ; + } + + Vector3& operator*=( const Vector3 &right) + { + x *= right.x; + y *= right.y; + z *= right.z; + return *this; + } + + Vector3 operator/ ( T s)const + { + return Vector3(x / s, y / s, z / s); + } + + Vector3& operator/=( T s) + { + x /= s; + y /= s; + z /= s; + return *this; + } + + Vector3 operator/( const Vector3 &right )const + { + return Vector3(x / right.x, y / right.y, z / right.z); + } + + Vector3& operator/=( const Vector3 &right) + { + x /= right.x; + y /= right.y; + z /= right.z; + return *this; + } + + bool operator == (const Vector3 &right)const + { + return x == right.x && y == right.y && z == right.z; + } + + bool operator != (const Vector3 &right)const + { + return !(*this == right); + } + + Vector3 operator < ( const Vector3 &right )const + { + return Vector3(x < right.x ? static_cast(1) : static_cast(0), + y < right.y ? static_cast(1) : static_cast(0), + z < right.z ? static_cast(1) : static_cast(0)); + } + + Vector3 operator > ( const Vector3 &right )const + { + return Vector3(x > right.x ? static_cast(1) : static_cast(0), + y > right.y ? static_cast(1) : static_cast(0), + z > right.z ? static_cast(1) : static_cast(0)); + } + + Vector3 operator <= ( const Vector3 &right )const + { + return Vector3(x <= right.x ? static_cast(1) : static_cast(0), + y <= right.y ? static_cast(1) : static_cast(0), + z <= right.z ? static_cast(1) : static_cast(0)); + } + + Vector3 operator >= ( const Vector3 &right )const + { + return Vector3(x >= right.x ? static_cast(1) : static_cast(0), + y >= right.y ? static_cast(1) : static_cast(0), + z >= right.z ? static_cast(1) : static_cast(0)); + } + + T& operator[](size_t index) + { + return reinterpret_cast(this)[index]; + } + + const T& operator[](size_t index)const + { + return reinterpret_cast(this)[index]; + } + + explicit + Vector3(T _x = 0, T _y = 0, T _z = 0) : x(_x), y(_y), z(_z) { } + + operator Vector2()const{return Vector2(x,y);} +}; + +template +Vector3 operator*(T s, const Vector3 &a) +{ + return a * s; +} + + +template struct Vector4 +{ + union + { + struct + { + T x; + T y; + T z; + T w; + }; + struct + { + T r; + T g; + T b; + T a; + }; + }; + + Vector4 operator-( const Vector4 &right)const + { + return Vector4(x - right.x, y - right.y, z - right.z, w - right.w); + } + + Vector4 operator-()const + { + return Vector4(-x, -y, -z, -w); + } + + Vector4& operator-=(const Vector4 &right) + { + x -= right.x; + y -= right.y; + z -= right.z; + w -= right.w; + return *this; + } + + Vector4 operator+( const Vector4 &right)const + { + return Vector4(x + right.x, y + right.y, z + right.z, w + right.w); + } + + Vector4& operator+=(const Vector4 &right) + { + x += right.x; + y += right.y; + z += right.z; + w += right.w; + return *this; + } + + Vector4 operator*( T s)const + { + return Vector4(x * s, y * s, z * s, w * s); + } + + Vector4& operator*=( T s) + { + x *= s; + y *= s; + z *= s; + w *= s; + return *this; + } + + Vector4 operator*( const Vector4 &right)const + { + return Vector4(x * right.x, y * right.y, z * right.z, w * right.w); + } + + Vector4& operator*=( const Vector4 &right) + { + x *= right.x; + y *= right.y; + z *= right.z; + w *= right.w; + return *this; + } + + Vector4 operator/( T s)const + { + return Vector4(x / s, y / s, z / s, w / s); + } + + Vector4& operator/=( T s) + { + x /= s; + y /= s; + z /= s; + w /= s; + return *this; + } + + Vector4 operator/( const Vector4 &right)const + { + return Vector4(x / right.x, y / right.y, z / right.z, w / right.w); + } + + Vector4& operator/=( const Vector4 &right) + { + x /= right.x; + y /= right.y; + z /= right.z; + w /= right.w; + return *this; + } + + bool operator == (const Vector4 &right)const + { + return x == right.x && y == right.y && z == right.z && w == right.w; + } + + bool operator != (const Vector4 &right)const + { + return !(*this == right); + } + + Vector4 operator*(const Matrix4x4& m)const + { + Vector4 out; + out[0] = x * m[0][0] + y * m[1][0] + z * m[2][0] + w * m[3][0]; + out[1] = x * m[0][1] + y * m[1][1] + z * m[2][1] + w * m[3][1]; + out[2] = x * m[0][2] + y * m[1][2] + z * m[2][2] + w * m[3][2]; + out[3] = x * m[0][3] + y * m[1][3] + z * m[2][3] + w * m[3][3]; + return out; + } + + Vector4& operator = (const Vector3 &v3) + { + x = v3.x; + y = v3.y; + z = v3.z; + w = 1; + return *this; + } + Vector4& operator = (const Vector4 &) = default; + + Vector4 operator < ( const Vector4 &right )const + { + return Vector4(x < right.x ? static_cast(1) : static_cast(0), + y < right.y ? static_cast(1) : static_cast(0), + z < right.z ? static_cast(1) : static_cast(0), + w < right.w ? static_cast(1) : static_cast(0)); + } + + Vector4 operator > ( const Vector4 &right )const + { + return Vector4(x > right.x ? static_cast(1) : static_cast(0), + y > right.y ? static_cast(1) : static_cast(0), + z > right.z ? static_cast(1) : static_cast(0), + w > right.w ? static_cast(1) : static_cast(0)); + } + + Vector4 operator <= ( const Vector4 &right )const + { + return Vector4(x <= right.x ? static_cast(1) : static_cast(0), + y <= right.y ? static_cast(1) : static_cast(0), + z <= right.z ? static_cast(1) : static_cast(0), + w <= right.w ? static_cast(1) : static_cast(0)); + } + + Vector4 operator >= ( const Vector4 &right )const + { + return Vector4(x >= right.x ? static_cast(1) : static_cast(0), + y >= right.y ? static_cast(1) : static_cast(0), + z >= right.z ? static_cast(1) : static_cast(0), + w >= right.w ? static_cast(1) : static_cast(0)); + } + + T& operator[](size_t index) + { + return reinterpret_cast(this)[index]; + } + + const T& operator[](size_t index)const + { + return reinterpret_cast(this)[index]; + } + + explicit + Vector4(T _x = 0, T _y = 0, T _z = 0, T _w = 0) : x(_x), y(_y), z(_z), w(_w) { } +}; + + +template +Vector4 operator*(T s, const Vector4 &a) +{ + return a * s; +} + +template struct Matrix3x3 +{ + union + { + struct + { + T _11; T _12; T _13; + T _21; T _22; T _23; + T _31; T _32; T _33; + }; + struct + { + T _m00; T _m01; T _m02; + T _m10; T _m11; T _m12; + T _m20; T _m21; T _m22; + }; + }; + + explicit + Matrix3x3(T value = 0) + { + _11 = _12 = _13 =value; + _21 = _22 = _23 =value; + _31 = _32 = _33 =value; + } + + explicit + Matrix3x3( + T i11, T i12, T i13, + T i21, T i22, T i23, + T i31, T i32, T i33 ) + { + _11 = i11; _12 = i12; _13 = i13; + _21 = i21; _22 = i22; _23 = i23; + _31 = i31; _32 = i32; _33 = i33; + } + + bool operator == (const Matrix3x3 &r)const + { + for( int i = 0; i < 3; ++i ) + for( int j = 0; i < 3; ++i ) + if( (*this)[i][j] != r[i][j] ) + return false; + + return true; + } + + bool operator != (const Matrix3x3 &r)const + { + return !(*this == r); + } + + T* operator[](size_t index) + { + return &(reinterpret_cast(this)[index*3]); + } + + const T* operator[](size_t index)const + { + return &(reinterpret_cast(this)[index*3]); + } + + Matrix3x3& operator *=(T s) + { + for( int i = 0; i < 9; ++i ) + (reinterpret_cast(this))[i] *= s; + + return *this; + } +}; + +template struct Matrix4x4 +{ + union + { + struct + { + T _11; T _12; T _13; T _14; + T _21; T _22; T _23; T _24; + T _31; T _32; T _33; T _34; + T _41; T _42; T _43; T _44; + }; + struct + { + T _m00; T _m01; T _m02; T _m03; + T _m10; T _m11; T _m12; T _m13; + T _m20; T _m21; T _m22; T _m23; + T _m30; T _m31; T _m32; T _m33; + }; + }; + + explicit + Matrix4x4(T value = 0) + { + _11 = _12 = _13 = _14 = value; + _21 = _22 = _23 = _24 = value; + _31 = _32 = _33 = _34 = value; + _41 = _42 = _43 = _44 = value; + } + + explicit + Matrix4x4( + T i11, T i12, T i13, T i14, + T i21, T i22, T i23, T i24, + T i31, T i32, T i33, T i34, + T i41, T i42, T i43, T i44 + ) + { + _11 = i11; _12 = i12; _13 = i13; _14 = i14; + _21 = i21; _22 = i22; _23 = i23; _24 = i24; + _31 = i31; _32 = i32; _33 = i33; _34 = i34; + _41 = i41; _42 = i42; _43 = i43; _44 = i44; + } + + bool operator == (const Matrix4x4 &r)const + { + for( int i = 0; i < 4; ++i ) + for( int j = 0; i < 4; ++i ) + if( (*this)[i][j] != r[i][j] ) + return false; + + return true; + } + + bool operator != (const Matrix4x4 &r)const + { + return !(*this == r); + } + + T* operator[](size_t index) + { + return &(reinterpret_cast(this)[index*4]); + } + + const T* operator[](size_t index)const + { + return &(reinterpret_cast(this)[index*4]); + } + + Matrix4x4& operator *=(T s) + { + for( int i = 0; i < 16; ++i ) + (reinterpret_cast(this))[i] *= s; + + return *this; + } +}; + +// Template Vector Operations + + +template +T dot(const Vector2 &a, const Vector2 &b) +{ + return a.x * b.x + a.y * b.y; +} + +template +T dot(const Vector3 &a, const Vector3 &b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z; +} + +template +T dot(const Vector4 &a, const Vector4 &b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; +} + +template +auto length(const VectorType &a)->decltype(dot(a,a)) +{ + return sqrt( dot(a,a) ); +} + + +template +Vector3 min(const Vector3 &a, const Vector3 &b) +{ + return Vector3( std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z) ); +} + +template +Vector4 min(const Vector4 &a, const Vector4 &b) +{ + return Vector4( std::min(a.x, b.x), std::min(a.y, b.y), std::min(a.z, b.z), std::min(a.w, b.w) ); +} + +template +Vector3 max(const Vector3 &a, const Vector3 &b) +{ + return Vector3( std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z) ); +} + +template +Vector4 max(const Vector4 &a, const Vector4 &b) +{ + return Vector4( std::max(a.x, b.x), std::max(a.y, b.y), std::max(a.z, b.z), std::max(a.w, b.w) ); +} + +template +Vector2 abs(const Vector2 &a) +{ + // WARNING: abs() on gcc is for integers only! + return Vector2( a.x < 0 ? -a.x : a.x, + a.y < 0 ? -a.y : a.y); +} + +template +Vector3 abs(const Vector3 &a) +{ + // WARNING: abs() on gcc is for integers only! + return Vector3( a.x < 0 ? -a.x : a.x, + a.y < 0 ? -a.y : a.y, + a.z < 0 ? -a.z : a.z); +} + +template +Vector4 abs(const Vector4 &a) +{ + // WARNING: abs() on gcc is for integers only! + return Vector4( a.x < 0 ? -a.x : a.x, + a.y < 0 ? -a.y : a.y, + a.z < 0 ? -a.z : a.z, + a.w < 0 ? -a.w : a.w); +} + + +template +Vector3 cross(const Vector3 &a, const Vector3 &b) +{ + // | i j k | + // | a.x a.y a.z | + // | b.x b.y b.z | + return Vector3((a.y*b.z)-(a.z*b.y), (a.z*b.x)-(a.x*b.z), (a.x*b.y)-(a.y*b.x)); +} + +template +VectorType normalize(const VectorType &a) +{ + auto len = length(a); + return a / len; +} + + +// Template Matrix Operations + +template +Matrix4x4 transposeMatrix(const Matrix4x4 &m) +{ + return Matrix4x4( + m._11, m._21, m._31, m._41, + m._12, m._22, m._32, m._42, + m._13, m._23, m._33, m._43, + m._14, m._24, m._34, m._44 + ); +} + +template +Matrix4x4 mul(const Matrix4x4 &m1, const Matrix4x4 &m2) +{ + Matrix4x4 mOut; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + for (int k = 0; k < 4; k++) + { + mOut[i][j] += m1[i][k] * m2[k][j]; + } + } + } + + return mOut; +} + +template +Matrix4x4 operator* (const Matrix4x4 &m1, const Matrix4x4 &m2) +{ + return mul( m1, m2 ); +} + + + +template +Matrix3x3 transposeMatrix(const Matrix3x3 &m) +{ + return Matrix3x3( + m._11, m._21, m._31, + m._12, m._22, m._32, + m._13, m._23, m._33 + ); +} + +template +Matrix3x3 mul(const Matrix3x3 &m1, const Matrix3x3 &m2) +{ + Matrix3x3 mOut; + + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + mOut[i][j] += m1[i][k] * m2[k][j]; + } + } + } + + return mOut; +} + +template +Matrix3x3 operator* (const Matrix3x3 &m1, const Matrix3x3 &m2) +{ + return mul( m1, m2 ); +} + +// Common HLSL-compatible vector typedefs + +typedef unsigned int uint; + +typedef Vector2 float2; +typedef Vector3 float3; +typedef Vector4 float4; + +typedef Matrix4x4 float4x4; +typedef Matrix3x3 float3x3; + +// Standard Matrix Intializers + +inline float4x4 identityMatrix() +{ + return float4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); +} + +inline float4x4 translationMatrix(float x, float y, float z) +{ + return float4x4 (1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + x, y, z, 1); +} + +inline float4x4 translationMatrix( const float3 &v ) +{ + return translationMatrix( v.x, v.y, v.z ); +} + + +inline float4x4 scaleMatrix(float x, float y, float z) +{ + return float4x4(x, 0, 0, 0, + 0, y, 0, 0, + 0, 0, z, 0, + 0, 0, 0, 1); +} + +inline float4x4 rotationX(float degreeX) +{ + float angleInRadians = degreeX * (PI_F / 180.0f); + + float sinAngle = sinf(angleInRadians); + float cosAngle = cosf(angleInRadians); + + float4x4 mOut; + + UNSUPPORTED("This function is not tested, it might be incorrect.") + mOut._11 = 1.0f; mOut._12 = 0.0f; mOut._13 = 0.0f; mOut._14 = 0.0f; + mOut._21 = 0.0f; mOut._22 = cosAngle; mOut._23 = -sinAngle; mOut._24 = 0.0f; + mOut._31 = 0.0f; mOut._32 = sinAngle; mOut._33 = cosAngle; mOut._34 = 0.0f; + mOut._41 = 0.0f; mOut._42 = 0.0f; mOut._43 = 0.0f; mOut._44 = 1.0f; + + return mOut; +} + +inline float4x4 rotationY(float degreeY) +{ + float angleInRadians = degreeY * (PI_F / 180.0f); + + float sinAngle = sinf(angleInRadians); + float cosAngle = cosf(angleInRadians); + + float4x4 mOut; + + UNSUPPORTED("This function is not tested, it might be incorrect.") + mOut._11 = cosAngle; mOut._12 = 0.0f; mOut._13 = sinAngle; mOut._14 = 0.0f; + mOut._21 = 0.0f; mOut._22 = 1.0f; mOut._23 = 0.0f; mOut._24 = 0.0f; + mOut._31 = -sinAngle; mOut._32 = 0.0f; mOut._33 = cosAngle; mOut._34 = 0.0f; + mOut._41 = 0.0f; mOut._42 = 0.0f; mOut._43 = 0.0f; mOut._44 = 1.0f; + + return mOut; +} + +inline float4x4 rotationZ(float degreeZ) +{ + float angleInRadians = degreeZ * (PI_F / 180.0f); + + float sinAngle = sinf(angleInRadians); + float cosAngle = cosf(angleInRadians); + + float4x4 mOut; + + UNSUPPORTED("This function is not tested, it might be incorrect.") + mOut._11 = cosAngle; mOut._12 = -sinAngle; mOut._13 = 0.0f; mOut._14 = 0.0f; + mOut._21 = sinAngle; mOut._22 = cosAngle; mOut._23 = 0.0f; mOut._24 = 0.0f; + mOut._31 = 0.0f; mOut._32 = 0.0f; mOut._33 = 1.0f; mOut._34 = 0.0f; + mOut._41 = 0.0f; mOut._42 = 0.0f; mOut._43 = 0.0f; mOut._44 = 1.0f; + + return mOut; +} + +// 3D Rotation matrix for an arbitrary axis specified by x, y and z +inline float4x4 rotationArbitrary(float3 axis, float degree) +{ + UNSUPPORTED("This function is not tested, it might be incorrect") + + axis = normalize(axis); + + float angleInRadians = degree * (PI_F / 180.0f); + + float sinAngle = sinf(angleInRadians); + float cosAngle = cosf(angleInRadians); + float oneMinusCosAngle = 1 - cosAngle; + + float4x4 mOut; + + mOut._11 = 1.0f + oneMinusCosAngle * (axis.x * axis.x - 1.0f); + mOut._12 = axis.z * sinAngle + oneMinusCosAngle * axis.x * axis.y; + mOut._13 = -axis.y * sinAngle + oneMinusCosAngle * axis.x * axis.z; + mOut._41 = 0.0f; + + mOut._21 = -axis.z * sinAngle + oneMinusCosAngle * axis.y * axis.x; + mOut._22 = 1.0f + oneMinusCosAngle * (axis.y * axis.y - 1.0f); + mOut._23 = axis.x * sinAngle + oneMinusCosAngle * axis.y * axis.z; + mOut._24 = 0.0f; + + mOut._31 = axis.y * sinAngle + oneMinusCosAngle * axis.z * axis.x; + mOut._32 = -axis.x * sinAngle + oneMinusCosAngle * axis.z * axis.y; + mOut._33 = 1.0f + oneMinusCosAngle * (axis.z * axis.z - 1.0f); + mOut._34 = 0.0f; + + mOut._41 = 0.0f; + mOut._42 = 0.0f; + mOut._43 = 0.0f; + mOut._44 = 1.0f; + + return mOut; +} + +inline float4x4 ViewMatrixFromBasis( const float3 &f3X, const float3 &f3Y, const float3 &f3Z ) +{ + return float4x4( f3X.x, f3Y.x, f3Z.x, 0, + f3X.y, f3Y.y, f3Z.y, 0, + f3X.z, f3Y.z, f3Z.z, 0, + 0, 0, 0, 1); +} + +inline void SetNearFarClipPlanes( float4x4 &ProjMatrix, float zNear, float zFar, bool bIsDirectX ) +{ + if( bIsDirectX ) + { + ProjMatrix._33 = zFar / (zFar - zNear); + ProjMatrix._43 = -zNear * zFar / (zFar - zNear); + ProjMatrix._34 = 1; + } + else + { + // https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml + // http://www.terathon.com/gdc07_lengyel.pdf + // Note that OpenGL uses right-handed coordinate system, where + // camera is looking in negative z direction: + // OO + // |__|<-------------------- + // -z +z + // Consequently, OpenGL projection matrix given by these two + // references inverts z axis. + + // We do not need to do this, because we use DX coordinate + // system for the camera space. Thus we need to invert the + // sign of the values in the third column in the matrix + // from the references: + + ProjMatrix._33 = -(-(zFar + zNear) / (zFar - zNear)); + ProjMatrix._43 = -2.0f * zNear * zFar / (zFar - zNear); + ProjMatrix._34 = -(-1); + } +} + +inline void GetNearFarPlaneFromProjMatrix( const float4x4 &ProjMatrix, float &zNear, float &zFar, bool bIsDirectX ) +{ + if( bIsDirectX ) + { + zNear = -ProjMatrix._43 / ProjMatrix._33; + zFar = ProjMatrix._33 / (ProjMatrix._33 - 1) * zNear; + } + else + { + zNear = ProjMatrix._43 / (-1.f - ProjMatrix._33); + zFar = ProjMatrix._43 / (+1.f - ProjMatrix._33); + } +} + +inline float4x4 Projection(float fov, float aspectRatio, float zNear, float zFar, bool bIsDirectX) // Left-handed projection +{ + float4x4 mOut; + float yScale = 1.0f / tan(fov / 2.0f); + float xScale = yScale / aspectRatio; + mOut._11 = xScale; + mOut._22 = yScale; + + SetNearFarClipPlanes( mOut, zNear, zFar, bIsDirectX ); + + return mOut; +} + + +struct Quaternion +{ + float q[4]; +}; + +inline Quaternion RotationFromAxisAngle(const float3& axis, float angle) +{ + Quaternion out; + float norm = length(axis); + float sina2 = sin(0.5f * angle); + out.q[0] = sina2 * axis[0] / norm; + out.q[1] = sina2 * axis[1] / norm; + out.q[2] = sina2 * axis[2] / norm; + out.q[3] = cos(0.5f * angle); + return out; +} + +inline void AxisAngleFromRotation(float3& outAxis, float& outAngle, const Quaternion& quat) +{ + float sina2 = sqrt(quat.q[0]*quat.q[0] + quat.q[1]*quat.q[1] + quat.q[2]*quat.q[2]); + outAngle = 2.0f * atan2(sina2, quat.q[3]); + float r = (sina2 > 0) ? (1.0f / sina2) : 0; + outAxis[0] = r * quat.q[0]; + outAxis[1] = r * quat.q[1]; + outAxis[2] = r * quat.q[2]; +} + +inline float4x4 QuaternionToMatrix(const Quaternion& quat) +{ + float4x4 out; + float yy2 = 2.0f * quat.q[1] * quat.q[1]; + float xy2 = 2.0f * quat.q[0] * quat.q[1]; + float xz2 = 2.0f * quat.q[0] * quat.q[2]; + float yz2 = 2.0f * quat.q[1] * quat.q[2]; + float zz2 = 2.0f * quat.q[2] * quat.q[2]; + float wz2 = 2.0f * quat.q[3] * quat.q[2]; + float wy2 = 2.0f * quat.q[3] * quat.q[1]; + float wx2 = 2.0f * quat.q[3] * quat.q[0]; + float xx2 = 2.0f * quat.q[0] * quat.q[0]; + out[0][0] = - yy2 - zz2 + 1.0f; + out[0][1] = xy2 + wz2; + out[0][2] = xz2 - wy2; + out[0][3] = 0; + out[1][0] = xy2 - wz2; + out[1][1] = - xx2 - zz2 + 1.0f; + out[1][2] = yz2 + wx2; + out[1][3] = 0; + out[2][0] = xz2 + wy2; + out[2][1] = yz2 - wx2; + out[2][2] = - xx2 - yy2 + 1.0f; + out[2][3] = 0; + out[3][0] = out[3][1] = out[3][2] = 0; + out[3][3] = 1; + return out; +} + +inline float determinant( const float3x3& m ) +{ + float det = 0.f; + det += m._11 * (m._22*m._33 - m._32*m._23); + det -= m._12 * (m._21*m._33 - m._31*m._23); + det += m._13 * (m._21*m._32 - m._31*m._22); + return det; +} + + +inline float determinant( const float4x4& m ) +{ + float det = 0.f; + + det += m._11 * determinant( + float3x3 ( m._22,m._23,m._24, + m._32,m._33,m._34, + m._42,m._43,m._44) ); + + det -= m._12 * determinant( + float3x3( m._21,m._23,m._24, + m._31,m._33,m._34, + m._41,m._43,m._44) ); + + det += m._13 * determinant( + float3x3( m._21,m._22,m._24, + m._31,m._32,m._34, + m._41,m._42,m._44) ); + + det -= m._14 * determinant( + float3x3( m._21,m._22,m._23, + m._31,m._32,m._33, + m._41,m._42,m._43) ); + + return det; +} + +inline float4x4 inverseMatrix(const float4x4& m) +{ + float4x4 inv; + + // row 1 + inv._11 = determinant( + float3x3( m._22, m._23, m._24, + m._32, m._33, m._34, + m._42, m._43, m._44 ) ); + + inv._12 = -determinant( + float3x3( m._21, m._23, m._24, + m._31, m._33, m._34, + m._41, m._43, m._44) ); + + inv._13 = determinant( + float3x3 ( m._21, m._22, m._24, + m._31, m._32, m._34, + m._41, m._42, m._44) ); + + inv._14 = -determinant( + float3x3 ( m._21, m._22, m._23, + m._31, m._32, m._33, + m._41, m._42, m._43) ); + + + // row 2 + inv._21 = -determinant( + float3x3( m._12, m._13, m._14, + m._32, m._33, m._34, + m._42, m._43, m._44) ); + + inv._22 = determinant( + float3x3( m._11, m._13, m._14, + m._31, m._33, m._34, + m._41, m._43, m._44) ); + + inv._23 = -determinant( + float3x3( m._11, m._12, m._14, + m._31, m._32, m._34, + m._41, m._42, m._44) ); + + inv._24 = determinant( + float3x3( m._11, m._12, m._13, + m._31, m._32, m._33, + m._41, m._42, m._43) ); + + + // row 3 + inv._31 = determinant( + float3x3( m._12,m._13,m._14, + m._22,m._23,m._24, + m._42,m._43,m._44) ); + + inv._32 = -determinant( + float3x3( m._11,m._13,m._14, + m._21,m._23,m._24, + m._41,m._43,m._44) ); + + inv._33 = determinant( + float3x3( m._11,m._12,m._14, + m._21,m._22,m._24, + m._41,m._42,m._44) ); + + inv._34 = -determinant( + float3x3( m._11,m._12,m._13, + m._21,m._22,m._23, + m._41,m._42,m._43) ); + + // row 4 + inv._41 = -determinant( + float3x3( m._12, m._13, m._14, + m._22, m._23, m._24, + m._32, m._33, m._34) ); + + inv._42 = determinant( + float3x3( m._11, m._13, m._14, + m._21, m._23, m._24, + m._31, m._33, m._34) ); + + inv._43 = -determinant( + float3x3( m._11, m._12, m._14, + m._21, m._22, m._24, + m._31, m._32, m._34) ); + + inv._44 = determinant( + float3x3( m._11, m._12, m._13, + m._21, m._22, m._23, + m._31, m._32, m._33) ); + + auto det = m._11 * inv._11 + m._12 * inv._12 + m._13 * inv._13 + m._14 * inv._14; + inv = transposeMatrix(inv); + inv *= 1.0f/det; + + return inv; +} + +namespace std +{ + template + Vector2 max( const Vector2 &Left, const Vector2 &Right ) + { + return Vector2( + std::max( Left.x, Right.x ), + std::max( Left.y, Right.y ) + ); + } + + template + Vector3 max( const Vector3 &Left, const Vector3 &Right ) + { + return Vector3( + std::max( Left.x, Right.x ), + std::max( Left.y, Right.y ), + std::max( Left.z, Right.z ) + ); + } + + template + Vector4 max( const Vector4 &Left, const Vector4 &Right ) + { + return Vector4( + std::max( Left.x, Right.x ), + std::max( Left.y, Right.y ), + std::max( Left.z, Right.z ), + std::max( Left.w, Right.w ) + ); + } + + + template + Vector2 min( const Vector2 &Left, const Vector2 &Right ) + { + return Vector2( + std::min( Left.x, Right.x ), + std::min( Left.y, Right.y ) + ); + } + + template + Vector3 min( const Vector3 &Left, const Vector3 &Right ) + { + return Vector3( + std::min( Left.x, Right.x ), + std::min( Left.y, Right.y ), + std::min( Left.z, Right.z ) + ); + } + + template + Vector4 min( const Vector4 &Left, const Vector4 &Right ) + { + return Vector4( + std::min( Left.x, Right.x ), + std::min( Left.y, Right.y ), + std::min( Left.z, Right.z ), + std::min( Left.w, Right.w ) + ); + } +} \ No newline at end of file diff --git a/Common/interface/ComPtr.h b/Common/interface/ComPtr.h new file mode 100644 index 00000000..94e4b1f2 --- /dev/null +++ b/Common/interface/ComPtr.h @@ -0,0 +1,43 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Defines Diligent::CComPtr + +#include "RefCntAutoPtr.h" + +namespace Diligent +{ + template + class BlockAddRefReleaseCOM : public T + { + private: + virtual decltype( reinterpret_cast(nullptr)->AddRef() ) STDMETHODCALLTYPE AddRef()override = 0; + virtual decltype( reinterpret_cast(nullptr)->Release() ) STDMETHODCALLTYPE Release()override = 0; + }; + + template + using CComPtr = Diligent::RefCntAutoPtr; +} diff --git a/Common/interface/DataBlob.h b/Common/interface/DataBlob.h new file mode 100644 index 00000000..2940f1d3 --- /dev/null +++ b/Common/interface/DataBlob.h @@ -0,0 +1,53 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Defines Diligent::IDataBlob interface + +#include "Object.h" + +namespace Diligent +{ + +// {F578FF0D-ABD2-4514-9D32-7CB454D4A73B} +static const Diligent::INTERFACE_ID IID_DataBlob = +{ 0xf578ff0d, 0xabd2, 0x4514, { 0x9d, 0x32, 0x7c, 0xb4, 0x54, 0xd4, 0xa7, 0x3b } }; + +/// Base interface for a file stream +class IDataBlob : public Diligent::IObject +{ +public: + + /// Sets the size of the internal data buffer + virtual void Resize( size_t NewSize ) = 0; + + /// Returns the size of the internal data buffer + virtual size_t GetSize() = 0; + + /// Returns the pointer to the internal data buffer + virtual void* GetDataPtr() = 0; +}; + +} diff --git a/Common/interface/FileStream.h b/Common/interface/FileStream.h new file mode 100644 index 00000000..1263ef42 --- /dev/null +++ b/Common/interface/FileStream.h @@ -0,0 +1,58 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Defines Diligent::IFileStream interface + +#include "Object.h" +#include "FileSystem.h" +#include "DataBlob.h" + +namespace Diligent +{ + +/// IFileStream interface unique identifier +// {E67F386C-6A5A-4A24-A0CE-C66435465D41} +static const Diligent::INTERFACE_ID IID_FileStream = +{ 0xe67f386c, 0x6a5a, 0x4a24, { 0xa0, 0xce, 0xc6, 0x64, 0x35, 0x46, 0x5d, 0x41 } }; + +/// Base interface for a file stream +class IFileStream : public IObject +{ +public: + /// Reads data from the stream + virtual bool Read( void *Data, size_t BufferSize ) = 0; + + virtual void Read( Diligent::IDataBlob *pData ) = 0; + + /// Writes data to the stream + virtual bool Write( const void *Data, size_t Size ) = 0; + + virtual size_t GetSize() = 0; + + virtual bool IsValid() = 0; +}; + +} diff --git a/Common/interface/Object.h b/Common/interface/Object.h new file mode 100644 index 00000000..b404889e --- /dev/null +++ b/Common/interface/Object.h @@ -0,0 +1,79 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Defines Diligent::IObject interface + +#include "InterfaceID.h" +#include "Atomics.h" +#include "ReferenceCounters.h" + +namespace Diligent +{ + +/// Base interface for all dynamic objects in the engine +class IObject +{ +public: + /// Queries the specific interface. + + /// \param [in] IID - Unique identifier of the requested interface. + /// \param [out] ppInterface - Memory address where the pointer to the requested interface will be written. + /// If the interface is not supported, null pointer will be returned. + /// \remark The method increments the number of strong references by 1. The interface must be + /// released by a call to Release() method when it is no longer needed. + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; + + + /// Increments the number of strong references by 1. + + /// \remark This method is equivalent to GetReferenceCounters()->AddStrongRef().\n + /// The method is thread-safe and does not require explicit synchronization. + /// \return The number of strong references after incrementing the counter. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + virtual Atomics::Long AddRef() = 0; + + + /// Decrements the number of strong references by 1 and destroys the object when the + /// counter reaches zero. + + /// \remark This method is equivalent to GetReferenceCounters()->ReleaseStrongRef().\n + /// The method is thread-safe and does not require explicit synchronization. + /// \return The number of strong references after decrementing the counter. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + /// The only reliable value is 0 as the object is destroyed when the last + /// strong reference is released. + virtual Atomics::Long Release() = 0; + + + /// Returns the pointer to IReferenceCounters interface of the associated + /// reference counters object. The metod does *NOT* increment + /// the number of strong references to the returned object. + virtual IReferenceCounters* GetReferenceCounters()const = 0; +}; + +} diff --git a/Common/interface/ReferenceCounters.h b/Common/interface/ReferenceCounters.h new file mode 100644 index 00000000..ffef91d5 --- /dev/null +++ b/Common/interface/ReferenceCounters.h @@ -0,0 +1,115 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Defines Diligent::IReferenceCounters interface + +#include "InterfaceID.h" +#include "Atomics.h" + +namespace Diligent +{ + +/// Base interface for a reference counter object that stores the number of strong and +/// weak references and the pointer to the object. It is necessary to separate reference +/// counters from the object to support weak pointers. +class IReferenceCounters +{ +public: + /// Increments the number of strong references by 1. + + /// \return The number of strong references after incrementing the counter. + /// \remark The method is thread-safe and does not require explicit synchronization. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + virtual Atomics::Long AddStrongRef() = 0; + + + /// Decrements the number of strong references by 1 and destroys the referenced object + /// when the counter reaches zero. If there are no more weak references, destroys the + /// reference counters object itself. + + /// \return The number of strong references after decrementing the counter. + /// \remark The referenced object is destroyed when the last strong reference is released.\n + /// If there are no more weak references, the reference counters object itself is + /// also destroyed.\n + /// The method is thread-safe and does not require explicit synchronization. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + /// The only reliable value is 0 as the object is destroyed when the last + /// strong reference is released. + virtual Atomics::Long ReleaseStrongRef() = 0; + + + /// Increments the number of weak references by 1. + + /// \return The number of weak references after incrementing the counter. + /// \remark The method is thread-safe and does not require explicit synchronization. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + virtual Atomics::Long AddWeakRef() = 0; + + + /// Decrements the number of weak references by 1. If there are no more strong and weak + /// references, destroys the reference counters object itself. + + /// \return The number of weak references after decrementing the counter. + /// \remark The method is thread-safe and does not require explicit synchronization. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + virtual Atomics::Long ReleaseWeakRef() = 0; + + + /// Gets the pointer to the IUnknown interface of the referenced object. + + /// \param [out] ppObject - Memory address where the pointer to the object + /// will be stored. + /// \remark If the object was destroyed, nullptr will be written to *ppObject. + /// If the object was not released, the pointer to the object's IUnknown interface + /// will be stored. In this case, the number of strong references to the object + /// will be incremented by 1.\n + /// The method is thread-safe and does not require explicit synchronization. + virtual void GetObject(class IObject **ppObject) = 0; + + + /// Returns the number of outstanding strong references. + + /// \return The number of strong references. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + /// The only reliable value is 0 as the object is destroyed when the last + /// strong reference is released. + virtual Atomics::Long GetNumStrongRefs()const = 0; + + + /// Returns the number of outstanding weak references. + + /// \return The number of weak references. + /// \note In a multithreaded environment, the returned number may not be reliable + /// as other threads may simultaneously change the actual value of the counter. + virtual Atomics::Long GetNumWeakRefs()const = 0; +}; + +} diff --git a/Common/make/AppCommon.mk b/Common/make/AppCommon.mk new file mode 100644 index 00000000..454fcf19 --- /dev/null +++ b/Common/make/AppCommon.mk @@ -0,0 +1,11 @@ + +APP_PLATFORM := android-19 +APP_ABI := x86 armeabi-v7a +NDK_TOOLCHAIN_VERSION := 4.9 +APP_STL := gnustl_static + +ifeq ($(APP_OPTIM),release) + APP_CFLAGS := -O2 -DNDEBUG -g $(APP_CFLAGS) +else + APP_CFLAGS := -O0 -g -D_DEBUG $(APP_CFLAGS) +endif \ No newline at end of file diff --git a/Common/src/BasicFileStream.cpp b/Common/src/BasicFileStream.cpp new file mode 100644 index 00000000..09719821 --- /dev/null +++ b/Common/src/BasicFileStream.cpp @@ -0,0 +1,61 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" +#include "BasicFileStream.h" + +namespace Diligent +{ + BasicFileStream::BasicFileStream(const Diligent::Char *Path, + EFileAccessMode Access/* = EFileAccessMode::Read*/) : + m_FileWrpr(Path, Access) + { + } + + IMPLEMENT_QUERY_INTERFACE(BasicFileStream, IID_FileStream, TBase) + + bool BasicFileStream::Read(void *Data, size_t BufferSize) + { + return m_FileWrpr->Read( Data, BufferSize ); + } + + void BasicFileStream::Read( Diligent::IDataBlob *pData ) + { + return m_FileWrpr->Read( pData ); + } + + bool BasicFileStream::Write(const void *Data, size_t Size) + { + return m_FileWrpr->Write( Data, Size ); + } + + bool BasicFileStream::IsValid() + { + return !!m_FileWrpr; + } + + size_t BasicFileStream::GetSize() + { + return m_FileWrpr->GetSize(); + } +} diff --git a/Common/src/DataBlobImpl.cpp b/Common/src/DataBlobImpl.cpp new file mode 100644 index 00000000..9255f2e3 --- /dev/null +++ b/Common/src/DataBlobImpl.cpp @@ -0,0 +1,52 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + + +#include "DataBlobImpl.h" + +namespace Diligent +{ + +/// Sets the size of the internal data buffer +void DataBlobImpl::Resize( size_t NewSize ) +{ + m_DataBuff.resize( NewSize ); +} + +/// Returns the size of the internal data buffer +size_t DataBlobImpl::GetSize() +{ + return m_DataBuff.size(); +} + + /// Returns the pointer to the internal data buffer +void* DataBlobImpl::GetDataPtr() +{ + return m_DataBuff.data(); +} + +IMPLEMENT_QUERY_INTERFACE(DataBlobImpl, IID_DataBlob, TBase) + +} diff --git a/Common/src/Timer.cpp b/Common/src/Timer.cpp new file mode 100644 index 00000000..caf6ffdb --- /dev/null +++ b/Common/src/Timer.cpp @@ -0,0 +1,58 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" +#include "Timer.h" + +using namespace std::chrono; +namespace Diligent +{ + Timer::Timer() + { + Restart(); + } + + void Timer::Restart() + { + m_StartTime = high_resolution_clock().now(); + } + + template + T GetElapsedTime( high_resolution_clock::time_point StartTime ) + { + auto CurrTime = high_resolution_clock::now(); + auto time_span = duration_cast>(CurrTime - StartTime); + return time_span.count(); + } + + double Timer::GetElapsedTime()const + { + return Diligent::GetElapsedTime( m_StartTime ); + } + + float Timer::GetElapsedTimef()const + { + + return Diligent::GetElapsedTime( m_StartTime ); + } +} diff --git a/Common/src/pch.cpp b/Common/src/pch.cpp new file mode 100644 index 00000000..1a94193e --- /dev/null +++ b/Common/src/pch.cpp @@ -0,0 +1,31 @@ +/* Copyright 2015 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +// stdafx.cpp : source file that includes just the standard includes +// Common.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "pch.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file -- cgit v1.2.3