Jump to content

Fixing SFXPlaylist (writeFloat vs writeSignedFloat)


newaged

Recommended Posts

SFXPlaylist's pack function outputs too much data for the bitstream to handle, so I am reducing the amount of data it sends. Some of its default values are -1, so I was wondering if writesignedfloat has any downsides when compared to writefloat. Secondary topic, is assigning 10 bits for general data too much or too little?

Link to comment
Share on other sites

https://github.com/GarageGames/Torque3D/blob/2044b2691e1a29fa65d1bdd163f0d834995433ce/Engine/source/sfx/sfxPlayList.cpp#L375 wow, that is nasty... Would say you could reduce more than a little overhead on all but the corneriest of cornercases by killing that fixed 16 off and tracking the max amount of filled-in slots.


For the signed/unsigned thing, general rule of thumb is go ahead and leave it signed throughout the majority of the codebase. Might as well stay consistent there.


On the bitlength end, to use an example with more than a few variants: https://github.com/GarageGames/Torque3D/blob/2044b2691e1a29fa65d1bdd163f0d834995433ce/Engine/source/T3D/fx/particle.cpp#L351 general range is 7(also used for things like packing player aiming angles to give you another point of reference for fidelity) up to typically around 12-14 for a cap-out when folks have specified. Not really seeing anything listed requiring ultra-sensitive didgits there though, so could see trending on the lower end.

Link to comment
Share on other sites

Went along with the lower precision idea for a bit, but my basic coding skills weren't enough to make something stable. I decided to use a bunch of flags until I get better at C++.

The code changes for anyone who wants them.

 SFXPlayList::packData( sfx/sfxPlaylist.cpp line 366)
...
   FOR_EACH_SLOT stream->write( mSlots.mFadeTimeIn.mValue[ i ] );
  FOR_EACH_SLOT stream->write( mSlots.mFadeTimeIn.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->write( mSlots.mFadeTimeIn.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->write( mSlots.mFadeTimeOut.mValue[ i ] );
  FOR_EACH_SLOT stream->write( mSlots.mFadeTimeOut.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->write( mSlots.mFadeTimeOut.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->write( mSlots.mDelayTimeIn.mValue[ i ] );
  FOR_EACH_SLOT stream->write( mSlots.mDelayTimeIn.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->write( mSlots.mDelayTimeIn.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->write( mSlots.mDelayTimeOut.mValue[ i ] );
  FOR_EACH_SLOT stream->write( mSlots.mDelayTimeOut.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->write( mSlots.mDelayTimeOut.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->write( mSlots.mVolumeScale.mValue[ i ] );
  FOR_EACH_SLOT stream->write( mSlots.mVolumeScale.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->write( mSlots.mVolumeScale.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->write( mSlots.mPitchScale.mValue[ i ] );
  FOR_EACH_SLOT stream->write( mSlots.mPitchScale.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->write( mSlots.mPitchScale.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->write( mSlots.mRepeatCount[ i ] );
  ...
  SFXPlayList::unpackData(line 408)
  ...
     FOR_EACH_SLOT stream->read( &mSlots.mFadeTimeIn.mValue[ i ] );
  FOR_EACH_SLOT stream->read( &mSlots.mFadeTimeIn.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mFadeTimeIn.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mFadeTimeOut.mValue[ i ] );
  FOR_EACH_SLOT stream->read( &mSlots.mFadeTimeOut.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mFadeTimeOut.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mDelayTimeIn.mValue[ i ] );
  FOR_EACH_SLOT stream->read( &mSlots.mDelayTimeIn.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mDelayTimeIn.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mDelayTimeOut.mValue[ i ] );
  FOR_EACH_SLOT stream->read( &mSlots.mDelayTimeOut.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mDelayTimeOut.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mVolumeScale.mValue[ i ] );
  FOR_EACH_SLOT stream->read( &mSlots.mVolumeScale.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mVolumeScale.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mPitchScale.mValue[ i ] );
  FOR_EACH_SLOT stream->read( &mSlots.mPitchScale.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mPitchScale.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT stream->read( &mSlots.mRepeatCount[ i ] );

change that to this

SFXPlayList::packData
...
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mFadeTimeIn.mValue[ i ] != -1 ))
   stream->write( mSlots.mFadeTimeIn.mValue[ i ] );
  FOR_EACH_SLOT if (stream->writeFlag( mSlots.mFadeTimeIn.mVariance[ i ][ 0 ] > 0))
   stream->write(mSlots.mFadeTimeIn.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT if (stream->writeFlag( mSlots.mFadeTimeIn.mVariance[ i ][ 1 ] > 0))
   stream->write(mSlots.mFadeTimeIn.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mFadeTimeOut.mValue[ i ] != -1 ))
   stream->write( mSlots.mFadeTimeOut.mValue[ i ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mFadeTimeOut.mVariance[i][0] > 0))
   stream->write(mSlots.mFadeTimeOut.mVariance[i][0]);
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mFadeTimeOut.mVariance[i][1] > 0))
   stream->write(mSlots.mFadeTimeOut.mVariance[i][1]);
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mDelayTimeIn.mValue[ i ] > 0))
   stream->write(mSlots.mDelayTimeIn.mValue[ i ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mDelayTimeIn.mVariance[ i ][ 0 ] > 0))
   stream->write(mSlots.mDelayTimeIn.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mDelayTimeIn.mVariance[ i ][ 1 ] > 0))
   stream->write(mSlots.mDelayTimeIn.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mDelayTimeOut.mValue[ i ] > 0))
   stream->write(mSlots.mDelayTimeOut.mValue[ i ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mDelayTimeOut.mVariance[ i ][ 0 ] > 0))
   stream->write(mSlots.mDelayTimeOut.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mDelayTimeOut.mVariance[ i ][ 1 ] > 0))
   stream->write(mSlots.mDelayTimeOut.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mVolumeScale.mValue[ i ] != 1))
   stream->write(mSlots.mVolumeScale.mValue[ i ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mVolumeScale.mVariance[ i ][ 0 ] > 0))
   stream->write(mSlots.mVolumeScale.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mVolumeScale.mVariance[ i ][ 1 ] > 0))
   stream->write(mSlots.mVolumeScale.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mPitchScale.mValue[ i ] != 1))
   stream->write(mSlots.mPitchScale.mValue[ i ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mPitchScale.mVariance[ i ][ 0 ] > 0))
   stream->write(mSlots.mPitchScale.mVariance[ i ][ 0 ] );
  FOR_EACH_SLOT if (stream->writeFlag(mSlots.mPitchScale.mVariance[ i ][ 1 ] > 0))
   stream->write(mSlots.mPitchScale.mVariance[ i ][ 1 ] );
  FOR_EACH_SLOT if (stream->writeFlag( mSlots.mRepeatCount[ i ] > 0))
   stream->write( mSlots.mRepeatCount[ i ] );

   .....
SFXPlayList::unpackData
...
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mFadeTimeIn.mValue[ i ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mFadeTimeIn.mVariance[ i ][ 0 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mFadeTimeIn.mVariance[ i ][ 1 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mFadeTimeOut.mValue[ i ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mFadeTimeOut.mVariance[ i ][ 0 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mFadeTimeOut.mVariance[ i ][ 1 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mDelayTimeIn.mValue[ i ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mDelayTimeIn.mVariance[ i ][ 0 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mDelayTimeIn.mVariance[ i ][ 1 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mDelayTimeOut.mValue[ i ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mDelayTimeOut.mVariance[ i ][ 0 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mDelayTimeOut.mVariance[ i ][ 1 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mVolumeScale.mValue[ i ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mVolumeScale.mVariance[ i ][ 0 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mVolumeScale.mVariance[ i ][ 1 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mPitchScale.mValue[ i ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mPitchScale.mVariance[ i ][ 0 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mPitchScale.mVariance[ i ][ 1 ] );}
  FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mRepeatCount[ i ] );}

I do realize I could have just changed the slot count, but it still would have sent out a large amount of mostly blank data.

Link to comment
Share on other sites

@Azaezel I should probably mention that the last comment was about lowering the hardcoded value, not about your idea of detecting filled slots. That would work fine if I knew how to do it.


Anyways, I am posting here again because I will probably do github stuff soon. Does anyone have an opinion on this being one of the prs? Its not a pretty solution to the problem, but it doesn't break networking like whats in the engine right now.

Link to comment
Share on other sites

  • 2 months later...

I am still having issues with engine 3.8 and dedicated server. Mod the core game with a few new assets and when I try to connect to a dedicated server I get this:

Connection error: sfxResolve - Could not resolve local SFXDescription datablock with name '���'.

Any help?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...