Programming (18)

Programming information.

Printing Floating-Point Numbers - Part 3: Formatting

We have written an implementation of the Dragon4 algorithm that can be used with both 32-bit and 64-bit floating-point numbers. However, the inputs and output to Dragon4 are not as user friendly as we need. Thus, we're going to create two user facing functions. One will print a supplied 32-bit float to a buffer and the other will print a supplied 64-bit float to a buffer.

Continue reading...

Printing Floating-Point Numbers - Part 2: Dragon4

So far, we've covered enough background to start diving into the real code. To get started, we need to write some high-precision arithmetic. Luckily we only require a subset of operations: comparison, addition, multiplication, exponentiation, division, and a bitwise shift.

The performance of what we write here will have a large impact on the overall algorithm. When I first got Dragon4 up and running, I was using a very C++ friendly public-domain big integer class that I found online. After everything was functional, I rewrote my own big integer code specifically tuned to the task at hand and performance increased over one hundred fold. That's not to say this is as optimized as possible, but it should be fast enough for production use.

Continue reading...

Printing Floating-Point Numbers

As far as I could find (as of today - March 5, 2014), there are only two open source implementations of floating-point to string conversion that are efficient, accurate and output "pretty" results. The code can be hard to follow and the licenses are a little more restrictive than I prefer. As an everyday tool that is often taken for granted, it might be surprising that it is so rarely implemented, but it's actually nontrivial to solve. It's also one of those problems complex enough where a wise engineer might recommend that "you never write your own", but I like a challenge and have been interested in it for a while. After spending a couple weeks investigating and experimenting, hopefully I can make it a bit more digestible for the curious.

Continue reading...

Damped Springs

I've worked on third-person camera systems for numerous games and I often need a method for smoothing camera motion as the player moves through the world. The player’s motion may create sharp, discontinuous changes in direction, speed or even position. The camera, however, should:

  1. Avoid discontinuities in motion. Accelerate and decelerate as needed rather than snap to a new velocity.
  2. Never let the player outrun the camera. The farther away he gets, the faster the camera needs to move.
  3. Move exactly the same with respect to time regardless of frame rate.

To solve this problem, I often simulate the camera with a set of damped springs.

Continue reading...

How to use ASSetPropFlags in ActionScript 2.0

There are multiple undocumented functions in ActionScript 2.0 of which one is ASSetPropFlags. I needed to use this function on a project recently and quickly found out that most of the unofficial documentation is either incorrect or overly brief. What I'm going to do here is describe how the function works and then show a program that will test and confirm some of the more complex functionality. 

Continue reading...