Game Development Reference
In-Depth Information
public function startProfile(frameRate:int):void : This function requires that the
needed frameRate be passed in. The profiler will use this value to evaluate ability of the
user's machine to run at that frame rate. This function sets up the text and location for
the profile and then starts the profile. There are five very important lines at the end of
the function:
for (var ctr:int = 0; ctr < profilerRenderObjects; ctr ++) {
profileAddObject()
}
Here we are creating the actual objects to render to the screen based on the preset
profilerRenderObjects value.
profilerRenderFrames = profilerRenderLoops * profilerFrameRate; : Here, we are
calculating the number of frames we want the profile to run. This is based on the number
of profile iterations we want to run and the frame rate we want to run them at.
addEventListener(Event.ENTER_FRAME, runProfile); : The profile is started with the
ENTER_FRAME event and will call the runProfile function on each iteration. It will run for
profileRenderLoops number of iterations.
These are the private functions:
private function runProfile(e:Event) : This function is the game loop for the profiler.
Its job it to calculate the frame rate for each set of render loops and store that data for
analysis after the profile has completed.
if (frameCounter.countFrames()) {
profilerFrameRateTotal += frameCounter.lastframecount;
profilerFrameRateEventCounter++;
messageTextField.text = "Profiling\nOptimal\nFrame Rate\n" +
String(int(profilerFrameCount / profilerRenderFrames * 100)) + "%";
profilerFrameRateArray.push(frameCounter.lastframecount);
}
When the frameCounter returns a true in the if conditional, 1,000 milliseconds have
passed since the last frame rate event. A frame rate event is simply a call to
calculate the current frame rate once 1,000 milliseconds have passed. It is not an
actual Event instance but rather our made up term to signify when a single second of
processing has been completed. Since we don't know exactly how the system will
perform under the profile, we cannot assume that the number of loops desired for the
test will actually be the number run. We don't know how the system will actually
perform under the stress of the test. For this reason, we keep our own count of
events using the profilerFrameRateEventCounter . We add the frameCounter 's last
calculated frame rate to the total, profilerFrameRateTotal , and we update the on-
screen text for the profile. Each frame rate is also placed in the
profilerFrameRateArray array to be used in the adjusted average. See Figure 11-2.
Search WWH ::




Custom Search