Tuesday, June 27, 2006

Turtle Speed: Faster simulations with OBJ shapes

In a recent post I demonstrated how to set the visible color of OBJ shapes. Today, I will highlight another benefit of OBJ shapes over their MD3 counterparts: they are often faster.

Recall that you can always monitor the rendered FPS and the VMPS by pressing the "H" key twice. If a model with many agents that are represented with MD3 shapes seems to be running slowly, even with the Speed Slider set to Max Speed, you may achieve better frame rates by switching to OBJ shapes.

Consider the sample project Epidemic (epidemic.sltng), found in the Projects folder in the StarLogo TNG installation directory. Epidemic uses simple OBJ spheres to represent agents that may become infected as they move around and interact with other agents. The use of OBJ shapes in Epidemic is primarily to be able to use color to differentiate between sick and healthy agents. However, you may find that Epidemic runs much more quickly thanks to the use of OBJ shapes instead of MD3s, especially on older computers.

To see the effect, try changing the shape of the agents from the sphere to an MD3, such as Mario or one of the animals. You will no longer be able to visualize sick and healthy agents with color, and you may also notice that the model runs much more slowly when many agents appear on the screen at once.

If we ever find a way to improve the performance of MD3s significantly, blog readers will be the first to know! In the meantime, if you find that your model is running sluggishly, consider changing some of the breeds to OBJ shapes.

Labels: ,

Tuesday, May 16, 2006

Turtle Speed: Focus on Spaceland

In a recent post, I explained the difference between FPS and VMPS in StarLogo as well as how to monitor them by pressing the "H" key. I also showed you how to control the VMPS using the Speed Slider.

Unfortunately, there is no way to control the FPS directly. The number of frames per second that StarLogo can show you depends a lot on your computer's hardware, especially its graphics card and processor. Nevertheless, today's tip explains one way to boost Spaceland's FPS substantially.

Many 3D games take up the whole screen while they are running. They can run as fast as possible without worrying about whether it will slow down your ability to surf the web or compose an e-mail message, whereas StarLogo does not have that luxury. One of our design goals is that running a model in Spaceland, even at max speed, should not interfere with your ability to modify the blocks code or work with other pieces of software. Spaceland cannot greedily hog your computer's processor if you want to multitask.

In order to meet this goal, we designed Spaceland to automatically throttle the FPS when it is not the focused window. For example, when you push a Forever button in the Runtime workspace, Spaceland will not have focus, as shown for Mac OS X in the screenshot below, where you'll notice that the title and the three buttons on the left are grayed out:


Even at max speed, when Spaceland is not in focus, this Mac only gets about 34 frames per second and 33 virtual machine cycles per second. Now, if you click on the Spaceland window, the buttons light up red and green, and the title becomes bold:


Wow! The FPS shot up to 110 frames per second on this Mac, and all we had to do was click on the window. By giving focus to the window, we are literally telling StarLogo that we intend to give Spaceland our attention, and Spaceland speeds ahead. Then, when we want to control the model with blocks, as soon as we click on a block, Spaceland loses focus and slams on the brakes, giving the blocks a chance to move.

Labels: ,

Tuesday, May 09, 2006

Turtle Speed: Slide into high gear

We designed StarLogo TNG with the following goal in mind: Models should run at the same speed on all computers that meet the minimum system requirements.

In order to meet this goal, we defined two distinct measures of model speed called FPS and VMPS. FPS may be familiar to all the gamers out there. It measures the number of "Frames Per Second" that your computer draws in the Spaceland window. Computers with high-end graphics cards will achieve higher FPS, and the higher the FPS, the smoother the animation. It will still take an agent the same amount of time to walk forward one step, but it will look more fluid on a faster computer.

VMPS is the number of "Virtual Machine [cycles] Per Second," and it measures the number of times per second that your model gets run by every agent. So if your block program is "Forward 1," there are 100 agents in the model, and you put the program in a Forever button, then the VMPS is how many times every second that all 100 agents take one step forward as the program is repeated forever.

Tip: The "H" key toggles displaying the FPS and VMPS in Spaceland.

While it is true that a given model should run at the same speed on any computer, we realized that not all models need to run at the same speed, and sometimes it is useful to speed up or slow down a model while you are developing it. The Speed Slider makes this task easy! Just click the "Runtime" tab and drag the slider to adjust the speed. You can even pause the model entirely and run it one VM cycle at a time with the "Step" button.

So, if you want your model to run twice as fast, drag the slider to the tick mark labeled "2x," or just click on "2x." The FPS might stay the same, but the VMPS will double!

But what if you don't care about your model running at the same speed on any computer, and you just want your model to run as fast as your computer will let it? Games would not be as fun if they played this way, but sometimes it helps if you are running a simulation. The good news is that you can; just move the slider all the way to "Max" to get the maximum speed.
Now, if you press the "H" key to look at the FPS and VMPS for your model, you'll see that they are about the same. Instead of trying to get smooth animation, TNG will only draw one frame for every cycle of the VM. It may not look as nice, but it will be fast!

You may also notice that the numbers fluctuate-- a lot. That's because your computer may be trying to do other things while you are running the model. For example, if your computer is also playing music or connecting to a web site, it will have less free time to run your model, and the model will run more slowly. At max speed, the fewer other things your computer has to worry about, the faster your model will run.

Labels: