Jump to content
Sign in to follow this  

Clever code?

Recommended Posts

Has their been any clever code you've amazed yourself with lately?


For me, it's a joystick handling routine.


Handling joystick input, in any assembly language, is always messy.


I got the idea to wrap the joystick handling into a macro that accepts "callback" routines for each of the movements, buttons, and an idle "callback". This is closer to the model used in many higher level languages.


This separates the joystick handling logic from the bit processing to identify the inputs, and it allows the code to be used in different sections of the game, I just have to write routines to handle the specific inputs.


I also customize the macro based on the inputs expected. My current one only looks for left, right, and fire. But, in a high score screen, I might need all four directions.


A potential downside would be the handling of diagonal movements near an edge. The macro could be expanded to check for diagonal movements first, and call the appropriate callback.

Share this post

Link to post
Share on other sites

Lately?  Not really, it's usually just hard work, and experience.
One time does really stand out.
When I was in my 20s, there was a piece of code I wrote for a project that nobody on the team had the slightest idea how to do.
We had to get some software (network switch simulators) to work together that was exhibiting what everyone thought was random behavior.
After putting off this piece of code as long as I could (2 a.m. a few nights before it was due), I wrote some code based on a complex mathematical relationship that worked.

When I showed it to the team they were like... how... the... hell... did you get that from this random data?
There's no way I can describe it other than I just saw it.  Divine inspiration maybe? 

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...