Browse Source

Add ToU8() for enums

1vanK 3 years ago
parent
commit
8595fb9e99

+ 1 - 1
Source/Tools/OgreImporter/OgreImporter.cpp

@@ -1017,7 +1017,7 @@ void WriteOutput(const String& outputFileName, bool exportAnimations, bool rotat
                 {
                 {
                     AnimationTrack& track = newAnimation.tracks_[i];
                     AnimationTrack& track = newAnimation.tracks_[i];
                     dest.WriteString(track.name_);
                     dest.WriteString(track.name_);
-                    dest.WriteU8((u8)track.channelMask_);
+                    dest.WriteU8(ToU8(track.channelMask_));
                     dest.WriteU32(track.keyFrames_.Size());
                     dest.WriteU32(track.keyFrames_.Size());
                     for (unsigned j = 0; j < track.keyFrames_.Size(); ++j)
                     for (unsigned j = 0; j < track.keyFrames_.Size(); ++j)
                     {
                     {

+ 7 - 0
Source/Urho3D/Base/Utils.h

@@ -10,6 +10,13 @@
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
+/// Converts enum class to u8 if underlying type is u8
+template<typename EnumClass>
+inline constexpr std::enable_if_t<std::is_same_v<std::underlying_type_t<EnumClass>, u8>, u8> ToU8(EnumClass enumClass)
+{
+	return static_cast<u8>(enumClass);
+}
+
 /// Converts enum class to u32 if underlying type is u32
 /// Converts enum class to u32 if underlying type is u32
 template<typename EnumClass>
 template<typename EnumClass>
 inline constexpr std::enable_if_t<std::is_same_v<std::underlying_type_t<EnumClass>, u32>, u32> ToU32(EnumClass enumClass)
 inline constexpr std::enable_if_t<std::is_same_v<std::underlying_type_t<EnumClass>, u32>, u32> ToU32(EnumClass enumClass)

+ 3 - 2
Source/Urho3D/Graphics/Animation.cpp

@@ -3,6 +3,7 @@
 
 
 #include "../Precompiled.h"
 #include "../Precompiled.h"
 
 
+#include "../Base/Utils.h"
 #include "../Container/Sort.h"
 #include "../Container/Sort.h"
 #include "../Core/Context.h"
 #include "../Core/Context.h"
 #include "../Core/Profiler.h"
 #include "../Core/Profiler.h"
@@ -11,9 +12,9 @@
 #include "../IO/FileSystem.h"
 #include "../IO/FileSystem.h"
 #include "../IO/Log.h"
 #include "../IO/Log.h"
 #include "../IO/Serializer.h"
 #include "../IO/Serializer.h"
+#include "../Resource/JSONFile.h"
 #include "../Resource/ResourceCache.h"
 #include "../Resource/ResourceCache.h"
 #include "../Resource/XMLFile.h"
 #include "../Resource/XMLFile.h"
-#include "../Resource/JSONFile.h"
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
@@ -224,7 +225,7 @@ bool Animation::Save(Serializer& dest) const
     {
     {
         const AnimationTrack& track = i->second_;
         const AnimationTrack& track = i->second_;
         dest.WriteString(track.name_);
         dest.WriteString(track.name_);
-        dest.WriteU8((u8)track.channelMask_);
+        dest.WriteU8(ToU8(track.channelMask_));
         dest.WriteU32(track.keyFrames_.Size());
         dest.WriteU32(track.keyFrames_.Size());
 
 
         // Write keyframes of the track
         // Write keyframes of the track