General Clinkster thread
category: code [glöplog]
Hi all
I am going to code a 4kb intro after few years break. I am working on a small 4k intro with Clinkster as soft synth. I have few question according to how to control speed of effects. Old approach was:
g_fDeltaTime was used as timer controlling the visuals of intro. The Clinkster offers Clinkster_GetPosition() function. Should I calculate delta based on values returned by Clinkster_GetPosition() in the begining and end of frane and pass it to a drawing functions or just pass returned value by Clinkster_GetPosition() to a drawing functions?
Thank you in advance
I am going to code a 4kb intro after few years break. I am working on a small 4k intro with Clinkster as soft synth. I have few question according to how to control speed of effects. Old approach was:
Code:
Init()
{
g_dwLastTime = timeGetTime();
g_dwTime1 = timeGetTime();
}
Draw()
{
g_dwCurrTime = timeGetTime() - g_dwLastTime;
... draw something...
g_dwTime2 = timeGetTime();
g_fDeltaTime = (g_dwTime2 - g_dwTime1)/1000.0f;
g_dwTime1 = g_dwTime2;
}
g_fDeltaTime was used as timer controlling the visuals of intro. The Clinkster offers Clinkster_GetPosition() function. Should I calculate delta based on values returned by Clinkster_GetPosition() in the begining and end of frane and pass it to a drawing functions or just pass returned value by Clinkster_GetPosition() to a drawing functions?
Thank you in advance
You should not use delta values. Rather you should calculate your effect parameters directly from the music timer (as returned by Clinkster_GetPosition()) every frame. This both simplifies the computations (leading to smaller code) and makes sure your visuals progress in the same way independently of the frame rate. For example, if you had something like:
an equivalent, and direct, computation would be:
You can convert the value returned by Clinkster_GetPosition() into seconds by dividing by Clinkster_TicksPerSecond. However, usually you will be better off basing your movements on the time in ticks directly, as music ticks is a more meaningful measure of time than seconds when you are timing something to the music.
Code:
x += delta_time * speed;
an equivalent, and direct, computation would be:
Code:
x = start_value + time * speed;
You can convert the value returned by Clinkster_GetPosition() into seconds by dividing by Clinkster_TicksPerSecond. However, usually you will be better off basing your movements on the time in ticks directly, as music ticks is a more meaningful measure of time than seconds when you are timing something to the music.
I am doing timings of the intro scenes base on the value returned by Clinkster_GetPosition() function. Integer value is extracted fro position variable and it is used for scene timings. Plase find the code attached below:
Code works fine but is there more elegant way of scene timings and more coder friendly?
Any help will be appreciated:)
Code:
float posCurrVal = Clinkster_GetPosition();
float cVal = 0;
modf(posCurrVal, &cVal);
int iPos = (int) cVal;
if ((iPos >= 0) && (iPos <=127))
{
drawTorus(posCurrVal);
if (iPos % 16 == 0)
{
flash(posCurrVal);
}
}
if ((iPos >= 129) && (iPos <=256))
{
drawSphere(posCurrVal, 2, 2);
if (iPos % 16 == 0)
{
flash(posCurrVal);
}
}
Code works fine but is there more elegant way of scene timings and more coder friendly?
Any help will be appreciated:)
Code:
int iScene = iPos >> 7;
if (iScene == 0)
{
//...
}
else if (iScene == 1)
{
//...
}
else if (iScene == 2)
{
//...
}
or you could directly switch (iScene) and case 0, 1, 2, ...
@xTr1m: What is int iScene variable? Could you please clarify?
...or you could just use the iScene variable as a direct index into an array of appropriate control parameters (sth. I like to do quite often).
Or just check specific bits in the iPos value directly (might need to be multiplied rathern than just converted to int for more-than-second granularity if you want to match individual beats).
Note that this only works if you have some equal-spaced timing pattern, but anything with a 4/4 based soundtrack usually matches that perfectly anyway ;)
Or just check specific bits in the iPos value directly (might need to be multiplied rathern than just converted to int for more-than-second granularity if you want to match individual beats).
Note that this only works if you have some equal-spaced timing pattern, but anything with a 4/4 based soundtrack usually matches that perfectly anyway ;)
You don't have to call modf to get the integer part out. The cast to int does that on its own.
Your example does nothing during tick 128. Is that intentional?
If your scenes are back to back, you don't have to check both bounds for every scene. You can do it like:
or, if all your scenes have the same length, you could use a scene index as xTr1m suggests.
The return value from Clinkster_GetPosition() is measured in music ticks, so it should have an appropriate scale for tricks like this already.
Your example does nothing during tick 128. Is that intentional?
If your scenes are back to back, you don't have to check both bounds for every scene. You can do it like:
Code:
if (iPos < 128) {
// Scene 1
} else if (iPos < 256) {
// Scene 2
} else // etc...
or, if all your scenes have the same length, you could use a scene index as xTr1m suggests.
Quote:
Or just check specific bits in the iPos value directly (might need to be multiplied rathern than just converted to int for more-than-second granularity if you want to match individual beats).
The return value from Clinkster_GetPosition() is measured in music ticks, so it should have an appropriate scale for tricks like this already.
Quote:
@xTr1m: What is int iScene variable? Could you please clarify?
I was just replacing part of your code. I'm using your own iPos for that:
Quote:
Code:float posCurrVal = Clinkster_GetPosition(); float cVal = 0; modf(posCurrVal, &cVal); int iPos = (int) cVal;
Thank you lads for valuable posts:)
@Blueberry: Tick 128 is for white flash of screen - transition between 1st and 2nd scene of intro:
I am stuck with other things so I removed it from code. I will deal with it in the next few days.
@Blueberry: Tick 128 is for white flash of screen - transition between 1st and 2nd scene of intro:
Code:
if (iPos== 128)
flash(posCurrVal);
I am stuck with other things so I removed it from code. I will deal with it in the next few days.