Jump to content

PublicConstants for Second Energy System?


Steve_Yorkshire

Recommended Posts

Okay, here's a question which I could do with some help...


I have duplicated a new energy system for shapebase/player. Works just like the original but I wanted more than one. Do I have to add a new "enum PublicConstants" for this? It seems to work fine whether I do or do not.


shapeBase.h

class ShapeBase : public GameBase, public ISceneLight
{
/...
public:
   typedef GameBase Parent;
 
   enum PublicConstants {
      ThreadSequenceBits = 6,
      MaxSequenceIndex = (1 << ThreadSequenceBits) - 1,
      EnergyLevelBits = 5,
	  //Energy2LevelBits = 5,//yorks - is it okay to use EnergyLevelBits again? Or give this new value and make ThreadSequenceBits 7? Seems to work either way
      DamageLevelBits = 6,
      DamageStateBits = 2,
      // The thread and image limits should not be changed without
      // also changing the ShapeBaseMasks enum values declared
      // further down.
      MaxSoundThreads =  4,            ///< Should be a power of 2
      MaxScriptThreads = 4,            ///< Should be a power of 2
      MaxMountedImages = 4,            ///< Should be a power of 2
      MaxImageEmitters = 3,
      NumImageBits = 3,
      CollisionTimeoutValue = 250      ///< Timeout in ms.
   };
//...

Any explanation welcomed, preferably expressed in an idiot proof manner. ;)

Link to comment
Share on other sites

ok. so the way that works is

https://github.com/GarageGames/Torque3D/blob/014b5660146e86a7dab677047c99a7cd10fbbf36/Engine/source/T3D/player.cpp#L6162-L6164

+

https://github.com/GarageGames/Torque3D/blob/014b5660146e86a7dab677047c99a7cd10fbbf36/Engine/source/T3D/player.cpp#L6334


specify how many bits to pack into the network stream for acceptable precision in terms of notifying the client. If for some reason you needed one energy system to have better fidelity, then they'd need two separate definitions. If not, then no.

Link to comment
Share on other sites

@Azaezel Just to check, I take it I needed a new bit so my new Energy2 takes position 7 and the total ThreadSequenceBits also updates to 7?

That's what I've done it seems to work fine.

 

enum PublicConstants {
      ThreadSequenceBits = 7,//yorks was 6 is now 7
      MaxSequenceIndex = (1 << ThreadSequenceBits) - 1,
      EnergyLevelBits = 5,
	  Energy2LevelBits = 7,//yorks - added and given the next available bit which is 7
      DamageLevelBits = 6,
      DamageStateBits = 2,
//...
Link to comment
Share on other sites

Not quite sure... If you're using the same general setup as the other energy system, say...

   stream->writeFloat(getEnergy2Level() / mDataBlock->maxEnergy2, Energy2LevelBits);

what you've written there will send 7 bits instead of 5. same with the threadsequence end. was 6 bits, now 7.

Link to comment
Share on other sites

  • 2 weeks later...

Just a heads up on the existing energy system: It's part of the client-predictive networking and was intended to be used mainly for energy related to movement (or other client-predictable events).


Since it's part of writePacketData it will:

-Only be updated to controlling clients (during a correction) and

-Trigger correction packets if modified by a server-initiated event (as opposed to a client-predictable event initiated by a "move").

+Allow movement to be energy-dependent without worrying about being out of sync with the server. For example it would be network-safe to scale player movement speed by current energy level.


It's not the best choice if you're doing script-based abilities that drain energy, want a pool for weapons (not client predicted in stock), shield energy that drains when you take damage, etc. It will work but the correction packets will cause movement stuttering and waste bandwidth (sending the whole correction packet when all the client needed was 5 bits).

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...