Jump to content
IGNORED

Clever code?


cdoty

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.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

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? 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...
On 9/13/2020 at 6:52 PM, JamesD said:

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? 

Very cool! :) Erlang's algorithm may have been similarly inspired by what other engineers thought was random behavior at the switch -   

 

Erlang was a Danish mathematician who came up with a complex algorithm to optimize throughput in Telephone switches.

 

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...