In Starcraft, you construct a base, manage an economy, and train military units to tear down the other opponent until either all their buildings are gone, or until they leave. Each unit you train has a designated "food usage", meaning that you may create a unit until you run out of "supply", or your food count is lower than the required food usage. To manage this, you create supply buildings (or in zerg's case, Overlords) to increase your supply. However, you may only have a maximum of 200 food. This is called an object pool.
| In Starcraft, you may use a maximum of 200 food. When a unit dies, it no longer uses that food. |
You can think of the object pool as an array. You have this array of 10 circles as such:
Circle[] circles = new Circle[10];
Now, say you want to use 3 spots in the array to create 3 circles, so you would type:
for(int x = 0; x < 3; x++)
{
circles[x] = new Circle(3.4f); // 3.4f would be the "radius" in this case
}
Now say you wanted more than three, you would simply designate which "empty circle" you want to use to contruct a new one.
circle[6] = new circle(4.2f);
But what if you want to "destroy" one of these circles? Well, when using pools, you don't actually "destroy" an object. You simply just change its properties to make it what you call empty.
circle[3].radius = 0;
Or you can create a boolean variable "IsActive" to let the program know if it is active or not.
circle[3].IsActive = false;
When you have a property like this, you can make a constantly running function that runs through all the objects (circles, in this case), check if it is active, if not, do not use (in video game design, you can tell the engine not to render the "circles" that are inactive)
void CheckCircles()
{
for(int x = 0; x < circles.length; x++
{
if(circles[x].IsActive)
circles[x].Draw(); //If the circle IS active, then the engine will draw it on the screen
}
}
The reason why "pooling" is standard practice is because it is an efficient way to handle multiple objects. Why would you want your game to constantly create hundreds, even thousands of objects, and then just get rid of the memory? Why not just re-use those objects? If you have any questions about pooling, please post in the comments.
I just reinstalled SC the other day.
ReplyDeleteInteresting :D
ReplyDeleteThanks for the tips, I've been working on a similar project for a while and your method is perfect for what I'm doing.
ReplyDeletenice read. any knowledge to help with game making is fine by me.
ReplyDeletenow if only you could make a script that could beat all those crazy Korean players :p
ReplyDeleteAhhh, Starcraft. Love it.
ReplyDeleteOh, starcraft. you owned my junior high school days.
ReplyDeleteA developer blog - Yay!
ReplyDeleteInteresting, I've never understood why it was called that.
ReplyDeletethanks ,, this is very usefull ;)
ReplyDeleteGood old StarCraft, I've not played it in a while I've been meaning to pick up StarCraft 2
ReplyDeletevery helpfull ,thanks ill be sure to get some of that in to my sc if I ever play it again :D
ReplyDeleteo great! very useful thanks for post
ReplyDeletelooks like gibberish to me lol :P the code i mean
ReplyDeleteI never knew pools worked like this. Thanks for the infos.
ReplyDeleteHey man, good article and im real excited you got it out there for the people to see. Web servers work the same way for the same reason. Its more efficient to have a pool of threads created up front, then to create and destroy threads as web pages are requested.
ReplyDeleteGreat help, nice to see developer blogs out there.
ReplyDeleteVery interesting blog, Definitely will be following!
ReplyDeleteCheers,
Mike
This is interesting, will have to try this out.
ReplyDeleteyey nice
ReplyDeleteThat 200 cap was always a bitch
ReplyDeletevery helpful, thanks!
ReplyDeleteI'm planning on going to school for coding, this is useful information for seeing how to put code into action.
ReplyDeleteawesome taking advantage of the coding! thanks bro.
ReplyDeletesupported!
collegeanon.tk
Wow this is great!
ReplyDeleteI'm in my first IT year so this will be great
Never thought about that.
ReplyDeletegreat post. following you
ReplyDeletetrying to get my head around the code but interesting stuff
ReplyDeleteGreat post, i am actually just getting into game programming. Can't wait for more.
ReplyDeleteThanks for the dev info, gonna pass it on to my friends that could use it
ReplyDeleteThanks for the great resource. If I get back into game development, I'll definitely be using your tips.
ReplyDeleteGreat info, cheers.
ReplyDeleteOver-kill!! for me.. hehe but i like the picture ;) Neard..
ReplyDeleteHaven't coded in ages. Would like to try some game coding but I'm afraid can't teach new tricks to old dogs
ReplyDeleteThe memories...
ReplyDeletedeveloper blogs are always interesting to watch because you find so many things you haven't known in before :)
ReplyDeleteI wish I could code, but I am to lazy to learn it ;-)
ReplyDeleteNot familiar with this kind of stuff but I like the way you explain it
ReplyDeleteDude you gotta make a new post soon i wanna see what youre gonna post next
ReplyDeleteWow, that seems really complicated.
ReplyDeleteLol @ Xuian's comment. If only there was a script to beat the Korean players.
ReplyDeleteI still have XNA somewhere around here.. might install it
ReplyDeleteNice and very interesting
ReplyDeletegreat tip
ReplyDeleteWish that was standard in all rts games. Micro-managing 100s of little buildings spoils things a lot.
ReplyDeletelooks like gibberish to me lol :P the code i mean
ReplyDeleteDeveloper blog, looks pretty cool, I'll have to read through the rest of your posts when I have some time.
ReplyDeleteFound you on youtub! Interesting stuff :)
ReplyDeletenice explanation thanks
ReplyDeletethat was interesting as I try to learn c++
ReplyDeleteI didnt know anything about pooling before this and I love starcraft. Great post!
ReplyDeleteSo confusing.
ReplyDeleteProgramming makes me feel dumb, probably because I am.
ReplyDeleteUm. I thought this was a guide to starcraft then I realized I was wayyyy in over my head. Got zerg rushed by a bunch of terms I've never heard of.
ReplyDelete:)