realXtend / tundra

realXtend Tundra SDK, a 3D virtual world application platform.
www.realxtend.org
Apache License 2.0
84 stars 70 forks source link

Omit leading zeros when serializing float Attribute (and other Attributes consisting of floats) into TXML #768

Open Stinkfist0 opened 10 years ago

Stinkfist0 commented 10 years ago

Currently f.ex. a default constructed Transform attribute looks like this in TXML:

<attribute value="0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.000000,1.000000,1.000000" type="Transform" id="transform" name="Transform"/>

By omitting unnecessary leading zeros in floats we would save a lot of bytes:

<attribute value="0,0,0,0,0,0,1,1,1" type="Transform" id="transform" name="Transform"/>
jonnenauha commented 10 years ago

Yes please :)

jonnenauha commented 10 years ago

Should be fairly trivial too, util func to remove all trailing 0s.

Here https://github.com/realXtend/tundra/blob/tundra2/src/Core/TundraCore/Scene/IAttribute.cpp#L158-163

Then float2/3/4/Quat in the MGL classes https://github.com/realXtend/tundra/blob/tundra2/src/Core/TundraCore/Scene/IAttribute.cpp#L170

jonnenauha commented 10 years ago

Btw is it ok to modify the MGL classes in Tundra? I mean there is some kind of manual merge/diffing step each time we want a new version of MGL in? Are these mods going to make that harder for @cadaver or whoever does that?

jonnenauha commented 10 years ago

Actually maybe its better to just do the to string logic in IAttribute (copying the format from matlib) and do all that stuff via QString::number() etc. So we dont have to touch the math classes.

Stinkfist0 commented 10 years ago

Yeah it's probably better to do in IAttribute in order to keep the Tundra-specific mods of MGL at minimum.

cadaver commented 10 years ago

Yes, the more we mod MGL, the more troublesome it is to merge a new version. That is a manual process as Tundra's MGL is just files in the Tundra repo.

Therefore this is indeed preferable to do in eg. IAttribute.

Stinkfist0 commented 10 years ago

However, I see no harm in pinging clb regarding this matter; maybe he'd prefer to have this in MGL.

jonnenauha commented 10 years ago

I'm sure the only thing where Jukka uses strings is debug prints if even there, but still reading that stuff is much nicer without extra zeros.

@juj Any input? :)

juj commented 10 years ago

There were functions X::SerializeToString() added to MathGeoLib some time ago, see here https://github.com/juj/MathGeoLib/commit/40d39819f4068333a23c69557be275bf4f328d8a

Those functions have the two features:

Try that form, in particular the %.9g should omit trailing zeros, as opposed to the older %f that was used.

Stinkfist0 commented 10 years ago

Ok, nice, I think we can pretty safely modify our MGL copy to use the 'g' modifier.

jonnenauha commented 10 years ago

Sure would be nice to sync whole MGL into Tundra again, seems out last update has been 1 year ago :( SerializeToCodeString also looks it might be useful in Tundra code.

What was the main reason of keeping a copy in Tundra source tree instead of using it as a pre-built dependency?