Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: Sat May 19, 2007 6:23 am   

%bitrshift(varname,bits), %bitlshift(varname,bits) 0xFFFFFFFF
 
Sorry for reposting this... I can't seem to find a delete thing for the other forum... whoops!

Idea ok so I've decided to make my illusion flag a boolean thing so that I can do something like:


FOR EXAMPLE ONLY!!:

Code:
magi = %leftshift(1,0)
forestal = %leftshift(1,1)
weapon = %leftshift(1,2)
vampire = %leftshift(1,3)
syssin = %leftshift(1,4)



#TR {Bob pricks you twice in rapid succession with his dirk.} {flags = %bitor(@flags, %bitor(@weapon,@syssin))}

#TR {You feel cold, look pale, and are super slimy.} {#IF(%bitand(@flags,0xFFFFFFFF) == 0) {illusion = 1}}



But I've noticed a number of things.... first of all, am I able to use hex notation??? 0xFFFFFFFF???
Second of all, is there a left and right shift operator??? it doesn't look like these features are in cmud, but I could totally be wrong.

If they aren't it's sorta impossible to do some operations without the left and right shift, so... er... yeah, I'm pleading for help on this one... well there are cludges but they make life unreadable and slow in some cases...

hex I can live without, but it's love to my eyes.

Thanks.

Also as you can see it would also be nice if there was a bitand/bitor, that could be applied to more than 2 objects, as I have above.
but, this is all cosmetic.

flags = %bitor(@flags, @weapon, @syssin)

Sorry Shocked
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat May 19, 2007 5:43 pm   
 
There are already %bitor and %bitand functions. As for shift just use math left shift x is the same as *2^x, right shift is division.

Generally greater speed can be achieved by using more variables and reducing complex function calls. Remember memory is cheap these days.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: Sat May 19, 2007 10:33 pm   
 
the problem with that is that in general shift is like 10000000000000000000 times faster than a standard multiply. but yeah, that's why I said it's a cludge.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue May 22, 2007 5:07 pm   
 
Actually, you would be surprised by the fact that the speed isn't very different these days. When using integer arithmetic the low-level chip can often optimize the operation and will use bit shifting when it can. It's only floating-point multiplies that are much slower. Run a test in C or Delphi and you'll see some speed improvement, but it will be a small percentage. Not even a factor of 2, and certainly not "10000000000000000000 times faster".

There was a time many many years ago when this was a bigger difference. But optimization has come a long way since then. I mostly use bit shifting for implementing various packed boolean flag operations, rather than for speed these days.

Also, don't forget that you can use other scripting languages in CMUD these days. So you can easily use another language that has bit shifting and hex notation.

I'll add hex notation to the wish list for a future version. Bit shift functions are already on the list.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net