Improve StringHash Saving #2570
base: master
Are you sure you want to change the base?
Conversation
… hash value for "eventtype".
…aps. Added StringHash reversing to VariantMap saving in JSONValue and XMLElement.
@@ -141,7 +145,10 @@ bool ValueAnimation::SaveXML(XMLElement& dest) const | |||
const VAnimEventFrame& eventFrame = eventFrames_[i]; | |||
XMLElement eventFrameElem = dest.CreateChild("eventframe"); | |||
eventFrameElem.SetFloat("time", eventFrame.time_); | |||
eventFrameElem.SetUInt("eventtype", eventFrame.eventType_.Value()); | |||
if (StringHash::GetGlobalStringHashRegister() && !eventFrame.eventType_.Reverse().Empty()) | |||
eventFrameElem.SetAttribute("eventname",eventFrame.eventType_.Reverse()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space missing after ("eventname",
@@ -198,7 +209,7 @@ bool ValueAnimation::SaveJSON(JSONValue& dest) const | |||
JSONValue keyFrameVal; | |||
keyFrameVal.Set("time", keyFrame.time_); | |||
JSONValue valueVal; | |||
valueVal.SetVariant(keyFrame.value_); | |||
valueVal.SetVariant(keyFrame.value_,GetContext()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space missing after (keyFrame.value_,
@@ -211,9 +222,12 @@ bool ValueAnimation::SaveJSON(JSONValue& dest) const | |||
const VAnimEventFrame& eventFrame = eventFrames_[i]; | |||
JSONValue eventFrameVal; | |||
eventFrameVal.Set("time", eventFrame.time_); | |||
eventFrameVal.Set("eventtype", eventFrame.eventType_.Value()); | |||
if (StringHash::GetGlobalStringHashRegister() && !eventFrame.eventType_.Reverse().Empty()) | |||
eventFrameVal.Set("eventname",eventFrame.eventType_.Reverse()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space missing after ("eventname",
JSONValue eventDataVal; | ||
eventDataVal.SetVariantMap(eventFrame.eventData_); | ||
eventDataVal.SetVariantMap(eventFrame.eventData_,GetContext()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space missing after (eventFrame.eventData_,
@SirNate0 So if I understand this correctly, this affects only the reading from JSON and XML files? |
Marking this stale since there has been no activity for 30 days. |
I think I need to comment on this PR. I added Therefore, I recommend to treat Having said that, I don't defend hashes in the saved text formats. It's awful. |
Since we have the optional ability to compile support for a reverse StringHash lookup, I added the ability to save the string version rather than just the hash for VariantMaps and events in ValueAnimations. Without URHO3D_HASH_DEBUG enabled, reading from these strings is still supported, but saving will simply be done by the hash value instead.
As part of this I also added support for reading a VariantMap from JSON with arbitrary string keys, they simply have to be prefixed with $ to distinguish, for example "BAD" as a string from 0xBAD as a hexadecimal number. I'm open to a different marker besides $, I just like it as I believe it would be allowed in Javascript, it's easy to type, and it would generally be reasonably clear that it's a marker and not part of the string, plus $ looks a lot like S for String.