Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Nypyren

Member Since 19 Aug 2002
Offline Last Active Yesterday, 09:40 PM

Posts I've Made

In Topic: Direction Booleans into single Integer

24 April 2015 - 08:56 PM

Well, since we are in the coding horrors forum...


Well, we sure are NOW anyway smile.png

In Topic: Direction Booleans into single Integer

24 April 2015 - 06:00 PM

In that case, you can do the bitfield as a temporary, then use that in a lookup table (this is C-like pseudocode so it won't necessarily actually compile):
 
int lookups[] = { 0, 1, 5, 0, 7, 8, 6, 7, 3, 2, 4, 3, 0, 1, 5, 0 };

int index = (up ? 1 : 0) + (down ? 2 : 0) + (left ? 4 : 0) + (right ? 8 : 0);

ReportByte[0] = lookups[index];
Should be damn efficient, and the code is compact.


(edit) My lookup table had zeroes for all of the 3-bit combinations instead of only cancelling out the opposing directions. Fixed.

In Topic: Direction Booleans into single Integer

24 April 2015 - 05:11 PM

Use a bit field. Also, why is this in Coding Horrors?

Following code is C# but the bitfield concept holds elsewhere:
 
[Flags]
public enum Direction
{
  None  = 0,
  Up    = 1,
  Down  = 2,
  Left  = 4,
  Right = 8,

  UpLeft = Up | Left,
  UpRight = Up | Right,
  DownLeft = Down | Left,
  DownRight = Down | Right,
}
Use | and & to perform bitwise manipulation.



This breaks your existing values, but will be much easier to deal with in the long run.

If the 0-8 range cannot be changed, then just go with your current code; it's not that bad.

In Topic: How to deal with fire and forget questions?

23 April 2015 - 06:50 PM

Even if the original poster never returns, answers may be helpful to others who have similar questions.

But yes, sometimes the original post is utterly senseless. They often get torn to shreds pretty quickly (the culture here is to answer nonsense with nonsense, which works fine).

In Topic: How Many of You Have A Successful Game? $5000+

22 April 2015 - 06:52 PM

A lot of us here work at large companies which have games that generate mind boggling amounts of money. Mind boggling. I am not exaggerating. I looked at the MRI and could SEE the boggles.

PARTNERS