
Alright, as usual, I was too lazy to actually carry through my idea of that "Interesting Projects.." column, which I described in my last post, and in another previous post which is also refered to in that previous post of mine. Anyhow, the point is that I probably won't be writing about the Morse Code-based Wireless Network I was developing from scratch, because I've been recently swept off my feet.
Not in 'The Pool', which I should tell you I have discontinued swimming in for a variety of reasons, but in my mind. I was hanging out at a friend's, and he showed me the video of a game by Will Wright (of The Sims fame) called Spore. The video was actually Wright's presentation at the Annual Game Development Conference where he presented his (and his team's) demo. I've never actually *awaited eagerly* the release of any game, or any movie, but this time, I do believe we are about to see a really revolutionary game which I just can't wait to get my hands on. I am probably not interested too much in the game, but in its source code and the concept that it uses to do the incredible things it does. Now that probably would be expected from a devoted game programmer, but how would you react if you could play a game where you see the entire universe in real-time, zoom in to any of the trillion^n stars with full detail, land on any of the near-infinite planets with full detail, control the evolution of species right from the stage of a single-celled organism to a developed animal, blow up planets with a *Death-Ray*, basically do whatever you want? All in real-time. Just imagine the amount of processing that would be required to simulate each and every cell/living-being, every planet, asteroid, comet, star, galaxy in the whole universe, every 50 milliseconds? Imagine the amount of storage required to store the data of all those things, all those cells and animals etc etc.. let's take a guess.. 40 Gigabytes? 40 Terabytes? Much more? Absolutely correct. Much more is indeed the amount it would take to store all that. So what am I talking about? What if I tell you that there exists a method to store all that data in about 10-15 bytes? That method is called Procedural Programming, where all the data required is generated on the fly.
Ever wondered why your games are always growing in size? Unreal 2000 came in about 1 CD, Unreal 2003 came in 3 CDs, Unreal 2004 came in 6 CDs, GTA San-Andreas takes about 6 GB of hard-disk space, and it goes on.. Why? The reason lies in the fact that the gamers are always demanding more realistic environments, we're not satisfied by barriers inside games, where you hit an invisible wall and can't go explore outside it. So they're making more detailed games, generating each and every building inside a city so that a player can explore all of them, generating textures on walls, basically generating everything beforehand. So if GTA-SA with just the measly amount of detail it has, takes 6 GB of space for code and data, imagine what the game I described in the above paragraph would take. In comes procedural programming. Procedural programming, as the name suggests, generates all the content on-the-fly. Each and every building is generated on the fly if required, all those textures are rendered on-the-spot if required. Now here is the important point, it doesn't simply generate *all* the buildings. It only generates what is *visible* to the player. How do you know if the universe still exists behind your back? This is the fundamental beauty of procedural programming. The time taken to render a single building or stuff like that is really quite small. As you may realise, procedural universes make a few compromises, but give you back much more. For example, with the simplest model I've described, its not possible to allow the player to *hear* a very loud bang at a place that he can't see, but neat programming tricks and hacks mostly tackle all those limitations.
At the heart of a procedural engine lies a seeded (or pseudo) random number generator, which essentially takes in a number and gives out a random number, except that the same random number is returned if the same original number is entered. So if I enter 5, it might return, say, 3.5. If I enter 23, it might return, say, 75. But every time I enter 5, it will always return 3.5, every time I enter 23, it will always return 75. That's why its a *seeded* random generator. The entered number, called the seed, gives us the same final number each time. So here a starting seed number is used, say A, and passed to a random number generator. The output number, say B, might be used to give us the number of buildings in the city. Now we iterate (loop) as many times as B (no. of buildings) and increment a particular variable, say 'i', by one each time. Inside each loop, we can pass the sum of B and I to the random generator, to get a particular number, say C, whose first two digits might give us the X coordinate of the building, and next two digits give the Y coordinate, and the next two digits, say D, are the seed for each building. Now we pass D into the random gen and get another number that might describe the properties of the building etc. And using a straight-forward technique we check which all points are visible to the player, and we generate only those buildings using the properties generated from D. All from a simple single number. As you can see, this need not end at just buildings, we can keep using the numbers after each random generation for more details, number of windows, number of people working in it, type of flooring, and the level of detail can be infinite. All from a single, say, two-digit number.
Obviously GTA-SA cannot be made using this method because the developers want a particular scripted story to play out, and the city generated in the above example is randomly generated. So trying to get a *particular* city, say, New York, using simple procedural generation would be worse than looking for a grain of sand in all the beaches of the universe. The entire city is generated from a single seed number, if we change the starting seed number (A) then the entire city changes, in all aspects. Big games have begun to use this kind of approach for small things, like making the textures on the walls, making rocks etc. But Spore is the first game that uses this approach for the entire game at the level it works on i.e. the universe.
Read up Procedural Generation on Wikipedia to get a better idea (and links to better descriptions). So what I'm upto is a universe-in-a-nutshell (literally!) thing, in the most efficient way. BTW, just as a side-info, procedural programming is almost as old as computers are. Ever heard of demoscene games (called demo-games) that work and look as good as Unreal 2003 and are all packed in just 96 KB (including the executable)? Look at .kkrieger. Demoscenes have been around ever since computers were first found as little electronic things like the Commodore, probably earlier.
I've been doing nothing else with my life, just programming, staring at TV since it has nothing interesting to watch, and sleeping.
6 comments:
amazing. So where have you reached with this project of yours?
I'm afraid not too far. As I've noted, I'm just lazing around, and I recently got a massive shock to note that I have been free as a bird for nearly 22 days now and I haven't achieved ANYTHING concrete yet.. I just feel too lazy to code when I finally sit in front of the PC, and once I have laid the foundations and know it can be done, I just don't feel like doing it anymore.
Basically, I have laid down the fundamental API code which I will use as the generic engine. That engine I will use to make a specific implementation, i.e. a Universe simulator. I had intended to make it like a game, but I am not sure if I have enough time left before I get busy with admissions and stuff. This Universe thing I promise (as far as possible!) to finish. I will put up the demos on the blog for you all to play with, once its done.
Nice to see ur blog....which univ/degree r u joining?
Why don't you drop in your name or a pseudo-name so that I can recognize you the next time you comment. :-)
Anyhow, the admission procedure and the counselling to list out the univs I'm eligible for is yet to take place.. it will be in July. Keeping my finger's crossed.
Ah, PCs are boring. I discovered that long back. Everyone feels lazy in front of them. But Macs, just looking at a brilliant 20-inch screen would make you feel like sitting and doing something productive. As of late, I have been having streaks of Mac fever and am somehow convinced that I should start saving money and try to pick up every rupee I find on the road, in the process.
But if I ever do buy it, it will definitely not be from India. I would rather pay $1299 instead of Rs.90000 for the same piece of hardware.
Picking up every rupee on the road or saving up won't get you rich enough to purchase a Mac in the near future. :-)
Post a Comment