Re: Can MUDs implement range/distance?
Heh. I know that, dentin, but I was so sure this time...
True, though, integer overflow == fun. I'd not use c for a mud, however, so idk. I suppose it greatly depends on what language you're using whether or not that function or something like it is needed--I know python can promote numbers to bigint and I'm almost certain c# and java throw exceptions.
But yeah, listen to KaVir. I forgot the integer overflow.
Anyone know how his function is actually fixing the problem, though? He appears to be converting to double, but I'm not sure what cThing->location is supposed to be.
For those using c, it may be worthwhile to go read about the gcc extensions--in particular, long long (which is standard, now, I think), and 128-bit integers (which is even bigger and may also be standard). If we assume the maximum value of long long to be some measurement in meters, it's aproximately 1949.8640344137174849557028971024 light-years, unless my math is failing again. Beware, these may have performance penalties.
There is also the option of writing your own distance class of some sort, but that probably deserves a whole new thread, if not an entire article, and there's probably tons of literature on that already, and it may/probably isn't worth your time.
I still advocate oct-trees, a bit--there's problems with the pythagorean theorem for larger worlds unless you split them somehow. The truth is, I don't think there's much more that can be said in this thread without a bunch of specifics and someone actually working on a project asking for help.
|