Advertisement

16 players, 512*512 tiles, 64*64 textures, why?

Started by July 26, 2004 07:01 AM
16 comments, last by CraZeE 20 years, 6 months ago
Look at this: Some games allow up to 16 players ... ... with maps that are 512*512 tiles ... ... with a 64x64 sized textures The combination of these values were randomly chosen, but it resembles what I often see: numbers that are powers of 2 where it does not seem needed at all. Why are things like the number of players very often powerers of two? What is the use of it? Why does OpenGL only want n*n textures where n is a power of two?
Quote: Original post by Sijmen
Why are things like the number of players very often powerers of two? What is the use of it? Why does OpenGL only want n*n textures where n is a power of two?

Maximum numbers of players are often powers of two because they're chosen by programmers (although, having said that, many games let whoever is hosting the game set their own limit...)

Textures should have width and height a power of two because the operations that the graphics card has to perform on them can be made faster if the sizes are limited to powers of two (otherwise the algorithm used has to be slightly more flexible to cope, which slows things down slightly). At least, afaik.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Advertisement
Max of 16 players might have to do because 16 fits *exactly* into 4 bits.. (well only if player 1 would be no. 0 and player 16 would be no. 15)
Since computers are built on the binary, The largest a varible can be is either a power of 2 or one less than that. It makes sense to utilize every variable to its highest degree.

Lets say you have a variable (amount of resources) that can be descibed by a byte. Since a byte is eight bits the largest the variable can be is 2^8 or 256 (more likely 255 because you will want to use zero as well). Now the programmer could limit the player to getting only 200 because that would be a nice round number in base 10, but why not let it extend all of the way to 255? More is better.

I can't answer why the graphics are that way, but I will assume it's for a similar reason.

Another thing to consider: When an RTS board is being set up, it helps to give each player an equal share of the board to begin with. You can think of this as slicing a pie. Have you every tried cutting a pie into 5 equal pieces? It is much easier to continue cutting each player's portion in half until you have the right number of players. Again- base 2
[s]I am a signature virus. Please add me to your signature so that I may multiply.[/s]I am a signature anti-virus. Please use me to remove your signature virus.
Sure, thanks.

In RTS games, indeed there is a good reason. But for FPS games, I'm still not sure.
Quote: Original post by Sijmen
Some games allow up to 16 players ...


I'm not aware of any particular reason for this, beyond the fact that the powers of two give you a decent amount of variety for different game types. e.g 16 player free for all, 2 teams of 8, 4 teams of 4 etc.

Quote:
... with maps that are 512*512 tiles ...


My guess is that this is usually convenience for whatever spatial partitioning structures/detail reduction algorithms are used in the map renderer. It's usually possible to support other sizes as well, it just requires a little bit more effort.

Quote:
... with a 64x64 sized textures


This is a hardware limitation. It's generally much easier for the gfx card to assume that all tetxures are a power of two for a variety of operations. Some of the more recent graphics cards support non-pow2 textures, but there are still plenty out there that don't.
Advertisement
It all has to do with programming-level concerns. Programmers are squeezing as much bandwidth/resource loading capability as possible out of the system. The other option is to write packing code, which, while interesting, is a waste of your time if you don't have to do it.

Take the 16 players example:
I have X players, each with a score from one to Y. I'm going to try to get them into as small a bitspace as possible. If I use a power of 2 for X, I can send a 4-bit header field that tells you how many players I'm describing. If I use anywhere from 9 to 15 player max, i still have to use 4 bits, wasting bits. A header packing scheme gets rid of wasted space, but there are almost always lost bits in there. Similarly, Y can be a power of 2, or I can waste more bitspace. Make those decisions 10,000 times and you've just lost yourself the technology war.
No Excuses
If I were designing a multiplayer game, I would make it a power of 2 for max players.

Simply because 15 would mean in a two team, full game, there would be uneven teams.

Whereas 16 would be 8 and 8, fair teams.

Now in a game where there are no teams, I might pick 1000, simply because it is a round number.

I think most people pick round numbers because they are... round. Not necessarily because they are programmers.

If you don't need a map of any particular shape, why pick funky or somewhat confusing sizes and options? Why not be simple and straightforward?

10x10, 12x12. I guess 11x11 works, but based on how we think in general, it's a less chosen path.
"Creativity requires you to murder your children." - Chris Crawford
Also, multiplying by a power of 2 can be done in a bitshift operation, which is much less costly than a multiplication.

This is the main reason for which tiles and textures are better with power of two sides: they are stored as single-dimensional arrays where texel/pixel (x,y) is stored in the array at index x+y*width.

The obvious optimization here is that if width is a power of two (say, 64 = 1<<6), then x+y*width can be computed as x+(y<<6), which is much more efficient, speed-wise.

There is another beneficial consequence of using poxer-of-two-sided tiles: determining which tile a player is in is much faster too. To do this, you'd divide the player position by the tile width (maybe substracting a constant somewhere if you're using offsets). Division by a power of two is also a bitshift.
In that case, you'd be using x>>6 instead of x/64 (and this, in the case of embedded gaming for instance, is essential, since divisions are exremely slow).

(Also notice that if D is a power of two, then x%D = x&(D-1), which is again faster than the % operation).
Quote: Original post by catch
I think most people pick round numbers because they are... round. Not necessarily because they are programmers.


Of course, to a programmer, the powers of two ARE round numbers...

This topic is closed to new replies.

Advertisement