Monday, April 26, 2010

Shoulder separation - Not recommended

I was playing ice hockey the other night and all was well. There were two minutes remaining in the game. We were winning 6 - 2. Then it happened.

I was heading into the boards to poke a puck around. It was just me and one of the fellows from the other team. Neither of us was going all that fast considering a deficit of 6 - 2 is not easily changed in 2 minutes. Sadly, our feet got tangled and I went shoulder-first in to the wall.

Now I've been checked full force before and everything was dandy, but a little harmless fall at like 5mph and CRUNCH. Yes, I heard an audible crunching sound. Oddly, it didn't hurt at all...for like three whole seconds. For those three seconds I was having thoughts like, "Well, a crunching sound can't be good" and "Maybe it's like when the chiropractor adjusts your spine?". Turns out that the first thought was the correct one. When the three seconds of interested-third-party thoughts concluded, the in-the-moment me returned to find a searingly horrific pain like few others I've felt over the years.

I sat on the bench for the remainder of the game carefully holding my arm in place. It was less than fun. After getting back to the locker room my teammates helped me get everything together, and one of them did a makeshift sling (impressive, actually), and then I called my wife since I was in no condition to drive.

We got to the Emergency Room and waited a while (something I'm sure will get better now that we have universal healthcare coming...) before they did x-rays and such. At first they couldn't find anything wrong. Then they tried a different angle. I believe I heard an "oh...hmmmm...that's not good." I asked what was up and was told the doctor would see me.

The doctor showed up sometime later. She told me I had a fractured clavicle and likely a torn AC joint. I asked what this meant for my hockey playing days. "You'll be out 6-8 months," she said. "Blehgang?!?" I replied, or something akin to that.

The following day I was able to get to a specialist (again, we're still not at that full-on universal healthcare stage here so getting an appointment is still possible). He went over my x-rays, did a few tests on my shoulder and said that the people at the ER jumped the gun a bit. He said that there is no fracture and that both my joints are intact. "You have a grade-one separation," he said. "Am I out 6-8 months, doc?" I asked, hopeful as ever. "No, probably 2-3 weeks."

At first I was elated, then I thought "2-3 weeks???" and said, "Blehgang?!?" again. It just seemed fitting. He explained that I needed to use the arm and that it's basically going to hurt like hell. He's right about that. It does. Fortunately, I have little happy pills to help with the pain. Unfortunately, I don't like taking meds so I'm avoiding them as much as possible.

So now I'm doing stretches and such in order to work myself back to being able to play again in the next 3 weeks.

I'm just glad I'm able to type fully again.

Monday, April 19, 2010

End of the line redone

I redid all of "End of the Line" over the weekend using the GS-10. It just sounds 100x better this way than using the VG-99. Everything is crisp and has no digital feel to it. Sustain is also a lot better. I don't know why that is, but it is!

This was liberating since I was able to pull back from using 10's on the high E. Why does that matter? Because 10's rip my fingers up. I used them because of the GK-3 pickup. Now that I have removed the GK-3 pickup from my main ax and put it instead on my secondary, my main ax is back to using 9's. They feel like butter.

I was so stoked about the new sound that I also went back and sang the song over again too. There was more punch to the vocals this time around, so that will help.

Now the song is off to Ron for adding in drums and percussion, and then for mixing.

...off to re-recording "Wielder of the Blade" this week.

AS3 memory management part II

I went through and did the plan from my previous AS3 memory management post and things are looking better. By just allocating things one time at the beginning of the game and pushing them to the display list once as well, I'm now at about 1/2 the amount of memory hogged by the time I reach level 20 of the game.

This should be sufficient to solve the problem of game slowdowns.

At this point I could pull all of the frames and such from the game, but I don't think I'm going to do that. If a person runs back and forth in the menu and such 100x, it'll likely bump up the memory usage a bit but not nearly as badly as the game frame is and it's frankly an edge-case anyway.

The bottom line is that if you're coding up a game or application that has a number of levels to it, and is full of tons of graphical elements and such, you'll probably want to:
  • Do all of your allocation at the start of your game
  • Use addChild(...) as you allocate and then just write a little function that "hides" your graphics by altering their x and y to be something like: -999,-999
  • Show your graphics by setting the new x and y to wherever they should actually be
  • Make sure you don't undercut the number of graphics you'll need when doing your initial allocation
Now before anyone gets all fired up about the use of globals here. You don't have to use globals. You can create a class that handles all this stuff and encapsulates things neatly. It'll add a little overhead doing this, but for purists it should work fine. For everyone else, globals are not as neat and tidy, no, but they do give that feeling of old-skool hack development. :)

Tuesday, April 13, 2010

AS3 memory management

...is a pain in the butt.

I've known for years that the AS3 GC (Garbage Collector) runs through and cleans junk up when it is ready to, but this is somewhat crazy.

Let's say you have a Sprite all set up called "Ship", and you blow it up on the screen and then want to remove the ship.
// remove the child from the display list...I'm using GameElements here
// could just as easily be the root

GameElements.removeChild(ship);


// and set the actual ship var to null

ship = null;
Now, the ship should be deleted and done, right? Wouldn't that be super? Turns out that you can no longer reference the ship, but Flash still has it sitting around in memory until it decides the time is right to remove it. This could take seconds or hours (or it may never remove it).

The problem gets worse if you use the Flash frames, apparently. (I'm kind of guessing on this one). If you use Flash frames, everything you have populated onto the frame is going to be allocated. So any images, text-fields, etc. Now, when you're done with that frame and move onto the next--assuming you have set everything on the previous frame to null--it should all disappear. Visually, it does, but just like the aforementioned "ship", all the elements are still in memory until the Flash GC nukes them.

So, now, imagine this:

Frame 1: Splash screen
Frame 2: Game Screen

Frame 3: Level Complete screen

Frame 4: Game Over Screen


The game starts and we show Frame 1 for a couple of seconds and then jump over to Frame 2. Frame 2 starts up your game with all its nifty little sprites and such. You play through the level and win (yay!). Now the game moves on to Frame 3 to show you how you did, and asks you if you're ready for the next level. Stop...

1 - Show Frame 1 (Splash)

2 - Show Frame 2 (Game)


3 - Remove elements from Frame 2


4 - Show Frame 3 (Level Complete)


5 - Remove elements from Frame 3


6 - Go back to item #2 in this list


See a problem here? All of the elements in Frame 2 are still sitting in memory (unless Flash's GC cleaned them up...highly unlikely), and then Frame 3's are as well. We could be 20 levels into a game and ALL of the prior data is still sitting in memory. UGH!

And this doesn't even touch the fact that if you have any event listeners tied to these items they'll keep firing until the GC deletes them. Even if you remove the even listener, the reference will stay there unless you set the useWeakReference to true.

When creating an event listener, instead of:
SayAgainButton.addEventListener(MouseEvent.CLICK,SayAgain);
Use:
SayAgainButton.addEventListener(MouseEvent.CLICK,SayAgain, false, 0, true);
Again, it'll still hang out until the GC picks it up, but at least it *will* pick it up eventually.

Until then, guess what happens? Yep, all the stuff you created from levels 1-19 will still be in memory firing until the GC snags it. Why? I honestly don't know. It seems rather silly to me.

Oh, one more thing to note: Even if you create a symbol that has a bunch of frames sitting inside of it, and you're using gotoAndStop(...) or next() to pulse through, etc., you'll see your memory go up. This is because it's not until you actual hit a particular frame that the frame is loaded. This is actually understandable and fine, but it is something to note as you're doing stuff so you don't pull you hair out.

So what is there to do?

Well, that's the $1M question. What I'm going to *try*, is the following:

1 - Remove the whole frame concept entirely.

2 - Create all my assets at the start of the project


3 - Instead of removing them from the child list and nulling them, I'm going to create a little (throw me off the screen) function that effectively does the same thing, but only retains ONE element in memory through the life of the game, no hundreds. I'll just stick the items at -999,-999 or something.


4 - I already reuse the majority of my elements in arrays, but it seems the child list is a part of the problem (at least from my testing). So I want to have a fixed set of addChild calls instead of numerous ones. Again, this is accomplished by creating the elements at the start of the game and reusing them throughout.


Will this solve the problem? That's the question I hope to answer tomorrow.

Tuesday, April 6, 2010

Coding

I had a little fun working up a Flash system that snagged and XML file and an .MP3 file, mushed about inside of them and churns out a little soundtrack with text running along at the same time.

Unfortunately, I have no way of getting the XML to be smart enough to load up everything on the .MP3's timing. This just means that I have to use a tool (I use Audacity) to find the start points of each each text portion and tell the XML file where those are.

The tricky bit is that Flash doesn't have a way to reset its start timer. Not a huge deal, but doing the pause and resume stuff gets a little wacky while trying to keep tabs on the location on the .MP3 and the story itself.

The trick is to make sure to have a timer offset that you set when the story actually starts. And you set your start time to zero. Now you can compare safely, like:


timeElapsed = (timeElapsed + (getTimer() - timeOffset)) / 1000;
if (timeElapsed > storyTime)
{
....
}


When you pause, make sure to set a time paused variable using the getTimer(), and also pause the .MP3 and get its current position.


soundPausePoint = storySoundChannel.position;
storySoundChannel.stop();
timePaused = getTimer();


Then when you're ready to resume, you'll have all the junk you need to set your timers and your .MP3 start point accordingly.


storySoundChannel = storySound.play(soundPausePoint);
timeOffset = getTimer() + (timeOffset - timePaused);


Nifty, no?

Friday, April 2, 2010

Re-recording with GS-10

Well, I re-recorded all the distorted guitars on Aeserian using the GS-10 instead of the VG-99. It sounds loads better in my opinion, so I'm glad I figured that out now instead of during the mixing phase. The sad news is that now I have to go through and re-record all the guitar bits for all the songs I've already done. Hopefully this won't take all that long. I have to redo the following tunes:

1. End of the Line
2. Mirnrith
3. Wall
4. Sings to You (Whisper)
5. The Wielder of the Blade
6. Sai

I still have to record the rest of the songs, so I'm glad I caught this now. At least I don't have to redo all of them!

It wouldn't be so bad if it was just the rhythm parts, but I'm not to just use a single guitar in my stuff. I think Wielder alone has like 15 different guitar bits throughout. On the plus side, I've been playing these songs for years so I know them like the back of my hand. With any luck, it'll go pretty quickly. We shall see!

Kreth'x

What's a Kreth'x, you ask? Why it is a sword, of course! It's a sentient sword at that. It is the sword used by the main character in "The Wielder of the Blade" book based in the land of Phylean. The main character's name, if you're wondering, is Rais'Alon.

Kreth'x is also the name of the "band" (consisting of myself and Ron Burgoyne, so it's more of a duo than a band, but "duo" just doesn't have that awe-inspiring umph that "band" does) that is creating the heavy metal album "The Wielder of the Blade", which, if you're still following along, is a concept album based upon the book.

The domain for Kreth'x is already reserved, but I've not done anything with it yet because I'm still awaiting some images. Hopefully we'll have something to show in the next few weeks on the actual site. I will, however, try to post a few images and such here as they become available.

Roland VG-99 vs. Boss GS-10

I have both the Roland VG-99 and the Boss GS-10 and both are pretty nifty, but I'm finding that I really need both to feel comfy recording.

The VG-99 is a crazy unit that has all sorts of bells and whistles, especially if you use the GK-3 pickup (which I do). With this system, I'm able to play all sorts of sounds and even control midi-devices and record into Sonar the midi notes I'm playing on the guitar. This works because the GK-3 pickup has per-string pickups instead of the standard guitar one pickup model. I can essentially make my standard 6-string electric sound like anything: a flute, a 12-string guitar, a mandolin, violins, drums, a bass, etc.

The latency is a bit problematic when trying to control midi-devices, but it's not awful for recording the midi notes. The trick here is to have the midi notes recording while you're listening to a normal sound from the VG-99. Then you can manually tweak the midi notes and assign them to the instrument of choice. So you record using a standard guitar sound, but when you have Sonar (or you recording system of choice) play back the midi, it can sound like anything your midi-device supports. This is great if you're not a keyboardist but still want those keyboard sounds. Plus, using this method you can alter the notes by hand for when your timing or note placement is off a bit.

So what's the problem with the VG-99? Sadly, there are a few.

1. The pickup installation messes with your guitar's action. This is particularly bad if you're using heavier gauge strings. There is the slightest (barely noticeable) delay from when the string is plucked to when the sound emerges. It's so slight that the only person that will notice is the person playing 100mph. Slower players may not notice it at all.

2. When you play fast stuff, it starts to sound a bit digital. It's as if there are little wav files there just playing over themselves. It gets choppy.

3. Anytime I hit the D note (or chord), the guitar loses the proper stereo sound and hits full center. It only happens on D when the guitar is distorted.

4. The distortions sound iffy. There's just no really kerboom to them, if you know what I mean.

And this is why I hang onto the Boss GS-10. The Boss distortions are awesome. I get all the aforementioned kerboom out of the GS-10 for distortion and speed junk, and since it has the built-in speakers I can also move it around with me wherever I roam.

So for midi and clean sounds, the VG-99 is a pretty nifty unit. For distortion, I prefer the GS-10 greatly.

You'll get to hear them both on the upcoming "The Wielder of the Blade" album.

Sonar 8.5

In preparation for getting back on track with "The Wielder of the Blade" album, I upgraded from Sonar 7 to 8.5. So far I rather like it.

They changed the default menus and layout a little bit in the new version. It works better for me now that I'm getting used to it.

One of the nicer things is that the audio engine is more responsive. It's smoother. I haven't had any audio dropouts since the upgrade and I was getting them at least once per recording session before. I'm in the process of saving up for a new machine, which will make this puppy really purr (or, is that kitty?). For now, though, it's performing quite well on my elderly clunker.

The new vocal strip is going to be quite helpful in making my singing sound good...erm, less bad. It has a lot of nifty little features and presets. I can see that there will be a bit of a learning curve on it, but it promises to be worthwhile.

I plan on getting after more of the recording facets this weekend, so I'm certain problems will turn up. But my initial reaction is that Sonar 8.5 has potential.

BlitzCoder / Blitz Basic

Old BlitzCoder Tutorials are up - I've recently received a bunch of requests for my old Blitz Basic tutorials (from the BlitzCoder era). Fortunately, Charles 'Specis' McCrimmon retains a copy of everything known to man. So he packaged it all up and sent them over. I got everything working today so anyone who's interested can check out the old tutorials and grab the old source code.

NOTE: I'm not supporting this stuff anymore, but if you're interested: BlitzCoder Tutorials

Thursday, April 1, 2010

The Big Move

I decided to move Krylar's Kreations over to the blogging format because I was tired of looking at the static page of my website. My hope is that this way I'll be able to write stuff more often in order to keep the content fresh.

For now, though, I've still got some integration work to do. So...more later!