Coding on vicodin...
by Jon Frisby · 01/25/2006 (10:43 am) · 7 comments
In the course of my project I have come to depend on a number of patches to T2D which may or may not survive into future versions of the engine. Notably, the OO TorqueScript patch. This is a wonderful patch -- it almost makes TorqueScript a usable language in and of itself, but I've come to realize that relying on it is problemmatic for me. If I encounter a problem, how do I know whether the crash is in T2D, or the patch? If I attempt to get support from GG or forum members, how do I prove that the problem is not in the patch? Being told to remove the patch and see if things work without it isn't practical as it would involve radically rewriting most of my script code (which is the majority of my game).
So what do I do? Rely on a large, complex patch that I don't understand, which modifies an engine I don't understand, and may or may not work with T2D 1.1 once the TGE 1.4 merge is complete? Rewrite my script code to not be OO (a non-trivial undertaking given the nature of my game)?
The other alternative is to systematically start rewriting my script classes in C++. This would force me to develop a better understanding of the engine, and would limit engine changes to smaller changes that I understand better than relying on a large, sweeping, deep patch. And so, that is what I have begun doing.
I had a script class called StaticBlock, which inherited from fxSceneObject2D and essentially acted as a wrapped for an fxTileMap2D/fxTileLayer2D providing game-specific operations for positioning, rotating, and so forth.
I started by making a C++ class of the same name that did virtually nothing. I changed my script class to be called ScriptBlock and made it inherit from StaticBlock. I then systematically started moving functionality up into the StaticBlock class until I no longer needed the OO patch to make it work. Cross-language refactoring however is not an easy thing, especially since I haven't used C++ since before there was an ISO spec (and even then I only dabbled in it). I kept getting the most bizarre crashes at random times in seemingly unrelated code.
Enter the vicodin. You see, I am presently recovering from minor surgery and have been given a prescription for vicoden to alleviate the pain. Last night, shortly after taking a dose, I decided to go over the code a bit more and see what I could find. I was already quite convinced that the error was caused by how I was managing the lifetime of the fxTileMap2D / fxTileLayer2D objects my StaticBlock needed, but the question was how do I dispose of these things gracefully and without (apparently) corrupting the internal state of the game engine? I was quite light-headed, and my thought-process was clearly not the same as usual. This time around, it occured to me to ask "how does fxTileMap2D manage the lifetime of fxTileLayer2D instances?" Aha! Looking at the implementation of
Voila! crashes gone! Vicodin saved my code by softening up my thought processes and giving me back some of the flexibility I had way back when I was learning to program in the first place.
So now I move on to migrating other classes one-by-one. The timing is good because my latest dose has just kicked in.
So what do I do? Rely on a large, complex patch that I don't understand, which modifies an engine I don't understand, and may or may not work with T2D 1.1 once the TGE 1.4 merge is complete? Rewrite my script code to not be OO (a non-trivial undertaking given the nature of my game)?
The other alternative is to systematically start rewriting my script classes in C++. This would force me to develop a better understanding of the engine, and would limit engine changes to smaller changes that I understand better than relying on a large, sweeping, deep patch. And so, that is what I have begun doing.
I had a script class called StaticBlock, which inherited from fxSceneObject2D and essentially acted as a wrapped for an fxTileMap2D/fxTileLayer2D providing game-specific operations for positioning, rotating, and so forth.
I started by making a C++ class of the same name that did virtually nothing. I changed my script class to be called ScriptBlock and made it inherit from StaticBlock. I then systematically started moving functionality up into the StaticBlock class until I no longer needed the OO patch to make it work. Cross-language refactoring however is not an easy thing, especially since I haven't used C++ since before there was an ISO spec (and even then I only dabbled in it). I kept getting the most bizarre crashes at random times in seemingly unrelated code.
Enter the vicodin. You see, I am presently recovering from minor surgery and have been given a prescription for vicoden to alleviate the pain. Last night, shortly after taking a dose, I decided to go over the code a bit more and see what I could find. I was already quite convinced that the error was caused by how I was managing the lifetime of the fxTileMap2D / fxTileLayer2D objects my StaticBlock needed, but the question was how do I dispose of these things gracefully and without (apparently) corrupting the internal state of the game engine? I was quite light-headed, and my thought-process was clearly not the same as usual. This time around, it occured to me to ask "how does fxTileMap2D manage the lifetime of fxTileLayer2D instances?" Aha! Looking at the implementation of
deleteAllTileLayers(), I found my mistake! In my onRemove method, I was doing this:
delete mBoard;But what I really needed to be doing was this:
mBoard->deleteObject();
Voila! crashes gone! Vicodin saved my code by softening up my thought processes and giving me back some of the flexibility I had way back when I was learning to program in the first place.
So now I move on to migrating other classes one-by-one. The timing is good because my latest dose has just kicked in.
#2
Welcome to club MED!! I have been on vicodin sense 12/28, make coding a joy at times. Just last night I was working on the TGE 1.4 make files for linux, wrote a nifty little bash script to detect and add links, worked fine until I tried it again this morning *snicker* Glad I have a 24 hour wait before commiting to CVS policy running *snicker*
-Ron
01/25/2006 (12:18 pm)
Quote:
Enter the vicodin. You see, I am presently recovering from minor surgery and have been given a prescription for vicoden to alleviate the pain
Welcome to club MED!! I have been on vicodin sense 12/28, make coding a joy at times. Just last night I was working on the TGE 1.4 make files for linux, wrote a nifty little bash script to detect and add links, worked fine until I tried it again this morning *snicker* Glad I have a 24 hour wait before commiting to CVS policy running *snicker*
-Ron
#3
01/25/2006 (1:28 pm)
Coding on drugs...just great. Glad to hear it's working out for you fellas. Can't wait to play your "games". wtf...
#4
It would be nice for GG to add the OO patch into HEAD and support it... but I don't think that will ever happen, unfortunately.
01/25/2006 (4:50 pm)
Well, if you have any problem with the OO patch, you can just contact its author at any time. He's always been available, and has supported his patch for going on years now. Not to mention how stable and well-tested his patch is ;)It would be nice for GG to add the OO patch into HEAD and support it... but I don't think that will ever happen, unfortunately.
#5
It wasn't meant to be a slam against you or anything, and you've indeed been very very helpful, but if you're not on my payroll, I have no guarantees that you'll have the time, energy, or inclination to keep things up to date. With GG I can buy a support contract and nag at them to help me, but using your patch can easily become a scapegoat for hard-to-find problems...
Now I might be interesting in adding you to my payroll at some point -- y'know, once I actually *have* a payroll in place... :p
01/25/2006 (4:59 pm)
Bryan,It wasn't meant to be a slam against you or anything, and you've indeed been very very helpful, but if you're not on my payroll, I have no guarantees that you'll have the time, energy, or inclination to keep things up to date. With GG I can buy a support contract and nag at them to help me, but using your patch can easily become a scapegoat for hard-to-find problems...
Now I might be interesting in adding you to my payroll at some point -- y'know, once I actually *have* a payroll in place... :p
#6
01/25/2006 (5:00 pm)
Ajari: All I can say is when I wrote the code sober, it crashed 100% of the time if you played for ~10-15 minutes. Now, it doesn't crash even after an hour. :D
#7
01/27/2006 (6:40 am)
Payroll - definitely! :D 
Torque Owner Dave D
Hope you surgery went well.