• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
pressgreen

funky looking conditional statement i think

18 posts in this topic

This should be a simple one. I am trying to rewrite this MouseCallback function. It is a Gluts MouseCallback function not that it matters i guess. I ran across a set of statements which im pretty sure are conditoinal statements. but i have never seen this kind of set up for a conditional statement before.

  mouseLClickButton |= (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN);
  mouseRClickButton |= (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN);
  mouseMClickButton |= (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN);

  mouseLClickButton &= !(button == GLUT_LEFT_BUTTON && state == GLUT_UP);
  mouseRClickButton &= !(button == GLUT_RIGHT_BUTTON && state == GLUT_UP);
  mouseMClickButton &= !(button == GLUT_MIDDLE_BUTTON && state == GLUT_UP);

can some one explain what the first set of operators are saying.    |=     and     &=

im assuming that the first three are conditional statements for individual button presses and the second three are for multiple button presses. But i would just like an explanation of what exactly is going on here with the syntax. I have never seen anything like that.

mouseClickButton are all bools. im guessing that if the contitional statement on the right of the operator is tru then it makes that bool on the left tru but its just kind of confusing to me.

Edited by greenzone
0

Share this post


Link to post
Share on other sites

This is interesting.  I did a little digging and found the following. They are apparently called (bitwise OR assignment) and (bitwise AND assignment), 

 

http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B

 

Here are two more pages that I found using the 'english' names

 

http://msdn.microsoft.com/en-us/library/ie/81bads72%28v=vs.94%29.aspx

http://msdn.microsoft.com/en-us/library/vstudio/k6d7hcca%28v=vs.100%29.aspx

 

Hopefully someone around here can explain how they apply to GLUT controls.

 

EDIT:  Oh wait here we go... It looks like your suspicions were correct about this allowing for simultaneous presses.

 

http://www.lighthouse3d.com/opengl/glut/index.php3?5

2

Share this post


Link to post
Share on other sites

That's weird though... since the right part is only a true or false expression, it could be written as

 

BOOL mouseLClickButton = (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN);

 

so im assuming mouseLClickButton are integer, which is ratter poor design choice imo.

Or it might be a bool and wanted to get rid of warning or error messages, being too lazy to cast...

 

Edit: i just saw the &= afterward. Still, this code look weird somehow.

Edited by Vortez
0

Share this post


Link to post
Share on other sites

I think i am understanding. mouseClickButton is in fact a bool and is actually never initialized until these conditional statements.

 

I am following what you say there frob but I am not understanding this a=a&b or a=a|b .

 

Is this (a=a&b) saying a is true if both a AND b are true?

 

and this (a=a|b) is saying a is true if a OR b is true?

Edited by greenzone
0

Share this post


Link to post
Share on other sites

If those variables are never initialized, that sounds like a mistake.

 

In my opinion this is a bit easier to read:

  bool is_down = (state == GLUT_DOWN);
  switch (button) {
  case GLUT_LEFT_BUTTON:
    mouseLClickButton = is_down;
    break;
  case GLUT_RIGHT_BUTTON:
    mouseRClickButton = is_down;  
    break;
  case GLUT_MIDDLE_BUTTON:
    mouseMClickButton = is_down;
  }

Edited by Álvaro
1

Share this post


Link to post
Share on other sites

I think i am understanding. mouseClickButton is in fact a bool and is actually never initialized until these conditional statements.
 
I am following what you say there frob but I am not understanding this a=a&b or a=a|b .
 
Is this (a=a&b) saying a is true if both a AND b are true?
 
and this (a=a|b) is saying a is true if a OR b is true?

Nope.  Bitwise operations operate on bits.
 
For example, a |= b means effectively
 

for i from 0 to number of bits in a:
  if bit i of b is set, set the bit i of a
  otherwise leave the bit i of a unchanged

Similarly for the AND operation.

0

Share this post


Link to post
Share on other sites

Alvaro, your example makes my eyes feel much better. And SiCrane thank you very much for your explanation.

 

Bregma is this diagram similar to your explanation of a|=b?

result = result | expression;
0101    (result)
1100    (expression)
----
1101    (output)
Edited by greenzone
0

Share this post


Link to post
Share on other sites

(To be pedantic, bools don't have a number of bits, but instead undergo integer promotion when placed in the context of bitwise operators, where true is promoted to 1 and false is promoted to 0.)

(except when they don't. like when some asshole vendor has decided to store flags in the other 31 bits of their boolean)

(I will be scarred for the rest of my life)
0

Share this post


Link to post
Share on other sites

 

(To be pedantic, bools don't have a number of bits, but instead undergo integer promotion when placed in the context of bitwise operators, where true is promoted to 1 and false is promoted to 0.)

(except when they don't. like when some asshole vendor has decided to store flags in the other 31 bits of their boolean)

(I will be scarred for the rest of my life)

 

 

That's why I don't like it when people can't just use the integrated bool type. It seems like every lib that comes along these days has to have its own proprietary bool.

0

Share this post


Link to post
Share on other sites

I became a lot more sympathetic to the idea of library defined boolean types when I first ran across a platform with an 8 byte bool. And, no, this wasn't a platform where everything was 64 bits. sizeof(bool) was 8. gcc on Alpha IIRC. 

0

Share this post


Link to post
Share on other sites

That's why I don't like it when people can't just use the integrated bool type. It seems like every lib that comes along these days has to have its own proprietary bool.

That *was* the integrated bool type.

See, C++ doesn't really enforce many rules. And if you happen to know that on your platform, the compiler allocates 4 bytes for a bool, then you can *(int)&booleanValue, and proceed to manipulate the bits...

0

Share this post


Link to post
Share on other sites

That's why I don't like it when people can't just use the integrated bool type. It seems like every lib that comes along these days has to have its own proprietary bool.

That *was* the integrated bool type.

See, C++ doesn't really enforce many rules. And if you happen to know that on your platform, the compiler allocates 4 bytes for a bool, then you can *(int)&booleanValue, and proceed to manipulate the bits...


Burn it with fire.
0

Share this post


Link to post
Share on other sites


See, C++ doesn't really enforce many rules. And if you happen to know that on your platform, the compiler allocates 4 bytes for a bool, then you can *(int)&booleanValue, and proceed to manipulate the bits...

 

This is actually very dangerous when doing language interop, even when the boolean types have the same size. C/C++ would seem to assume that 0 is false and anything else is true, but it is by no means certain that this is the same for all languages. For instance some other languages consider even = false and odd = true (i.e. they look only at the least significant bit, which imho makes more sense, but whatever). In these situations if you hack your "boolean" variable to equal, say, 42 in C++, this will evaluate to true in C++ but false in that other language. And it's not fun to debug.

 

It happened to me once. I was wondering why the boolean returned by a call to a C++ library I used from Pascal years ago didn't evaluate to what it should have. Turned out their idea of a boolean was not true/false but more like true/false + handle to some internal structure (because apparently, returning that handle by reference wasn't good enough and they needed to squeeze a copy in the return value "for my convenience"). /sigh

 

But this all goes with the rest.. people trying to be clever by finding loopholes in the standard and ending up shooting themselves (or, preferably, their users) in the foot.

0

Share this post


Link to post
Share on other sites


This is actually very dangerous when doing language interop, even when the boolean types have the same size. C/C++ would seem to assume that 0 is false and anything else is true, but it is by no means certain that this is the same for all languages.

Bingo.

 

Proprietary embedded chip, with 4-byte native alignment, and a CMP instruction that only looked at the least-significant bit.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0