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!


Member Since 09 Dec 1999
Offline Last Active Today, 01:55 AM

Posts I've Made

In Topic: Information about in-game events management

28 May 2015 - 12:11 PM

Event is an overloaded word in games. It could mean special events like when an online game has extra quests for Valentine's Day. It could mean handling a key press or a swipe. It could mean playing a cut scene or a character animation. What kind of events are you asking about?

In Topic: When you realize how dumb a bug is...

21 May 2015 - 09:44 AM

I'm more curious to know why one would type the lowercase L instead of the 1 in the first place, given that at least on a QWERTY keyboard they're practically on opposite sides of the keyboard.

To disguise an exploit deliberately inserted into the code, of course.

I may have spent too much time reading entries at the underhanded C contest.

In Topic: Too clever...?

20 May 2015 - 08:12 PM

std::is_sorted() works pretty much how you imagine. It loops through the sequence and checks if the first element is less than or equal to the second element and the second element is less than or equal to the third element and so on. In principle, if you have a fixed sized array, the compiler can unroll the loop and just do the checks on the individual elements. In practice, many compilers don't that kind of aggressive data flow analysis. Additionally, many standard library implementations don't implement is_sorted() in what you might consider the most straightforward manner, and instead implement in terms of comparing std::is_sorted_until() against last. This requires the addresses of the individual array elements, which compilers have a harder time optimizing out than the raw value comparisons. 
In Python a < b < c has the exact same performance as a < b and b < c during execution, and is very slightly faster during compilation to byte code. With sufficiently aggressive inlining C++ expression templates would have the same run time as the raw operators, but would be massively slower during compilation. Ex: gcc 4.9.2 with -03 generates the same assembly code for comp1() and comp2() in the following code:
struct Lte {
  static bool process(int a, int  b) {
    return a <= b;

template <typename T>
struct Operator {};

Operator<Lte> lte;

template <typename Op, typename Lhs>
struct Holder {
  Lhs lhs;
  int rhs;

  Holder(Lhs l, int r) : lhs(l), rhs(r) {}

  operator bool() {
    return Op::process(lhs, rhs);

template <typename Op, typename Val>
struct Holder<Lte, Holder<Op, Val> > {
  Holder<Op, Val> lhs;
  int rhs;

  Holder(Holder<Op, Val> l, int r) : lhs(l), rhs(r) {}

  operator bool() {
    return lhs.operator bool() && (lhs.rhs <= rhs);

template <typename Op, typename Val>
struct LeftHandProxy {
  Val lhs;

  LeftHandProxy(Val val) : lhs(val) {}

template <typename Op, typename Val>
LeftHandProxy<Op, Val> operator<(Val lhs, Operator<Op> rhs) {
  return LeftHandProxy<Op, Val>(lhs);

template <typename Op, typename Val>
Holder<Op, Val> operator>(LeftHandProxy<Op, Val> lhs, int rhs) {
  return Holder<Op, Val>(lhs.lhs, rhs);

bool comp1(int a, int b, int c, int d) {
  return a <= b && b <= c && c <= d;

bool comp2(int a, int b, int c, int d) {
  return a <lte> b <lte> c <lte> d;
This is slightly more complicated than necessary, but it compiles, produces the desired assembly code and I don't feel like spending more time on it just for a forum post. Adding other operators in addition to <= is left as an exercise for the reader, but should be fairly straightforward.

In Topic: Too clever...?

20 May 2015 - 06:04 PM

This isn't too bad. Overly clever would be putting 0, first, last and length in an array, calling is_sorted() on it, and relying on the compiler to unroll the loop to get the same result. Or abusing operator overloading and expression templates to get 0 <lte> first <lte> last <lte> length to compile so that you can python style chained comparisons.

In Topic: A whole lot of constants.... good or terrible? :/ (c++)

20 May 2015 - 11:22 AM

Note that for the case of IDLE_LEFT and WALK_LEFTDOWN you may not want a single constant that combines both IDLE vs WALK and direction. You might instead want a state enum that contains IDLE, WALK, RUN, etc. and a direction enum that has UP, DOWN, LEFT, RIGHT, etc. You may also want to choose your direction enum values so that things like DOWNLEFT can be expressed by a bitwise or or other arithmetic combination of an UP/DOWN constant and a LEFT/RIGHT constant. Even if you go for a single enum, you may want to be careful picking your values so that they can be decomposed in this manner.