Jump to content
  • 0

checking negative values in ACS


msx2plus

Question

hey all; i've got an issue where this statement will turn up true the second the integer hits a negative value:

...
int playposz = round(GetActorZ (0));
if (playposz <= -440)
...

the values are returning properly rounded, but anything below 0 will trigger the if statement. interestingly, if i combine this with other checks via && (ex: if (playposz <= -440 && playposx <= -1336 && playposy >= 4480)), this alone will set off the entire thing. what on earth is going on?

Edited by msx2plus

Share this post


Link to post

4 answers to this question

Recommended Posts

  • 1

GetActorZ returns a fixed point value. That means you have to compare it to a fixed point value. The easiest way to do it is to add a ".0" to your integer values, i.e.

 

if (playposz <= -440.0)

 

Share this post


Link to post
  • 0

that works perfectly! i was under the impression i wouldn't be able to store those as integers properly and that rounding/flooring them would work, but i guess not? thanks a bunch.

Share this post


Link to post
  • 0
3 hours ago, msx2plus said:

that works perfectly! i was under the impression i wouldn't be able to store those as integers properly and that rounding/flooring them would work, but i guess not? thanks a bunch.

Fixed point values are integers, in Doom they are 16.16. The upper 16 bits are basically treated as a signed word, while the lower 16 bits is the precision.

Basically,

if (playposz <= -440.0)

is no different from any of these

if (playposz <= (-440 << 16))
// --
if ((playposz >> 16) <= -440)
// -- This last one makes more sense if you chuck -28835840 into a programmer calculator set to DWORD to look at the bit arrangements, but it's basically what -440 << 16 equals to.
if (playposz <= -28835840)

 

Edited by Edward850

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...