Tuesday, April 3, 2012

Late Night Lovin'

Okay, I'll be the first to admit that's a terrible name for a blog post.

Regardless, let's take a look at what I've done in the past week or so:

Watched all of the Game Of Thrones.

Watched Girl With The Dragon Tattoo.

Hung out with friends a lot.

Celebrated Ricky's birthday.

Uh, wait... I programmed in there somewhere, right?

Yes, a little bit.  I fixed a massive processor-sink known as the "pit of constant memory allocation"
Our game has these really awesome scores that pop up when you hit guys and deal damage, and I worked my butt off creating a really dynamic (if a little costly) means of adding in our own sprite fonts, since I find XNA's defaults to be... messy.  Limiting. Primitive. Primordial. Neanderthal.  Really not cool.

The default sprite-fonts in XNA are not nearly as bad as I've made them out to be, but there were a number of limitations that caused me to balk at using them.  
-They required the computer to have the fonts pre-installed or packaged with the game (not that bad.)  
-They require you to use and allocate and entirely different font if you wanted to change the font size! (Kinda but bad, again, a good programmer can create systems to allow them to easily make up for these, creating an array of sprite fonts at different font sizes to allow for rapid font-switching)  
-Creating your own font meant learning how to create fonts according to standards (The equivalent of asking for directions, which guys never do. ...Right? Wait, why don't we do that?)
-To my knowledge, you couldn't do cool things like rotation and flexible scaling.

Looking back, it would have been far, far easier to just implement a system that simply didn't try and deal with dynamic rotation and scaling.  But I will not be dissuaded from my goal.  I crafted a system that lets a person use an image to specify a new font (adding it in is rather tedious, though) and after it's been added any string can be created and scaled, rotated, color changed, it can check for collisions and evra'thang!  The way it does this isn't necessarily great, it creates a new texture2d for every unique string generated, but stores all previously generated strings in a lovely hash-table for quick look up and grabbing the next time the same string  wishes to be generated.  This resets every time the game runs, so in theory a dedicated programmer could pre-populate his list of textures with his desired strings and lookup would run just that much faster!  Hooray!

Anyway, the long point of my story was that I was generating a bunch of new calls to create these little effects that called my sprite font, created themselves and then deleted themselves within a hot second (literally) and then sat around, presumably on some duvet somewhere in the lobby of lost memory allocations, smoking a cigar illegally or drinking heavily, waiting for the Garbage collector to come along, and when he did, boy would he have a lot of work to do.  Which causes the game to lag hardcore for a few miliseconds, and then return to normal.

Can't have that, that's just bad practice.  If games like Borderlands can run at 60fps (or near to it) on my computer then there is absolutely no excuse for my 2D game to lag.

Aside from that, I've just done some work on the score system, creating examples for Brian and making sure that it's at least visualized partially for upcoming playtests.

W00t w00t.

-Kev.

Oh yeah, you came for pictures, didn't you?



Cousin Collaboration

Guaranteed to solve most problems. 

No comments:

Post a Comment