Game Development Community

Changing MaxMountedImages

by Derk Adams · in Torque Game Engine · 11/09/2004 (2:07 pm) · 9 replies

Greetings,

I need to increase the number of mount points from 8 to 32. In shapebase.h I have found:

// 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 = 32, ///< Should be a power of 2
MaxImageEmitters = 3,
NumImageBits = 3,
ShieldNormalBits = 8,
CollisionTimeoutValue = 250 ///< Timeout in ms.

and increased the MaxMountedImages to 32. But notice the warning at the top, which is true because just changing MaxMountedImages doesn't work. Further down:

enum ShapeBaseMasks {
NameMask = Parent::NextFreeMask,
DamageMask = Parent::NextFreeMask << 1,
NoWarpMask = Parent::NextFreeMask << 2,
MountedMask = Parent::NextFreeMask << 3,
CloakMask = Parent::NextFreeMask << 4,
ShieldMask = Parent::NextFreeMask << 5,
InvincibleMask = Parent::NextFreeMask << 6,
SkinMask = Parent::NextFreeMask << 7,
SoundMaskN = Parent::NextFreeMask << 8, ///< Extends + MaxSoundThreads bits
ThreadMaskN = SoundMaskN << MaxSoundThreads, ///< Extends + MaxScriptThreads bits
ImageMaskN = ThreadMaskN << MaxScriptThreads, ///< Extends + MaxMountedImage bits
NextFreeMask = ImageMaskN << MaxMountedImages
};

enum BaseMaskConstants {
SoundMask = (SoundMaskN << MaxSoundThreads) - SoundMaskN,
ThreadMask = (ThreadMaskN << MaxScriptThreads) - ThreadMaskN,
ImageMask = (ImageMaskN << MaxMountedImages) - ImageMaskN
};

So the question is, what do I have to change to get it to work with 32 instead of 8? I figured since it was last in the list that everything would be ok.

Thanks.

#1
11/12/2004 (7:35 am)
Hi,

Surely this won't work, because you run out of bits, shifting left by 32 bits bring the next mask to 0 generating an error in the packUpdate function.
The mask is a U32 so it is made of 32 bits, and you want to use them all just for the weapons, you can't unless you change the mask with something bigger, like a 64 bits integer or a bit vector class
#2
11/12/2004 (10:28 am)
I would suggest using a single mask for all the mounted images and just updating all of them whenever one changes, or updating them in groups of 4... basically, making the mask bit represent change for more than just one thing.
#3
11/12/2004 (11:41 am)
David,

Thanks, I understand.

Ben,

Ok, now I'm in over my head. Do you have any suggestions on how I can learn about masks and their use?

Thanks.
#4
11/13/2004 (3:18 am)
Derk,

Well, start by reading the NetObject docs in the Torque Engine Reference. You might also want to look at the TNL docs at www.opentnl.org - the Torque Networking Library has some differences from the network implementation in TGE, but the basic concepts are very similar.

If the notion of masks themselves is foreign to you, you might want to check out some tutorials on bitwise arithmetic and operations. Basically, the way Torque keeps track of ghost updates is by storing 32 flags, and setting one of those flags whenever state has changed. Then it can easily check to see if an update for that flag's data has to be sent.

Anyway, I hope that can give you a bit of a kickstart. You might also try asking nicely in the IRC channel - if you are lucky, someone there might walk you through the basics of how the networking system works.

Best of luck!
#5
11/16/2004 (12:43 pm)
Ben,

I ended up finding the Skin Modifier resource and it pointed me in the right direction. I have added a resource called Mount More Weapons or How to Get More Mask Bits which should help those coming behind me as soon as it is approved.

Thanks.
#6
11/17/2004 (4:07 am)
Hi Derk,
I've taken a fast look to your resource, and if it is used only in a single player game it should work fine, but in a client-server configuration you can have problems like weapons not mounting correctly on all the clients. If you want to use this method in a client-server environment test it heavily at least with one host and two clients, because with one host and one client perhaps you don't see the problem
#7
11/17/2004 (9:57 am)
David,

That is why I have a "Development Environment" section, so that users know what kind of system it worked on. I would like to have someone test multiplayer because I currently am developing a single-player system, with the possibility of lan support latter.

Thanks.
#8
11/17/2004 (10:05 am)
You see the line:

MountedMask = Parent::NextFreeMask << 3,

That says, I'll be able to refer to any mounted image by a single bit. 2^3 = 8, so to get 32, you'd do 2^5 = 32.. or

MountedMask = Parent::NextFreeMask << 5,

Done there.. now you need to figure out what other impact it has on the engine. See if there is anywhere else that it uses a left shift of 3 for the image masks.

- Brett
#9
11/17/2004 (10:50 am)
Brett,

No, that wouldn't work. The MountedMask is a single bit mask. It happens to be the 4th bit out of the 32 bits of the object mask. If I changed it to 5, then it would just be the 6th bit and confuse the system because the ShieldMask is in that position.

Thanks.