Skip to main content
gamedev.net
🔒 Locked

bizarre code rot

Started by balla_the_king Jan 13, 2005 at 10:02 PM 2 replies 1.1k views
Original Post
balla_the_king
balla_the_king
I just started to write a new GUI interface in C++ using Allegro - but Allegro lacks a tiled-blit but it just so happened that I a few years ago wrote a GUI using allegro in straight C so I decided to steal my tiledblit function from that project. The function had been used extensively in different controls so I assumed it would be trouble free to use it, but when I changed my stretchblit calls to tiledblit the screen looks strange. It somehow decides to fill the whole screen to the right and below the control. So when I look at the source I find this: blit(source, dest, source_x, source_y, dx, dy, dest_width, dest_height); ... blit(source, dest, source_x, source_y, dx, dy, extrah, dest_height); ... blit(source, dest, source_x, source_y, dx, dy, dest_width, extrav); this might not look so bad if you don't see the whole source but my code is using the wrong variables. I should have been using source_width and source_height so instead of blitting a 10x10 area each time it now blitted a 600x600 pixel area. Before my change this code worked nothing like a tiled blit - more like a screenfiller. And I used this function without any problems in my old GUI. I just can't understand how it worked in the old project, it is absolutely totally unbelievable. Anyone else experienced someting similar with rotten code?
balla_the_king
balla_the_king
I just realized why it worked dest_width got clipped to source_width because the source bitmap and the same width as source width. Now tell me of your worst rotten code!
Binomine
Binomine
Oh the memories.

I had a qbasic poker game that allowed you to purchase cheats as one of the features. Except instead of having a single variable for keeping track of the cards, I had three global variables.

One for suit
One for number
and one for number relative to deck, so 1 would be the ace of hearts and 14 would be the ace of diamonds.

Then for every function, I used a different way of calculationg what cards the player had. Sometimes I would derive the card from the whole number, sometimes I'd use the number and suit and something I'd calculate the card and check to make sure my calculations were correct.

The damn thing worked. I'm not sure how, but the game played, had a generic AI and allowed players AND the AI to cheat.(reveal 1 or 2 cards for a cost of monies) However, I had a wicked bug with the AI cheating. It would always assume the worse and fold. The worse was always the worse with one card, since one card could would at least be a straight flush. I didn't realize the problem and gave up on it.

I picked up the code 6 months later and I couldn't make heads or tails of it. It was a few thousand lines of horrible goto programming.
falkone
falkone
I was up late one night furiously coding a 3D renderer in QBasic (years.. years ago). Coffee and pizza powering my effort, I eventually took a break and fell asleep. When i woke up the next morning, I took a look at what I had written. I couldn't understand what I was doing. The worst part was that the program ran as it should.. but my code was so obscure that I couldn't work with it. So I rewrote it.

Not quite code rot.. but related.
Disclaimer: "I am in no way qualified to present advice n any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)" o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.