Integer bit size?
by Daniel Buckmaster · in Torque Game Engine · 12/23/2007 (1:57 am) · 3 replies
I'm adding a timer to a custom class, and I assume I need to send the timer's value down the network. The time is kept in an S32 that is increased every processTick. When I use stream->writeInt or readInt, I need to have a value representing the bit size of, I guess, the first argument. My question is, what is a reasonable size for that? I put 32 because I have no idea, but NetConnection::GhostIdBitSize is 12. What does this represent?
About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#2
The minimum is zero, of course, but I've no idea what the maximum will need to be. The trigger will need to be held down for quite a while for some weapons, I guess...
If I set the size at 12, that means 4096 states. So at 16 ticks/sec (right?), that's 256 seconds of time, approximately. That should be enough :P. Maybe I'll make it smaller, if it'll do anything useful.
12/23/2007 (10:47 pm)
So you basically get 2^n states where n is the bit size?The minimum is zero, of course, but I've no idea what the maximum will need to be. The trigger will need to be held down for quite a while for some weapons, I guess...
If I set the size at 12, that means 4096 states. So at 16 ticks/sec (right?), that's 256 seconds of time, approximately. That should be enough :P. Maybe I'll make it smaller, if it'll do anything useful.
#3
Lets say that you allow 0 - 8194 (13 bits) but before you transfer the data you divide by 2 giving 0 - 4192 (12 bits) because you now that the difference of 1 tick isn't big enough to care about missing.
Don't forget that you can also clamp the value to a maximum if it makes sense to your application. If you are keep track of whether a weapon is charged or not and it becomes charged after 1 seconds, then clamp the value at 1 second. You don't care if they've held it for 2 seconds.
These tricks are all application specific but can be used to help reduce network traffic.
12/24/2007 (7:29 am)
Unless you need a lot of precision for your timer you can divide the value before transmitting it to make it even smaller.Lets say that you allow 0 - 8194 (13 bits) but before you transfer the data you divide by 2 giving 0 - 4192 (12 bits) because you now that the difference of 1 tick isn't big enough to care about missing.
Don't forget that you can also clamp the value to a maximum if it makes sense to your application. If you are keep track of whether a weapon is charged or not and it becomes charged after 1 seconds, then clamp the value at 1 second. You don't care if they've held it for 2 seconds.
These tricks are all application specific but can be used to help reduce network traffic.
Torque Owner Michael Bacon
Default Studio Name
In 2 bits we get 4 states or a number between 0 and 3.
In 3 bits we get 8 states or 0 to 7
4 - 16 - 0 to 15
5 - 32 - 0 to 31
and so on.
So the real question is what are the valid values of your timer variable? You need to allow for the minimum and maximum value of your variable.
If you need more help, start by providing these values.