Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Improve StringHash Saving #2570

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

SirNate0
Copy link
Contributor

@SirNate0 SirNate0 commented Jan 4, 2020

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.

@ArnisLielturks ArnisLielturks added the улучшение Улучшение существующих вещей label Feb 3, 2020
@@ -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());
Copy link
Contributor

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());
Copy link
Contributor

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());
Copy link
Contributor

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());
Copy link
Contributor

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_,

@ArnisLielturks
Copy link
Contributor

@SirNate0 So if I understand this correctly, this affects only the reading from JSON and XML files?

@github-actions
Copy link

github-actions bot commented Mar 9, 2020

Marking this stale since there has been no activity for 30 days.
It will be closed if there is no activity for another 15 days.

@github-actions github-actions bot added the stale label Mar 9, 2020
@weitjong weitjong added backlog and removed stale labels Mar 9, 2020
@eugeneko
Copy link
Contributor

eugeneko commented Apr 6, 2020

I think I need to comment on this PR.

I added StringHash reversal functionality for debug purposes only and I actually expect users to disable it before shipping. It's called URHO3D_HASH_DEBUG for that reason.
I never profiled it and I think it slows down some segements of the code.

Therefore, I recommend to treat URHO3D_HASH_DEBUG somewhat like debug C++ build.
Sure, you can do nice debug-only things like logging, but they shouldn't affect functionality.

Having said that, I don't defend hashes in the saved text formats. It's awful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backlog улучшение Улучшение существующих вещей
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants