last day (15 days later) » 

17:40
23
Q: How can a game handle all characters at once?

Developer NationThis question is just to gain knowledge about how a game can handle so many characters at once. I am new to gaming so I beg your pardon in advance. Example I am creating a tower defense game in which there are 15 tower slots where towers are built and each tower ejects projectile at a certain r...

Your computer's CPU speed is probably measured in gigahertz. That's billions of cycles per second. Updating 100 tower defence units isn't going to make it break a sweat (unless the game code is very inefficient at doing its work).
Games like Total War can handle armies of 100,000 soldiers, along with any projectiles they fire, complex troop movements, formations, thousands of random visual permutations for individual troops and other assorted game systems. I assure you that having 100 entities is not an issue at all.
It's sometimes difficult when beginning development to really understand how fast modern computers are at basic mathematical operations. I suggest that you create a test that simulates the handling for a unit or projectile and then run it to see how many times per second you can do that operation. Even without the many kinds of optimizations you can do to this kind of thing, I think you'll be surprised at how many you can handle.
I just recently made a gravity simulation where over 500 rocks influence each other and calculate for collision. In javascript!. Modern computers are overpowered. No need to worry.
Just make a loop, iterate over each character, and update the positions one by one. Give it a try and see if it's slow.
Sam
Sam
17:40
100 threads is not "too much for a PC" I have 579 running right now and I'm not doing all that much.
@Sam But how much process do you have running ? 100 threads for one process is a lot.
Am I the only one who thought this would be about unicode and font rendering?
You only think it's slow. You won't know until you test it.
Sam
Sam
@zakinster, it is not. a number of my processes are running 65+ threads. Admittedly that is not 100, but knowing how threads work I promise you 100 is not a a lot.
17:40
Google for game-loop and you will find a bunch of simple explanations how most games work and handle hell a lot of entities.
Just made a demo, a GT820 can handle 1k 3d objects with physics on 60fps, 10k objects with physics on 20fps.
Ask yourself related real world questions. The post office handles hundreds of millions of objects a day. Does it do so by hiring one worker (a thread) per object? Of course not. Rather, it builds systems that handle many millions of objects very quickly, and then takes advantage of the natural geographic separation of those objects to impose parallelism. Video games are no different. You build special purpose systems to handle millions of polygons per second, and organize the data well so that they can do their work.
I remember Age of Empires and StarCraft, which allowed up to 200 units per player for dozens of players, and those games ran on PCs from the 90s. I really do hope PCs nowadays are a tiny little bit more powerful than that...
@Nolonar The Starcraft limit of 200 per player could be broken via Dark Archons mind control.
@Nolonar In fact, you could double it: starcraft.wikia.com/wiki/Mind_Control
@Sam it is a lot. In general you should not use more than 2x no of cores system (real) threads. Otherwise context switching can kill Your app. But there is other solution, i. e. green (lightweight) threads, which runs in userspace. Unlike system threads (which are de facto independent processes) you can spawn them almost as much as you can. This is how it works In Go or Erlang.
17:40
@TomášZato: Ooh, show!

last day (15 days later) »