Using A Fixed Render Frequency |
Print Previous Next |
Up to now, we know that the maximal render frequency of an effect is 50 FPS, which translates to 3000 BPM. We also know how to manage that a script can act like it would run much faster. The last thing we want to introduce here is the possibility to have a fixed render frequency. Imagine a script that needs a lot of processing time; much too much to render it at 50 FPS. You may want to decrease the render frequency while the user is still able to set the speed of the effect using the BPM slider or the Speed Master. We have done this before, but with the difference that MADRIX did set the maximal fixed render frequency. We can tell MADRIX to render an effect with a fixed frame rate, for example 1500 BPM (or 25 FPS), using the function: void SetFixedFrameRate(int bpm, int enable)
This function sets the render frequency to the given value in bpm if enable is set to true. If enable is false, the bpm value is ignored and the usage of a fixed render frequency is disabled again. The parameter bpm may have a value of 1 to 3000. If the render frequency is set to a fixed rate, you will need to use the function framesteps value to calculate the effect. If this function is not used, it will be rendered with the speed the user has set. The following two examples will explain this in more detail. To demonstrate this effect, the first script of this chapter is used as a basis. The line SetFixedFrameRate(1500, true) simply needs to be added to InitEffect. Here is the complete source code: int g_pos[]; int g_rectSize[] = {4, 4}; //size of the rect
void MatrixSizeChanged() { g_pos[1] = GetMatrixHeight() / 2 - g_rectSize[1] / 2;; }
void InitEffect() { MatrixSizeChanged(); SetFixedFrameRate(1500, true); }
void RenderEffect() { Clear(); FillPixelRect(WHITE, g_pos[0], g_pos[1], g_rectSize[0], g_rectSize[1]); //move the rectangle g_pos[0] += 1; //check if the rectangle has left the matrix and set it back if(g_pos[0] > GetMatrixWidth() + g_rectSize[0]) g_pos[0] = -g_rectSize[0]; }
Please load and start the script using the MAS Script effect. While it is running, try to move the BPM slider or the Speed Master and you will see that nothing happens. The rectangle moves exactly with 25 FPS from the left to the right side of the matrix. In order to get a faster or slower movement of the rectangle, two things are necessary: First, the function framesteps must be used to calculate the movement. Second, the position values need be changed from integer to float since the frame steps will be given as floating point values. Here is the new example: float g_pos[]; int g_rectSize[] = {4, 4}; //size of the rect
void MatrixSizeChanged() { g_pos[1] = (float)(GetMatrixHeight() / 2 - g_rectSize[1] / 2); }
void InitEffect() { MatrixSizeChanged(); SetFixedFrameRate(1500, true); }
void RenderEffect() { Clear(); FillPixelRect(WHITE, (int)g_pos[0], (int)g_pos[1], g_rectSize[0], g_rectSize[1]);
//move the rectangle g_pos[0] += GetFrameSteps(); //check if the rectangle has left the matrix and set it to the other side if((int)g_pos[0] > GetMatrixWidth() + g_rectSize[0]) g_pos[0] = (float)-g_rectSize[0]; else if((int)g_pos[0] < -g_rectSize[0]) g_pos[0] = (float)(GetMatrixWidth()+g_rectSize[0]); }
In the previous examples, GetFrameSteps() always resulted in integer values like 1.0, 2.0, etc. The minimum value was 1.0. Now the framesteps are given as floating point values and may also result in 0.5 or 1.73. SetFixedFrameRate requires floating point values to work accurately. Therefore, if SetFixedFrameRate is enabled, floating point frames will be enabled as well. Moreover, it is not possible to disable floating point frames when a fixed frame rate is used. Please note: Even though a script may use a fixed render frequency, after recompiling and starting another script it will be disabled again.
|