Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Vanilla

Reply
 
Thread Tools Display Modes
Old January 14, 2017, 12:10   #11
PowerWyrm
Veteran
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 1,784
PowerWyrm is on a distinguished road
http://angband.oook.cz/forum/showpos...&postcount=177

I was pretty sure that was fixed in 4.0.4, but apparently not...
__________________
PWMAngband variant maintainer - check http://www.mangband.org/forum/viewforum.php?f=9 to learn more about this new variant!
PowerWyrm is offline   Reply With Quote
Old January 19, 2017, 19:01   #12
kandrc
Adept
 
Join Date: Dec 2007
Posts: 105
kandrc is on a distinguished road
Quote:
Originally Posted by Pondlife View Post
If both sides of that division are integer, you'll end up with integer division. That's rarely what you want (e.g. 10/3 = 3). I'd normally force something to be float or double, e.g:

final *= (100.0 + context->boost) / 100.0;

Note that I know nothing about the Angband source; so I may well be talking out of my backside. But I've been burnt by integer division in C before so I thought I'd mention it.
Floating point is sloooooowwwwww. 10s (or on some architectures even 100s) of cycles of latency, versus one cycle of latency for integer. Roguelikes have enough complicated stuff going on that this actually does matter. It's easy to end up with a compute-bound roguelike game simply by using floating point.

Today's processors are fast enough that you could get away with expressions like the above here and there, but back in the day it would have made the game unplayable. Maintainers have made the wise decision (whether or not they understood it (no implication intended)) to stick with an integer only design philosophy, thus avoiding painful FP creep.

If your integer division gives you unacceptable rounding errors, the solution is not to convert to float; it's to multiply all numerator terms by 10 (or 100, or whatever value gives you enough decimal places) and treat it as fixed point.
kandrc is offline   Reply With Quote
Old January 19, 2017, 19:15   #13
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 7,685
Derakon is on a distinguished road
Quote:
Originally Posted by kandrc View Post
Floating point is sloooooowwwwww. 10s (or on some architectures even 100s) of cycles of latency, versus one cycle of latency for integer. Roguelikes have enough complicated stuff going on that this actually does matter. It's easy to end up with a compute-bound roguelike game simply by using floating point.
This might have been the case way back in the day when Angband was first written, but is really not the case any more. Certainly it is possible to make a slow roguelike by making unwise choices, but it's not going to be because you decided to use floating-point math instead of fixed-point, it's going to be because you decided to have hundreds of units all running A* pathfinding every turn, or because you're using software rendering to draw thousands of letters, one at a time, every time any aspect of the screen changes. Dumb algorithmic decisions are what will wreck you, not dumb formulaic decisions.

And the problem with the "just avoid floating point" mindset is that now every single computation you do, you have to worry about whether you're screwing things up. It's easy to introduce bugs like the above. If you just let yourself use floats then things get a lot simpler.

As always, obey these rules of optimizing:

* Is it slow? If not, don't optimize.
* Figure out what part is slow.
* Measure how slow it is.
* Optimize that part.
* Measure it again.

Optimizing almost always sacrifices clarity of code for efficiency of code, and it always results in more work being spent on a given piece of code that's otherwise functional. These are both substantial costs, so you should only optimize when it proves to be necessary.

That doesn't mean that you shouldn't be aware of broad-scale runtime implications, of course. Don't use bubble sort, that kind of thing. But your #1 concern for your code should always be does it do the right thing? Code that provides the wrong answer is worse than useless; code that is correct but slow is merely annoying.
Derakon is offline   Reply With Quote
Old January 19, 2017, 19:50   #14
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 3,812
Donated: $40
Pete Mack is on a distinguished road
Or you can just do
final += final* boost/100
like any other normal integer calculation.
Pete Mack is offline   Reply With Quote
Old January 19, 2017, 20:25   #15
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 51
Posts: 6,254
Donated: $60
Nick is on a distinguished road
Quote:
Originally Posted by Derakon View Post
This might have been the case way back in the day when Angband was first written, but is really not the case any more. Certainly it is possible to make a slow roguelike by making unwise choices, but it's not going to be because you decided to use floating-point math instead of fixed-point, it's going to be because you decided to have hundreds of units all running A* pathfinding every turn, or because you're using software rendering to draw thousands of letters, one at a time, every time any aspect of the screen changes. Dumb algorithmic decisions are what will wreck you, not dumb formulaic decisions.
You are, of course, correct in principle, although at this point in its development starting to use floating point in Angband would be a great source of bugs. There's also the consideration that we don't know for sure exactly what architecture the game will "need" to run on in the future. So it will be staying integer only for now.
__________________
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them.
Nick is offline   Reply With Quote
Old January 19, 2017, 20:42   #16
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 7,685
Derakon is on a distinguished road
Quote:
Originally Posted by Nick View Post
You are, of course, correct in principle, although at this point in its development starting to use floating point in Angband would be a great source of bugs. There's also the consideration that we don't know for sure exactly what architecture the game will "need" to run on in the future. So it will be staying integer only for now.
Yeah, my screed was more meant to apply to anyone considering starting a new project. Legacy code will always have weird quirks that made sense at the time and that aren't worth the hassle of trying to bring "up to date".
Derakon is offline   Reply With Quote
Old January 19, 2017, 22:05   #17
AnonymousHero
Veteran
 
AnonymousHero's Avatar
 
Join Date: Jun 2007
Posts: 1,238
AnonymousHero is on a distinguished road
Quote:
Originally Posted by Nick View Post
There's also the consideration that we don't know for sure exactly what architecture the game will "need" to run on in the future. So it will be staying integer only for now.
Heh. I don't think it's particularly likely that there'll be many new platforms without (at least emulated) floating point . Doesn't C89 actually mandate floating point support?
AnonymousHero is offline   Reply With Quote
Old January 20, 2017, 13:18   #18
Rydel
Apprentice
 
Join Date: Jul 2008
Posts: 78
Rydel is on a distinguished road
Send a message via Skype™ to Rydel
I think it's less an issue of new platforms, and more of someone deciding that's it's vital that Angband be ported to their Commodore VIC-20... assuming that port doesn't already exist.
__________________
I'm trying to think of an analogy, and the best I can come up with is Angband is like fishing for sharks, and Sil is like hunting a bear with a pocket knife and a pair of chopsticks. It's not great. -Nick
Rydel is offline   Reply With Quote
Old January 20, 2017, 16:57   #19
PowerDiver
Prophet
 
Join Date: Mar 2008
Posts: 2,712
PowerDiver is on a distinguished road
Quote:
Originally Posted by Rydel View Post
I think it's less an issue of new platforms, and more of someone deciding that's it's vital that Angband be ported to their Commodore VIC-20... assuming that port doesn't already exist.
That's what compilers are for.
PowerDiver is offline   Reply With Quote
Old January 20, 2017, 19:34   #20
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 3,812
Donated: $40
Pete Mack is on a distinguished road
Sure, floating point has it's place. But in this case, it really is fundamentally an integer operation. I posted the correct arithmetic earlier. No, you do not want to add first then multiply. Multiply first then add.
Pete Mack is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[FA] How do I activate Warrior Probe skill? Ingwe Ingweron Variants 2 November 17, 2014 06:11
[BUG] Getting a skill for 0 XP Stone Dog Sil 2 December 8, 2013 23:04
Magic Device Skill Old Coach v4 1 January 23, 2012 22:05
Gadgeteer skill in steamband UglySquirrell Variants 2 October 14, 2011 03:06
New spell / skill dhegler Vanilla 3 May 21, 2010 20:36


All times are GMT +1. The time now is 06:35.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.