[Fixed] CheckInventory for Heretic keys fails

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

CheckInventory for Heretic keys fails

Postby Graf Zahl » Sun Jan 04, 2004 9:49 am

Code: Select allExpand view
         if (strcmp (HereticKeyNames[i], type) == 3)
         {
            return player->keys[i] ? 1 : 0;
         }


The first line should read '== 0'.

CheckInventory for Hexen keys isn't implemented at all.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: CheckInventory for Heretic keys fails

Postby Hirogen2 » Sun Jan 04, 2004 2:06 pm

Graf Zahl wrote:
Code: Select allExpand view
if (strcmp (HereticKeyNames[i], type) == 3) {
  return player->keys[i] ? 1 : 0;
}


Lol, similar topic on ?: on IRC:
Code: Select allExpand view
return !!player->keys[i];
User avatar
Hirogen2
 
Joined: 19 Jul 2003
Location: Central Germany
Github ID: jengelh
Operating System: RedHat-like Linux (RHEL, Fedora, CentOS, etc) 64-bit
Graphics Processor: Intel (Modern GZDoom)

Postby HotWax » Sun Jan 04, 2004 2:43 pm

not-not? heh.
User avatar
HotWax
Do what you must, and pay the price later.
 
Joined: 18 Jul 2003
Location: Idaho Falls, ID

Postby Hirogen2 » Sun Jan 04, 2004 2:47 pm

Yeah you can use !! to make a bool from a number, or you could use ?:
If player->keys[i] is 0, you get 0. If it is -1, you get 1, 1->1, 2->1, etc.
Practical tests have shown that both MSVC and GCC optimize it away at even -O0 (no optimization), they use the cmp and setne x86 asm instructions.
User avatar
Hirogen2
 
Joined: 19 Jul 2003
Location: Central Germany
Github ID: jengelh
Operating System: RedHat-like Linux (RHEL, Fedora, CentOS, etc) 64-bit
Graphics Processor: Intel (Modern GZDoom)

Postby HotWax » Sun Jan 04, 2004 2:58 pm

Cool trick. I'm supposing it would be useless in an if statement though. :D

Code: Select allExpand view
if (!!Player.Jumping) printf("Yep, the player is definately not-not-jumping!");
User avatar
HotWax
Do what you must, and pay the price later.
 
Joined: 18 Jul 2003
Location: Idaho Falls, ID

Postby Graf Zahl » Sun Jan 04, 2004 5:36 pm

HotWax wrote:Cool trick. I'm supposing it would be useless in an if statement though. :D

Code: Select allExpand view
if (!!Player.Jumping) printf("Yep, the player is definately not-not-jumping!");




Yes, it would. But when assigning it to a boolean variable '!!' is quite useful to avoid warnings. Like:

Code: Select allExpand view
void func(char * p)
{
bool valid=!!p;


...
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Postby randi » Tue Jan 06, 2004 6:15 pm

Fixed.
User avatar
randi
Site Admin
 
Joined: 09 Jul 2003


Return to Closed Bugs

Who is online

Users browsing this forum: No registered users and 0 guests