Register


Active : 981
Logged in : 359
Time: 16:02 KST

User Streams
40 online (4 live)
Home | Forum | VODs | Liquibet | Fantasy | Blogs | Liquipedia | Articles | Store
Search TeamLiquid.net
Starcraft Progaming News
[TSL] Go Go Go!
[PL] Lim-Jin Rok
[TSL] Ladder with Legends
[OSL] The End of the Begi…
[MST] The Beginning of th…
Featured Threads
Recommended VODs of rece…
TL User Locations
Small Vod Thread.
Funny Quotes from TL's I…
Team Liquid Manpower
General Forum
Marijuana in American Cu…
White-Ra's face is EVERY…
Best Rock Songs
Comp/SC help needed 2
[ABC]V remake
Starcraft 2 Forum
Zerg spies?
New race in SC2?
Vote for SC2 in Spike's …
StarCraft II Q&A Batch 55
Data Editor: Mod Examples
Starcraft: Brood War Forum
[Interview] SPL KT vs Ace
KeSPA Dream League
Day[9].tv Daily
Post your cheese/rush/fu…
OSL audience
Starcraft Tournaments and Leagues
[OSL] Group Selection
[SPL] STX Soul vs Samsun…
[SPL] SK Telecom T1 vs W…
[SPL] Airforce ACE vs KT…
$1000 - ASL Season II
Starcraft Strategy Forum
[Guide] Map Analysis - F…
Why does destination fav…
[Q]Protoss FE vs 5 pool?
ZvT 3 Hatch Muta - Adapt…
Recommended Threads
Sports & Games Forum
[HoN/DotA] Let's Play~!!
League of Legends
Left 4 Dead 2 - TL Nerds
modern warfare 2
NFL 2009!!!
Blogs
Starcraft Replays
By.FlaSh - Best[WHITE]
By.FlaSh - Tempest)Is(
Light[aLive] - By.hero
Bisu - HyuK
By.FlaSh - By.hero


Website Feedback

Closed Threads

IRC Updated
irc.quakenet.org #teamliquid

IRC Web Client
New to Team Liquid? Register here!

Random Bill Stuff

Join the PokerStrategy.com TSL ladder for a chance at $22,000 in prizes!
rss
  Bill307, Sep 03 2009

Here's a funny game development experience my friend and I had recently...

Last week, I added the ability for our prototype game to play random sounds for things like enemies being shot or killed.

Like all game programming tasks, once a flexible groundwork was laid, I could add as many sounds for as many events as I liked. So I added a gratuitous number of sound effects, including a number of Ahnold voice clips that I downloaded online.

For example, when an enemy is shot for the first time, he'll respond with one of 10 sound effects, such as Apu saying "I'm gonna kill you!" or Ahnold's "I'm a cop, you idiot!"

(Ideally, I'd like to get a bunch of clips of Ahnold making his "auleahuelhauhelahela" noises and play them as an enemy is being hit rapidly. )

So anyway, a few days ago we were working at my friend's place when his uncle, aunt, and 8 year old cousin dropped by for a visit. We love getting feedback from people when they try our prototype, so my friend sat down with his cousin to show him our work-in-progress.

Leaping into action, I immediately tell my friend telepathically that we should comment out a few "inappropriate" things before showing his young cousin the game. Sadly, my attempt at ESP fails as he approaches an idle enemy.

Things get off to a rough start: the enemy, doing random idle actions like a stationary hydra, refuses to do the cute head-scratching animation that my friend had made earlier. After the 5th "Okay watch this he's gonna scratch his head now!", my friend loses his patience and just shoots the bastard. The enemy responds with one of the Ahnold voice clips I'd downloaded. The parents stare in shock as Ahnold shouts in the boy's face:

"FUCK YOU ASSHOLE!"

*silence*

.....

"So notice how as you shoot him, he turns white indicating that he's been hit..."

My friend gracefully changes the subject, but you can tell from the looks on the parents' faces that they are not pleased by what just happened.

There was only a 1-in-10 chance of that one PG-13 sound being played, too.


A few minutes later and everyone is back to normal, but I'll never forget the feeling of horror we had when that happened. ^^;;



*****

Comments (9)


  Bill307, Jul 16 2009

Since ~January, I've been hard at work programming a mid-sized (from my perspective) game. Through this experience, I've learned and come up with a number of code design ideas, both good and bad. To save others from making the same mistakes that I did, and to give others ideas for their own games or programs, I've decided to share some of my experience here.

Please comment if you found this information useful / easy to understand / hard to understand, or if you have suggestions or improvements for it.

By the way, the game is being programmed in C# using XNA Game Studio. It's also a long way from being finished, so many aspects of the game have not matured yet and won't be covered here.


--------------------------------------------------

Class Organization

Below is an overview of many of the game's classes, showing how they are organized from the top down, i.e. from general knowlege to specific knowledge.

  • Game class -- the over-arching class that encompasses the entire game. Essentially all of the game logic is off-loaded to other classes. It also provides static methods for accessing "global" objects anywhere. (Using XNA's "game services" functionality.)

  • Stage Updater and Stage Drawer classes -- these classes manage the game logic and rendering of the game, respectively. These also off-load most of the work to other classes. All they really know is the order in which parts of the game are updated/drawn.

  • Various manager classes -- e.g. Enemy Manager, Bullet Manager, etc. These classes know some of the detailed game logic for their own little subsets of game objects.

  • Various game object classes -- e.g. Enemies, Bullets, Explosions, Players, etc. These classes are self-explanatory, and contain the rest of the detailed game logic.

  • Lower-level classes and data structures -- e.g. Sprites, Particles, Hitboxes, Custom Lists, Custom "Vertex Buffers", inactive object Pools, etc. These don't contain any game logic, and handle small, common tasks like displaying sprites, moving particles, checking for hitbox collisions, storing vertices, etc.

  • Physics class -- handles all game physics (just basic linear kinematics with linear forces, acceleration, velocity, and position, and all objects being treated as circles/spheres). The only "physics" code outside of this class is simple stuff like adding an acceleration to a velocity, or multiplying a force by the inverse of a mass to get an acceleration.

  • ... and more!

--------------------------------------------------

Pooling Objects

When a game is running, you want to create and destroy as few objects as possible (outside of loading screens and the like). This is especially true when using a managed language such as C# or Java that uses garbage collection.

A common solution to this problem in general is to use "pools" of inactive objects.

Basically, your objects have two pairs of methods:
- a constructor and a destructor / Dispose()
- Activate() and Deactivate()

When objects are created, they are initially inactive and don't do anything. You start your game / level by creating a bunch of these inactive objects and sticking them in a pool (e.g. a stack). Then whenever your game needs one of these objects, instead of creating a new one, it gets an inactive one from the pool. Similarly, when an object is no longer needed, it is not destroyed / disposed of: it is deactivated and stuck back into the pool.

Sounds simple, but there's a caveat: when an object is deactivated, you have to remove all references to it (aside from the pool) immediately. E.g. if an enemy explodes and disappears, the Enemy Manager needs to stop calling its Update() and Draw() methods, homing missiles need to stop following it, etc. You have to remove all these references immediately. E.g. you could use the Observer design pattern (event sending and receiving) to accomplish this.

You might think of adding an IsActive() method as an alternative, and each time something wants to use the object, it checks whether the object is still active before using it, and removes the reference to the object if it is inactive. Unless you do some ugly workarounds, this isn't going to work, because the object could be reactivated as a totally different object. It's much simpler to just remove all references to the object right away.


--------------------------------------------------

Drawing Sprites yourself

This tip is for do-it-yourself sprite-drawing, in contrast to using a sprite-drawing library such as XNA's SpriteBatch. (I don't use SpriteBatch mainly because it uses a different coordinate system from all the 3D graphics.)

Sprites can be rendered in 3D in one of two ways: Orthographic Projection, or Billboards. Which method you use doesn't matter. In both cases, you're drawing the sprite on a rectangle made from two triangles.

When you learn how to draw a sprite on a quad (a rectangle), you get some tutorial code that will draw a single sprite for you. Chances are, when you want to draw a collection of sprites, you'll simply run that tutorial code for every sprite.

THIS IS BAD!! Your game will slow below 60 fps with just a few hundred sprites. Even something as simple as a 30x30 grid of tiles will bring your graphics card to its knees if you draw it like this!

The problem is that your graphics card is designed to process a large number of vertices / polygons all at once, but instead, you're sending it 4 vertices / 2 polygons at a time.

The solution is to put all your sprites' vertices into one big array, then tell your graphics card to draw that. Yes, it really makes a BIG difference! E.g. previously, only 3 particle explosions (~50 sprites each) were enough to slow down my game, but after I made this change, I could fill the screen with explosions without any drop in framerate.

More precisely, you need to group all your sprites' vertices by texture, then for each texture, draw all the sprites that use it (as a big array of vertices). So you'll want to put multiple sprite images into a single texture, instead of giving each sprite its own texture. (If you've ever seen a "sprite rip" of a game, then you'll know what I mean. )


--------------------------------------------------

A way to organize your collision detection (hitbox) code

It's a good idea to take your code for comparing hitboxes against each other and put that into its own class(es), as opposed to putting that logic into every single class with a hitbox.

For example, you can make a Hitbox class that stores four coordinates -- x1, y1, x2, and y2 -- and provides a method to test if it is overlapping another Hitbox.

But what if some of your game objects have multiple hitboxes, like an irregularly-shaped enemy? Or maybe you want to give some objects Hitcircles instead of Hitboxes? Or maybe you want to check against a bounding box before doing finer collision detection? In any case, it'd be nice to have all of this mass wrapped away in some separate class heirarchy, so that all your player or enemy needs to do is "myHitArea.IsOverlapping(otherHitArea)" no matter how complicated the collision areas actually are.

My first attempt at designing this code was a huge failure. It's so obviously bad in retrospect that I won't even bother sharing it here.

Instead, I'll share my second attempt, which I'm implementing right now. (By the way, a good way to check if your design is good or bad is to try writing it out like this. It'll help you to see problems with your design that you wouldn't have found if you kept it in your head, especially when you try to explain why your design is so good.)

I'm going to make a class called HittableArea, that has a method "Overlaps(HittableArea other)" to check if this area overlaps the given one. I'm going to make an interface called Hittable that has a method "GetHittableArea()" that returns the object's collision area. Every player, enemy, bullet, crate, etc. in my game is going to implement Hittable, and have a HittableArea object to keep track of its hitbox / bounding box / finer hitboxes / whatever.

So whenever I need to do a collision test, I can just write:

bullet.GetHittableArea().Overlaps(player.GetHittableArea());


And that's it: that's my whole design.

Why is this a good design? Because it works even though we don't know anything about how HittableArea works. (Hell, not even I know how it'll work just yet.) It decouples the long and volatile collision detection code from the rest of my program, simplifying the rest of the code and making the collision detection code much easier to modify.

This will definitely be slower than a simple hitbox-hitbox check, however. But this is something I should look into at the END, when the game is 99% finished. If this code is causing a bottleneck, then I can optimize it knowing I probably won't need to change it again. (As opposed to right now, where I may decide the player won't have just a simple hitbox, or that some bullets will have two hitboxes, etc.)


--------------------------------------------------

Passing some of your game objects' initialization parameters in structs

Suppose you're activating a new game object. (Activating, not constructing, since you got an inactive one from a pool. )

Your activation method might look like this:

public void Activate(Vector2 position, Vector2 velocity, float mass, float size, int hitpoints, float aggression, bool isAsleep, ...)


I suggest replacing it with something like this:

public void Activate(Vector2 position, Vector2 velocity, Params ps)


Where Params is a data structure like this:

public struct Params
{
public float mass;
public float size;
public int hitpoints;
public float aggression;
public bool isAsleep;
...
}


(in Java, you can use a class instead of a struct, but keep in mind you might end up frequently creating and destroying instances of the class, whereas a struct in C/C++/C# is passed by-value)

Right away, you can see that the Activate() method looks a lot cleaner, but that's not the main reason to do this.

The main motivation is that if/when you start storing your game data in XML or binary files, you're going to want a data structure like that, anyway, to contain the same data as your XML/binary file. If you're really lucky, you might not have to change your old code at all when you want to load your game data from a file instead. Speaking of which...


--------------------------------------------------

Loading Game Content, part 1: Game Data class

This is a new idea I came up recently, so it might actually be terrible.

Originally, all our game content -- enemy properties, level design, etc. -- was being loaded all over the place. Eventually the time came to actually organize all this code. So I decided to store all of our game content in a single class called Game Data.

Whenever the game needs some content, it always loads it through the Game Data class. The reason for this is that it allows me easily to change whether this content is loaded from hard-code, or an XML file, or a binary file, or wherever. See, right now almost all of our content is hard-coded, but eventually we'd like to store it in XML or binary files. My hope is that, when the time comes to switch from hard-coded to file-loaded content, I'll have to modify only a single method.

E.g. suppose we've written a map editor and now our maps are stored in XML files. In theory, all I'd have to change is the folllowing:

public static MapParameters GetMap(String name)
{
// OLD:
//return mapHashtable.Get(name); // all the hardcoded map data is stored in this hashtable

// NEW:
return XMLLoaderThingy.Load(MAP_PATH + name);
}


Hopefully this will actually work well in practice.


--------------------------------------------------

Loading Game Content, part 2: Data Loading classes

This is a simple improvement to how I load all my static game content at the start of the game. Note that I haven't really thought about how to load content in short bursts between levels instead of loading it all at the start of the game, so this idea might flop hard if/when we need to do that. Anyway, at least it's better than what I was doing before.

Game has a method called LoadContent() that's called by XNA at the start of the game, and it's the place where you're supposed to load all of your game content. Originally, this method looked like:

Game.LoadContent()
{
Enemy1.LoadContent();
Enemy2.LoadContent();
Map1.LoadContent();
Map2.LoadContent();
HitBox.LoadContent();
Sprite.LoadContent();
ExplosionParticle.LoadContent();
// etc.
}


Basically, every class that had to load some static data had its method called here. This mess was compounded by the fact that the Game class is already bloated with other code.

The solution: every code folder (that needs one) has a class like "LoadEnemyData" that calls LoadContent() for each class in that subfolder. So the code flows like this:

LoadGameData.LoadContent() // load root folder
--> Hitbox.LoadContent()
--> Sprite.LoadContent()
--> ...
--> LoadEnemyData.LoadContent() // load enemies folder
----> Enemy1.LoadContent()
----> Enemy2.LoadContent()
----> ...
--> LoadMapData.LoadContent() // load maps folder
----> Map1.LoadContent()
----> Map2.LoadContent()
----> ...
--> ...


And so on. Much cleaner than putting everything in the Game class.


--------------------------------------------------

Well, that's it for now. I probably won't write one of these again unless a significant # of people actually learn from this one or start some good discussion around it. Enjoy!




Comments (34)


  Bill307, Aug 25 2008

Posted on Slashdot, the following videos show you how to visualize a few different aspects of mathematics:
- stereographic projections and 4-dimensional space
- complex numbers and their relation to fractals
- fibrations in topology
- a couple of geometric proofs

They're aimed at the level of someone who has finished secondary school math. IMO the chapters on complex numbers are the easiest to understand, followed by the chapter with geometric proofs, then the chapters on 4-dimensions, and finally the chapters on fibrations which I found to be the most difficult to understand.

http://www.dimensions-math.org/Dim_regarder_E_E.htm

Below is a brief description of the contents of each chapter.

Chapter 1:
- Introduces stereographic projection using the Earth.

Chapter 2:
- Talks about how a being in a 2-dimensional world might be able to conceptualize objects in 3 dimensions.
- First technique: "slide" the 3-dimensional object through the 2-dimensional world, showing a sequence of cross-sections.
- Better technique: first "inflate" the solid into the shape of a sphere, then use a stereographic projection as shown in Chapter 1.

Chapter 3:
- Introduces five of the six regular 4-dimensional objects and displays and rotates them without using stereographic projection.

Chapter 4:
- Shows the stereographic projections of these five 4-dimensional objects.

Chapter 5:
- A geometric introduction to complex numbers.
- Shows how complex numbers correspond to points in the complex plane.
- Shows how multiplication by i is a 90-degree rotation in the complex plane.
- Defines the modulus and the argument of a complex number.

Chapter 6:
- Shows the geometric effect of transforming complex numbers by adding them, multiplying them, etc.
- Shows the geometric effect of squaring complex numbers repeatedly, leading into the Julia set.
- Explains Julia sets and the related Mandelbrot set (both are fractals).

Chapter 7:
- Visualizes S3 (the unit 4-dimensional hypersphere) geometrically using two complex axes and a circle.
- Visualizes S3 as a set of non-intersecting circles where each circle corresponds to a point on S2 (the unit sphere) projected stereographically, also known as a fibration of S3.
- I've never really taken any topology courses in university, so I had to rewatch parts of this video several times to let it sink in.

Chapter 8:
- Introduction to Villarceau circles on a torus.
- Shows geometrically how each point on the torus has four circles on the surface of the torus that pass through it.
- Shows a stereographic projection of a torus inside a sphere.

Chapter 9:
- Gives a geometric proof that when a non-tangent plane intersects a sphere, the resulting intersection is a circle.
- Gives a geometric proof that the stereographic projection of a circle on a sphere (that does not pass through the "north pole") results in a circle.
- The proofs rely on geometry that one should learn in secondary school.
- IMO these are especially helpful for someone who has an interest in post-secondary math but who has had no exposure to mathematical proofs.

The last video is a "coming in Dimensions II" video.



*****

Comments (10)


  Bill307, Aug 02 2008

http://www.ted.com/index.php/talks/list/page/1

I recently discovered this website, ted.com . It has a collection of talks from prominent academics and professionals. They have the potential to be very informative, insightful, and inspiring.

Below I'll briefly review the videos that I've seen so far, so that others can decide whether they are worth watching. I'll use the following rating system:
3 - Not worth watching. You'd might as well read TLnet forums.
4 - Good, if not necessarily worth watching. (Still much better than TLnet forums, though!)
5 - Definitely worth watching.
6 - Highly recommended.

Chances are, anyone reading this list will enjoy watching anything rated 4 or above. Don't get me wrong: I enjoyed watching ALL of these videos. The rating system is there to separate the good ones from the outstanding ones.

In order of increasing rating, here are the videos I have seen so far:


Talks - Carolyn Porco: Fly me to the moons of Saturn
4.25 / 6
http://www.ted.com/index.php/talks/carolyn_porco_flies_us_to_saturn.html

If you're interested in space exploration, then you'll probably enjoy this video. She briefly talks about two of Saturn's moons: Titan and Enceladus. She shows some pictures of them and tells us some facts about them. The information is a little bit outdated, unfortunately, e.g. liquid has now been confirmed on Titan. Also, it's not super-informative: you could learn a lot more from those moons' Wikipedia pages.


Talks - Chris Jordan: Picturing excess
4.5 / 6
http://www.ted.com/index.php/talks/chris_jordan_pictures_some_shocking_stats.html

The first half is a series of scary statistics about the US, with pictures that are intended to help us visualize and understand the enormous numbers we are talking about. The second half is more about effecting change in our (well, in the American) culture. Overall, some of the stats are pretty interesting. It's not particularly great but I still think you'll enjoy it.


Talks - Helen Fisher: The brain in love
4.5 / 6
http://www.ted.com/index.php/talks/helen_fisher_studies_the_brain_in_love.html

Starts off slow with a bunch of quotes from poems and such. Then talks briefly about brain activity in people who have recently broken up. Talks about how romantic love is similar to an addiction. Next, some stuff I don't remember. Finally, she concludes with an interesting fact: women gain intimacy from looking at each other and talking together, whereas men gain intimacy from doing things side-by-side. I think this last fact was the most intriguing thing I took away from the video... but since you've heard it now, I'm not sure if the rest of the video is worth your time to watch. Up to you.


Talks - Mark Bittman: What's wrong with what we eat
4.75 / 6
http://www.ted.com/index.php/talks/mark_bittman_on_what_s_wrong_with_what_we_eat.html

At first you might think this is going to be about becoming a vegetarian, or trying to reduce global warming. But actually, its primary focus is looking at how unhealthy the average American diet has become. There's a part where he talks about what the American diet used to be like in the 1900s, and how it has degraded to the state it's in today. He talks about the causes of the current state of poor eating, such as the influence of big businesses and the convenience of not having to cook. He mentions how "organic" foods like "organic salmon" can fail to be any better. Lastly, he talks about how we should change our diets to eat healthier. Overall, I'd say it's worth watching if you're not already very concerned with how you eat.


Talks - A.J. Jacobs: My year of living biblically
5.25 / 6
http://www.ted.com/index.php/talks/a_j_jacobs_year_of_living_biblically.html

He starts by talking about some of his earlier projects. Then he talks about his recent project where he tried to spend one year living by the rules and laws of the Bible, interpreted literally. Example: the Bible says "be fruitful and multiply" and he actually had twins during this time period! The most educational part is the last half, where he talks about 5 or 6 things that he learned during this experiment. I think they are important for Catholics and Christians to hear, but also equally important for atheists and agnostics to hear as well. It's far from a Bible-bashing video: he talks about both the benefits and the drawbacks of living in this manner. Overall, a very educational and insightful video.


Talks - Sir Ken Robinson: Do schools kill creativity?
5.75 / 6
http://www.ted.com/index.php/talks/ken_robinson_says_schools_kill_creativity.html

The only downside to this video is that this guy goes off on a lot of anecdotal tangents and, though they're amusing, they can sometimes be distracting. Other than that, it's full of information and insight. Among other things, he talks about how education systems around the world place most emphasis on math and language, and least emphasis on the arts, especially drama and dance. He points out how children are initially not afraid of making mistakes, but over time we teach them to be afraid of making mistakes. This reminded me of the current state of the games industry, where very few companies are willing to take risks, and as a result our games become much less creative. There was so much content in this video that I cannot summarize it all. I definitely recommend it.




****

Comments (14)




Calendar
Mo Tu We Th Fr Sa Su
      1
2345678
9101112131415
16171819202122
23242526272829
30      

ON AIR:
→ [TSL] Ladder Start

Live user streams:
KawaiiRice
skryoo1004
[ Show 1 non-featured ]

Upcoming events:  [ More ]
Nov 22  [PL] STX vs KHAN
Nov 22  [PL] hite vs MBC
Nov 23  [KDL] Week 1 Day 1
Team Liquid Progaming Database

League Standings:
» Shinhan 09-10 Proleague
» EVER 2009 OSL
PokerStrategy.com TSL Forum
TSL Ladder Standings
TSL Player Eligibility a…
TSL Ladder predictions
Official Raffle Entries
The Ladderland, by TS eL…
Final Edits: Progaming Editorials
On The Shoulders of Giant…
Here To Stay
A Finale in Five
Masters of the Universe
Map of the Swarm
Power Rank: Progamer Rankings
1. Flash 6. Fantasy
2. Jaedong 7. Effort
3. Inter.Calm 8. Shine[Kal]
4. Stork[gm] 9. HyuK
5. Bisu 10. Kal
   Comments (304)
Poll
TSL Ladder #1?

Comments (131)      Older Polls


International Cyber Cup

Liquid Poker
Sitemap Contact Poker Forum

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2002-2009 Teamliquid.net. All Rights Reserved